sqlite-executor 4.0.1 → 4.0.3
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/cjs/core/pipelineEngine.d.cts +2 -0
- package/dist/cjs/core/process.d.cts +16 -1
- package/dist/cjs/core/taskWorker.d.cts +6 -0
- package/dist/cjs/index.cjs +78 -17
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/core/pipelineEngine.d.mts +2 -0
- package/dist/esm/core/process.d.mts +16 -1
- package/dist/esm/core/taskWorker.d.mts +6 -0
- package/dist/esm/index.mjs +78 -17
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -12,6 +12,8 @@ export interface PipelineEngineOptions {
|
|
|
12
12
|
logger?: { error?: (...args: any[]) => void };
|
|
13
13
|
/** 管线化批量大小,控制一次 stdin.write 合并几条语句,默认 10 */
|
|
14
14
|
batchSize?: number;
|
|
15
|
+
/** 最大 inflight 任务数,默认 50 */
|
|
16
|
+
maxInflight?: number;
|
|
15
17
|
/** 任务超时时的回调 */
|
|
16
18
|
onTaskTimeout?: (task: any) => void;
|
|
17
19
|
}
|
|
@@ -11,8 +11,14 @@ export declare class ProcessManager {
|
|
|
11
11
|
* @param options.initMode 初始化模式
|
|
12
12
|
* - `"wal"` (默认):启动时通过 `-cmd` 设置 WAL 模式 + busy_timeout
|
|
13
13
|
* - `"none"`:不添加任何初始化参数(适用于 reader,直接继承数据库已有 WAL 模式)
|
|
14
|
+
* @param options.onDrain drain 回调,当 stdin pipe 重新可写时调用
|
|
14
15
|
*/
|
|
15
|
-
constructor(options?: {
|
|
16
|
+
constructor(options?: {
|
|
17
|
+
binary?: string;
|
|
18
|
+
database?: string;
|
|
19
|
+
initMode?: "wal" | "none";
|
|
20
|
+
onDrain?: () => void;
|
|
21
|
+
});
|
|
16
22
|
|
|
17
23
|
/** 当前使用的 sqlite3 可执行文件路径 */
|
|
18
24
|
get binary(): string;
|
|
@@ -20,6 +26,12 @@ export declare class ProcessManager {
|
|
|
20
26
|
/** 底层子进程实例,未启动时为 null */
|
|
21
27
|
get process(): ChildProcess | null;
|
|
22
28
|
|
|
29
|
+
/**
|
|
30
|
+
* drain 状态,true 表示 OS pipe 已满,应暂停写入 stdin。
|
|
31
|
+
* 当 pipe 重新可写时 drain 事件触发,draining 恢复为 false。
|
|
32
|
+
*/
|
|
33
|
+
get draining(): boolean;
|
|
34
|
+
|
|
23
35
|
/**
|
|
24
36
|
* 启动子进程(json 模式),返回 ChildProcess 实例。
|
|
25
37
|
* @throws {Error} 如果 binary 路径为空或文件不存在
|
|
@@ -29,6 +41,9 @@ export declare class ProcessManager {
|
|
|
29
41
|
/** 向子进程的 stdin 写入数据 */
|
|
30
42
|
write(data: string): void;
|
|
31
43
|
|
|
44
|
+
/** 注册 drain 回调,当 pipe 重新可写时被调用。 */
|
|
45
|
+
setOnDrainCallback(fn: () => void): void;
|
|
46
|
+
|
|
32
47
|
/**
|
|
33
48
|
* 终止子进程。
|
|
34
49
|
* 先尝试 SIGTERM,3 秒后未退出则 SIGKILL。
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Metrics } from "./metrics.cts";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* 单个 sqlite3 进程 Worker,支持管线化(pipelining)。
|
|
3
5
|
*
|
|
@@ -18,6 +20,8 @@ export class TaskWorker {
|
|
|
18
20
|
* @param options.name Worker 名称,用于日志和调试
|
|
19
21
|
* @param options.initMode 子进程初始化模式(参考 ProcessManager)
|
|
20
22
|
* @param options.batchSize 管线化批量大小,默认 10
|
|
23
|
+
* @param options.maxInflight 最大 inflight 任务数,默认 50
|
|
24
|
+
* @param options.metrics 指标收集器
|
|
21
25
|
*/
|
|
22
26
|
constructor(options: {
|
|
23
27
|
binary: string;
|
|
@@ -27,6 +31,8 @@ export class TaskWorker {
|
|
|
27
31
|
name?: string;
|
|
28
32
|
initMode?: "wal" | "none";
|
|
29
33
|
batchSize?: number;
|
|
34
|
+
maxInflight?: number;
|
|
35
|
+
metrics?: Metrics;
|
|
30
36
|
});
|
|
31
37
|
|
|
32
38
|
/** Worker 名称 */
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -465,6 +465,7 @@ function createRowStreamParser(onRow) {
|
|
|
465
465
|
}
|
|
466
466
|
var TOKEN_COLUMN = "__sqlite_executor_token__";
|
|
467
467
|
var DEFAULT_BATCH_SIZE = 10;
|
|
468
|
+
var DEFAULT_MAX_INFLIGHT = 50;
|
|
468
469
|
function stream_check_private_redeclaration(obj, privateCollection) {
|
|
469
470
|
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
470
471
|
}
|
|
@@ -979,11 +980,11 @@ function _ts_generator(thisArg, body) {
|
|
|
979
980
|
}
|
|
980
981
|
}
|
|
981
982
|
var GRACEFUL_SHUTDOWN_TIMEOUT = 5000;
|
|
982
|
-
var _binary = /*#__PURE__*/ new WeakMap(), _database = /*#__PURE__*/ new WeakMap(), _proc = /*#__PURE__*/ new WeakMap(), _initMode = /*#__PURE__*/ new WeakMap(), _draining = /*#__PURE__*/ new WeakMap();
|
|
983
|
+
var _binary = /*#__PURE__*/ new WeakMap(), _database = /*#__PURE__*/ new WeakMap(), _proc = /*#__PURE__*/ new WeakMap(), _initMode = /*#__PURE__*/ new WeakMap(), _draining = /*#__PURE__*/ new WeakMap(), _onDrain = /*#__PURE__*/ new WeakMap();
|
|
983
984
|
var process_ProcessManager = /*#__PURE__*/ function() {
|
|
984
985
|
"use strict";
|
|
985
986
|
function ProcessManager() {
|
|
986
|
-
var _ref = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, binary = _ref.binary, database = _ref.database, _ref_initMode = _ref.initMode, initMode = void 0 === _ref_initMode ? "wal" : _ref_initMode;
|
|
987
|
+
var _ref = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, binary = _ref.binary, database = _ref.database, _ref_initMode = _ref.initMode, initMode = void 0 === _ref_initMode ? "wal" : _ref_initMode, onDrain = _ref.onDrain;
|
|
987
988
|
process_class_call_check(this, ProcessManager);
|
|
988
989
|
process_class_private_field_init(this, _binary, {
|
|
989
990
|
writable: true,
|
|
@@ -1005,12 +1006,29 @@ var process_ProcessManager = /*#__PURE__*/ function() {
|
|
|
1005
1006
|
writable: true,
|
|
1006
1007
|
value: false
|
|
1007
1008
|
});
|
|
1009
|
+
process_class_private_field_init(this, _onDrain, {
|
|
1010
|
+
writable: true,
|
|
1011
|
+
value: void 0
|
|
1012
|
+
});
|
|
1008
1013
|
var _which;
|
|
1009
1014
|
process_class_private_field_set(this, _binary, null != (_which = which(binary)) ? _which : binary);
|
|
1010
1015
|
process_class_private_field_set(this, _database, database);
|
|
1011
1016
|
process_class_private_field_set(this, _initMode, initMode);
|
|
1017
|
+
process_class_private_field_set(this, _onDrain, null != onDrain ? onDrain : function() {});
|
|
1012
1018
|
}
|
|
1013
1019
|
process_create_class(ProcessManager, [
|
|
1020
|
+
{
|
|
1021
|
+
key: "draining",
|
|
1022
|
+
get: function() {
|
|
1023
|
+
return process_class_private_field_get(this, _draining);
|
|
1024
|
+
}
|
|
1025
|
+
},
|
|
1026
|
+
{
|
|
1027
|
+
key: "setOnDrainCallback",
|
|
1028
|
+
value: function(fn) {
|
|
1029
|
+
process_class_private_field_set(this, _onDrain, fn);
|
|
1030
|
+
}
|
|
1031
|
+
},
|
|
1014
1032
|
{
|
|
1015
1033
|
key: "binary",
|
|
1016
1034
|
get: function() {
|
|
@@ -1056,10 +1074,12 @@ var process_ProcessManager = /*#__PURE__*/ function() {
|
|
|
1056
1074
|
var _$_class_private_field_get;
|
|
1057
1075
|
var stream = null == (_$_class_private_field_get = process_class_private_field_get(this, _proc)) ? void 0 : _$_class_private_field_get.stdin;
|
|
1058
1076
|
if (!stream) return;
|
|
1059
|
-
if (
|
|
1077
|
+
if (process_class_private_field_get(this, _draining)) return;
|
|
1078
|
+
if (!stream.write(data)) {
|
|
1060
1079
|
process_class_private_field_set(this, _draining, true);
|
|
1061
1080
|
stream.once("drain", function() {
|
|
1062
1081
|
process_class_private_field_set(_this, _draining, false);
|
|
1082
|
+
process_class_private_field_get(_this, _onDrain).call(_this);
|
|
1063
1083
|
});
|
|
1064
1084
|
}
|
|
1065
1085
|
}
|
|
@@ -1078,7 +1098,7 @@ var process_ProcessManager = /*#__PURE__*/ function() {
|
|
|
1078
1098
|
2
|
|
1079
1099
|
];
|
|
1080
1100
|
timer = setTimeout(function() {
|
|
1081
|
-
|
|
1101
|
+
proc.kill();
|
|
1082
1102
|
}, GRACEFUL_SHUTDOWN_TIMEOUT);
|
|
1083
1103
|
_state.label = 1;
|
|
1084
1104
|
case 1:
|
|
@@ -1703,9 +1723,13 @@ function buildPayload(sql, token) {
|
|
|
1703
1723
|
var suffix = normalized.endsWith(";") ? "" : ";";
|
|
1704
1724
|
return "".concat(normalized).concat(suffix, "\nSELECT '").concat(token, "' AS ").concat(TOKEN_COLUMN, ";\n");
|
|
1705
1725
|
}
|
|
1726
|
+
function isTransactionControl(sql) {
|
|
1727
|
+
var s = sql.trim().toUpperCase();
|
|
1728
|
+
return "BEGIN" === s || "BEGIN TRANSACTION" === s || "COMMIT" === s || "COMMIT TRANSACTION" === s || "ROLLBACK" === s || "ROLLBACK TRANSACTION" === s || s.startsWith("BEGIN ") || s.startsWith("COMMIT ") || s.startsWith("ROLLBACK ");
|
|
1729
|
+
}
|
|
1706
1730
|
function buildBatchPayload(batch) {
|
|
1707
1731
|
var useWalBatch = batch.length > 1 && batch.every(function(t) {
|
|
1708
|
-
return "execute" === t.kind;
|
|
1732
|
+
return "execute" === t.kind && !isTransactionControl(t.sql);
|
|
1709
1733
|
});
|
|
1710
1734
|
if (useWalBatch) {
|
|
1711
1735
|
var parts = [
|
|
@@ -1829,6 +1853,8 @@ function processStreamRows(task, parsed) {
|
|
|
1829
1853
|
}
|
|
1830
1854
|
function settleTask(task, error, value, metrics) {
|
|
1831
1855
|
var _ref = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : {}, _ref_resetRowParser = _ref.resetRowParser, resetRowParser = void 0 === _ref_resetRowParser ? false : _ref_resetRowParser;
|
|
1856
|
+
if (task.settled) return;
|
|
1857
|
+
task.settled = true;
|
|
1832
1858
|
clearTimeout(task.timer);
|
|
1833
1859
|
if (resetRowParser) {
|
|
1834
1860
|
var _task_rowParser_reset, _task_rowParser;
|
|
@@ -1924,12 +1950,12 @@ function taskWorker_unsupported_iterable_to_array(o, minLen) {
|
|
|
1924
1950
|
if ("Map" === n || "Set" === n) return Array.from(n);
|
|
1925
1951
|
if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return taskWorker_array_like_to_array(o, minLen);
|
|
1926
1952
|
}
|
|
1927
|
-
var _processManager = /*#__PURE__*/ new WeakMap(), _pendingQueue = /*#__PURE__*/ new WeakMap(), _inflightTasks = /*#__PURE__*/ new WeakMap(), _pendingFinalizeTasks = /*#__PURE__*/ new WeakMap(), _scheduledFinalize = /*#__PURE__*/ new WeakMap(), _valueParser = /*#__PURE__*/ new WeakMap(), _statementTimeout = /*#__PURE__*/ new WeakMap(), _logger = /*#__PURE__*/ new WeakMap(), _name = /*#__PURE__*/ new WeakMap(), _batchSize = /*#__PURE__*/ new WeakMap(), _metrics = /*#__PURE__*/ new WeakMap(), _startProcess = /*#__PURE__*/ new WeakSet(), _pumpQueue = /*#__PURE__*/ new WeakSet(), _handleParsedValue = /*#__PURE__*/ new WeakSet(), _scheduleFinalizeCheck = /*#__PURE__*/ new WeakSet(), _handleStderrChunk = /*#__PURE__*/ new WeakSet(), _handleTaskTimeout = /*#__PURE__*/ new WeakSet(), _settleTask = /*#__PURE__*/ new WeakSet(), _rejectAll = /*#__PURE__*/ new WeakSet();
|
|
1953
|
+
var _processManager = /*#__PURE__*/ new WeakMap(), _pendingQueue = /*#__PURE__*/ new WeakMap(), _inflightTasks = /*#__PURE__*/ new WeakMap(), _pendingFinalizeTasks = /*#__PURE__*/ new WeakMap(), _scheduledFinalize = /*#__PURE__*/ new WeakMap(), _valueParser = /*#__PURE__*/ new WeakMap(), _statementTimeout = /*#__PURE__*/ new WeakMap(), _logger = /*#__PURE__*/ new WeakMap(), _name = /*#__PURE__*/ new WeakMap(), _batchSize = /*#__PURE__*/ new WeakMap(), _maxInflight = /*#__PURE__*/ new WeakMap(), _metrics = /*#__PURE__*/ new WeakMap(), _startProcess = /*#__PURE__*/ new WeakSet(), _pumpQueue = /*#__PURE__*/ new WeakSet(), _handleParsedValue = /*#__PURE__*/ new WeakSet(), _scheduleFinalizeCheck = /*#__PURE__*/ new WeakSet(), _handleStderrChunk = /*#__PURE__*/ new WeakSet(), _handleTaskTimeout = /*#__PURE__*/ new WeakSet(), _settleTask = /*#__PURE__*/ new WeakSet(), _rejectAll = /*#__PURE__*/ new WeakSet();
|
|
1928
1954
|
var taskWorker_TaskWorker = /*#__PURE__*/ function() {
|
|
1929
1955
|
"use strict";
|
|
1930
1956
|
function TaskWorker(param) {
|
|
1931
1957
|
var _this = this;
|
|
1932
|
-
var binary = param.binary, database = param.database, statementTimeout = param.statementTimeout, logger = param.logger, name = param.name, initMode = param.initMode, _param_batchSize = param.batchSize, batchSize = void 0 === _param_batchSize ? DEFAULT_BATCH_SIZE : _param_batchSize, metrics = param.metrics;
|
|
1958
|
+
var binary = param.binary, database = param.database, statementTimeout = param.statementTimeout, logger = param.logger, name = param.name, initMode = param.initMode, _param_batchSize = param.batchSize, batchSize = void 0 === _param_batchSize ? DEFAULT_BATCH_SIZE : _param_batchSize, _param_maxInflight = param.maxInflight, maxInflight = void 0 === _param_maxInflight ? DEFAULT_MAX_INFLIGHT : _param_maxInflight, metrics = param.metrics;
|
|
1933
1959
|
taskWorker_class_call_check(this, TaskWorker);
|
|
1934
1960
|
taskWorker_class_private_method_init(this, _startProcess);
|
|
1935
1961
|
taskWorker_class_private_method_init(this, _pumpQueue);
|
|
@@ -1979,6 +2005,10 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
|
|
|
1979
2005
|
writable: true,
|
|
1980
2006
|
value: void 0
|
|
1981
2007
|
});
|
|
2008
|
+
taskWorker_class_private_field_init(this, _maxInflight, {
|
|
2009
|
+
writable: true,
|
|
2010
|
+
value: void 0
|
|
2011
|
+
});
|
|
1982
2012
|
taskWorker_class_private_field_init(this, _metrics, {
|
|
1983
2013
|
writable: true,
|
|
1984
2014
|
value: void 0
|
|
@@ -1987,11 +2017,15 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
|
|
|
1987
2017
|
taskWorker_class_private_field_set(this, _statementTimeout, statementTimeout);
|
|
1988
2018
|
taskWorker_class_private_field_set(this, _logger, logger);
|
|
1989
2019
|
taskWorker_class_private_field_set(this, _batchSize, batchSize);
|
|
2020
|
+
taskWorker_class_private_field_set(this, _maxInflight, maxInflight);
|
|
1990
2021
|
taskWorker_class_private_field_set(this, _metrics, metrics);
|
|
1991
2022
|
taskWorker_class_private_field_set(this, _processManager, new process_ProcessManager({
|
|
1992
2023
|
binary: binary,
|
|
1993
2024
|
database: database,
|
|
1994
|
-
initMode: initMode
|
|
2025
|
+
initMode: initMode,
|
|
2026
|
+
onDrain: function() {
|
|
2027
|
+
return taskWorker_class_private_method_get(_this, _pumpQueue, pumpQueue).call(_this);
|
|
2028
|
+
}
|
|
1995
2029
|
}));
|
|
1996
2030
|
taskWorker_class_private_field_set(this, _valueParser, createJsonValueParser(function(raw) {
|
|
1997
2031
|
return taskWorker_class_private_method_get(_this, _handleParsedValue, handleParsedValue).call(_this, raw);
|
|
@@ -2033,6 +2067,7 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
|
|
|
2033
2067
|
onRow: null != (_config_onRow = config.onRow) ? _config_onRow : null,
|
|
2034
2068
|
consumerError: null,
|
|
2035
2069
|
stderrText: "",
|
|
2070
|
+
settled: false,
|
|
2036
2071
|
errorScheduled: false,
|
|
2037
2072
|
timer: null,
|
|
2038
2073
|
startTime: 0
|
|
@@ -2076,8 +2111,10 @@ function startProcess() {
|
|
|
2076
2111
|
function pumpQueue() {
|
|
2077
2112
|
var _this = this;
|
|
2078
2113
|
var _$_class_private_field_get;
|
|
2114
|
+
if (taskWorker_class_private_field_get(this, _processManager).draining) return;
|
|
2115
|
+
if (taskWorker_class_private_field_get(this, _inflightTasks).length >= taskWorker_class_private_field_get(this, _maxInflight)) return;
|
|
2079
2116
|
var batch = [];
|
|
2080
|
-
while(batch.length < taskWorker_class_private_field_get(this, _batchSize) && !taskWorker_class_private_field_get(this, _pendingQueue).isEmpty()){
|
|
2117
|
+
while(batch.length < taskWorker_class_private_field_get(this, _batchSize) && !taskWorker_class_private_field_get(this, _pendingQueue).isEmpty() && taskWorker_class_private_field_get(this, _inflightTasks).length + batch.length < taskWorker_class_private_field_get(this, _maxInflight)){
|
|
2081
2118
|
var task = taskWorker_class_private_field_get(this, _pendingQueue).peek();
|
|
2082
2119
|
if ("stream" === task.kind && (batch.length > 0 || taskWorker_class_private_field_get(this, _inflightTasks).length > 0)) break;
|
|
2083
2120
|
taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
|
|
@@ -2123,6 +2160,7 @@ function handleParsedValue(raw) {
|
|
|
2123
2160
|
if (isSentinelRow(parsed, task.token)) {
|
|
2124
2161
|
clearTimeout(task.timer);
|
|
2125
2162
|
taskWorker_class_private_field_get(this, _inflightTasks).shift();
|
|
2163
|
+
if (task.timedout) return void taskWorker_class_private_method_get(this, _pumpQueue, pumpQueue).call(this);
|
|
2126
2164
|
if (task.stderrText) {
|
|
2127
2165
|
taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, new Error(task.stderrText.trim()), void 0);
|
|
2128
2166
|
taskWorker_class_private_method_get(this, _pumpQueue, pumpQueue).call(this);
|
|
@@ -2191,9 +2229,12 @@ function taskWorker_handleStderrChunk(chunk) {
|
|
|
2191
2229
|
}
|
|
2192
2230
|
function handleTaskTimeout(task) {
|
|
2193
2231
|
var _$_class_private_field_get;
|
|
2194
|
-
if (
|
|
2232
|
+
if (task.settled) return;
|
|
2233
|
+
task.timedout = true;
|
|
2234
|
+
clearTimeout(task.timer);
|
|
2235
|
+
task.timer = null;
|
|
2195
2236
|
null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _metrics)) || _$_class_private_field_get.incrementTasksTimeout();
|
|
2196
|
-
taskWorker_class_private_method_get(this,
|
|
2237
|
+
taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, createTimeoutError(task.timeout, task.sql), void 0);
|
|
2197
2238
|
}
|
|
2198
2239
|
function settleTask1(task, error, value) {
|
|
2199
2240
|
settleTask(task, error, value, taskWorker_class_private_field_get(this, _metrics));
|
|
@@ -2958,16 +2999,17 @@ function pipelineEngine_unsupported_iterable_to_array(o, minLen) {
|
|
|
2958
2999
|
if ("Map" === n || "Set" === n) return Array.from(n);
|
|
2959
3000
|
if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return pipelineEngine_array_like_to_array(o, minLen);
|
|
2960
3001
|
}
|
|
2961
|
-
var _queue = /*#__PURE__*/ new WeakMap(), pipelineEngine_inflightTasks = /*#__PURE__*/ new WeakMap(), pipelineEngine_pendingFinalizeTasks = /*#__PURE__*/ new WeakMap(), pipelineEngine_scheduledFinalize = /*#__PURE__*/ new WeakMap(), _sharedValueParser = /*#__PURE__*/ new WeakMap(), pipelineEngine_processManager = /*#__PURE__*/ new WeakMap(), pipelineEngine_metrics = /*#__PURE__*/ new WeakMap(), pipelineEngine_statementTimeout = /*#__PURE__*/ new WeakMap(), pipelineEngine_logger = /*#__PURE__*/ new WeakMap(), pipelineEngine_batchSize = /*#__PURE__*/ new WeakMap(), _onTaskTimeout = /*#__PURE__*/ new WeakMap(), _active = /*#__PURE__*/ new WeakMap(), core_pipelineEngine_pumpQueue = /*#__PURE__*/ new WeakSet(), pipelineEngine_handleParsedValue = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_scheduleFinalizeCheck = /*#__PURE__*/ new WeakSet(), pipelineEngine_settleTask = /*#__PURE__*/ new WeakSet();
|
|
3002
|
+
var _queue = /*#__PURE__*/ new WeakMap(), pipelineEngine_inflightTasks = /*#__PURE__*/ new WeakMap(), pipelineEngine_pendingFinalizeTasks = /*#__PURE__*/ new WeakMap(), pipelineEngine_scheduledFinalize = /*#__PURE__*/ new WeakMap(), _sharedValueParser = /*#__PURE__*/ new WeakMap(), pipelineEngine_processManager = /*#__PURE__*/ new WeakMap(), pipelineEngine_metrics = /*#__PURE__*/ new WeakMap(), pipelineEngine_statementTimeout = /*#__PURE__*/ new WeakMap(), pipelineEngine_logger = /*#__PURE__*/ new WeakMap(), pipelineEngine_batchSize = /*#__PURE__*/ new WeakMap(), pipelineEngine_maxInflight = /*#__PURE__*/ new WeakMap(), _onTaskTimeout = /*#__PURE__*/ new WeakMap(), _active = /*#__PURE__*/ new WeakMap(), core_pipelineEngine_pumpQueue = /*#__PURE__*/ new WeakSet(), pipelineEngine_handleParsedValue = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_scheduleFinalizeCheck = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_handleTaskTimeout = /*#__PURE__*/ new WeakSet(), pipelineEngine_settleTask = /*#__PURE__*/ new WeakSet();
|
|
2962
3003
|
var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
|
|
2963
3004
|
"use strict";
|
|
2964
3005
|
function PipelineEngine(processManager, param) {
|
|
2965
3006
|
var _this = this;
|
|
2966
|
-
var metrics = param.metrics, statementTimeout = param.statementTimeout, logger = param.logger, _param_batchSize = param.batchSize, batchSize = void 0 === _param_batchSize ? DEFAULT_BATCH_SIZE : _param_batchSize, onTaskTimeout = param.onTaskTimeout;
|
|
3007
|
+
var metrics = param.metrics, statementTimeout = param.statementTimeout, logger = param.logger, _param_batchSize = param.batchSize, batchSize = void 0 === _param_batchSize ? DEFAULT_BATCH_SIZE : _param_batchSize, _param_maxInflight = param.maxInflight, maxInflight = void 0 === _param_maxInflight ? DEFAULT_MAX_INFLIGHT : _param_maxInflight, onTaskTimeout = param.onTaskTimeout;
|
|
2967
3008
|
pipelineEngine_class_call_check(this, PipelineEngine);
|
|
2968
3009
|
pipelineEngine_class_private_method_init(this, core_pipelineEngine_pumpQueue);
|
|
2969
3010
|
pipelineEngine_class_private_method_init(this, pipelineEngine_handleParsedValue);
|
|
2970
3011
|
pipelineEngine_class_private_method_init(this, core_pipelineEngine_scheduleFinalizeCheck);
|
|
3012
|
+
pipelineEngine_class_private_method_init(this, core_pipelineEngine_handleTaskTimeout);
|
|
2971
3013
|
pipelineEngine_class_private_method_init(this, pipelineEngine_settleTask);
|
|
2972
3014
|
pipelineEngine_class_private_field_init(this, _queue, {
|
|
2973
3015
|
writable: true,
|
|
@@ -3009,6 +3051,10 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
|
|
|
3009
3051
|
writable: true,
|
|
3010
3052
|
value: void 0
|
|
3011
3053
|
});
|
|
3054
|
+
pipelineEngine_class_private_field_init(this, pipelineEngine_maxInflight, {
|
|
3055
|
+
writable: true,
|
|
3056
|
+
value: void 0
|
|
3057
|
+
});
|
|
3012
3058
|
pipelineEngine_class_private_field_init(this, _onTaskTimeout, {
|
|
3013
3059
|
writable: true,
|
|
3014
3060
|
value: void 0
|
|
@@ -3022,10 +3068,14 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
|
|
|
3022
3068
|
pipelineEngine_class_private_field_set(this, pipelineEngine_statementTimeout, statementTimeout);
|
|
3023
3069
|
pipelineEngine_class_private_field_set(this, pipelineEngine_logger, logger);
|
|
3024
3070
|
pipelineEngine_class_private_field_set(this, pipelineEngine_batchSize, batchSize);
|
|
3071
|
+
pipelineEngine_class_private_field_set(this, pipelineEngine_maxInflight, maxInflight);
|
|
3025
3072
|
pipelineEngine_class_private_field_set(this, _onTaskTimeout, null != onTaskTimeout ? onTaskTimeout : function() {});
|
|
3026
3073
|
pipelineEngine_class_private_field_set(this, _sharedValueParser, createJsonValueParser(function(raw) {
|
|
3027
3074
|
return pipelineEngine_class_private_method_get(_this, pipelineEngine_handleParsedValue, core_pipelineEngine_handleParsedValue).call(_this, raw);
|
|
3028
3075
|
}));
|
|
3076
|
+
pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).setOnDrainCallback(function() {
|
|
3077
|
+
return pipelineEngine_class_private_method_get(_this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(_this);
|
|
3078
|
+
});
|
|
3029
3079
|
}
|
|
3030
3080
|
pipelineEngine_create_class(PipelineEngine, [
|
|
3031
3081
|
{
|
|
@@ -3158,8 +3208,10 @@ function pipelineEngine_pumpQueue() {
|
|
|
3158
3208
|
var _this = this;
|
|
3159
3209
|
var _$_class_private_field_get;
|
|
3160
3210
|
if (!pipelineEngine_class_private_field_get(this, _active)) return;
|
|
3211
|
+
if (pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).draining) return;
|
|
3212
|
+
if (pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length >= pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)) return;
|
|
3161
3213
|
var batch = [];
|
|
3162
|
-
while(batch.length < pipelineEngine_class_private_field_get(this, pipelineEngine_batchSize) && !pipelineEngine_class_private_field_get(this, _queue).isEmpty()){
|
|
3214
|
+
while(batch.length < pipelineEngine_class_private_field_get(this, pipelineEngine_batchSize) && !pipelineEngine_class_private_field_get(this, _queue).isEmpty() && pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length + batch.length < pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)){
|
|
3163
3215
|
var task = pipelineEngine_class_private_field_get(this, _queue).peek();
|
|
3164
3216
|
if ("stream" === task.kind && (batch.length > 0 || pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length > 0)) break;
|
|
3165
3217
|
pipelineEngine_class_private_field_get(this, _queue).dequeue();
|
|
@@ -3174,8 +3226,7 @@ function pipelineEngine_pumpQueue() {
|
|
|
3174
3226
|
var task = _step.value;
|
|
3175
3227
|
task.startTime = now;
|
|
3176
3228
|
task.timer = setTimeout(function() {
|
|
3177
|
-
|
|
3178
|
-
pipelineEngine_class_private_field_get(_this, _onTaskTimeout).call(_this, task);
|
|
3229
|
+
return pipelineEngine_class_private_method_get(_this, core_pipelineEngine_handleTaskTimeout, pipelineEngine_handleTaskTimeout).call(_this, task);
|
|
3179
3230
|
}, task.timeout);
|
|
3180
3231
|
};
|
|
3181
3232
|
for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
@@ -3205,6 +3256,7 @@ function core_pipelineEngine_handleParsedValue(raw) {
|
|
|
3205
3256
|
if (isSentinelRow(parsed, task.token)) {
|
|
3206
3257
|
clearTimeout(task.timer);
|
|
3207
3258
|
pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).shift();
|
|
3259
|
+
if (task.timedout) return void pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
|
|
3208
3260
|
if (task.consumerError) {
|
|
3209
3261
|
pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, task.consumerError, void 0);
|
|
3210
3262
|
pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
|
|
@@ -3215,6 +3267,7 @@ function core_pipelineEngine_handleParsedValue(raw) {
|
|
|
3215
3267
|
pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
|
|
3216
3268
|
return;
|
|
3217
3269
|
}
|
|
3270
|
+
if (task.timedout) return;
|
|
3218
3271
|
if ("query" === task.kind) return void collectQueryRows(task, parsed);
|
|
3219
3272
|
if ("stream" === task.kind) processStreamRows(task, parsed);
|
|
3220
3273
|
}
|
|
@@ -3255,6 +3308,14 @@ function pipelineEngine_scheduleFinalizeCheck() {
|
|
|
3255
3308
|
pipelineEngine_class_private_field_get(_this, pipelineEngine_pendingFinalizeTasks).clear();
|
|
3256
3309
|
});
|
|
3257
3310
|
}
|
|
3311
|
+
function pipelineEngine_handleTaskTimeout(task) {
|
|
3312
|
+
var _this, _this1;
|
|
3313
|
+
if (task.settled) return;
|
|
3314
|
+
task.timedout = true;
|
|
3315
|
+
clearTimeout(task.timer);
|
|
3316
|
+
pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, createTimeoutError(task.timeout, task.sql), void 0);
|
|
3317
|
+
null == (_this = pipelineEngine_class_private_field_get(_this1 = this, _onTaskTimeout)) || _this.call(_this1, task);
|
|
3318
|
+
}
|
|
3258
3319
|
function pipelineEngine_settleTask1(task, error, value) {
|
|
3259
3320
|
settleTask(task, error, value, pipelineEngine_class_private_field_get(this, pipelineEngine_metrics), {
|
|
3260
3321
|
resetRowParser: true
|
|
@@ -3564,7 +3625,6 @@ var executor_SQLiteExecutor = /*#__PURE__*/ function() {
|
|
|
3564
3625
|
logger: executor_class_private_field_get(this, executor_logger),
|
|
3565
3626
|
onTaskTimeout: function(task) {
|
|
3566
3627
|
executor_class_private_field_get(_this, executor_metrics).incrementTasksTimeout();
|
|
3567
|
-
executor_class_private_method_get(_this, _handleProcessFailure, handleProcessFailure).call(_this, createTimeoutError(task.timeout, task.sql));
|
|
3568
3628
|
}
|
|
3569
3629
|
}));
|
|
3570
3630
|
executor_class_private_method_get(this, executor_startProcess, core_executor_startProcess).call(this);
|
|
@@ -3881,6 +3941,7 @@ function enqueueWriter(kind, sql, timeout, token, onRow, scopeId) {
|
|
|
3881
3941
|
reject: reject,
|
|
3882
3942
|
consumerError: null,
|
|
3883
3943
|
stderrText: "",
|
|
3944
|
+
settled: false,
|
|
3884
3945
|
timer: null,
|
|
3885
3946
|
startTime: 0,
|
|
3886
3947
|
rowParser: null
|