diff options
author | Jordi Serra Torrens <jordi.serra-torrens@mongodb.com> | 2021-02-16 17:47:18 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-17 10:22:39 +0000 |
commit | d4ff82a11019aef87701db9053499461601e75d6 (patch) | |
tree | 88a4438bf69201fd3f34c8b2fe1fdba651087419 /src/mongo | |
parent | 8c2c462fbb802a2093fae9be5e21b4a1d723988b (diff) | |
download | mongo-d4ff82a11019aef87701db9053499461601e75d6.tar.gz |
SERVER-54579: Complete TODO listed in SERVER-53105
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/s/config/config_server_test_fixture.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/s/config/initial_split_policy.h | 6 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_ddl_util.cpp | 37 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_ddl_util_test.cpp | 25 |
4 files changed, 24 insertions, 55 deletions
diff --git a/src/mongo/db/s/config/config_server_test_fixture.cpp b/src/mongo/db/s/config/config_server_test_fixture.cpp index 4022eb3a25b..a2fba05a49b 100644 --- a/src/mongo/db/s/config/config_server_test_fixture.cpp +++ b/src/mongo/db/s/config/config_server_test_fixture.cpp @@ -322,7 +322,16 @@ void ConfigServerTestFixture::setupCollection(const NamespaceString& nss, setupDatabase(nss.db().toString(), ShardId(shard.getName()), true /* sharded */); } - CollectionType coll(nss, chunks[0].getVersion().epoch(), Date_t::now(), UUID::gen()); + const auto collUUID = [&]() { + const auto& chunk = chunks.front(); + if (chunk.getVersion().getTimestamp()) { + return chunk.getCollectionUUID(); + } else { + return UUID::gen(); + } + }(); + CollectionType coll(nss, chunks[0].getVersion().epoch(), Date_t::now(), collUUID); + coll.setTimestamp(chunks.front().getVersion().getTimestamp()); coll.setKeyPattern(shardKey); ASSERT_OK( insertToConfigCollection(operationContext(), CollectionType::ConfigNS, coll.toBSON())); diff --git a/src/mongo/db/s/config/initial_split_policy.h b/src/mongo/db/s/config/initial_split_policy.h index 91f1c3c4054..8f2f4da1c2d 100644 --- a/src/mongo/db/s/config/initial_split_policy.h +++ b/src/mongo/db/s/config/initial_split_policy.h @@ -44,9 +44,9 @@ namespace mongo { struct SplitPolicyParams { NamespaceString nss; - // TODO SERVER-53105 update this comment explaining that just (nss || uuid) field will be - // persisted If boost::none, the resulting config.chunks document(s) are not going to include - // the collection UUID field + // If collectionUUID is set, then only the uuid field will be persisted on the config.chunks + // document(s), but not the nss. If collectionUUID is not set, then only nss will be persisted + // on config.chunks, but not the uuid. boost::optional<CollectionUUID> collectionUUID; ShardId primaryShardId; }; diff --git a/src/mongo/db/s/sharding_ddl_util.cpp b/src/mongo/db/s/sharding_ddl_util.cpp index 1953918dc86..17ab89ab9e0 100644 --- a/src/mongo/db/s/sharding_ddl_util.cpp +++ b/src/mongo/db/s/sharding_ddl_util.cpp @@ -171,43 +171,6 @@ void shardedRenameMetadata(OperationContext* opCtx, collType.toBSON(), ShardingCatalogClient::kMajorityWriteConcern)); - // Update source chunks to target collection - // Super-inefficient due to limitation of the catalogClient (no multi-document update), but just - // temporary: TODO on SERVER-53105 completion, throw out the following scope. - { - repl::OpTime opTime; - auto chunks = uassertStatusOK(Grid::get(opCtx)->catalogClient()->getChunks( - opCtx, - BSON(ChunkType::ns(fromNss.ns())), - BSON(ChunkType::lastmod() << 1), - boost::none, - &opTime, - repl::ReadConcernLevel::kMajorityReadConcern)); - - if (!chunks.empty()) { - // Wait for majority just for last chunk - auto lastChunk = chunks.back(); - chunks.pop_back(); - for (auto& chunk : chunks) { - uassertStatusOK(catalogClient->updateConfigDocument( - opCtx, - ChunkType::ConfigNS, - BSON(ChunkType::name(chunk.getName())), - BSON("$set" << BSON(ChunkType::ns(toNss.ns()))), - false, /* upsert */ - ShardingCatalogClient::kLocalWriteConcern)); - } - - uassertStatusOK( - catalogClient->updateConfigDocument(opCtx, - ChunkType::ConfigNS, - BSON(ChunkType::name(lastChunk.getName())), - BSON("$set" << BSON(ChunkType::ns(toNss.ns()))), - false, /* upsert */ - ShardingCatalogClient::kMajorityWriteConcern)); - } - } - // Delete FROM tag/collection entries removeTagsMetadataFromConfig(opCtx, fromNss); deleteCollection(opCtx, fromNss); diff --git a/src/mongo/db/s/sharding_ddl_util_test.cpp b/src/mongo/db/s/sharding_ddl_util_test.cpp index 6d6be9de4e1..a92a39c080c 100644 --- a/src/mongo/db/s/sharding_ddl_util_test.cpp +++ b/src/mongo/db/s/sharding_ddl_util_test.cpp @@ -92,15 +92,18 @@ TEST_F(ShardingDDLUtilTest, ShardedRenameMetadata) { const auto toCollQuery = Query(BSON(CollectionType::kNssFieldName << kToNss.ns())); + const Timestamp collTimestamp(1); + const auto collUUID = UUID::gen(); + // Initialize FROM collection chunks const auto fromEpoch = OID::gen(); const int nChunks = 10; std::vector<ChunkType> chunks; for (int i = 0; i < nChunks; i++) { - ChunkVersion chunkVersion(1, i, fromEpoch, boost::none); + ChunkVersion chunkVersion(1, i, fromEpoch, collTimestamp); ChunkType chunk; chunk.setName(OID::gen()); - chunk.setNS(fromNss); + chunk.setCollectionUUID(collUUID); chunk.setVersion(chunkVersion); chunk.setShard(shard0.getName()); chunk.setHistory({ChunkHistory(Timestamp(1, i), shard0.getName())}); @@ -111,13 +114,11 @@ TEST_F(ShardingDDLUtilTest, ShardedRenameMetadata) { setupCollection(fromNss, KeyPattern(BSON("x" << 1)), chunks); - // TODO SERVER-53105 remove all nss chunk references from this test - const auto nssChunkFieldName = "ns"; - // Get FROM collection document and chunks auto fromDoc = client.findOne(CollectionType::ConfigNS.ns(), fromCollQuery); CollectionType fromCollection(fromDoc); - auto fromChunksQuery = Query(BSON(nssChunkFieldName << fromNss.ns())).sort(BSON("_id" << 1)); + auto fromChunksQuery = + Query(BSON(ChunkType::collectionUUID << collUUID)).sort(BSON("_id" << 1)); std::vector<BSONObj> fromChunks; client.findN(fromChunks, ChunkType::ConfigNS.ns(), fromChunksQuery, nChunks); @@ -127,12 +128,10 @@ TEST_F(ShardingDDLUtilTest, ShardedRenameMetadata) { // Check that the FROM config.collections entry has been deleted ASSERT(client.findOne(CollectionType::ConfigNS.ns(), fromCollQuery).isEmpty()); - // Ensure no chunks are referring the FROM collection anymore - ASSERT(client.findOne(ChunkType::ConfigNS.ns(), fromChunksQuery).isEmpty()); - // Get TO collection document and chunks auto toDoc = client.findOne(CollectionType::ConfigNS.ns(), toCollQuery); - const auto toChunksQuery = Query(BSON(nssChunkFieldName << kToNss.ns())).sort(BSON("_id" << 1)); + const auto toChunksQuery = + Query(BSON(ChunkType::collectionUUID << collUUID)).sort(BSON("_id" << 1)); CollectionType toCollection(toDoc); std::vector<BSONObj> toChunks; client.findN(toChunks, ChunkType::ConfigNS.ns(), toChunksQuery, nChunks); @@ -145,14 +144,12 @@ TEST_F(ShardingDDLUtilTest, ShardedRenameMetadata) { auto toUnchangedFields = toDoc.removeField(CollectionType::kNssFieldName); ASSERT_EQ(fromUnchangedFields.woCompare(toUnchangedFields), 0); - // Check that epoch and nss have been updated in chunk documents + // Check that chunk documents remain unchanged for (int i = 0; i < nChunks; i++) { auto fromChunkDoc = fromChunks[i]; auto toChunkDoc = toChunks[i]; - ASSERT_EQ(fromChunkDoc.removeField(nssChunkFieldName) - .woCompare(toChunkDoc.removeField(nssChunkFieldName)), - 0); + ASSERT_EQ(fromChunkDoc.woCompare(toChunkDoc), 0); } } |