[SERVER-11674] Write command write concerns parameter w should be validated >= 0 Created: 13/Nov/13  Updated: 06/Dec/22  Resolved: 02/Feb/20

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.5.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Christian Amor Kvalheim Assignee: Backlog - Replication Team
Resolution: Duplicate Votes: 0
Labels: 26qa, neweng, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-45920 Validate writeConcern.w Closed
Related
Assigned Teams:
Replication
Operating System: ALL
Steps To Reproduce:

//
// Ensures that mongod respects the batch write protocols
//
 
var collectionName = "batch_write_protocol";
var coll = db.getCollection(collectionName);
 
jsTest.log("Starting insert tests...");
 
coll.remove({});
 
var request;
var result;
 
// Drop collection
coll.dropIndexes();
coll.drop();
 
request = {insert : collectionName, documents: [{a:1}], writeConcern:{w:-100}, ordered:true};
result = coll.runCommand(request)
assert.eq(0, result.ok);
assert.eq('number', typeof result.code);
assert.eq('string', typeof result.errmsg);
 
request = {update : collectionName, updates: [
	{q: {a:1}, u: {$set: {a:1}}, upsert:true}
], writeConcern:{w:-100}, ordered:true};
result = coll.runCommand(request)
assert.eq(0, result.ok);
assert.eq('number', typeof result.code);
assert.eq('string', typeof result.errmsg);
 
request = {delete : collectionName, deletes: [
	{q:{a:1}, limit:0}
], writeConcern:{w:-100}, ordered:true};
result = coll.runCommand(request)
assert.eq(0, result.ok);
assert.eq('number', typeof result.code);
assert.eq('string', typeof result.errmsg);

Participants:

 Description   

When using a write command with write concern w it allows for negative values. They seem to be ignored. Not sure this is expected behavior.



 Comments   
Comment by Sheeri Cabral (Inactive) [ 22/Oct/19 ]

I didn't investigate! This was a simple test on my laptop in a VirtualBox environment. I have re-created the test environment and the same data with the same tests:

On a 3-node replica set, I tried writeConcern values of: majority, 1, 2,3, 4, 0, -1, -2, -2147483648, -2147483649, 2147483648, 2147483649, -2147483647 and 2147483647.

The results:

Everything was accepted and wrote a value 0 (gave null writeResult), and 4 and 2147483647 gave "not enough data-bearing nodes"). No timeout this time.

 

 

"opWriteConcernCounters" : {
 "insert" : {
 "wmajority" : NumberLong(1),
 "wnum" : {
 "-2147483648" : NumberLong(4),
 "-2147483647" : NumberLong(1),
 "-2" : NumberLong(1),
 "-1" : NumberLong(1),
 "0" : NumberLong(1),
 "1" : NumberLong(1),
 "2" : NumberLong(1),
 "3" : NumberLong(1),
 "4" : NumberLong(1),
 "2147483647" : NumberLong(1)
 },
 

 

 

Comment by Judah Schvimer [ 18/Oct/19 ]

One clarification question: you said w:3 timed out. Had you stopped one of the three nodes in the set? Why did it time out?

Comment by Sheeri Cabral (Inactive) [ 18/Oct/19 ]

On a 3-node replica set, I tried writeConcern values of: majority, 1, 2,3, 4, 0, -1, -2, -2147483648, -2147483649, 2147483648, 2147483649, -2147483647 and 2147483647.

The results:

Everything was accepted and wrote a value except 3 (timed out) and 0 (gave null writeResult), and 4 and 2147483647 gave "not enough data-bearing nodes") (I also tried other values from 2147483640-2147483646 and got the same error). So it looks like, up to a point, it just says "not enough data bearing nodes" and after that it 

 

 
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: "majority", wtimeout: 5000 } } )
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: 1, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1 }) 
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: 2, wtimeout: 5000 } } )
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: 3, wtimeout: 5000 } } )
WriteResult({
 "nInserted" : 1,
 "writeConcernError" : {
 "code" : 64,
 "codeName" : "WriteConcernFailed",
 "errInfo" : {
 "wtimeout" : true
 },
 "errmsg" : "waiting for replication timed out"
 }
})
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: 4, wtimeout: 5000 } } )
WriteResult({
	"nInserted" : 1,
	"writeConcernError" : {
		"code" : 100,
		"codeName" : "CannotSatisfyWriteConcern",
		"errmsg" : "Not enough data-bearing nodes"
	}
})
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: 0, wtimeout: 5000 } } )
WriteResult({ })
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: -1, wtimeout: 5000 } } )
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: -2, wtimeout: 5000 } } )
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: -2147483648, wtimeout: 5000 } } )
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: -2147483649, wtimeout: 5000 } } )
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: 2147483649, wtimeout: 5000 } } )
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: 2147483648, wtimeout: 5000 } } )
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: 2147483647, wtimeout: 5000 } } )
WriteResult({
	"nInserted" : 1,
	"writeConcernError" : {
		"code" : 100,
		"codeName" : "CannotSatisfyWriteConcern",
		"errmsg" : "Not enough data-bearing nodes"
	}
})
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: -2147483647, wtimeout: 5000 } } )
WriteResult({ "nInserted" : 1 }

 

 

And db.serverStatus() shows:

 

	"opWriteConcernCounters" : {
		"insert" : {
			"wmajority" : NumberLong(775177),
			"wnum" : {
				"-2147483648" : NumberLong(4),
				"-2" : NumberLong(1),
				"-1" : NumberLong(1),
				"0" : NumberLong(1),
				"1" : NumberLong(1),
				"2" : NumberLong(1),
				"3" : NumberLong(1)
			},
			"wtag" : {
				
			},
			"none" : NumberLong(8)
		},

 

I also tried 'majority' without quotes, "y", "" and null to see what I'd get - and all except "" had an error, though different ones:

 

MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: majority, wtimeout: 5000 } } ) 2019-10-18T15:08:01.775+0000 E QUERY    [thread1] ReferenceError: majority is not defined : @(shell):1:96 
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: "y", wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1, "writeConcernError" : { "code" : 79, "codeName" : "UnknownReplWriteConcern", "errmsg" : "No write concern mode named 'y' found in replica set configuration" } })
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: , wtimeout: 5000 } } ) 2019-10-18T15:15:46.400+0000 E QUERY    [thread1] SyntaxError: expected expression, got ',' @(shell):1:98 
MongoDB Enterprise m103-repl:PRIMARY> db.products.insert(     { item: "envelopes", qty : 100, type: "Clasp" },     { writeConcern: { w: "", wtimeout: 5000 } } ) WriteResult({ })

 

 

Here's the output from opWriteConcernCounters:

	"opWriteConcernCounters" : {
		"insert" : {
			"wmajority" : NumberLong(775177),
			"wnum" : {
				"-2147483648" : NumberLong(4),
				"-2147483647" : NumberLong(1),
				"-2147483646" : NumberLong(1),
				"-2147483640" : NumberLong(1),
				"-2" : NumberLong(1),
				"-1" : NumberLong(1),
				"0" : NumberLong(2),
				"1" : NumberLong(1),
				"2" : NumberLong(1),
				"3" : NumberLong(1),
				"4" : NumberLong(1),
				"2147483640" : NumberLong(1),
				"2147483641" : NumberLong(1),
				"2147483645" : NumberLong(1),
				"2147483647" : NumberLong(1)
			},

Everything is reflected there - even the writes that had an error. Note that 0 has 2 values, which were from 0 and "", and -2147483648 has 4 values, which correspond to a writeConcern of:

-2147483648

-2147483649

2147483648

2147483649

 

 

Comment by Judah Schvimer [ 25/Apr/16 ]

This still exists. The write commands accept write concern project did not modify any of the writeConcern parsing or validation.

Comment by Ian Whalen (Inactive) [ 25/Apr/16 ]

judah.schvimer can you confirm whether or not this is still an issue?

Generated at Thu Feb 08 03:26:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.