Simulating Rollback on MongoDB
The Rollback state of MongoDB can cause a lot of confusion when it occurs. While there are documents and posts that describe how to deal with the state, there is nothing that explains step by step how you might end up that way. I often find that figuring out how to simulate the event makes it a lot clearer what is going on, while at the same time allowing people to figure out how they should deal with the situation when it arises. Here is the basic outline:
- Create a replica set, load up some data, verify it is working as expected, start to insert data
- Break replication (artificially) on the set so that the secondary falls behind
- Stop the primary while the secondary is still lagging behind
- This will cause the lagging secondary to be promoted
I’ll go through each step, including diagrams to explain what is going on after the jump.
———