velocious 1.0.741 → 1.0.742
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/build/background-jobs/pooled-runner-child.js +33 -1
- package/build/background-jobs/worker.js +1 -20
- package/build/database/record/index.js +18 -0
- package/build/src/background-jobs/pooled-runner-child.js +30 -2
- package/build/src/background-jobs/worker.d.ts +0 -4
- package/build/src/background-jobs/worker.d.ts.map +1 -1
- package/build/src/background-jobs/worker.js +2 -21
- package/build/src/database/record/index.d.ts.map +1 -1
- package/build/src/database/record/index.js +19 -1
- package/package.json +1 -1
- package/src/background-jobs/pooled-runner-child.js +33 -1
- package/src/background-jobs/worker.js +1 -20
- package/src/database/record/index.js +18 -0
package/package.json
CHANGED
|
@@ -54,6 +54,9 @@ setRunnerProcessTitle()
|
|
|
54
54
|
/** @type {Promise<void> | undefined} */
|
|
55
55
|
let shutdownPromise
|
|
56
56
|
|
|
57
|
+
/** @type {{exitCode: number, reason: import("./types.js").PooledChildShutdownReason, shutdownRequestedAtMs: number | null, signal: import("node:child_process").ChildProcess["signalCode"]} | undefined} */
|
|
58
|
+
let deferredShutdown
|
|
59
|
+
|
|
57
60
|
/**
|
|
58
61
|
* Closes the runner's connections — releasing any advisory lock a killed-mid-pass
|
|
59
62
|
* job still holds — before exiting, instead of leaving a half-open session that
|
|
@@ -77,6 +80,30 @@ function shutdownRunner({exitCode, reason, shutdownRequestedAtMs = null, signal
|
|
|
77
80
|
return shutdownPromise
|
|
78
81
|
}
|
|
79
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Requests shutdown after the current pooled jobs have completed their own
|
|
85
|
+
* finally blocks. The parent receives a terminal job outcome before that
|
|
86
|
+
* finally block runs, so retiring on the outcome alone can close application
|
|
87
|
+
* transports while the job is still releasing its live streams.
|
|
88
|
+
* @param {{exitCode: number, reason: import("./types.js").PooledChildShutdownReason, shutdownRequestedAtMs?: number | null, signal?: import("node:child_process").ChildProcess["signalCode"]}} request - Shutdown request.
|
|
89
|
+
* @returns {void}
|
|
90
|
+
*/
|
|
91
|
+
function requestShutdown(request) {
|
|
92
|
+
const normalizedRequest = {
|
|
93
|
+
exitCode: request.exitCode,
|
|
94
|
+
reason: request.reason,
|
|
95
|
+
shutdownRequestedAtMs: request.shutdownRequestedAtMs ?? null,
|
|
96
|
+
signal: request.signal ?? null
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (request.reason !== "parent_retire_drained" || runningJobIds.size === 0) {
|
|
100
|
+
void shutdownRunner(normalizedRequest)
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
deferredShutdown = normalizedRequest
|
|
105
|
+
}
|
|
106
|
+
|
|
80
107
|
/**
|
|
81
108
|
* Ids of jobs currently running in this child. A pooled child runs up to
|
|
82
109
|
* `pooledRunnerConcurrency` jobs at once (the worker only dispatches within that
|
|
@@ -365,6 +392,11 @@ async function runJob(payload, sharedTransactionBroker) {
|
|
|
365
392
|
|
|
366
393
|
if (runningJobIds.size === 0) {
|
|
367
394
|
stopMemoryObservationSampling()
|
|
395
|
+
if (deferredShutdown) {
|
|
396
|
+
const request = deferredShutdown
|
|
397
|
+
deferredShutdown = undefined
|
|
398
|
+
void shutdownRunner(request)
|
|
399
|
+
}
|
|
368
400
|
}
|
|
369
401
|
}
|
|
370
402
|
}
|
|
@@ -376,7 +408,7 @@ async function runJob(payload, sharedTransactionBroker) {
|
|
|
376
408
|
*/
|
|
377
409
|
function handleMessage(message) {
|
|
378
410
|
if (isShutdownRequestMessage(message)) {
|
|
379
|
-
|
|
411
|
+
requestShutdown({
|
|
380
412
|
exitCode: message.reason === "parent_retire_drained" ? 0 : 1,
|
|
381
413
|
reason: message.reason,
|
|
382
414
|
shutdownRequestedAtMs: message.shutdownRequestedAtMs,
|
|
@@ -62,7 +62,6 @@ import { POOLED_RUNNER_INFLIGHT_JOB_ID_LIMIT, boundedPooledRunnerInflightJobIds,
|
|
|
62
62
|
* @property {import("./types.js").PooledChildShutdownReason} [shutdownReason] - Exact parent-requested shutdown reason.
|
|
63
63
|
* @property {number} [shutdownRequestedAtMs] - Exact parent shutdown-request timestamp.
|
|
64
64
|
* @property {import("node:child_process").ChildProcess["signalCode"]} [shutdownSignal] - Signal selected by the parent request.
|
|
65
|
-
* @property {ReturnType<typeof setTimeout>} [shutdownSignalTimer] - Drained-retirement fallback signal timer.
|
|
66
65
|
* @property {ReturnType<typeof setTimeout> | null} [timeoutSigkillTimer] - Pending timeout SIGKILL timer.
|
|
67
66
|
* @property {string} [timeoutJobId] - Job whose timeout initiated termination.
|
|
68
67
|
* @property {number} lastActivityAtMs - Last time the worker saw any IPC message from this child, or dispatched to it.
|
|
@@ -71,8 +70,6 @@ import { POOLED_RUNNER_INFLIGHT_JOB_ID_LIMIT, boundedPooledRunnerInflightJobIds,
|
|
|
71
70
|
*/
|
|
72
71
|
/** Grace period after SIGTERM before a lingering process runner is SIGKILLed. */
|
|
73
72
|
const FORKED_CHILD_SIGKILL_GRACE_MS = 5000
|
|
74
|
-
/** Time a drained retirement gives the child IPC request to begin teardown before SIGTERM fallback. */
|
|
75
|
-
const POOLED_RUNNER_SHUTDOWN_REQUEST_GRACE_MS = 250
|
|
76
73
|
/**
|
|
77
74
|
* Default bound on how long a pooled child with in-flight jobs may stay silent on
|
|
78
75
|
* its IPC channel before the worker declares it wedged. A healthy child samples its
|
|
@@ -1600,10 +1597,6 @@ export default class BackgroundJobsWorker {
|
|
|
1600
1597
|
if (state) {
|
|
1601
1598
|
state.childInstanceId = message.childInstanceId
|
|
1602
1599
|
state.shutdownObservation = message
|
|
1603
|
-
if (state.shutdownSignalTimer) {
|
|
1604
|
-
clearTimeout(state.shutdownSignalTimer)
|
|
1605
|
-
state.shutdownSignalTimer = undefined
|
|
1606
|
-
}
|
|
1607
1600
|
}
|
|
1608
1601
|
return
|
|
1609
1602
|
}
|
|
@@ -2043,10 +2036,6 @@ export default class BackgroundJobsWorker {
|
|
|
2043
2036
|
child.send({type: "shutdown-request", reason, shutdownRequestedAtMs, signal}, (error) => {
|
|
2044
2037
|
if (!error || !waitForObservation || state.settling) return
|
|
2045
2038
|
|
|
2046
|
-
if (state.shutdownSignalTimer) {
|
|
2047
|
-
clearTimeout(state.shutdownSignalTimer)
|
|
2048
|
-
state.shutdownSignalTimer = undefined
|
|
2049
|
-
}
|
|
2050
2039
|
this._signalPooledChild({child, signal})
|
|
2051
2040
|
})
|
|
2052
2041
|
requestSent = true
|
|
@@ -2055,14 +2044,7 @@ export default class BackgroundJobsWorker {
|
|
|
2055
2044
|
}
|
|
2056
2045
|
}
|
|
2057
2046
|
|
|
2058
|
-
if (waitForObservation && requestSent)
|
|
2059
|
-
state.shutdownSignalTimer = setTimeout(() => {
|
|
2060
|
-
state.shutdownSignalTimer = undefined
|
|
2061
|
-
this._signalPooledChild({child, signal})
|
|
2062
|
-
}, POOLED_RUNNER_SHUTDOWN_REQUEST_GRACE_MS)
|
|
2063
|
-
state.shutdownSignalTimer.unref()
|
|
2064
|
-
return
|
|
2065
|
-
}
|
|
2047
|
+
if (waitForObservation && requestSent) return
|
|
2066
2048
|
|
|
2067
2049
|
this._signalPooledChild({child, signal})
|
|
2068
2050
|
}
|
|
@@ -2104,7 +2086,6 @@ export default class BackgroundJobsWorker {
|
|
|
2104
2086
|
// Cancel this child's pending timers before its in-flight set is reported —
|
|
2105
2087
|
// the SIGKILL grace from a timeout kill, and every armed per-job backstop.
|
|
2106
2088
|
if (state.timeoutSigkillTimer) clearTimeout(state.timeoutSigkillTimer)
|
|
2107
|
-
if (state.shutdownSignalTimer) clearTimeout(state.shutdownSignalTimer)
|
|
2108
2089
|
if (state.silenceTimer) clearTimeout(state.silenceTimer)
|
|
2109
2090
|
if (state.silenceSigkillTimer) clearTimeout(state.silenceSigkillTimer)
|
|
2110
2091
|
for (const inflightEntry of state.inflight.values()) {
|
|
@@ -3093,6 +3093,24 @@ class VelociousDatabaseRecord {
|
|
|
3093
3093
|
static async hasAdvisoryLock(name) {
|
|
3094
3094
|
await this.ensureInitialized()
|
|
3095
3095
|
|
|
3096
|
+
const configuration = this._getConfiguration()
|
|
3097
|
+
const policy = configuration.resolveAdvisoryLockPolicy(name)
|
|
3098
|
+
|
|
3099
|
+
// A configured lock server owns the default authority for undeclared
|
|
3100
|
+
// names. Query that authority first; MariaDB's IS_USED_LOCK cannot see a
|
|
3101
|
+
// lease which is intentionally no longer held by a database session.
|
|
3102
|
+
if (policy.allowedTiers.includes("lock-server")) {
|
|
3103
|
+
const lockServer = await configuration.getAdvisoryLockLockServerBackend()
|
|
3104
|
+
|
|
3105
|
+
if (lockServer) {
|
|
3106
|
+
try {
|
|
3107
|
+
if (await lockServer.whoHolds(name)) return true
|
|
3108
|
+
} catch (error) {
|
|
3109
|
+
if (policy.minTier === "lock-server") throw error
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
|
|
3096
3114
|
return await this.connection().isAdvisoryLockHeld(name)
|
|
3097
3115
|
}
|
|
3098
3116
|
|