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

Transactional bulkWrite error missing writeErrors (mongod)

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1.9
    • Affects Version/s: 4.0.4
    • Component/s: Replication, Write Ops
    • Labels:
      None
    • Major Change
    • ALL
    • v4.0
    • Hide

      Start a 3 node replset

      mlaunch init --replicaset --nodes 3 --binarypath $(m bin 4.0.4-ent) --port ${port}
      

      I'm using the following test code

      db.dropDatabase();
      db.createCollection("c");
      session = db.getMongo().startSession();
      try {
          session.startTransaction();
          coll = session.getDatabase("test").c;
          try {
              coll.bulkWrite([
                  { insertOne : { "document" : { _id: 1, v: 1} } },
                  { insertOne : { "document" : { _id: 2, v: 1} } },
                  { insertOne : { "document" : { _id: 1, v: 1} } }
              ]);
          } 
          catch (error) {
              print("Operation exception, aborting txn...");
              print(error.stack);
              session.abortTransaction();
              throw error;
          }
          session.commitTransaction(); // Uses write concern set at transaction start.
      }
      catch (error) {
          print("Transaction exception");
          print(error);
      }
      finally {
          session.endSession();
      }
      
      Show
      Start a 3 node replset mlaunch init --replicaset --nodes 3 --binarypath $(m bin 4.0.4-ent) --port ${port} I'm using the following test code db.dropDatabase(); db.createCollection( "c" ); session = db.getMongo().startSession(); try { session.startTransaction(); coll = session.getDatabase( "test" ).c; try { coll.bulkWrite([ { insertOne : { "document" : { _id: 1, v: 1} } }, { insertOne : { "document" : { _id: 2, v: 1} } }, { insertOne : { "document" : { _id: 1, v: 1} } } ]); } catch (error) { print( "Operation exception, aborting txn..." ); print(error.stack); session.abortTransaction(); throw error; } session.commitTransaction(); // Uses write concern set at transaction start. } catch (error) { print( "Transaction exception" ); print(error); } finally { session.endSession(); }
    • Repl 2019-01-14, Repl 2019-01-28, Repl 2019-02-11, Repl 2019-02-25

      Testing the bulkWrite DUP Key example from https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#bulk-write-operations in a transaction I can't find the writeErrors array in the result.

      Server: 4.0.4-ent

      WriteCommandError({
      	"operationTime" : Timestamp(1544613730, 3),
      	"ok" : 0,
      	"errmsg" : "E11000 duplicate key error collection: test.c index: _id_ dup key: { : 1.0 }",
      	"code" : 11000,
      	"codeName" : "DuplicateKey",
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1544613730, 3),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	}
      })
      

      Thinking that perhaps this is a client side issue I looked at the wire protocol response and I don't see it there either

      sudo tshark -nQ -i lo0 --enable-protocol "MONGO" -f "portrange 12108-12110" -Y "mongo.opcode==2013" -d "tcp.port==12108-12110,mongo" -t u -T json
      
                "mongo.msg.sections.section": {
                  "mongo.msg.sections.section.kind": "0",
                  "mongo.msg.sections.section.body": {
                    "mongo.document.length": "268",
                    "mongo.elements": {
                      "mongo.element.name": "operationTime",
                      "mongo.element.name_tree": {
                        "mongo.element.type": "0x00000011",
                        "mongo.element.value.int64": "6634065455302574083"
                      },
                      "mongo.element.name": "ok",
                      "mongo.element.name_tree": {
                        "mongo.element.type": "0x00000001",
                        "mongo.element.value.double": "0"
                      },
                      "mongo.element.name": "errmsg",
                      "mongo.element.name_tree": {
                        "mongo.element.type": "0x00000002",
                        "mongo.element.value.length": "77",
                        "mongo.element.value.string": "E11000 duplicate key error collection: test.c index: _id_ dup key: { : 1.0 }"
                      },
                      "mongo.element.name": "code",
                      "mongo.element.name_tree": {
                        "mongo.element.type": "0x00000010",
                        "mongo.element.value.int": "11000"
                      },
                      "mongo.element.name": "codeName",
                      "mongo.element.name_tree": {
                        "mongo.element.type": "0x00000002",
                        "mongo.element.value.length": "13",
                        "mongo.element.value.string": "DuplicateKey"
                      },
                      "mongo.element.name": "$clusterTime",
                      "mongo.element.name_tree": {
                        "mongo.element.type": "0x00000003",
                        "mongo.document": {
                          "mongo.document.length": "88",
                          "mongo.elements": {
                            "mongo.element.name": "clusterTime",
                            "mongo.element.name_tree": {
                              "mongo.element.type": "0x00000011",
                              "mongo.element.value.int64": "6634065455302574083"
                            },
                            "mongo.element.name": "signature",
                            "mongo.element.name_tree": {
                              "mongo.element.type": "0x00000003",
                              "mongo.document": {
                                "mongo.document.length": "51",
                                "mongo.elements": {
                                  "mongo.element.name": "hash",
                                  "mongo.element.name_tree": {
                                    "mongo.element.type": "0x00000005",
                                    "mongo.element.value.length": "20",
                                    "mongo.element.value.bytes": "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"
                                  },
                                  "mongo.element.name": "keyId",
                                  "mongo.element.name_tree": {
                                    "mongo.element.type": "0x00000012",
                                    "mongo.element.value.int64": "0"
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
      

      How do I identify failed items?

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            vick.mena Vick Mena (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: