-
Notifications
You must be signed in to change notification settings - Fork 291
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
server: Implement separate mutex for peer state. #3251
Commits on May 16, 2024
-
server: Implement separate mutex for peer state.
Currently, all operations related to adding, removing, and banning peers are implemented via a single goroutine and channels to protect concurrent access. The existing implementation has worked well for over a decade, however, it is really not ideal in a few ways: - It is difficult to improve parallel processing since everything is forced into a single goroutine - It requires a lot of plumbing to provide access to any related information - The use of multiple channels means the ordering of events is not entirely well defined. In regards to the final point about event ordering, one example is that it's possible for a peer to be removed before it was ever added. The surrounding code is aware of these possibilities and handles things gracefully, but it really is not ideal. In practice, channels are best suited for passing ownership of data, distributing units of work, and communicating async results while mutexes are better suited for caches and state. Converting all of the code the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it will address the aforementioned concerns. Namely, it: - Improves the semantics in regards to the aforementioned ordering - Ultimately allows more code to run in parallel in the individual peer goroutines - Requires less plumbing for updating and querying the state - Makes the state available to calling code so it can make better decisions Thus, this is part of a series of commits that aims to make that conversion. This first commit introduces a separate mutex on the peer state and updates the code to protect all references to the relevant fields with that mutex. This will allow future commits to methodically refactor the various operations without introducing races.
Configuration menu - View commit details
-
Copy full SHA for dae0266 - Browse repository at this point
Copy the full SHA dae0266View commit details -
server: Make server peer conn req concurrent safe.
This updates the server peer connection request field to be safe for concurrent access by making it an atomic pointer. It also reorders some of the server peer fields and adds some comments that call out the concurrency semantics while here. This is a part of the overall effort to convert all of the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it.
Configuration menu - View commit details
-
Copy full SHA for 0302beb - Browse repository at this point
Copy the full SHA 0302bebView commit details -
server: Use iterator for connected ip count.
This modifies the connectionsWithIP method in the server to make use of the forAllPeers iterator instead of repeating the same logic for each peer category.
Configuration menu - View commit details
-
Copy full SHA for 0946e94 - Browse repository at this point
Copy the full SHA 0946e94View commit details -
server: Make add peer logic synchronous.
This refactors the logic related to adding a connected peer to the server out of the peer handler since it is now protected by the newly added peer state mutex. This is a part of the overall effort to convert all of the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it.
Configuration menu - View commit details
-
Copy full SHA for ca01de1 - Browse repository at this point
Copy the full SHA ca01de1View commit details -
server: Make done peer logic synchronous.
This refactors the logic related to removing a disconnected peer from the server out of the peer handler since it is now protected by the newly added peer state mutex. This is a part of the overall effort to convert all of the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it.
Configuration menu - View commit details
-
Copy full SHA for 0c5923f - Browse repository at this point
Copy the full SHA 0c5923fView commit details -
server: Make conn count query synchronous.
This refactors the logic for querying the number of connected peers out of the peer handler since it is now protected by the newly added peer state mutex. This is a part of the overall effort to convert all of the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it.
Configuration menu - View commit details
-
Copy full SHA for cfc52a0 - Browse repository at this point
Copy the full SHA cfc52a0View commit details -
server: Make outbound group query synchronous.
This refactors the logic for querying the outbound group counts out of the peer handler since it is now protected by the newly added peer state mutex. This is a part of the overall effort to convert all of the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it.
Configuration menu - View commit details
-
Copy full SHA for 8be3929 - Browse repository at this point
Copy the full SHA 8be3929View commit details -
server: Make manual connect code synchronous.
This refactors the logic for manually connecting peers out of the peer handler since it is now protected by the newly added peer state mutex. This is a part of the overall effort to convert all of the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it.
Configuration menu - View commit details
-
Copy full SHA for 28e3dcd - Browse repository at this point
Copy the full SHA 28e3dcdView commit details -
server: Make pending conn cancel code synchronous.
This refactors the logic for canceling a pending connection out of the peer handler since it no longer needs to be plumbed through the query channel. This is a part of the overall effort to convert all of the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it.
Configuration menu - View commit details
-
Copy full SHA for 2f0bf59 - Browse repository at this point
Copy the full SHA 2f0bf59View commit details -
server: Make persistent peer removal synchronous.
This refactors the logic for manually removing persistent peers out of the peer handler since it no longer needs to be plumbed through the query channel. This is a part of the overall effort to convert all of the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it.
Configuration menu - View commit details
-
Copy full SHA for 7673bed - Browse repository at this point
Copy the full SHA 7673bedView commit details -
server: Make persistent node query synchronous.
This refactors the logic for querying the persistent peers out of the peer handler since it is now protected by the newly added peer state mutex and no longer needs to be plumbed through the query channel.. This is a part of the overall effort to convert all of the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it.
Configuration menu - View commit details
-
Copy full SHA for cad836f - Browse repository at this point
Copy the full SHA cad836fView commit details -
server: Make manual peer disconnect synchronous.
This refactors the logic for manually disconnecting peers out of the peer handler since it no longer needs to be plumbed through the query channel. This is a part of the overall effort to convert all of the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it.
Configuration menu - View commit details
-
Copy full SHA for 9a746ba - Browse repository at this point
Copy the full SHA 9a746baView commit details -
server: Remove unused query chan and handler.
This removes the query channel and associated handler and plumbing now that it is no longer used. This completes the overall effort to convert all of the code related to updating and querying the server's peer state to synchronous code that makes use of a separate mutex to protect it.
Configuration menu - View commit details
-
Copy full SHA for 78bf86b - Browse repository at this point
Copy the full SHA 78bf86bView commit details