-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RIVER-1738] Update pg store to use advisory locking instead of compa…
…ring UUIDs per transaction (#1739) This PR adds the usage of a session-wide `pg_advisory_lock`s to ensure unique read/write access to the database schema for this node while the node is up and available, and removes the per-transaction check on the singlenodekey table, improving query performance of the running node at the cost of neglegible amount of additional startup latency to take the schema lock. In order to maintain the session lock we acquire a connection from the pgx pool, take the lock on that connection, and continuously maintain the connection by polling it with pings. If a ping fails, the node will close the connection and attempt to acquire a new connection and re-establish the lock on the schema. If the node is unable to establish a healthy connection after about 20s of retries, or the node is unable to retake the schema lock, the node will exit. As before, we still detect the entrance of other nodes vying for the same schema on the network by monitoring updates to the singlenodekey table. The node updates the singlenodekey table on startup before taking the schema lock, and new nodes will trigger old nodes to release their schema lock and exit. When a node detects that a schema lock is unavailable, it will use the existing StartupDelay config parameter to give the exiting node some time to clean up after itself. Tests: - an existing unit test confirms that the existing node exits whenever a new node starts, properly responding to the new entry in the singlenodekey table. The success of the test case implies that the first node is properly releasing the schema lock. - manual local testing, using toxiproxy: - the node is able to recover the schema lock after temporary connection interruptions - the node will shut down after maximum retries to re-establish the connection and retake the schema lock if connectivity is not restored - the node will shut down if it is not able to retake the schema lock if network connectivity to pg is restored before it exhausts reconnection retries.
- Loading branch information
Showing
10 changed files
with
412 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.