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.mts";
|
|
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/esm/index.mjs
CHANGED
|
@@ -412,6 +412,7 @@ function createRowStreamParser(onRow) {
|
|
|
412
412
|
}
|
|
413
413
|
var TOKEN_COLUMN = "__sqlite_executor_token__";
|
|
414
414
|
var DEFAULT_BATCH_SIZE = 10;
|
|
415
|
+
var DEFAULT_MAX_INFLIGHT = 50;
|
|
415
416
|
function stream_check_private_redeclaration(obj, privateCollection) {
|
|
416
417
|
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
417
418
|
}
|
|
@@ -919,11 +920,11 @@ function _ts_generator(thisArg, body) {
|
|
|
919
920
|
}
|
|
920
921
|
}
|
|
921
922
|
var GRACEFUL_SHUTDOWN_TIMEOUT = 5000;
|
|
922
|
-
var _binary = /*#__PURE__*/ new WeakMap(), _database = /*#__PURE__*/ new WeakMap(), _proc = /*#__PURE__*/ new WeakMap(), _initMode = /*#__PURE__*/ new WeakMap(), _draining = /*#__PURE__*/ new WeakMap();
|
|
923
|
+
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();
|
|
923
924
|
var process_ProcessManager = /*#__PURE__*/ function() {
|
|
924
925
|
"use strict";
|
|
925
926
|
function ProcessManager() {
|
|
926
|
-
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;
|
|
927
|
+
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;
|
|
927
928
|
process_class_call_check(this, ProcessManager);
|
|
928
929
|
process_class_private_field_init(this, _binary, {
|
|
929
930
|
writable: true,
|
|
@@ -945,12 +946,29 @@ var process_ProcessManager = /*#__PURE__*/ function() {
|
|
|
945
946
|
writable: true,
|
|
946
947
|
value: false
|
|
947
948
|
});
|
|
949
|
+
process_class_private_field_init(this, _onDrain, {
|
|
950
|
+
writable: true,
|
|
951
|
+
value: void 0
|
|
952
|
+
});
|
|
948
953
|
var _which;
|
|
949
954
|
process_class_private_field_set(this, _binary, null != (_which = which(binary)) ? _which : binary);
|
|
950
955
|
process_class_private_field_set(this, _database, database);
|
|
951
956
|
process_class_private_field_set(this, _initMode, initMode);
|
|
957
|
+
process_class_private_field_set(this, _onDrain, null != onDrain ? onDrain : function() {});
|
|
952
958
|
}
|
|
953
959
|
process_create_class(ProcessManager, [
|
|
960
|
+
{
|
|
961
|
+
key: "draining",
|
|
962
|
+
get: function() {
|
|
963
|
+
return process_class_private_field_get(this, _draining);
|
|
964
|
+
}
|
|
965
|
+
},
|
|
966
|
+
{
|
|
967
|
+
key: "setOnDrainCallback",
|
|
968
|
+
value: function(fn) {
|
|
969
|
+
process_class_private_field_set(this, _onDrain, fn);
|
|
970
|
+
}
|
|
971
|
+
},
|
|
954
972
|
{
|
|
955
973
|
key: "binary",
|
|
956
974
|
get: function() {
|
|
@@ -996,10 +1014,12 @@ var process_ProcessManager = /*#__PURE__*/ function() {
|
|
|
996
1014
|
var _$_class_private_field_get;
|
|
997
1015
|
var stream = null == (_$_class_private_field_get = process_class_private_field_get(this, _proc)) ? void 0 : _$_class_private_field_get.stdin;
|
|
998
1016
|
if (!stream) return;
|
|
999
|
-
if (
|
|
1017
|
+
if (process_class_private_field_get(this, _draining)) return;
|
|
1018
|
+
if (!stream.write(data)) {
|
|
1000
1019
|
process_class_private_field_set(this, _draining, true);
|
|
1001
1020
|
stream.once("drain", function() {
|
|
1002
1021
|
process_class_private_field_set(_this, _draining, false);
|
|
1022
|
+
process_class_private_field_get(_this, _onDrain).call(_this);
|
|
1003
1023
|
});
|
|
1004
1024
|
}
|
|
1005
1025
|
}
|
|
@@ -1018,7 +1038,7 @@ var process_ProcessManager = /*#__PURE__*/ function() {
|
|
|
1018
1038
|
2
|
|
1019
1039
|
];
|
|
1020
1040
|
timer = setTimeout(function() {
|
|
1021
|
-
|
|
1041
|
+
proc.kill();
|
|
1022
1042
|
}, GRACEFUL_SHUTDOWN_TIMEOUT);
|
|
1023
1043
|
_state.label = 1;
|
|
1024
1044
|
case 1:
|
|
@@ -1643,9 +1663,13 @@ function buildPayload(sql, token) {
|
|
|
1643
1663
|
var suffix = normalized.endsWith(";") ? "" : ";";
|
|
1644
1664
|
return "".concat(normalized).concat(suffix, "\nSELECT '").concat(token, "' AS ").concat(TOKEN_COLUMN, ";\n");
|
|
1645
1665
|
}
|
|
1666
|
+
function isTransactionControl(sql) {
|
|
1667
|
+
var s = sql.trim().toUpperCase();
|
|
1668
|
+
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 ");
|
|
1669
|
+
}
|
|
1646
1670
|
function buildBatchPayload(batch) {
|
|
1647
1671
|
var useWalBatch = batch.length > 1 && batch.every(function(t) {
|
|
1648
|
-
return "execute" === t.kind;
|
|
1672
|
+
return "execute" === t.kind && !isTransactionControl(t.sql);
|
|
1649
1673
|
});
|
|
1650
1674
|
if (useWalBatch) {
|
|
1651
1675
|
var parts = [
|
|
@@ -1769,6 +1793,8 @@ function processStreamRows(task, parsed) {
|
|
|
1769
1793
|
}
|
|
1770
1794
|
function settleTask(task, error, value, metrics) {
|
|
1771
1795
|
var _ref = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : {}, _ref_resetRowParser = _ref.resetRowParser, resetRowParser = void 0 === _ref_resetRowParser ? false : _ref_resetRowParser;
|
|
1796
|
+
if (task.settled) return;
|
|
1797
|
+
task.settled = true;
|
|
1772
1798
|
clearTimeout(task.timer);
|
|
1773
1799
|
if (resetRowParser) {
|
|
1774
1800
|
var _task_rowParser_reset, _task_rowParser;
|
|
@@ -1864,12 +1890,12 @@ function taskWorker_unsupported_iterable_to_array(o, minLen) {
|
|
|
1864
1890
|
if ("Map" === n || "Set" === n) return Array.from(n);
|
|
1865
1891
|
if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return taskWorker_array_like_to_array(o, minLen);
|
|
1866
1892
|
}
|
|
1867
|
-
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();
|
|
1893
|
+
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();
|
|
1868
1894
|
var taskWorker_TaskWorker = /*#__PURE__*/ function() {
|
|
1869
1895
|
"use strict";
|
|
1870
1896
|
function TaskWorker(param) {
|
|
1871
1897
|
var _this = this;
|
|
1872
|
-
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;
|
|
1898
|
+
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;
|
|
1873
1899
|
taskWorker_class_call_check(this, TaskWorker);
|
|
1874
1900
|
taskWorker_class_private_method_init(this, _startProcess);
|
|
1875
1901
|
taskWorker_class_private_method_init(this, _pumpQueue);
|
|
@@ -1919,6 +1945,10 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
|
|
|
1919
1945
|
writable: true,
|
|
1920
1946
|
value: void 0
|
|
1921
1947
|
});
|
|
1948
|
+
taskWorker_class_private_field_init(this, _maxInflight, {
|
|
1949
|
+
writable: true,
|
|
1950
|
+
value: void 0
|
|
1951
|
+
});
|
|
1922
1952
|
taskWorker_class_private_field_init(this, _metrics, {
|
|
1923
1953
|
writable: true,
|
|
1924
1954
|
value: void 0
|
|
@@ -1927,11 +1957,15 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
|
|
|
1927
1957
|
taskWorker_class_private_field_set(this, _statementTimeout, statementTimeout);
|
|
1928
1958
|
taskWorker_class_private_field_set(this, _logger, logger);
|
|
1929
1959
|
taskWorker_class_private_field_set(this, _batchSize, batchSize);
|
|
1960
|
+
taskWorker_class_private_field_set(this, _maxInflight, maxInflight);
|
|
1930
1961
|
taskWorker_class_private_field_set(this, _metrics, metrics);
|
|
1931
1962
|
taskWorker_class_private_field_set(this, _processManager, new process_ProcessManager({
|
|
1932
1963
|
binary: binary,
|
|
1933
1964
|
database: database,
|
|
1934
|
-
initMode: initMode
|
|
1965
|
+
initMode: initMode,
|
|
1966
|
+
onDrain: function() {
|
|
1967
|
+
return taskWorker_class_private_method_get(_this, _pumpQueue, pumpQueue).call(_this);
|
|
1968
|
+
}
|
|
1935
1969
|
}));
|
|
1936
1970
|
taskWorker_class_private_field_set(this, _valueParser, createJsonValueParser(function(raw) {
|
|
1937
1971
|
return taskWorker_class_private_method_get(_this, _handleParsedValue, handleParsedValue).call(_this, raw);
|
|
@@ -1973,6 +2007,7 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
|
|
|
1973
2007
|
onRow: null != (_config_onRow = config.onRow) ? _config_onRow : null,
|
|
1974
2008
|
consumerError: null,
|
|
1975
2009
|
stderrText: "",
|
|
2010
|
+
settled: false,
|
|
1976
2011
|
errorScheduled: false,
|
|
1977
2012
|
timer: null,
|
|
1978
2013
|
startTime: 0
|
|
@@ -2016,8 +2051,10 @@ function startProcess() {
|
|
|
2016
2051
|
function pumpQueue() {
|
|
2017
2052
|
var _this = this;
|
|
2018
2053
|
var _$_class_private_field_get;
|
|
2054
|
+
if (taskWorker_class_private_field_get(this, _processManager).draining) return;
|
|
2055
|
+
if (taskWorker_class_private_field_get(this, _inflightTasks).length >= taskWorker_class_private_field_get(this, _maxInflight)) return;
|
|
2019
2056
|
var batch = [];
|
|
2020
|
-
while(batch.length < taskWorker_class_private_field_get(this, _batchSize) && !taskWorker_class_private_field_get(this, _pendingQueue).isEmpty()){
|
|
2057
|
+
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)){
|
|
2021
2058
|
var task = taskWorker_class_private_field_get(this, _pendingQueue).peek();
|
|
2022
2059
|
if ("stream" === task.kind && (batch.length > 0 || taskWorker_class_private_field_get(this, _inflightTasks).length > 0)) break;
|
|
2023
2060
|
taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
|
|
@@ -2063,6 +2100,7 @@ function handleParsedValue(raw) {
|
|
|
2063
2100
|
if (isSentinelRow(parsed, task.token)) {
|
|
2064
2101
|
clearTimeout(task.timer);
|
|
2065
2102
|
taskWorker_class_private_field_get(this, _inflightTasks).shift();
|
|
2103
|
+
if (task.timedout) return void taskWorker_class_private_method_get(this, _pumpQueue, pumpQueue).call(this);
|
|
2066
2104
|
if (task.stderrText) {
|
|
2067
2105
|
taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, new Error(task.stderrText.trim()), void 0);
|
|
2068
2106
|
taskWorker_class_private_method_get(this, _pumpQueue, pumpQueue).call(this);
|
|
@@ -2131,9 +2169,12 @@ function taskWorker_handleStderrChunk(chunk) {
|
|
|
2131
2169
|
}
|
|
2132
2170
|
function handleTaskTimeout(task) {
|
|
2133
2171
|
var _$_class_private_field_get;
|
|
2134
|
-
if (
|
|
2172
|
+
if (task.settled) return;
|
|
2173
|
+
task.timedout = true;
|
|
2174
|
+
clearTimeout(task.timer);
|
|
2175
|
+
task.timer = null;
|
|
2135
2176
|
null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _metrics)) || _$_class_private_field_get.incrementTasksTimeout();
|
|
2136
|
-
taskWorker_class_private_method_get(this,
|
|
2177
|
+
taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, createTimeoutError(task.timeout, task.sql), void 0);
|
|
2137
2178
|
}
|
|
2138
2179
|
function settleTask1(task, error, value) {
|
|
2139
2180
|
settleTask(task, error, value, taskWorker_class_private_field_get(this, _metrics));
|
|
@@ -2898,16 +2939,17 @@ function pipelineEngine_unsupported_iterable_to_array(o, minLen) {
|
|
|
2898
2939
|
if ("Map" === n || "Set" === n) return Array.from(n);
|
|
2899
2940
|
if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return pipelineEngine_array_like_to_array(o, minLen);
|
|
2900
2941
|
}
|
|
2901
|
-
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();
|
|
2942
|
+
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();
|
|
2902
2943
|
var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
|
|
2903
2944
|
"use strict";
|
|
2904
2945
|
function PipelineEngine(processManager, param) {
|
|
2905
2946
|
var _this = this;
|
|
2906
|
-
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;
|
|
2947
|
+
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;
|
|
2907
2948
|
pipelineEngine_class_call_check(this, PipelineEngine);
|
|
2908
2949
|
pipelineEngine_class_private_method_init(this, core_pipelineEngine_pumpQueue);
|
|
2909
2950
|
pipelineEngine_class_private_method_init(this, pipelineEngine_handleParsedValue);
|
|
2910
2951
|
pipelineEngine_class_private_method_init(this, core_pipelineEngine_scheduleFinalizeCheck);
|
|
2952
|
+
pipelineEngine_class_private_method_init(this, core_pipelineEngine_handleTaskTimeout);
|
|
2911
2953
|
pipelineEngine_class_private_method_init(this, pipelineEngine_settleTask);
|
|
2912
2954
|
pipelineEngine_class_private_field_init(this, _queue, {
|
|
2913
2955
|
writable: true,
|
|
@@ -2949,6 +2991,10 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
|
|
|
2949
2991
|
writable: true,
|
|
2950
2992
|
value: void 0
|
|
2951
2993
|
});
|
|
2994
|
+
pipelineEngine_class_private_field_init(this, pipelineEngine_maxInflight, {
|
|
2995
|
+
writable: true,
|
|
2996
|
+
value: void 0
|
|
2997
|
+
});
|
|
2952
2998
|
pipelineEngine_class_private_field_init(this, _onTaskTimeout, {
|
|
2953
2999
|
writable: true,
|
|
2954
3000
|
value: void 0
|
|
@@ -2962,10 +3008,14 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
|
|
|
2962
3008
|
pipelineEngine_class_private_field_set(this, pipelineEngine_statementTimeout, statementTimeout);
|
|
2963
3009
|
pipelineEngine_class_private_field_set(this, pipelineEngine_logger, logger);
|
|
2964
3010
|
pipelineEngine_class_private_field_set(this, pipelineEngine_batchSize, batchSize);
|
|
3011
|
+
pipelineEngine_class_private_field_set(this, pipelineEngine_maxInflight, maxInflight);
|
|
2965
3012
|
pipelineEngine_class_private_field_set(this, _onTaskTimeout, null != onTaskTimeout ? onTaskTimeout : function() {});
|
|
2966
3013
|
pipelineEngine_class_private_field_set(this, _sharedValueParser, createJsonValueParser(function(raw) {
|
|
2967
3014
|
return pipelineEngine_class_private_method_get(_this, pipelineEngine_handleParsedValue, core_pipelineEngine_handleParsedValue).call(_this, raw);
|
|
2968
3015
|
}));
|
|
3016
|
+
pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).setOnDrainCallback(function() {
|
|
3017
|
+
return pipelineEngine_class_private_method_get(_this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(_this);
|
|
3018
|
+
});
|
|
2969
3019
|
}
|
|
2970
3020
|
pipelineEngine_create_class(PipelineEngine, [
|
|
2971
3021
|
{
|
|
@@ -3098,8 +3148,10 @@ function pipelineEngine_pumpQueue() {
|
|
|
3098
3148
|
var _this = this;
|
|
3099
3149
|
var _$_class_private_field_get;
|
|
3100
3150
|
if (!pipelineEngine_class_private_field_get(this, _active)) return;
|
|
3151
|
+
if (pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).draining) return;
|
|
3152
|
+
if (pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length >= pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)) return;
|
|
3101
3153
|
var batch = [];
|
|
3102
|
-
while(batch.length < pipelineEngine_class_private_field_get(this, pipelineEngine_batchSize) && !pipelineEngine_class_private_field_get(this, _queue).isEmpty()){
|
|
3154
|
+
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)){
|
|
3103
3155
|
var task = pipelineEngine_class_private_field_get(this, _queue).peek();
|
|
3104
3156
|
if ("stream" === task.kind && (batch.length > 0 || pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length > 0)) break;
|
|
3105
3157
|
pipelineEngine_class_private_field_get(this, _queue).dequeue();
|
|
@@ -3114,8 +3166,7 @@ function pipelineEngine_pumpQueue() {
|
|
|
3114
3166
|
var task = _step.value;
|
|
3115
3167
|
task.startTime = now;
|
|
3116
3168
|
task.timer = setTimeout(function() {
|
|
3117
|
-
|
|
3118
|
-
pipelineEngine_class_private_field_get(_this, _onTaskTimeout).call(_this, task);
|
|
3169
|
+
return pipelineEngine_class_private_method_get(_this, core_pipelineEngine_handleTaskTimeout, pipelineEngine_handleTaskTimeout).call(_this, task);
|
|
3119
3170
|
}, task.timeout);
|
|
3120
3171
|
};
|
|
3121
3172
|
for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
@@ -3145,6 +3196,7 @@ function core_pipelineEngine_handleParsedValue(raw) {
|
|
|
3145
3196
|
if (isSentinelRow(parsed, task.token)) {
|
|
3146
3197
|
clearTimeout(task.timer);
|
|
3147
3198
|
pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).shift();
|
|
3199
|
+
if (task.timedout) return void pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
|
|
3148
3200
|
if (task.consumerError) {
|
|
3149
3201
|
pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, task.consumerError, void 0);
|
|
3150
3202
|
pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
|
|
@@ -3155,6 +3207,7 @@ function core_pipelineEngine_handleParsedValue(raw) {
|
|
|
3155
3207
|
pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
|
|
3156
3208
|
return;
|
|
3157
3209
|
}
|
|
3210
|
+
if (task.timedout) return;
|
|
3158
3211
|
if ("query" === task.kind) return void collectQueryRows(task, parsed);
|
|
3159
3212
|
if ("stream" === task.kind) processStreamRows(task, parsed);
|
|
3160
3213
|
}
|
|
@@ -3195,6 +3248,14 @@ function pipelineEngine_scheduleFinalizeCheck() {
|
|
|
3195
3248
|
pipelineEngine_class_private_field_get(_this, pipelineEngine_pendingFinalizeTasks).clear();
|
|
3196
3249
|
});
|
|
3197
3250
|
}
|
|
3251
|
+
function pipelineEngine_handleTaskTimeout(task) {
|
|
3252
|
+
var _this, _this1;
|
|
3253
|
+
if (task.settled) return;
|
|
3254
|
+
task.timedout = true;
|
|
3255
|
+
clearTimeout(task.timer);
|
|
3256
|
+
pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, createTimeoutError(task.timeout, task.sql), void 0);
|
|
3257
|
+
null == (_this = pipelineEngine_class_private_field_get(_this1 = this, _onTaskTimeout)) || _this.call(_this1, task);
|
|
3258
|
+
}
|
|
3198
3259
|
function pipelineEngine_settleTask1(task, error, value) {
|
|
3199
3260
|
settleTask(task, error, value, pipelineEngine_class_private_field_get(this, pipelineEngine_metrics), {
|
|
3200
3261
|
resetRowParser: true
|
|
@@ -3504,7 +3565,6 @@ var executor_SQLiteExecutor = /*#__PURE__*/ function() {
|
|
|
3504
3565
|
logger: executor_class_private_field_get(this, executor_logger),
|
|
3505
3566
|
onTaskTimeout: function(task) {
|
|
3506
3567
|
executor_class_private_field_get(_this, executor_metrics).incrementTasksTimeout();
|
|
3507
|
-
executor_class_private_method_get(_this, _handleProcessFailure, handleProcessFailure).call(_this, createTimeoutError(task.timeout, task.sql));
|
|
3508
3568
|
}
|
|
3509
3569
|
}));
|
|
3510
3570
|
executor_class_private_method_get(this, executor_startProcess, core_executor_startProcess).call(this);
|
|
@@ -3821,6 +3881,7 @@ function enqueueWriter(kind, sql, timeout, token, onRow, scopeId) {
|
|
|
3821
3881
|
reject: reject,
|
|
3822
3882
|
consumerError: null,
|
|
3823
3883
|
stderrText: "",
|
|
3884
|
+
settled: false,
|
|
3824
3885
|
timer: null,
|
|
3825
3886
|
startTime: 0,
|
|
3826
3887
|
rowParser: null
|