velocious 1.0.757 → 1.0.759

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.
Files changed (41) hide show
  1. package/build/background-jobs/main.js +35 -3
  2. package/build/database/advisory-lock-lock-server-backend.js +10 -0
  3. package/build/database/advisory-lock-runner.js +46 -17
  4. package/build/database/drivers/base-table.js +13 -0
  5. package/build/database/drivers/mssql/table.js +18 -8
  6. package/build/database/drivers/mysql/table.js +14 -4
  7. package/build/database/drivers/pgsql/table.js +18 -8
  8. package/build/database/drivers/sqlite/table.js +16 -6
  9. package/build/src/background-jobs/main.d.ts +14 -0
  10. package/build/src/background-jobs/main.d.ts.map +1 -1
  11. package/build/src/background-jobs/main.js +35 -4
  12. package/build/src/database/advisory-lock-lock-server-backend.d.ts +7 -0
  13. package/build/src/database/advisory-lock-lock-server-backend.d.ts.map +1 -1
  14. package/build/src/database/advisory-lock-lock-server-backend.js +10 -1
  15. package/build/src/database/advisory-lock-runner.d.ts +3 -0
  16. package/build/src/database/advisory-lock-runner.d.ts.map +1 -1
  17. package/build/src/database/advisory-lock-runner.js +43 -18
  18. package/build/src/database/drivers/base-table.d.ts +8 -0
  19. package/build/src/database/drivers/base-table.d.ts.map +1 -1
  20. package/build/src/database/drivers/base-table.js +12 -1
  21. package/build/src/database/drivers/mssql/table.d.ts +7 -2
  22. package/build/src/database/drivers/mssql/table.d.ts.map +1 -1
  23. package/build/src/database/drivers/mssql/table.js +15 -7
  24. package/build/src/database/drivers/mysql/table.d.ts +7 -2
  25. package/build/src/database/drivers/mysql/table.d.ts.map +1 -1
  26. package/build/src/database/drivers/mysql/table.js +13 -5
  27. package/build/src/database/drivers/pgsql/table.d.ts +7 -2
  28. package/build/src/database/drivers/pgsql/table.d.ts.map +1 -1
  29. package/build/src/database/drivers/pgsql/table.js +15 -7
  30. package/build/src/database/drivers/sqlite/table.d.ts +6 -0
  31. package/build/src/database/drivers/sqlite/table.d.ts.map +1 -1
  32. package/build/src/database/drivers/sqlite/table.js +15 -7
  33. package/package.json +1 -1
  34. package/src/background-jobs/main.js +35 -3
  35. package/src/database/advisory-lock-lock-server-backend.js +10 -0
  36. package/src/database/advisory-lock-runner.js +46 -17
  37. package/src/database/drivers/base-table.js +13 -0
  38. package/src/database/drivers/mssql/table.js +18 -8
  39. package/src/database/drivers/mysql/table.js +14 -4
  40. package/src/database/drivers/pgsql/table.js +18 -8
  41. package/src/database/drivers/sqlite/table.js +16 -6
@@ -367,6 +367,9 @@ export default class AdvisoryLockRunner {
367
367
  * A name whose minimum tier is `lock-server` is never served by a weaker
368
368
  * tier: an absent or unreachable server raises
369
369
  * `AdvisoryLockBackendUnavailableError` instead of reporting a fallback.
370
+ * A mandated name still waits for the backend's own bounded re-probe window
371
+ * whenever this acquisition's budget covers it, so a lock-server restart is
372
+ * not mistaken for an unavailable backend.
370
373
  *
371
374
  * `null` means "this tier did not serve the acquisition — continue with the
372
375
  * next eligible tier". A returned value means the lock-server tier answered,
@@ -400,29 +403,55 @@ export default class AdvisoryLockRunner {
400
403
  return null
401
404
  }
402
405
 
406
+ // A mandated tier may only be abandoned once the backend has no bounded
407
+ // reconnect event left inside this acquisition's own budget. The backend
408
+ // publishes that window (`reprobeCooldownRemainingMs`), so the wait is
409
+ // bounded by the backend's own re-probe rather than by a retry policy.
410
+ const acquireBudgetMs = this.acquireTimeoutMs(args)
411
+ const transportWaitBudgetMs = mode === "wait" && acquireBudgetMs !== null ? acquireBudgetMs : null
403
412
  /** @type {boolean} */
404
413
  let acquired
414
+ /** @type {number} */
415
+ let waitedForTransportMs = 0
405
416
 
406
- try {
407
- if (mode === "wait") {
408
- acquired = await backend.acquire(name, {timeoutMs: this.acquireTimeoutMs(args)})
409
- } else {
410
- acquired = await backend.tryAcquire(name)
411
- }
412
- } catch (error) {
413
- if (!(error instanceof AdvisoryLockServiceUnavailableError)) throw error
417
+ for (;;) {
418
+ try {
419
+ if (mode === "wait") {
420
+ const remainingBudgetMs = acquireBudgetMs === null ? null : Math.max(0, acquireBudgetMs - waitedForTransportMs)
414
421
 
415
- if (policy.minTier === "lock-server") {
416
- throw advisoryLockBackendUnavailable({
417
- lockName: name,
418
- minTier: policy.minTier,
419
- reasons: [`lock-server unavailable: ${error.message}`]
420
- })
421
- }
422
+ acquired = await backend.acquire(name, {timeoutMs: remainingBudgetMs})
423
+ } else {
424
+ acquired = await backend.tryAcquire(name)
425
+ }
422
426
 
423
- this.reportAdvisoryLockFallback({reason: error.message, servedBy: "driver-native", lockName: name})
427
+ break
428
+ } catch (error) {
429
+ if (!(error instanceof AdvisoryLockServiceUnavailableError)) throw error
424
430
 
425
- return null
431
+ if (policy.minTier !== "lock-server") {
432
+ this.reportAdvisoryLockFallback({reason: error.message, servedBy: "driver-native", lockName: name})
433
+
434
+ return null
435
+ }
436
+
437
+ const cooldownMs = typeof backend.reprobeCooldownRemainingMs === "function" ? backend.reprobeCooldownRemainingMs() : 0
438
+ // `or-fail`/`defer` declare no wait budget, so their bound is the
439
+ // backend's own single re-probe cycle: one reconnect attempt, never a queue.
440
+ const waitBudgetMs = transportWaitBudgetMs ?? cooldownMs
441
+
442
+ if (cooldownMs <= 0 || waitedForTransportMs + cooldownMs > waitBudgetMs) {
443
+ throw advisoryLockBackendUnavailable({
444
+ lockName: name,
445
+ minTier: policy.minTier,
446
+ reasons: [`lock-server unavailable: ${error.message}`]
447
+ })
448
+ }
449
+
450
+ await new Promise((resolve) => {
451
+ setTimeout(resolve, cooldownMs)
452
+ })
453
+ waitedForTransportMs += cooldownMs
454
+ }
426
455
  }
427
456
 
428
457
  if (!acquired) {
@@ -9,6 +9,19 @@ export default class VelociousDatabaseDriversBaseTable {
9
9
  * @type {import("./base.js").default | undefined} */
10
10
  driver = undefined
11
11
 
12
+ /**
13
+ * Builds this table's column objects from raw introspection rows that were already read,
14
+ * so a batched catalog read and a per-table read produce the same columns.
15
+ * @abstract
16
+ * @param {import("./base.js").QueryResultType} columnRows - Raw column rows for this table.
17
+ * @returns {Array<import("./base-column.js").default>} - Columns built from the rows.
18
+ */
19
+ columnsFromRows(columnRows) {
20
+ void columnRows
21
+
22
+ throw new Error("columnsFromRows not implemented")
23
+ }
24
+
12
25
  /**
13
26
  * Runs get column by name.
14
27
  * @param {string} columnName - Column name.
@@ -63,6 +63,23 @@ export default class VelociousDatabaseDriversMssqlTable extends BaseTable {
63
63
  this.driver = driver
64
64
  }
65
65
 
66
+ /**
67
+ * Builds this table's column objects from raw `INFORMATION_SCHEMA.COLUMNS`-shaped rows.
68
+ * @param {import("../base.js").QueryResultType} columnRows - Raw column rows for this table.
69
+ * @returns {Array<import("../base-column.js").default>} - Columns built from the rows.
70
+ */
71
+ columnsFromRows(columnRows) {
72
+ const columns = []
73
+
74
+ for (const data of columnRows) {
75
+ const column = new Column(this, data)
76
+
77
+ columns.push(column)
78
+ }
79
+
80
+ return columns
81
+ }
82
+
66
83
  async getColumns() {
67
84
  const columnRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
68
85
  const result = await this.driver.query(`
@@ -88,15 +105,8 @@ export default class VelociousDatabaseDriversMssqlTable extends BaseTable {
88
105
  `)
89
106
  return result
90
107
  })
91
- const columns = []
92
-
93
- for (const data of columnRows) {
94
- const column = new Column(this, data)
95
108
 
96
- columns.push(column)
97
- }
98
-
99
- return columns
109
+ return this.columnsFromRows(columnRows)
100
110
  }
101
111
 
102
112
  async getForeignKeys() {
@@ -17,10 +17,12 @@ export default class VelociousDatabaseDriversMysqlTable extends BaseTable {
17
17
  this.driver = driver
18
18
  }
19
19
 
20
- async getColumns() {
21
- const columnRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
22
- return await this.driver.query(`SHOW FULL COLUMNS FROM \`${this.getName()}\``)
23
- })
20
+ /**
21
+ * Builds this table's column objects from raw `SHOW FULL COLUMNS`-shaped rows.
22
+ * @param {import("../base.js").QueryResultType} columnRows - Raw column rows for this table.
23
+ * @returns {Array<import("../base-column.js").default>} - Columns built from the rows.
24
+ */
25
+ columnsFromRows(columnRows) {
24
26
  const columns = []
25
27
 
26
28
  for (const data of columnRows) {
@@ -32,6 +34,14 @@ export default class VelociousDatabaseDriversMysqlTable extends BaseTable {
32
34
  return columns
33
35
  }
34
36
 
37
+ async getColumns() {
38
+ const columnRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
39
+ return await this.driver.query(`SHOW FULL COLUMNS FROM \`${this.getName()}\``)
40
+ })
41
+
42
+ return this.columnsFromRows(columnRows)
43
+ }
44
+
35
45
  async getForeignKeys() {
36
46
  const foreignKeyRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "foreignKeys", async () => {
37
47
  const sql = `
@@ -62,6 +62,23 @@ export default class VelociousDatabaseDriversPgsqlTable extends BaseTable {
62
62
  this.driver = driver
63
63
  }
64
64
 
65
+ /**
66
+ * Builds this table's column objects from raw `information_schema.columns`-shaped rows.
67
+ * @param {import("../base.js").QueryResultType} columnRows - Raw column rows for this table.
68
+ * @returns {Array<import("../base-column.js").default>} - Columns built from the rows.
69
+ */
70
+ columnsFromRows(columnRows) {
71
+ const columns = []
72
+
73
+ for (const data of columnRows) {
74
+ const column = new Column(this, data)
75
+
76
+ columns.push(column)
77
+ }
78
+
79
+ return columns
80
+ }
81
+
65
82
  async getColumns() {
66
83
  const columnRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
67
84
  const result = await this.driver.query(`
@@ -91,15 +108,8 @@ export default class VelociousDatabaseDriversPgsqlTable extends BaseTable {
91
108
  `)
92
109
  return result
93
110
  })
94
- const columns = []
95
-
96
- for (const data of columnRows) {
97
- const column = new Column(this, data)
98
111
 
99
- columns.push(column)
100
- }
101
-
102
- return columns
112
+ return this.columnsFromRows(columnRows)
103
113
  }
104
114
 
105
115
  async getForeignKeys() {
@@ -19,13 +19,11 @@ export default class VelociousDatabaseDriversSqliteTable extends BaseTable {
19
19
  }
20
20
 
21
21
  /**
22
- * Runs get columns.
23
- * @returns {Promise<Array<import("../base-column.js").default>>} - Resolves with the columns.
22
+ * Builds this table's column objects from raw `PRAGMA table_info` rows.
23
+ * @param {import("../base.js").QueryResultType} columnRows - Raw column rows for this table.
24
+ * @returns {Array<import("../base-column.js").default>} - Columns built from the rows.
24
25
  */
25
- async getColumns() {
26
- const columnRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
27
- return await this.driver.query(`PRAGMA table_info('${this.getName()}')`)
28
- })
26
+ columnsFromRows(columnRows) {
29
27
  const columns = []
30
28
 
31
29
  for (const columnData of columnRows) {
@@ -37,6 +35,18 @@ export default class VelociousDatabaseDriversSqliteTable extends BaseTable {
37
35
  return columns
38
36
  }
39
37
 
38
+ /**
39
+ * Runs get columns.
40
+ * @returns {Promise<Array<import("../base-column.js").default>>} - Resolves with the columns.
41
+ */
42
+ async getColumns() {
43
+ const columnRows = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "columns", async () => {
44
+ return await this.driver.query(`PRAGMA table_info('${this.getName()}')`)
45
+ })
46
+
47
+ return this.columnsFromRows(columnRows)
48
+ }
49
+
40
50
  async getForeignKeys() {
41
51
  const foreignKeysData = await this.getDriver()._cachedTableSchemaMetadata(this.getName(), "foreignKeys", async () => {
42
52
  return await this.driver.query(`SELECT * FROM pragma_foreign_key_list(${this.driver.quote(this.getName())})`)