Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-52634

Transactional bulkWrite error returns only 1 error

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.2.3, 4.4.1, 4.2.10
    • Component/s: Replication, Write Ops
    • None
    • ALL
    • Hide
      1. start session, open transaction
      2. in this session write documents with several duplicated keys
      3. expected: write errors about all duplicates
      4. actual: 1 write error
          @Test
          public void transactionalCase() {
              ClientSession session = dbFactory.getSession(ClientSessionOptions.builder().build());
      
              Document document1 = Document.parse("{_id:1, value: 1}");
              Document document2 = Document.parse("{_id:2, value: 2}");
              Document document3 = Document.parse("{_id:1, value: 3}");
              Document document4 = Document.parse("{_id:1, value: 4}");
      
              session.startTransaction();
              try {
                  collection.insertMany(session, List.of(document1, document2, document3, document4),
                          new InsertManyOptions().ordered(false));
                  Assert.fail("insertMany should fail");
      //            session.commitTransaction();
              } catch (MongoBulkWriteException e) {
                  session.abortTransaction();
                  Assert.assertEquals(e.getWriteErrors().size(), 2, "Expected to have 2 dup key errors:"); // fails here!
              } finally {
                  session.close();
              }
          }
      

       

      Show
      start session, open transaction in this session write documents with several duplicated keys expected: write errors about all duplicates actual: 1 write error @Test public void transactionalCase() { ClientSession session = dbFactory.getSession(ClientSessionOptions.builder().build()); Document document1 = Document.parse( "{_id:1, value: 1}" ); Document document2 = Document.parse( "{_id:2, value: 2}" ); Document document3 = Document.parse( "{_id:1, value: 3}" ); Document document4 = Document.parse( "{_id:1, value: 4}" ); session.startTransaction(); try { collection.insertMany(session, List.of(document1, document2, document3, document4), new InsertManyOptions().ordered( false )); Assert.fail( "insertMany should fail" ); // session.commitTransaction(); } catch (MongoBulkWriteException e) { session.abortTransaction(); Assert.assertEquals(e.getWriteErrors().size(), 2, "Expected to have 2 dup key errors:" ); // fails here! } finally { session.close(); } }  

      Problem pretty same as in SERVER-38583

      There is only one BulkWriteError with dup key after inserting duplicated data within a transaction, even if data contain many of them.

      Problem reproduces with Mongo version 4.2.3, 4.2.10, 4.4.1. No info regarding another versions.

       

            Assignee:
            edwin.zhou@mongodb.com Edwin Zhou
            Reporter:
            dmitry.kiziloff@gmail.com Dmitry Kizilov
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: