1

We have setup a 3 node replication set configuration for MongoDB. I want to know what happens to read/write operations during primary switchover. To be more explicit, few read/write operations were issued to primary node from clients. Switch over of primary was also initiated.

  1. What will happen to those read/write operations?
  2. Does MongoDB ensures that these requests are served before Primary steps down and election process is initiated?
  3. During election process, what will happen to new read/write requests from the clients?
  4. Does the native nodejs driver for MongoDB takes care of automatic client failover? And, also how does it handles the new read/write requests during switchover process?
2

a) They will fail explicitly. It is your responsibility to deal with it. What I tend to do is to retry the operation after a short grace period if the exception/error indicates that the operation failed because of a communication failure.

b) Implicitly. After the command to step down was issued, there is a 10 second grace period in which no write operations are accepted. During that time, the primary basically waits for the secondaries to catch up (be it necessary or not). For read operations: should they finish within the grace period, everything is fine. Otherwise, the connection is closed by the server, causing an error to be raised on th free client side.

c) The drivers are aware that they are connected to a replica set. If the primary steps down, the driver will notice. No primary = no write operations. Any write operation issued while there's no primary will fail with a according message. As per reads it depends on your read preference. Reads with a preference of primary will obviously fail while there is no primary, all other read preference will succeed. I usually issue my request with the default read preference of primary and when it falls because of a missing primary, I reissue the query with a read preference of secondaryPreferred (for the rare case that the primary came up and the first secondary failed while dealing with the original error).

d) I am not a node expert, but the node driver is maintained by the Inc, so it is safe to assume it is replica set aware and adheres to the standardsas described above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.