[SERVER-52612] Can't use getMore or transaction-continuing commands when requireApiVersion parameter is true Created: 03/Nov/20  Updated: 29/Oct/23  Resolved: 30/Nov/20

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 4.7.0
Fix Version/s: 4.9.0

Type: Bug Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: A. Jesse Jiryu Davis
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-49377 Ensure transactions inherit API param... Closed
related to SERVER-56925 Remove requireApiVersion server param... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

I start a 4.7.0 standalone mongod like:

mongod --setParameter requireApiVersion=true

If I don’t include apiVersion: "1" in the getMore command, I get the error:

{
  “ok”: 0.0, 
  “errmsg”: “The apiVersion parameter is required, please configure your MongoClient’s API version”, 
  “code”: 498870, 
  “codeName”: “Location498870"
}

and if I do include it I get:

{
   “ok”: 0.0, 
   “errmsg”: “Cannot pass in API parameter field apiVersion”,
   “code”: 4937600, 
   “codeName”: “Location4937600"
}

According to spec the server should not accept api version in getMore commands:

The getMore command does not accept API parameters; cursors inherit their API parameters from the initiating command. 

so I expect the second error but not the first. 



 Comments   
Comment by A. Jesse Jiryu Davis [ 18/May/21 ]

Update: a few months later we reversed, getMore and transaction-continuing commands now require the same API params as the cursor/transaction-initiating command.

Comment by A. Jesse Jiryu Davis [ 02/Dec/20 ]

One more bug I found: commit/abortTransaction should ban API parameters such as apiVersion, because commit/abortTransaction are transaction-continuing commands and all transaction-continuing commands must ban API params. However, on mongos commitTransaction didn't. Fixed in a followup commit along with more testing.

Comment by Githook User [ 02/Dec/20 ]

Author:

{'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com', 'username': 'ajdavis'}

Message: SERVER-52612 Test requireApiVersion with txn commit/abort
Branch: master
https://github.com/mongodb/mongo/commit/7da20590e81e8e9396d4a9771698ff689c2308ef

Comment by Githook User [ 30/Nov/20 ]

Author:

{'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com', 'username': 'ajdavis'}

Message: SERVER-52612 Fix requireApiVersion for getMore and transactions
Branch: master
https://github.com/mongodb/mongo/commit/d498981d509964a6540e2064ea7c0bda7b5fd77b

Comment by Jeffrey Yemin [ 25/Nov/20 ]

They do, I just recalled incorrectly that I had run the tests against a replica set. I can confirm now that most transaction spec tests fail when requireApiVersion is on.

Good catch. Thanks!

Comment by A. Jesse Jiryu Davis [ 25/Nov/20 ]

Transaction-continuing commands seem to have the same problem. Run "mongo --nodb" and paste:

var rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();
 
primary = rst.getPrimary();
assert.commandWorked(primary.getDB("test").runCommand({insert: "collection", documents: [{}, {}, {}]}));
assert.commandWorked(primary.getDB("admin").runCommand({setParameter: 1, requireApiVersion: true}));
 
session = primary.startSession({causalConsistency: false});
sessionDb = session.getDatabase("test");
reply = sessionDb.runCommand({
    find: "collection",
    batchSize: 1,
    apiVersion: "1",
    txnNumber: NumberLong(0),
    stmtId: NumberInt(0),
    startTransaction: true,
    autocommit: false
});
assert.commandWorked(reply);
assert.commandWorked(sessionDb.runCommand({
    getMore: reply.cursor.id,
    collection: "collection",
    txnNumber: NumberLong(0),
    stmtId: NumberInt(1),
    autocommit: false
}));
assert.commandWorked(sessionDb.runCommand({
    find: "collection",
    batchSize: 1,
    txnNumber: NumberLong(0),
    stmtId: NumberInt(2),
    autocommit: false
}));

The last two commands should succeed, but on master #5f72078a both fail with "The apiVersion parameter is required, please configure your MongoClient's API version". This might be a testing gap. Do the the transaction spec tests cover transaction-continuing commands?

Comment by Jeffrey Yemin [ 24/Nov/20 ]

jesse definitely that should be tested, but iirc I ran all of our txn spec tests against a server configured this way, and they pass.

Comment by A. Jesse Jiryu Davis [ 24/Nov/20 ]

I wonder if we made the same mistake with transaction-continuing commands.

Comment by Jeffrey Yemin [ 04/Nov/20 ]

Simple repro in the shell:

MongoDB Enterprise > db.test.insert({})
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise > db.test.insert({})
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise > db.test.insert({})
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise > db.test.find().batchSize(1)
{ "_id" : ObjectId("5fa2a31be47b78dd209c5330") }
Error: command failed: {
	"ok" : 0,
	"errmsg" : "Cannot pass in API parameter field apiVersion",
	"code" : 4937600,
	"codeName" : "Location4937600"
} : getMore command failed: {
	"ok" : 0,
	"errmsg" : "Cannot pass in API parameter field apiVersion",
	"code" : 4937600,
	"codeName" : "Location4937600"
}

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