summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCheahuychou Mao <cheahuychou.mao@mongodb.com>2020-02-24 22:48:22 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-28 19:54:40 +0000
commit0219d8e3489f7934c3eda10a18ac70de81d1e7b4 (patch)
tree9b29a85adfdf1470b84f72e8fdd2f03ca667403d /src
parentbd05da2372a83bdbe2efa1f488a893a9ea40530c (diff)
downloadmongo-0219d8e3489f7934c3eda10a18ac70de81d1e7b4.tar.gz
SERVER-9391 tailable cursors should throw an exception in DBClientCursor when a cursor is not found on the server
Diffstat (limited to 'src')
-rw-r--r--src/mongo/client/dbclient_cursor.cpp10
-rw-r--r--src/mongo/scripting/mozjs/cursor.cpp14
-rw-r--r--src/mongo/scripting/mozjs/cursor.h3
-rw-r--r--src/mongo/shell/query.js8
-rw-r--r--src/mongo/shell/utils.js1
5 files changed, 28 insertions, 8 deletions
diff --git a/src/mongo/client/dbclient_cursor.cpp b/src/mongo/client/dbclient_cursor.cpp
index 7af7d314769..77d5c802eb7 100644
--- a/src/mongo/client/dbclient_cursor.cpp
+++ b/src/mongo/client/dbclient_cursor.cpp
@@ -359,13 +359,11 @@ void DBClientCursor::dataReceived(const Message& reply, bool& retry, string& hos
// cursor id no longer valid at the server.
invariant(qr.getCursorId() == 0);
- if (!(opts & QueryOption_CursorTailable)) {
- uasserted(ErrorCodes::CursorNotFound,
- str::stream() << "cursor id " << cursorId << " didn't exist on server.");
- }
-
- // 0 indicates no longer valid (dead)
+ // 0 indicates no longer valid (dead).
cursorId = 0;
+
+ uasserted(ErrorCodes::CursorNotFound,
+ str::stream() << "cursor id " << cursorId << " didn't exist on server.");
}
if (cursorId == 0 || !(opts & QueryOption_CursorTailable)) {
diff --git a/src/mongo/scripting/mozjs/cursor.cpp b/src/mongo/scripting/mozjs/cursor.cpp
index dc6d65dfb1d..f90bcb924db 100644
--- a/src/mongo/scripting/mozjs/cursor.cpp
+++ b/src/mongo/scripting/mozjs/cursor.cpp
@@ -41,11 +41,12 @@
namespace mongo {
namespace mozjs {
-const JSFunctionSpec CursorInfo::methods[7] = {
+const JSFunctionSpec CursorInfo::methods[8] = {
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(close, CursorInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(hasNext, CursorInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(next, CursorInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(objsLeftInBatch, CursorInfo),
+ MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(getId, CursorInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(readOnly, CursorInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(isClosed, CursorInfo),
JS_FS_END,
@@ -119,6 +120,17 @@ void CursorInfo::Functions::readOnly::call(JSContext* cx, JS::CallArgs args) {
args.rval().set(args.thisv());
}
+void CursorInfo::Functions::getId::call(JSContext* cx, JS::CallArgs args) {
+ auto cursor = getCursor(args);
+
+ if (!cursor) {
+ ValueReader(cx, args.rval()).fromInt64(0);
+ return;
+ }
+
+ ValueReader(cx, args.rval()).fromInt64(cursor->getCursorId());
+}
+
void CursorInfo::Functions::close::call(JSContext* cx, JS::CallArgs args) {
auto cursor = getCursor(args);
diff --git a/src/mongo/scripting/mozjs/cursor.h b/src/mongo/scripting/mozjs/cursor.h
index 110653747e7..6aa610f80b6 100644
--- a/src/mongo/scripting/mozjs/cursor.h
+++ b/src/mongo/scripting/mozjs/cursor.h
@@ -51,9 +51,10 @@ struct CursorInfo : public BaseInfo {
MONGO_DECLARE_JS_FUNCTION(next);
MONGO_DECLARE_JS_FUNCTION(objsLeftInBatch);
MONGO_DECLARE_JS_FUNCTION(readOnly);
+ MONGO_DECLARE_JS_FUNCTION(getId);
};
- static const JSFunctionSpec methods[7];
+ static const JSFunctionSpec methods[8];
static const char* const className;
static const unsigned classFlags = JSCLASS_HAS_PRIVATE;
diff --git a/src/mongo/shell/query.js b/src/mongo/shell/query.js
index bd451166e9d..cbdbeda2929 100644
--- a/src/mongo/shell/query.js
+++ b/src/mongo/shell/query.js
@@ -328,6 +328,11 @@ DBQuery.prototype.readOnly = function() {
return this;
};
+DBQuery.prototype.getId = function() {
+ this._exec();
+ return this._cursor.getId();
+};
+
DBQuery.prototype.toArray = function() {
if (this._arr)
return this._arr;
@@ -876,6 +881,9 @@ DBCommandCursor.prototype.objsLeftInBatch = function() {
return this._cursor.objsLeftInBatch();
}
};
+DBCommandCursor.prototype.getId = function() {
+ return this._cursorid;
+};
DBCommandCursor.prototype.getResumeToken = function() {
// Return the most recent recorded resume token, if such a token exists.
return this._resumeToken;
diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js
index dcfface166e..9ae58f3910c 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -301,6 +301,7 @@ jsTestOptions = function() {
// Note: does not support the array version
mongosBinVersion: TestData.mongosBinVersion || "",
shardMixedBinVersions: TestData.shardMixedBinVersions || false,
+ mixedBinVersions: TestData.mixedBinVersions || false,
networkMessageCompressors: TestData.networkMessageCompressors,
replSetFeatureCompatibilityVersion: TestData.replSetFeatureCompatibilityVersion,
skipRetryOnNetworkError: TestData.skipRetryOnNetworkError,