Skip to content

Commit b9c13fa

Browse files
lankasevergreen
authored andcommitted
SERVER-43698 Don't allow atClusterTime whwere number of seconds in Timestamp is 0
1 parent d93b7e6 commit b9c13fa

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

jstests/noPassthrough/readConcern_atClusterTime.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ session.startTransaction({readConcern: {level: "snapshot", atClusterTime: "bad"}
5656
assert.commandFailedWithCode(sessionDb.runCommand({find: collName}), ErrorCodes.TypeMismatch);
5757
assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
5858

59+
// 'atClusterTime' cannot specify a null Timestamp.
60+
session.startTransaction({readConcern: {level: "snapshot", atClusterTime: Timestamp(0, 0)}});
61+
assert.commandFailedWithCode(sessionDb.runCommand({find: collName}), ErrorCodes.InvalidOptions);
62+
assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
63+
64+
// 'atClusterTime' cannot specify a Timestamp with zero seconds.
65+
session.startTransaction({readConcern: {level: "snapshot", atClusterTime: Timestamp(0, 1)}});
66+
assert.commandFailedWithCode(sessionDb.runCommand({find: collName}), ErrorCodes.InvalidOptions);
67+
assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction);
68+
5969
// 'atClusterTime' cannot be used with readConcern level 'majority'.
6070
session.startTransaction({readConcern: {level: "majority", atClusterTime: clusterTime}});
6171
assert.commandFailedWithCode(sessionDb.runCommand({find: collName}), ErrorCodes.InvalidOptions);

src/mongo/db/repl/read_concern_args.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,17 @@ Status ReadConcernArgs::parse(const BSONObj& readConcernObj) {
220220
<< kLevelFieldName << " is equal to " << kSnapshotReadConcernStr);
221221
}
222222

223-
if (_afterClusterTime && _afterClusterTime == LogicalTime::kUninitialized) {
223+
// Make sure that atClusterTime wasn't specified with zero seconds.
224+
if (_atClusterTime && _atClusterTime->asTimestamp().isNull()) {
224225
return Status(ErrorCodes::InvalidOptions,
225-
str::stream() << kAfterClusterTimeFieldName << " cannot be a null timestamp");
226+
str::stream() << kAtClusterTimeFieldName << " cannot be a null timestamp");
226227
}
227228

228-
if (_atClusterTime && _atClusterTime == LogicalTime::kUninitialized) {
229+
// It's okay for afterClusterTime to be specified with zero seconds, but not an uninitialized
230+
// timestamp.
231+
if (_afterClusterTime && _afterClusterTime == LogicalTime::kUninitialized) {
229232
return Status(ErrorCodes::InvalidOptions,
230-
str::stream() << kAtClusterTimeFieldName << " cannot be a null timestamp");
233+
str::stream() << kAfterClusterTimeFieldName << " cannot be a null timestamp");
231234
}
232235

233236
return Status::OK();

0 commit comments

Comments
 (0)