Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoShake从mongos拉取仍旧存在duplicate key error #392

Closed
vinllen opened this issue Jul 23, 2020 · 2 comments
Closed

MongoShake从mongos拉取仍旧存在duplicate key error #392

vinllen opened this issue Jul 23, 2020 · 2 comments
Labels
enhancement New feature or request mark something needs to be noticed

Comments

@vinllen
Copy link
Collaborator

vinllen commented Jul 23, 2020

不符合预期,从mongos拉取不应该出现孤儿文档的问题。从mongod上看,的确有多个mongod存在相同的文档

[2020/07/22 00:17:26 CST] [WARN] insert docs with length[128] into ns[{live liveMeta}] of dest mongo failed[index[115], msg[E11000 duplicate key error collection: live.liveMeta index: _id_ dup key: { : ObjectId('5ee4799561f65774ac1f37be') }], dup[true]]
@vinllen vinllen added mark something needs to be noticed enhancement New feature or request labels Jul 23, 2020
@vinllen
Copy link
Collaborator Author

vinllen commented Jul 23, 2020

这个原因是现在mongoshake全量阶段用的是secondaryPreferred,所以优先读的secondary。read concern没有进行配置,导致读secondary是available的方式,available和local方式不同的是前者不会过滤掉孤儿文档。

  • 对于3.6以下的版本,readPreferred建议改为primary。
  • 对于3.6+的版本,readConcern需要默认改为local。3.6添加了一个sharding_filter的stage用于过滤文档:mongod读到以后会判断该文档是否属于当前mongod,不是的话会过滤掉,从此避免孤儿文档。

此处MongoShake将会给出建议和优化:

  • 对于3.6以下版本,用户自己调整配置项:mongo_connect_mode = primary。这是因为考虑到MongoShake如果直接强制修改,可能不符合用户的预期,导致primary节点负载打高。
  • 对于3.6+的版本,默认readConcern改为local。

当然,用户也可以通过full_sync.executor.insert_on_dup_update = true来进行过滤,不过建议还是采用上面方式更合理。
还有一种方式是全量开始前,先cleanupOrphaned清理一下孤儿文档。

参考:https://docs.mongodb.com/manual/reference/read-concern/

vinllen added a commit that referenced this issue Jul 24, 2020
vinllen added a commit that referenced this issue Jul 29, 2020
* fix bug that checkpoint.storage.db does not work since v2.4.6

* fix bug of orphan document filter core. #389.

* remove listDatabase request when incr_sync.shard_key != auto. #385

* add oplog_max_size and oplog_avg_size metric

* polish ChangeLog

* bugfix: HA switch with checkpoint duplicate update. #388

* polish ChangeLog

* increase syncer thread when fetching method is change stream

* add more log in reader to debug

* add readConcern and writeConcern in client to solve the orphan document problem reading from MongoS. #392

* Replace incorrect usages of blsstat with mongoshake-stat in scripts/mongoshake-stat (#393)

* fix wrong name usage in mongoshake-stat script, thanks @Neal Gosalia. see #393

* release v2.4.8

Co-authored-by: Neal Gosalia <[email protected]>
@vinllen
Copy link
Collaborator Author

vinllen commented Aug 14, 2020

亲测发现4.0版本,孤儿文档过滤不完善,即使配置了readConcern=local/majority,readPreferred=primary还是会碰到孤儿文档,这种情况建议手动清理一下。如果还有疑问请reopen当前issue

@vinllen vinllen closed this as completed Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mark something needs to be noticed
Projects
None yet
Development

No branches or pull requests

1 participant