summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2017-11-12 00:00:52 -0500
committerXiangyu Yao <xiangyu.yao@mongodb.com>2017-11-22 11:37:25 -0500
commit9ab80a38613917a9d4c66331c923e09f3151445a (patch)
tree6deb6bf8ac89d5a5bfe76d7acc9e374562f85f7a /src/mongo/db
parent969ddd3d921cd8e6c5ab3068fdb77cb2dc271ed5 (diff)
downloadmongo-9ab80a38613917a9d4c66331c923e09f3151445a.tar.gz
SERVER-29453 Disallow removing featureCompatibilityVersion document and renaming collection
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/commands/rename_collection_cmd.cpp7
-rw-r--r--src/mongo/db/namespace_string.h3
-rw-r--r--src/mongo/db/op_observer_impl.cpp7
-rw-r--r--src/mongo/db/repl/sync_tail_test.cpp43
4 files changed, 15 insertions, 45 deletions
diff --git a/src/mongo/db/commands/rename_collection_cmd.cpp b/src/mongo/db/commands/rename_collection_cmd.cpp
index 569907eaab2..6385dcc5d0f 100644
--- a/src/mongo/db/commands/rename_collection_cmd.cpp
+++ b/src/mongo/db/commands/rename_collection_cmd.cpp
@@ -144,6 +144,13 @@ public:
return false;
}
+ if (source.isAdminDotSystemDotVersion()) {
+ appendCommandStatus(result,
+ Status(ErrorCodes::IllegalOperation,
+ "renaming admin.system.version is not allowed"));
+ return false;
+ }
+
RenameCollectionOptions options;
options.dropTarget = cmdObj["dropTarget"].trueValue();
options.stayTemp = cmdObj["stayTemp"].trueValue();
diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h
index f110489916e..07240fa9f0a 100644
--- a/src/mongo/db/namespace_string.h
+++ b/src/mongo/db/namespace_string.h
@@ -192,6 +192,9 @@ public:
bool isSystemDotViews() const {
return coll() == kSystemDotViewsCollectionName;
}
+ bool isAdminDotSystemDotVersion() const {
+ return ((db() == "admin") && (coll() == "system.version"));
+ }
bool isConfigDB() const {
return db() == "config";
}
diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp
index 6da9b7f9599..cdc1dbc4756 100644
--- a/src/mongo/db/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer_impl.cpp
@@ -437,8 +437,11 @@ void OpObserverImpl::onDelete(OperationContext* opCtx,
Scope::storedFuncMod(opCtx);
} else if (nss.coll() == DurableViewCatalog::viewsCollectionName()) {
DurableViewCatalog::onExternalChange(opCtx, nss);
- } else if (nss.ns() == FeatureCompatibilityVersion::kCollection) {
- FeatureCompatibilityVersion::onDelete(opCtx, deleteState.documentKey);
+ } else if (nss.isAdminDotSystemDotVersion()) {
+ auto _id = deleteState.documentKey["_id"];
+ if (_id.type() == BSONType::String &&
+ _id.String() == FeatureCompatibilityVersion::kParameterName)
+ uasserted(40670, "removing FeatureCompatibilityVersion document is not allowed");
} else if (nss == NamespaceString::kSessionTransactionsTableNamespace &&
!opTime.writeOpTime.isNull()) {
SessionCatalog::get(opCtx)->invalidateSessions(opCtx, deleteState.documentKey);
diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp
index e1c83e5e89f..6f7537ee68f 100644
--- a/src/mongo/db/repl/sync_tail_test.cpp
+++ b/src/mongo/db/repl/sync_tail_test.cpp
@@ -1664,29 +1664,6 @@ TEST_F(SyncTailTest, FailOnDropFCVCollectionInRecovering) {
ASSERT_EQUALS(runOpSteadyState(op), ErrorCodes::OplogOperationUnsupported);
}
-TEST_F(SyncTailTest, FailOnDeleteFCVDocumentInRecovering) {
- auto fcvNS = NamespaceString(FeatureCompatibilityVersion::kCollection);
- CollectionOptions options;
- options.uuid = UUID::gen();
- ::mongo::repl::createCollection(_opCtx.get(), fcvNS, options);
-
- // Insert the fCV document.
- ASSERT_OK(
- ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_SECONDARY));
- auto insertCmd = BSON("_id" << FeatureCompatibilityVersion::kParameterName
- << FeatureCompatibilityVersion::kVersionField
- << FeatureCompatibilityVersionCommandParser::kVersion36);
- auto insertOp = makeInsertDocumentOplogEntry(nextOpTime(), fcvNS, insertCmd);
- ASSERT_OK(runOpSteadyState(insertOp));
-
- ASSERT_OK(
- ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_RECOVERING));
-
- auto cmd = BSON("_id" << FeatureCompatibilityVersion::kParameterName);
- auto op = makeDeleteDocumentOplogEntry(nextOpTime(), fcvNS, cmd);
- ASSERT_EQUALS(runOpSteadyState(op), ErrorCodes::OplogOperationUnsupported);
-}
-
TEST_F(SyncTailTest, SuccessOnUpdateFCV34TargetVersionUnsetDocumentInRecovering) {
auto fcvNS = NamespaceString(FeatureCompatibilityVersion::kCollection);
::mongo::repl::createCollection(_opCtx.get(), fcvNS, CollectionOptions());
@@ -1732,26 +1709,6 @@ TEST_F(SyncTailTest, SuccessOnDropFCVCollectionInSecondary) {
ASSERT_OK(runOpSteadyState(op));
}
-TEST_F(SyncTailTest, SuccessOnDeleteFCVDocumentInSecondary) {
- auto fcvNS = NamespaceString(FeatureCompatibilityVersion::kCollection);
- CollectionOptions options;
- options.uuid = UUID::gen();
- ::mongo::repl::createCollection(_opCtx.get(), fcvNS, options);
- ASSERT_OK(
- ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_SECONDARY));
-
- // Insert the fCV document.
- auto insertCmd = BSON("_id" << FeatureCompatibilityVersion::kParameterName
- << FeatureCompatibilityVersion::kVersionField
- << FeatureCompatibilityVersionCommandParser::kVersion36);
- auto insertOp = makeInsertDocumentOplogEntry(nextOpTime(), fcvNS, insertCmd);
- ASSERT_OK(runOpSteadyState(insertOp));
-
- auto cmd = BSON("_id" << FeatureCompatibilityVersion::kParameterName);
- auto op = makeDeleteDocumentOplogEntry(nextOpTime(), fcvNS, cmd);
- ASSERT_OK(runOpSteadyState(op));
-}
-
TEST_F(SyncTailTest, SuccessOnUpdateFCV34TargetVersion34DocumentInSecondary) {
auto fcvNS = NamespaceString(FeatureCompatibilityVersion::kCollection);
::mongo::repl::createCollection(_opCtx.get(), fcvNS, CollectionOptions());