简体   繁体   English

为什么mongodb oplog是幂等的? 即使是插入操作?

[英]why is the mongodb oplog is idempotent? Even for insert operation?

I am learning the replica set function of mongodb and when i read this article: replica set oplog 我正在学习mongodb的副本集功能,当我读到这篇文章时: replica set oplog

it said: 它说:

Each operation in the oplog is idempotent. oplog中的每个操作都是幂等的。 That is, oplog operations produce the same results whether applied once or multiple times to the target dataset. 也就是说,无论是对目标数据集应用一次还是多次,oplog操作都会产生相同的结果。

What does it mean? 这是什么意思? An insert or delete operation surely produce different result applying once than twice. 插入或删除操作肯定会产生不同于两次的不同结果。

So maybe i am wrong or somebody explain it? 也许我错了或有人解释一下? Thanks! 谢谢!

An insert or delete operation surely produce different result applying once than twice. 插入或删除操作肯定会产生不同于两次的不同结果。

You can't delete things twice. 你不能两次删除东西。 If you were to apply the same delete operation again, it would be a no-op. 如果您再次应用相同的删除操作,那将是一个无操作。

As for the insert: it's been a while since I looked at oplog, but I'm quite sure that replicated insert operation includes value for _id . 至于插入:自从我查看oplog以来已经有一段时间了,但我非常确定复制的插入操作包含_id值。 And so it too won't insert a second copy of a document (because _id must be unique) 所以它也不会插入文档的第二个副本(因为_id必须是唯一的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM