@cubejs-backend/query-orchestrator 1.3.43 → 1.3.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/orchestrator/LocalQueueDriver.d.ts +7 -122
- package/dist/src/orchestrator/LocalQueueDriver.d.ts.map +1 -1
- package/dist/src/orchestrator/LocalQueueDriver.js +12 -319
- package/dist/src/orchestrator/LocalQueueDriver.js.map +1 -1
- package/dist/src/orchestrator/LocalQueueDriverConnection.d.ts +70 -0
- package/dist/src/orchestrator/LocalQueueDriverConnection.d.ts.map +1 -0
- package/dist/src/orchestrator/LocalQueueDriverConnection.js +235 -0
- package/dist/src/orchestrator/LocalQueueDriverConnection.js.map +1 -0
- package/dist/src/orchestrator/PreAggregationLoadCache.d.ts +3 -0
- package/dist/src/orchestrator/PreAggregationLoadCache.d.ts.map +1 -1
- package/dist/src/orchestrator/PreAggregationLoader.d.ts.map +1 -1
- package/dist/src/orchestrator/PreAggregationLoader.js +3 -1
- package/dist/src/orchestrator/PreAggregationLoader.js.map +1 -1
- package/dist/src/orchestrator/PreAggregations.d.ts +2 -2
- package/dist/src/orchestrator/PreAggregations.d.ts.map +1 -1
- package/dist/src/orchestrator/PreAggregations.js +2 -3
- package/dist/src/orchestrator/PreAggregations.js.map +1 -1
- package/dist/src/orchestrator/QueryCache.d.ts +4 -4
- package/dist/src/orchestrator/QueryCache.d.ts.map +1 -1
- package/dist/src/orchestrator/QueryCache.js +49 -49
- package/dist/src/orchestrator/QueryCache.js.map +1 -1
- package/dist/src/orchestrator/QueryOrchestrator.d.ts +5 -2
- package/dist/src/orchestrator/QueryOrchestrator.d.ts.map +1 -1
- package/dist/src/orchestrator/QueryOrchestrator.js.map +1 -1
- package/dist/src/orchestrator/QueryQueue.d.ts +72 -160
- package/dist/src/orchestrator/QueryQueue.d.ts.map +1 -1
- package/dist/src/orchestrator/QueryQueue.js +51 -159
- package/dist/src/orchestrator/QueryQueue.js.map +1 -1
- package/dist/src/orchestrator/index.d.ts +1 -0
- package/dist/src/orchestrator/index.d.ts.map +1 -1
- package/dist/src/orchestrator/index.js +1 -0
- package/dist/src/orchestrator/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,124 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
* @implements {QueueDriverConnectionInterface}
|
|
3
|
-
*/
|
|
4
|
-
export class LocalQueueDriverConnection implements QueueDriverConnectionInterface {
|
|
5
|
-
constructor(driver: any, options: any);
|
|
6
|
-
redisQueuePrefix: any;
|
|
7
|
-
continueWaitTimeout: any;
|
|
8
|
-
heartBeatTimeout: any;
|
|
9
|
-
concurrency: any;
|
|
10
|
-
driver: any;
|
|
11
|
-
results: any;
|
|
12
|
-
resultPromises: any;
|
|
13
|
-
queryDef: any;
|
|
14
|
-
toProcess: any;
|
|
15
|
-
recent: any;
|
|
16
|
-
active: any;
|
|
17
|
-
heartBeat: any;
|
|
18
|
-
processingCounter: any;
|
|
19
|
-
processingLocks: any;
|
|
20
|
-
getQueriesToCancel(): Promise<QueryKeysTuple[]>;
|
|
21
|
-
/**
|
|
22
|
-
* @returns {Promise<GetActiveAndToProcessResponse>}
|
|
23
|
-
*/
|
|
24
|
-
getActiveAndToProcess(): Promise<GetActiveAndToProcessResponse>;
|
|
25
|
-
getResultPromise(resultListKey: any): any;
|
|
26
|
-
getResultBlocking(queryKeyHash: any): Promise<any>;
|
|
27
|
-
/**
|
|
28
|
-
* Returns promise wich will be resolved with the specified by the
|
|
29
|
-
* queryKey query result or null if query was not added to the
|
|
30
|
-
* processing.
|
|
31
|
-
* @param {*} queryKey
|
|
32
|
-
* @returns {Promise<null | *>}
|
|
33
|
-
*/
|
|
34
|
-
getResult(queryKey: any): Promise<null | any>;
|
|
35
|
-
/**
|
|
36
|
-
* @protected
|
|
37
|
-
*/
|
|
38
|
-
protected queueArray(queueObj: any, orderFilterLessThan: any): any[];
|
|
39
|
-
/**
|
|
40
|
-
* @protected
|
|
41
|
-
* @param queueObj
|
|
42
|
-
* @param orderFilterLessThan
|
|
43
|
-
* @returns {QueryKeysTuple[]}
|
|
44
|
-
*/
|
|
45
|
-
protected queueArrayAsTuple(queueObj: any, orderFilterLessThan: any): QueryKeysTuple[];
|
|
46
|
-
/**
|
|
47
|
-
* Adds specified by the queryKey query to the queue, returns tuple
|
|
48
|
-
* with the operation result.
|
|
49
|
-
*
|
|
50
|
-
* @typedef {[added: number, _b: null, _c: null, toProcessLength: number, addedTime: number]} AddedTuple
|
|
51
|
-
*
|
|
52
|
-
* @param {number} keyScore
|
|
53
|
-
* @param {*} queryKey
|
|
54
|
-
* @param {number} orphanedTime
|
|
55
|
-
* @param {string} queryHandler (for the regular query is eq to 'query')
|
|
56
|
-
* @param {*} query
|
|
57
|
-
* @param {number} priority
|
|
58
|
-
* @param {*} options
|
|
59
|
-
* @returns {AddedTuple}
|
|
60
|
-
*/
|
|
61
|
-
addToQueue(keyScore: number, queryKey: any, orphanedTime: number, queryHandler: string, query: any, priority: number, options: any): [added: number, _b: null, _c: null, toProcessLength: number, addedTime: number];
|
|
62
|
-
getToProcessQueries(): QueryKeysTuple[];
|
|
63
|
-
getActiveQueries(): QueryKeysTuple[];
|
|
64
|
-
getQueryAndRemove(queryKey: any): Promise<any[]>;
|
|
65
|
-
cancelQuery(queryKey: any): Promise<any>;
|
|
66
|
-
setResultAndRemoveQuery(queryKey: any, executionResult: any, processingId: any): Promise<boolean>;
|
|
67
|
-
getNextProcessingId(): any;
|
|
68
|
-
getOrphanedQueries(): QueryKeysTuple[];
|
|
69
|
-
getStalledQueries(): QueryKeysTuple[];
|
|
70
|
-
getQueryStageState(onlyKeys: any): Promise<any[]>;
|
|
71
|
-
getQueryDef(queryKey: any): Promise<any>;
|
|
72
|
-
/**
|
|
73
|
-
* Updates heart beat for the processing query by its `queryKey`.
|
|
74
|
-
*
|
|
75
|
-
* @param {string} queryKey
|
|
76
|
-
*/
|
|
77
|
-
updateHeartBeat(queryKey: string): void;
|
|
78
|
-
retrieveForProcessing(queryKey: any, processingId: any): any[];
|
|
79
|
-
freeProcessingLock(queryKey: any, processingId: any, activated: any): void;
|
|
80
|
-
optimisticQueryUpdate(queryKey: any, toUpdate: any, processingId: any): Promise<boolean>;
|
|
81
|
-
release(): void;
|
|
82
|
-
/**
|
|
83
|
-
* Returns cache key to the specified by the queryKey query and the
|
|
84
|
-
* specified by the suffix query state.
|
|
85
|
-
* @param {*} queryKey
|
|
86
|
-
* @param {string} suffix
|
|
87
|
-
* @returns {string}
|
|
88
|
-
*/
|
|
89
|
-
queryRedisKey(queryKey: any, suffix: string): string;
|
|
90
|
-
/**
|
|
91
|
-
* Returns cache key to the cached query result.
|
|
92
|
-
* @param {*} queryKey
|
|
93
|
-
* @returns {string}
|
|
94
|
-
*/
|
|
95
|
-
resultListKey(queryKey: any): string;
|
|
96
|
-
/**
|
|
97
|
-
* Returns hash sum of the query specified by the queryKey.
|
|
98
|
-
* @param {*} queryKey
|
|
99
|
-
* @returns {string}
|
|
100
|
-
*/
|
|
101
|
-
redisHash(queryKey: any): string;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* @implements {QueueDriverInterface}
|
|
105
|
-
*/
|
|
106
|
-
export class LocalQueueDriver extends BaseQueueDriver implements QueueDriverInterface {
|
|
107
|
-
constructor(options: any);
|
|
108
|
-
options: any;
|
|
109
|
-
results: any;
|
|
110
|
-
resultPromises: any;
|
|
111
|
-
queryDef: any;
|
|
112
|
-
toProcess: any;
|
|
113
|
-
recent: any;
|
|
114
|
-
active: any;
|
|
115
|
-
heartBeat: any;
|
|
116
|
-
processingCounter: any;
|
|
117
|
-
processingLocks: any;
|
|
118
|
-
createConnection(): LocalQueueDriverConnection;
|
|
119
|
-
release(client: any): void;
|
|
120
|
-
}
|
|
121
|
-
import { QueueDriverConnectionInterface } from '@cubejs-backend/base-driver';
|
|
122
|
-
import { QueueDriverInterface } from '@cubejs-backend/base-driver';
|
|
1
|
+
import { QueueDriverConnectionInterface, QueueDriverOptions } from '@cubejs-backend/base-driver';
|
|
123
2
|
import { BaseQueueDriver } from './BaseQueueDriver';
|
|
3
|
+
export declare class LocalQueueDriver extends BaseQueueDriver {
|
|
4
|
+
private readonly options;
|
|
5
|
+
constructor(options: QueueDriverOptions);
|
|
6
|
+
createConnection(): Promise<QueueDriverConnectionInterface>;
|
|
7
|
+
release(client: QueueDriverConnectionInterface): void;
|
|
8
|
+
}
|
|
124
9
|
//# sourceMappingURL=LocalQueueDriver.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalQueueDriver.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/LocalQueueDriver.
|
|
1
|
+
{"version":3,"file":"LocalQueueDriver.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/LocalQueueDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,kBAAkB,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAapD,qBAAa,gBAAiB,SAAQ,eAAe;IACnD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;gBAE1B,OAAO,EAAE,kBAAkB;IAKjC,gBAAgB,IAAI,OAAO,CAAC,8BAA8B,CAAC;IAKjE,OAAO,CAAC,MAAM,EAAE,8BAA8B,GAAG,IAAI;CAG7D"}
|
|
@@ -1,331 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.LocalQueueDriver =
|
|
7
|
-
const ramda_1 = __importDefault(require("ramda"));
|
|
8
|
-
const base_driver_1 = require("@cubejs-backend/base-driver");
|
|
3
|
+
exports.LocalQueueDriver = void 0;
|
|
9
4
|
const BaseQueueDriver_1 = require("./BaseQueueDriver");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.redisQueuePrefix = options.redisQueuePrefix;
|
|
16
|
-
this.continueWaitTimeout = options.continueWaitTimeout;
|
|
17
|
-
this.heartBeatTimeout = options.heartBeatTimeout;
|
|
18
|
-
this.concurrency = options.concurrency;
|
|
19
|
-
this.driver = driver;
|
|
20
|
-
this.results = driver.results;
|
|
21
|
-
this.resultPromises = driver.resultPromises;
|
|
22
|
-
this.queryDef = driver.queryDef;
|
|
23
|
-
this.toProcess = driver.toProcess;
|
|
24
|
-
this.recent = driver.recent;
|
|
25
|
-
this.active = driver.active;
|
|
26
|
-
this.heartBeat = driver.heartBeat;
|
|
27
|
-
this.processingCounter = driver.processingCounter;
|
|
28
|
-
this.processingLocks = driver.processingLocks;
|
|
29
|
-
}
|
|
30
|
-
async getQueriesToCancel() {
|
|
31
|
-
const [stalled, orphaned] = await Promise.all([
|
|
32
|
-
this.getStalledQueries(),
|
|
33
|
-
this.getOrphanedQueries(),
|
|
34
|
-
]);
|
|
35
|
-
return stalled.concat(orphaned);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @returns {Promise<GetActiveAndToProcessResponse>}
|
|
39
|
-
*/
|
|
40
|
-
async getActiveAndToProcess() {
|
|
41
|
-
const active = this.queueArrayAsTuple(this.active);
|
|
42
|
-
const toProcess = this.queueArrayAsTuple(this.toProcess);
|
|
43
|
-
return [
|
|
44
|
-
active,
|
|
45
|
-
toProcess
|
|
46
|
-
];
|
|
47
|
-
}
|
|
48
|
-
getResultPromise(resultListKey) {
|
|
49
|
-
if (!this.resultPromises[resultListKey]) {
|
|
50
|
-
let resolveMethod = null;
|
|
51
|
-
this.resultPromises[resultListKey] = new Promise(resolve => {
|
|
52
|
-
resolveMethod = resolve;
|
|
53
|
-
});
|
|
54
|
-
this.resultPromises[resultListKey].resolve = resolveMethod;
|
|
55
|
-
}
|
|
56
|
-
return this.resultPromises[resultListKey];
|
|
57
|
-
}
|
|
58
|
-
async getResultBlocking(queryKeyHash) {
|
|
59
|
-
// Double redisHash apply is being used here
|
|
60
|
-
const resultListKey = this.resultListKey(queryKeyHash);
|
|
61
|
-
if (!this.queryDef[queryKeyHash] && !this.resultPromises[resultListKey]) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const timeoutPromise = (timeout) => new Promise((resolve) => setTimeout(() => resolve(null), timeout));
|
|
65
|
-
const res = await Promise.race([
|
|
66
|
-
this.getResultPromise(resultListKey),
|
|
67
|
-
timeoutPromise(this.continueWaitTimeout * 1000),
|
|
68
|
-
]);
|
|
69
|
-
if (res) {
|
|
70
|
-
delete this.resultPromises[resultListKey];
|
|
71
|
-
}
|
|
72
|
-
return res;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Returns promise wich will be resolved with the specified by the
|
|
76
|
-
* queryKey query result or null if query was not added to the
|
|
77
|
-
* processing.
|
|
78
|
-
* @param {*} queryKey
|
|
79
|
-
* @returns {Promise<null | *>}
|
|
80
|
-
*/
|
|
81
|
-
async getResult(queryKey) {
|
|
82
|
-
const resultListKey = this.resultListKey(queryKey);
|
|
83
|
-
if (this.resultPromises[resultListKey] && this.resultPromises[resultListKey].resolved) {
|
|
84
|
-
return this.getResultBlocking(queryKey);
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* @protected
|
|
90
|
-
*/
|
|
91
|
-
queueArray(queueObj, orderFilterLessThan) {
|
|
92
|
-
return ramda_1.default.pipe(ramda_1.default.values, ramda_1.default.filter(orderFilterLessThan ? q => q.order < orderFilterLessThan : ramda_1.default.identity), ramda_1.default.sortBy(q => q.order), ramda_1.default.map(q => q.key))(queueObj);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* @protected
|
|
96
|
-
* @param queueObj
|
|
97
|
-
* @param orderFilterLessThan
|
|
98
|
-
* @returns {QueryKeysTuple[]}
|
|
99
|
-
*/
|
|
100
|
-
queueArrayAsTuple(queueObj, orderFilterLessThan) {
|
|
101
|
-
return ramda_1.default.pipe(ramda_1.default.values, ramda_1.default.filter(orderFilterLessThan ? q => q.order < orderFilterLessThan : ramda_1.default.identity), ramda_1.default.sortBy(q => q.order), ramda_1.default.map(q => [q.key, q.queueId]))(queueObj);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Adds specified by the queryKey query to the queue, returns tuple
|
|
105
|
-
* with the operation result.
|
|
106
|
-
*
|
|
107
|
-
* @typedef {[added: number, _b: null, _c: null, toProcessLength: number, addedTime: number]} AddedTuple
|
|
108
|
-
*
|
|
109
|
-
* @param {number} keyScore
|
|
110
|
-
* @param {*} queryKey
|
|
111
|
-
* @param {number} orphanedTime
|
|
112
|
-
* @param {string} queryHandler (for the regular query is eq to 'query')
|
|
113
|
-
* @param {*} query
|
|
114
|
-
* @param {number} priority
|
|
115
|
-
* @param {*} options
|
|
116
|
-
* @returns {AddedTuple}
|
|
117
|
-
*/
|
|
118
|
-
addToQueue(keyScore, queryKey, orphanedTime, queryHandler, query, priority, options) {
|
|
119
|
-
const queryQueueObj = {
|
|
120
|
-
queueId: options.queueId,
|
|
121
|
-
queryHandler,
|
|
122
|
-
query,
|
|
123
|
-
queryKey,
|
|
124
|
-
stageQueryKey: options.stageQueryKey,
|
|
125
|
-
priority,
|
|
126
|
-
requestId: options.requestId,
|
|
127
|
-
addedToQueueTime: new Date().getTime()
|
|
128
|
-
};
|
|
129
|
-
const key = this.redisHash(queryKey);
|
|
130
|
-
if (!this.queryDef[key]) {
|
|
131
|
-
this.queryDef[key] = queryQueueObj;
|
|
132
|
-
}
|
|
133
|
-
let added = 0;
|
|
134
|
-
if (!this.toProcess[key] && !this.active[key]) {
|
|
135
|
-
this.toProcess[key] = {
|
|
136
|
-
order: keyScore,
|
|
137
|
-
queueId: options.queueId,
|
|
138
|
-
key
|
|
139
|
-
};
|
|
140
|
-
added = 1;
|
|
141
|
-
}
|
|
142
|
-
this.recent[key] = {
|
|
143
|
-
order: orphanedTime,
|
|
144
|
-
key,
|
|
145
|
-
queueId: options.queueId,
|
|
146
|
-
};
|
|
147
|
-
return [
|
|
148
|
-
added,
|
|
149
|
-
queryQueueObj.queueId,
|
|
150
|
-
Object.keys(this.toProcess).length,
|
|
151
|
-
queryQueueObj.addedToQueueTime
|
|
152
|
-
];
|
|
153
|
-
}
|
|
154
|
-
getToProcessQueries() {
|
|
155
|
-
return this.queueArrayAsTuple(this.toProcess);
|
|
156
|
-
}
|
|
157
|
-
getActiveQueries() {
|
|
158
|
-
return this.queueArrayAsTuple(this.active);
|
|
159
|
-
}
|
|
160
|
-
async getQueryAndRemove(queryKey) {
|
|
161
|
-
const key = this.redisHash(queryKey);
|
|
162
|
-
const query = this.queryDef[key];
|
|
163
|
-
delete this.active[key];
|
|
164
|
-
delete this.heartBeat[key];
|
|
165
|
-
delete this.toProcess[key];
|
|
166
|
-
delete this.recent[key];
|
|
167
|
-
delete this.queryDef[key];
|
|
168
|
-
delete this.processingLocks[key];
|
|
169
|
-
return [query];
|
|
170
|
-
}
|
|
171
|
-
async cancelQuery(queryKey) {
|
|
172
|
-
const [query] = await this.getQueryAndRemove(queryKey);
|
|
173
|
-
return query;
|
|
174
|
-
}
|
|
175
|
-
async setResultAndRemoveQuery(queryKey, executionResult, processingId) {
|
|
176
|
-
const key = this.redisHash(queryKey);
|
|
177
|
-
if (this.processingLocks[key] !== processingId) {
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
const promise = this.getResultPromise(this.resultListKey(queryKey));
|
|
181
|
-
delete this.active[key];
|
|
182
|
-
delete this.heartBeat[key];
|
|
183
|
-
delete this.toProcess[key];
|
|
184
|
-
delete this.recent[key];
|
|
185
|
-
delete this.queryDef[key];
|
|
186
|
-
delete this.processingLocks[key];
|
|
187
|
-
promise.resolved = true;
|
|
188
|
-
promise.resolve(executionResult);
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
getNextProcessingId() {
|
|
192
|
-
this.processingCounter.counter = this.processingCounter.counter ? this.processingCounter.counter + 1 : 1;
|
|
193
|
-
return this.processingCounter.counter;
|
|
194
|
-
}
|
|
195
|
-
getOrphanedQueries() {
|
|
196
|
-
return this.queueArrayAsTuple(this.recent, new Date().getTime());
|
|
197
|
-
}
|
|
198
|
-
getStalledQueries() {
|
|
199
|
-
return this.queueArrayAsTuple(this.heartBeat, new Date().getTime() - this.heartBeatTimeout * 1000);
|
|
200
|
-
}
|
|
201
|
-
async getQueryStageState(onlyKeys) {
|
|
202
|
-
return [this.queueArray(this.active), this.queueArray(this.toProcess), onlyKeys ? {} : ramda_1.default.clone(this.queryDef)];
|
|
203
|
-
}
|
|
204
|
-
async getQueryDef(queryKey) {
|
|
205
|
-
return this.queryDef[queryKey];
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Updates heart beat for the processing query by its `queryKey`.
|
|
209
|
-
*
|
|
210
|
-
* @param {string} queryKey
|
|
211
|
-
*/
|
|
212
|
-
updateHeartBeat(queryKey) {
|
|
213
|
-
const key = this.redisHash(queryKey);
|
|
214
|
-
if (this.heartBeat[key]) {
|
|
215
|
-
this.heartBeat[key] = { key, order: new Date().getTime() };
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
retrieveForProcessing(queryKey, processingId) {
|
|
219
|
-
const key = this.redisHash(queryKey);
|
|
220
|
-
let lockAcquired = false;
|
|
221
|
-
if (!this.processingLocks[key]) {
|
|
222
|
-
this.processingLocks[key] = processingId;
|
|
223
|
-
lockAcquired = true;
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
return null;
|
|
227
|
-
}
|
|
228
|
-
let added = 0;
|
|
229
|
-
if (Object.keys(this.active).length < this.concurrency && !this.active[key]) {
|
|
230
|
-
this.active[key] = { key, order: processingId, queueId: processingId };
|
|
231
|
-
delete this.toProcess[key];
|
|
232
|
-
added = 1;
|
|
233
|
-
}
|
|
234
|
-
this.heartBeat[key] = { key, order: new Date().getTime() };
|
|
235
|
-
return [
|
|
236
|
-
added,
|
|
237
|
-
this.queryDef[key]?.queueId,
|
|
238
|
-
this.queueArray(this.active),
|
|
239
|
-
Object.keys(this.toProcess).length,
|
|
240
|
-
this.queryDef[key],
|
|
241
|
-
lockAcquired
|
|
242
|
-
];
|
|
243
|
-
}
|
|
244
|
-
freeProcessingLock(queryKey, processingId, activated) {
|
|
245
|
-
const key = this.redisHash(queryKey);
|
|
246
|
-
if (this.processingLocks[key] === processingId) {
|
|
247
|
-
delete this.processingLocks[key];
|
|
248
|
-
if (activated) {
|
|
249
|
-
delete this.active[key];
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
async optimisticQueryUpdate(queryKey, toUpdate, processingId) {
|
|
254
|
-
const key = this.redisHash(queryKey);
|
|
255
|
-
if (this.processingLocks[key] !== processingId) {
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
this.queryDef[key] = { ...this.queryDef[key], ...toUpdate };
|
|
259
|
-
return true;
|
|
260
|
-
}
|
|
261
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
262
|
-
release() {
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Returns cache key to the specified by the queryKey query and the
|
|
266
|
-
* specified by the suffix query state.
|
|
267
|
-
* @param {*} queryKey
|
|
268
|
-
* @param {string} suffix
|
|
269
|
-
* @returns {string}
|
|
270
|
-
*/
|
|
271
|
-
queryRedisKey(queryKey, suffix) {
|
|
272
|
-
return `${this.redisQueuePrefix}_${this.redisHash(queryKey)}_${suffix}`;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Returns cache key to the cached query result.
|
|
276
|
-
* @param {*} queryKey
|
|
277
|
-
* @returns {string}
|
|
278
|
-
*/
|
|
279
|
-
resultListKey(queryKey) {
|
|
280
|
-
return this.queryRedisKey(queryKey, 'RESULT');
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Returns hash sum of the query specified by the queryKey.
|
|
284
|
-
* @param {*} queryKey
|
|
285
|
-
* @returns {string}
|
|
286
|
-
*/
|
|
287
|
-
redisHash(queryKey) {
|
|
288
|
-
return this.driver.redisHash(queryKey);
|
|
5
|
+
const LocalQueueDriverConnection_1 = require("./LocalQueueDriverConnection");
|
|
6
|
+
const sharedState = {};
|
|
7
|
+
function getState(prefix) {
|
|
8
|
+
if (!sharedState[prefix]) {
|
|
9
|
+
sharedState[prefix] = new LocalQueueDriverConnection_1.LocalQueueDriverConnectionState();
|
|
289
10
|
}
|
|
11
|
+
return sharedState[prefix];
|
|
290
12
|
}
|
|
291
|
-
exports.LocalQueueDriverConnection = LocalQueueDriverConnection;
|
|
292
|
-
const results = {};
|
|
293
|
-
const resultPromises = {};
|
|
294
|
-
const queryDef = {};
|
|
295
|
-
const toProcess = {};
|
|
296
|
-
const recent = {};
|
|
297
|
-
const active = {};
|
|
298
|
-
const heartBeat = {};
|
|
299
|
-
const processingCounters = {};
|
|
300
|
-
const processingLocks = {};
|
|
301
|
-
/**
|
|
302
|
-
* @implements {QueueDriverInterface}
|
|
303
|
-
*/
|
|
304
13
|
class LocalQueueDriver extends BaseQueueDriver_1.BaseQueueDriver {
|
|
14
|
+
options;
|
|
305
15
|
constructor(options) {
|
|
306
|
-
super(options.processUid);
|
|
16
|
+
super(options.processUid || 'local');
|
|
307
17
|
this.options = options;
|
|
308
|
-
results[options.redisQueuePrefix] = results[options.redisQueuePrefix] || {};
|
|
309
|
-
resultPromises[options.redisQueuePrefix] = resultPromises[options.redisQueuePrefix] || {};
|
|
310
|
-
queryDef[options.redisQueuePrefix] = queryDef[options.redisQueuePrefix] || {};
|
|
311
|
-
toProcess[options.redisQueuePrefix] = toProcess[options.redisQueuePrefix] || {};
|
|
312
|
-
recent[options.redisQueuePrefix] = recent[options.redisQueuePrefix] || {};
|
|
313
|
-
active[options.redisQueuePrefix] = active[options.redisQueuePrefix] || {};
|
|
314
|
-
heartBeat[options.redisQueuePrefix] = heartBeat[options.redisQueuePrefix] || {};
|
|
315
|
-
processingCounters[options.redisQueuePrefix] = processingCounters[options.redisQueuePrefix] || {};
|
|
316
|
-
processingLocks[options.redisQueuePrefix] = processingLocks[options.redisQueuePrefix] || {};
|
|
317
|
-
this.results = results[options.redisQueuePrefix];
|
|
318
|
-
this.resultPromises = resultPromises[options.redisQueuePrefix];
|
|
319
|
-
this.queryDef = queryDef[options.redisQueuePrefix];
|
|
320
|
-
this.toProcess = toProcess[options.redisQueuePrefix];
|
|
321
|
-
this.recent = recent[options.redisQueuePrefix];
|
|
322
|
-
this.active = active[options.redisQueuePrefix];
|
|
323
|
-
this.heartBeat = heartBeat[options.redisQueuePrefix];
|
|
324
|
-
this.processingCounter = processingCounters[options.redisQueuePrefix];
|
|
325
|
-
this.processingLocks = processingLocks[options.redisQueuePrefix];
|
|
326
18
|
}
|
|
327
|
-
createConnection() {
|
|
328
|
-
|
|
19
|
+
async createConnection() {
|
|
20
|
+
const state = getState(this.options.redisQueuePrefix);
|
|
21
|
+
return new LocalQueueDriverConnection_1.LocalQueueDriverConnection(this, state, this.options);
|
|
329
22
|
}
|
|
330
23
|
release(client) {
|
|
331
24
|
client.release();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalQueueDriver.js","sourceRoot":"","sources":["../../../src/orchestrator/LocalQueueDriver.js"],"names":[],"mappings":";;;;;;AAAA,kDAAsB;AACtB,6DAAmG;AACnG,uDAAoD;AAEpD;;GAEG;AACH,MAAa,0BAA0B;IACrC,YAAY,MAAM,EAAE,OAAO;QACzB,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;QACvD,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO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"],"names":[],"mappings":";;;AAIA,uDAAoD;AACpD,6EAA2G;AAE3G,MAAM,WAAW,GAAoD,EAAE,CAAC;AAExE,SAAS,QAAQ,CAAC,MAAc;IAC9B,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;QACxB,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,4DAA+B,EAAE,CAAC;KAC7D;IAED,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED,MAAa,gBAAiB,SAAQ,iCAAe;IAClC,OAAO,CAAqB;IAE7C,YAAmB,OAA2B;QAC5C,KAAK,CAAC,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,gBAAgB;QAC3B,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACtD,OAAO,IAAI,uDAA0B,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACnE,CAAC;IAEM,OAAO,CAAC,MAAsC;QACnD,MAAM,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;CACF;AAhBD,4CAgBC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { QueueDriverConnectionInterface, QueryKey, QueryKeyHash, QueueId, ProcessingId, QueryDef, AddToQueueQuery, AddToQueueOptions, AddToQueueResponse, QueryKeysTuple, GetActiveAndToProcessResponse, QueryStageStateResponse, RetrieveForProcessingResponse, QueueDriverOptions } from '@cubejs-backend/base-driver';
|
|
2
|
+
import { LocalQueueDriver } from './LocalQueueDriver';
|
|
3
|
+
export interface QueueItem {
|
|
4
|
+
order: number;
|
|
5
|
+
key: QueryKeyHash;
|
|
6
|
+
queueId: QueueId;
|
|
7
|
+
}
|
|
8
|
+
export interface QueryDefObject {
|
|
9
|
+
queueId: QueueId;
|
|
10
|
+
queryHandler: string;
|
|
11
|
+
query: any;
|
|
12
|
+
queryKey: QueryKey;
|
|
13
|
+
stageQueryKey: string;
|
|
14
|
+
priority: number;
|
|
15
|
+
requestId: string;
|
|
16
|
+
addedToQueueTime: number;
|
|
17
|
+
}
|
|
18
|
+
export interface PromiseWithResolve<T = any> extends Promise<T> {
|
|
19
|
+
resolve?: (value: T) => void;
|
|
20
|
+
resolved?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ProcessingCounter {
|
|
23
|
+
counter: number;
|
|
24
|
+
}
|
|
25
|
+
export declare class LocalQueueDriverConnectionState {
|
|
26
|
+
resultPromises: Record<QueryKeyHash, PromiseWithResolve>;
|
|
27
|
+
queryDef: Record<QueryKeyHash, QueryDefObject>;
|
|
28
|
+
toProcess: Record<QueryKeyHash, QueueItem>;
|
|
29
|
+
recent: Record<QueryKeyHash, QueueItem>;
|
|
30
|
+
active: Record<QueryKeyHash, QueueItem>;
|
|
31
|
+
heartBeat: Record<QueryKeyHash, QueueItem>;
|
|
32
|
+
processingCounter: ProcessingCounter;
|
|
33
|
+
processingLocks: Record<QueryKeyHash, any>;
|
|
34
|
+
}
|
|
35
|
+
export declare class LocalQueueDriverConnection implements QueueDriverConnectionInterface {
|
|
36
|
+
private redisQueuePrefix;
|
|
37
|
+
private continueWaitTimeout;
|
|
38
|
+
private heartBeatTimeout;
|
|
39
|
+
private concurrency;
|
|
40
|
+
private driver;
|
|
41
|
+
private state;
|
|
42
|
+
constructor(driver: LocalQueueDriver, state: LocalQueueDriverConnectionState, options: QueueDriverOptions);
|
|
43
|
+
getQueriesToCancel(): Promise<QueryKeysTuple[]>;
|
|
44
|
+
getActiveAndToProcess(): Promise<GetActiveAndToProcessResponse>;
|
|
45
|
+
getResultPromise(resultListKey: string): PromiseWithResolve;
|
|
46
|
+
getResultBlocking(queryKeyHash: QueryKeyHash, _queueId?: QueueId): Promise<any>;
|
|
47
|
+
getResult(queryKey: QueryKey): Promise<any>;
|
|
48
|
+
protected queueArray(queueObj: Record<QueryKeyHash, QueueItem>, orderFilterLessThan?: number): string[];
|
|
49
|
+
protected queueArrayAsTuple(queueObj: Record<QueryKeyHash, QueueItem>, orderFilterLessThan?: number): QueryKeysTuple[];
|
|
50
|
+
addToQueue(keyScore: number, queryKey: QueryKey, orphanedTime: number, queryHandler: string, query: AddToQueueQuery, priority: number, options: AddToQueueOptions): Promise<AddToQueueResponse>;
|
|
51
|
+
getToProcessQueries(): Promise<QueryKeysTuple[]>;
|
|
52
|
+
getActiveQueries(): Promise<QueryKeysTuple[]>;
|
|
53
|
+
getQueryAndRemove(queryKeyHash: QueryKeyHash, _queueId?: QueueId | null): Promise<[QueryDef]>;
|
|
54
|
+
cancelQuery(queryKey: QueryKey, queueId?: QueueId | null): Promise<QueryDef | null>;
|
|
55
|
+
setResultAndRemoveQuery(queryKeyHash: QueryKeyHash, executionResult: any, processingId: ProcessingId, _queueId?: QueueId | null): Promise<boolean>;
|
|
56
|
+
getNextProcessingId(): Promise<ProcessingId>;
|
|
57
|
+
getOrphanedQueries(): Promise<QueryKeysTuple[]>;
|
|
58
|
+
getStalledQueries(): Promise<QueryKeysTuple[]>;
|
|
59
|
+
getQueryStageState(onlyKeys: boolean): Promise<QueryStageStateResponse>;
|
|
60
|
+
getQueryDef(queryKeyHash: QueryKeyHash, _queueId?: QueueId | null): Promise<QueryDef | null>;
|
|
61
|
+
updateHeartBeat(queryKeyHash: QueryKeyHash, queueId?: QueueId | null): Promise<void>;
|
|
62
|
+
retrieveForProcessing(queryKeyHash: QueryKeyHash, processingId: ProcessingId): Promise<RetrieveForProcessingResponse>;
|
|
63
|
+
freeProcessingLock(queryKeyHash: QueryKeyHash, processingId: ProcessingId, activated: any): Promise<void>;
|
|
64
|
+
optimisticQueryUpdate(queryKeyHash: QueryKeyHash, toUpdate: any, processingId: ProcessingId, _queueId?: QueueId | null): Promise<boolean>;
|
|
65
|
+
release(): void;
|
|
66
|
+
queryRedisKey(queryKey: QueryKey, suffix: string): string;
|
|
67
|
+
resultListKey(queryKey: QueryKey | QueryKeyHash): string;
|
|
68
|
+
redisHash(queryKey: QueryKey): QueryKeyHash;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=LocalQueueDriverConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalQueueDriverConnection.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/LocalQueueDriverConnection.ts"],"names":[],"mappings":"AACA,OAAO,EACL,8BAA8B,EAC9B,QAAQ,EACR,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,6BAA6B,EAC7B,uBAAuB,EACvB,6BAA6B,EAC7B,kBAAkB,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,YAAY,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,EAAE,QAAQ,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,OAAO,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,+BAA+B;IACnC,cAAc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