velocious 1.0.724 → 1.0.726
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 +1 -1
- package/build/background-jobs/adapter.js +16 -0
- package/build/background-jobs/job-record.js +3 -1
- package/build/background-jobs/main.js +62 -2
- package/build/background-jobs/owner-liveness.js +27 -5
- package/build/background-jobs/store.js +130 -20
- package/build/background-jobs/types.js +3 -0
- package/build/configuration.js +36 -1
- package/build/database/drivers/mysql/index.js +29 -0
- package/build/src/background-jobs/adapter.d.ts +23 -0
- package/build/src/background-jobs/adapter.d.ts.map +1 -1
- package/build/src/background-jobs/adapter.js +15 -1
- package/build/src/background-jobs/job-record.d.ts +3 -1
- package/build/src/background-jobs/job-record.d.ts.map +1 -1
- package/build/src/background-jobs/job-record.js +4 -2
- package/build/src/background-jobs/main.d.ts +33 -0
- package/build/src/background-jobs/main.d.ts.map +1 -1
- package/build/src/background-jobs/main.js +59 -3
- package/build/src/background-jobs/owner-liveness.d.ts +25 -3
- package/build/src/background-jobs/owner-liveness.d.ts.map +1 -1
- package/build/src/background-jobs/owner-liveness.js +26 -7
- package/build/src/background-jobs/store.d.ts +60 -7
- package/build/src/background-jobs/store.d.ts.map +1 -1
- package/build/src/background-jobs/store.js +123 -20
- package/build/src/background-jobs/types.d.ts +6 -0
- package/build/src/background-jobs/types.d.ts.map +1 -1
- package/build/src/background-jobs/types.js +4 -1
- package/build/src/configuration.d.ts +22 -0
- package/build/src/configuration.d.ts.map +1 -1
- package/build/src/configuration.js +30 -2
- package/build/src/database/drivers/mysql/index.d.ts.map +1 -1
- package/build/src/database/drivers/mysql/index.js +27 -1
- package/package.json +1 -1
- package/src/background-jobs/adapter.js +16 -0
- package/src/background-jobs/job-record.js +3 -1
- package/src/background-jobs/main.js +62 -2
- package/src/background-jobs/owner-liveness.js +27 -5
- package/src/background-jobs/store.js +130 -20
- package/src/background-jobs/types.js +3 -0
- package/src/configuration.js +36 -1
- package/src/database/drivers/mysql/index.js +29 -0
|
@@ -18,6 +18,14 @@ import os from "node:os"
|
|
|
18
18
|
* @property {BackgroundJobOwnerLivenessStatus} status - Liveness verdict.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* A runner process this main currently observes as live, used to disprove a
|
|
23
|
+
* recorded pid that the OS has recycled onto a different runner.
|
|
24
|
+
* @typedef {object} BackgroundJobLiveChildIdentity
|
|
25
|
+
* @property {string | null} childInstanceId - Stable pooled-child identity of the live runner.
|
|
26
|
+
* @property {number} childPid - OS pid of the live runner.
|
|
27
|
+
*/
|
|
28
|
+
|
|
21
29
|
/**
|
|
22
30
|
* Probes a local pid without signalling the target process. `EPERM` means the
|
|
23
31
|
* process exists but belongs to another user, so it counts as alive; `ESRCH`
|
|
@@ -49,12 +57,16 @@ export function isProcessAlive(pid) {
|
|
|
49
57
|
* another machine the result is `unknown`, because liveness there needs a
|
|
50
58
|
* heartbeat or instance registry rather than a local probe. A pid alone can be
|
|
51
59
|
* recycled by the OS after a process exits, so treat `alive` as "a process with
|
|
52
|
-
* that pid exists now", not proof that it is the same process
|
|
53
|
-
* `
|
|
60
|
+
* that pid exists now", not proof that it is the same process. `child_instance_id`
|
|
61
|
+
* is a UUID and cannot be recycled: when `liveChildren` shows the recorded pid
|
|
62
|
+
* currently belongs to a runner with a different instance identity, the recorded
|
|
63
|
+
* runner is provably gone and the verdict is `dead` (`local_pid_recycled`)
|
|
64
|
+
* instead of a false `alive`.
|
|
54
65
|
* @param {object} [args] - Options.
|
|
55
66
|
* @param {string | null} [args.childInstanceId] - Recorded pooled-child identity.
|
|
56
67
|
* @param {number | null} [args.childPid] - Recorded OS pid.
|
|
57
68
|
* @param {string} [args.currentHostname] - Hostname of this process, defaults to `os.hostname()`.
|
|
69
|
+
* @param {BackgroundJobLiveChildIdentity[]} [args.liveChildren] - Runner identities this main observes as live, for the pid-recycling check.
|
|
58
70
|
* @param {(pid: number) => boolean} [args.probe] - Process probe, injectable for tests.
|
|
59
71
|
* @param {string | null} [args.runnerHostname] - Hostname recorded with the job.
|
|
60
72
|
* @returns {BackgroundJobOwnerLivenessResult} - Liveness verdict with its reason.
|
|
@@ -63,6 +75,7 @@ export function evaluateBackgroundJobOwnerLiveness({
|
|
|
63
75
|
childInstanceId = null,
|
|
64
76
|
childPid = null,
|
|
65
77
|
currentHostname = os.hostname(),
|
|
78
|
+
liveChildren = [],
|
|
66
79
|
probe = isProcessAlive,
|
|
67
80
|
runnerHostname = null
|
|
68
81
|
} = {}) {
|
|
@@ -86,7 +99,16 @@ export function evaluateBackgroundJobOwnerLiveness({
|
|
|
86
99
|
|
|
87
100
|
const probedPid = /** @type {number} */ (owner.childPid)
|
|
88
101
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
if (!probe(probedPid)) return {...owner, reason: "local_pid_missing", status: "dead"}
|
|
103
|
+
|
|
104
|
+
// PID-recycling guard: a live pid whose instance identity differs from the
|
|
105
|
+
// recorded one proves the recorded runner exited and the OS handed its pid
|
|
106
|
+
// to a new runner — the honest verdict is dead, not a false alive.
|
|
107
|
+
if (owner.childInstanceId) {
|
|
108
|
+
const recycledBy = liveChildren.find((child) => child.childPid === probedPid && child.childInstanceId !== null && child.childInstanceId !== owner.childInstanceId)
|
|
109
|
+
|
|
110
|
+
if (recycledBy) return {...owner, reason: "local_pid_recycled", status: "dead"}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {...owner, reason: "local_pid_alive", status: "alive"}
|
|
92
114
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
import {createHash, randomUUID} from "crypto"
|
|
4
|
+
import os from "node:os"
|
|
4
5
|
import BackgroundJobsAdapter from "./adapter.js"
|
|
5
6
|
import Logger from "../logger.js"
|
|
6
7
|
import TableData from "../database/table-data/index.js"
|
|
7
8
|
import VelociousError from "../velocious-error.js"
|
|
8
9
|
import BackgroundJobRecord from "./job-record.js"
|
|
9
10
|
import normalizeBackgroundJobError from "./normalize-error.js"
|
|
11
|
+
import {evaluateBackgroundJobOwnerLiveness, isProcessAlive} from "./owner-liveness.js"
|
|
10
12
|
import { coordinateSharedTransactionConnection } from "../testing/shared-transaction-connection-coordinator.js"
|
|
11
13
|
import stableJsonStringify from "../utils/stable-json.js"
|
|
12
14
|
import {
|
|
@@ -51,6 +53,7 @@ import {
|
|
|
51
53
|
* BackgroundJobOrphanSelection type.
|
|
52
54
|
* @typedef {object} BackgroundJobOrphanSelection
|
|
53
55
|
* @property {Record<string, ReturnType<typeof JSON.parse>>} conditions - Exact update fence.
|
|
56
|
+
* @property {ReturnType<typeof JSON.parse>} error - Orphan reason for this selection.
|
|
54
57
|
* @property {import("./types.js").BackgroundJobRow} job - Selected active handoff.
|
|
55
58
|
*/
|
|
56
59
|
|
|
@@ -1679,14 +1682,89 @@ export default class BackgroundJobsStore extends BackgroundJobsAdapter {
|
|
|
1679
1682
|
status: "handed_off",
|
|
1680
1683
|
worker_id: handoff.workerId
|
|
1681
1684
|
},
|
|
1685
|
+
error,
|
|
1682
1686
|
job
|
|
1683
1687
|
})
|
|
1684
1688
|
}
|
|
1685
1689
|
|
|
1686
|
-
return await this._markOrphanSelections({db,
|
|
1690
|
+
return await this._markOrphanSelections({db, selections})
|
|
1687
1691
|
})
|
|
1688
1692
|
}
|
|
1689
1693
|
|
|
1694
|
+
/**
|
|
1695
|
+
* Evaluates the recorded runner-process liveness of every exact, lease-aware
|
|
1696
|
+
* active handoff through {@link BackgroundJobRecord#ownerIsAlive}. Rows without
|
|
1697
|
+
* a complete lease identity stay out of the verdicts — they belong to the
|
|
1698
|
+
* age-based legacy sweep. The probe and live-child list are injectable so
|
|
1699
|
+
* specs can prove dead/recycled verdicts deterministically.
|
|
1700
|
+
* @param {object} [args] - Options.
|
|
1701
|
+
* @param {string} [args.hostname] - Hostname whose local probe answers ownership, defaults to this process's hostname.
|
|
1702
|
+
* @param {import("./owner-liveness.js").BackgroundJobLiveChildIdentity[]} [args.liveChildren] - Runner identities this main observes as live, for the pid-recycling check.
|
|
1703
|
+
* @param {(pid: number) => boolean} [args.probe] - Process probe, injectable for tests.
|
|
1704
|
+
* @returns {Promise<import("./types.js").BackgroundJobHandoffOwnershipVerdict[]>} - One verdict per exact active handoff.
|
|
1705
|
+
*/
|
|
1706
|
+
async snapshotHandedOffJobOwnership({hostname, liveChildren = [], probe} = {}) {
|
|
1707
|
+
await this.ensureReady()
|
|
1708
|
+
|
|
1709
|
+
return await this._withDb(async (db) => {
|
|
1710
|
+
const rows = await db
|
|
1711
|
+
.newQuery()
|
|
1712
|
+
.from(JOBS_TABLE)
|
|
1713
|
+
.where({status: "handed_off"})
|
|
1714
|
+
.order("created_at_ms ASC")
|
|
1715
|
+
.order("id ASC")
|
|
1716
|
+
.results()
|
|
1717
|
+
/** @type {import("./types.js").BackgroundJobHandoffOwnershipVerdict[]} */
|
|
1718
|
+
const verdicts = []
|
|
1719
|
+
|
|
1720
|
+
for (const row of rows) {
|
|
1721
|
+
const job = this._normalizeJobRow(row)
|
|
1722
|
+
|
|
1723
|
+
if (!job.handoffId || !job.workerId || typeof job.handedOffAtMs !== "number") continue
|
|
1724
|
+
|
|
1725
|
+
const record = new BackgroundJobRecord()
|
|
1726
|
+
|
|
1727
|
+
record.loadExistingRecord(row)
|
|
1728
|
+
verdicts.push({
|
|
1729
|
+
handedOffAtMs: job.handedOffAtMs,
|
|
1730
|
+
handoffId: job.handoffId,
|
|
1731
|
+
jobId: job.id,
|
|
1732
|
+
liveness: record.ownerIsAlive({hostname, liveChildren, probe}),
|
|
1733
|
+
workerId: job.workerId
|
|
1734
|
+
})
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
return verdicts
|
|
1738
|
+
})
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
/**
|
|
1742
|
+
* Settles every exact active handoff whose recorded runner process is
|
|
1743
|
+
* provably dead on this host, regardless of which generation created the
|
|
1744
|
+
* lease. Owners that answer `alive` (still running) or `unknown` (remote
|
|
1745
|
+
* host, identity recorded before hostnames/pids existed) stay untouched for
|
|
1746
|
+
* their existing recovery paths. Each settled row goes through the same
|
|
1747
|
+
* fenced orphan transition as the orphan sweep, so retries, terminal status,
|
|
1748
|
+
* `orphaned_at_ms`/`last_error` stamping, count transitions, schedule
|
|
1749
|
+
* ownership, and concurrency release all follow.
|
|
1750
|
+
* @param {object} [args] - Options.
|
|
1751
|
+
* @param {ReturnType<typeof JSON.parse>} [args.error] - Orphan reason recorded on settled rows.
|
|
1752
|
+
* @param {string} [args.hostname] - Hostname whose local probe answers ownership, defaults to this process's hostname.
|
|
1753
|
+
* @param {import("./owner-liveness.js").BackgroundJobLiveChildIdentity[]} [args.liveChildren] - Runner identities this main observes as live, for the pid-recycling check.
|
|
1754
|
+
* @param {(pid: number) => boolean} [args.probe] - Process probe, injectable for tests.
|
|
1755
|
+
* @returns {Promise<import("./types.js").BackgroundJobRow[]>} - Accepted orphan transitions.
|
|
1756
|
+
*/
|
|
1757
|
+
async markOrphanedHandoffsByDeadOwner({error = "Job orphaned when its recorded runner process was found dead", hostname, liveChildren = [], probe} = {}) {
|
|
1758
|
+
await this.ensureReady()
|
|
1759
|
+
|
|
1760
|
+
const verdicts = await this.snapshotHandedOffJobOwnership({hostname, liveChildren, probe})
|
|
1761
|
+
const deadHandoffs = verdicts.filter((verdict) => verdict.liveness.status === "dead")
|
|
1762
|
+
|
|
1763
|
+
if (deadHandoffs.length === 0) return []
|
|
1764
|
+
|
|
1765
|
+
return await this.markOrphanedHandoffs({error, handoffs: deadHandoffs})
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1690
1768
|
/**
|
|
1691
1769
|
* Runs mark failed.
|
|
1692
1770
|
* @param {object} args - Options.
|
|
@@ -1714,29 +1792,65 @@ export default class BackgroundJobsStore extends BackgroundJobsAdapter {
|
|
|
1714
1792
|
}
|
|
1715
1793
|
|
|
1716
1794
|
/**
|
|
1717
|
-
*
|
|
1795
|
+
* Reaps `handed_off` jobs whose executing child is gone. A live child is
|
|
1796
|
+
* never reaped: a job that is still running (or whose child is still
|
|
1797
|
+
* starting) keeps its lease and its concurrency slot. A child recorded on
|
|
1798
|
+
* this host is reaped only when the handoff age exceeds the job's effective
|
|
1799
|
+
* timeout AND the pid probe proves the child is gone — never on age alone,
|
|
1800
|
+
* because a pid that still exists may be the same child mid-startup. Rows
|
|
1801
|
+
* whose liveness cannot be answered (remote runner host, or no recorded pid)
|
|
1802
|
+
* stay under the bounded age sweep, which is the recovery path for crashes
|
|
1803
|
+
* that cannot report (container restart, OOM kill).
|
|
1718
1804
|
* @param {object} [args] - Options.
|
|
1719
|
-
* @param {number} [args.orphanedAfterMs] - Mark jobs orphaned after this duration.
|
|
1805
|
+
* @param {number} [args.orphanedAfterMs] - Mark jobs orphaned after this duration when liveness is unknown.
|
|
1806
|
+
* @param {(pid: number) => boolean} [args.livenessProbe] - Process probe for local children, injectable for tests.
|
|
1807
|
+
* @param {string} [args.currentHostname] - Hostname of this process, defaults to `os.hostname()`.
|
|
1720
1808
|
* @returns {Promise<import("./types.js").BackgroundJobRow[]>} - The jobs this sweep marked orphaned.
|
|
1721
1809
|
*/
|
|
1722
|
-
async markOrphanedJobs({orphanedAfterMs = ORPHANED_AFTER_MS} = {}) {
|
|
1810
|
+
async markOrphanedJobs({orphanedAfterMs = ORPHANED_AFTER_MS, livenessProbe = isProcessAlive, currentHostname = os.hostname()} = {}) {
|
|
1723
1811
|
await this.ensureReady()
|
|
1724
1812
|
|
|
1725
1813
|
return await this._serializedCountMutation(async (db) => {
|
|
1726
|
-
const
|
|
1727
|
-
const
|
|
1814
|
+
const now = this.clock.now()
|
|
1815
|
+
const rows = await db
|
|
1728
1816
|
.newQuery()
|
|
1729
1817
|
.from(JOBS_TABLE)
|
|
1730
1818
|
.where({status: "handed_off"})
|
|
1731
|
-
.
|
|
1732
|
-
|
|
1733
|
-
const rows = await query.results()
|
|
1819
|
+
.results()
|
|
1734
1820
|
|
|
1735
1821
|
/** @type {BackgroundJobOrphanSelection[]} */
|
|
1736
1822
|
const selections = []
|
|
1737
1823
|
|
|
1738
1824
|
for (const row of rows) {
|
|
1739
1825
|
const job = this._normalizeJobRow(row)
|
|
1826
|
+
// A handed-off row without a handoff timestamp cannot be aged; it stays
|
|
1827
|
+
// for startup reconciliation rather than being reaped blindly.
|
|
1828
|
+
if (job.handedOffAtMs === null) continue
|
|
1829
|
+
const ageMs = now - job.handedOffAtMs
|
|
1830
|
+
const liveness = evaluateBackgroundJobOwnerLiveness({
|
|
1831
|
+
childInstanceId: job.childInstanceId,
|
|
1832
|
+
childPid: job.childPid,
|
|
1833
|
+
currentHostname,
|
|
1834
|
+
probe: livenessProbe,
|
|
1835
|
+
runnerHostname: job.runnerHostname
|
|
1836
|
+
})
|
|
1837
|
+
|
|
1838
|
+
if (liveness.status === "alive") continue
|
|
1839
|
+
|
|
1840
|
+
/** @type {ReturnType<typeof JSON.parse>} */
|
|
1841
|
+
let error
|
|
1842
|
+
|
|
1843
|
+
if (liveness.status === "dead") {
|
|
1844
|
+
const effectiveTimeoutMs = job.timeoutMs ?? this.configuration.getBackgroundJobsConfig().jobTimeoutMs ?? orphanedAfterMs
|
|
1845
|
+
|
|
1846
|
+
if (ageMs <= effectiveTimeoutMs) continue
|
|
1847
|
+
error = `Job orphaned: handoff child ${liveness.reason} after ${ageMs}ms (timeout ${effectiveTimeoutMs}ms)`
|
|
1848
|
+
} else {
|
|
1849
|
+
// Matches the original sweep boundary: `handed_off_at_ms <= now - orphanedAfterMs`,
|
|
1850
|
+
// i.e. reap when the age reaches the configured window.
|
|
1851
|
+
if (ageMs < orphanedAfterMs) continue
|
|
1852
|
+
error = "Job orphaned after timeout"
|
|
1853
|
+
}
|
|
1740
1854
|
|
|
1741
1855
|
// Fence the reclaim on the exact handoff this sweep selected, using its
|
|
1742
1856
|
// `handed_off_at_ms` rather than its `handoff_id`. Two reasons:
|
|
@@ -1749,19 +1863,16 @@ export default class BackgroundJobsStore extends BackgroundJobsAdapter {
|
|
|
1749
1863
|
// `handed_off_at_ms` (always "now"), so this stale cutoff-era
|
|
1750
1864
|
// timestamp no longer matches and we won't fail/orphan — or
|
|
1751
1865
|
// wrongly release the concurrency reservation of — that new lease.
|
|
1752
|
-
// `handed_off_at_ms` is always set on a handed-off row
|
|
1753
|
-
//
|
|
1866
|
+
// `handed_off_at_ms` is always set on a handed-off row, so it is a
|
|
1867
|
+
// reliable null-safe lease pin.
|
|
1754
1868
|
selections.push({
|
|
1755
1869
|
conditions: {id: job.id, status: "handed_off", handed_off_at_ms: job.handedOffAtMs},
|
|
1870
|
+
error,
|
|
1756
1871
|
job
|
|
1757
1872
|
})
|
|
1758
1873
|
}
|
|
1759
1874
|
|
|
1760
|
-
return await this._markOrphanSelections({
|
|
1761
|
-
db,
|
|
1762
|
-
error: "Job orphaned after timeout",
|
|
1763
|
-
selections
|
|
1764
|
-
})
|
|
1875
|
+
return await this._markOrphanSelections({db, selections})
|
|
1765
1876
|
})
|
|
1766
1877
|
}
|
|
1767
1878
|
|
|
@@ -1770,15 +1881,14 @@ export default class BackgroundJobsStore extends BackgroundJobsAdapter {
|
|
|
1770
1881
|
* delta for the accepted rows.
|
|
1771
1882
|
* @param {object} args - Options.
|
|
1772
1883
|
* @param {import("../database/drivers/base.js").default} args.db - Transaction connection.
|
|
1773
|
-
* @param {
|
|
1774
|
-
* @param {BackgroundJobOrphanSelection[]} args.selections - Selected handoffs and exact fences.
|
|
1884
|
+
* @param {BackgroundJobOrphanSelection[]} args.selections - Selected handoffs, per-row orphan reasons and exact fences.
|
|
1775
1885
|
* @returns {Promise<import("./types.js").BackgroundJobRow[]>} - Accepted transitions.
|
|
1776
1886
|
*/
|
|
1777
|
-
async _markOrphanSelections({db,
|
|
1887
|
+
async _markOrphanSelections({db, selections}) {
|
|
1778
1888
|
/** @type {import("./types.js").BackgroundJobRow[]} */
|
|
1779
1889
|
const orphanedJobs = []
|
|
1780
1890
|
|
|
1781
|
-
for (const {conditions, job} of selections) {
|
|
1891
|
+
for (const {conditions, error, job} of selections) {
|
|
1782
1892
|
const orphanedJob = await this._applyFailure({
|
|
1783
1893
|
conditions,
|
|
1784
1894
|
db,
|
|
@@ -159,6 +159,9 @@
|
|
|
159
159
|
* @property {string} workerId - Stable worker id that received the lease.
|
|
160
160
|
* @property {number} handedOffAtMs - Time handed to the worker in ms.
|
|
161
161
|
*/
|
|
162
|
+
/**
|
|
163
|
+
* @typedef {BackgroundJobHandoffSnapshot & {liveness: import("./owner-liveness.js").BackgroundJobOwnerLivenessResult}} BackgroundJobHandoffOwnershipVerdict
|
|
164
|
+
*/
|
|
162
165
|
/**
|
|
163
166
|
* @typedef {object} BackgroundJobHandoffRequest
|
|
164
167
|
* @property {string} jobId - Job to claim.
|
package/src/configuration.js
CHANGED
|
@@ -275,6 +275,14 @@ export default class VelociousConfiguration {
|
|
|
275
275
|
_advisoryLockAcquisitions = new Map()
|
|
276
276
|
_advisoryLockReentries = new Map()
|
|
277
277
|
|
|
278
|
+
/**
|
|
279
|
+
* Per-tier advisory-lock acquisition counters — the "how many locks are
|
|
280
|
+
* served by which tier" attribution surface (STC-218 scope 1). Keyed by
|
|
281
|
+
* tier so production reads tier attribution directly instead of ad-hoc
|
|
282
|
+
* processlist probing.
|
|
283
|
+
* @type {Map<import("./database/advisory-lock-backend-policy.js").AdvisoryLockTier, {count: number, lastServedAt: string}>} */
|
|
284
|
+
_advisoryLockTierCounts = new Map()
|
|
285
|
+
|
|
278
286
|
/** @type {Map<string, number>} */
|
|
279
287
|
_schemaCacheGenerationsByReuseKey = new Map()
|
|
280
288
|
|
|
@@ -4353,7 +4361,34 @@ export default class VelociousConfiguration {
|
|
|
4353
4361
|
* @returns {void}
|
|
4354
4362
|
*/
|
|
4355
4363
|
recordAdvisoryLockAcquisition({lockName, backend, fencingSupported}) {
|
|
4356
|
-
|
|
4364
|
+
const servedAt = new Date().toISOString()
|
|
4365
|
+
|
|
4366
|
+
this._advisoryLockAcquisitions.set(lockName, {backend, fencingSupported, servedAt})
|
|
4367
|
+
|
|
4368
|
+
const tierCount = this._advisoryLockTierCounts.get(backend) ?? {count: 0, lastServedAt: servedAt}
|
|
4369
|
+
|
|
4370
|
+
tierCount.count += 1
|
|
4371
|
+
tierCount.lastServedAt = servedAt
|
|
4372
|
+
this._advisoryLockTierCounts.set(backend, tierCount)
|
|
4373
|
+
}
|
|
4374
|
+
|
|
4375
|
+
/**
|
|
4376
|
+
* The "how many locks are served by which tier" attribution surface
|
|
4377
|
+
* (STC-218 scope 1): per tier, the total acquisitions this process served
|
|
4378
|
+
* and when the tier last served one. Together with
|
|
4379
|
+
* `getAdvisoryLockBackendStatus(lockName)` this is what production reads to
|
|
4380
|
+
* attribute lock traffic to backends without ad-hoc probing.
|
|
4381
|
+
* @returns {Record<string, {count: number, lastServedAt: string}>} - Snapshot of the per-tier counters.
|
|
4382
|
+
*/
|
|
4383
|
+
getAdvisoryLockBackendStats() {
|
|
4384
|
+
/** @type {Record<string, {count: number, lastServedAt: string}>} */
|
|
4385
|
+
const snapshot = {}
|
|
4386
|
+
|
|
4387
|
+
for (const [tier, counter] of this._advisoryLockTierCounts) {
|
|
4388
|
+
snapshot[tier] = {count: counter.count, lastServedAt: counter.lastServedAt}
|
|
4389
|
+
}
|
|
4390
|
+
|
|
4391
|
+
return snapshot
|
|
4357
4392
|
}
|
|
4358
4393
|
|
|
4359
4394
|
/**
|
|
@@ -34,6 +34,33 @@ import parseInnodbDeadlockSummary from "./deadlock-diagnostic-parser.js"
|
|
|
34
34
|
*/
|
|
35
35
|
const MYSQL_INDEFINITE_LOCK_TIMEOUT_SECONDS = 60 * 60 * 24 * 365
|
|
36
36
|
const INNODB_DEADLOCK_CAPTURE_TIMEOUT_MS = 250
|
|
37
|
+
const INFORMATION_SCHEMA_STRING_LITERAL_PATTERN = /^[A-Za-z0-9 _.,:/@+-]*$/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* `information_schema.COLUMNS` reports a string column default as its SQL literal
|
|
41
|
+
* (quoted, e.g. `'normal'`), while `SHOW FULL COLUMNS` reports the bare value
|
|
42
|
+
* (`normal`). Column consumers key on the `SHOW FULL COLUMNS` shape: the schema
|
|
43
|
+
* cloner's simple-default pattern rejects the quoted form, so a batch-read string
|
|
44
|
+
* default would be dropped from the cloned column and an insert that omits it then
|
|
45
|
+
* fails with ER_NO_DEFAULT_FOR_FIELD on the tenant copy. Normalize the batch read
|
|
46
|
+
* to the same shape the per-table read produces.
|
|
47
|
+
* @param {unknown} defaultValue - Raw `COLUMN_DEFAULT` value from the batch read.
|
|
48
|
+
* @returns {unknown} - The default in the `SHOW FULL COLUMNS` shape.
|
|
49
|
+
*/
|
|
50
|
+
function normalizeInformationSchemaDefault(defaultValue) {
|
|
51
|
+
if (typeof defaultValue !== "string") return defaultValue
|
|
52
|
+
|
|
53
|
+
if (defaultValue.length >= 2 && defaultValue.startsWith("'") && defaultValue.endsWith("'")) {
|
|
54
|
+
const innerValue = defaultValue.slice(1, -1)
|
|
55
|
+
|
|
56
|
+
// Only plain string literals are unquoted; expression defaults (e.g.
|
|
57
|
+
// DEFAULT '''UUID()''') keep their stored form, which SHOW FULL COLUMNS
|
|
58
|
+
// also reports verbatim.
|
|
59
|
+
if (INFORMATION_SCHEMA_STRING_LITERAL_PATTERN.test(innerValue)) return innerValue
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return defaultValue
|
|
63
|
+
}
|
|
37
64
|
|
|
38
65
|
export default class VelociousDatabaseDriversMysql extends Base{
|
|
39
66
|
/** @type {import("mysql").Pool | undefined} */
|
|
@@ -807,6 +834,8 @@ export default class VelociousDatabaseDriversMysql extends Base{
|
|
|
807
834
|
|
|
808
835
|
if (!table) continue
|
|
809
836
|
|
|
837
|
+
row.Default = normalizeInformationSchemaDefault(row.Default)
|
|
838
|
+
|
|
810
839
|
const columns = columnsByTable.get(tableName) || []
|
|
811
840
|
|
|
812
841
|
columns.push(new Column(table, /** @type {Record<string, ReturnType<typeof JSON.parse>>} */ (row)))
|