Skip to content

Commit 1d78606

Browse files
allisoneastonEvergreen Agent
authored andcommitted
SERVER-58895 Prevent querying config.chunks for the shard version during chunk split
1 parent f4fc6da commit 1d78606

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ MONGO_FAIL_POINT_DEFINE(skipExpiringOldChunkHistory);
7373

7474
const WriteConcernOptions kNoWaitWriteConcern(1, WriteConcernOptions::SyncMode::UNSET, Seconds(0));
7575

76+
constexpr StringData kCollectionVersionField = "collectionVersion"_sd;
77+
7678
/**
7779
* Append min, max and version information from chunk to the buffer for logChange purposes.
7880
*/
@@ -384,7 +386,7 @@ ChunkVersion getDonorShardVersion(OperationContext* opCtx,
384386
return swDonorShardVersion.getValue();
385387
}
386388

387-
// Helper function to get collection version and donor shard version following a merge/split
389+
// Helper function to get collection version and donor shard version following a merge
388390
BSONObj getShardAndCollectionVersion(OperationContext* opCtx,
389391
const CollectionType& coll,
390392
const ShardId& fromShard) {
@@ -401,8 +403,8 @@ BSONObj getShardAndCollectionVersion(OperationContext* opCtx,
401403
shardVersion.isOlderOrEqualThan(collectionVersion));
402404

403405
BSONObjBuilder result;
404-
collectionVersion.appendWithField(&result, "collectionVersion");
405-
shardVersion.appendWithField(&result, "shardVersion");
406+
collectionVersion.appendWithField(&result, kCollectionVersionField);
407+
shardVersion.appendWithField(&result, ChunkVersion::kShardVersionField);
406408

407409
return result.obj();
408410
}
@@ -707,11 +709,6 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkSplit(
707709
return applyOpsStatus;
708710
}
709711

710-
// The current implementation of the split chunk is not idempotent (SERVER-51805).
711-
// Best effort: in order to reduce the probability of having an error, try to execute the
712-
// getShardAndCollectionVersion as soon as the batch of updates is completed
713-
const auto shardAndCollVersion = getShardAndCollectionVersion(opCtx, coll, ShardId(shardName));
714-
715712
// log changes
716713
BSONObjBuilder logDetail;
717714
{
@@ -750,7 +747,10 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkSplit(
750747
}
751748
}
752749

753-
return shardAndCollVersion;
750+
BSONObjBuilder response;
751+
currentMaxVersion.appendWithField(&response, kCollectionVersionField);
752+
currentMaxVersion.appendWithField(&response, ChunkVersion::kShardVersionField);
753+
return response.obj();
754754
}
755755

756756
StatusWith<BSONObj> ShardingCatalogManager::commitChunkMerge(
@@ -1150,10 +1150,10 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration(
11501150
if (currentChunk.getShard() == toShard) {
11511151
// The commit was already done successfully
11521152
BSONObjBuilder response;
1153-
currentCollectionVersion.appendWithField(&response, "collectionVersion");
1153+
currentCollectionVersion.appendWithField(&response, kCollectionVersionField);
11541154
const auto currentShardVersion =
11551155
getDonorShardVersion(opCtx, coll, fromShard, currentCollectionVersion);
1156-
currentShardVersion.appendWithField(&response, "shardVersion");
1156+
currentShardVersion.appendWithField(&response, ChunkVersion::kShardVersionField);
11571157
// Makes sure that the last thing we read in getCurrentChunk and
11581158
// getShardAndCollectionVersion gets majority written before to return from this command,
11591159
// otherwise next RoutingInfo cache refresh from the shard may not see those newest
@@ -1270,13 +1270,14 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration(
12701270
BSONObjBuilder response;
12711271
if (!newControlChunk) {
12721272
// We migrated the last chunk from the donor shard.
1273-
newMigratedChunk.getVersion().appendWithField(&response, "collectionVersion");
1273+
newMigratedChunk.getVersion().appendWithField(&response, kCollectionVersionField);
12741274
const ChunkVersion donorShardVersion(
12751275
0, 0, currentCollectionVersion.epoch(), currentCollectionVersion.getTimestamp());
1276-
donorShardVersion.appendWithField(&response, "shardVersion");
1276+
donorShardVersion.appendWithField(&response, ChunkVersion::kShardVersionField);
12771277
} else {
1278-
newControlChunk.get().getVersion().appendWithField(&response, "collectionVersion");
1279-
newControlChunk.get().getVersion().appendWithField(&response, "shardVersion");
1278+
newControlChunk.get().getVersion().appendWithField(&response, kCollectionVersionField);
1279+
newControlChunk.get().getVersion().appendWithField(&response,
1280+
ChunkVersion::kShardVersionField);
12801281
}
12811282
return response.obj();
12821283
}

0 commit comments

Comments
 (0)