@@ -73,6 +73,8 @@ MONGO_FAIL_POINT_DEFINE(skipExpiringOldChunkHistory);
73
73
74
74
const WriteConcernOptions kNoWaitWriteConcern (1 , WriteConcernOptions::SyncMode::UNSET, Seconds(0 ));
75
75
76
+ constexpr StringData kCollectionVersionField = " collectionVersion" _sd;
77
+
76
78
/* *
77
79
* Append min, max and version information from chunk to the buffer for logChange purposes.
78
80
*/
@@ -384,7 +386,7 @@ ChunkVersion getDonorShardVersion(OperationContext* opCtx,
384
386
return swDonorShardVersion.getValue ();
385
387
}
386
388
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
388
390
BSONObj getShardAndCollectionVersion (OperationContext* opCtx,
389
391
const CollectionType& coll,
390
392
const ShardId& fromShard) {
@@ -401,8 +403,8 @@ BSONObj getShardAndCollectionVersion(OperationContext* opCtx,
401
403
shardVersion.isOlderOrEqualThan (collectionVersion));
402
404
403
405
BSONObjBuilder result;
404
- collectionVersion.appendWithField (&result, " collectionVersion " );
405
- shardVersion.appendWithField (&result, " shardVersion " );
406
+ collectionVersion.appendWithField (&result, kCollectionVersionField );
407
+ shardVersion.appendWithField (&result, ChunkVersion:: kShardVersionField );
406
408
407
409
return result.obj ();
408
410
}
@@ -707,11 +709,6 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkSplit(
707
709
return applyOpsStatus;
708
710
}
709
711
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
-
715
712
// log changes
716
713
BSONObjBuilder logDetail;
717
714
{
@@ -750,7 +747,10 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkSplit(
750
747
}
751
748
}
752
749
753
- return shardAndCollVersion;
750
+ BSONObjBuilder response;
751
+ currentMaxVersion.appendWithField (&response, kCollectionVersionField );
752
+ currentMaxVersion.appendWithField (&response, ChunkVersion::kShardVersionField );
753
+ return response.obj ();
754
754
}
755
755
756
756
StatusWith<BSONObj> ShardingCatalogManager::commitChunkMerge (
@@ -1150,10 +1150,10 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration(
1150
1150
if (currentChunk.getShard () == toShard) {
1151
1151
// The commit was already done successfully
1152
1152
BSONObjBuilder response;
1153
- currentCollectionVersion.appendWithField (&response, " collectionVersion " );
1153
+ currentCollectionVersion.appendWithField (&response, kCollectionVersionField );
1154
1154
const auto currentShardVersion =
1155
1155
getDonorShardVersion (opCtx, coll, fromShard, currentCollectionVersion);
1156
- currentShardVersion.appendWithField (&response, " shardVersion " );
1156
+ currentShardVersion.appendWithField (&response, ChunkVersion:: kShardVersionField );
1157
1157
// Makes sure that the last thing we read in getCurrentChunk and
1158
1158
// getShardAndCollectionVersion gets majority written before to return from this command,
1159
1159
// otherwise next RoutingInfo cache refresh from the shard may not see those newest
@@ -1270,13 +1270,14 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration(
1270
1270
BSONObjBuilder response;
1271
1271
if (!newControlChunk) {
1272
1272
// We migrated the last chunk from the donor shard.
1273
- newMigratedChunk.getVersion ().appendWithField (&response, " collectionVersion " );
1273
+ newMigratedChunk.getVersion ().appendWithField (&response, kCollectionVersionField );
1274
1274
const ChunkVersion donorShardVersion (
1275
1275
0 , 0 , currentCollectionVersion.epoch (), currentCollectionVersion.getTimestamp ());
1276
- donorShardVersion.appendWithField (&response, " shardVersion " );
1276
+ donorShardVersion.appendWithField (&response, ChunkVersion:: kShardVersionField );
1277
1277
} 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 );
1280
1281
}
1281
1282
return response.obj ();
1282
1283
}
0 commit comments