velocious 1.0.727 → 1.0.728
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/README.md +2 -2
- package/bin/velocious.js +2 -19
- package/build/application.js +32 -3
- package/build/background-jobs/main.js +9 -1
- package/build/background-jobs/worker.js +69 -6
- package/build/bin/velocious.js +2 -19
- package/build/cli/process-args.js +34 -0
- package/build/configuration.js +26 -0
- package/build/database/drivers/base.js +34 -12
- package/build/database/drivers/mssql/index.js +17 -18
- package/build/database/drivers/mssql/table.js +28 -25
- package/build/database/drivers/mysql/index.js +15 -18
- package/build/database/drivers/mysql/table.js +31 -23
- package/build/database/drivers/pgsql/index.js +15 -18
- package/build/database/drivers/pgsql/table.js +28 -26
- package/build/database/drivers/sqlite/base.js +7 -9
- package/build/database/drivers/sqlite/table.js +32 -26
- package/build/database/pool/async-tracked-multi-connection.js +1 -0
- package/build/database/pool/base.js +14 -4
- package/build/database/pool/single-multi-use.js +1 -0
- package/build/environment-handlers/node/cli/commands/server.js +1 -0
- package/build/http-server/server-lock.js +28 -4
- package/build/src/application.d.ts +7 -4
- package/build/src/application.d.ts.map +1 -1
- package/build/src/application.js +27 -4
- package/build/src/background-jobs/main.d.ts +2 -1
- package/build/src/background-jobs/main.d.ts.map +1 -1
- package/build/src/background-jobs/main.js +10 -2
- package/build/src/background-jobs/worker.d.ts +42 -0
- package/build/src/background-jobs/worker.d.ts.map +1 -1
- package/build/src/background-jobs/worker.js +61 -5
- package/build/src/cli/process-args.d.ts +11 -0
- package/build/src/cli/process-args.d.ts.map +1 -0
- package/build/src/cli/process-args.js +34 -0
- package/build/src/configuration.d.ts +13 -0
- package/build/src/configuration.d.ts.map +1 -1
- package/build/src/configuration.js +22 -1
- package/build/src/database/drivers/base.d.ts +15 -2
- package/build/src/database/drivers/base.d.ts.map +1 -1
- package/build/src/database/drivers/base.js +33 -13
- package/build/src/database/drivers/mssql/index.d.ts +2 -2
- package/build/src/database/drivers/mssql/index.d.ts.map +1 -1
- package/build/src/database/drivers/mssql/index.js +17 -18
- package/build/src/database/drivers/mssql/table.d.ts.map +1 -1
- package/build/src/database/drivers/mssql/table.js +25 -23
- package/build/src/database/drivers/mysql/index.d.ts +2 -2
- package/build/src/database/drivers/mysql/index.d.ts.map +1 -1
- package/build/src/database/drivers/mysql/index.js +16 -19
- package/build/src/database/drivers/mysql/table.d.ts.map +1 -1
- package/build/src/database/drivers/mysql/table.js +27 -22
- package/build/src/database/drivers/pgsql/index.d.ts +2 -2
- package/build/src/database/drivers/pgsql/index.d.ts.map +1 -1
- package/build/src/database/drivers/pgsql/index.js +16 -19
- package/build/src/database/drivers/pgsql/table.d.ts.map +1 -1
- package/build/src/database/drivers/pgsql/table.js +25 -23
- package/build/src/database/drivers/sqlite/base.d.ts.map +1 -1
- package/build/src/database/drivers/sqlite/base.js +8 -10
- package/build/src/database/drivers/sqlite/table.d.ts.map +1 -1
- package/build/src/database/drivers/sqlite/table.js +29 -25
- package/build/src/database/pool/async-tracked-multi-connection.d.ts.map +1 -1
- package/build/src/database/pool/async-tracked-multi-connection.js +2 -1
- package/build/src/database/pool/base.d.ts +6 -0
- package/build/src/database/pool/base.d.ts.map +1 -1
- package/build/src/database/pool/base.js +14 -5
- package/build/src/database/pool/single-multi-use.d.ts.map +1 -1
- package/build/src/database/pool/single-multi-use.js +2 -1
- package/build/src/environment-handlers/node/cli/commands/server.d.ts.map +1 -1
- package/build/src/environment-handlers/node/cli/commands/server.js +2 -1
- package/build/src/http-server/server-lock.d.ts +23 -5
- package/build/src/http-server/server-lock.d.ts.map +1 -1
- package/build/src/http-server/server-lock.js +27 -5
- package/build/src/tenants/default-tenant-database-provisioning.d.ts.map +1 -1
- package/build/src/tenants/default-tenant-database-provisioning.js +7 -1
- package/build/tenants/default-tenant-database-provisioning.js +8 -0
- package/package.json +2 -2
- package/src/application.js +32 -3
- package/src/background-jobs/main.js +9 -1
- package/src/background-jobs/worker.js +69 -6
- package/src/cli/process-args.js +34 -0
- package/src/configuration.js +26 -0
- package/src/database/drivers/base.js +34 -12
- package/src/database/drivers/mssql/index.js +17 -18
- package/src/database/drivers/mssql/table.js +28 -25
- package/src/database/drivers/mysql/index.js +15 -18
- package/src/database/drivers/mysql/table.js +31 -23
- package/src/database/drivers/pgsql/index.js +15 -18
- package/src/database/drivers/pgsql/table.js +28 -26
- package/src/database/drivers/sqlite/base.js +7 -9
- package/src/database/drivers/sqlite/table.js +32 -26
- package/src/database/pool/async-tracked-multi-connection.js +1 -0
- package/src/database/pool/base.js +14 -4
- package/src/database/pool/single-multi-use.js +1 -0
- package/src/environment-handlers/node/cli/commands/server.js +1 -0
- package/src/http-server/server-lock.js +28 -4
- package/src/tenants/default-tenant-database-provisioning.js +8 -0
package/README.md
CHANGED
|
@@ -1598,7 +1598,7 @@ await new StructureSqlLoader().load({db, structureSql})
|
|
|
1598
1598
|
|
|
1599
1599
|
## Schema metadata cache
|
|
1600
1600
|
|
|
1601
|
-
Velocious caches schema metadata
|
|
1601
|
+
Velocious caches schema metadata per physical database so repeated model initialization, table lookups, column introspection, and structure SQL generation can reuse the same database results. Every connection to one physical database shares the cache, so pooled drivers do not re-introspect after idle-connection reaping or connection churn. The cache is cleared automatically after schema-changing SQL runs through Velocious, such as migrations, `createTable`, `dropTable`, `renameColumn`, `ALTER TABLE`, `CREATE INDEX`, and `COMMENT ON`. See [docs/schema-metadata-cache.md](docs/schema-metadata-cache.md) for details.
|
|
1602
1602
|
|
|
1603
1603
|
If another process changes the schema outside Velocious while the current process is still running, clear the cache before reading metadata again:
|
|
1604
1604
|
|
|
@@ -2954,7 +2954,7 @@ request parser.
|
|
|
2954
2954
|
|
|
2955
2955
|
When the server runs in the `development` environment, Velocious watches application `src/` trees and hot-reloads by recycling HTTP workers after `.js`/`.mjs`/`.cjs`/`.json`/`.ejs` changes. That picks up edited controllers, models, resources, routes, and views without a manual server restart while keeping production/test behavior unchanged.
|
|
2956
2956
|
|
|
2957
|
-
Starting the HTTP server creates `tmp/server
|
|
2957
|
+
Starting the HTTP server creates `tmp/server.<environment>.lock` under the configured application directory before Beacon, workers, or the TCP listener start. A second server for the same app and environment fails fast with the lock owner details instead of partially starting. Normal shutdown removes the lock; stale locks with a dead local PID are reclaimed automatically, while locks from another host or unreadable metadata should be removed manually only after confirming no server is running. A caller that knowingly wants a second server in one (directory, environment) pair can opt out with `--no-server-lock` or `VELOCIOUS_HTTP_SERVER_LOCK=off`, which logs one warning naming the application directory and port; that escape hatch is for test-spawned backends, not production. See [docs/http-server.md](docs/http-server.md#server-lock).
|
|
2958
2958
|
|
|
2959
2959
|
Set `database: false` for an explicitly database-free application; its HTTP and
|
|
2960
2960
|
initializer lifecycle remains intact without creating a default pool or an
|
package/bin/velocious.js
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import Cli from "../src/cli/index.js"
|
|
4
|
+
import parseProcessArgs from "../src/cli/process-args.js"
|
|
4
5
|
import configurationResolver from "../src/configuration-resolver.js"
|
|
5
6
|
|
|
6
7
|
const processArgs = process.argv.slice(2)
|
|
7
|
-
|
|
8
|
-
const parsedProcessArgs = {}
|
|
9
|
-
|
|
10
|
-
for (let i = 0; i < processArgs.length; i++) {
|
|
11
|
-
const processArg = processArgs[i]
|
|
12
|
-
const singleLetterArgMatch = processArg.match(/^-([a-z])$/)
|
|
13
|
-
const multiLetterArgMatch = processArg.match(/^--([a-z]+)$/)
|
|
14
|
-
const nextArg = processArgs[i + 1]
|
|
15
|
-
const hasValue = typeof nextArg === "string" && !nextArg.startsWith("-")
|
|
16
|
-
const parsedValue = hasValue ? nextArg : true
|
|
17
|
-
|
|
18
|
-
if (singleLetterArgMatch) {
|
|
19
|
-
parsedProcessArgs[singleLetterArgMatch[1]] = parsedValue
|
|
20
|
-
if (hasValue) i++
|
|
21
|
-
} else if (multiLetterArgMatch) {
|
|
22
|
-
parsedProcessArgs[multiLetterArgMatch[1]] = parsedValue
|
|
23
|
-
if (hasValue) i++
|
|
24
|
-
}
|
|
25
|
-
}
|
|
8
|
+
const parsedProcessArgs = parseProcessArgs(processArgs)
|
|
26
9
|
|
|
27
10
|
const configuration = await configurationResolver()
|
|
28
11
|
const debugEnabled = Boolean(parsedProcessArgs.d || parsedProcessArgs.debug)
|
package/build/application.js
CHANGED
|
@@ -15,15 +15,27 @@ import { runShutdownSteps } from "./utils/shutdown-lifecycle.js"
|
|
|
15
15
|
* HttpServerConfiguration type.
|
|
16
16
|
* @typedef {import("./configuration-types.js").HttpServerConfiguration} HttpServerConfiguration */
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Reads the lock opt-out requested through the environment. Only an explicit
|
|
20
|
+
* off value opts out; anything else keeps the default protected behaviour.
|
|
21
|
+
* @returns {boolean} - Whether the environment asks for the HTTP server lock opt-out.
|
|
22
|
+
*/
|
|
23
|
+
function environmentHttpServerLockOptOut() {
|
|
24
|
+
const value = (process.env.VELOCIOUS_HTTP_SERVER_LOCK || "").trim().toLowerCase()
|
|
25
|
+
|
|
26
|
+
return value === "off" || value === "false" || value === "0"
|
|
27
|
+
}
|
|
28
|
+
|
|
18
29
|
export default class VelociousApplication {
|
|
19
30
|
/**
|
|
20
31
|
* Runs constructor.
|
|
21
32
|
* @param {object} args - Options object.
|
|
22
33
|
* @param {import("./configuration.js").default} args.configuration - Configuration instance.
|
|
23
34
|
* @param {HttpServerConfiguration} [args.httpServer] - Http server.
|
|
35
|
+
* @param {boolean} [args.httpServerLockOptOut] - Start this server without the HTTP server lock, knowingly running unprotected against a duplicate server in the same application directory and environment.
|
|
24
36
|
* @param {string} args.type - Type identifier.
|
|
25
37
|
*/
|
|
26
|
-
constructor({configuration, httpServer, type, ...restArgs}) {
|
|
38
|
+
constructor({configuration, httpServer, httpServerLockOptOut, type, ...restArgs}) {
|
|
27
39
|
restArgsError(restArgs)
|
|
28
40
|
|
|
29
41
|
if (!configuration) throw new Error("configuration is required")
|
|
@@ -35,6 +47,11 @@ export default class VelociousApplication {
|
|
|
35
47
|
* @type {HttpServerConfiguration} */
|
|
36
48
|
this.httpServerConfiguration = httpServer ?? {}
|
|
37
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Stores the explicit HTTP server lock opt-out for this application.
|
|
52
|
+
* @type {boolean} */
|
|
53
|
+
this.httpServerLockOptOut = httpServerLockOptOut === true
|
|
54
|
+
|
|
38
55
|
this.logger = new Logger(this)
|
|
39
56
|
this._type = type
|
|
40
57
|
/**
|
|
@@ -165,8 +182,20 @@ export default class VelociousApplication {
|
|
|
165
182
|
async acquireHttpServerLock({configuration, host, port}) {
|
|
166
183
|
if (this.getType() === "test-runner") return
|
|
167
184
|
|
|
168
|
-
const httpServerLock = new HttpServerLock({
|
|
169
|
-
|
|
185
|
+
const httpServerLock = new HttpServerLock({
|
|
186
|
+
configuration,
|
|
187
|
+
host,
|
|
188
|
+
port,
|
|
189
|
+
optOut: this.httpServerLockOptOut || environmentHttpServerLockOptOut()
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
const acquired = await httpServerLock.acquire()
|
|
193
|
+
|
|
194
|
+
if (!acquired) {
|
|
195
|
+
await this.logger.warn(httpServerLock.lockSkippedMessage())
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
|
|
170
199
|
this.httpServerLock = httpServerLock
|
|
171
200
|
}
|
|
172
201
|
|
|
@@ -1660,7 +1660,8 @@ export default class BackgroundJobsMain {
|
|
|
1660
1660
|
}
|
|
1661
1661
|
|
|
1662
1662
|
/**
|
|
1663
|
-
* Forgets
|
|
1663
|
+
* Forgets an in-memory lease that no longer exists durably — a reported lease or
|
|
1664
|
+
* one settled as orphaned — without relying on worker ids.
|
|
1664
1665
|
* @param {object} args - Options.
|
|
1665
1666
|
* @param {string} args.handoffId - Handoff lease id.
|
|
1666
1667
|
* @param {string} args.jobId - Job id.
|
|
@@ -2793,6 +2794,13 @@ export default class BackgroundJobsMain {
|
|
|
2793
2794
|
// Emit before awaiting the drain so a blocked dispatcher cannot delay
|
|
2794
2795
|
// application recovery. Isolate handlers so one cannot suppress the rest.
|
|
2795
2796
|
for (const job of jobs) {
|
|
2797
|
+
// The durable lease is gone, so the in-memory mirror must stop counting it.
|
|
2798
|
+
// A retired generation is pinned by `workerHandoffs`, and a row settled here
|
|
2799
|
+
// is no longer a live claim while its mirror still says it is — that is what
|
|
2800
|
+
// kept a retired main open after its worker's runner was proven gone
|
|
2801
|
+
// (STOE-1663), because the stop fence could never be reached.
|
|
2802
|
+
if (job.handoffId) this._forgetHandoff({handoffId: job.handoffId, jobId: job.id})
|
|
2803
|
+
|
|
2796
2804
|
try {
|
|
2797
2805
|
this._emitBackgroundJobOrphaned({job})
|
|
2798
2806
|
} catch (error) {
|
|
@@ -13,6 +13,7 @@ import BackgroundJobRescheduleSignal from "./reschedule-signal.js"
|
|
|
13
13
|
import performBackgroundJob from "./perform-job.js"
|
|
14
14
|
import { runWithBackgroundJobPayload } from "./execution-context.js"
|
|
15
15
|
import { createGenerationWorkerId } from "./generation-identity.js"
|
|
16
|
+
import { isProcessAlive } from "./owner-liveness.js"
|
|
16
17
|
import BackgroundJobsGenerationHandshakeTimeoutError, { DEFAULT_GENERATION_HANDSHAKE_TIMEOUT_MS, validateGenerationHandshakeTimeoutMs } from "./generation-handshake-timeout-error.js"
|
|
17
18
|
import { POOLED_RUNNER_INFLIGHT_JOB_ID_LIMIT, boundedPooledRunnerInflightJobIds, isPooledChildShutdownReason, isPooledChildShutdownSignal } from "./pooled-runner-shutdown.js"
|
|
18
19
|
|
|
@@ -33,7 +34,9 @@ import { POOLED_RUNNER_INFLIGHT_JOB_ID_LIMIT, boundedPooledRunnerInflightJobIds,
|
|
|
33
34
|
* One live runner child, kept so a shutdown that runs out of drain time can name
|
|
34
35
|
* the exact process it is still waiting on instead of a bare count.
|
|
35
36
|
* @typedef {object} ProcessJobHolder
|
|
37
|
+
* @property {number | null} childPid - OS pid recorded for the runner, or null when the fork gave none.
|
|
36
38
|
* @property {string} jobId - Job the child was handed.
|
|
39
|
+
* @property {(() => void)} settle - Frees the worker's in-flight entry for this job.
|
|
37
40
|
* @property {number} startedAtMs - When the worker handed it that job.
|
|
38
41
|
*/
|
|
39
42
|
/**
|
|
@@ -590,6 +593,7 @@ export default class BackgroundJobsWorker {
|
|
|
590
593
|
|
|
591
594
|
await this._drainInflight(this.inflightInlineJobs, timeoutMs, {phase: "inline-jobs"})
|
|
592
595
|
await this._drainInflight(this.inflightPooledJobs, timeoutMs, {phase: "pooled-jobs"})
|
|
596
|
+
this._releaseProcessJobHoldersWithGoneChildren()
|
|
593
597
|
await this._drainInflight(this.inflightProcessJobs, timeoutMs, {phase: "process-jobs", describeHolders: () => this._describeProcessJobHolders()})
|
|
594
598
|
await this._terminateProcessChildren()
|
|
595
599
|
// Give in-flight result reports (now decoupled from job slots) a bounded
|
|
@@ -635,6 +639,7 @@ export default class BackgroundJobsWorker {
|
|
|
635
639
|
|
|
636
640
|
await this._drainInflight(this.inflightInlineJobs)
|
|
637
641
|
await this._drainInflight(this.inflightPooledJobs)
|
|
642
|
+
this._releaseProcessJobHoldersWithGoneChildren()
|
|
638
643
|
await this._drainInflight(this.inflightProcessJobs)
|
|
639
644
|
await this._drainInflight(this.inflightReports)
|
|
640
645
|
|
|
@@ -722,6 +727,48 @@ export default class BackgroundJobsWorker {
|
|
|
722
727
|
return [...this.processChildJobs.values()].sort((left, right) => left.startedAtMs - right.startedAtMs)
|
|
723
728
|
}
|
|
724
729
|
|
|
730
|
+
/**
|
|
731
|
+
* Frees in-flight process-job entries whose recorded runner pid no longer
|
|
732
|
+
* exists, so an unbounded drain can reach child termination.
|
|
733
|
+
*
|
|
734
|
+
* A drain that has no bound can only be pinned by work that is still able to
|
|
735
|
+
* report its outcome. A holder whose recorded pid has no process cannot report
|
|
736
|
+
* and cannot produce the exit observation that would have freed the entry, so
|
|
737
|
+
* the drain waits on it forever and never reaches `_terminateProcessChildren()`
|
|
738
|
+
* — the shape that kept a retired generation alive across four deploys on
|
|
739
|
+
* 2026-11-12 (STOE-1663). This is one proof-of-absence check at the point the
|
|
740
|
+
* drain begins, not a polling layer: a child that is still alive keeps the
|
|
741
|
+
* indefinite wait it was designed to have, because a live runner with a live
|
|
742
|
+
* job must never be cut off by this path (STOE-1077), and its exit observation
|
|
743
|
+
* is the event that frees its entry when it does go.
|
|
744
|
+
* @returns {ProcessJobHolder[]} - Holders freed, in recording order.
|
|
745
|
+
*/
|
|
746
|
+
_releaseProcessJobHoldersWithGoneChildren() {
|
|
747
|
+
const released = []
|
|
748
|
+
|
|
749
|
+
for (const holder of [...this.processChildJobs.values()]) {
|
|
750
|
+
if (holder.childPid === null || isProcessAlive(holder.childPid)) continue
|
|
751
|
+
|
|
752
|
+
released.push(holder)
|
|
753
|
+
holder.settle()
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
if (released.length > 0) {
|
|
757
|
+
const nowMs = Date.now()
|
|
758
|
+
|
|
759
|
+
console.error(JSON.stringify({
|
|
760
|
+
event: "worker-shutdown-gone-runner-released",
|
|
761
|
+
runners: released.map((holder) => ({
|
|
762
|
+
childPid: holder.childPid,
|
|
763
|
+
heldMs: nowMs - holder.startedAtMs,
|
|
764
|
+
jobId: holder.jobId
|
|
765
|
+
}))
|
|
766
|
+
}))
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
return released
|
|
770
|
+
}
|
|
771
|
+
|
|
725
772
|
/**
|
|
726
773
|
* Logs one compact drain-timeout event to the worker's own stderr (the surface
|
|
727
774
|
* that reaches the production log), naming the held processes and how long each
|
|
@@ -2234,9 +2281,6 @@ export default class BackgroundJobsWorker {
|
|
|
2234
2281
|
_forkJob(payload) {
|
|
2235
2282
|
const child = this._createForkedChild()
|
|
2236
2283
|
|
|
2237
|
-
this.inflightProcessChildren.add(child)
|
|
2238
|
-
this.processChildJobs.set(child, {jobId: payload.id, startedAtMs: Date.now()})
|
|
2239
|
-
|
|
2240
2284
|
const finished = this._waitForForkedChild({child, payload})
|
|
2241
2285
|
|
|
2242
2286
|
this._sendForkedPayload({child, payload})
|
|
@@ -2244,6 +2288,25 @@ export default class BackgroundJobsWorker {
|
|
|
2244
2288
|
return finished
|
|
2245
2289
|
}
|
|
2246
2290
|
|
|
2291
|
+
/**
|
|
2292
|
+
* Records the live runner child this worker handed a job to, with the resolver
|
|
2293
|
+
* that frees the worker's in-flight entry for it, so a drain can name the exact
|
|
2294
|
+
* process it is waiting on and can prove which of them is no longer there.
|
|
2295
|
+
* @param {object} args - Holder fields.
|
|
2296
|
+
* @param {import("node:child_process").ChildProcess} args.child - Runner child.
|
|
2297
|
+
* @param {import("./types.js").BackgroundJobPayload & {id: string}} args.payload - Job payload.
|
|
2298
|
+
* @param {(() => void)} args.settle - Frees the worker's in-flight entry for this job.
|
|
2299
|
+
* @returns {ProcessJobHolder} - Recorded holder.
|
|
2300
|
+
*/
|
|
2301
|
+
_registerProcessJobHolder({child, payload, settle}) {
|
|
2302
|
+
const holder = {childPid: child.pid ?? null, jobId: payload.id, settle, startedAtMs: Date.now()}
|
|
2303
|
+
|
|
2304
|
+
this.inflightProcessChildren.add(child)
|
|
2305
|
+
this.processChildJobs.set(child, holder)
|
|
2306
|
+
|
|
2307
|
+
return holder
|
|
2308
|
+
}
|
|
2309
|
+
|
|
2247
2310
|
/**
|
|
2248
2311
|
* Runs create forked child.
|
|
2249
2312
|
* @returns {import("node:child_process").ChildProcess} - Forked child process.
|
|
@@ -2283,6 +2346,7 @@ export default class BackgroundJobsWorker {
|
|
|
2283
2346
|
|
|
2284
2347
|
return new Promise((resolve) => {
|
|
2285
2348
|
state.resolve = resolve
|
|
2349
|
+
this._registerProcessJobHolder({child, payload, settle: () => this._settleForkedJob({child, state})})
|
|
2286
2350
|
this._armForkedJobTimeout({child, payload, state})
|
|
2287
2351
|
|
|
2288
2352
|
child.once("message", (message) => {
|
|
@@ -2557,10 +2621,9 @@ export default class BackgroundJobsWorker {
|
|
|
2557
2621
|
env: Object.assign({}, process.env, this._childBackgroundJobsEnvironment(), {VELOCIOUS_JOB_PAYLOAD: encodedPayload})
|
|
2558
2622
|
})
|
|
2559
2623
|
|
|
2560
|
-
this.inflightProcessChildren.add(child)
|
|
2561
|
-
this.processChildJobs.set(child, {jobId: payload.id, startedAtMs: Date.now()})
|
|
2562
|
-
|
|
2563
2624
|
const finished = new Promise((resolve) => {
|
|
2625
|
+
this._registerProcessJobHolder({child, payload, settle: () => resolve(undefined)})
|
|
2626
|
+
|
|
2564
2627
|
child.once("exit", () => {
|
|
2565
2628
|
this.inflightProcessChildren.delete(child)
|
|
2566
2629
|
this.processChildJobs.delete(child)
|
package/build/bin/velocious.js
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import Cli from "../src/cli/index.js"
|
|
4
|
+
import parseProcessArgs from "../src/cli/process-args.js"
|
|
4
5
|
import configurationResolver from "../src/configuration-resolver.js"
|
|
5
6
|
|
|
6
7
|
const processArgs = process.argv.slice(2)
|
|
7
|
-
|
|
8
|
-
const parsedProcessArgs = {}
|
|
9
|
-
|
|
10
|
-
for (let i = 0; i < processArgs.length; i++) {
|
|
11
|
-
const processArg = processArgs[i]
|
|
12
|
-
const singleLetterArgMatch = processArg.match(/^-([a-z])$/)
|
|
13
|
-
const multiLetterArgMatch = processArg.match(/^--([a-z]+)$/)
|
|
14
|
-
const nextArg = processArgs[i + 1]
|
|
15
|
-
const hasValue = typeof nextArg === "string" && !nextArg.startsWith("-")
|
|
16
|
-
const parsedValue = hasValue ? nextArg : true
|
|
17
|
-
|
|
18
|
-
if (singleLetterArgMatch) {
|
|
19
|
-
parsedProcessArgs[singleLetterArgMatch[1]] = parsedValue
|
|
20
|
-
if (hasValue) i++
|
|
21
|
-
} else if (multiLetterArgMatch) {
|
|
22
|
-
parsedProcessArgs[multiLetterArgMatch[1]] = parsedValue
|
|
23
|
-
if (hasValue) i++
|
|
24
|
-
}
|
|
25
|
-
}
|
|
8
|
+
const parsedProcessArgs = parseProcessArgs(processArgs)
|
|
26
9
|
|
|
27
10
|
const configuration = await configurationResolver()
|
|
28
11
|
const debugEnabled = Boolean(parsedProcessArgs.d || parsedProcessArgs.debug)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parses CLI flags into values keyed by long option name without `--`.
|
|
5
|
+
*
|
|
6
|
+
* Hyphenated long flags are parsed as one option name (`--no-server-lock` →
|
|
7
|
+
* `no-server-lock`), so a boolean flag can carry its own words instead of
|
|
8
|
+
* being silently dropped by a single-word pattern.
|
|
9
|
+
* @param {string[]} processArgs - Raw CLI arguments.
|
|
10
|
+
* @returns {Record<string, string | boolean | undefined>} - Values keyed by option name.
|
|
11
|
+
*/
|
|
12
|
+
export default function parseProcessArgs(processArgs) {
|
|
13
|
+
/** @type {Record<string, string | boolean | undefined>} */
|
|
14
|
+
const parsedProcessArgs = {}
|
|
15
|
+
|
|
16
|
+
for (let i = 0; i < processArgs.length; i++) {
|
|
17
|
+
const processArg = processArgs[i]
|
|
18
|
+
const singleLetterArgMatch = processArg.match(/^-([a-z])$/)
|
|
19
|
+
const multiLetterArgMatch = processArg.match(/^--([a-z][a-z-]*)$/)
|
|
20
|
+
const nextArg = processArgs[i + 1]
|
|
21
|
+
const hasValue = typeof nextArg === "string" && !nextArg.startsWith("-")
|
|
22
|
+
const parsedValue = hasValue ? nextArg : true
|
|
23
|
+
|
|
24
|
+
if (singleLetterArgMatch) {
|
|
25
|
+
parsedProcessArgs[singleLetterArgMatch[1]] = parsedValue
|
|
26
|
+
if (hasValue) i++
|
|
27
|
+
} else if (multiLetterArgMatch) {
|
|
28
|
+
parsedProcessArgs[multiLetterArgMatch[1]] = parsedValue
|
|
29
|
+
if (hasValue) i++
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return parsedProcessArgs
|
|
34
|
+
}
|
package/build/configuration.js
CHANGED
|
@@ -286,6 +286,14 @@ export default class VelociousConfiguration {
|
|
|
286
286
|
/** @type {Map<string, number>} */
|
|
287
287
|
_schemaCacheGenerationsByReuseKey = new Map()
|
|
288
288
|
|
|
289
|
+
/**
|
|
290
|
+
* Schema-metadata cache maps keyed by physical database reuse key. Every
|
|
291
|
+
* connection to one physical database shares a single map, so cached table
|
|
292
|
+
* and column introspection survives pool connection churn instead of being
|
|
293
|
+
* re-run on every re-spawned connection.
|
|
294
|
+
* @type {Map<string, Map<string, Promise<ReturnType<typeof JSON.parse>>>>} */
|
|
295
|
+
_schemaCacheMapsByReuseKey = new Map()
|
|
296
|
+
|
|
289
297
|
/**
|
|
290
298
|
* Runs current.
|
|
291
299
|
* @returns {VelociousConfiguration} - The current.
|
|
@@ -1422,6 +1430,8 @@ export default class VelociousConfiguration {
|
|
|
1422
1430
|
this.schemaCacheGenerationForReuseKey(reuseKey) + 1
|
|
1423
1431
|
)
|
|
1424
1432
|
|
|
1433
|
+
this.schemaCacheMapForReuseKey(reuseKey).clear()
|
|
1434
|
+
|
|
1425
1435
|
for (const pool of Object.values(this.databasePools)) {
|
|
1426
1436
|
if (pool.getConfigurationReuseKey() === reuseKey) {
|
|
1427
1437
|
pool.clearSchemaCache()
|
|
@@ -1438,6 +1448,22 @@ export default class VelociousConfiguration {
|
|
|
1438
1448
|
return this._schemaCacheGenerationsByReuseKey.get(reuseKey) || 0
|
|
1439
1449
|
}
|
|
1440
1450
|
|
|
1451
|
+
/**
|
|
1452
|
+
* Returns the schema-metadata cache map shared by every connection to one physical database, creating it on first use.
|
|
1453
|
+
* @param {string} reuseKey - Connection reuse key identifying the physical database.
|
|
1454
|
+
* @returns {Map<string, Promise<ReturnType<typeof JSON.parse>>>} - Shared schema metadata cache map.
|
|
1455
|
+
*/
|
|
1456
|
+
schemaCacheMapForReuseKey(reuseKey) {
|
|
1457
|
+
let schemaCacheMap = this._schemaCacheMapsByReuseKey.get(reuseKey)
|
|
1458
|
+
|
|
1459
|
+
if (!schemaCacheMap) {
|
|
1460
|
+
schemaCacheMap = new Map()
|
|
1461
|
+
this._schemaCacheMapsByReuseKey.set(reuseKey, schemaCacheMap)
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
return schemaCacheMap
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1441
1467
|
/**
|
|
1442
1468
|
* Invalidates record metadata owned by one closed/deleted physical tenant
|
|
1443
1469
|
* database while preserving every other tenant generation.
|
|
@@ -339,6 +339,8 @@ export default class VelociousDatabaseDriversBase {
|
|
|
339
339
|
* Narrows the runtime value to the documented type.
|
|
340
340
|
* @type {(() => void) | undefined} */
|
|
341
341
|
_schemaCacheInvalidator
|
|
342
|
+
/** @type {(() => Map<string, Promise<ReturnType<typeof JSON.parse>>>) | undefined} */
|
|
343
|
+
_schemaCacheMapProvider
|
|
342
344
|
/**
|
|
343
345
|
* Narrows the runtime value to the documented type.
|
|
344
346
|
* @type {string | undefined} */
|
|
@@ -803,7 +805,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
803
805
|
* @returns {void} - No return value.
|
|
804
806
|
*/
|
|
805
807
|
_clearLocalSchemaCache() {
|
|
806
|
-
this.
|
|
808
|
+
this._schemaCacheMap().clear()
|
|
807
809
|
}
|
|
808
810
|
|
|
809
811
|
/**
|
|
@@ -815,6 +817,25 @@ export default class VelociousDatabaseDriversBase {
|
|
|
815
817
|
this._schemaCacheInvalidator = invalidator
|
|
816
818
|
}
|
|
817
819
|
|
|
820
|
+
/**
|
|
821
|
+
* Runs set schema cache map provider.
|
|
822
|
+
* @param {() => Map<string, Promise<ReturnType<typeof JSON.parse>>>} provider - Returns the schema-metadata cache map shared by every connection to this driver's physical database.
|
|
823
|
+
* @returns {void} - No return value.
|
|
824
|
+
*/
|
|
825
|
+
setSchemaCacheMapProvider(provider) {
|
|
826
|
+
this._schemaCacheMapProvider = provider
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Returns the schema-metadata cache map: the configuration-owned map shared by every connection to the same physical database when the pool stamped a reuse key, otherwise this instance's own map. Sharing survives pool connection churn (idle reaping, pool maximums) so a re-spawned connection does not re-introspect every table.
|
|
831
|
+
* @returns {Map<string, Promise<ReturnType<typeof JSON.parse>>>} - The schema metadata cache map.
|
|
832
|
+
*/
|
|
833
|
+
_schemaCacheMap() {
|
|
834
|
+
if (this._schemaCacheMapProvider) return this._schemaCacheMapProvider()
|
|
835
|
+
|
|
836
|
+
return this._schemaCache
|
|
837
|
+
}
|
|
838
|
+
|
|
818
839
|
/**
|
|
819
840
|
* Runs schema cache enabled.
|
|
820
841
|
* @returns {boolean} - Whether schema metadata caching is enabled.
|
|
@@ -879,7 +900,8 @@ export default class VelociousDatabaseDriversBase {
|
|
|
879
900
|
async _cachedSchemaMetadata(cacheKey, callback) {
|
|
880
901
|
if (!this._schemaCacheEnabled()) return await this._withSchemaMetadataDdlRetry(callback)
|
|
881
902
|
|
|
882
|
-
const
|
|
903
|
+
const schemaCache = this._schemaCacheMap()
|
|
904
|
+
const existingPromise = schemaCache.get(cacheKey)
|
|
883
905
|
|
|
884
906
|
if (existingPromise) {
|
|
885
907
|
return /** @type {T} */ (this._schemaCacheReturnValue(await existingPromise))
|
|
@@ -887,13 +909,13 @@ export default class VelociousDatabaseDriversBase {
|
|
|
887
909
|
|
|
888
910
|
const promise = (async () => await this._withSchemaMetadataDdlRetry(callback))()
|
|
889
911
|
|
|
890
|
-
|
|
912
|
+
schemaCache.set(cacheKey, promise)
|
|
891
913
|
|
|
892
914
|
try {
|
|
893
915
|
return /** @type {T} */ (this._schemaCacheReturnValue(await promise))
|
|
894
916
|
} catch (error) {
|
|
895
|
-
if (
|
|
896
|
-
|
|
917
|
+
if (schemaCache.get(cacheKey) === promise) {
|
|
918
|
+
schemaCache.delete(cacheKey)
|
|
897
919
|
}
|
|
898
920
|
|
|
899
921
|
throw error
|
|
@@ -924,7 +946,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
924
946
|
seedTableSchemaMetadata(tableName, metadataName, value) {
|
|
925
947
|
if (!this._schemaCacheEnabled()) return
|
|
926
948
|
|
|
927
|
-
this.
|
|
949
|
+
this._schemaCacheMap().set(`table:${tableName}:${metadataName}`, Promise.resolve(value))
|
|
928
950
|
}
|
|
929
951
|
|
|
930
952
|
/**
|
|
@@ -939,11 +961,11 @@ export default class VelociousDatabaseDriversBase {
|
|
|
939
961
|
if (!this._schemaCacheEnabled()) return
|
|
940
962
|
if (tables.length === 0) return
|
|
941
963
|
|
|
942
|
-
const
|
|
964
|
+
const batchedColumnRows = await this.batchTableColumns(tables)
|
|
943
965
|
|
|
944
|
-
if (
|
|
945
|
-
for (const [tableName,
|
|
946
|
-
this.seedTableSchemaMetadata(tableName, "columns",
|
|
966
|
+
if (batchedColumnRows) {
|
|
967
|
+
for (const [tableName, columnRows] of batchedColumnRows) {
|
|
968
|
+
this.seedTableSchemaMetadata(tableName, "columns", columnRows)
|
|
947
969
|
}
|
|
948
970
|
|
|
949
971
|
return
|
|
@@ -963,7 +985,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
963
985
|
* answer for several tables in one statement return null, leaving the caller to
|
|
964
986
|
* read them per table.
|
|
965
987
|
* @param {Array<import("./base-table.js").default>} tables - Tables to load columns for.
|
|
966
|
-
* @returns {Promise<Map<string, Array<
|
|
988
|
+
* @returns {Promise<Map<string, Array<Record<string, ReturnType<typeof JSON.parse>>>> | null>} - Raw column rows keyed by table name, or null when unsupported.
|
|
967
989
|
*/
|
|
968
990
|
async batchTableColumns(tables) {
|
|
969
991
|
void tables
|
|
@@ -2339,7 +2361,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
2339
2361
|
driverClass: this.constructor.name,
|
|
2340
2362
|
idSeq: this.idSeq,
|
|
2341
2363
|
openTransactions: this._transactionsCount,
|
|
2342
|
-
schemaCacheEntries: this.
|
|
2364
|
+
schemaCacheEntries: this._schemaCacheMap().size
|
|
2343
2365
|
}
|
|
2344
2366
|
}
|
|
2345
2367
|
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import AlterTable from "./sql/alter-table.js"
|
|
4
4
|
import Base from "../base.js"
|
|
5
|
-
import Column from "./column.js"
|
|
6
5
|
import CreateDatabase from "./sql/create-database.js"
|
|
7
6
|
import CreateIndex from "./sql/create-index.js"
|
|
8
7
|
import CreateTable from "./sql/create-table.js"
|
|
@@ -499,22 +498,22 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
499
498
|
* @returns {Promise<Array<import("../base-table.js").default>>} - Resolves with the tables.
|
|
500
499
|
*/
|
|
501
500
|
async getTables() {
|
|
502
|
-
|
|
501
|
+
const tableRows = await this._cachedSchemaMetadata("tables", async () => {
|
|
503
502
|
const schema = this.getArgs()?.schema || this.getArgs()?.sqlConfig?.options?.schema
|
|
504
503
|
const schemaClause = schema
|
|
505
504
|
? ` AND [TABLE_SCHEMA] = ${this.quote(schema)}`
|
|
506
505
|
: " AND [TABLE_SCHEMA] = SCHEMA_NAME()"
|
|
507
|
-
|
|
508
|
-
|
|
506
|
+
return await this.query(`SELECT [TABLE_NAME] FROM [INFORMATION_SCHEMA].[TABLES] WHERE [TABLE_CATALOG] = DB_NAME()${schemaClause}`)
|
|
507
|
+
})
|
|
508
|
+
const tables = []
|
|
509
509
|
|
|
510
|
-
|
|
511
|
-
|
|
510
|
+
for (const row of tableRows) {
|
|
511
|
+
const table = new Table(this, /** @type {Record<string, string>} */ (row))
|
|
512
512
|
|
|
513
|
-
|
|
514
|
-
|
|
513
|
+
tables.push(table)
|
|
514
|
+
}
|
|
515
515
|
|
|
516
|
-
|
|
517
|
-
})
|
|
516
|
+
return tables
|
|
518
517
|
}
|
|
519
518
|
|
|
520
519
|
/**
|
|
@@ -523,13 +522,13 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
523
522
|
* does against the legacy SQL Server, so it is worth combining regardless of the
|
|
524
523
|
* number of tables.
|
|
525
524
|
* @param {Array<import("../base-table.js").default>} tables - Tables to load columns for.
|
|
526
|
-
* @returns {Promise<Map<string, Array<
|
|
525
|
+
* @returns {Promise<Map<string, Array<Record<string, ReturnType<typeof JSON.parse>>>>>} - Raw column rows keyed by table name.
|
|
527
526
|
*/
|
|
528
527
|
async batchTableColumns(tables) {
|
|
529
|
-
/** @type {Map<string, Array<
|
|
530
|
-
const
|
|
528
|
+
/** @type {Map<string, Array<Record<string, ReturnType<typeof JSON.parse>>>>} */
|
|
529
|
+
const rowsByTable = new Map()
|
|
531
530
|
|
|
532
|
-
if (tables.length === 0) return
|
|
531
|
+
if (tables.length === 0) return rowsByTable
|
|
533
532
|
|
|
534
533
|
const schema = this.getArgs()?.schema || this.getArgs()?.sqlConfig?.options?.schema
|
|
535
534
|
const schemaClause = schema
|
|
@@ -566,13 +565,13 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
566
565
|
|
|
567
566
|
if (!table) continue
|
|
568
567
|
|
|
569
|
-
const
|
|
568
|
+
const tableRows = rowsByTable.get(tableName) || []
|
|
570
569
|
|
|
571
|
-
|
|
572
|
-
|
|
570
|
+
tableRows.push(/** @type {Record<string, ReturnType<typeof JSON.parse>>} */ (row))
|
|
571
|
+
rowsByTable.set(tableName, tableRows)
|
|
573
572
|
}
|
|
574
573
|
|
|
575
|
-
return
|
|
574
|
+
return rowsByTable
|
|
576
575
|
}
|
|
577
576
|
|
|
578
577
|
/**
|