6

Sometimes we observe the next case:

  • We insert a document to MongoDB with write concern w: 1 via mongos router that writes to primary replica of shard A.
  • We read this document from MongoDB with default local read concern via mongos router that should read from primary replica of shard A.
  • This findOne returns null as if the document is not found.
  • (Actually it is Python driver pymongo - find_one() and it returns None).
  • We sleep 0.1 seconds and retry the read.
  • On step 2-5 the document is finally read successfully.

We found:

  • Such cases are observed more often when a lot of documents are inserted to this collection quickly.
  • We suspected such inserts lead to chunking and migration of chunk from shard A to shard B.
  • While a document is migrating, could it be unavailable for reads for a short time?
  • But there is only one insert to only one shard in db.oplog.rs, no fromMigrate flags.

Why does it happen? How to deal with it correctly?

These false-positive "not found"-s may lead to faulty atomic-find-or-create via $setOnInsert?

1
  • Some having the same issue here but no solution has been suggested at the time of writting this comment ! Commented Aug 19, 2022 at 10:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.