Skip to content

Commit

Permalink
Use 0 count for timeseries
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Oct 4, 2024
1 parent a93ee79 commit a108d21
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions packages/shell-api/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2083,38 +2083,34 @@ export default class Collection extends ShellApiWithMongoClass {
async _getShardedTimeseriesCollectionInfo(
config: Database,
collStats: Document[]
): Promise<{
timeseriesBucketCount: number | null;
timeseriesCollectionInfo: Document | null;
}> {
): Promise<Document | null> {
const timeseriesShardStats = collStats.find(
(extractedShardStats) =>
typeof extractedShardStats.storageStats.timeseries !== 'undefined'
);

if (!timeseriesShardStats) {
return {
timeseriesCollectionInfo: null,
timeseriesBucketCount: null,
};
return null;
}

const { storageStats } = timeseriesShardStats;

const timeseries: Document = storageStats['timeseries'];

const timeseriesBucketCount: number | null =
timeseries['bucketCount'] ?? null;
const timeseriesBucketNs: string | undefined = timeseries['bucketsNs'];

if (!timeseriesBucketNs) {
return null;
}

const timeseriesCollectionInfo = await config
.getCollection('collections')
.findOne({
_id: timeseriesBucketNs,
...onlyShardedCollectionsInConfigFilter,
});

return { timeseriesBucketCount, timeseriesCollectionInfo };
return timeseriesCollectionInfo;
}

@returnsPromise
Expand Down Expand Up @@ -2150,20 +2146,17 @@ export default class Collection extends ShellApiWithMongoClass {
...onlyShardedCollectionsInConfigFilter,
});

let fallbackTimeseriesBucketCount: number | undefined;

if (!configCollectionsInfo) {
const { timeseriesCollectionInfo, timeseriesBucketCount } =
const timeseriesCollectionInfo =
await this._getShardedTimeseriesCollectionInfo(config, collStats);

if (!timeseriesCollectionInfo || !timeseriesBucketCount) {
if (!timeseriesCollectionInfo) {
throw new MongoshInvalidInputError(
`Collection ${this._name} is not sharded`,
ShellApiErrors.NotConnectedToShardedCluster
);
}

fallbackTimeseriesBucketCount = timeseriesBucketCount;
configCollectionsInfo = timeseriesCollectionInfo;
}

Expand Down Expand Up @@ -2195,9 +2188,8 @@ export default class Collection extends ShellApiWithMongoClass {

const key = `Shard ${shardStats.shardId} at ${shardStats.host}`;

// In sharded timeseries collections, we use the bucket count
const shardStatsCount =
fallbackTimeseriesBucketCount ?? shardStats.count ?? 0;
// In sharded timeseries collections, count is 0.
const shardStatsCount = shardStats.count ?? 0;

const estimatedChunkDataPerChunk =
shardStats.numChunks === 0
Expand Down

0 comments on commit a108d21

Please sign in to comment.