Skip to content

Commit ff724f7

Browse files
authored
fix: Re-use external connection for CubeStore in queue (#6028)
1 parent 0f4a431 commit ff724f7

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

packages/cubejs-query-orchestrator/src/orchestrator/PreAggregations.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ import {
2525
StreamOptions,
2626
UnloadOptions
2727
} from '@cubejs-backend/base-driver';
28+
import { CubeStoreDriver } from '@cubejs-backend/cubestore-driver';
2829
import { PreAggTableToTempTable, Query, QueryBody, QueryCache, QueryTuple, QueryWithParams } from './QueryCache';
2930
import { ContinueWaitError } from './ContinueWaitError';
3031
import { DriverFactory, DriverFactoryByDataSource } from './DriverFactory';
3132
import { QueryQueue } from './QueryQueue';
3233
import { LargeStreamWarning } from './StreamObjectsCounter';
3334
import { CacheAndQueryDriverType } from './QueryOrchestrator';
35+
import { RedisPool } from './RedisPool';
3436

3537
/// Name of the inline table containing the lambda rows.
3638
export const LAMBDA_TABLE_PREFIX = 'lambda';
@@ -1883,7 +1885,8 @@ type PreAggregationsOptions = {
18831885
orphanedTimeout?: number;
18841886
heartBeatInterval?: number;
18851887
}>;
1886-
redisPool?: any;
1888+
redisPool?: RedisPool;
1889+
cubeStoreDriverFactory?: () => Promise<CubeStoreDriver>;
18871890
continueWaitTimeout?: number;
18881891
cacheAndQueueDriver?: CacheAndQueryDriverType;
18891892
skipExternalCacheAndQueue?: boolean;
@@ -2264,6 +2267,7 @@ export class PreAggregations {
22642267
logger: this.logger,
22652268
cacheAndQueueDriver: this.options.cacheAndQueueDriver,
22662269
redisPool: this.options.redisPool,
2270+
cubeStoreDriverFactory: this.options.cubeStoreDriverFactory,
22672271
// Centralized continueWaitTimeout that can be overridden in queueOptions
22682272
continueWaitTimeout: this.options.continueWaitTimeout,
22692273
...(await this.options.queueOptions(dataSource)),
@@ -2310,6 +2314,7 @@ export class PreAggregations {
23102314
logger: this.logger,
23112315
cacheAndQueueDriver: this.options.cacheAndQueueDriver,
23122316
redisPool: this.options.redisPool,
2317+
cubeStoreDriverFactory: this.options.cubeStoreDriverFactory,
23132318
...this.options.loadCacheQueueOptions
23142319
}
23152320
);

packages/cubejs-query-orchestrator/src/orchestrator/QueryCache.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ export class QueryCache {
150150
this.cacheDriver = new LocalCacheDriver();
151151
break;
152152
case 'cubestore':
153+
if (!options.cubeStoreDriverFactory) {
154+
throw new Error('cubeStoreDriverFactory is a required option for Cube Store cache driver');
155+
}
156+
153157
this.cacheDriver = new CubeStoreCacheDriver(
154-
options.cubeStoreDriverFactory || (async () => new CubeStoreDriver({}))
158+
options.cubeStoreDriverFactory
155159
);
156160
break;
157161
default:
@@ -498,6 +502,7 @@ export class QueryCache {
498502
logger: this.logger,
499503
cacheAndQueueDriver: this.options.cacheAndQueueDriver,
500504
redisPool: this.options.redisPool,
505+
cubeStoreDriverFactory: this.options.cubeStoreDriverFactory,
501506
// Centralized continueWaitTimeout that can be overridden in queueOptions
502507
continueWaitTimeout: this.options.continueWaitTimeout,
503508
...(await this.options.queueOptions(dataSource)),
@@ -546,6 +551,7 @@ export class QueryCache {
546551
logger: this.logger,
547552
cacheAndQueueDriver: this.options.cacheAndQueueDriver,
548553
redisPool: this.options.redisPool,
554+
cubeStoreDriverFactory: this.options.cubeStoreDriverFactory,
549555
// Centralized continueWaitTimeout that can be overridden in queueOptions
550556
continueWaitTimeout: this.options.continueWaitTimeout,
551557
skipQueue: this.options.skipExternalCacheAndQueue,

packages/cubejs-query-orchestrator/src/orchestrator/QueryOrchestrator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class QueryOrchestrator {
9898
externalDriverFactory,
9999
cacheAndQueueDriver,
100100
redisPool,
101+
cubeStoreDriverFactory,
101102
continueWaitTimeout,
102103
skipExternalCacheAndQueue,
103104
...options.preAggregationsOptions,

packages/cubejs-query-orchestrator/src/orchestrator/QueryQueue.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ function factoryQueueDriver(cacheAndQueueDriver, queueDriverOptions) {
2222
case 'memory':
2323
return new LocalQueueDriver(queueDriverOptions);
2424
case 'cubestore':
25+
if (!queueDriverOptions.cubeStoreDriverFactory) {
26+
throw new Error('cubeStoreDriverFactory is a required option for Cube Store queue driver');
27+
}
28+
2529
return new CubeStoreQueueDriver(
26-
queueDriverOptions.cubeStoreDriverFactory || (async () => new CubeStoreDriver({})),
30+
queueDriverOptions.cubeStoreDriverFactory,
2731
queueDriverOptions
2832
);
2933
default:

0 commit comments

Comments
 (0)