diff options
author | Tommaso Tocci <tommaso.tocci@mongodb.com> | 2022-03-30 20:12:07 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-30 20:51:55 +0000 |
commit | 6a06d60a41605738cfb882aa5a5aaedeb30e0512 (patch) | |
tree | 50139aa7732b75a3574faee884202efd8dfc40a9 | |
parent | aef0b4ad970c8382a6108fbd9bc2c6f39e27fa39 (diff) | |
download | mongo-6a06d60a41605738cfb882aa5a5aaedeb30e0512.tar.gz |
SERVER-65014 Use long long type for orphan count
-rw-r--r-- | jstests/sharding/collstats_returns_orphan_count.js | 6 | ||||
-rw-r--r-- | src/mongo/db/s/migration_destination_manager.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/s/migration_util.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/s/migration_util.h | 6 | ||||
-rw-r--r-- | src/mongo/db/stats/storage_stats.cpp | 6 |
5 files changed, 16 insertions, 14 deletions
diff --git a/jstests/sharding/collstats_returns_orphan_count.js b/jstests/sharding/collstats_returns_orphan_count.js index 4f7ae294e7a..d3f56be4677 100644 --- a/jstests/sharding/collstats_returns_orphan_count.js +++ b/jstests/sharding/collstats_returns_orphan_count.js @@ -23,12 +23,12 @@ const st = new ShardingTest({ function assertCollStatsHasCorrectOrphanCount(coll, shardName, numOrphans) { const pipeline = [ {'$collStats': {'storageStats': {}}}, - {'$project': {'shard': true, 'storageStats': {'orphanCount': true}}} + {'$project': {'shard': true, 'storageStats': {'numOrphanDocs': true}}} ]; const storageStats = coll.aggregate(pipeline).toArray(); storageStats.forEach((stat) => { if (stat['shard'] === shardName) { - assert.eq(stat.storageStats.orphanCount, numOrphans); + assert.eq(stat.storageStats.numOrphanDocs, numOrphans); } }); } @@ -42,7 +42,7 @@ assert.commandWorked( // Test non-existing collection const noColl = db['unusedColl']; let res = db.runCommand({'collStats': noColl.getFullName()}); -assert.eq(res.shards[st.shard0.shardName].orphanCount, 0); +assert.eq(res.shards[st.shard0.shardName].numOrphanDocs, 0); // Setup collection for test with orphans const coll = db['test']; diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp index c747a371567..1481b9d073e 100644 --- a/src/mongo/db/s/migration_destination_manager.cpp +++ b/src/mongo/db/s/migration_destination_manager.cpp @@ -1648,7 +1648,7 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx, bool MigrationDestinationManager::_applyMigrateOp(OperationContext* opCtx, const BSONObj& xfer) { bool didAnything = false; - int changeInOrphans = 0; + long long changeInOrphans = 0; // Deleted documents if (xfer["deleted"].isABSONObj()) { diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp index 0ee6e29f272..697340cc150 100644 --- a/src/mongo/db/s/migration_util.cpp +++ b/src/mongo/db/s/migration_util.cpp @@ -672,7 +672,7 @@ void persistRangeDeletionTaskLocally(OperationContext* opCtx, void persistUpdatedNumOrphans(OperationContext* opCtx, const UUID& migrationId, - const int& changeInOrphans) { + long long changeInOrphans) { // TODO (SERVER-63819) Remove numOrphanDocsFieldName field from the query // Add $exists to the query to ensure that on upgrade and downgrade, the numOrphanDocs field // is only updated after the upgrade procedure has populated it with an initial value. @@ -695,8 +695,8 @@ void persistUpdatedNumOrphans(OperationContext* opCtx, } } -int retrieveNumOrphansFromRecipient(OperationContext* opCtx, - const MigrationCoordinatorDocument& migrationInfo) { +long long retrieveNumOrphansFromRecipient(OperationContext* opCtx, + const MigrationCoordinatorDocument& migrationInfo) { const auto recipientShard = uassertStatusOK( Grid::get(opCtx)->shardRegistry()->getShard(opCtx, migrationInfo.getRecipientShardId())); FindCommandRequest findCommand(NamespaceString::kRangeDeletionNamespace); @@ -720,7 +720,9 @@ int retrieveNumOrphansFromRecipient(OperationContext* opCtx, "migrationId"_attr = migrationInfo.getId()); return 0; } - return rangeDeletionResponse.docs[0].getIntField("numOrphanDocs"); + const auto numOrphanDocsElem = + rangeDeletionResponse.docs[0].getField(RangeDeletionTask::kNumOrphanDocsFieldName); + return numOrphanDocsElem ? numOrphanDocsElem.safeNumberLong() : 0; } void notifyChangeStreamsOnRecipientFirstChunk(OperationContext* opCtx, diff --git a/src/mongo/db/s/migration_util.h b/src/mongo/db/s/migration_util.h index 893752a0faf..49de15b74f4 100644 --- a/src/mongo/db/s/migration_util.h +++ b/src/mongo/db/s/migration_util.h @@ -149,13 +149,13 @@ void persistRangeDeletionTaskLocally(OperationContext* opCtx, */ void persistUpdatedNumOrphans(OperationContext* opCtx, const UUID& migrationId, - const int& changeInOrphans); + long long changeInOrphans); /** * Retrieves the value of 'numOrphanedDocs' from the recipient shard's range deletion task document. */ -int retrieveNumOrphansFromRecipient(OperationContext* opCtx, - const MigrationCoordinatorDocument& migrationInfo); +long long retrieveNumOrphansFromRecipient(OperationContext* opCtx, + const MigrationCoordinatorDocument& migrationInfo); /** * Updates the migration coordinator document to set the decision field to "committed" and waits for diff --git a/src/mongo/db/stats/storage_stats.cpp b/src/mongo/db/stats/storage_stats.cpp index 00966458fa1..870dc908021 100644 --- a/src/mongo/db/stats/storage_stats.cpp +++ b/src/mongo/db/stats/storage_stats.cpp @@ -50,7 +50,7 @@ namespace mongo { namespace { -int countOrphanDocsForCollection(OperationContext* opCtx, const UUID& uuid) { +long long countOrphanDocsForCollection(OperationContext* opCtx, const UUID& uuid) { // TODO (SERVER-64162): move this function to range_deletion_util.cpp and replace // "collectionUuid" and "numOrphanDocs" with RangeDeletionTask field names. DBDirectClient client(opCtx); @@ -75,7 +75,7 @@ int countOrphanDocsForCollection(OperationContext* opCtx, const UUID& uuid) { invariant(!cursor->more()); auto numOrphans = res.getField("count"); invariant(numOrphans); - return numOrphans.numberInt(); + return numOrphans.exactNumberLong(); } } // namespace @@ -83,7 +83,7 @@ Status appendCollectionStorageStats(OperationContext* opCtx, const NamespaceString& nss, const StorageStatsSpec& storageStatsSpec, BSONObjBuilder* result) { - const std::string kOrphanCountField = "orphanCount"; + static constexpr auto kOrphanCountField = "numOrphanDocs"_sd; auto scale = storageStatsSpec.getScale().value_or(1); bool verbose = storageStatsSpec.getVerbose(); |