3

The MongoDB docs say:

$isolated does not work with sharded clusters

Does this mean it does not work at all? Or does it mean that it does not work if the affected documents are on different shards, meaning that it does work if the affected documents are on the same shard?

I have a sharded cluster but I can assure that all affected documents are on the same shard. So I want to know, if in that case I can use $isolated.

heinob
  • 19,127
  • 5
  • 41
  • 61
  • Possibly worth a code dig for a real answer, but this line grabs me immeditately: *"Prevents a write operation that affects multiple documents from yielding to other reads or writes once the first document is written"*. So a little lateral thinking would suggest that the selected documents in a collection would be held with a "write lock" (granularity depending on engine) which would therefore not make a lot of sense to go out and contact all shards and do this. I would err on the suspicion that once your connection was though `mongos` this is ignored completely. – Blakes Seven Feb 27 '16 at 10:22
  • I suppose the other test would be "what's in the logs on the shard members?". That would tell you if the `$isolated` option was passed through or stripped. – Blakes Seven Feb 27 '16 at 10:23
  • $isolated is guaranteed to work with non-sharding mongodb database instances. It is not guaranteed to work with shards and I am not quite sure if it should, considering the semantics of $isolated. It is still possible, but you've to invest a little bit more like implementing Two-Phase commits by crafting a sequence a sequence of changes that manipulate documents in a way that supports multi-document transactional behavior. – Stefan Feb 27 '16 at 12:40
  • With some agreement from the client to certain conventions you can implement an $isolated behavior for sharded clusters, that is reliable and if written well resume- and recoverable. – Stefan Feb 27 '16 at 12:46

0 Answers0