cojen / TuplDB

TuplDB is a high-performance, concurrent, transactional, scalable, low-level embedded database.
GNU Affero General Public License v3.0
110 stars 22 forks source link

Add method to wait until the local member has become the leader #104

Closed broneill closed 5 years ago

broneill commented 5 years ago

This method is added to the Replicator interface, and it waits if the local member will become the leader. This is only possible when the local member is the only one in the group, or if it's the only one which has a normal role. If the preconditions change while waiting, the wait method immediately returns false. When true is returned, the local member is the leader.

This option is then used by the DatabaseStreamReplicator, in the overridden ready method. This blocks database startup until recovery is complete and leadership is established, and makes it easier to create new replicated databases.

broneill commented 5 years ago

The method might be named waitForRecovery, and it also waits if the one group member is an observer or standby. It means that recovery is expected to actually finish instead of run indefinitely.