summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2017-11-13 18:50:20 -0500
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2017-11-21 16:55:07 -0500
commit0c8b1e562ec785d6860c44a8fac700c69a85b023 (patch)
treed55c7b8e070ba8bfd12005a52a4dffb7ac819a4e
parent26981405f83426e94f38772a773f9e4d4e55801e (diff)
downloadmongo-0c8b1e562ec785d6860c44a8fac700c69a85b023.tar.gz
SERVER-31476 Server should prohibit establishing a cursor on a read-only view
(cherry picked from commit 60929bb3b6c8df3c620f61b09d90c14d64dd31ef)
-rw-r--r--buildscripts/resmokeconfig/suites/change_streams_secondary_reads.yml1
-rw-r--r--etc/evergreen.yml1
-rw-r--r--jstests/change_streams/change_stream_ban_from_views.js5
-rw-r--r--jstests/libs/override_methods/set_read_and_write_concerns.js3
-rw-r--r--jstests/libs/override_methods/set_read_preference_secondary.js3
-rw-r--r--src/mongo/db/commands/run_aggregate.cpp2
6 files changed, 13 insertions, 2 deletions
diff --git a/buildscripts/resmokeconfig/suites/change_streams_secondary_reads.yml b/buildscripts/resmokeconfig/suites/change_streams_secondary_reads.yml
index 25bbae3aa1f..7aec4fd772b 100644
--- a/buildscripts/resmokeconfig/suites/change_streams_secondary_reads.yml
+++ b/buildscripts/resmokeconfig/suites/change_streams_secondary_reads.yml
@@ -44,6 +44,7 @@ executor:
verbosity: 0
command: 1
query: 1
+ replication: 3
numInitialSyncAttempts: 1
num_rs_nodes_per_shard: 2
enable_sharding:
diff --git a/etc/evergreen.yml b/etc/evergreen.yml
index 4611d2151fd..0bb9e702d38 100644
--- a/etc/evergreen.yml
+++ b/etc/evergreen.yml
@@ -7351,6 +7351,7 @@ buildvariants:
- name: sharded_causally_consistent_jscore_passthrough_WT
- name: change_streams_WT
- name: change_streams_mongos_passthrough_WT
+ - name: change_streams_secondary_reads_WT
- name: change_streams_sharded_collections_passthrough_WT
- name: concurrency
- name: concurrency_WT
diff --git a/jstests/change_streams/change_stream_ban_from_views.js b/jstests/change_streams/change_stream_ban_from_views.js
index 643df54bd74..c06932e55b3 100644
--- a/jstests/change_streams/change_stream_ban_from_views.js
+++ b/jstests/change_streams/change_stream_ban_from_views.js
@@ -30,4 +30,9 @@
assert.commandFailedWithCode(
db.runCommand({collMod: normalViewName, viewOn: coll.getName(), pipeline: csPipe}),
ErrorCodes.OptionNotSupportedOnView);
+
+ // Verify change streams cannot be created on views.
+ assert.commandFailedWithCode(
+ db.runCommand({aggregate: normalViewName, pipeline: [{$changeStream: {}}], cursor: {}}),
+ ErrorCodes.CommandNotSupportedOnView);
})();
diff --git a/jstests/libs/override_methods/set_read_and_write_concerns.js b/jstests/libs/override_methods/set_read_and_write_concerns.js
index dbcbbf2bcb1..8bbf29226f2 100644
--- a/jstests/libs/override_methods/set_read_and_write_concerns.js
+++ b/jstests/libs/override_methods/set_read_and_write_concerns.js
@@ -52,6 +52,7 @@
return originalStartParallelShell(newCode, port, noConnect);
};
+ const originalRunCommand = DB.prototype._runCommandImpl;
DB.prototype._runCommandImpl = function(dbName, obj, options) {
var cmdName = "";
for (var fieldName in obj) {
@@ -178,7 +179,7 @@
}
}
- var res = this.getMongo().runCommand(dbName, obj, options);
+ var res = originalRunCommand.call(this, dbName, obj, options);
return res;
};
diff --git a/jstests/libs/override_methods/set_read_preference_secondary.js b/jstests/libs/override_methods/set_read_preference_secondary.js
index 98fbdbe4f4c..9955c7f016d 100644
--- a/jstests/libs/override_methods/set_read_preference_secondary.js
+++ b/jstests/libs/override_methods/set_read_preference_secondary.js
@@ -37,6 +37,7 @@
"parallelCollectionScan",
]);
+ const originalRunCommand = DB.prototype._runCommandImpl;
DB.prototype._runCommandImpl = function(dbName, obj, options) {
const cmdName = Object.keys(obj)[0];
@@ -62,7 +63,7 @@
}
}
- return this.getMongo().runCommand(dbName, obj, options);
+ return originalRunCommand.call(this, dbName, obj, options);
};
})();
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp
index 976fb378ed7..7c430629d9b 100644
--- a/src/mongo/db/commands/run_aggregate.cpp
+++ b/src/mongo/db/commands/run_aggregate.cpp
@@ -362,6 +362,8 @@ Status runAggregate(OperationContext* opCtx,
// of the collection on which $changeStream was invoked, so that we do not end up
// resolving the collation on the oplog.
invariant(!collatorToUse);
+ // Change streams can only be created on collections. An error will be raised in
+ // AutoGetCollection if the given namespace is a view.
AutoGetCollection origNssCtx(opCtx, origNss, MODE_IS);
Collection* origColl = origNssCtx.getCollection();
collatorToUse.emplace(resolveCollator(opCtx, request, origColl));