Idempotency in Replication

Hello @Muskan_Sharma

“The goal of transformation here is to make sure that the statements stored in the log can be applied an indefinite number of times while still resulting in the same data state. This term is called Idempotency.”

I am unable to understand this “statements in the log can be applied an indefinite number of times while still resulting in the same data state

Please help.

Thanks,
Bhavik

In essence, when the primary node writes the statement to its oplog, it ensures that when the secondaries get copies of the oplog, the statement can be replayed across as many secondary nodes and all nodes will result in the same state.

For example, if the Quantity is 100, and you update this field by adding 1 to it, the oplog will rewrite the statement to become 101 and all the secondaries will be updated to 101.

You:
$inc: {Quantity: 1}

Oplog:
$set: {Quantity: 101}

3 Likes

Now I understood. You’ve explained very well. Thanks a lot @007_jb

Regards,
Bhavik

You’re welcome!

Suggest you have a look in the oplog and see what it looks like after an operation:
use local
db.oplog.rs.find({<apply your filters>}).pretty()

oplog.rs is the name of the oplog collection.