Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-948

WriteConcern.SAFE isn't.

    XMLWordPrintableJSON

Details

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

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            mikelehen Michael Lehenbauer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: