Skip to content

Commit 650dd6e

Browse files
committed
fix: requestId isn't propagating to all pre-aggregations messages
1 parent 217895f commit 650dd6e

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,29 @@ const tablesToVersionEntries = (schema, tables) => {
4545
};
4646

4747
class PreAggregationLoadCache {
48-
constructor(redisPrefix, clientFactory, queryCache, preAggregations) {
48+
constructor(redisPrefix, clientFactory, queryCache, preAggregations, options) {
49+
options = options || {};
4950
this.redisPrefix = redisPrefix;
5051
this.driverFactory = clientFactory;
5152
this.queryCache = queryCache;
5253
this.preAggregations = preAggregations;
5354
this.queryResults = {};
5455
this.cacheDriver = preAggregations.cacheDriver;
5556
this.externalDriverFactory = preAggregations.externalDriverFactory;
57+
this.requestId = options.requestId;
5658
}
5759

5860
async tablesFromCache(preAggregation, forceRenew) {
5961
let tables = forceRenew ? null : await this.cacheDriver.get(this.tablesRedisKey(preAggregation));
6062
if (!tables) {
6163
tables = await this.preAggregations.getLoadCacheQueue().executeInQueue(
6264
'query',
63-
preAggregation.preAggregationsSchema,
65+
`Fetch tables for ${preAggregation.preAggregationsSchema}`,
6466
{
65-
preAggregation
67+
preAggregation, requestId: this.requestId
6668
},
67-
0
69+
0,
70+
{ requestId: this.requestId }
6871
);
6972
}
7073
return tables;
@@ -121,7 +124,8 @@ class PreAggregationLoadCache {
121124
2 * 60,
122125
renewalKey: keyQuery,
123126
waitForRenew,
124-
priority
127+
priority,
128+
requestId: this.requestId
125129
}
126130
);
127131
}
@@ -358,7 +362,7 @@ class PreAggregationLoader {
358362
requestId: this.requestId
359363
},
360364
priority,
361-
{ stageQueryKey: PreAggregations.preAggregationQueryCacheKey(this.preAggregation) }
365+
{ stageQueryKey: PreAggregations.preAggregationQueryCacheKey(this.preAggregation), requestId: this.requestId }
362366
);
363367
}
364368

@@ -543,7 +547,9 @@ class PreAggregations {
543547

544548
loadAllPreAggregationsIfNeeded(queryBody) {
545549
const preAggregations = queryBody.preAggregations || [];
546-
const loadCache = new PreAggregationLoadCache(this.redisPrefix, this.driverFactory, this.queryCache, this);
550+
const loadCache = new PreAggregationLoadCache(this.redisPrefix, this.driverFactory, this.queryCache, this, {
551+
requestId: queryBody.requestId
552+
});
547553
return preAggregations.map(p => (preAggregationsTablesToTempTables) => {
548554
const loader = new PreAggregationLoader(
549555
this.redisPrefix,
@@ -579,7 +585,7 @@ class PreAggregations {
579585
this,
580586
preAggregation,
581587
preAggregationsTablesToTempTables,
582-
new PreAggregationLoadCache(this.redisPrefix, this.driverFactory, this.queryCache, this),
588+
new PreAggregationLoadCache(this.redisPrefix, this.driverFactory, this.queryCache, this, { requestId }),
583589
{ requestId }
584590
);
585591
return loader.refresh(newVersionEntry)(client);
@@ -598,9 +604,11 @@ class PreAggregations {
598604
if (!this.loadCacheQueue) {
599605
this.loadCacheQueue = QueryCache.createQueue(`SQL_PRE_AGGREGATIONS_CACHE_${this.redisPrefix}`, this.driverFactory, (client, q) => {
600606
const {
601-
preAggregation
607+
preAggregation,
608+
requestId
602609
} = q;
603-
const loadCache = new PreAggregationLoadCache(this.redisPrefix, this.driverFactory, this.queryCache, this);
610+
const loadCache = new PreAggregationLoadCache(this.redisPrefix, this.driverFactory, this.queryCache, this,
611+
{ requestId });
604612
return loadCache.fetchTables(preAggregation);
605613
}, {
606614
concurrency: 4,

packages/cubejs-query-orchestrator/test/QueryOrchestrator.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ describe('QueryOrchestrator', () => {
5858
loadSql: ["CREATE TABLE stb_pre_aggregations.orders_number_and_count20191101 AS SELECT\n date_trunc('week', (\"orders\".created_at::timestamptz AT TIME ZONE 'UTC')) \"orders__created_at_week\", count(\"orders\".id) \"orders__count\", sum(\"orders\".number) \"orders__number\"\n FROM\n public.orders AS \"orders\"\n WHERE (\"orders\".created_at >= $1::timestamptz AND \"orders\".created_at <= $2::timestamptz) GROUP BY 1", ["2019-11-01T00:00:00Z", "2019-11-30T23:59:59Z"]],
5959
invalidateKeyQueries: [["SELECT date_trunc('hour', (NOW()::timestamptz AT TIME ZONE 'UTC')) as current_hour", []]]
6060
}],
61-
renewQuery: true
61+
renewQuery: true,
62+
requestId: 'basic'
6263
};
6364
const result = await queryOrchestrator.fetchQuery(query);
6465
console.log(result.data[0]);
@@ -83,7 +84,8 @@ describe('QueryOrchestrator', () => {
8384
indexName: 'orders_number_and_count_week20191101'
8485
}],
8586
}],
86-
renewQuery: true
87+
renewQuery: true,
88+
requestId: 'indexes'
8789
};
8890
const result = await queryOrchestrator.fetchQuery(query);
8991
console.log(result.data[0]);
@@ -105,7 +107,8 @@ describe('QueryOrchestrator', () => {
105107
loadSql: ["CREATE TABLE stb_pre_aggregations.orders_number_and_count_and_very_very_very_very_very_very_long20191101 AS SELECT\n date_trunc('week', (\"orders\".created_at::timestamptz AT TIME ZONE 'UTC')) \"orders__created_at_week\", count(\"orders\".id) \"orders__count\", sum(\"orders\".number) \"orders__number\"\n FROM\n public.orders AS \"orders\"\n WHERE (\"orders\".created_at >= $1::timestamptz AND \"orders\".created_at <= $2::timestamptz) GROUP BY 1", ["2019-11-01T00:00:00Z", "2019-11-30T23:59:59Z"]],
106108
invalidateKeyQueries: [["SELECT date_trunc('hour', (NOW()::timestamptz AT TIME ZONE 'UTC')) as current_hour", []]],
107109
}],
108-
renewQuery: true
110+
renewQuery: true,
111+
requestId: 'silent truncate'
109112
};
110113
let thrown = true;
111114
try {

0 commit comments

Comments
 (0)