diff options
author | Marcos José Grillo Ramirez <marcos.grillo@mongodb.com> | 2022-11-08 15:20:48 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-08 16:01:26 +0000 |
commit | ccffa2062f09352f6c064e64090bdda42b829e73 (patch) | |
tree | 0951cc91e27d3dba9cfdcbeba80c0b88a0cbbdd5 /src/mongo/db/s/shard_server_op_observer.cpp | |
parent | f906c9b49d589616a9bc8147cf62e6092fed600b (diff) | |
download | mongo-ccffa2062f09352f6c064e64090bdda42b829e73.tar.gz |
SERVER-67103 Add global index copy when migrating a chunk
Diffstat (limited to 'src/mongo/db/s/shard_server_op_observer.cpp')
-rw-r--r-- | src/mongo/db/s/shard_server_op_observer.cpp | 85 |
1 files changed, 61 insertions, 24 deletions
diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp index 4253499fec9..1efc635e7d2 100644 --- a/src/mongo/db/s/shard_server_op_observer.cpp +++ b/src/mongo/db/s/shard_server_op_observer.cpp @@ -527,30 +527,67 @@ void ShardServerOpObserver::onModifyShardedCollectionGlobalIndexCatalogEntry( 1, "Updating sharding in-memory state onModifyShardedCollectionGlobalIndexCatalogEntry", "indexDoc"_attr = indexDoc); - if (indexDoc["op"].str() == "i") { - auto indexEntry = IndexCatalogType::parse( - IDLParserContext("onModifyShardedCollectionGlobalIndexCatalogEntry"), - indexDoc["entry"].Obj()); - auto indexVersion = indexDoc["entry"][IndexCatalogType::kLastmodFieldName].timestamp(); - auto uuid = uassertStatusOK( - UUID::parse(indexDoc["entry"][IndexCatalogType::kCollectionUUIDFieldName])); - opCtx->recoveryUnit()->onCommit([opCtx, nss, indexVersion, indexEntry, uuid](auto _) { - AutoGetCollection autoColl(opCtx, nss, MODE_IX); - CollectionShardingRuntime::assertCollectionLockedAndAcquire( - opCtx, nss, CSRAcquisitionMode::kExclusive) - ->addIndex(opCtx, indexEntry, {uuid, indexVersion}); - }); - } else { - auto indexName = indexDoc["entry"][IndexCatalogType::kNameFieldName].str(); - auto indexVersion = indexDoc["entry"][IndexCatalogType::kLastmodFieldName].timestamp(); - auto uuid = uassertStatusOK( - UUID::parse(indexDoc["entry"][IndexCatalogType::kCollectionUUIDFieldName])); - opCtx->recoveryUnit()->onCommit([opCtx, nss, indexName, indexVersion, uuid](auto _) { - AutoGetCollection autoColl(opCtx, nss, MODE_IX); - CollectionShardingRuntime::assertCollectionLockedAndAcquire( - opCtx, nss, CSRAcquisitionMode::kExclusive) - ->removeIndex(opCtx, indexName, {uuid, indexVersion}); - }); + auto op = indexDoc["op"].String(); + invariant(op.size() > 0); + switch (op[0]) { + case 'i': { + auto indexEntry = IndexCatalogType::parse( + IDLParserContext("onModifyShardedCollectionGlobalIndexCatalogEntry"), + indexDoc["entry"].Obj()); + auto indexVersion = indexDoc["entry"][IndexCatalogType::kLastmodFieldName].timestamp(); + auto uuid = uassertStatusOK( + UUID::parse(indexDoc["entry"][IndexCatalogType::kCollectionUUIDFieldName])); + opCtx->recoveryUnit()->onCommit([opCtx, nss, uuid, indexVersion, indexEntry](auto _) { + AutoGetCollection autoColl(opCtx, nss, MODE_IX); + auto scsr = CollectionShardingRuntime::assertCollectionLockedAndAcquire( + opCtx, nss, CSRAcquisitionMode::kExclusive); + scsr->addIndex(opCtx, indexEntry, {uuid, indexVersion}); + }); + break; + } + case 'd': { + auto indexName = indexDoc["entry"][IndexCatalogType::kNameFieldName].str(); + auto indexVersion = indexDoc["entry"][IndexCatalogType::kLastmodFieldName].timestamp(); + auto uuid = uassertStatusOK( + UUID::parse(indexDoc["entry"][IndexCatalogType::kCollectionUUIDFieldName])); + opCtx->recoveryUnit()->onCommit([opCtx, nss, indexName, indexVersion, uuid](auto _) { + AutoGetCollection autoColl(opCtx, nss, MODE_IX); + auto scsr = CollectionShardingRuntime::assertCollectionLockedAndAcquire( + opCtx, nss, CSRAcquisitionMode::kExclusive); + scsr->removeIndex(opCtx, indexName, {uuid, indexVersion}); + }); + break; + } + case 'r': { + std::vector<IndexCatalogType> indexes; + for (const auto& i : indexDoc["entry"]["i"].Array()) { + auto indexEntry = IndexCatalogType::parse( + IDLParserContext("onModifyShardedCollectionGlobalIndexCatalogEntry"), i.Obj()); + indexes.push_back(indexEntry); + } + + auto indexVersion = indexDoc["entry"][IndexCatalogType::kLastmodFieldName].timestamp(); + auto uuid = uassertStatusOK( + UUID::parse(indexDoc["entry"][IndexCatalogType::kCollectionUUIDFieldName])); + opCtx->recoveryUnit()->onCommit([opCtx, nss, uuid, indexVersion, indexes](auto _) { + AutoGetCollection autoColl(opCtx, nss, MODE_IX); + auto scsr = CollectionShardingRuntime::assertCollectionLockedAndAcquire( + opCtx, nss, CSRAcquisitionMode::kExclusive); + scsr->replaceIndexes(opCtx, indexes, {uuid, indexVersion}); + }); + break; + } + case 'c': + opCtx->recoveryUnit()->onCommit([opCtx, nss](auto _) { + AutoGetCollection autoColl(opCtx, nss, MODE_IX); + auto scsr = CollectionShardingRuntime::assertCollectionLockedAndAcquire( + opCtx, nss, CSRAcquisitionMode::kExclusive); + scsr->clearIndexes(opCtx); + }); + + break; + default: + MONGO_UNREACHABLE; } } |