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

Shell bulk api hides write concern errors when there is a write error and the bulk write is 'ordered'

    • Type: Icon: Bug Bug
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • Server Development Platform
    • ALL

      It's possible for a write to fail both with a write error and a write concern error - for example if there is a duplicate key violation during an insert, we will still need to wait for write concern to ensure that the state that triggered the dup key error is visible across the majority of nodes. The shell bulk api, however, swallows write concern errors when doing an ordered bulk write if it encounters a write error. Unordered bulk writes correctly report both the write concern error and the write error.

      replset:PRIMARY> db.test1.bulkWrite([{insertOne:{document:{_id:1}}}],{ordered:true,writeConcern:{w:2,wtimeout:1000}})
      2017-04-27T16:38:39.568-0400 E QUERY    [thread1] BulkWriteError: write error at item 0 in bulk operation :
      BulkWriteError({
      	"writeErrors" : [
      		{
      			"index" : 0,
      			"code" : 11000,
      			"errmsg" : "E11000 duplicate key error collection: test.test1 index: _id_ dup key: { : 1.0 }",
      			"op" : {
      				"_id" : 1
      			}
      		}
      	],
      	"writeConcernErrors" : [ ],
      	"nInserted" : 0,
      	"nUpserted" : 0,
      	"nMatched" : 0,
      	"nModified" : 0,
      	"nRemoved" : 0,
      	"upserted" : [ ]
      })
      
      replset:PRIMARY> db.test1.bulkWrite([{insertOne:{document:{_id:1}}}],{ordered:false,writeConcern:{w:2,wtimeout:1000}})
      2017-04-27T16:38:17.558-0400 E QUERY    [thread1] BulkWriteError: write error at item 0 and problem enforcing write concern in bulk operation :
      BulkWriteError({
      	"writeErrors" : [
      		{
      			"index" : 0,
      			"code" : 11000,
      			"errmsg" : "E11000 duplicate key error collection: test.test1 index: _id_ dup key: { : 1.0 }",
      			"op" : {
      				"_id" : 1
      			}
      		}
      	],
      	"writeConcernErrors" : [
      		{
      			"code" : 64,
      			"codeName" : "WriteConcernFailed",
      			"errInfo" : {
      				"wtimeout" : true
      			},
      			"errmsg" : "waiting for replication timed out"
      		}
      	],
      	"nInserted" : 0,
      	"nUpserted" : 0,
      	"nMatched" : 0,
      	"nModified" : 0,
      	"nRemoved" : 0,
      	"upserted" : [ ]
      })
      BulkWriteError@src/mongo/shell/bulk_api.js:372:48
      BulkWriteResult/this.toError@src/mongo/shell/bulk_api.js:336:24
      Bulk/this.execute@src/mongo/shell/bulk_api.js:1173:1
      DBCollection.prototype.bulkWrite@src/mongo/shell/crud_api.js:191:20
      @(shell):1:1
      

            Assignee:
            backlog-server-devplatform [DO NOT ASSIGN] Backlog - Server Development Platform Team (SDP) (Inactive)
            Reporter:
            spencer@mongodb.com Spencer Brody (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: