Addressing #74 - Wait until primary is transitioned from secondary for replicaSet #203
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My attempt to has deterministic implementation for waitUntilRunning for replicaSet, which is discussed in #74 .
Was testing if there is way to tell if its ready from
replSetGetStatus
, but my testing shows it rather shows the intention (whats going to be master) rather than actual real time status. With debug info from mongod - you can see that mongod instance is transitioning from secondary state to primary state (after voting) which takes about 2s. Also my testing shows that you get connect error until this transition is finished. And only reliable approach I found was usingserverStatus
which indicates in realtime whether its master or secondary.Obviously
serverStatus
gives me status for the instance I am connect to, which is first server. Therefore this strategy would fail if some other instance would decide to be master initially. But in practice (testing 3 instances) always first server ended being primary, therefore this approach seems to be reliable from my testing.Another small change was just rely on
MongoMemoryServer.start
to be resolved (which should resolve once instance starts listening) instead of waiting 1s. That shaved off about 800ms.On my computer (current macbook pro) I am getting pretty good times. waitUntilRunning() gets resolved for single instance: 2100ms and multiple instance (3): 4100ms.
Let me know if you think I missed something. Thanks!