Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom iterators to SafeUnorderedMap #98

Closed
wants to merge 59 commits into from

Conversation

fcecin
Copy link
Collaborator

@fcecin fcecin commented Mar 8, 2024

This patch hides the std::unordered_map iterators that were exposed, and replaces them with new SafeUnorderedMap::iterator and SafeUnorderedMap::const_iterator.

As part of the proposed changes, some SafeUnorderedMap methods had to be removed. We can re-implement them later without exposing internal details, if it turns out that we will be needing them.

Added tests for the new features, and also some additional tests to make sure all of the insert/emplace/erase methods from the template type get instantiated at least once.

Jean-Lessa and others added 30 commits February 6, 2024 20:25
* Custom exception base class

* tests for DynamicException

* finish template behavior

* Test dynamic excpetion in prod code

* Fix member init

* Fix linter errors

* add more test cases

* test ethCall thrpw

* remove duplicate test

* Change runtime excpetions to DynamicExceptions
This solves a race condition by making sure that during stop() the
P2P::ManagerBase's thread pool waits for all tasks to be flushed
out before its Session objects are closed and the underlying
networking component is destroyed.
Move thread pool cleanup to after all sessions are deleted, to make
sure message production actually stops. This was causing
heap-use-after-free during ManagerBase destructor in testcases.
itamarcps and others added 29 commits February 13, 2024 11:44
P2P::Session on receiving a message, passes it to
ManagerBase::handleMessage with a weak_ptr instead.
* Replace weak_ptr<Session> with NodeId in Manager* APIs

* Fix SonarQube issue

* Remove retrieving session object for logging errors

* Harden P2P networking shutdown sequence

- Rule out any possibility that ManagerBase::sessions_ will
grow (or shrink) after ManagerBase::close_ is set to true, so that
ManagerBase::stop() can close all registered sessions

- On ManagerBase::stop(), join the Session thread pool after
Server and ClientFactory are stopped (possibly more correct)

* P2P::ManagerBase:

- removed closed_; replaced by started_ (ManagerBase should be
able to start() and stop() repeatedly and safely)
- added stateMutex_ to synchronize start(), stop() and thread pool
- start() creates threadPool_
- stop() destroys threadPool_ (waits for all tasks and joins all
threads, guaranteeing that there is no session/socket message
handling code active when it is time to e.g. destroy the
underlying io_context)
- threadPool_ is now isolated and not forwarded to other objects;
to use the ManagerBase thread pool, other objects have to call a
method on ManagerBase that will service the request, such as
ManagerBase::asyncHandleMessage()

state.cpp (test):

- increased timeout from 5s to 120s in a couple of futures to
avoid random, performance-related failures (logs to cout if they
exceed 5s, which in any case is rare)

* add this->
Make rdPoS an exclusive member class of State + parametrize some vars in Options
- Implement operator=()
- Implement size()
- Fix erase-insert-commit bug in commit()
- Improve & fix operator=() testcase that was calling the copy constructor instead
- Add erase-insert-commit regression test
- Fix all testcase asserts that depended on the placeholder size() code
- new custom iterators keep all internals hidden
- remove range-erase erase(first, last) method (use
  it = erase(it) in a loop instead)
- remove all node_type methods (harder to implement now
  that internals are not exposed)
- remove insert(T&&) template methods (don't instantiate)
- add testcases for functionality tests and for template
  instantiation tests
@fcecin fcecin closed this Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants