summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorYu Jin Kang Park <yujin.kang@mongodb.com>2022-09-02 13:17:57 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-08 16:49:10 +0000
commit17dc0a48233b4c7c6e95b43236f0fc8dba2d3b4e (patch)
treeb4cade7072a3b633acd8540139981f33a76341e6 /src/mongo
parent000691a65de1ba61fca5bf81316cdd146fbd20e4 (diff)
downloadmongo-17dc0a48233b4c7c6e95b43236f0fc8dba2d3b4e.tar.gz
SERVER-67893 Add _shardsvrDropGlobalIndex command
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/auth/auth_op_observer.h4
-rw-r--r--src/mongo/db/free_mon/free_mon_op_observer.h4
-rw-r--r--src/mongo/db/global_index.cpp60
-rw-r--r--src/mongo/db/global_index.h6
-rw-r--r--src/mongo/db/op_observer/fcv_op_observer.h4
-rw-r--r--src/mongo/db/op_observer/op_observer.h4
-rw-r--r--src/mongo/db/op_observer/op_observer_impl.cpp44
-rw-r--r--src/mongo/db/op_observer/op_observer_impl.h4
-rw-r--r--src/mongo/db/op_observer/op_observer_noop.h4
-rw-r--r--src/mongo/db/op_observer/op_observer_registry.h8
-rw-r--r--src/mongo/db/op_observer/user_write_block_mode_op_observer.h4
-rw-r--r--src/mongo/db/repl/oplog.cpp6
-rw-r--r--src/mongo/db/repl/oplog_entry.cpp2
-rw-r--r--src/mongo/db/repl/oplog_entry.h1
-rw-r--r--src/mongo/db/repl/primary_only_service_op_observer.h4
-rw-r--r--src/mongo/db/repl/rollback_impl.cpp1
-rw-r--r--src/mongo/db/repl/rs_rollback.cpp1
-rw-r--r--src/mongo/db/repl/tenant_migration_donor_op_observer.h4
-rw-r--r--src/mongo/db/repl/tenant_migration_recipient_op_observer.h4
-rw-r--r--src/mongo/db/s/SConscript1
-rw-r--r--src/mongo/db/s/config_server_op_observer.h4
-rw-r--r--src/mongo/db/s/range_deleter_service_op_observer.h4
-rw-r--r--src/mongo/db/s/resharding/resharding_op_observer.h4
-rw-r--r--src/mongo/db/s/shard_server_op_observer.h4
-rw-r--r--src/mongo/db/s/shardsvr_drop_global_index_command.cpp108
-rw-r--r--src/mongo/db/serverless/shard_split_donor_op_observer.h4
-rw-r--r--src/mongo/idl/cluster_server_parameter_op_observer.h4
-rw-r--r--src/mongo/s/request_types/sharded_ddl_commands.idl10
28 files changed, 291 insertions, 21 deletions
diff --git a/src/mongo/db/auth/auth_op_observer.h b/src/mongo/db/auth/auth_op_observer.h
index 34e945a9e96..642425f62e5 100644
--- a/src/mongo/db/auth/auth_op_observer.h
+++ b/src/mongo/db/auth/auth_op_observer.h
@@ -49,6 +49,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/free_mon/free_mon_op_observer.h b/src/mongo/db/free_mon/free_mon_op_observer.h
index 3473e333b5f..fbc9d56f1ef 100644
--- a/src/mongo/db/free_mon/free_mon_op_observer.h
+++ b/src/mongo/db/free_mon/free_mon_op_observer.h
@@ -49,6 +49,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/global_index.cpp b/src/mongo/db/global_index.cpp
index 4cc53b5d9a8..9e83aba0280 100644
--- a/src/mongo/db/global_index.cpp
+++ b/src/mongo/db/global_index.cpp
@@ -48,22 +48,32 @@
namespace mongo::global_index {
-
-void createContainer(OperationContext* opCtx, const UUID& indexUUID) {
- // StmtId will always be 0, as the command only replicates a createGlobalIndex oplog entry.
+namespace { // Anonymous namespace for private functions.
+bool checkRetryableDDLStatementExecuted(OperationContext* opCtx) {
+ // StmtId will always be 0, as the ddl commands only replicate a
+ // createGlobalIndex/dropGlobalIndex oplog entry.
constexpr StmtId stmtId = 0;
if (opCtx->isRetryableWrite()) {
const auto txnParticipant = TransactionParticipant::get(opCtx);
if (txnParticipant.checkStatementExecuted(opCtx, stmtId)) {
RetryableWritesStats::get(opCtx)->incrementRetriedCommandsCount();
RetryableWritesStats::get(opCtx)->incrementRetriedStatementsCount();
- LOGV2_DEBUG(6789203,
- 1,
- "_shardsvrCreateGlobalIndex retried statement already executed",
- "indexUUID"_attr = indexUUID);
- return;
+ return true;
}
}
+ return false;
+}
+} // namespace
+
+
+void createContainer(OperationContext* opCtx, const UUID& indexUUID) {
+ if (checkRetryableDDLStatementExecuted(opCtx)) {
+ LOGV2_DEBUG(6789203,
+ 1,
+ "_shardsvrCreateGlobalIndex retried statement already executed",
+ "indexUUID"_attr = indexUUID);
+ return;
+ }
const auto nss = NamespaceString::makeGlobalIndexNSS(indexUUID);
LOGV2(6789200, "Create global index container", "indexUUID"_attr = indexUUID);
@@ -122,6 +132,40 @@ void createContainer(OperationContext* opCtx, const UUID& indexUUID) {
});
}
+void dropContainer(OperationContext* opCtx, const UUID& indexUUID) {
+ if (checkRetryableDDLStatementExecuted(opCtx)) {
+ LOGV2_DEBUG(6789303,
+ 1,
+ "_shardsvrDropGlobalIndex retried statement already executed",
+ "indexUUID"_attr = indexUUID);
+ return;
+ }
+
+ const auto nss = NamespaceString::makeGlobalIndexNSS(indexUUID);
+ LOGV2(6789300, "Drop global index container", "indexUUID"_attr = indexUUID);
+
+ // Drop the container.
+ return writeConflictRetry(opCtx, "dropGlobalIndexContainer", nss.ns(), [&]() {
+ AutoGetCollection autoColl(opCtx, nss, MODE_X);
+ if (!CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss)) {
+ // Idempotent command, return OK if the collection is non-existing.
+ return;
+ }
+
+ WriteUnitOfWork wuow(opCtx);
+ {
+ repl::UnreplicatedWritesBlock unreplicatedWrites(opCtx);
+ uassertStatusOK(autoColl.getDb()->dropCollection(opCtx, nss));
+ }
+
+ auto opObserver = opCtx->getServiceContext()->getOpObserver();
+ opObserver->onDropGlobalIndex(opCtx, nss, indexUUID);
+
+ wuow.commit();
+ return;
+ });
+}
+
void insertKey(OperationContext* opCtx,
const UUID& indexUUID,
const BSONObj& key,
diff --git a/src/mongo/db/global_index.h b/src/mongo/db/global_index.h
index 82fbec7187d..dcfa1a29871 100644
--- a/src/mongo/db/global_index.h
+++ b/src/mongo/db/global_index.h
@@ -45,6 +45,12 @@ namespace mongo::global_index {
void createContainer(OperationContext* opCtx, const UUID& indexUUID);
/**
+ * Drops the internal collection acting as the global index container with the given UUID on the
+ * shard. Replicates as a 'dropGlobalIndex' command.
+ */
+void dropContainer(OperationContext* opCtx, const UUID& indexUUID);
+
+/**
* Inserts a key into the global index container identified by UUID. Replicates as an 'xi' command.
* - 'key' is the unique index key.
* - 'docKey' is the document key of the index entry.
diff --git a/src/mongo/db/op_observer/fcv_op_observer.h b/src/mongo/db/op_observer/fcv_op_observer.h
index 5976aeee4ea..f3852faa4b4 100644
--- a/src/mongo/db/op_observer/fcv_op_observer.h
+++ b/src/mongo/db/op_observer/fcv_op_observer.h
@@ -74,6 +74,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/op_observer/op_observer.h b/src/mongo/db/op_observer/op_observer.h
index 66e0ed1bfee..5756ad47af7 100644
--- a/src/mongo/db/op_observer/op_observer.h
+++ b/src/mongo/db/op_observer/op_observer.h
@@ -127,6 +127,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) = 0;
+ virtual void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) = 0;
+
virtual void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/op_observer/op_observer_impl.cpp b/src/mongo/db/op_observer/op_observer_impl.cpp
index 638f1ed4ead..da1330a81bc 100644
--- a/src/mongo/db/op_observer/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer/op_observer_impl.cpp
@@ -364,19 +364,16 @@ bool shouldTimestampIndexBuildSinglePhase(OperationContext* opCtx, const Namespa
return true;
}
-} // namespace
-
-OpObserverImpl::OpObserverImpl(std::unique_ptr<OplogWriter> oplogWriter)
- : _oplogWriter(std::move(oplogWriter)) {}
-
-void OpObserverImpl::onCreateGlobalIndex(OperationContext* opCtx,
- const NamespaceString& globalIndexNss,
- const UUID& globalIndexUUID) {
+void logGlobalIndexDDLOperation(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID,
+ const StringData commandString,
+ OplogWriter* oplogWriter) {
invariant(!opCtx->inMultiDocumentTransaction());
BSONObjBuilder builder;
// The rollback implementation requires the collection name to list affected namespaces.
- builder.append("createGlobalIndex", globalIndexNss.coll());
+ builder.append(commandString, globalIndexNss.coll());
MutableOplogEntry oplogEntry;
oplogEntry.setOpType(repl::OpTypeEnum::kCommand);
@@ -388,13 +385,13 @@ void OpObserverImpl::onCreateGlobalIndex(OperationContext* opCtx,
if (TransactionParticipant::get(opCtx)) {
// This is a retryable write: populate the lsid, txnNumber and stmtId fields.
// The oplog link to previous statement is empty and the stmtId is zero because this is a
- // single-statement command replicating as a single createGlobalIndex oplog entry.
+ // single-statement command replicating as a single createGlobalIndex/dropGlobalIndex oplog
+ // entry.
repl::OplogLink oplogLink;
- _oplogWriter->appendOplogEntryChainInfo(opCtx, &oplogEntry, &oplogLink, {stmtId});
+ oplogWriter->appendOplogEntryChainInfo(opCtx, &oplogEntry, &oplogLink, {stmtId});
}
- auto writeOpTime =
- logOperation(opCtx, &oplogEntry, true /*assignWallClockTime*/, _oplogWriter.get());
+ auto writeOpTime = logOperation(opCtx, &oplogEntry, true /*assignWallClockTime*/, oplogWriter);
// Register the retryable write to in-memory transactions table.
SessionTxnRecord sessionTxnRecord;
@@ -403,6 +400,27 @@ void OpObserverImpl::onCreateGlobalIndex(OperationContext* opCtx,
onWriteOpCompleted(opCtx, {stmtId}, sessionTxnRecord);
}
+} // namespace
+
+OpObserverImpl::OpObserverImpl(std::unique_ptr<OplogWriter> oplogWriter)
+ : _oplogWriter(std::move(oplogWriter)) {}
+
+void OpObserverImpl::onCreateGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) {
+ constexpr StringData commandString = "createGlobalIndex"_sd;
+ logGlobalIndexDDLOperation(
+ opCtx, globalIndexNss, globalIndexUUID, commandString, _oplogWriter.get());
+}
+
+void OpObserverImpl::onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) {
+ constexpr StringData commandString = "dropGlobalIndex"_sd;
+ logGlobalIndexDDLOperation(
+ opCtx, globalIndexNss, globalIndexUUID, commandString, _oplogWriter.get());
+}
+
void OpObserverImpl::onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/op_observer/op_observer_impl.h b/src/mongo/db/op_observer/op_observer_impl.h
index d1f5f9348e7..8509c2db14d 100644
--- a/src/mongo/db/op_observer/op_observer_impl.h
+++ b/src/mongo/db/op_observer/op_observer_impl.h
@@ -57,6 +57,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final;
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final;
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/op_observer/op_observer_noop.h b/src/mongo/db/op_observer/op_observer_noop.h
index d162bdd2049..6a1db4c2578 100644
--- a/src/mongo/db/op_observer/op_observer_noop.h
+++ b/src/mongo/db/op_observer/op_observer_noop.h
@@ -39,6 +39,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/op_observer/op_observer_registry.h b/src/mongo/db/op_observer/op_observer_registry.h
index 8686140e373..616246726f9 100644
--- a/src/mongo/db/op_observer/op_observer_registry.h
+++ b/src/mongo/db/op_observer/op_observer_registry.h
@@ -66,6 +66,14 @@ public:
o->onCreateGlobalIndex(opCtx, globalIndexNss, globalIndexUUID);
};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final {
+ ReservedTimes times{opCtx};
+ for (auto& o : _observers)
+ o->onDropGlobalIndex(opCtx, globalIndexNss, globalIndexUUID);
+ };
+
void onCreateIndex(OperationContext* const opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/op_observer/user_write_block_mode_op_observer.h b/src/mongo/db/op_observer/user_write_block_mode_op_observer.h
index 7a4f49ddc31..53676ef3fde 100644
--- a/src/mongo/db/op_observer/user_write_block_mode_op_observer.h
+++ b/src/mongo/db/op_observer/user_write_block_mode_op_observer.h
@@ -159,6 +159,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
// Index builds committing can be left unchecked since we kill any active index builds before
// enabling write blocking. This means any index build which gets to the commit phase while
// write blocking is active was started and hit the onStartIndexBuild hook with write blocking
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 7ae35aaa875..be4cc5863b4 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -1111,6 +1111,12 @@ const StringMap<ApplyOpMetadata> kOpsMap = {
global_index::createContainer(opCtx, globalIndexUUID);
return Status::OK();
}}},
+ {"dropGlobalIndex",
+ {[](OperationContext* opCtx, const OplogEntry& entry, OplogApplication::Mode mode) -> Status {
+ const auto& globalIndexUUID = entry.getUuid().get();
+ global_index::dropContainer(opCtx, globalIndexUUID);
+ return Status::OK();
+ }}},
};
// Writes a change stream pre-image 'preImage' associated with oplog entry 'oplogEntry' and a write
diff --git a/src/mongo/db/repl/oplog_entry.cpp b/src/mongo/db/repl/oplog_entry.cpp
index 0d7d31e610d..b4a40cd5a52 100644
--- a/src/mongo/db/repl/oplog_entry.cpp
+++ b/src/mongo/db/repl/oplog_entry.cpp
@@ -165,6 +165,8 @@ DurableOplogEntry::CommandType parseCommandType(const BSONObj& objectField) {
return DurableOplogEntry::CommandType::kImportCollection;
} else if (commandString == "createGlobalIndex") {
return DurableOplogEntry::CommandType::kCreateGlobalIndex;
+ } else if (commandString == "dropGlobalIndex") {
+ return DurableOplogEntry::CommandType::kDropGlobalIndex;
} else if (commandString == "xi") {
return DurableOplogEntry::CommandType::kInsertGlobalIndexKey;
} else {
diff --git a/src/mongo/db/repl/oplog_entry.h b/src/mongo/db/repl/oplog_entry.h
index 14f7e767597..07c63bb58b7 100644
--- a/src/mongo/db/repl/oplog_entry.h
+++ b/src/mongo/db/repl/oplog_entry.h
@@ -464,6 +464,7 @@ public:
kAbortTransaction,
kImportCollection,
kCreateGlobalIndex,
+ kDropGlobalIndex,
kInsertGlobalIndexKey,
};
diff --git a/src/mongo/db/repl/primary_only_service_op_observer.h b/src/mongo/db/repl/primary_only_service_op_observer.h
index 44bc189f5ea..ff545888e7e 100644
--- a/src/mongo/db/repl/primary_only_service_op_observer.h
+++ b/src/mongo/db/repl/primary_only_service_op_observer.h
@@ -51,6 +51,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp
index 93bba2fdc5b..5c0f74b225c 100644
--- a/src/mongo/db/repl/rollback_impl.cpp
+++ b/src/mongo/db/repl/rollback_impl.cpp
@@ -432,6 +432,7 @@ StatusWith<std::set<NamespaceString>> RollbackImpl::_namespacesForOp(const Oplog
return Status(ErrorCodes::UnrecoverableRollbackError, message);
}
case OplogEntry::CommandType::kCreateGlobalIndex:
+ case OplogEntry::CommandType::kDropGlobalIndex:
case OplogEntry::CommandType::kCreate:
case OplogEntry::CommandType::kDrop:
case OplogEntry::CommandType::kImportCollection:
diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp
index 81f4725a695..c652807fb08 100644
--- a/src/mongo/db/repl/rs_rollback.cpp
+++ b/src/mongo/db/repl/rs_rollback.cpp
@@ -355,6 +355,7 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
fixUpInfo.collectionsToDrop.insert(*uuid);
return Status::OK();
}
+ case OplogEntry::CommandType::kDropGlobalIndex:
case OplogEntry::CommandType::kDrop: {
// Example drop collection oplog entry
// {
diff --git a/src/mongo/db/repl/tenant_migration_donor_op_observer.h b/src/mongo/db/repl/tenant_migration_donor_op_observer.h
index 97f23419942..2dcf00e06cb 100644
--- a/src/mongo/db/repl/tenant_migration_donor_op_observer.h
+++ b/src/mongo/db/repl/tenant_migration_donor_op_observer.h
@@ -49,6 +49,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/repl/tenant_migration_recipient_op_observer.h b/src/mongo/db/repl/tenant_migration_recipient_op_observer.h
index a7cedb3f808..a83b97e9bb5 100644
--- a/src/mongo/db/repl/tenant_migration_recipient_op_observer.h
+++ b/src/mongo/db/repl/tenant_migration_recipient_op_observer.h
@@ -50,6 +50,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index 0ea097e9e61..2a988b0879b 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -454,6 +454,7 @@ env.Library(
'shardsvr_create_collection_command.cpp',
'shardsvr_create_collection_participant_command.cpp',
'shardsvr_create_global_index_command.cpp',
+ 'shardsvr_drop_global_index_command.cpp',
'shardsvr_drop_collection_command.cpp',
'shardsvr_drop_collection_if_uuid_not_matching_command.cpp',
'shardsvr_drop_collection_participant_command.cpp',
diff --git a/src/mongo/db/s/config_server_op_observer.h b/src/mongo/db/s/config_server_op_observer.h
index 5a5808b4266..127ceb6607f 100644
--- a/src/mongo/db/s/config_server_op_observer.h
+++ b/src/mongo/db/s/config_server_op_observer.h
@@ -50,6 +50,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/s/range_deleter_service_op_observer.h b/src/mongo/db/s/range_deleter_service_op_observer.h
index a800d594bc0..4bd0f2945f2 100644
--- a/src/mongo/db/s/range_deleter_service_op_observer.h
+++ b/src/mongo/db/s/range_deleter_service_op_observer.h
@@ -75,6 +75,10 @@ private:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/s/resharding/resharding_op_observer.h b/src/mongo/db/s/resharding/resharding_op_observer.h
index 58ed4ea70d7..c8f07c6bffe 100644
--- a/src/mongo/db/s/resharding/resharding_op_observer.h
+++ b/src/mongo/db/s/resharding/resharding_op_observer.h
@@ -65,6 +65,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/s/shard_server_op_observer.h b/src/mongo/db/s/shard_server_op_observer.h
index f3008f187ae..88f9d31ebd0 100644
--- a/src/mongo/db/s/shard_server_op_observer.h
+++ b/src/mongo/db/s/shard_server_op_observer.h
@@ -49,6 +49,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/db/s/shardsvr_drop_global_index_command.cpp b/src/mongo/db/s/shardsvr_drop_global_index_command.cpp
new file mode 100644
index 00000000000..69e17b2c2d1
--- /dev/null
+++ b/src/mongo/db/s/shardsvr_drop_global_index_command.cpp
@@ -0,0 +1,108 @@
+/**
+ * Copyright (C) 2022-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include <string>
+
+#include "mongo/db/auth/authorization_session.h"
+#include "mongo/db/commands.h"
+#include "mongo/db/global_index.h"
+#include "mongo/db/server_feature_flags_gen.h"
+#include "mongo/s/request_types/sharded_ddl_commands_gen.h"
+
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
+
+
+namespace mongo {
+namespace {
+
+class ShardsvrCreateGlobalIndexCommand final
+ : public TypedCommand<ShardsvrCreateGlobalIndexCommand> {
+public:
+ using Request = DropGlobalIndex;
+
+ AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
+ return AllowedOnSecondary::kNever;
+ }
+
+ std::string help() const override {
+ return "Internal command that drops the shard-local container for a global index.";
+ }
+
+ ReadWriteType getReadWriteType() const override {
+ return ReadWriteType::kWrite;
+ }
+
+ bool skipApiVersionCheck() const override {
+ // Internal command (server to server).
+ return true;
+ }
+
+ bool adminOnly() const override {
+ return true;
+ }
+
+ bool supportsRetryableWrite() const final {
+ return true;
+ }
+
+ class Invocation final : public InvocationBase {
+ public:
+ using InvocationBase::InvocationBase;
+
+ bool supportsWriteConcern() const final {
+ return true;
+ }
+
+ NamespaceString ns() const final {
+ return NamespaceString(request().getDbName(), "");
+ }
+
+ void typedRun(OperationContext* opCtx) {
+
+ uassert(ErrorCodes::CommandNotSupported,
+ "_shardsvrDropGlobalIndex command not enabled",
+ gFeatureFlagGlobalIndexes.isEnabledAndIgnoreFCV());
+
+ const auto indexUUID = request().getCommandParameter();
+ global_index::dropContainer(opCtx, indexUUID);
+ }
+
+ private:
+ void doCheckAuthorization(OperationContext* opCtx) const override {
+ uassert(ErrorCodes::Unauthorized,
+ "Unauthorized",
+ AuthorizationSession::get(opCtx->getClient())
+ ->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(),
+ ActionType::internal));
+ }
+ };
+} shardsvrDropGlobalIndexCommand;
+
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/db/serverless/shard_split_donor_op_observer.h b/src/mongo/db/serverless/shard_split_donor_op_observer.h
index 32ef1664214..f13e7c1e63f 100644
--- a/src/mongo/db/serverless/shard_split_donor_op_observer.h
+++ b/src/mongo/db/serverless/shard_split_donor_op_observer.h
@@ -48,6 +48,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/idl/cluster_server_parameter_op_observer.h b/src/mongo/idl/cluster_server_parameter_op_observer.h
index c4dce5c018d..26482472424 100644
--- a/src/mongo/idl/cluster_server_parameter_op_observer.h
+++ b/src/mongo/idl/cluster_server_parameter_op_observer.h
@@ -97,6 +97,10 @@ public:
const NamespaceString& globalIndexNss,
const UUID& globalIndexUUID) final{};
+ void onDropGlobalIndex(OperationContext* opCtx,
+ const NamespaceString& globalIndexNss,
+ const UUID& globalIndexUUID) final{};
+
void onCreateIndex(OperationContext* opCtx,
const NamespaceString& nss,
const UUID& uuid,
diff --git a/src/mongo/s/request_types/sharded_ddl_commands.idl b/src/mongo/s/request_types/sharded_ddl_commands.idl
index fe4030d7884..c8ec71bc979 100644
--- a/src/mongo/s/request_types/sharded_ddl_commands.idl
+++ b/src/mongo/s/request_types/sharded_ddl_commands.idl
@@ -290,6 +290,16 @@ commands:
api_version: ""
reply_type: OkReply
+ _shardsvrDropGlobalIndex:
+ description: "Internal command sent to participant shards to drop a global index container with a given UUID."
+ command_name: _shardsvrDropGlobalIndex
+ cpp_name: DropGlobalIndex
+ strict: true
+ type: uuid
+ namespace: type
+ api_version: ""
+ reply_type: OkReply
+
_shardsvrDropDatabase:
description: "Internal command sent to the primary shard of a database to drop it."
command_name: _shardsvrDropDatabase