WriteConcern.SAFE isn't.

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Blocker - P1
    • None
    • Affects Version/s: 2.10.0, 2.10.1, 2.11.0, 2.11.1, 2.11.2, 2.11.3
    • Component/s: Write Operations
    • None
    • Environment:
      Running against a mongod 2.0.2 server (but I believe the issue exists with latest mongod as well).
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      We recently upgraded from mongo-java-driver 2.9.0 to 2.11.2 and started getting DuplicateKey exceptions in a scenario where we do a remove for a key followed by an insert.

      All of our operations use WriteConcern.SAFE, so they should be serialized and the DuplicateKey exception should be impossible.

      I dug into the code and found the following change in https://github.com/mongodb/mongo-java-driver/commit/b4d0a6ee933b268f9ca0b890adc4aed1bf30e097 :

      • if ( _w instanceof Integer && ( (Integer) _w > 0) ||
      • ( _w instanceof String && _w != null ) ){
        + if (_w instanceof Integer && ((Integer) _w > 1) || (_w instanceof String)) { _command.put( "w" , _w ); + }

      It looks to me like the driver is /not/ sending 'w' with the GLE command when 'w' is 1 (which corresponds to WriteConcern.SAFE or WriteConcern.ACKNOWLEDGED). But I believe it should be. If it doesn't send 'w', mongod does not wait for the previous operation to finish. So we are effectively getting WriteConcern.NORMAL instead.

            Assignee:
            Unassigned
            Reporter:
            Michael Lehenbauer
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: