Skip to content

Commit 75833b1

Browse files
committed
fix: Limit pre-aggregations fetch table requests using queue -- handle HA for pre-aggregations
1 parent 7bcb941 commit 75833b1

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

packages/cubejs-query-orchestrator/orchestrator/PreAggregations.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,14 @@ class PreAggregationLoadCache {
5858
async tablesFromCache(preAggregation, forceRenew) {
5959
let tables = forceRenew ? null : await this.cacheDriver.get(this.tablesRedisKey(preAggregation));
6060
if (!tables) {
61-
if (this.fetchTablesPromise) {
62-
tables = await this.fetchTablesPromise;
63-
} else {
64-
this.fetchTablesPromise = this.fetchTables(preAggregation);
65-
try {
66-
tables = await this.fetchTablesPromise;
67-
} finally {
68-
this.fetchTablesPromise = null;
69-
}
70-
}
61+
tables = await this.preAggregations.getLoadCacheQueue().executeInQueue(
62+
'query',
63+
preAggregation.preAggregationsSchema,
64+
{
65+
preAggregation
66+
},
67+
0
68+
);
7169
}
7270
return tables;
7371
}
@@ -596,6 +594,25 @@ class PreAggregations {
596594
return this.queue;
597595
}
598596

597+
getLoadCacheQueue() {
598+
if (!this.loadCacheQueue) {
599+
this.loadCacheQueue = QueryCache.createQueue(`SQL_PRE_AGGREGATIONS_CACHE_${this.redisPrefix}`, this.driverFactory, (client, q) => {
600+
const {
601+
preAggregation
602+
} = q;
603+
const loadCache = new PreAggregationLoadCache(this.redisPrefix, this.driverFactory, this.queryCache, this);
604+
return loadCache.fetchTables(preAggregation);
605+
}, {
606+
concurrency: 4,
607+
logger: this.logger,
608+
cacheAndQueueDriver: this.options.cacheAndQueueDriver,
609+
redisPool: this.options.redisPool,
610+
...this.options.loadCacheQueueOptions
611+
});
612+
}
613+
return this.loadCacheQueue;
614+
}
615+
599616
static preAggregationQueryCacheKey(preAggregation) {
600617
return preAggregation.tableName;
601618
}

0 commit comments

Comments
 (0)