Skip to content

Commit 7aeb3e2

Browse files
authored
chore(shell-api): query config.chunks like the legacy shell MONGOSH-1179 (#1419)
1 parent f79d36c commit 7aeb3e2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

packages/shell-api/src/collection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import {
3232
isValidCollectionName,
3333
scaleIndividualShardStatistics,
3434
shouldRunAggregationImmediately,
35-
coerceToJSNumber
35+
coerceToJSNumber,
36+
buildConfigChunksCollectionMatch
3637
} from './helpers';
3738
import {
3839
AnyBulkWriteOperation,
@@ -1898,7 +1899,6 @@ export default class Collection extends ShellApiWithMongoClass {
18981899
}
18991900

19001901
const collStats = await (await this.aggregate({ '$collStats': { storageStats: {} } })).toArray();
1901-
const uuid = configCollectionsInfo?.uuid ?? null;
19021902

19031903
const totals = { numChunks: 0, size: 0, count: 0 };
19041904
const conciseShardsStats: {
@@ -1918,7 +1918,7 @@ export default class Collection extends ShellApiWithMongoClass {
19181918
// If we have an UUID, use that for lookups. If we have only the ns,
19191919
// use that. (On 5.0+ servers, config.chunk has uses the UUID, before
19201920
// that it had the ns).
1921-
const countChunksQuery = uuid ? { $or: [ { uuid }, { ns } ], shard } : { ns, shard };
1921+
const countChunksQuery = { ...buildConfigChunksCollectionMatch(configCollectionsInfo), shard };
19221922
const [ host, numChunks ] = await Promise.all([
19231923
config.getCollection('shards').findOne({ _id: extShardStats.shard }),
19241924
config.getCollection('chunks').countDocuments(countChunksQuery)

packages/shell-api/src/helpers.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,7 @@ export async function getPrintableShardStatus(configDB: Database, verbose: boole
430430
collRes.balancing = [ !coll.noBalance, { noBalance: coll.noBalance } ];
431431
}
432432
const chunksRes = [];
433-
const chunksCollMatch =
434-
coll.uuid ? { $or: [ { uuid: coll.uuid }, { ns: coll._id } ] } : { ns: coll._id };
433+
const chunksCollMatch = buildConfigChunksCollectionMatch(coll);
435434
const chunks = await
436435
(await chunksColl.aggregate([
437436
{ $match: chunksCollMatch },
@@ -474,7 +473,9 @@ export async function getPrintableShardStatus(configDB: Database, verbose: boole
474473
}
475474

476475
const tagsRes: any[] = [];
477-
for await (const tag of (await configDB.getCollection('tags').find(chunksCollMatch)).sort({ min: 1 })) {
476+
for await (const tag of (await configDB.getCollection('tags').find({
477+
ns: coll._id
478+
})).sort({ min: 1 })) {
478479
tagsRes.push({
479480
tag: tag.tag,
480481
min: tag.min,
@@ -851,3 +852,13 @@ export function shallowClone<T>(input: T): T {
851852
if (!input || typeof input !== 'object') return input;
852853
return Array.isArray(input) ? ([...input] as unknown as T) : { ...input };
853854
}
855+
856+
// Take a document from config.collections and return a corresponding match filter
857+
// for config.chunks.
858+
// https://jira.mongodb.org/browse/MONGOSH-1179
859+
// https://github.com/mongodb/mongo/commit/aeb430b26171d5afc55f1278a29cc0f998f6a4e1
860+
export function buildConfigChunksCollectionMatch(configCollectionsInfo: Document): Document {
861+
return Object.prototype.hasOwnProperty.call(configCollectionsInfo, 'timestamp') ?
862+
{ uuid: configCollectionsInfo.uuid } : // new format
863+
{ ns: configCollectionsInfo._id }; // old format
864+
}

0 commit comments

Comments
 (0)