@jeffusion/bungee-core 6.11.3 → 6.12.0
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/config-storage-worker.js +1442 -524
- package/dist/main.js +1799 -378
- package/dist/plugin-state-worker.js +1 -0
- package/dist/plugins/chatgpt-oauth/manifest.json +0 -8
- package/dist/plugins/llm-protocol-adapter/index.js.map +2 -2
- package/dist/plugins/models-dev/index.js +6 -2
- package/dist/plugins/models-dev/index.js.map +3 -3
- package/package.json +2 -2
|
@@ -7947,8 +7947,9 @@ function freezePublicationRetirement(db, mutationId, generation, value, now) {
|
|
|
7947
7947
|
return prior;
|
|
7948
7948
|
}
|
|
7949
7949
|
const operation = sqliteGet(db, "SELECT state,drain_recovery_generation FROM configuration_operations WHERE mutation_id=?", mutationId);
|
|
7950
|
-
if (operation === null || operation.state === "converged" || operation.state === "degraded" || operation.drain_recovery_generation !== generation)
|
|
7950
|
+
if (operation === null || operation.state === "converged" || operation.state === "degraded" || operation.state === "superseded" || operation.drain_recovery_generation !== generation) {
|
|
7951
7951
|
invalid2("retirement must match the active publication generation");
|
|
7952
|
+
}
|
|
7952
7953
|
db.run("INSERT INTO configuration_retirements(mutation_id,generation,members_json,state,updated_at) VALUES(?,?,?,'pending',?)", [mutationId, generation, canonicalJson(members), now]);
|
|
7953
7954
|
for (const member of members)
|
|
7954
7955
|
db.run(`INSERT INTO configuration_retirement_evidence(mutation_id,member_id,exit_state,cleanup_state,updated_at)
|
|
@@ -8037,7 +8038,7 @@ function readRetirementDescriptorCleanupState(db, workerInstanceId) {
|
|
|
8037
8038
|
JOIN configuration_operations o USING(mutation_id) WHERE e.member_id=?`, workerInstanceId);
|
|
8038
8039
|
if (!rows.length)
|
|
8039
8040
|
return "absent";
|
|
8040
|
-
return rows.every((row) => row.state === "converged" || row.state === "degraded") ? "terminal" : "pending";
|
|
8041
|
+
return rows.every((row) => row.state === "converged" || row.state === "degraded" || row.state === "superseded") ? "terminal" : "pending";
|
|
8041
8042
|
}
|
|
8042
8043
|
function parseServingMembers(value) {
|
|
8043
8044
|
const input = snapshotJsonGraph(value);
|
|
@@ -8101,7 +8102,7 @@ function freezePublicationServingSet(db, mutationId, generation, input) {
|
|
|
8101
8102
|
return before;
|
|
8102
8103
|
}
|
|
8103
8104
|
const operation = sqliteGet(db, "SELECT state,committed_revision,target_worker_count,drain_recovery_generation FROM configuration_operations WHERE mutation_id=?", mutationId);
|
|
8104
|
-
if (!operation || operation.state === "converged" || operation.state === "degraded" || operation.drain_recovery_generation !== generation || workers.length !== operation.target_worker_count || workers.some((worker) => worker.revision !== operation.committed_revision || worker.publication?.mutation_id !== mutationId || worker.publication.drain_recovery_generation !== generation))
|
|
8105
|
+
if (!operation || operation.state === "converged" || operation.state === "degraded" || operation.state === "superseded" || operation.drain_recovery_generation !== generation || workers.length !== operation.target_worker_count || workers.some((worker) => worker.revision !== operation.committed_revision || worker.publication?.mutation_id !== mutationId || worker.publication.drain_recovery_generation !== generation))
|
|
8105
8106
|
invalid2("publication serving authority does not match the current attempt");
|
|
8106
8107
|
const attemptKey = currentServingAttemptKey(db, mutationId);
|
|
8107
8108
|
if (canonicalJson(workers.map((worker) => [worker.identity.worker_slot, worker.publication.attempt_no]).sort((a, b) => a[0] - b[0])) !== attemptKey) {
|
|
@@ -8259,7 +8260,7 @@ function requireOneOf(value, allowed, field) {
|
|
|
8259
8260
|
// src/config-storage/operation-records.ts
|
|
8260
8261
|
var OPERATION_SELECT = `SELECT mutation_id,request_hash,expected_revision,committed_revision,kind,state,
|
|
8261
8262
|
target_worker_count,result_status,error_code,error_detail,drain_recovery_generation,
|
|
8262
|
-
last_drain_recovery_previous_generation,created_at,updated_at
|
|
8263
|
+
last_drain_recovery_previous_generation,plugin_catalog_hash,cancel_requested,prepare_started,created_at,updated_at
|
|
8263
8264
|
FROM configuration_operations`;
|
|
8264
8265
|
var WORKER_SELECT = `SELECT mutation_id,worker_slot,target_revision,drain_recovery_generation,
|
|
8265
8266
|
attempt_no,last_begin_previous_attempt_no,last_begin_reason,state,applied_revision,last_error,updated_at
|
|
@@ -8285,6 +8286,12 @@ function operationFromRow(row) {
|
|
|
8285
8286
|
}
|
|
8286
8287
|
if (row.updated_at < row.created_at)
|
|
8287
8288
|
throw new ConfigRepositoryError("schema_corrupt", "operation timestamps are invalid");
|
|
8289
|
+
if (row.plugin_catalog_hash !== null && !validateDigest(row.plugin_catalog_hash)) {
|
|
8290
|
+
throw new ConfigRepositoryError("schema_corrupt", "operation plugin catalog identity is invalid");
|
|
8291
|
+
}
|
|
8292
|
+
if (row.cancel_requested !== 0 && row.cancel_requested !== 1 || row.prepare_started !== 0 && row.prepare_started !== 1) {
|
|
8293
|
+
throw new ConfigRepositoryError("schema_corrupt", "operation cancellation flags are invalid");
|
|
8294
|
+
}
|
|
8288
8295
|
const kind = row.kind === "config" ? "config" : "admin_state";
|
|
8289
8296
|
const base = {
|
|
8290
8297
|
mutation_id: row.mutation_id,
|
|
@@ -8295,10 +8302,18 @@ function operationFromRow(row) {
|
|
|
8295
8302
|
target_worker_count: row.target_worker_count,
|
|
8296
8303
|
drain_recovery_generation: row.drain_recovery_generation,
|
|
8297
8304
|
last_drain_recovery_previous_generation: row.last_drain_recovery_previous_generation,
|
|
8305
|
+
plugin_catalog_hash: row.plugin_catalog_hash,
|
|
8306
|
+
cancel_requested: row.cancel_requested === 1,
|
|
8307
|
+
prepare_started: row.prepare_started === 1,
|
|
8298
8308
|
created_at: row.created_at,
|
|
8299
8309
|
updated_at: row.updated_at
|
|
8300
8310
|
};
|
|
8301
8311
|
switch (row.state) {
|
|
8312
|
+
case "pending":
|
|
8313
|
+
if (row.result_status === null && row.error_code === null && row.error_detail === null && row.drain_recovery_generation === 0 && !base.cancel_requested && !base.prepare_started) {
|
|
8314
|
+
return { ...base, state: "pending", result_status: null, error_code: null, error_detail: null };
|
|
8315
|
+
}
|
|
8316
|
+
break;
|
|
8302
8317
|
case "committed":
|
|
8303
8318
|
case "publishing":
|
|
8304
8319
|
case "draining":
|
|
@@ -8306,6 +8321,17 @@ function operationFromRow(row) {
|
|
|
8306
8321
|
return { ...base, state: row.state, result_status: null, error_code: null, error_detail: null };
|
|
8307
8322
|
}
|
|
8308
8323
|
break;
|
|
8324
|
+
case "superseded":
|
|
8325
|
+
if (row.result_status === 409 && row.error_code === "revision_superseded" && row.drain_recovery_generation === 0 && !base.prepare_started && row.error_detail !== null && row.error_detail.length <= 512 && row.error_detail.trim().length > 0) {
|
|
8326
|
+
return {
|
|
8327
|
+
...base,
|
|
8328
|
+
state: "superseded",
|
|
8329
|
+
result_status: 409,
|
|
8330
|
+
error_code: "revision_superseded",
|
|
8331
|
+
error_detail: row.error_detail
|
|
8332
|
+
};
|
|
8333
|
+
}
|
|
8334
|
+
break;
|
|
8309
8335
|
case "converged":
|
|
8310
8336
|
if (row.drain_recovery_generation === 0 && row.result_status === 200 && row.error_code === null && row.error_detail === null) {
|
|
8311
8337
|
return { ...base, state: "converged", result_status: 200, error_code: null, error_detail: null };
|
|
@@ -8381,8 +8407,434 @@ function readAllWorkers(db) {
|
|
|
8381
8407
|
return sqliteAll(db, `${WORKER_SELECT} ORDER BY mutation_id,worker_slot`).map(workerFromRow);
|
|
8382
8408
|
}
|
|
8383
8409
|
|
|
8410
|
+
// src/config-storage/worker-launch-store.ts
|
|
8411
|
+
var INTENT_SELECT = `SELECT worker_instance_id,master_generation,worker_slot,
|
|
8412
|
+
allocation_mutation_id,allocation_worker_slot,allocation_attempt_no,guard_json,registered_at
|
|
8413
|
+
FROM configuration_worker_launch_intents`;
|
|
8414
|
+
function invalid3(message) {
|
|
8415
|
+
throw new ConfigRepositoryError("invalid_command", message);
|
|
8416
|
+
}
|
|
8417
|
+
function invalidOperation(message) {
|
|
8418
|
+
throw new ConfigRepositoryError("invalid_operation", message);
|
|
8419
|
+
}
|
|
8420
|
+
function natural2(value, minimum = 0) {
|
|
8421
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= minimum;
|
|
8422
|
+
}
|
|
8423
|
+
function validateIdentity(identity) {
|
|
8424
|
+
if (typeof identity !== "object" || identity === null || !isLowercaseUuid(identity.master_generation) || !isLowercaseUuid(identity.worker_instance_id) || !natural2(identity.worker_slot)) {
|
|
8425
|
+
invalid3("worker launch identity is invalid");
|
|
8426
|
+
}
|
|
8427
|
+
}
|
|
8428
|
+
function validateAllocation(allocation, identity) {
|
|
8429
|
+
if (typeof allocation !== "object" || allocation === null || typeof allocation.mutation_id !== "string" || !validateMutationId(allocation.mutation_id) || !natural2(allocation.worker_slot) || allocation.worker_slot !== identity.worker_slot || !natural2(allocation.attempt_no, 1)) {
|
|
8430
|
+
invalid3("worker launch allocation is invalid");
|
|
8431
|
+
}
|
|
8432
|
+
}
|
|
8433
|
+
function validateAllocationInput(allocation) {
|
|
8434
|
+
if (typeof allocation !== "object" || allocation === null || typeof allocation.mutation_id !== "string" || !validateMutationId(allocation.mutation_id) || !natural2(allocation.worker_slot) || !natural2(allocation.attempt_no, 1)) {
|
|
8435
|
+
invalid3("worker launch allocation is invalid");
|
|
8436
|
+
}
|
|
8437
|
+
}
|
|
8438
|
+
function parseGuard(value) {
|
|
8439
|
+
try {
|
|
8440
|
+
return parseProcessLifetimeGuardFacts(value);
|
|
8441
|
+
} catch {
|
|
8442
|
+
throw new ConfigRepositoryError("schema_corrupt", "worker launch guard facts are invalid");
|
|
8443
|
+
}
|
|
8444
|
+
}
|
|
8445
|
+
function parseInputGuard(value, identity) {
|
|
8446
|
+
let guard;
|
|
8447
|
+
try {
|
|
8448
|
+
guard = parseProcessLifetimeGuardFacts(value);
|
|
8449
|
+
} catch {
|
|
8450
|
+
invalid3("worker launch guard facts are invalid");
|
|
8451
|
+
}
|
|
8452
|
+
if (guard.process_instance_id !== identity.worker_instance_id) {
|
|
8453
|
+
invalid3("worker launch guard belongs to another process");
|
|
8454
|
+
}
|
|
8455
|
+
return guard;
|
|
8456
|
+
}
|
|
8457
|
+
function sameAllocation(left, right) {
|
|
8458
|
+
return left === null ? right === null : right !== null && left.mutation_id === right.mutation_id && left.worker_slot === right.worker_slot && left.attempt_no === right.attempt_no;
|
|
8459
|
+
}
|
|
8460
|
+
function allocationKey(allocation) {
|
|
8461
|
+
return `${allocation.mutation_id}\x00${allocation.worker_slot}\x00${allocation.attempt_no}`;
|
|
8462
|
+
}
|
|
8463
|
+
function rowAllocation(row) {
|
|
8464
|
+
if (row.allocation_mutation_id === null || row.allocation_worker_slot === null || row.allocation_attempt_no === null)
|
|
8465
|
+
return null;
|
|
8466
|
+
return {
|
|
8467
|
+
mutation_id: row.allocation_mutation_id,
|
|
8468
|
+
worker_slot: row.allocation_worker_slot,
|
|
8469
|
+
attempt_no: row.allocation_attempt_no
|
|
8470
|
+
};
|
|
8471
|
+
}
|
|
8472
|
+
function readFacts(db, instance, allocation) {
|
|
8473
|
+
const rows = allocation === null ? sqliteAll(db, `SELECT kind,recorded_at FROM configuration_worker_launch_facts WHERE worker_instance_id=?`, instance) : sqliteAll(db, `SELECT kind,recorded_at FROM configuration_worker_launch_facts
|
|
8474
|
+
WHERE worker_instance_id=? OR (mutation_id=? AND worker_slot=? AND attempt_no=?)`, instance, allocation.mutation_id, allocation.worker_slot, allocation.attempt_no);
|
|
8475
|
+
let admitted = false;
|
|
8476
|
+
let notStarted = false;
|
|
8477
|
+
let exited = false;
|
|
8478
|
+
let cleanup = false;
|
|
8479
|
+
let lastRecordedAt = 0;
|
|
8480
|
+
for (const row of rows) {
|
|
8481
|
+
if (row.kind === "admitted")
|
|
8482
|
+
admitted = true;
|
|
8483
|
+
else if (row.kind === "not_started")
|
|
8484
|
+
notStarted = true;
|
|
8485
|
+
else if (row.kind === "exited")
|
|
8486
|
+
exited = true;
|
|
8487
|
+
else if (row.kind === "cleanup")
|
|
8488
|
+
cleanup = true;
|
|
8489
|
+
lastRecordedAt = Math.max(lastRecordedAt, row.recorded_at);
|
|
8490
|
+
}
|
|
8491
|
+
return { admitted, not_started: notStarted, exited, cleanup_released: cleanup, last_recorded_at: lastRecordedAt };
|
|
8492
|
+
}
|
|
8493
|
+
function launchFromRow(db, row) {
|
|
8494
|
+
if (!isLowercaseUuid(row.worker_instance_id) || !isLowercaseUuid(row.master_generation) || !natural2(row.worker_slot) || !natural2(row.registered_at)) {
|
|
8495
|
+
throw new ConfigRepositoryError("schema_corrupt", "worker launch intent is invalid");
|
|
8496
|
+
}
|
|
8497
|
+
const allocation = rowAllocation(row);
|
|
8498
|
+
if (row.allocation_mutation_id === null !== (row.allocation_worker_slot === null) || row.allocation_mutation_id === null !== (row.allocation_attempt_no === null) || allocation !== null && (!validateMutationId(allocation.mutation_id) || !natural2(allocation.worker_slot) || !natural2(allocation.attempt_no, 1) || allocation.worker_slot !== row.worker_slot)) {
|
|
8499
|
+
throw new ConfigRepositoryError("schema_corrupt", "worker launch allocation is invalid");
|
|
8500
|
+
}
|
|
8501
|
+
let guardJson;
|
|
8502
|
+
try {
|
|
8503
|
+
guardJson = JSON.parse(row.guard_json);
|
|
8504
|
+
} catch {
|
|
8505
|
+
throw new ConfigRepositoryError("schema_corrupt", "worker launch guard facts are invalid");
|
|
8506
|
+
}
|
|
8507
|
+
const guard = parseGuard(guardJson);
|
|
8508
|
+
if (guard.process_instance_id !== row.worker_instance_id) {
|
|
8509
|
+
throw new ConfigRepositoryError("schema_corrupt", "worker launch guard identity is invalid");
|
|
8510
|
+
}
|
|
8511
|
+
const facts = readFacts(db, row.worker_instance_id, allocation);
|
|
8512
|
+
return Object.freeze({
|
|
8513
|
+
identity: Object.freeze({
|
|
8514
|
+
master_generation: row.master_generation,
|
|
8515
|
+
worker_instance_id: row.worker_instance_id,
|
|
8516
|
+
worker_slot: row.worker_slot
|
|
8517
|
+
}),
|
|
8518
|
+
guard,
|
|
8519
|
+
allocation: allocation === null ? null : Object.freeze(allocation),
|
|
8520
|
+
registered_at: row.registered_at,
|
|
8521
|
+
admitted: facts.admitted,
|
|
8522
|
+
not_started: facts.not_started,
|
|
8523
|
+
exited: facts.exited,
|
|
8524
|
+
cleanup_released: facts.cleanup_released
|
|
8525
|
+
});
|
|
8526
|
+
}
|
|
8527
|
+
function requireIntentRow(db, workerInstanceId) {
|
|
8528
|
+
if (typeof workerInstanceId !== "string" || !isLowercaseUuid(workerInstanceId)) {
|
|
8529
|
+
invalid3("worker launch instance identity is invalid");
|
|
8530
|
+
}
|
|
8531
|
+
const row = sqliteGet(db, `${INTENT_SELECT} WHERE worker_instance_id=?`, workerInstanceId);
|
|
8532
|
+
if (row === null)
|
|
8533
|
+
invalidOperation("worker launch intent was not registered");
|
|
8534
|
+
return row;
|
|
8535
|
+
}
|
|
8536
|
+
function requireTimestamp(updatedAt, minimum) {
|
|
8537
|
+
if (!natural2(updatedAt) || updatedAt < minimum) {
|
|
8538
|
+
invalidOperation("worker launch timestamp regressed or is unsafe");
|
|
8539
|
+
}
|
|
8540
|
+
}
|
|
8541
|
+
function hasFact(db, kind, allocation) {
|
|
8542
|
+
return sqliteGet(db, `SELECT fact_id FROM configuration_worker_launch_facts
|
|
8543
|
+
WHERE kind=? AND mutation_id=? AND worker_slot=? AND attempt_no=?`, kind, allocation.mutation_id, allocation.worker_slot, allocation.attempt_no) !== null;
|
|
8544
|
+
}
|
|
8545
|
+
function insertAllocationFact(db, kind, allocation, updatedAt) {
|
|
8546
|
+
if (!natural2(updatedAt))
|
|
8547
|
+
invalid3("worker launch fact timestamp is invalid");
|
|
8548
|
+
if (hasFact(db, kind, allocation))
|
|
8549
|
+
return;
|
|
8550
|
+
db.run(`INSERT INTO configuration_worker_launch_facts
|
|
8551
|
+
(kind,mutation_id,worker_slot,attempt_no,recorded_at) VALUES (?,?,?,?,?)`, [kind, allocation.mutation_id, allocation.worker_slot, allocation.attempt_no, updatedAt]);
|
|
8552
|
+
}
|
|
8553
|
+
function insertInstanceFact(db, kind, intent, updatedAt) {
|
|
8554
|
+
if (!natural2(updatedAt))
|
|
8555
|
+
invalid3("worker launch fact timestamp is invalid");
|
|
8556
|
+
const allocation = intent.allocation;
|
|
8557
|
+
db.run(`INSERT INTO configuration_worker_launch_facts
|
|
8558
|
+
(kind,mutation_id,worker_slot,attempt_no,worker_instance_id,recorded_at) VALUES (?,?,?,?,?,?)`, [
|
|
8559
|
+
kind,
|
|
8560
|
+
allocation?.mutation_id ?? null,
|
|
8561
|
+
allocation?.worker_slot ?? null,
|
|
8562
|
+
allocation?.attempt_no ?? null,
|
|
8563
|
+
intent.identity.worker_instance_id,
|
|
8564
|
+
updatedAt
|
|
8565
|
+
]);
|
|
8566
|
+
}
|
|
8567
|
+
function requireOpenAllocation(db, allocation, allowCancelled) {
|
|
8568
|
+
const authority = sqliteGet(db, `SELECT o.state,o.cancel_requested,w.attempt_no
|
|
8569
|
+
FROM configuration_operations o
|
|
8570
|
+
JOIN configuration_operation_workers w ON w.mutation_id=o.mutation_id
|
|
8571
|
+
WHERE o.mutation_id=? AND w.worker_slot=?`, allocation.mutation_id, allocation.worker_slot);
|
|
8572
|
+
if (authority === null || authority.state !== "committed" && authority.state !== "publishing" && authority.state !== "draining" || authority.attempt_no !== allocation.attempt_no || !allowCancelled && authority.cancel_requested === 1) {
|
|
8573
|
+
invalidOperation("worker launch allocation is not the current open attempt");
|
|
8574
|
+
}
|
|
8575
|
+
return authority;
|
|
8576
|
+
}
|
|
8577
|
+
function requireReservation(db, allocation) {
|
|
8578
|
+
const row = sqliteGet(db, `SELECT mutation_id,worker_slot,attempt_no,recorded_at FROM configuration_worker_launch_facts
|
|
8579
|
+
WHERE kind='reserved' AND mutation_id=? AND worker_slot=? AND attempt_no=?`, allocation.mutation_id, allocation.worker_slot, allocation.attempt_no);
|
|
8580
|
+
if (row === null)
|
|
8581
|
+
invalidOperation("worker launch allocation was not reserved");
|
|
8582
|
+
return row;
|
|
8583
|
+
}
|
|
8584
|
+
function candidateEvidenceSettled(db, allocation) {
|
|
8585
|
+
return sqliteGet(db, `SELECT mutation_id FROM configuration_publication_candidate_evidence
|
|
8586
|
+
WHERE mutation_id=? AND worker_slot=? AND attempt_no=? AND
|
|
8587
|
+
(exit_kind='not_started' OR (exit_kind='exited' AND cleanup='released'))`, allocation.mutation_id, allocation.worker_slot, allocation.attempt_no) !== null;
|
|
8588
|
+
}
|
|
8589
|
+
function writeWorkerLaunchReservation(db, mutationId, workerSlot, attemptNo, updatedAt) {
|
|
8590
|
+
if (typeof mutationId !== "string" || !validateMutationId(mutationId) || !natural2(workerSlot) || !natural2(attemptNo, 1) || !natural2(updatedAt)) {
|
|
8591
|
+
throw new ConfigRepositoryError("invalid_operation", "worker launch reservation is invalid");
|
|
8592
|
+
}
|
|
8593
|
+
insertAllocationFact(db, "reserved", { mutation_id: mutationId, worker_slot: workerSlot, attempt_no: attemptNo }, updatedAt);
|
|
8594
|
+
}
|
|
8595
|
+
function fenceWorkerLaunchNotStarted(db, mutationId, workerSlot, attemptNo, updatedAt) {
|
|
8596
|
+
const allocation = { mutation_id: mutationId, worker_slot: workerSlot, attempt_no: attemptNo };
|
|
8597
|
+
if (typeof mutationId !== "string" || !validateMutationId(mutationId) || !natural2(workerSlot) || !natural2(attemptNo, 1)) {
|
|
8598
|
+
invalid3("worker launch allocation is invalid");
|
|
8599
|
+
}
|
|
8600
|
+
requireOpenAllocation(db, allocation, true);
|
|
8601
|
+
const reservation = requireReservation(db, allocation);
|
|
8602
|
+
if (sqliteGet(db, `SELECT worker_instance_id FROM configuration_worker_launch_intents
|
|
8603
|
+
WHERE allocation_mutation_id=? AND allocation_worker_slot=? AND allocation_attempt_no=? LIMIT 1`, mutationId, workerSlot, attemptNo) !== null) {
|
|
8604
|
+
invalidOperation("worker launch intent already registered");
|
|
8605
|
+
}
|
|
8606
|
+
if (hasFact(db, "not_started", allocation))
|
|
8607
|
+
return;
|
|
8608
|
+
requireTimestamp(updatedAt, reservation.recorded_at);
|
|
8609
|
+
insertAllocationFact(db, "not_started", allocation, updatedAt);
|
|
8610
|
+
}
|
|
8611
|
+
function registerWorkerLaunch(db, identity, guard, allocation, updatedAt) {
|
|
8612
|
+
validateIdentity(identity);
|
|
8613
|
+
const parsedGuard = parseInputGuard(guard, identity);
|
|
8614
|
+
const guardJson = canonicalJson(parsedGuard);
|
|
8615
|
+
if (allocation !== null)
|
|
8616
|
+
validateAllocation(allocation, identity);
|
|
8617
|
+
if (!natural2(updatedAt))
|
|
8618
|
+
invalid3("worker launch registration timestamp is invalid");
|
|
8619
|
+
if (allocation !== null) {
|
|
8620
|
+
requireOpenAllocation(db, allocation, false);
|
|
8621
|
+
const reservation = requireReservation(db, allocation);
|
|
8622
|
+
requireTimestamp(updatedAt, reservation.recorded_at);
|
|
8623
|
+
if (hasFact(db, "not_started", allocation)) {
|
|
8624
|
+
invalidOperation("worker launch allocation is fenced not_started");
|
|
8625
|
+
}
|
|
8626
|
+
const byAllocation = sqliteGet(db, `${INTENT_SELECT} WHERE allocation_mutation_id=? AND allocation_worker_slot=? AND allocation_attempt_no=?`, allocation.mutation_id, allocation.worker_slot, allocation.attempt_no);
|
|
8627
|
+
if (byAllocation !== null) {
|
|
8628
|
+
const existing = launchFromRow(db, byAllocation);
|
|
8629
|
+
if (existing.identity.master_generation !== identity.master_generation || existing.identity.worker_instance_id !== identity.worker_instance_id || existing.identity.worker_slot !== identity.worker_slot || canonicalJson(existing.guard) !== guardJson || !sameAllocation(existing.allocation, allocation)) {
|
|
8630
|
+
throw new ConfigRepositoryError("cas_conflict", "worker launch allocation is already registered");
|
|
8631
|
+
}
|
|
8632
|
+
return existing;
|
|
8633
|
+
}
|
|
8634
|
+
}
|
|
8635
|
+
const byInstance = sqliteGet(db, `${INTENT_SELECT} WHERE worker_instance_id=?`, identity.worker_instance_id);
|
|
8636
|
+
if (byInstance !== null) {
|
|
8637
|
+
const existing = launchFromRow(db, byInstance);
|
|
8638
|
+
if (sameAllocation(existing.allocation, allocation) && existing.identity.master_generation === identity.master_generation && existing.identity.worker_slot === identity.worker_slot && canonicalJson(existing.guard) === guardJson) {
|
|
8639
|
+
return existing;
|
|
8640
|
+
}
|
|
8641
|
+
invalidOperation("worker instance identity was already registered with another launch");
|
|
8642
|
+
}
|
|
8643
|
+
db.run(`INSERT INTO configuration_worker_launch_intents
|
|
8644
|
+
(worker_instance_id,master_generation,worker_slot,allocation_mutation_id,allocation_worker_slot,
|
|
8645
|
+
allocation_attempt_no,guard_json,registered_at) VALUES (?,?,?,?,?,?,?,?)`, [
|
|
8646
|
+
identity.worker_instance_id,
|
|
8647
|
+
identity.master_generation,
|
|
8648
|
+
identity.worker_slot,
|
|
8649
|
+
allocation?.mutation_id ?? null,
|
|
8650
|
+
allocation?.worker_slot ?? null,
|
|
8651
|
+
allocation?.attempt_no ?? null,
|
|
8652
|
+
guardJson,
|
|
8653
|
+
updatedAt
|
|
8654
|
+
]);
|
|
8655
|
+
const saved = sqliteGet(db, `${INTENT_SELECT} WHERE worker_instance_id=?`, identity.worker_instance_id);
|
|
8656
|
+
if (saved === null)
|
|
8657
|
+
throw new ConfigRepositoryError("repository_failure", "worker launch intent was not persisted");
|
|
8658
|
+
return launchFromRow(db, saved);
|
|
8659
|
+
}
|
|
8660
|
+
function recordWorkerLaunchAdmitted(db, workerInstanceId, updatedAt) {
|
|
8661
|
+
const row = requireIntentRow(db, workerInstanceId);
|
|
8662
|
+
const launch = launchFromRow(db, row);
|
|
8663
|
+
if (launch.not_started || launch.exited) {
|
|
8664
|
+
invalidOperation("worker launch cannot be admitted after exit proof");
|
|
8665
|
+
}
|
|
8666
|
+
if (launch.admitted)
|
|
8667
|
+
return launch;
|
|
8668
|
+
requireTimestamp(updatedAt, Math.max(launch.registered_at, readFacts(db, workerInstanceId, launch.allocation).last_recorded_at));
|
|
8669
|
+
insertInstanceFact(db, "admitted", launch, updatedAt);
|
|
8670
|
+
return launchFromRow(db, row);
|
|
8671
|
+
}
|
|
8672
|
+
function recordWorkerLaunchExit(db, workerInstanceId, evidence, updatedAt) {
|
|
8673
|
+
if (typeof evidence !== "object" || evidence === null || evidence.kind !== "not_started" && (evidence.kind !== "exited" || evidence.cleanup !== "released" && evidence.cleanup !== "unknown")) {
|
|
8674
|
+
invalid3("worker launch exit evidence is invalid");
|
|
8675
|
+
}
|
|
8676
|
+
const row = requireIntentRow(db, workerInstanceId);
|
|
8677
|
+
const launch = launchFromRow(db, row);
|
|
8678
|
+
const candidate = launch.allocation === null ? null : sqliteGet(db, `SELECT exit_kind FROM configuration_publication_candidate_evidence
|
|
8679
|
+
WHERE mutation_id=? AND worker_slot=? AND attempt_no=?`, launch.allocation.mutation_id, launch.allocation.worker_slot, launch.allocation.attempt_no);
|
|
8680
|
+
if (candidate !== null && (evidence.kind === "not_started" && candidate.exit_kind === "exited" || evidence.kind === "exited" && candidate.exit_kind === "not_started")) {
|
|
8681
|
+
throw new ConfigRepositoryError("cas_conflict", "worker launch exit proof conflicts with candidate evidence");
|
|
8682
|
+
}
|
|
8683
|
+
if (evidence.kind === "not_started") {
|
|
8684
|
+
if (launch.exited || launch.cleanup_released) {
|
|
8685
|
+
invalidOperation("worker launch exit proof conflicts with not_started");
|
|
8686
|
+
}
|
|
8687
|
+
if (launch.admitted)
|
|
8688
|
+
invalidOperation("an admitted worker launch cannot be proven not started");
|
|
8689
|
+
if (launch.not_started)
|
|
8690
|
+
return launch;
|
|
8691
|
+
requireTimestamp(updatedAt, Math.max(launch.registered_at, readFacts(db, workerInstanceId, launch.allocation).last_recorded_at));
|
|
8692
|
+
insertInstanceFact(db, "not_started", launch, updatedAt);
|
|
8693
|
+
return launchFromRow(db, row);
|
|
8694
|
+
}
|
|
8695
|
+
if (launch.not_started)
|
|
8696
|
+
invalidOperation("worker launch was already proven not started");
|
|
8697
|
+
let { exited, cleanup_released: cleanupReleased, last_recorded_at: lastRecordedAt } = readFacts(db, workerInstanceId, launch.allocation);
|
|
8698
|
+
if (!exited) {
|
|
8699
|
+
requireTimestamp(updatedAt, Math.max(launch.registered_at, lastRecordedAt));
|
|
8700
|
+
insertInstanceFact(db, "exited", launch, updatedAt);
|
|
8701
|
+
exited = true;
|
|
8702
|
+
lastRecordedAt = updatedAt;
|
|
8703
|
+
}
|
|
8704
|
+
if (evidence.cleanup === "released" && !cleanupReleased) {
|
|
8705
|
+
requireTimestamp(updatedAt, Math.max(launch.registered_at, lastRecordedAt));
|
|
8706
|
+
insertInstanceFact(db, "cleanup", launch, updatedAt);
|
|
8707
|
+
cleanupReleased = true;
|
|
8708
|
+
}
|
|
8709
|
+
return launchFromRow(db, row);
|
|
8710
|
+
}
|
|
8711
|
+
function readWorkerLaunch(db, workerInstanceId) {
|
|
8712
|
+
if (typeof workerInstanceId !== "string" || !isLowercaseUuid(workerInstanceId)) {
|
|
8713
|
+
invalid3("worker launch instance identity is invalid");
|
|
8714
|
+
}
|
|
8715
|
+
const row = sqliteGet(db, `${INTENT_SELECT} WHERE worker_instance_id=?`, workerInstanceId);
|
|
8716
|
+
return row === null ? null : launchFromRow(db, row);
|
|
8717
|
+
}
|
|
8718
|
+
function readWorkerLaunchAllocationFacts(db, allocation) {
|
|
8719
|
+
validateAllocationInput(allocation);
|
|
8720
|
+
const intent = sqliteGet(db, `${INTENT_SELECT} WHERE allocation_mutation_id=? AND allocation_worker_slot=? AND allocation_attempt_no=?`, allocation.mutation_id, allocation.worker_slot, allocation.attempt_no);
|
|
8721
|
+
const launch = intent === null ? null : launchFromRow(db, intent);
|
|
8722
|
+
const allocationFacts = sqliteAll(db, `SELECT kind,recorded_at FROM configuration_worker_launch_facts
|
|
8723
|
+
WHERE mutation_id=? AND worker_slot=? AND attempt_no=?`, allocation.mutation_id, allocation.worker_slot, allocation.attempt_no);
|
|
8724
|
+
const instanceFacts = launch === null ? [] : sqliteAll(db, "SELECT kind,recorded_at FROM configuration_worker_launch_facts WHERE worker_instance_id=?", launch.identity.worker_instance_id);
|
|
8725
|
+
if (launch === null && allocationFacts.length === 0)
|
|
8726
|
+
return null;
|
|
8727
|
+
const times = new Map;
|
|
8728
|
+
for (const fact of [...allocationFacts, ...instanceFacts]) {
|
|
8729
|
+
times.set(fact.kind, Math.max(times.get(fact.kind) ?? 0, fact.recorded_at));
|
|
8730
|
+
}
|
|
8731
|
+
const notStartedAt = times.get("not_started") ?? null;
|
|
8732
|
+
const exitedAt = times.get("exited") ?? null;
|
|
8733
|
+
const cleanupReleasedAt = times.get("cleanup") ?? null;
|
|
8734
|
+
const settled = notStartedAt !== null || exitedAt !== null && cleanupReleasedAt !== null || candidateEvidenceSettled(db, allocation);
|
|
8735
|
+
return Object.freeze({
|
|
8736
|
+
allocation: Object.freeze({ ...allocation }),
|
|
8737
|
+
launch,
|
|
8738
|
+
reserved_at: times.get("reserved") ?? null,
|
|
8739
|
+
not_started_at: notStartedAt,
|
|
8740
|
+
admitted_at: times.get("admitted") ?? null,
|
|
8741
|
+
exited_at: exitedAt,
|
|
8742
|
+
cleanup_released_at: cleanupReleasedAt,
|
|
8743
|
+
settled
|
|
8744
|
+
});
|
|
8745
|
+
}
|
|
8746
|
+
function launchSettled(db, launch) {
|
|
8747
|
+
return launch.not_started || launch.exited && launch.cleanup_released || launch.allocation !== null && candidateEvidenceSettled(db, launch.allocation);
|
|
8748
|
+
}
|
|
8749
|
+
function assertWorkerAttemptLaunchSettled(db, mutationId, workerSlot, attemptNo) {
|
|
8750
|
+
if (attemptNo <= 0)
|
|
8751
|
+
return;
|
|
8752
|
+
const allocation = { mutation_id: mutationId, worker_slot: workerSlot, attempt_no: attemptNo };
|
|
8753
|
+
if (!hasFact(db, "reserved", allocation))
|
|
8754
|
+
return;
|
|
8755
|
+
if (hasFact(db, "not_started", allocation))
|
|
8756
|
+
return;
|
|
8757
|
+
const row = sqliteGet(db, `${INTENT_SELECT} WHERE allocation_mutation_id=? AND allocation_worker_slot=? AND allocation_attempt_no=?`, mutationId, workerSlot, attemptNo);
|
|
8758
|
+
if (row !== null && launchSettled(db, launchFromRow(db, row)))
|
|
8759
|
+
return;
|
|
8760
|
+
if (row === null && candidateEvidenceSettled(db, allocation))
|
|
8761
|
+
return;
|
|
8762
|
+
invalidOperation("previous worker launch attempt has no exit and cleanup proof");
|
|
8763
|
+
}
|
|
8764
|
+
function assertPublicationLaunchDebtSettled(db, mutationId) {
|
|
8765
|
+
const allocations = sqliteAll(db, `SELECT mutation_id,worker_slot,attempt_no,recorded_at FROM configuration_worker_launch_facts
|
|
8766
|
+
WHERE kind='reserved' AND mutation_id=? ORDER BY worker_slot,attempt_no`, mutationId);
|
|
8767
|
+
const seen = new Set;
|
|
8768
|
+
for (const reservation of allocations) {
|
|
8769
|
+
const allocation = {
|
|
8770
|
+
mutation_id: reservation.mutation_id,
|
|
8771
|
+
worker_slot: reservation.worker_slot,
|
|
8772
|
+
attempt_no: reservation.attempt_no
|
|
8773
|
+
};
|
|
8774
|
+
seen.add(allocationKey(allocation));
|
|
8775
|
+
if (hasFact(db, "not_started", allocation))
|
|
8776
|
+
continue;
|
|
8777
|
+
const row = sqliteGet(db, `${INTENT_SELECT} WHERE allocation_mutation_id=? AND allocation_worker_slot=? AND allocation_attempt_no=?`, mutationId, reservation.worker_slot, reservation.attempt_no);
|
|
8778
|
+
if (row === null) {
|
|
8779
|
+
invalidOperation("unregistered worker launch blocks degraded finalization");
|
|
8780
|
+
}
|
|
8781
|
+
const launch = launchFromRow(db, row);
|
|
8782
|
+
if (launch.admitted || launchSettled(db, launch))
|
|
8783
|
+
continue;
|
|
8784
|
+
invalidOperation("unsettled worker launch blocks degraded finalization");
|
|
8785
|
+
}
|
|
8786
|
+
const unallocated = sqliteAll(db, `${INTENT_SELECT} WHERE allocation_mutation_id=?`, mutationId);
|
|
8787
|
+
for (const row of unallocated) {
|
|
8788
|
+
const allocation = rowAllocation(row);
|
|
8789
|
+
if (allocation === null || seen.has(allocationKey(allocation)))
|
|
8790
|
+
continue;
|
|
8791
|
+
const launch = launchFromRow(db, row);
|
|
8792
|
+
if (launch.admitted || launchSettled(db, launch))
|
|
8793
|
+
continue;
|
|
8794
|
+
invalidOperation("unsettled worker launch blocks degraded finalization");
|
|
8795
|
+
}
|
|
8796
|
+
}
|
|
8797
|
+
function readWorkerLaunchInventory(db) {
|
|
8798
|
+
const result = [];
|
|
8799
|
+
const handled = new Set;
|
|
8800
|
+
const reservations = sqliteAll(db, `SELECT mutation_id,worker_slot,attempt_no,recorded_at FROM configuration_worker_launch_facts
|
|
8801
|
+
WHERE kind='reserved' ORDER BY mutation_id,worker_slot,attempt_no`);
|
|
8802
|
+
for (const reservation of reservations) {
|
|
8803
|
+
const allocation = {
|
|
8804
|
+
mutation_id: reservation.mutation_id,
|
|
8805
|
+
worker_slot: reservation.worker_slot,
|
|
8806
|
+
attempt_no: reservation.attempt_no
|
|
8807
|
+
};
|
|
8808
|
+
const key = allocationKey(allocation);
|
|
8809
|
+
const row = sqliteGet(db, `${INTENT_SELECT} WHERE allocation_mutation_id=? AND allocation_worker_slot=? AND allocation_attempt_no=?`, allocation.mutation_id, allocation.worker_slot, allocation.attempt_no);
|
|
8810
|
+
if (row !== null) {
|
|
8811
|
+
handled.add(key);
|
|
8812
|
+
const launch = launchFromRow(db, row);
|
|
8813
|
+
if (!launchSettled(db, launch))
|
|
8814
|
+
result.push({ kind: "launch", launch });
|
|
8815
|
+
continue;
|
|
8816
|
+
}
|
|
8817
|
+
if (hasFact(db, "not_started", allocation) || candidateEvidenceSettled(db, allocation))
|
|
8818
|
+
continue;
|
|
8819
|
+
result.push({ kind: "reservation", allocation });
|
|
8820
|
+
}
|
|
8821
|
+
const intents = sqliteAll(db, `${INTENT_SELECT} ORDER BY registered_at,worker_instance_id`);
|
|
8822
|
+
for (const row of intents) {
|
|
8823
|
+
const allocation = rowAllocation(row);
|
|
8824
|
+
if (allocation !== null && handled.has(allocationKey(allocation)))
|
|
8825
|
+
continue;
|
|
8826
|
+
const launch = launchFromRow(db, row);
|
|
8827
|
+
if (!launchSettled(db, launch))
|
|
8828
|
+
result.push({ kind: "launch", launch });
|
|
8829
|
+
}
|
|
8830
|
+
return Object.freeze(result);
|
|
8831
|
+
}
|
|
8832
|
+
function readUnsettledWorkerLaunches(db) {
|
|
8833
|
+
return Object.freeze(readWorkerLaunchInventory(db).filter((item) => item.kind === "reservation" || !item.launch.admitted));
|
|
8834
|
+
}
|
|
8835
|
+
|
|
8384
8836
|
// src/config-storage/operation-store.ts
|
|
8385
|
-
function
|
|
8837
|
+
function requireTimestamp2(updatedAt, operation) {
|
|
8386
8838
|
if (!Number.isSafeInteger(updatedAt) || updatedAt < operation.updated_at) {
|
|
8387
8839
|
throw new ConfigRepositoryError("invalid_operation", "operation timestamp regressed or is unsafe");
|
|
8388
8840
|
}
|
|
@@ -8393,9 +8845,25 @@ function requireOperation(db, mutationId) {
|
|
|
8393
8845
|
throw new ConfigRepositoryError("invalid_operation", "configuration operation was not found");
|
|
8394
8846
|
return operation;
|
|
8395
8847
|
}
|
|
8848
|
+
function finalizeOfflineOperation(db, mutationId, updatedAt) {
|
|
8849
|
+
const operation = requireOperation(db, mutationId);
|
|
8850
|
+
if (operation.state === "converged")
|
|
8851
|
+
return operation;
|
|
8852
|
+
if (operation.state !== "pending" || operation.target_worker_count !== 0) {
|
|
8853
|
+
throw new ConfigRepositoryError("invalid_operation", "offline operation must be an unstarted target-free change");
|
|
8854
|
+
}
|
|
8855
|
+
requireTimestamp2(updatedAt, operation);
|
|
8856
|
+
db.run(`UPDATE configuration_operations
|
|
8857
|
+
SET state='converged',result_status=200,error_code=NULL,error_detail=NULL,updated_at=?
|
|
8858
|
+
WHERE mutation_id=? AND state='pending'`, [updatedAt, mutationId]);
|
|
8859
|
+
const terminal = getOperation(db, mutationId);
|
|
8860
|
+
if (terminal === null)
|
|
8861
|
+
throw new ConfigRepositoryError("repository_failure", "offline operation finalization failed");
|
|
8862
|
+
return terminal;
|
|
8863
|
+
}
|
|
8396
8864
|
function beginPublication(db, mutationId, updatedAt) {
|
|
8397
8865
|
const operation = requireOperation(db, mutationId);
|
|
8398
|
-
|
|
8866
|
+
requireTimestamp2(updatedAt, operation);
|
|
8399
8867
|
if (operation.state === "publishing")
|
|
8400
8868
|
return operation;
|
|
8401
8869
|
if (operation.state !== "committed")
|
|
@@ -8405,7 +8873,7 @@ function beginPublication(db, mutationId, updatedAt) {
|
|
|
8405
8873
|
}
|
|
8406
8874
|
function beginWorkerAttempt(db, mutationId, workerSlot, previousAttemptNo, reason, updatedAt) {
|
|
8407
8875
|
const operation = requireOperation(db, mutationId);
|
|
8408
|
-
if (operation.state !== "publishing" && operation.state !== "draining" || !Number.isSafeInteger(workerSlot) || workerSlot < 0 || !Number.isSafeInteger(previousAttemptNo) || previousAttemptNo < 0 || previousAttemptNo >= Number.MAX_SAFE_INTEGER) {
|
|
8876
|
+
if (operation.state !== "publishing" && operation.state !== "draining" || operation.cancel_requested || !Number.isSafeInteger(workerSlot) || workerSlot < 0 || !Number.isSafeInteger(previousAttemptNo) || previousAttemptNo < 0 || previousAttemptNo >= Number.MAX_SAFE_INTEGER) {
|
|
8409
8877
|
throw new ConfigRepositoryError("invalid_operation", "worker begin command is invalid");
|
|
8410
8878
|
}
|
|
8411
8879
|
const row = sqliteGet(db, `${WORKER_SELECT} WHERE mutation_id=? AND worker_slot=?`, mutationId, workerSlot);
|
|
@@ -8417,13 +8885,15 @@ function beginWorkerAttempt(db, mutationId, workerSlot, previousAttemptNo, reaso
|
|
|
8417
8885
|
}
|
|
8418
8886
|
if (worker.attempt_no === previousAttemptNo + 1 && worker.last_begin_previous_attempt_no === previousAttemptNo && worker.last_begin_reason === reason)
|
|
8419
8887
|
return worker;
|
|
8420
|
-
|
|
8888
|
+
assertWorkerAttemptLaunchSettled(db, mutationId, workerSlot, previousAttemptNo);
|
|
8889
|
+
requireTimestamp2(updatedAt, operation);
|
|
8421
8890
|
const valid = worker.attempt_no === previousAttemptNo && (operation.state === "publishing" ? worker.state === "pending" && previousAttemptNo === 0 && reason === "initial" || worker.state === "failed" && reason === "retry" || reason === "master_recovery" : worker.state === "failed" && reason === "retry");
|
|
8422
8891
|
if (!valid)
|
|
8423
8892
|
throw new ConfigRepositoryError("invalid_operation", "worker begin transition is invalid");
|
|
8424
8893
|
const attemptNo = previousAttemptNo + 1;
|
|
8425
8894
|
db.run(`UPDATE configuration_operation_workers SET attempt_no=?,last_begin_previous_attempt_no=?,last_begin_reason=?,
|
|
8426
8895
|
state='pending',applied_revision=NULL,last_error=NULL,updated_at=? WHERE mutation_id=? AND worker_slot=?`, [attemptNo, previousAttemptNo, reason, updatedAt, mutationId, workerSlot]);
|
|
8896
|
+
writeWorkerLaunchReservation(db, mutationId, workerSlot, attemptNo, updatedAt);
|
|
8427
8897
|
db.run("UPDATE configuration_operations SET updated_at=? WHERE mutation_id=?", [updatedAt, mutationId]);
|
|
8428
8898
|
const updated = sqliteGet(db, `${WORKER_SELECT} WHERE mutation_id=? AND worker_slot=?`, mutationId, workerSlot);
|
|
8429
8899
|
if (updated === null)
|
|
@@ -8450,7 +8920,7 @@ function recordWorkerResult(db, mutationId, workerSlot, result, updatedAt) {
|
|
|
8450
8920
|
if (operation.state !== "publishing" && operation.state !== "draining") {
|
|
8451
8921
|
throw new ConfigRepositoryError("invalid_operation", "operation is not publishing or draining");
|
|
8452
8922
|
}
|
|
8453
|
-
|
|
8923
|
+
requireTimestamp2(updatedAt, operation);
|
|
8454
8924
|
if (result.kind === "converged") {
|
|
8455
8925
|
if (result.applied_revision !== worker.target_revision) {
|
|
8456
8926
|
throw new ConfigRepositoryError("invalid_operation", "worker applied revision does not match target");
|
|
@@ -8496,7 +8966,10 @@ function finalizePublication(db, mutationId, outcome, updatedAt) {
|
|
|
8496
8966
|
return operation;
|
|
8497
8967
|
throw new ConfigRepositoryError("invalid_operation", "terminal finalization conflicts with durable result");
|
|
8498
8968
|
}
|
|
8499
|
-
|
|
8969
|
+
if (operation.cancel_requested) {
|
|
8970
|
+
throw new ConfigRepositoryError("invalid_operation", "cancelled candidate must be superseded after exit proof");
|
|
8971
|
+
}
|
|
8972
|
+
requireTimestamp2(updatedAt, operation);
|
|
8500
8973
|
if (controlReadinessFailure) {
|
|
8501
8974
|
if (outcome.error_detail.length > 512 || outcome.error_detail.trim().length === 0) {
|
|
8502
8975
|
throw new ConfigRepositoryError("invalid_operation", "terminal error detail is invalid");
|
|
@@ -8544,9 +9017,10 @@ function markDraining(db, mutationId, updatedAt) {
|
|
|
8544
9017
|
const operation = requireOperation(db, mutationId);
|
|
8545
9018
|
if (operation.state === "draining")
|
|
8546
9019
|
return operation;
|
|
8547
|
-
|
|
8548
|
-
if (operation.state !== "publishing")
|
|
8549
|
-
throw new ConfigRepositoryError("invalid_operation", "operation is not
|
|
9020
|
+
requireTimestamp2(updatedAt, operation);
|
|
9021
|
+
if (operation.state !== "publishing" || operation.cancel_requested) {
|
|
9022
|
+
throw new ConfigRepositoryError("invalid_operation", "operation is not a running candidate");
|
|
9023
|
+
}
|
|
8550
9024
|
const workers = readOperationWorkers(db, mutationId);
|
|
8551
9025
|
if (workers.some(({ state, attempt_no }) => state !== "converged" || attempt_no === 0)) {
|
|
8552
9026
|
throw new ConfigRepositoryError("invalid_operation", "all frozen targets must converge before draining");
|
|
@@ -8559,12 +9033,12 @@ function beginDrainingRecovery(db, mutationId, previousGeneration, updatedAt) {
|
|
|
8559
9033
|
if (!Number.isSafeInteger(previousGeneration) || previousGeneration < 0 || previousGeneration >= Number.MAX_SAFE_INTEGER || !Number.isSafeInteger(updatedAt) || updatedAt < 0) {
|
|
8560
9034
|
throw new ConfigRepositoryError("invalid_operation", "draining recovery command is invalid");
|
|
8561
9035
|
}
|
|
8562
|
-
if (operation.state !== "draining") {
|
|
9036
|
+
if (operation.state !== "draining" || operation.cancel_requested) {
|
|
8563
9037
|
throw new ConfigRepositoryError("invalid_operation", "operation is not draining");
|
|
8564
9038
|
}
|
|
8565
9039
|
if (operation.drain_recovery_generation === previousGeneration + 1 && operation.last_drain_recovery_previous_generation === previousGeneration)
|
|
8566
9040
|
return operation;
|
|
8567
|
-
|
|
9041
|
+
requireTimestamp2(updatedAt, operation);
|
|
8568
9042
|
if (operation.drain_recovery_generation !== previousGeneration) {
|
|
8569
9043
|
throw new ConfigRepositoryError("invalid_operation", "draining recovery generation is stale or future");
|
|
8570
9044
|
}
|
|
@@ -8574,6 +9048,7 @@ function beginDrainingRecovery(db, mutationId, previousGeneration, updatedAt) {
|
|
|
8574
9048
|
}
|
|
8575
9049
|
const nextGeneration = previousGeneration + 1;
|
|
8576
9050
|
for (const worker of workers) {
|
|
9051
|
+
assertWorkerAttemptLaunchSettled(db, mutationId, worker.worker_slot, worker.attempt_no);
|
|
8577
9052
|
db.run(`UPDATE configuration_operation_workers SET attempt_no=?,last_begin_previous_attempt_no=?,
|
|
8578
9053
|
last_begin_reason='master_recovery',drain_recovery_generation=?,state='pending',
|
|
8579
9054
|
applied_revision=NULL,last_error=NULL,updated_at=?
|
|
@@ -8585,6 +9060,7 @@ function beginDrainingRecovery(db, mutationId, previousGeneration, updatedAt) {
|
|
|
8585
9060
|
mutationId,
|
|
8586
9061
|
worker.worker_slot
|
|
8587
9062
|
]);
|
|
9063
|
+
writeWorkerLaunchReservation(db, mutationId, worker.worker_slot, worker.attempt_no + 1, updatedAt);
|
|
8588
9064
|
}
|
|
8589
9065
|
db.run(`UPDATE configuration_operations SET drain_recovery_generation=?,
|
|
8590
9066
|
last_drain_recovery_previous_generation=?,updated_at=? WHERE mutation_id=?`, [nextGeneration, previousGeneration, updatedAt, mutationId]);
|
|
@@ -8596,234 +9072,127 @@ function beginDrainingRecovery(db, mutationId, previousGeneration, updatedAt) {
|
|
|
8596
9072
|
};
|
|
8597
9073
|
}
|
|
8598
9074
|
|
|
8599
|
-
// src/config-storage/
|
|
8600
|
-
function
|
|
8601
|
-
|
|
8602
|
-
|
|
8603
|
-
|
|
8604
|
-
...readManagementRequestIdentity(db, operation.mutation_id),
|
|
8605
|
-
kind: operation.kind,
|
|
8606
|
-
expected_revision: operation.expected_revision,
|
|
8607
|
-
aggregate: snapshot.aggregate,
|
|
8608
|
-
target_worker_slots: workers.map((worker) => worker.worker_slot).sort((left, right) => left - right)
|
|
8609
|
-
})) {
|
|
8610
|
-
throw new ConfigRepositoryError("schema_corrupt", "active operation identity is incoherent");
|
|
8611
|
-
}
|
|
9075
|
+
// src/config-storage/consistent-read.ts
|
|
9076
|
+
function withConsistentRead(db, fn) {
|
|
9077
|
+
if (db.inTransaction)
|
|
9078
|
+
return fn();
|
|
9079
|
+
return db.transaction(fn).deferred();
|
|
8612
9080
|
}
|
|
8613
|
-
|
|
8614
|
-
|
|
8615
|
-
|
|
9081
|
+
|
|
9082
|
+
// src/config-storage/serving-snapshot.ts
|
|
9083
|
+
var MAX_AGGREGATE_BYTES = 1048576;
|
|
9084
|
+
function invalid4(message) {
|
|
9085
|
+
throw new ConfigRepositoryError("invalid_configuration", message);
|
|
9086
|
+
}
|
|
9087
|
+
function corrupt2(message) {
|
|
9088
|
+
throw new ConfigRepositoryError("serving_snapshot_corrupt", message);
|
|
9089
|
+
}
|
|
9090
|
+
function canonicalAggregate(aggregate) {
|
|
9091
|
+
const result = parseNormalizeCompileAggregate(aggregate, undefined);
|
|
9092
|
+
if (!result.ok)
|
|
9093
|
+
invalid4("configuration aggregate is invalid");
|
|
9094
|
+
const aggregateJson = canonicalJson(result.value);
|
|
9095
|
+
const bytes = new TextEncoder().encode(aggregateJson).byteLength;
|
|
9096
|
+
if (bytes < 2 || bytes > MAX_AGGREGATE_BYTES) {
|
|
9097
|
+
invalid4("configuration aggregate is too large");
|
|
8616
9098
|
}
|
|
8617
|
-
|
|
8618
|
-
|
|
9099
|
+
return { aggregateJson, contentHash: hashConfigurationContent(result.value) };
|
|
9100
|
+
}
|
|
9101
|
+
function writeServingSnapshot(db, snapshot, pluginCatalogHash) {
|
|
9102
|
+
if (!Number.isSafeInteger(snapshot?.revision) || snapshot.revision <= 0 || typeof snapshot.content_hash !== "string" || !validateDigest(snapshot.content_hash) || !validateDigest(pluginCatalogHash)) {
|
|
9103
|
+
invalid4("serving snapshot identity is invalid");
|
|
8619
9104
|
}
|
|
8620
|
-
|
|
8621
|
-
|
|
9105
|
+
const normalized = canonicalAggregate(snapshot.aggregate);
|
|
9106
|
+
if (normalized.contentHash !== snapshot.content_hash) {
|
|
9107
|
+
invalid4("configuration aggregate content hash does not match");
|
|
8622
9108
|
}
|
|
8623
|
-
|
|
8624
|
-
|
|
9109
|
+
const revision = sqliteGet(db, "SELECT revision,content_hash FROM configuration_revisions WHERE revision=?", snapshot.revision);
|
|
9110
|
+
if (revision === null || revision.content_hash !== snapshot.content_hash) {
|
|
9111
|
+
invalid4("serving snapshot revision does not match configuration history");
|
|
8625
9112
|
}
|
|
8626
|
-
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
|
|
9113
|
+
const existing = sqliteGet(db, `SELECT revision,content_hash,plugin_catalog_hash,aggregate_json
|
|
9114
|
+
FROM configuration_serving_snapshots
|
|
9115
|
+
WHERE revision=? AND content_hash=? AND plugin_catalog_hash=?`, snapshot.revision, snapshot.content_hash, pluginCatalogHash);
|
|
9116
|
+
if (existing !== null) {
|
|
9117
|
+
if (existing.aggregate_json !== normalized.aggregateJson) {
|
|
9118
|
+
corrupt2("configuration serving snapshot is immutable and inconsistent");
|
|
8630
9119
|
}
|
|
9120
|
+
return;
|
|
8631
9121
|
}
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
9122
|
+
db.run(`INSERT INTO configuration_serving_snapshots
|
|
9123
|
+
(revision,content_hash,plugin_catalog_hash,aggregate_json) VALUES (?,?,?,?)`, [snapshot.revision, snapshot.content_hash, pluginCatalogHash, normalized.aggregateJson]);
|
|
9124
|
+
}
|
|
9125
|
+
function appendServingSnapshot(db, snapshot, pluginCatalogHash) {
|
|
9126
|
+
db.transaction(() => writeServingSnapshot(db, snapshot, pluginCatalogHash)).immediate();
|
|
9127
|
+
}
|
|
9128
|
+
function getServingSnapshot(db, key) {
|
|
9129
|
+
if (!Number.isSafeInteger(key?.revision) || key.revision <= 0 || typeof key.content_hash !== "string" || !validateDigest(key.content_hash) || typeof key.plugin_catalog_hash !== "string" || !validateDigest(key.plugin_catalog_hash)) {
|
|
9130
|
+
invalid4("serving snapshot lookup identity is invalid");
|
|
8640
9131
|
}
|
|
8641
|
-
|
|
8642
|
-
|
|
8643
|
-
|
|
9132
|
+
return withConsistentRead(db, () => {
|
|
9133
|
+
const row = sqliteGet(db, `SELECT revision,content_hash,plugin_catalog_hash,aggregate_json
|
|
9134
|
+
FROM configuration_serving_snapshots
|
|
9135
|
+
WHERE revision=? AND content_hash=? AND plugin_catalog_hash=?`, key.revision, key.content_hash, key.plugin_catalog_hash);
|
|
9136
|
+
if (row === null)
|
|
9137
|
+
return null;
|
|
9138
|
+
if (row.revision !== key.revision || row.content_hash !== key.content_hash || row.plugin_catalog_hash !== key.plugin_catalog_hash || !Number.isSafeInteger(row.revision) || row.revision <= 0 || !validateDigest(row.content_hash) || !validateDigest(row.plugin_catalog_hash)) {
|
|
9139
|
+
corrupt2("configuration serving snapshot identity is invalid");
|
|
8644
9140
|
}
|
|
8645
|
-
|
|
8646
|
-
|
|
9141
|
+
const bytes = new TextEncoder().encode(row.aggregate_json).byteLength;
|
|
9142
|
+
if (bytes < 2 || bytes > MAX_AGGREGATE_BYTES)
|
|
9143
|
+
corrupt2("configuration serving snapshot size is invalid");
|
|
9144
|
+
let parsed;
|
|
9145
|
+
try {
|
|
9146
|
+
parsed = JSON.parse(row.aggregate_json);
|
|
9147
|
+
} catch {
|
|
9148
|
+
corrupt2("configuration serving snapshot JSON is invalid");
|
|
8647
9149
|
}
|
|
8648
|
-
|
|
8649
|
-
|
|
9150
|
+
let canonical;
|
|
9151
|
+
try {
|
|
9152
|
+
canonical = canonicalJson(parsed);
|
|
9153
|
+
} catch {
|
|
9154
|
+
corrupt2("configuration serving snapshot JSON is invalid");
|
|
8650
9155
|
}
|
|
8651
|
-
if (
|
|
8652
|
-
|
|
9156
|
+
if (canonical !== row.aggregate_json)
|
|
9157
|
+
corrupt2("configuration serving snapshot JSON is not canonical");
|
|
9158
|
+
const normalized = parseNormalizeCompileAggregate(parsed, undefined);
|
|
9159
|
+
if (!normalized.ok) {
|
|
9160
|
+
if (normalized.errors.some((error) => error.code === "unknown_field" && /^logical_configuration\.routes\[\d+\]\.(service_id|service)$/.test(error.path))) {
|
|
9161
|
+
throw new ConfigRepositoryError("invalid_configuration", "historical serving snapshot does not use the current configuration schema and cannot be loaded");
|
|
9162
|
+
}
|
|
9163
|
+
corrupt2("configuration serving snapshot aggregate is invalid");
|
|
8653
9164
|
}
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
case "degraded":
|
|
8667
|
-
throw new ConfigRepositoryError("schema_corrupt", "terminal operation matched active publication query");
|
|
8668
|
-
}
|
|
9165
|
+
if (canonicalJson(normalized.value) !== row.aggregate_json) {
|
|
9166
|
+
corrupt2("configuration serving snapshot aggregate normalization drifted");
|
|
9167
|
+
}
|
|
9168
|
+
if (hashConfigurationContent(normalized.value) !== key.content_hash) {
|
|
9169
|
+
corrupt2("configuration serving snapshot content hash is invalid");
|
|
9170
|
+
}
|
|
9171
|
+
const revision = sqliteGet(db, "SELECT revision,content_hash FROM configuration_revisions WHERE revision=?", key.revision);
|
|
9172
|
+
if (revision === null || revision.revision !== key.revision || revision.content_hash !== key.content_hash) {
|
|
9173
|
+
corrupt2("configuration serving snapshot revision is invalid");
|
|
9174
|
+
}
|
|
9175
|
+
return { revision: row.revision, content_hash: row.content_hash, aggregate: normalized.value };
|
|
9176
|
+
});
|
|
8669
9177
|
}
|
|
8670
|
-
function
|
|
8671
|
-
const
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
const
|
|
8675
|
-
|
|
8676
|
-
|
|
8677
|
-
|
|
8678
|
-
|
|
8679
|
-
|
|
8680
|
-
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
|
|
8685
|
-
|
|
8686
|
-
|
|
8687
|
-
return null;
|
|
8688
|
-
const operation = requireActiveOperation(row);
|
|
8689
|
-
const targets = readOperationWorkers(db, operation.mutation_id);
|
|
8690
|
-
validateActiveOperationIdentity(db, operation, targets, snapshot);
|
|
8691
|
-
const uniqueSlots = new Set(targets.map(({ worker_slot }) => worker_slot));
|
|
8692
|
-
if (targets.length !== operation.target_worker_count || uniqueSlots.size !== targets.length) {
|
|
8693
|
-
throw new ConfigRepositoryError("schema_corrupt", "active publication target cardinality is incoherent");
|
|
8694
|
-
}
|
|
8695
|
-
if (snapshot.revision !== operation.committed_revision || targets.some(({ target_revision }) => target_revision !== snapshot.revision)) {
|
|
8696
|
-
throw new ConfigRepositoryError("schema_corrupt", "active publication revision is incoherent");
|
|
9178
|
+
function auditServingSnapshotHistory(db) {
|
|
9179
|
+
const rows = db.query(`SELECT s.revision,s.content_hash,s.plugin_catalog_hash,s.aggregate_json,
|
|
9180
|
+
r.content_hash AS revision_hash FROM configuration_serving_snapshots s
|
|
9181
|
+
LEFT JOIN configuration_revisions r ON r.revision=s.revision`).all();
|
|
9182
|
+
for (const row of rows) {
|
|
9183
|
+
if (row.revision_hash !== row.content_hash || !validateDigest(row.content_hash) || !validateDigest(row.plugin_catalog_hash)) {
|
|
9184
|
+
corrupt2("historical serving snapshot identity is invalid");
|
|
9185
|
+
}
|
|
9186
|
+
try {
|
|
9187
|
+
const parsed = JSON.parse(row.aggregate_json);
|
|
9188
|
+
if (new TextEncoder().encode(row.aggregate_json).byteLength > MAX_AGGREGATE_BYTES || canonicalJson(parsed) !== row.aggregate_json || hashConfigurationContent(parsed) !== row.content_hash)
|
|
9189
|
+
corrupt2("historical serving snapshot content is invalid");
|
|
9190
|
+
} catch (error) {
|
|
9191
|
+
if (error instanceof ConfigRepositoryError)
|
|
9192
|
+
throw error;
|
|
9193
|
+
corrupt2("historical serving snapshot JSON is invalid");
|
|
9194
|
+
}
|
|
8697
9195
|
}
|
|
8698
|
-
return { operation, snapshot, targets };
|
|
8699
|
-
}
|
|
8700
|
-
|
|
8701
|
-
// src/config-storage/materialize.ts
|
|
8702
|
-
function writeBindings(db, bindings, owner) {
|
|
8703
|
-
for (const binding of bindings) {
|
|
8704
|
-
db.run(`INSERT INTO plugin_bindings
|
|
8705
|
-
(id,scope_kind,scope_owner,service_id,route_id,upstream_id,position,plugin_name,options_json,enabled)
|
|
8706
|
-
VALUES (?,?,?,?,?,?,?,?,?,?)`, [
|
|
8707
|
-
binding.id,
|
|
8708
|
-
owner.kind,
|
|
8709
|
-
owner.id,
|
|
8710
|
-
owner.kind === "service" ? owner.id : null,
|
|
8711
|
-
owner.kind === "route" ? owner.id : null,
|
|
8712
|
-
owner.kind === "upstream" ? owner.id : null,
|
|
8713
|
-
binding.position,
|
|
8714
|
-
binding.name,
|
|
8715
|
-
binding.options === undefined ? null : canonicalJson(binding.options),
|
|
8716
|
-
binding.enabled ? 1 : 0
|
|
8717
|
-
]);
|
|
8718
|
-
}
|
|
8719
|
-
}
|
|
8720
|
-
function upstreamPolicy(upstream) {
|
|
8721
|
-
const { id, position, target, weight, priority, is_disabled, plugins, ...policy } = upstream;
|
|
8722
|
-
return policy;
|
|
8723
|
-
}
|
|
8724
|
-
function writeUpstreams(db, upstreams, owner) {
|
|
8725
|
-
for (const upstream of upstreams) {
|
|
8726
|
-
db.run(`INSERT INTO upstreams
|
|
8727
|
-
(id,owner_kind,service_id,route_id,position,target,weight,priority,is_disabled,policy_json)
|
|
8728
|
-
VALUES (?,?,?,?,?,?,?,?,?,?)`, [
|
|
8729
|
-
upstream.id,
|
|
8730
|
-
owner.kind,
|
|
8731
|
-
owner.kind === "service" ? owner.id : null,
|
|
8732
|
-
owner.kind === "route" ? owner.id : null,
|
|
8733
|
-
upstream.position,
|
|
8734
|
-
upstream.target,
|
|
8735
|
-
upstream.weight,
|
|
8736
|
-
upstream.priority,
|
|
8737
|
-
upstream.is_disabled ? 1 : 0,
|
|
8738
|
-
canonicalJson(upstreamPolicy(upstream))
|
|
8739
|
-
]);
|
|
8740
|
-
writeBindings(db, upstream.plugins, { kind: "upstream", id: upstream.id });
|
|
8741
|
-
}
|
|
8742
|
-
}
|
|
8743
|
-
function servicePolicy(service) {
|
|
8744
|
-
const { id, position, name, endpoints, service_references, plugins, ...policy } = service;
|
|
8745
|
-
return policy;
|
|
8746
|
-
}
|
|
8747
|
-
function routePolicy(route) {
|
|
8748
|
-
const { id, position, path, plugins, ...remainder } = route;
|
|
8749
|
-
const { endpoints, service_references, ...policy } = remainder;
|
|
8750
|
-
return policy;
|
|
8751
|
-
}
|
|
8752
|
-
function writeServices(db, services) {
|
|
8753
|
-
for (const service of services) {
|
|
8754
|
-
db.run("INSERT INTO services (id,position,name,policy_json) VALUES (?,?,?,?)", [
|
|
8755
|
-
service.id,
|
|
8756
|
-
service.position,
|
|
8757
|
-
service.name,
|
|
8758
|
-
canonicalJson(servicePolicy(service))
|
|
8759
|
-
]);
|
|
8760
|
-
writeUpstreams(db, service.endpoints, { kind: "service", id: service.id });
|
|
8761
|
-
writeBindings(db, service.plugins, { kind: "service", id: service.id });
|
|
8762
|
-
}
|
|
8763
|
-
}
|
|
8764
|
-
function writeRoutes(db, routes) {
|
|
8765
|
-
for (const route of routes) {
|
|
8766
|
-
db.run("INSERT INTO routes (id,position,path,policy_json) VALUES (?,?,?,?)", [
|
|
8767
|
-
route.id,
|
|
8768
|
-
route.position,
|
|
8769
|
-
route.path,
|
|
8770
|
-
canonicalJson(routePolicy(route))
|
|
8771
|
-
]);
|
|
8772
|
-
if (route.endpoints !== undefined)
|
|
8773
|
-
writeUpstreams(db, route.endpoints, { kind: "route", id: route.id });
|
|
8774
|
-
writeBindings(db, route.plugins, { kind: "route", id: route.id });
|
|
8775
|
-
}
|
|
8776
|
-
}
|
|
8777
|
-
function replaceActiveMaterialization(db, aggregate) {
|
|
8778
|
-
if (db.query("SELECT 1 FROM sqlite_schema WHERE name='service_references'").get())
|
|
8779
|
-
db.run("DELETE FROM service_references");
|
|
8780
|
-
db.run("DELETE FROM plugin_bindings");
|
|
8781
|
-
db.run("DELETE FROM plugin_activations");
|
|
8782
|
-
db.run("DELETE FROM upstreams");
|
|
8783
|
-
db.run("DELETE FROM routes");
|
|
8784
|
-
db.run("DELETE FROM services");
|
|
8785
|
-
db.run("DELETE FROM settings");
|
|
8786
|
-
const logical = aggregate.logical_configuration;
|
|
8787
|
-
const settingsColumns = new Set(db.query("PRAGMA table_info(settings)").all().map(({ name }) => name));
|
|
8788
|
-
const publicationColumn = settingsColumns.has("publication_json") ? ",publication_json" : "";
|
|
8789
|
-
const publicationValue = settingsColumns.has("publication_json") ? ",?" : "";
|
|
8790
|
-
const hasWebSocketLimit = settingsColumns.has("websocket_max_connections_json");
|
|
8791
|
-
const hasWebSocketMessageSize = settingsColumns.has("websocket_max_message_bytes");
|
|
8792
|
-
db.run(`INSERT INTO settings
|
|
8793
|
-
(id,log_level,body_parser_limit,auth_json,logging_json${publicationColumn}${hasWebSocketLimit ? ",websocket_max_connections_json" : ""}${hasWebSocketMessageSize ? ",websocket_max_message_bytes" : ""}) VALUES (1,?,?,?,?${publicationValue}${hasWebSocketLimit ? ",?" : ""}${hasWebSocketMessageSize ? ",?" : ""})`, [
|
|
8794
|
-
logical.log_level ?? null,
|
|
8795
|
-
logical.body_parser_limit ?? null,
|
|
8796
|
-
logical.auth === undefined ? null : canonicalJson(logical.auth),
|
|
8797
|
-
logical.logging === undefined ? null : canonicalJson(logical.logging),
|
|
8798
|
-
...settingsColumns.has("publication_json") ? [logical.publication === undefined ? null : canonicalJson(logical.publication)] : [],
|
|
8799
|
-
...hasWebSocketLimit ? [logical.websocket_max_connections === undefined ? null : canonicalJson(logical.websocket_max_connections)] : [],
|
|
8800
|
-
...hasWebSocketMessageSize ? [logical.websocket_max_message_bytes ?? null] : []
|
|
8801
|
-
]);
|
|
8802
|
-
writeServices(db, logical.services);
|
|
8803
|
-
writeRoutes(db, logical.routes);
|
|
8804
|
-
for (const service of logical.services)
|
|
8805
|
-
writeReferences(db, service.service_references ?? [], "service", service.id);
|
|
8806
|
-
for (const route of logical.routes)
|
|
8807
|
-
writeReferences(db, route.service_references ?? [], "route", route.id);
|
|
8808
|
-
writeBindings(db, logical.plugins, { kind: "global", id: "" });
|
|
8809
|
-
for (const activation of aggregate.plugin_activations) {
|
|
8810
|
-
db.run("INSERT INTO plugin_activations (plugin_name) VALUES (?)", [activation.plugin_name]);
|
|
8811
|
-
}
|
|
8812
|
-
}
|
|
8813
|
-
function writeReferences(db, references, ownerKind, ownerId) {
|
|
8814
|
-
for (const ref of references)
|
|
8815
|
-
db.run(`INSERT INTO service_references
|
|
8816
|
-
(id,owner_kind,owner_service_id,route_id,position,service_id,weight,priority,is_disabled) VALUES(?,?,?,?,?,?,?,?,?)`, [
|
|
8817
|
-
ref.id,
|
|
8818
|
-
ownerKind,
|
|
8819
|
-
ownerKind === "service" ? ownerId : null,
|
|
8820
|
-
ownerKind === "route" ? ownerId : null,
|
|
8821
|
-
ref.position,
|
|
8822
|
-
ref.service_id,
|
|
8823
|
-
ref.weight,
|
|
8824
|
-
ref.priority,
|
|
8825
|
-
ref.is_disabled ? 1 : 0
|
|
8826
|
-
]);
|
|
8827
9196
|
}
|
|
8828
9197
|
|
|
8829
9198
|
// src/config-storage/recovery-store.ts
|
|
@@ -8843,27 +9212,27 @@ var REASON_CODES = [
|
|
|
8843
9212
|
var RECOVERY_SELECT = `SELECT recovery_sequence,recovery_id,source_mutation_id,target_revision,trigger,state,
|
|
8844
9213
|
attempt_count,max_attempts,next_retry_at,final_reason_code,final_reason_detail,created_at,updated_at
|
|
8845
9214
|
FROM configuration_recoveries`;
|
|
8846
|
-
function
|
|
9215
|
+
function invalid5(message) {
|
|
8847
9216
|
throw new ConfigRepositoryError("invalid_operation", message);
|
|
8848
9217
|
}
|
|
8849
|
-
function
|
|
9218
|
+
function corrupt3(message) {
|
|
8850
9219
|
throw new ConfigRepositoryError("schema_corrupt", message);
|
|
8851
9220
|
}
|
|
8852
9221
|
function stringValue(value, field) {
|
|
8853
9222
|
if (typeof value !== "string")
|
|
8854
|
-
|
|
9223
|
+
corrupt3(`configuration_recoveries.${field} is invalid`);
|
|
8855
9224
|
return value;
|
|
8856
9225
|
}
|
|
8857
9226
|
function nullableStringValue(value, field) {
|
|
8858
9227
|
if (value !== null && typeof value !== "string")
|
|
8859
|
-
|
|
9228
|
+
corrupt3(`configuration_recoveries.${field} is invalid`);
|
|
8860
9229
|
return value;
|
|
8861
9230
|
}
|
|
8862
9231
|
function reasonCode(value) {
|
|
8863
9232
|
if (value === null)
|
|
8864
9233
|
return null;
|
|
8865
9234
|
if (typeof value !== "string" || !REASON_CODES.includes(value)) {
|
|
8866
|
-
|
|
9235
|
+
corrupt3("configuration_recoveries.final_reason_code is invalid");
|
|
8867
9236
|
}
|
|
8868
9237
|
return value;
|
|
8869
9238
|
}
|
|
@@ -8883,49 +9252,49 @@ function validateTerminalMatrix(state, attemptCount, finalReasonCode, fail) {
|
|
|
8883
9252
|
}
|
|
8884
9253
|
function recoveryFromRow(row) {
|
|
8885
9254
|
if (typeof row.recovery_sequence !== "number")
|
|
8886
|
-
|
|
9255
|
+
corrupt3("configuration_recoveries.recovery_sequence is invalid");
|
|
8887
9256
|
requireSafeInteger(row.recovery_sequence, "configuration_recoveries.recovery_sequence", 1);
|
|
8888
9257
|
const recoveryId = stringValue(row.recovery_id, "recovery_id");
|
|
8889
9258
|
const sourceMutationId = stringValue(row.source_mutation_id, "source_mutation_id");
|
|
8890
9259
|
if (!isLowercaseUuid(recoveryId) || sourceMutationId.length < 1 || sourceMutationId.length > 128) {
|
|
8891
|
-
|
|
9260
|
+
corrupt3("configuration_recoveries identifier bounds are invalid");
|
|
8892
9261
|
}
|
|
8893
|
-
const targetRevision = typeof row.target_revision === "number" ? requireSafeInteger(row.target_revision, "configuration_recoveries.target_revision", 1) :
|
|
9262
|
+
const targetRevision = typeof row.target_revision === "number" ? requireSafeInteger(row.target_revision, "configuration_recoveries.target_revision", 1) : corrupt3("configuration_recoveries.target_revision is invalid");
|
|
8894
9263
|
const trigger = stringValue(row.trigger, "trigger");
|
|
8895
9264
|
if (trigger !== "automatic" && trigger !== "manual")
|
|
8896
|
-
|
|
9265
|
+
corrupt3("configuration_recoveries.trigger is invalid");
|
|
8897
9266
|
const state = stringValue(row.state, "state");
|
|
8898
9267
|
if (state !== "scheduled" && state !== "running" && state !== "succeeded" && state !== "stopped") {
|
|
8899
|
-
|
|
9268
|
+
corrupt3("configuration_recoveries.state is invalid");
|
|
8900
9269
|
}
|
|
8901
|
-
const attemptCount = typeof row.attempt_count === "number" ? requireSafeInteger(row.attempt_count, "configuration_recoveries.attempt_count") :
|
|
8902
|
-
const maxAttempts = typeof row.max_attempts === "number" ? requireSafeInteger(row.max_attempts, "configuration_recoveries.max_attempts") :
|
|
9270
|
+
const attemptCount = typeof row.attempt_count === "number" ? requireSafeInteger(row.attempt_count, "configuration_recoveries.attempt_count") : corrupt3("configuration_recoveries.attempt_count is invalid");
|
|
9271
|
+
const maxAttempts = typeof row.max_attempts === "number" ? requireSafeInteger(row.max_attempts, "configuration_recoveries.max_attempts") : corrupt3("configuration_recoveries.max_attempts is invalid");
|
|
8903
9272
|
if (maxAttempts !== RECOVERY_MAX_ATTEMPTS || attemptCount > maxAttempts) {
|
|
8904
|
-
|
|
9273
|
+
corrupt3("configuration_recoveries attempt bounds are invalid");
|
|
8905
9274
|
}
|
|
8906
|
-
const nextRetryAt = row.next_retry_at === null ? null : typeof row.next_retry_at === "number" ? requireSafeInteger(row.next_retry_at, "configuration_recoveries.next_retry_at") :
|
|
9275
|
+
const nextRetryAt = row.next_retry_at === null ? null : typeof row.next_retry_at === "number" ? requireSafeInteger(row.next_retry_at, "configuration_recoveries.next_retry_at") : corrupt3("configuration_recoveries.next_retry_at is invalid");
|
|
8907
9276
|
const finalReasonCode = reasonCode(row.final_reason_code);
|
|
8908
9277
|
const finalReasonDetail = nullableStringValue(row.final_reason_detail, "final_reason_detail");
|
|
8909
9278
|
if (finalReasonDetail !== null && (finalReasonDetail.length > 512 || finalReasonDetail.trim().length === 0)) {
|
|
8910
|
-
|
|
9279
|
+
corrupt3("configuration_recoveries.final_reason_detail is invalid");
|
|
8911
9280
|
}
|
|
8912
|
-
const createdAt = typeof row.created_at === "number" ? requireSafeInteger(row.created_at, "configuration_recoveries.created_at") :
|
|
8913
|
-
const updatedAt = typeof row.updated_at === "number" ? requireSafeInteger(row.updated_at, "configuration_recoveries.updated_at", createdAt) :
|
|
9281
|
+
const createdAt = typeof row.created_at === "number" ? requireSafeInteger(row.created_at, "configuration_recoveries.created_at") : corrupt3("configuration_recoveries.created_at is invalid");
|
|
9282
|
+
const updatedAt = typeof row.updated_at === "number" ? requireSafeInteger(row.updated_at, "configuration_recoveries.updated_at", createdAt) : corrupt3("configuration_recoveries.updated_at is invalid");
|
|
8914
9283
|
if ((state === "scheduled" || state === "running") && (finalReasonCode !== null || finalReasonDetail !== null)) {
|
|
8915
|
-
|
|
9284
|
+
corrupt3("active recovery has a final reason");
|
|
8916
9285
|
}
|
|
8917
9286
|
if (state === "running" && (nextRetryAt !== null || attemptCount < 1))
|
|
8918
|
-
|
|
9287
|
+
corrupt3("running recovery fields are invalid");
|
|
8919
9288
|
if (state === "scheduled" && attemptCount >= RECOVERY_MAX_ATTEMPTS)
|
|
8920
|
-
|
|
9289
|
+
corrupt3("scheduled recovery attempt limit is invalid");
|
|
8921
9290
|
if (state === "scheduled" && nextRetryAt !== null && nextRetryAt <= updatedAt) {
|
|
8922
|
-
|
|
9291
|
+
corrupt3("scheduled recovery retry time is not in the future");
|
|
8923
9292
|
}
|
|
8924
9293
|
if ((state === "succeeded" || state === "stopped") && (finalReasonCode === null || nextRetryAt !== null)) {
|
|
8925
|
-
|
|
9294
|
+
corrupt3("terminal recovery fields are invalid");
|
|
8926
9295
|
}
|
|
8927
9296
|
if (state === "succeeded" || state === "stopped")
|
|
8928
|
-
validateTerminalMatrix(state, attemptCount, finalReasonCode,
|
|
9297
|
+
validateTerminalMatrix(state, attemptCount, finalReasonCode, corrupt3);
|
|
8929
9298
|
return {
|
|
8930
9299
|
recovery_id: recoveryId,
|
|
8931
9300
|
source_mutation_id: sourceMutationId,
|
|
@@ -8948,43 +9317,49 @@ function readRecovery(db, recoveryId) {
|
|
|
8948
9317
|
function readRecoveryRows(db, sql, ...params) {
|
|
8949
9318
|
return sqliteAll(db, sql, ...params).map(recoveryFromRow);
|
|
8950
9319
|
}
|
|
9320
|
+
function readPublicationRecoveryBarrier(db, excludeRecoveryId = null) {
|
|
9321
|
+
if (excludeRecoveryId !== null)
|
|
9322
|
+
requireRecoveryId(excludeRecoveryId);
|
|
9323
|
+
const exclusion = excludeRecoveryId === null ? "" : " AND recovery_id<>?";
|
|
9324
|
+
return readRecoveryRows(db, `${RECOVERY_SELECT}
|
|
9325
|
+
WHERE (state IN ('scheduled','running')
|
|
9326
|
+
OR (state='stopped' AND final_reason_code='safety_outcome_unknown'))${exclusion}
|
|
9327
|
+
ORDER BY CASE WHEN state IN ('scheduled','running') THEN 0 ELSE 1 END,
|
|
9328
|
+
recovery_sequence DESC LIMIT 1`, ...excludeRecoveryId === null ? [] : [excludeRecoveryId])[0] ?? null;
|
|
9329
|
+
}
|
|
8951
9330
|
function readLatestRecovery(db, targetRevision) {
|
|
8952
9331
|
return readRecoveryRows(db, `${RECOVERY_SELECT} WHERE target_revision=?
|
|
8953
9332
|
ORDER BY recovery_sequence DESC LIMIT 1`, targetRevision)[0] ?? null;
|
|
8954
9333
|
}
|
|
8955
|
-
function readCurrentRecovery(db
|
|
8956
|
-
return readRecoveryRows(db, `${RECOVERY_SELECT}
|
|
9334
|
+
function readCurrentRecovery(db) {
|
|
9335
|
+
return readRecoveryRows(db, `${RECOVERY_SELECT}
|
|
8957
9336
|
ORDER BY CASE WHEN state IN ('scheduled','running') THEN 0 ELSE 1 END,
|
|
8958
|
-
recovery_sequence DESC LIMIT 1
|
|
8959
|
-
}
|
|
8960
|
-
function readActiveRecovery(db, targetRevision) {
|
|
8961
|
-
return readRecoveryRows(db, `${RECOVERY_SELECT} WHERE target_revision=? AND state IN ('scheduled','running')
|
|
8962
|
-
ORDER BY recovery_sequence DESC LIMIT 1`, targetRevision)[0] ?? null;
|
|
9337
|
+
recovery_sequence DESC LIMIT 1`)[0] ?? null;
|
|
8963
9338
|
}
|
|
8964
9339
|
function requireRecoveryId(recoveryId) {
|
|
8965
9340
|
if (typeof recoveryId !== "string" || !isLowercaseUuid(recoveryId)) {
|
|
8966
|
-
|
|
9341
|
+
invalid5("recovery_id is invalid");
|
|
8967
9342
|
}
|
|
8968
9343
|
}
|
|
8969
9344
|
function requireNow(now) {
|
|
8970
9345
|
if (!Number.isSafeInteger(now) || now < 0 || now > Number.MAX_SAFE_INTEGER)
|
|
8971
|
-
|
|
9346
|
+
invalid5("recovery timestamp is invalid");
|
|
8972
9347
|
}
|
|
8973
9348
|
function initialRetryAt(trigger, now) {
|
|
8974
9349
|
if (trigger === "manual")
|
|
8975
9350
|
return null;
|
|
8976
9351
|
if (now > Number.MAX_SAFE_INTEGER - RECOVERY_INITIAL_DELAY_MS)
|
|
8977
|
-
|
|
9352
|
+
invalid5("automatic recovery retry timestamp would overflow");
|
|
8978
9353
|
return now + RECOVERY_INITIAL_DELAY_MS;
|
|
8979
9354
|
}
|
|
8980
9355
|
function requireAttempt(attemptCount) {
|
|
8981
9356
|
if (!Number.isSafeInteger(attemptCount) || attemptCount < 0 || attemptCount > RECOVERY_MAX_ATTEMPTS) {
|
|
8982
|
-
|
|
9357
|
+
invalid5("recovery attempt count is invalid");
|
|
8983
9358
|
}
|
|
8984
9359
|
}
|
|
8985
9360
|
function requireDetail(detail) {
|
|
8986
9361
|
if (detail !== null && (detail.length > 512 || detail.trim().length === 0))
|
|
8987
|
-
|
|
9362
|
+
invalid5("recovery reason detail is invalid");
|
|
8988
9363
|
}
|
|
8989
9364
|
function requireReasonCompatible(db, recovery, reason) {
|
|
8990
9365
|
if (reason !== "deterministic_worker_rejection" && reason !== "deterministic_protocol_failure" && reason !== "deterministic_control_failure" && reason !== "fatal_source_failure")
|
|
@@ -8997,22 +9372,16 @@ function requireReasonCompatible(db, recovery, reason) {
|
|
|
8997
9372
|
function requireRevisionDrift(db, recovery) {
|
|
8998
9373
|
const currentRevision = sqliteGet(db, "SELECT active_revision FROM configuration_state WHERE id=1")?.active_revision;
|
|
8999
9374
|
if (currentRevision === undefined || currentRevision <= recovery.target_revision)
|
|
9000
|
-
|
|
9375
|
+
invalid5("revision has not been superseded");
|
|
9001
9376
|
}
|
|
9002
|
-
function
|
|
9377
|
+
function requireTimestamp3(now, recovery) {
|
|
9003
9378
|
requireNow(now);
|
|
9004
9379
|
if (now < recovery.updated_at)
|
|
9005
|
-
|
|
9380
|
+
invalid5("recovery timestamp regressed");
|
|
9006
9381
|
}
|
|
9007
9382
|
function sameIdentity(recovery, trigger, sourceMutationId, targetRevision) {
|
|
9008
9383
|
return recovery.trigger === trigger && recovery.source_mutation_id === sourceMutationId && recovery.target_revision === targetRevision;
|
|
9009
9384
|
}
|
|
9010
|
-
function requireCurrentTarget(db, recovery) {
|
|
9011
|
-
const currentRevision = sqliteGet(db, "SELECT active_revision FROM configuration_state WHERE id=1")?.active_revision;
|
|
9012
|
-
if (currentRevision !== recovery.target_revision) {
|
|
9013
|
-
throw new ConfigRepositoryError("stale_revision", "recovery target revision is no longer active");
|
|
9014
|
-
}
|
|
9015
|
-
}
|
|
9016
9385
|
function requireSource(db, sourceMutationId) {
|
|
9017
9386
|
const source = sqliteGet(db, "SELECT state,error_code,committed_revision FROM configuration_operations WHERE mutation_id=?", sourceMutationId);
|
|
9018
9387
|
if (source === null || source.state !== "degraded" || source.error_code !== "replacement_convergence_failed" && source.error_code !== "control_readiness_failed") {
|
|
@@ -9022,10 +9391,9 @@ function requireSource(db, sourceMutationId) {
|
|
|
9022
9391
|
}
|
|
9023
9392
|
function requireNoActivePublication(db) {
|
|
9024
9393
|
const active = sqliteGet(db, `SELECT mutation_id FROM configuration_operations
|
|
9025
|
-
WHERE
|
|
9026
|
-
AND state IN ('committed','publishing','draining') LIMIT 1`);
|
|
9394
|
+
WHERE state IN ('committed','publishing','draining') LIMIT 1`);
|
|
9027
9395
|
if (active !== null)
|
|
9028
|
-
|
|
9396
|
+
invalid5("an active publication already exists");
|
|
9029
9397
|
}
|
|
9030
9398
|
function insertRecovery(db, recoveryId, sourceMutationId, targetRevision, trigger, now, initial = { state: "scheduled", final_reason_code: null, final_reason_detail: null }) {
|
|
9031
9399
|
requireRecoveryId(recoveryId);
|
|
@@ -9037,20 +9405,21 @@ function insertRecovery(db, recoveryId, sourceMutationId, targetRevision, trigge
|
|
|
9037
9405
|
}
|
|
9038
9406
|
return existing;
|
|
9039
9407
|
}
|
|
9040
|
-
const active =
|
|
9041
|
-
|
|
9408
|
+
const active = readRecoveryRows(db, `${RECOVERY_SELECT} WHERE target_revision=? AND state IN ('scheduled','running')
|
|
9409
|
+
ORDER BY recovery_sequence DESC LIMIT 1`, targetRevision)[0];
|
|
9410
|
+
if (active !== undefined) {
|
|
9042
9411
|
throw new ConfigRepositoryError("recovery_in_progress", "target revision already has an active recovery", undefined, active);
|
|
9043
9412
|
}
|
|
9044
9413
|
const latest = readLatestRecovery(db, targetRevision);
|
|
9045
9414
|
if (latest !== null && now < latest.updated_at)
|
|
9046
|
-
|
|
9415
|
+
invalid5("recovery timestamp regressed");
|
|
9047
9416
|
const latestCreatedAt = sqliteGet(db, "SELECT created_at FROM configuration_recoveries ORDER BY recovery_sequence DESC LIMIT 1")?.created_at;
|
|
9048
9417
|
if (latestCreatedAt !== null && latestCreatedAt !== undefined && now < latestCreatedAt) {
|
|
9049
|
-
|
|
9418
|
+
invalid5("recovery creation timestamp regressed");
|
|
9050
9419
|
}
|
|
9051
9420
|
const nextRetryAt = initial.state === "scheduled" ? initialRetryAt(trigger, now) : null;
|
|
9052
9421
|
if (initial.state === "stopped" && (initial.final_reason_code === null || initial.final_reason_code === "target_serving" || initial.final_reason_code === "already_serving" || initial.final_reason_code === "retry_exhausted" || initial.final_reason_code === "revision_superseded" || initial.final_reason_code === "safety_outcome_unknown")) {
|
|
9053
|
-
|
|
9422
|
+
invalid5("initial stopped recovery reason is invalid");
|
|
9054
9423
|
}
|
|
9055
9424
|
if (initial.final_reason_detail !== null)
|
|
9056
9425
|
requireDetail(initial.final_reason_detail);
|
|
@@ -9097,13 +9466,21 @@ function createManualRecovery(db, recoveryId, sourceMutationId, expectedRevision
|
|
|
9097
9466
|
throw new ConfigRepositoryError("source_not_retryable", "recovery source operation is not retryable");
|
|
9098
9467
|
}
|
|
9099
9468
|
requireNoActivePublication(db);
|
|
9469
|
+
const barrier = readPublicationRecoveryBarrier(db);
|
|
9470
|
+
if (barrier !== null) {
|
|
9471
|
+
throw new ConfigRepositoryError("recovery_in_progress", "configuration application is blocked by an unresolved recovery", undefined, barrier);
|
|
9472
|
+
}
|
|
9100
9473
|
return insertRecovery(db, recoveryId, sourceMutationId, expectedRevision, "manual", now);
|
|
9101
9474
|
}
|
|
9102
9475
|
function claimRecoveryAttempt(db, recoveryId, previousAttemptCount, now) {
|
|
9103
9476
|
const recovery = readRecovery(db, recoveryId);
|
|
9104
9477
|
if (recovery === null)
|
|
9105
|
-
|
|
9106
|
-
|
|
9478
|
+
invalid5("recovery was not found");
|
|
9479
|
+
requireNoActivePublication(db);
|
|
9480
|
+
const barrier = readPublicationRecoveryBarrier(db, recoveryId);
|
|
9481
|
+
if (barrier !== null) {
|
|
9482
|
+
throw new ConfigRepositoryError("recovery_in_progress", "configuration application is blocked by an unresolved recovery", undefined, barrier);
|
|
9483
|
+
}
|
|
9107
9484
|
requireAttempt(previousAttemptCount);
|
|
9108
9485
|
requireNow(now);
|
|
9109
9486
|
if (recovery.state === "running" && recovery.attempt_count === previousAttemptCount + 1)
|
|
@@ -9111,7 +9488,7 @@ function claimRecoveryAttempt(db, recoveryId, previousAttemptCount, now) {
|
|
|
9111
9488
|
if (recovery.state !== "scheduled" || recovery.attempt_count !== previousAttemptCount) {
|
|
9112
9489
|
throw new ConfigRepositoryError("cas_conflict", "recovery claim CAS failed");
|
|
9113
9490
|
}
|
|
9114
|
-
|
|
9491
|
+
requireTimestamp3(now, recovery);
|
|
9115
9492
|
if (previousAttemptCount >= recovery.max_attempts) {
|
|
9116
9493
|
throw new ConfigRepositoryError("attempts_exhausted", "recovery attempt limit reached");
|
|
9117
9494
|
}
|
|
@@ -9131,20 +9508,19 @@ function claimRecoveryAttempt(db, recoveryId, previousAttemptCount, now) {
|
|
|
9131
9508
|
function scheduleRecoveryRetry(db, recoveryId, attemptCount, nextRetryAt, now) {
|
|
9132
9509
|
const recovery = readRecovery(db, recoveryId);
|
|
9133
9510
|
if (recovery === null)
|
|
9134
|
-
|
|
9135
|
-
requireCurrentTarget(db, recovery);
|
|
9511
|
+
invalid5("recovery was not found");
|
|
9136
9512
|
requireAttempt(attemptCount);
|
|
9137
9513
|
requireNow(nextRetryAt);
|
|
9138
9514
|
if (recovery.state === "scheduled" && recovery.attempt_count === attemptCount && recovery.next_retry_at === nextRetryAt)
|
|
9139
9515
|
return recovery;
|
|
9140
9516
|
if (recovery.state !== "running" || recovery.attempt_count !== attemptCount)
|
|
9141
9517
|
throw new ConfigRepositoryError("cas_conflict", "recovery retry CAS failed");
|
|
9142
|
-
|
|
9518
|
+
requireTimestamp3(now, recovery);
|
|
9143
9519
|
if (attemptCount >= recovery.max_attempts) {
|
|
9144
9520
|
throw new ConfigRepositoryError("attempts_exhausted", "recovery attempt limit reached");
|
|
9145
9521
|
}
|
|
9146
9522
|
if (nextRetryAt <= now)
|
|
9147
|
-
|
|
9523
|
+
invalid5("next retry time must be in the future");
|
|
9148
9524
|
const result = db.run(`UPDATE configuration_recoveries SET state='scheduled',next_retry_at=?,updated_at=?
|
|
9149
9525
|
WHERE recovery_id=? AND state='running' AND attempt_count=?`, [nextRetryAt, now, recoveryId, attemptCount]);
|
|
9150
9526
|
if (result.changes !== 1)
|
|
@@ -9157,20 +9533,18 @@ function scheduleRecoveryRetry(db, recoveryId, attemptCount, nextRetryAt, now) {
|
|
|
9157
9533
|
function terminalTransition(db, recoveryId, attemptCount, state, finalReasonCode, finalReasonDetail, now) {
|
|
9158
9534
|
const recovery = readRecovery(db, recoveryId);
|
|
9159
9535
|
if (recovery === null)
|
|
9160
|
-
|
|
9536
|
+
invalid5("recovery was not found");
|
|
9161
9537
|
requireAttempt(attemptCount);
|
|
9162
|
-
validateTerminalMatrix(state, attemptCount, finalReasonCode,
|
|
9538
|
+
validateTerminalMatrix(state, attemptCount, finalReasonCode, invalid5);
|
|
9163
9539
|
requireDetail(finalReasonDetail);
|
|
9164
9540
|
if (recovery.state === state && recovery.attempt_count === attemptCount && recovery.final_reason_code === finalReasonCode && recovery.final_reason_detail === finalReasonDetail)
|
|
9165
9541
|
return recovery;
|
|
9166
9542
|
if (state === "succeeded" && recovery.state !== "running" && recovery.state !== "scheduled" || state === "stopped" && recovery.state !== "running" && recovery.state !== "scheduled" || recovery.attempt_count !== attemptCount)
|
|
9167
9543
|
throw new ConfigRepositoryError("cas_conflict", "recovery terminal transition CAS failed");
|
|
9168
|
-
if (state === "succeeded")
|
|
9169
|
-
requireCurrentTarget(db, recovery);
|
|
9170
9544
|
if (state === "stopped" && finalReasonCode === "revision_superseded")
|
|
9171
9545
|
requireRevisionDrift(db, recovery);
|
|
9172
9546
|
requireReasonCompatible(db, recovery, finalReasonCode);
|
|
9173
|
-
|
|
9547
|
+
requireTimestamp3(now, recovery);
|
|
9174
9548
|
const result = db.run(`UPDATE configuration_recoveries SET state=?,next_retry_at=NULL,
|
|
9175
9549
|
final_reason_code=?,final_reason_detail=?,updated_at=?
|
|
9176
9550
|
WHERE recovery_id=? AND state IN ('scheduled','running') AND attempt_count=?`, [state, finalReasonCode, finalReasonDetail, now, recoveryId, attemptCount]);
|
|
@@ -9190,8 +9564,7 @@ function stopRecovery(db, recoveryId, attemptCount, finalReasonCode, finalReason
|
|
|
9190
9564
|
function requeueRecovery(db, recoveryId, attemptCount, now) {
|
|
9191
9565
|
const recovery = readRecovery(db, recoveryId);
|
|
9192
9566
|
if (recovery === null)
|
|
9193
|
-
|
|
9194
|
-
requireCurrentTarget(db, recovery);
|
|
9567
|
+
invalid5("recovery was not found");
|
|
9195
9568
|
requireAttempt(attemptCount);
|
|
9196
9569
|
requireNow(now);
|
|
9197
9570
|
if (attemptCount >= recovery.max_attempts) {
|
|
@@ -9201,7 +9574,7 @@ function requeueRecovery(db, recoveryId, attemptCount, now) {
|
|
|
9201
9574
|
return recovery;
|
|
9202
9575
|
if (recovery.state !== "running" || recovery.attempt_count !== attemptCount)
|
|
9203
9576
|
throw new ConfigRepositoryError("cas_conflict", "recovery requeue CAS failed");
|
|
9204
|
-
|
|
9577
|
+
requireTimestamp3(now, recovery);
|
|
9205
9578
|
const result = db.run(`UPDATE configuration_recoveries SET state='scheduled',next_retry_at=NULL,updated_at=?
|
|
9206
9579
|
WHERE recovery_id=? AND state='running' AND attempt_count=?`, [now, recoveryId, attemptCount]);
|
|
9207
9580
|
if (result.changes !== 1)
|
|
@@ -9211,57 +9584,502 @@ function requeueRecovery(db, recoveryId, attemptCount, now) {
|
|
|
9211
9584
|
throw new ConfigRepositoryError("repository_failure", "recovery requeue failed");
|
|
9212
9585
|
return queued;
|
|
9213
9586
|
}
|
|
9214
|
-
function verifyRecoveryIntegrity(db,
|
|
9215
|
-
const rows = readRecoveryRows(db, `${RECOVERY_SELECT} ORDER BY recovery_sequence`);
|
|
9216
|
-
const sequences = sqliteAll(db, "SELECT recovery_sequence,created_at FROM configuration_recoveries ORDER BY recovery_sequence");
|
|
9217
|
-
if (sequences.length !== rows.length || sequences.some((row, index) => row.recovery_sequence !== index + 1) || sequences.some((row, index) => index > 0 && row.created_at < sequences[index - 1].created_at)) {
|
|
9218
|
-
|
|
9587
|
+
function verifyRecoveryIntegrity(db, _allowActiveRecoveryDrift = false) {
|
|
9588
|
+
const rows = readRecoveryRows(db, `${RECOVERY_SELECT} ORDER BY recovery_sequence`);
|
|
9589
|
+
const sequences = sqliteAll(db, "SELECT recovery_sequence,created_at FROM configuration_recoveries ORDER BY recovery_sequence");
|
|
9590
|
+
if (sequences.length !== rows.length || sequences.some((row, index) => row.recovery_sequence !== index + 1) || sequences.some((row, index) => index > 0 && row.created_at < sequences[index - 1].created_at)) {
|
|
9591
|
+
corrupt3("configuration recovery sequences are not contiguous");
|
|
9592
|
+
}
|
|
9593
|
+
const sqliteSequence = sqliteGet(db, "SELECT seq FROM sqlite_sequence WHERE name='configuration_recoveries'");
|
|
9594
|
+
const maxSequence = rows.length === 0 ? 0 : rows.length;
|
|
9595
|
+
if (sqliteSequence === null && maxSequence !== 0 || sqliteSequence !== null && sqliteSequence.seq !== maxSequence) {
|
|
9596
|
+
corrupt3("configuration recovery sqlite sequence is incoherent");
|
|
9597
|
+
}
|
|
9598
|
+
const activeByTarget = new Set;
|
|
9599
|
+
const currentRevision = sqliteGet(db, "SELECT active_revision FROM configuration_state WHERE id=1")?.active_revision;
|
|
9600
|
+
if (currentRevision === undefined)
|
|
9601
|
+
corrupt3("configuration state is missing for recovery audit");
|
|
9602
|
+
for (const recovery of rows) {
|
|
9603
|
+
const source = sqliteGet(db, "SELECT state,error_code,committed_revision FROM configuration_operations WHERE mutation_id=?", recovery.source_mutation_id);
|
|
9604
|
+
if (source === null || source.state !== "degraded" || source.committed_revision !== recovery.target_revision || source.error_code !== "replacement_convergence_failed" && source.error_code !== "control_readiness_failed") {
|
|
9605
|
+
corrupt3("configuration recovery source metadata is incoherent");
|
|
9606
|
+
}
|
|
9607
|
+
if (recovery.final_reason_code === "deterministic_control_failure" && source.error_code !== "control_readiness_failed") {
|
|
9608
|
+
corrupt3("configuration recovery reason is incompatible with its source");
|
|
9609
|
+
}
|
|
9610
|
+
if ((recovery.final_reason_code === "deterministic_worker_rejection" || recovery.final_reason_code === "deterministic_protocol_failure") && source.error_code !== "replacement_convergence_failed") {
|
|
9611
|
+
corrupt3("configuration recovery reason is incompatible with its source");
|
|
9612
|
+
}
|
|
9613
|
+
if (recovery.final_reason_code === "fatal_source_failure" && source.error_code !== "replacement_convergence_failed" && source.error_code !== "control_readiness_failed") {
|
|
9614
|
+
corrupt3("fatal recovery reason is incompatible with its source");
|
|
9615
|
+
}
|
|
9616
|
+
const target = sqliteGet(db, "SELECT revision FROM configuration_revisions WHERE revision=?", recovery.target_revision);
|
|
9617
|
+
if (target === null)
|
|
9618
|
+
corrupt3("configuration recovery target revision is missing");
|
|
9619
|
+
if ((recovery.state === "scheduled" || recovery.state === "running") && activeByTarget.has(recovery.target_revision)) {
|
|
9620
|
+
corrupt3("multiple active recoveries target one revision");
|
|
9621
|
+
}
|
|
9622
|
+
if (recovery.final_reason_code === "revision_superseded" && recovery.target_revision >= currentRevision) {
|
|
9623
|
+
corrupt3("superseded recovery target is not older than the active revision");
|
|
9624
|
+
}
|
|
9625
|
+
if (recovery.target_revision > currentRevision) {
|
|
9626
|
+
corrupt3("recovery target revision is newer than the active revision");
|
|
9627
|
+
}
|
|
9628
|
+
if (recovery.state === "scheduled" || recovery.state === "running")
|
|
9629
|
+
activeByTarget.add(recovery.target_revision);
|
|
9630
|
+
}
|
|
9631
|
+
}
|
|
9632
|
+
|
|
9633
|
+
// src/config-storage/operation-relations.ts
|
|
9634
|
+
function validateOperationIdentity(db, operation, workers, snapshot) {
|
|
9635
|
+
validateOperationRelations(operation, workers);
|
|
9636
|
+
const revision = sqliteGet(db, "SELECT content_hash,kind,created_at FROM configuration_revisions WHERE revision=?", snapshot.revision);
|
|
9637
|
+
if (operation.committed_revision !== snapshot.revision || operation.expected_revision !== snapshot.revision - 1 || revision === null || revision.content_hash !== snapshot.content_hash || revision.kind !== operation.kind || revision.created_at !== operation.created_at || operation.request_hash !== hashConfigurationRequest({
|
|
9638
|
+
...readManagementRequestIdentity(db, operation.mutation_id),
|
|
9639
|
+
kind: operation.kind,
|
|
9640
|
+
expected_revision: operation.expected_revision,
|
|
9641
|
+
aggregate: snapshot.aggregate,
|
|
9642
|
+
target_worker_slots: workers.map((worker) => worker.worker_slot).sort((left, right) => left - right)
|
|
9643
|
+
})) {
|
|
9644
|
+
throw new ConfigRepositoryError("schema_corrupt", "operation identity is incoherent");
|
|
9645
|
+
}
|
|
9646
|
+
}
|
|
9647
|
+
function validateOperationRelations(operation, workers) {
|
|
9648
|
+
if (workers.some((worker) => worker.mutation_id !== operation.mutation_id || worker.target_revision !== operation.committed_revision || worker.updated_at < operation.created_at || worker.updated_at > operation.updated_at)) {
|
|
9649
|
+
throw new ConfigRepositoryError("schema_corrupt", "operation worker metadata is incoherent");
|
|
9650
|
+
}
|
|
9651
|
+
if (workers.length !== operation.target_worker_count) {
|
|
9652
|
+
throw new ConfigRepositoryError("schema_corrupt", "operation target cardinality is incoherent");
|
|
9653
|
+
}
|
|
9654
|
+
if (workers.some(({ drain_recovery_generation }) => drain_recovery_generation !== operation.drain_recovery_generation)) {
|
|
9655
|
+
throw new ConfigRepositoryError("schema_corrupt", "operation recovery generation is incoherent");
|
|
9656
|
+
}
|
|
9657
|
+
if ((operation.state === "pending" || operation.state === "committed") && workers.some(({ state: workerState, attempt_no }) => workerState !== "pending" || attempt_no !== 0)) {
|
|
9658
|
+
throw new ConfigRepositoryError("schema_corrupt", "unstarted operation has terminal worker state");
|
|
9659
|
+
}
|
|
9660
|
+
if (operation.state === "draining" && workers.some(({ state: workerState, attempt_no }) => workerState !== "converged" || attempt_no === 0)) {
|
|
9661
|
+
const invalidRecovery = workers.some(({ state: workerState, attempt_no, last_begin_reason }) => attempt_no === 0 || workerState !== "converged" && last_begin_reason !== "master_recovery" && last_begin_reason !== "retry");
|
|
9662
|
+
if (invalidRecovery) {
|
|
9663
|
+
throw new ConfigRepositoryError("schema_corrupt", "draining operation targets are incoherent");
|
|
9664
|
+
}
|
|
9665
|
+
}
|
|
9666
|
+
if (operation.state === "draining" && operation.drain_recovery_generation > 0 && workers.some(({ last_begin_reason }) => last_begin_reason !== "master_recovery" && last_begin_reason !== "retry")) {
|
|
9667
|
+
throw new ConfigRepositoryError("schema_corrupt", "draining recovery targets are not fully fenced");
|
|
9668
|
+
}
|
|
9669
|
+
if (operation.state === "draining" && operation.drain_recovery_generation === 0 && workers.some(({ state: workerState }) => workerState !== "converged")) {
|
|
9670
|
+
throw new ConfigRepositoryError("schema_corrupt", "unfenced draining operation has active recovery targets");
|
|
9671
|
+
}
|
|
9672
|
+
if (operation.state === "converged" && workers.some(({ state: workerState }) => workerState !== "converged")) {
|
|
9673
|
+
throw new ConfigRepositoryError("schema_corrupt", "converged operation targets are incoherent");
|
|
9674
|
+
}
|
|
9675
|
+
if (operation.state === "degraded") {
|
|
9676
|
+
if (operation.error_code === "replacement_convergence_failed" && (workers.some(({ state: workerState }) => workerState === "pending") || !workers.some(({ state: workerState }) => workerState === "failed"))) {
|
|
9677
|
+
throw new ConfigRepositoryError("schema_corrupt", "replacement failure targets are incoherent");
|
|
9678
|
+
}
|
|
9679
|
+
if (operation.error_code === "old_worker_drain_failed" && workers.some(({ state: workerState, attempt_no }) => workerState !== "converged" || attempt_no === 0)) {
|
|
9680
|
+
throw new ConfigRepositoryError("schema_corrupt", "drain failure targets are incoherent");
|
|
9681
|
+
}
|
|
9682
|
+
if (operation.drain_recovery_generation > 0 && operation.error_code !== "old_worker_drain_failed" && operation.error_code !== "control_readiness_failed") {
|
|
9683
|
+
throw new ConfigRepositoryError("schema_corrupt", "drain recovery terminal result is incoherent");
|
|
9684
|
+
}
|
|
9685
|
+
if (operation.drain_recovery_generation > 0 && workers.some(({ last_begin_reason }) => last_begin_reason !== "master_recovery" && last_begin_reason !== "retry")) {
|
|
9686
|
+
throw new ConfigRepositoryError("schema_corrupt", "drain recovery terminal targets are not fully fenced");
|
|
9687
|
+
}
|
|
9688
|
+
}
|
|
9689
|
+
}
|
|
9690
|
+
|
|
9691
|
+
// src/config-storage/active-publication.ts
|
|
9692
|
+
var OWNER_STATES = `('committed','publishing','draining')`;
|
|
9693
|
+
var SUPERSEDED_DETAIL = "revision was superseded before publication was claimed";
|
|
9694
|
+
var CANCELLED_DETAIL = "publication candidate was cancelled before admission preparation";
|
|
9695
|
+
function readPublicationOwner(db) {
|
|
9696
|
+
const rows = sqliteAll(db, `${OPERATION_SELECT} WHERE state IN ${OWNER_STATES}`);
|
|
9697
|
+
if (rows.length > 1)
|
|
9698
|
+
throw new ConfigRepositoryError("schema_corrupt", "multiple publication owners exist");
|
|
9699
|
+
const row = rows[0];
|
|
9700
|
+
if (row === undefined)
|
|
9701
|
+
return null;
|
|
9702
|
+
const operation = operationFromRow(row);
|
|
9703
|
+
if (operation.state === "pending" || operation.state === "converged" || operation.state === "degraded" || operation.state === "superseded") {
|
|
9704
|
+
throw new ConfigRepositoryError("schema_corrupt", "publication owner state is invalid");
|
|
9705
|
+
}
|
|
9706
|
+
return { operation, targets: readOperationWorkers(db, operation.mutation_id) };
|
|
9707
|
+
}
|
|
9708
|
+
function resolveSnapshot(db, operation, pluginCatalogHash) {
|
|
9709
|
+
const revision = sqliteGet(db, "SELECT content_hash FROM configuration_revisions WHERE revision=?", operation.committed_revision);
|
|
9710
|
+
if (revision === null)
|
|
9711
|
+
throw new ConfigRepositoryError("schema_corrupt", "publication revision is missing");
|
|
9712
|
+
const snapshot = getServingSnapshot(db, {
|
|
9713
|
+
revision: operation.committed_revision,
|
|
9714
|
+
content_hash: revision.content_hash,
|
|
9715
|
+
plugin_catalog_hash: pluginCatalogHash
|
|
9716
|
+
});
|
|
9717
|
+
if (snapshot === null)
|
|
9718
|
+
throw new ConfigRepositoryError("schema_corrupt", "publication snapshot is missing");
|
|
9719
|
+
validateOperationIdentity(db, operation, readOperationWorkers(db, operation.mutation_id), snapshot);
|
|
9720
|
+
return snapshot;
|
|
9721
|
+
}
|
|
9722
|
+
function publicationFrom(db, owner, pluginCatalogHash) {
|
|
9723
|
+
const { operation, targets } = owner;
|
|
9724
|
+
const snapshot = resolveSnapshot(db, operation, pluginCatalogHash);
|
|
9725
|
+
const uniqueSlots = new Set(targets.map(({ worker_slot }) => worker_slot));
|
|
9726
|
+
if (targets.length !== operation.target_worker_count || uniqueSlots.size !== targets.length) {
|
|
9727
|
+
throw new ConfigRepositoryError("schema_corrupt", "publication target cardinality is incoherent");
|
|
9728
|
+
}
|
|
9729
|
+
if (targets.some(({ target_revision }) => target_revision !== operation.committed_revision)) {
|
|
9730
|
+
throw new ConfigRepositoryError("schema_corrupt", "publication targets do not belong to the frozen revision");
|
|
9731
|
+
}
|
|
9732
|
+
return { operation, snapshot, targets, plugin_catalog_hash: pluginCatalogHash };
|
|
9733
|
+
}
|
|
9734
|
+
function readActivePublication(db) {
|
|
9735
|
+
const owner = readPublicationOwner(db);
|
|
9736
|
+
if (owner === null)
|
|
9737
|
+
return null;
|
|
9738
|
+
if (owner.operation.plugin_catalog_hash === null) {
|
|
9739
|
+
throw new ConfigRepositoryError("schema_corrupt", "publication snapshot catalog identity is missing");
|
|
9740
|
+
}
|
|
9741
|
+
return publicationFrom(db, owner, owner.operation.plugin_catalog_hash);
|
|
9742
|
+
}
|
|
9743
|
+
function requireLatestAggregate(db, snapshot, revision) {
|
|
9744
|
+
if (snapshot.revision !== revision || snapshot.revision !== readActiveRevision(db)) {
|
|
9745
|
+
throw new ConfigRepositoryError("schema_corrupt", "publication target disagrees with the latest snapshot");
|
|
9746
|
+
}
|
|
9747
|
+
return snapshot.aggregate;
|
|
9748
|
+
}
|
|
9749
|
+
function claimPublicationTarget(db, snapshot, pluginCatalogHash, updatedAt) {
|
|
9750
|
+
if (!validateDigest(pluginCatalogHash)) {
|
|
9751
|
+
throw new ConfigRepositoryError("invalid_command", "publication catalog identity is invalid");
|
|
9752
|
+
}
|
|
9753
|
+
if (!Number.isSafeInteger(updatedAt) || updatedAt < 0) {
|
|
9754
|
+
throw new ConfigRepositoryError("invalid_command", "publication claim timestamp is invalid");
|
|
9755
|
+
}
|
|
9756
|
+
const owner = readPublicationOwner(db);
|
|
9757
|
+
if (owner !== null) {
|
|
9758
|
+
if (owner.operation.plugin_catalog_hash === null) {
|
|
9759
|
+
throw new ConfigRepositoryError("schema_corrupt", "publication owner has no frozen catalog identity");
|
|
9760
|
+
}
|
|
9761
|
+
if (owner.operation.plugin_catalog_hash !== pluginCatalogHash) {
|
|
9762
|
+
throw new ConfigRepositoryError("invalid_operation", "claimed publication catalog identity is immutable");
|
|
9763
|
+
}
|
|
9764
|
+
return publicationFrom(db, owner, pluginCatalogHash);
|
|
9765
|
+
}
|
|
9766
|
+
const recovery = readPublicationRecoveryBarrier(db);
|
|
9767
|
+
if (recovery !== null) {
|
|
9768
|
+
throw new ConfigRepositoryError("recovery_in_progress", "configuration application is blocked by an unresolved recovery", undefined, recovery);
|
|
9769
|
+
}
|
|
9770
|
+
const retirement = sqliteGet(db, "SELECT mutation_id FROM configuration_retirements WHERE state<>'released' LIMIT 1");
|
|
9771
|
+
if (retirement !== null) {
|
|
9772
|
+
throw new ConfigRepositoryError("invalid_operation", "configuration application is blocked by unresolved worker retirement");
|
|
9773
|
+
}
|
|
9774
|
+
if (readUnsettledWorkerLaunches(db).length > 0) {
|
|
9775
|
+
throw new ConfigRepositoryError("invalid_operation", "configuration application is blocked by an unsettled worker launch");
|
|
9776
|
+
}
|
|
9777
|
+
const candidateRow = sqliteGet(db, `${OPERATION_SELECT} WHERE state='pending' ORDER BY committed_revision DESC LIMIT 1`);
|
|
9778
|
+
if (candidateRow === null)
|
|
9779
|
+
return null;
|
|
9780
|
+
const candidate = operationFromRow(candidateRow);
|
|
9781
|
+
if (candidate.state !== "pending")
|
|
9782
|
+
throw new ConfigRepositoryError("schema_corrupt", "pending target state is invalid");
|
|
9783
|
+
const activeRevision = readActiveRevision(db);
|
|
9784
|
+
if (candidate.committed_revision !== activeRevision) {
|
|
9785
|
+
throw new ConfigRepositoryError("schema_corrupt", "pending target is not the latest revision");
|
|
9786
|
+
}
|
|
9787
|
+
const supersededAt = Math.max(updatedAt, candidate.created_at);
|
|
9788
|
+
db.run(`UPDATE configuration_operations
|
|
9789
|
+
SET state='superseded',result_status=409,error_code='revision_superseded',error_detail=?,updated_at=?
|
|
9790
|
+
WHERE state='pending' AND committed_revision<>?`, [SUPERSEDED_DETAIL, supersededAt, candidate.committed_revision]);
|
|
9791
|
+
const aggregate = requireLatestAggregate(db, snapshot, candidate.committed_revision);
|
|
9792
|
+
const revision = sqliteGet(db, "SELECT content_hash FROM configuration_revisions WHERE revision=?", candidate.committed_revision);
|
|
9793
|
+
if (revision === null || hashConfigurationContent(aggregate) !== revision.content_hash) {
|
|
9794
|
+
throw new ConfigRepositoryError("schema_corrupt", "claimed target aggregate does not match its revision");
|
|
9795
|
+
}
|
|
9796
|
+
writeServingSnapshot(db, {
|
|
9797
|
+
revision: candidate.committed_revision,
|
|
9798
|
+
content_hash: revision.content_hash,
|
|
9799
|
+
aggregate
|
|
9800
|
+
}, pluginCatalogHash);
|
|
9801
|
+
const claimed = db.run(`UPDATE configuration_operations
|
|
9802
|
+
SET state='committed',plugin_catalog_hash=?,updated_at=?
|
|
9803
|
+
WHERE mutation_id=? AND state='pending'`, [pluginCatalogHash, supersededAt, candidate.mutation_id]);
|
|
9804
|
+
if (claimed.changes !== 1)
|
|
9805
|
+
throw new ConfigRepositoryError("repository_failure", "publication claim lost its target");
|
|
9806
|
+
const ownerAfter = readPublicationOwner(db);
|
|
9807
|
+
if (ownerAfter === null)
|
|
9808
|
+
throw new ConfigRepositoryError("repository_failure", "publication claim did not persist");
|
|
9809
|
+
return publicationFrom(db, ownerAfter, pluginCatalogHash);
|
|
9810
|
+
}
|
|
9811
|
+
function requireOwner(db, mutationId, committedRevision) {
|
|
9812
|
+
const owner = readPublicationOwner(db);
|
|
9813
|
+
if (owner === null || owner.operation.mutation_id !== mutationId || owner.operation.committed_revision !== committedRevision) {
|
|
9814
|
+
throw new ConfigRepositoryError("invalid_operation", "publication command does not match the current owner");
|
|
9815
|
+
}
|
|
9816
|
+
return owner.operation;
|
|
9817
|
+
}
|
|
9818
|
+
function requireTimestamp4(updatedAt, operation) {
|
|
9819
|
+
if (!Number.isSafeInteger(updatedAt) || updatedAt < operation.updated_at) {
|
|
9820
|
+
throw new ConfigRepositoryError("invalid_operation", "operation timestamp regressed or is unsafe");
|
|
9821
|
+
}
|
|
9822
|
+
}
|
|
9823
|
+
function requestPublicationCancellation(db, mutationId, committedRevision, updatedAt) {
|
|
9824
|
+
const operation = requireOwner(db, mutationId, committedRevision);
|
|
9825
|
+
if (operation.prepare_started || operation.state === "draining") {
|
|
9826
|
+
throw new ConfigRepositoryError("cancellation_not_permitted", "publication candidate has entered admission preparation");
|
|
9827
|
+
}
|
|
9828
|
+
if (operation.cancel_requested)
|
|
9829
|
+
return operation;
|
|
9830
|
+
requireTimestamp4(updatedAt, operation);
|
|
9831
|
+
db.run(`UPDATE configuration_operations SET cancel_requested=1,updated_at=?
|
|
9832
|
+
WHERE mutation_id=? AND state IN ('committed','publishing') AND prepare_started=0`, [updatedAt, mutationId]);
|
|
9833
|
+
const updated = sqliteGet(db, `${OPERATION_SELECT} WHERE mutation_id=?`, mutationId);
|
|
9834
|
+
if (updated === null)
|
|
9835
|
+
throw new ConfigRepositoryError("repository_failure", "cancellation request was not persisted");
|
|
9836
|
+
return operationFromRow(updated);
|
|
9837
|
+
}
|
|
9838
|
+
function enterPublicationPrepare(db, mutationId, committedRevision, updatedAt) {
|
|
9839
|
+
const operation = requireOwner(db, mutationId, committedRevision);
|
|
9840
|
+
if (operation.state === "draining")
|
|
9841
|
+
throw new ConfigRepositoryError("invalid_operation", "operation is not a candidate");
|
|
9842
|
+
if (operation.prepare_started)
|
|
9843
|
+
return { kind: "granted", operation };
|
|
9844
|
+
const latestRevision = readActiveRevision(db);
|
|
9845
|
+
if (latestRevision < operation.committed_revision) {
|
|
9846
|
+
throw new ConfigRepositoryError("schema_corrupt", "publication target is newer than the latest revision");
|
|
9847
|
+
}
|
|
9848
|
+
if (latestRevision > operation.committed_revision) {
|
|
9849
|
+
if (!operation.cancel_requested) {
|
|
9850
|
+
db.run(`UPDATE configuration_operations SET cancel_requested=1,updated_at=?
|
|
9851
|
+
WHERE mutation_id=? AND state IN ('committed','publishing') AND prepare_started=0 AND cancel_requested=0`, [Math.max(updatedAt, operation.updated_at), mutationId]);
|
|
9852
|
+
}
|
|
9853
|
+
return { kind: "cancelled" };
|
|
9854
|
+
}
|
|
9855
|
+
if (operation.cancel_requested)
|
|
9856
|
+
return { kind: "cancelled" };
|
|
9857
|
+
requireTimestamp4(updatedAt, operation);
|
|
9858
|
+
const granted = db.run(`UPDATE configuration_operations SET prepare_started=1,updated_at=?
|
|
9859
|
+
WHERE mutation_id=? AND state IN ('committed','publishing') AND prepare_started=0 AND cancel_requested=0`, [updatedAt, mutationId]).changes;
|
|
9860
|
+
const current = sqliteGet(db, `${OPERATION_SELECT} WHERE mutation_id=?`, mutationId);
|
|
9861
|
+
if (current === null)
|
|
9862
|
+
throw new ConfigRepositoryError("repository_failure", "preparation decision was not persisted");
|
|
9863
|
+
const result = operationFromRow(current);
|
|
9864
|
+
if (granted === 1)
|
|
9865
|
+
return { kind: "granted", operation: result };
|
|
9866
|
+
if (result.state === "committed" || result.state === "publishing") {
|
|
9867
|
+
if (result.cancel_requested)
|
|
9868
|
+
return { kind: "cancelled" };
|
|
9869
|
+
}
|
|
9870
|
+
throw new ConfigRepositoryError("invalid_operation", "preparation decision lost the owner");
|
|
9871
|
+
}
|
|
9872
|
+
function recordPublicationCandidateExit(db, mutationId, committedRevision, workerSlot, attemptNo, evidence, updatedAt) {
|
|
9873
|
+
if (evidence === null || typeof evidence !== "object" || evidence.kind !== "not_started" && (evidence.kind !== "exited" || evidence.cleanup !== "released")) {
|
|
9874
|
+
throw new ConfigRepositoryError("invalid_command", "candidate exit evidence is invalid");
|
|
9875
|
+
}
|
|
9876
|
+
const operation = requireOwner(db, mutationId, committedRevision);
|
|
9877
|
+
if (operation.state === "draining") {
|
|
9878
|
+
throw new ConfigRepositoryError("invalid_operation", "operation is not a candidate");
|
|
9879
|
+
}
|
|
9880
|
+
requireTimestamp4(updatedAt, operation);
|
|
9881
|
+
const worker = readOperationWorkers(db, mutationId).find((candidate) => candidate.worker_slot === workerSlot);
|
|
9882
|
+
if (worker === undefined || !Number.isSafeInteger(attemptNo) || attemptNo <= 0 || worker.attempt_no !== attemptNo) {
|
|
9883
|
+
throw new ConfigRepositoryError("invalid_operation", "candidate attempt identity is stale or not started");
|
|
9884
|
+
}
|
|
9885
|
+
const exitKind = evidence.kind;
|
|
9886
|
+
const cleanup = evidence.kind === "not_started" ? "not_started" : "released";
|
|
9887
|
+
const launchFacts = readWorkerLaunchAllocationFacts(db, { mutation_id: mutationId, worker_slot: workerSlot, attempt_no: attemptNo });
|
|
9888
|
+
if (launchFacts !== null && (exitKind === "not_started" && launchFacts.exited_at !== null || exitKind === "exited" && launchFacts.not_started_at !== null)) {
|
|
9889
|
+
throw new ConfigRepositoryError("cas_conflict", "candidate exit evidence conflicts with worker launch proof");
|
|
9890
|
+
}
|
|
9891
|
+
const existing = sqliteGet(db, `SELECT exit_kind,cleanup FROM configuration_publication_candidate_evidence
|
|
9892
|
+
WHERE mutation_id=? AND worker_slot=? AND attempt_no=?`, mutationId, workerSlot, attemptNo);
|
|
9893
|
+
if (existing !== null) {
|
|
9894
|
+
if (existing.exit_kind !== exitKind || existing.cleanup !== cleanup) {
|
|
9895
|
+
throw new ConfigRepositoryError("cas_conflict", "candidate exit evidence is already frozen");
|
|
9896
|
+
}
|
|
9897
|
+
return;
|
|
9898
|
+
}
|
|
9899
|
+
db.run(`INSERT INTO configuration_publication_candidate_evidence
|
|
9900
|
+
(mutation_id,worker_slot,attempt_no,exit_kind,cleanup,updated_at) VALUES (?,?,?,?,?,?)`, [mutationId, workerSlot, attemptNo, exitKind, cleanup, updatedAt]);
|
|
9901
|
+
}
|
|
9902
|
+
function readOutstandingPublicationCandidates(db) {
|
|
9903
|
+
const owner = readPublicationOwner(db);
|
|
9904
|
+
if (owner === null)
|
|
9905
|
+
return [];
|
|
9906
|
+
return owner.targets.filter(({ attempt_no }) => attempt_no > 0).map(({ worker_slot, attempt_no, state, updated_at }) => ({
|
|
9907
|
+
mutation_id: owner.operation.mutation_id,
|
|
9908
|
+
committed_revision: owner.operation.committed_revision,
|
|
9909
|
+
plugin_catalog_hash: owner.operation.plugin_catalog_hash,
|
|
9910
|
+
worker_slot,
|
|
9911
|
+
attempt_no,
|
|
9912
|
+
state,
|
|
9913
|
+
updated_at
|
|
9914
|
+
}));
|
|
9915
|
+
}
|
|
9916
|
+
function confirmPublicationCandidateExited(db, mutationId, committedRevision, updatedAt) {
|
|
9917
|
+
const operation = requireOwner(db, mutationId, committedRevision);
|
|
9918
|
+
if (operation.state === "draining" || operation.prepare_started) {
|
|
9919
|
+
throw new ConfigRepositoryError("cancellation_not_permitted", "publication candidate has entered admission preparation");
|
|
9920
|
+
}
|
|
9921
|
+
if (!operation.cancel_requested) {
|
|
9922
|
+
throw new ConfigRepositoryError("invalid_operation", "candidate cancellation was not requested");
|
|
9923
|
+
}
|
|
9924
|
+
const started = readOperationWorkers(db, mutationId).filter(({ attempt_no }) => attempt_no > 0);
|
|
9925
|
+
for (const worker of started) {
|
|
9926
|
+
const evidence = sqliteGet(db, `SELECT attempt_no FROM configuration_publication_candidate_evidence
|
|
9927
|
+
WHERE mutation_id=? AND worker_slot=? AND attempt_no=?`, mutationId, worker.worker_slot, worker.attempt_no);
|
|
9928
|
+
const launch = readWorkerLaunchAllocationFacts(db, {
|
|
9929
|
+
mutation_id: mutationId,
|
|
9930
|
+
worker_slot: worker.worker_slot,
|
|
9931
|
+
attempt_no: worker.attempt_no
|
|
9932
|
+
});
|
|
9933
|
+
if (evidence === null && launch?.settled !== true) {
|
|
9934
|
+
throw new ConfigRepositoryError("invalid_operation", "candidate exit evidence is incomplete");
|
|
9935
|
+
}
|
|
9936
|
+
}
|
|
9937
|
+
requireTimestamp4(updatedAt, operation);
|
|
9938
|
+
const changed = db.run(`UPDATE configuration_operations
|
|
9939
|
+
SET state='superseded',result_status=409,error_code='revision_superseded',error_detail=?,updated_at=?
|
|
9940
|
+
WHERE mutation_id=? AND state IN ('committed','publishing') AND prepare_started=0 AND cancel_requested=1`, [CANCELLED_DETAIL, updatedAt, mutationId]).changes;
|
|
9941
|
+
if (changed !== 1)
|
|
9942
|
+
throw new ConfigRepositoryError("cas_conflict", "candidate supersession lost its owner");
|
|
9943
|
+
const terminal = sqliteGet(db, `${OPERATION_SELECT} WHERE mutation_id=?`, mutationId);
|
|
9944
|
+
if (terminal === null)
|
|
9945
|
+
throw new ConfigRepositoryError("repository_failure", "candidate supersession was not persisted");
|
|
9946
|
+
return operationFromRow(terminal);
|
|
9947
|
+
}
|
|
9948
|
+
|
|
9949
|
+
// src/config-storage/materialize.ts
|
|
9950
|
+
function writeBindings(db, bindings, owner) {
|
|
9951
|
+
for (const binding of bindings) {
|
|
9952
|
+
db.run(`INSERT INTO plugin_bindings
|
|
9953
|
+
(id,scope_kind,scope_owner,service_id,route_id,upstream_id,position,plugin_name,options_json,enabled)
|
|
9954
|
+
VALUES (?,?,?,?,?,?,?,?,?,?)`, [
|
|
9955
|
+
binding.id,
|
|
9956
|
+
owner.kind,
|
|
9957
|
+
owner.id,
|
|
9958
|
+
owner.kind === "service" ? owner.id : null,
|
|
9959
|
+
owner.kind === "route" ? owner.id : null,
|
|
9960
|
+
owner.kind === "upstream" ? owner.id : null,
|
|
9961
|
+
binding.position,
|
|
9962
|
+
binding.name,
|
|
9963
|
+
binding.options === undefined ? null : canonicalJson(binding.options),
|
|
9964
|
+
binding.enabled ? 1 : 0
|
|
9965
|
+
]);
|
|
9966
|
+
}
|
|
9967
|
+
}
|
|
9968
|
+
function upstreamPolicy(upstream) {
|
|
9969
|
+
const { id, position, target, weight, priority, is_disabled, plugins, ...policy } = upstream;
|
|
9970
|
+
return policy;
|
|
9971
|
+
}
|
|
9972
|
+
function writeUpstreams(db, upstreams, owner) {
|
|
9973
|
+
for (const upstream of upstreams) {
|
|
9974
|
+
db.run(`INSERT INTO upstreams
|
|
9975
|
+
(id,owner_kind,service_id,route_id,position,target,weight,priority,is_disabled,policy_json)
|
|
9976
|
+
VALUES (?,?,?,?,?,?,?,?,?,?)`, [
|
|
9977
|
+
upstream.id,
|
|
9978
|
+
owner.kind,
|
|
9979
|
+
owner.kind === "service" ? owner.id : null,
|
|
9980
|
+
owner.kind === "route" ? owner.id : null,
|
|
9981
|
+
upstream.position,
|
|
9982
|
+
upstream.target,
|
|
9983
|
+
upstream.weight,
|
|
9984
|
+
upstream.priority,
|
|
9985
|
+
upstream.is_disabled ? 1 : 0,
|
|
9986
|
+
canonicalJson(upstreamPolicy(upstream))
|
|
9987
|
+
]);
|
|
9988
|
+
writeBindings(db, upstream.plugins, { kind: "upstream", id: upstream.id });
|
|
9989
|
+
}
|
|
9990
|
+
}
|
|
9991
|
+
function servicePolicy(service) {
|
|
9992
|
+
const { id, position, name, endpoints, service_references, plugins, ...policy } = service;
|
|
9993
|
+
return policy;
|
|
9994
|
+
}
|
|
9995
|
+
function routePolicy(route) {
|
|
9996
|
+
const { id, position, path, plugins, ...remainder } = route;
|
|
9997
|
+
const { endpoints, service_references, ...policy } = remainder;
|
|
9998
|
+
return policy;
|
|
9999
|
+
}
|
|
10000
|
+
function writeServices(db, services) {
|
|
10001
|
+
for (const service of services) {
|
|
10002
|
+
db.run("INSERT INTO services (id,position,name,policy_json) VALUES (?,?,?,?)", [
|
|
10003
|
+
service.id,
|
|
10004
|
+
service.position,
|
|
10005
|
+
service.name,
|
|
10006
|
+
canonicalJson(servicePolicy(service))
|
|
10007
|
+
]);
|
|
10008
|
+
writeUpstreams(db, service.endpoints, { kind: "service", id: service.id });
|
|
10009
|
+
writeBindings(db, service.plugins, { kind: "service", id: service.id });
|
|
9219
10010
|
}
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
10011
|
+
}
|
|
10012
|
+
function writeRoutes(db, routes) {
|
|
10013
|
+
for (const route of routes) {
|
|
10014
|
+
db.run("INSERT INTO routes (id,position,path,policy_json) VALUES (?,?,?,?)", [
|
|
10015
|
+
route.id,
|
|
10016
|
+
route.position,
|
|
10017
|
+
route.path,
|
|
10018
|
+
canonicalJson(routePolicy(route))
|
|
10019
|
+
]);
|
|
10020
|
+
if (route.endpoints !== undefined)
|
|
10021
|
+
writeUpstreams(db, route.endpoints, { kind: "route", id: route.id });
|
|
10022
|
+
writeBindings(db, route.plugins, { kind: "route", id: route.id });
|
|
9224
10023
|
}
|
|
9225
|
-
|
|
9226
|
-
|
|
9227
|
-
if (
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
}
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
10024
|
+
}
|
|
10025
|
+
function replaceActiveMaterialization(db, aggregate) {
|
|
10026
|
+
if (db.query("SELECT 1 FROM sqlite_schema WHERE name='service_references'").get())
|
|
10027
|
+
db.run("DELETE FROM service_references");
|
|
10028
|
+
db.run("DELETE FROM plugin_bindings");
|
|
10029
|
+
db.run("DELETE FROM plugin_activations");
|
|
10030
|
+
db.run("DELETE FROM upstreams");
|
|
10031
|
+
db.run("DELETE FROM routes");
|
|
10032
|
+
db.run("DELETE FROM services");
|
|
10033
|
+
db.run("DELETE FROM settings");
|
|
10034
|
+
const logical = aggregate.logical_configuration;
|
|
10035
|
+
const settingsColumns = new Set(db.query("PRAGMA table_info(settings)").all().map(({ name }) => name));
|
|
10036
|
+
const publicationColumn = settingsColumns.has("publication_json") ? ",publication_json" : "";
|
|
10037
|
+
const publicationValue = settingsColumns.has("publication_json") ? ",?" : "";
|
|
10038
|
+
const hasWebSocketLimit = settingsColumns.has("websocket_max_connections_json");
|
|
10039
|
+
const hasWebSocketMessageSize = settingsColumns.has("websocket_max_message_bytes");
|
|
10040
|
+
db.run(`INSERT INTO settings
|
|
10041
|
+
(id,log_level,body_parser_limit,auth_json,logging_json${publicationColumn}${hasWebSocketLimit ? ",websocket_max_connections_json" : ""}${hasWebSocketMessageSize ? ",websocket_max_message_bytes" : ""}) VALUES (1,?,?,?,?${publicationValue}${hasWebSocketLimit ? ",?" : ""}${hasWebSocketMessageSize ? ",?" : ""})`, [
|
|
10042
|
+
logical.log_level ?? null,
|
|
10043
|
+
logical.body_parser_limit ?? null,
|
|
10044
|
+
logical.auth === undefined ? null : canonicalJson(logical.auth),
|
|
10045
|
+
logical.logging === undefined ? null : canonicalJson(logical.logging),
|
|
10046
|
+
...settingsColumns.has("publication_json") ? [logical.publication === undefined ? null : canonicalJson(logical.publication)] : [],
|
|
10047
|
+
...hasWebSocketLimit ? [logical.websocket_max_connections === undefined ? null : canonicalJson(logical.websocket_max_connections)] : [],
|
|
10048
|
+
...hasWebSocketMessageSize ? [logical.websocket_max_message_bytes ?? null] : []
|
|
10049
|
+
]);
|
|
10050
|
+
writeServices(db, logical.services);
|
|
10051
|
+
writeRoutes(db, logical.routes);
|
|
10052
|
+
for (const service of logical.services)
|
|
10053
|
+
writeReferences(db, service.service_references ?? [], "service", service.id);
|
|
10054
|
+
for (const route of logical.routes)
|
|
10055
|
+
writeReferences(db, route.service_references ?? [], "route", route.id);
|
|
10056
|
+
writeBindings(db, logical.plugins, { kind: "global", id: "" });
|
|
10057
|
+
for (const activation of aggregate.plugin_activations) {
|
|
10058
|
+
db.run("INSERT INTO plugin_activations (plugin_name) VALUES (?)", [activation.plugin_name]);
|
|
9257
10059
|
}
|
|
9258
10060
|
}
|
|
10061
|
+
function writeReferences(db, references, ownerKind, ownerId) {
|
|
10062
|
+
for (const ref of references)
|
|
10063
|
+
db.run(`INSERT INTO service_references
|
|
10064
|
+
(id,owner_kind,owner_service_id,route_id,position,service_id,weight,priority,is_disabled) VALUES(?,?,?,?,?,?,?,?,?)`, [
|
|
10065
|
+
ref.id,
|
|
10066
|
+
ownerKind,
|
|
10067
|
+
ownerKind === "service" ? ownerId : null,
|
|
10068
|
+
ownerKind === "route" ? ownerId : null,
|
|
10069
|
+
ref.position,
|
|
10070
|
+
ref.service_id,
|
|
10071
|
+
ref.weight,
|
|
10072
|
+
ref.priority,
|
|
10073
|
+
ref.is_disabled ? 1 : 0
|
|
10074
|
+
]);
|
|
10075
|
+
}
|
|
9259
10076
|
|
|
9260
10077
|
// src/config-storage/commit-transaction.ts
|
|
9261
10078
|
function commitTransaction(db, prepared, options, snapshot, offlineManagement = false) {
|
|
9262
10079
|
const existing = sqliteGet(db, `SELECT mutation_id,request_hash,expected_revision,
|
|
9263
10080
|
committed_revision,kind,target_worker_count,state,result_status,error_code,error_detail,
|
|
9264
|
-
drain_recovery_generation,last_drain_recovery_previous_generation,
|
|
10081
|
+
drain_recovery_generation,last_drain_recovery_previous_generation,plugin_catalog_hash,cancel_requested,
|
|
10082
|
+
prepare_started,created_at,updated_at
|
|
9265
10083
|
FROM configuration_operations WHERE mutation_id=?`, prepared.mutationId);
|
|
9266
10084
|
if (existing !== null) {
|
|
9267
10085
|
const operation = operationFromRow(existing);
|
|
@@ -9270,38 +10088,11 @@ function commitTransaction(db, prepared, options, snapshot, offlineManagement =
|
|
|
9270
10088
|
}
|
|
9271
10089
|
return { kind: "duplicate", operation };
|
|
9272
10090
|
}
|
|
9273
|
-
const
|
|
9274
|
-
if (
|
|
9275
|
-
return { kind: "stale_revision", expected_revision: prepared.expectedRevision, active_revision:
|
|
9276
|
-
}
|
|
9277
|
-
const activeRow = sqliteGet(db, `SELECT mutation_id,request_hash,expected_revision,
|
|
9278
|
-
committed_revision,kind,target_worker_count,state,result_status,error_code,error_detail,
|
|
9279
|
-
drain_recovery_generation,last_drain_recovery_previous_generation,created_at,updated_at
|
|
9280
|
-
FROM configuration_operations WHERE committed_revision=?`, state.active_revision);
|
|
9281
|
-
if (activeRow !== null) {
|
|
9282
|
-
const active = operationFromRow(activeRow);
|
|
9283
|
-
validateActiveOperationIdentity(db, active, readOperationWorkers(db, active.mutation_id), snapshot);
|
|
9284
|
-
if (active.state === "committed" || active.state === "publishing" || active.state === "draining") {
|
|
9285
|
-
return {
|
|
9286
|
-
kind: "operation_in_progress",
|
|
9287
|
-
mutation_id: active.mutation_id,
|
|
9288
|
-
committed_revision: active.committed_revision,
|
|
9289
|
-
state: active.state
|
|
9290
|
-
};
|
|
9291
|
-
}
|
|
9292
|
-
} else if (state.active_revision !== 1) {
|
|
9293
|
-
throw new ConfigRepositoryError("schema_corrupt", "active revision operation is missing");
|
|
9294
|
-
}
|
|
9295
|
-
const activeRecovery = readActiveRecovery(db, state.active_revision);
|
|
9296
|
-
if (activeRecovery !== null && (activeRecovery.state === "scheduled" || activeRecovery.state === "running")) {
|
|
9297
|
-
return {
|
|
9298
|
-
kind: "recovery_in_progress",
|
|
9299
|
-
recovery_id: activeRecovery.recovery_id,
|
|
9300
|
-
target_revision: activeRecovery.target_revision,
|
|
9301
|
-
state: activeRecovery.state
|
|
9302
|
-
};
|
|
10091
|
+
const activeRevision = readActiveRevision(db);
|
|
10092
|
+
if (activeRevision !== prepared.expectedRevision) {
|
|
10093
|
+
return { kind: "stale_revision", expected_revision: prepared.expectedRevision, active_revision: activeRevision };
|
|
9303
10094
|
}
|
|
9304
|
-
if (
|
|
10095
|
+
if (activeRevision === Number.MAX_SAFE_INTEGER) {
|
|
9305
10096
|
throw new ConfigRepositoryError("repository_failure", "configuration revision limit reached");
|
|
9306
10097
|
}
|
|
9307
10098
|
const protection = readManagementProtection(db);
|
|
@@ -9311,14 +10102,29 @@ function commitTransaction(db, prepared, options, snapshot, offlineManagement =
|
|
|
9311
10102
|
if (prepared.managementProvider !== null && !prepared.aggregate.plugin_activations.some((a) => a.plugin_name === prepared.managementProvider)) {
|
|
9312
10103
|
throw new ConfigRepositoryError("invalid_configuration", "selected management provider activation is missing");
|
|
9313
10104
|
}
|
|
9314
|
-
const
|
|
10105
|
+
const latestRow = sqliteGet(db, `SELECT mutation_id,request_hash,expected_revision,
|
|
10106
|
+
committed_revision,kind,target_worker_count,state,result_status,error_code,error_detail,
|
|
10107
|
+
drain_recovery_generation,last_drain_recovery_previous_generation,plugin_catalog_hash,cancel_requested,
|
|
10108
|
+
prepare_started,created_at,updated_at
|
|
10109
|
+
FROM configuration_operations WHERE committed_revision=?`, activeRevision);
|
|
10110
|
+
if (latestRow !== null) {
|
|
10111
|
+
if (snapshot.revision !== activeRevision) {
|
|
10112
|
+
throw new ConfigRepositoryError("schema_corrupt", "repository snapshot disagrees with the latest revision");
|
|
10113
|
+
}
|
|
10114
|
+
const latest = operationFromRow(latestRow);
|
|
10115
|
+
validateOperationIdentity(db, latest, readOperationWorkers(db, latest.mutation_id), snapshot);
|
|
10116
|
+
}
|
|
10117
|
+
if (!offlineManagement)
|
|
10118
|
+
readActivePublication(db);
|
|
10119
|
+
const committedRevision = activeRevision + 1;
|
|
9315
10120
|
replaceActiveMaterialization(db, prepared.aggregate);
|
|
9316
10121
|
options.faultInjection?.("after_materialization");
|
|
9317
10122
|
db.run(`INSERT INTO configuration_revisions (revision,content_hash,kind,created_at) VALUES (?,?,?,?)`, [committedRevision, prepared.contentHash, prepared.kind, prepared.createdAt]);
|
|
9318
10123
|
db.run(`INSERT INTO configuration_operations
|
|
9319
10124
|
(mutation_id,request_hash,expected_revision,committed_revision,kind,state,result_status,error_code,error_detail,
|
|
9320
|
-
drain_recovery_generation,last_drain_recovery_previous_generation,
|
|
9321
|
-
|
|
10125
|
+
drain_recovery_generation,last_drain_recovery_previous_generation,plugin_catalog_hash,cancel_requested,
|
|
10126
|
+
prepare_started,target_worker_count,created_at,updated_at)
|
|
10127
|
+
VALUES (?,?,?,?,?,'pending',NULL,NULL,NULL,0,NULL,NULL,0,0,?,?,?)`, [
|
|
9322
10128
|
prepared.mutationId,
|
|
9323
10129
|
prepared.requestHash,
|
|
9324
10130
|
prepared.expectedRevision,
|
|
@@ -9354,7 +10160,10 @@ function commitTransaction(db, prepared, options, snapshot, offlineManagement =
|
|
|
9354
10160
|
target_worker_count: prepared.targetSlots.length,
|
|
9355
10161
|
drain_recovery_generation: 0,
|
|
9356
10162
|
last_drain_recovery_previous_generation: null,
|
|
9357
|
-
|
|
10163
|
+
plugin_catalog_hash: null,
|
|
10164
|
+
cancel_requested: false,
|
|
10165
|
+
prepare_started: false,
|
|
10166
|
+
state: "pending",
|
|
9358
10167
|
result_status: null,
|
|
9359
10168
|
error_code: null,
|
|
9360
10169
|
error_detail: null,
|
|
@@ -9604,11 +10413,17 @@ function auditConfigurationTables(db) {
|
|
|
9604
10413
|
}
|
|
9605
10414
|
workersByMutation.set(worker.mutation_id, [...workersByMutation.get(worker.mutation_id) ?? [], worker]);
|
|
9606
10415
|
}
|
|
10416
|
+
let owner;
|
|
9607
10417
|
for (const operation of operations) {
|
|
9608
10418
|
const workers = workersByMutation.get(operation.mutation_id) ?? [];
|
|
9609
10419
|
validateOperationRelations(operation, workers);
|
|
9610
|
-
if (operation.
|
|
9611
|
-
|
|
10420
|
+
if (operation.state === "committed" || operation.state === "publishing" || operation.state === "draining") {
|
|
10421
|
+
if (owner !== undefined)
|
|
10422
|
+
throw new ConfigRepositoryError("schema_corrupt", "multiple publication owners exist");
|
|
10423
|
+
owner = operation;
|
|
10424
|
+
}
|
|
10425
|
+
if (operation.state === "superseded" && operation.committed_revision === state.active_revision) {
|
|
10426
|
+
throw new ConfigRepositoryError("schema_corrupt", "the latest revision cannot be superseded");
|
|
9612
10427
|
}
|
|
9613
10428
|
}
|
|
9614
10429
|
const activeRevisionRow = revisions.at(-1);
|
|
@@ -9700,129 +10515,6 @@ function prepareCommitCommand(input, compileOptions) {
|
|
|
9700
10515
|
};
|
|
9701
10516
|
}
|
|
9702
10517
|
|
|
9703
|
-
// src/config-storage/consistent-read.ts
|
|
9704
|
-
function withConsistentRead(db, fn) {
|
|
9705
|
-
if (db.inTransaction)
|
|
9706
|
-
return fn();
|
|
9707
|
-
return db.transaction(fn).deferred();
|
|
9708
|
-
}
|
|
9709
|
-
|
|
9710
|
-
// src/config-storage/serving-snapshot.ts
|
|
9711
|
-
var MAX_AGGREGATE_BYTES = 1048576;
|
|
9712
|
-
function invalid4(message) {
|
|
9713
|
-
throw new ConfigRepositoryError("invalid_configuration", message);
|
|
9714
|
-
}
|
|
9715
|
-
function corrupt3(message) {
|
|
9716
|
-
throw new ConfigRepositoryError("serving_snapshot_corrupt", message);
|
|
9717
|
-
}
|
|
9718
|
-
function canonicalAggregate(aggregate) {
|
|
9719
|
-
const result = parseNormalizeCompileAggregate(aggregate, undefined);
|
|
9720
|
-
if (!result.ok)
|
|
9721
|
-
invalid4("configuration aggregate is invalid");
|
|
9722
|
-
const aggregateJson = canonicalJson(result.value);
|
|
9723
|
-
const bytes = new TextEncoder().encode(aggregateJson).byteLength;
|
|
9724
|
-
if (bytes < 2 || bytes > MAX_AGGREGATE_BYTES) {
|
|
9725
|
-
invalid4("configuration aggregate is too large");
|
|
9726
|
-
}
|
|
9727
|
-
return { aggregateJson, contentHash: hashConfigurationContent(result.value) };
|
|
9728
|
-
}
|
|
9729
|
-
function appendServingSnapshot(db, snapshot, pluginCatalogHash) {
|
|
9730
|
-
if (!Number.isSafeInteger(snapshot?.revision) || snapshot.revision <= 0 || typeof snapshot.content_hash !== "string" || !validateDigest(snapshot.content_hash) || !validateDigest(pluginCatalogHash)) {
|
|
9731
|
-
invalid4("serving snapshot identity is invalid");
|
|
9732
|
-
}
|
|
9733
|
-
const normalized = canonicalAggregate(snapshot.aggregate);
|
|
9734
|
-
if (normalized.contentHash !== snapshot.content_hash) {
|
|
9735
|
-
invalid4("configuration aggregate content hash does not match");
|
|
9736
|
-
}
|
|
9737
|
-
const transaction = db.transaction(() => {
|
|
9738
|
-
const revision = sqliteGet(db, "SELECT revision,content_hash FROM configuration_revisions WHERE revision=?", snapshot.revision);
|
|
9739
|
-
if (revision === null || revision.content_hash !== snapshot.content_hash) {
|
|
9740
|
-
invalid4("serving snapshot revision does not match configuration history");
|
|
9741
|
-
}
|
|
9742
|
-
const existing = sqliteGet(db, `SELECT revision,content_hash,plugin_catalog_hash,aggregate_json
|
|
9743
|
-
FROM configuration_serving_snapshots
|
|
9744
|
-
WHERE revision=? AND content_hash=? AND plugin_catalog_hash=?`, snapshot.revision, snapshot.content_hash, pluginCatalogHash);
|
|
9745
|
-
if (existing !== null) {
|
|
9746
|
-
if (existing.aggregate_json !== normalized.aggregateJson) {
|
|
9747
|
-
corrupt3("configuration serving snapshot is immutable and inconsistent");
|
|
9748
|
-
}
|
|
9749
|
-
return;
|
|
9750
|
-
}
|
|
9751
|
-
db.run(`INSERT INTO configuration_serving_snapshots
|
|
9752
|
-
(revision,content_hash,plugin_catalog_hash,aggregate_json) VALUES (?,?,?,?)`, [snapshot.revision, snapshot.content_hash, pluginCatalogHash, normalized.aggregateJson]);
|
|
9753
|
-
});
|
|
9754
|
-
transaction.immediate();
|
|
9755
|
-
}
|
|
9756
|
-
function getServingSnapshot(db, key) {
|
|
9757
|
-
if (!Number.isSafeInteger(key?.revision) || key.revision <= 0 || typeof key.content_hash !== "string" || !validateDigest(key.content_hash) || typeof key.plugin_catalog_hash !== "string" || !validateDigest(key.plugin_catalog_hash)) {
|
|
9758
|
-
invalid4("serving snapshot lookup identity is invalid");
|
|
9759
|
-
}
|
|
9760
|
-
return withConsistentRead(db, () => {
|
|
9761
|
-
const row = sqliteGet(db, `SELECT revision,content_hash,plugin_catalog_hash,aggregate_json
|
|
9762
|
-
FROM configuration_serving_snapshots
|
|
9763
|
-
WHERE revision=? AND content_hash=? AND plugin_catalog_hash=?`, key.revision, key.content_hash, key.plugin_catalog_hash);
|
|
9764
|
-
if (row === null)
|
|
9765
|
-
return null;
|
|
9766
|
-
if (row.revision !== key.revision || row.content_hash !== key.content_hash || row.plugin_catalog_hash !== key.plugin_catalog_hash || !Number.isSafeInteger(row.revision) || row.revision <= 0 || !validateDigest(row.content_hash) || !validateDigest(row.plugin_catalog_hash)) {
|
|
9767
|
-
corrupt3("configuration serving snapshot identity is invalid");
|
|
9768
|
-
}
|
|
9769
|
-
const bytes = new TextEncoder().encode(row.aggregate_json).byteLength;
|
|
9770
|
-
if (bytes < 2 || bytes > MAX_AGGREGATE_BYTES)
|
|
9771
|
-
corrupt3("configuration serving snapshot size is invalid");
|
|
9772
|
-
let parsed;
|
|
9773
|
-
try {
|
|
9774
|
-
parsed = JSON.parse(row.aggregate_json);
|
|
9775
|
-
} catch {
|
|
9776
|
-
corrupt3("configuration serving snapshot JSON is invalid");
|
|
9777
|
-
}
|
|
9778
|
-
let canonical;
|
|
9779
|
-
try {
|
|
9780
|
-
canonical = canonicalJson(parsed);
|
|
9781
|
-
} catch {
|
|
9782
|
-
corrupt3("configuration serving snapshot JSON is invalid");
|
|
9783
|
-
}
|
|
9784
|
-
if (canonical !== row.aggregate_json)
|
|
9785
|
-
corrupt3("configuration serving snapshot JSON is not canonical");
|
|
9786
|
-
const normalized = parseNormalizeCompileAggregate(parsed, undefined);
|
|
9787
|
-
if (!normalized.ok) {
|
|
9788
|
-
if (normalized.errors.some((error) => error.code === "unknown_field" && /^logical_configuration\.routes\[\d+\]\.(service_id|service)$/.test(error.path))) {
|
|
9789
|
-
throw new ConfigRepositoryError("invalid_configuration", "historical serving snapshot does not use the current configuration schema and cannot be loaded");
|
|
9790
|
-
}
|
|
9791
|
-
corrupt3("configuration serving snapshot aggregate is invalid");
|
|
9792
|
-
}
|
|
9793
|
-
if (canonicalJson(normalized.value) !== row.aggregate_json) {
|
|
9794
|
-
corrupt3("configuration serving snapshot aggregate normalization drifted");
|
|
9795
|
-
}
|
|
9796
|
-
if (hashConfigurationContent(normalized.value) !== key.content_hash) {
|
|
9797
|
-
corrupt3("configuration serving snapshot content hash is invalid");
|
|
9798
|
-
}
|
|
9799
|
-
const revision = sqliteGet(db, "SELECT revision,content_hash FROM configuration_revisions WHERE revision=?", key.revision);
|
|
9800
|
-
if (revision === null || revision.revision !== key.revision || revision.content_hash !== key.content_hash) {
|
|
9801
|
-
corrupt3("configuration serving snapshot revision is invalid");
|
|
9802
|
-
}
|
|
9803
|
-
return { revision: row.revision, content_hash: row.content_hash, aggregate: normalized.value };
|
|
9804
|
-
});
|
|
9805
|
-
}
|
|
9806
|
-
function auditServingSnapshotHistory(db) {
|
|
9807
|
-
const rows = db.query(`SELECT s.revision,s.content_hash,s.plugin_catalog_hash,s.aggregate_json,
|
|
9808
|
-
r.content_hash AS revision_hash FROM configuration_serving_snapshots s
|
|
9809
|
-
LEFT JOIN configuration_revisions r ON r.revision=s.revision`).all();
|
|
9810
|
-
for (const row of rows) {
|
|
9811
|
-
if (row.revision_hash !== row.content_hash || !validateDigest(row.content_hash) || !validateDigest(row.plugin_catalog_hash)) {
|
|
9812
|
-
corrupt3("historical serving snapshot identity is invalid");
|
|
9813
|
-
}
|
|
9814
|
-
try {
|
|
9815
|
-
const parsed = JSON.parse(row.aggregate_json);
|
|
9816
|
-
if (new TextEncoder().encode(row.aggregate_json).byteLength > MAX_AGGREGATE_BYTES || canonicalJson(parsed) !== row.aggregate_json || hashConfigurationContent(parsed) !== row.content_hash)
|
|
9817
|
-
corrupt3("historical serving snapshot content is invalid");
|
|
9818
|
-
} catch (error) {
|
|
9819
|
-
if (error instanceof ConfigRepositoryError)
|
|
9820
|
-
throw error;
|
|
9821
|
-
corrupt3("historical serving snapshot JSON is invalid");
|
|
9822
|
-
}
|
|
9823
|
-
}
|
|
9824
|
-
}
|
|
9825
|
-
|
|
9826
10518
|
// src/config-storage/schema-fingerprint.ts
|
|
9827
10519
|
import { Database } from "bun:sqlite";
|
|
9828
10520
|
|
|
@@ -10317,8 +11009,152 @@ var PUBLICATION_RETIREMENT_MIGRATION = {
|
|
|
10317
11009
|
}
|
|
10318
11010
|
};
|
|
10319
11011
|
|
|
11012
|
+
// src/config-storage/migrations/publication-targets.ts
|
|
11013
|
+
var PUBLICATION_TARGET_MIGRATION = {
|
|
11014
|
+
version: 8,
|
|
11015
|
+
name: "publication_targets_and_cancellation",
|
|
11016
|
+
up(db) {
|
|
11017
|
+
const unfinished = sqliteGet(db, `SELECT mutation_id,state FROM configuration_operations
|
|
11018
|
+
WHERE state IN ('committed','publishing','draining') LIMIT 1`);
|
|
11019
|
+
if (unfinished !== null) {
|
|
11020
|
+
throw new ConfigRepositoryError("migration_failed", `configuration upgrade cannot resume publication ${unfinished.mutation_id} (${unfinished.state}); finish it with the previous executable before upgrading`);
|
|
11021
|
+
}
|
|
11022
|
+
db.run(`CREATE TABLE configuration_operations_next (
|
|
11023
|
+
mutation_id TEXT PRIMARY KEY CHECK(length(mutation_id) BETWEEN 1 AND 128),
|
|
11024
|
+
request_hash TEXT NOT NULL CHECK(length(request_hash)=71 AND substr(request_hash,1,7)='sha256:' AND substr(request_hash,8) NOT GLOB '*[^0-9a-f]*'),
|
|
11025
|
+
expected_revision INTEGER NOT NULL CHECK(expected_revision > 0 AND expected_revision <= 9007199254740991),
|
|
11026
|
+
committed_revision INTEGER NOT NULL CHECK(committed_revision > 0 AND committed_revision <= 9007199254740991)
|
|
11027
|
+
REFERENCES configuration_revisions(revision),
|
|
11028
|
+
kind TEXT NOT NULL CHECK(kind IN ('config','admin_state')),
|
|
11029
|
+
target_worker_count INTEGER NOT NULL CHECK(target_worker_count >= 0 AND target_worker_count <= 9007199254740991),
|
|
11030
|
+
state TEXT NOT NULL CHECK(state IN ('pending','committed','publishing','draining','converged','degraded','superseded')),
|
|
11031
|
+
result_status INTEGER,
|
|
11032
|
+
error_code TEXT,
|
|
11033
|
+
error_detail TEXT,
|
|
11034
|
+
drain_recovery_generation INTEGER NOT NULL DEFAULT 0
|
|
11035
|
+
CHECK(drain_recovery_generation >= 0 AND drain_recovery_generation <= 9007199254740991),
|
|
11036
|
+
last_drain_recovery_previous_generation INTEGER
|
|
11037
|
+
CHECK(last_drain_recovery_previous_generation IS NULL OR
|
|
11038
|
+
(last_drain_recovery_previous_generation >= 0 AND
|
|
11039
|
+
last_drain_recovery_previous_generation < 9007199254740991)),
|
|
11040
|
+
management_provider TEXT,
|
|
11041
|
+
offline_management INTEGER NOT NULL DEFAULT 0 CHECK(offline_management IN (0,1)),
|
|
11042
|
+
plugin_catalog_hash TEXT CHECK(plugin_catalog_hash IS NULL OR
|
|
11043
|
+
(length(plugin_catalog_hash)=71 AND substr(plugin_catalog_hash,1,7)='sha256:' AND
|
|
11044
|
+
substr(plugin_catalog_hash,8) NOT GLOB '*[^0-9a-f]*')),
|
|
11045
|
+
cancel_requested INTEGER NOT NULL DEFAULT 0 CHECK(cancel_requested IN (0,1)),
|
|
11046
|
+
prepare_started INTEGER NOT NULL DEFAULT 0 CHECK(prepare_started IN (0,1)),
|
|
11047
|
+
created_at INTEGER NOT NULL CHECK(created_at >= 0 AND created_at <= 9007199254740991),
|
|
11048
|
+
updated_at INTEGER NOT NULL CHECK(updated_at >= created_at AND updated_at <= 9007199254740991),
|
|
11049
|
+
UNIQUE(mutation_id,committed_revision),
|
|
11050
|
+
CHECK((drain_recovery_generation=0 AND last_drain_recovery_previous_generation IS NULL) OR
|
|
11051
|
+
(drain_recovery_generation > 0 AND
|
|
11052
|
+
last_drain_recovery_previous_generation=drain_recovery_generation-1)),
|
|
11053
|
+
CHECK((state='pending' AND drain_recovery_generation=0 AND result_status IS NULL AND
|
|
11054
|
+
error_code IS NULL AND error_detail IS NULL AND cancel_requested=0 AND prepare_started=0) OR
|
|
11055
|
+
(state IN ('committed','publishing') AND drain_recovery_generation=0 AND
|
|
11056
|
+
result_status IS NULL AND error_code IS NULL AND error_detail IS NULL) OR
|
|
11057
|
+
(state='draining' AND result_status IS NULL AND error_code IS NULL AND error_detail IS NULL) OR
|
|
11058
|
+
(state='converged' AND drain_recovery_generation=0 AND
|
|
11059
|
+
result_status=200 AND error_code IS NULL AND error_detail IS NULL) OR
|
|
11060
|
+
(state='degraded' AND result_status=202 AND
|
|
11061
|
+
error_code IN ('replacement_convergence_failed','old_worker_drain_failed','control_readiness_failed') AND
|
|
11062
|
+
(error_code <> 'replacement_convergence_failed' OR drain_recovery_generation=0) AND
|
|
11063
|
+
error_detail IS NOT NULL AND length(error_detail) <= 512 AND length(trim(error_detail)) > 0) OR
|
|
11064
|
+
(state='superseded' AND drain_recovery_generation=0 AND result_status=409 AND
|
|
11065
|
+
error_code='revision_superseded' AND prepare_started=0 AND
|
|
11066
|
+
error_detail IS NOT NULL AND length(error_detail) <= 512 AND length(trim(error_detail)) > 0))
|
|
11067
|
+
) STRICT`);
|
|
11068
|
+
db.run(`INSERT INTO configuration_operations_next
|
|
11069
|
+
(mutation_id,request_hash,expected_revision,committed_revision,kind,target_worker_count,state,
|
|
11070
|
+
result_status,error_code,error_detail,drain_recovery_generation,
|
|
11071
|
+
last_drain_recovery_previous_generation,management_provider,offline_management,created_at,updated_at)
|
|
11072
|
+
SELECT mutation_id,request_hash,expected_revision,committed_revision,kind,target_worker_count,state,
|
|
11073
|
+
result_status,error_code,error_detail,drain_recovery_generation,
|
|
11074
|
+
last_drain_recovery_previous_generation,management_provider,offline_management,created_at,updated_at
|
|
11075
|
+
FROM configuration_operations`);
|
|
11076
|
+
db.run("DROP TABLE configuration_operations");
|
|
11077
|
+
db.run("ALTER TABLE configuration_operations_next RENAME TO configuration_operations");
|
|
11078
|
+
db.run(`CREATE TRIGGER configuration_operations_terminal_immutable_delete
|
|
11079
|
+
BEFORE DELETE ON configuration_operations
|
|
11080
|
+
WHEN OLD.state IN ('converged','degraded','superseded')
|
|
11081
|
+
BEGIN SELECT RAISE(ABORT,'terminal configuration operations are immutable'); END`);
|
|
11082
|
+
db.run(`CREATE TRIGGER configuration_operations_terminal_immutable_update
|
|
11083
|
+
BEFORE UPDATE ON configuration_operations
|
|
11084
|
+
WHEN OLD.state IN ('converged','degraded','superseded')
|
|
11085
|
+
BEGIN SELECT RAISE(ABORT,'terminal configuration operations are immutable'); END`);
|
|
11086
|
+
db.run(`CREATE UNIQUE INDEX configuration_operations_single_owner
|
|
11087
|
+
ON configuration_operations((state IN ('committed','publishing','draining')))
|
|
11088
|
+
WHERE state IN ('committed','publishing','draining')`);
|
|
11089
|
+
db.run(`CREATE TABLE configuration_publication_candidate_evidence (
|
|
11090
|
+
mutation_id TEXT NOT NULL,
|
|
11091
|
+
worker_slot INTEGER NOT NULL CHECK(worker_slot >= 0 AND worker_slot <= 9007199254740991),
|
|
11092
|
+
attempt_no INTEGER NOT NULL CHECK(attempt_no > 0 AND attempt_no <= 9007199254740991),
|
|
11093
|
+
exit_kind TEXT NOT NULL CHECK(exit_kind IN ('not_started','exited')),
|
|
11094
|
+
cleanup TEXT NOT NULL CHECK((exit_kind='not_started' AND cleanup='not_started') OR
|
|
11095
|
+
(exit_kind='exited' AND cleanup='released')),
|
|
11096
|
+
updated_at INTEGER NOT NULL CHECK(updated_at >= 0 AND updated_at <= 9007199254740991),
|
|
11097
|
+
PRIMARY KEY(mutation_id,worker_slot,attempt_no),
|
|
11098
|
+
FOREIGN KEY(mutation_id,worker_slot)
|
|
11099
|
+
REFERENCES configuration_operation_workers(mutation_id,worker_slot)
|
|
11100
|
+
) STRICT, WITHOUT ROWID`);
|
|
11101
|
+
db.run("CREATE TRIGGER publication_candidate_evidence_no_delete BEFORE DELETE ON configuration_publication_candidate_evidence BEGIN SELECT RAISE(ABORT,'publication candidate evidence is immutable'); END");
|
|
11102
|
+
db.run("CREATE TRIGGER publication_candidate_evidence_no_update BEFORE UPDATE ON configuration_publication_candidate_evidence BEGIN SELECT RAISE(ABORT,'publication candidate evidence is immutable'); END");
|
|
11103
|
+
db.run("CREATE TRIGGER publication_candidate_evidence_no_replace BEFORE INSERT ON configuration_publication_candidate_evidence WHEN EXISTS(SELECT 1 FROM configuration_publication_candidate_evidence WHERE mutation_id=NEW.mutation_id AND worker_slot=NEW.worker_slot AND attempt_no=NEW.attempt_no) BEGIN SELECT RAISE(ABORT,'publication candidate evidence is immutable'); END");
|
|
11104
|
+
db.run(`CREATE TABLE configuration_worker_launch_intents (
|
|
11105
|
+
worker_instance_id TEXT PRIMARY KEY CHECK(length(worker_instance_id)=36 AND
|
|
11106
|
+
substr(worker_instance_id,9,1)='-' AND substr(worker_instance_id,14,1)='-' AND
|
|
11107
|
+
substr(worker_instance_id,19,1)='-' AND substr(worker_instance_id,24,1)='-' AND
|
|
11108
|
+
replace(worker_instance_id,'-','') NOT GLOB '*[^0-9a-f]*'),
|
|
11109
|
+
master_generation TEXT NOT NULL CHECK(length(master_generation)=36),
|
|
11110
|
+
worker_slot INTEGER NOT NULL CHECK(worker_slot >= 0 AND worker_slot <= 9007199254740991),
|
|
11111
|
+
allocation_mutation_id TEXT CHECK(allocation_mutation_id IS NULL OR
|
|
11112
|
+
length(allocation_mutation_id) BETWEEN 1 AND 128),
|
|
11113
|
+
allocation_worker_slot INTEGER CHECK(allocation_worker_slot IS NULL OR
|
|
11114
|
+
(allocation_worker_slot >= 0 AND allocation_worker_slot <= 9007199254740991)),
|
|
11115
|
+
allocation_attempt_no INTEGER CHECK(allocation_attempt_no IS NULL OR
|
|
11116
|
+
(allocation_attempt_no > 0 AND allocation_attempt_no <= 9007199254740991)),
|
|
11117
|
+
guard_json TEXT NOT NULL CHECK(length(guard_json) > 0),
|
|
11118
|
+
registered_at INTEGER NOT NULL CHECK(registered_at >= 0 AND registered_at <= 9007199254740991),
|
|
11119
|
+
CHECK((allocation_mutation_id IS NULL AND allocation_worker_slot IS NULL AND allocation_attempt_no IS NULL) OR
|
|
11120
|
+
(allocation_mutation_id IS NOT NULL AND allocation_worker_slot IS NOT NULL AND
|
|
11121
|
+
allocation_attempt_no IS NOT NULL AND allocation_worker_slot=worker_slot)),
|
|
11122
|
+
FOREIGN KEY(allocation_mutation_id,allocation_worker_slot)
|
|
11123
|
+
REFERENCES configuration_operation_workers(mutation_id,worker_slot)
|
|
11124
|
+
) STRICT`);
|
|
11125
|
+
db.run("CREATE TRIGGER configuration_worker_launch_intents_no_delete BEFORE DELETE ON configuration_worker_launch_intents BEGIN SELECT RAISE(ABORT,'worker launch intent is immutable'); END");
|
|
11126
|
+
db.run("CREATE TRIGGER configuration_worker_launch_intents_no_update BEFORE UPDATE ON configuration_worker_launch_intents BEGIN SELECT RAISE(ABORT,'worker launch intent is immutable'); END");
|
|
11127
|
+
db.run(`CREATE TABLE configuration_worker_launch_facts (
|
|
11128
|
+
fact_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
11129
|
+
kind TEXT NOT NULL CHECK(kind IN ('reserved','not_started','admitted','exited','cleanup')),
|
|
11130
|
+
mutation_id TEXT,
|
|
11131
|
+
worker_slot INTEGER,
|
|
11132
|
+
attempt_no INTEGER,
|
|
11133
|
+
worker_instance_id TEXT,
|
|
11134
|
+
recorded_at INTEGER NOT NULL CHECK(recorded_at >= 0 AND recorded_at <= 9007199254740991),
|
|
11135
|
+
CHECK((mutation_id IS NULL AND worker_slot IS NULL AND attempt_no IS NULL) OR
|
|
11136
|
+
(mutation_id IS NOT NULL AND worker_slot IS NOT NULL AND attempt_no IS NOT NULL AND
|
|
11137
|
+
worker_slot >= 0 AND worker_slot <= 9007199254740991 AND
|
|
11138
|
+
attempt_no > 0 AND attempt_no <= 9007199254740991)),
|
|
11139
|
+
CHECK((kind='reserved' AND worker_instance_id IS NULL AND mutation_id IS NOT NULL) OR
|
|
11140
|
+
(kind='not_started' AND (worker_instance_id IS NOT NULL OR mutation_id IS NOT NULL)) OR
|
|
11141
|
+
(kind IN ('admitted','exited','cleanup') AND worker_instance_id IS NOT NULL)),
|
|
11142
|
+
FOREIGN KEY(mutation_id,worker_slot) REFERENCES configuration_operation_workers(mutation_id,worker_slot),
|
|
11143
|
+
FOREIGN KEY(worker_instance_id) REFERENCES configuration_worker_launch_intents(worker_instance_id)
|
|
11144
|
+
) STRICT`);
|
|
11145
|
+
db.run("CREATE UNIQUE INDEX configuration_worker_launch_facts_reserved ON configuration_worker_launch_facts(mutation_id,worker_slot,attempt_no) WHERE kind='reserved'");
|
|
11146
|
+
db.run("CREATE UNIQUE INDEX configuration_worker_launch_facts_not_started_allocation ON configuration_worker_launch_facts(mutation_id,worker_slot,attempt_no) WHERE kind='not_started' AND mutation_id IS NOT NULL");
|
|
11147
|
+
db.run("CREATE UNIQUE INDEX configuration_worker_launch_facts_not_started_instance ON configuration_worker_launch_facts(worker_instance_id) WHERE kind='not_started' AND worker_instance_id IS NOT NULL");
|
|
11148
|
+
db.run("CREATE UNIQUE INDEX configuration_worker_launch_facts_admitted ON configuration_worker_launch_facts(worker_instance_id) WHERE kind='admitted'");
|
|
11149
|
+
db.run("CREATE UNIQUE INDEX configuration_worker_launch_facts_exited ON configuration_worker_launch_facts(worker_instance_id) WHERE kind='exited'");
|
|
11150
|
+
db.run("CREATE UNIQUE INDEX configuration_worker_launch_facts_cleanup ON configuration_worker_launch_facts(worker_instance_id) WHERE kind='cleanup'");
|
|
11151
|
+
db.run("CREATE TRIGGER configuration_worker_launch_facts_no_delete BEFORE DELETE ON configuration_worker_launch_facts BEGIN SELECT RAISE(ABORT,'worker launch facts are immutable'); END");
|
|
11152
|
+
db.run("CREATE TRIGGER configuration_worker_launch_facts_no_update BEFORE UPDATE ON configuration_worker_launch_facts BEGIN SELECT RAISE(ABORT,'worker launch facts are immutable'); END");
|
|
11153
|
+
}
|
|
11154
|
+
};
|
|
11155
|
+
|
|
10320
11156
|
// src/config-storage/migrations/plan.ts
|
|
10321
|
-
var CONFIG_MIGRATIONS = [CONFIG_BASELINE, PUBLICATION_RETIREMENT_MIGRATION, UI_MENUS_MIGRATION, MANAGEMENT_PROTECTION_MIGRATION, SERVICE_REFERENCES_MIGRATION, WEBSOCKET_CONNECTIONS_MIGRATION, WEBSOCKET_MESSAGE_SIZE_MIGRATION];
|
|
11157
|
+
var CONFIG_MIGRATIONS = [CONFIG_BASELINE, PUBLICATION_RETIREMENT_MIGRATION, UI_MENUS_MIGRATION, MANAGEMENT_PROTECTION_MIGRATION, SERVICE_REFERENCES_MIGRATION, WEBSOCKET_CONNECTIONS_MIGRATION, WEBSOCKET_MESSAGE_SIZE_MIGRATION, PUBLICATION_TARGET_MIGRATION];
|
|
10322
11158
|
var CONFIG_SCHEMA_VERSION = CONFIG_MIGRATIONS.at(-1).version;
|
|
10323
11159
|
|
|
10324
11160
|
// src/config-storage/schema-fingerprint.ts
|
|
@@ -10480,15 +11316,19 @@ function convertServiceReferenceRevision(db, options) {
|
|
|
10480
11316
|
const result = commitTransaction(db, command, options, snapshot);
|
|
10481
11317
|
if (result.kind !== "committed")
|
|
10482
11318
|
throw new ConfigRepositoryError("migration_failed", `service reference revision commit failed (${result.kind})`);
|
|
10483
|
-
|
|
10484
|
-
markDraining(db, operationId, now);
|
|
10485
|
-
finalizePublication(db, operationId, { outcome: "converged", old_workers_exited: true }, now);
|
|
11319
|
+
finalizeOfflineOperation(db, operationId, now);
|
|
10486
11320
|
readRepositorySnapshot(db);
|
|
10487
11321
|
}
|
|
10488
11322
|
|
|
10489
11323
|
// src/config-storage/migrations/index.ts
|
|
10490
11324
|
function migrateConfigurationDatabase(db, plan = CONFIG_MIGRATIONS, options = {}) {
|
|
11325
|
+
if (db.inTransaction)
|
|
11326
|
+
throw new ConfigRepositoryError("migration_failed", "configuration migration must not nest in a transaction");
|
|
11327
|
+
db.run("PRAGMA foreign_keys = OFF");
|
|
10491
11328
|
try {
|
|
11329
|
+
if (db.query("PRAGMA foreign_keys").get()?.foreign_keys !== 0) {
|
|
11330
|
+
throw new ConfigRepositoryError("migration_failed", "configuration migration could not disable foreign keys");
|
|
11331
|
+
}
|
|
10492
11332
|
db.transaction(() => {
|
|
10493
11333
|
if (!plan.length || plan[0] !== CONFIG_MIGRATIONS[0] || plan.some((m, i) => i > 0 && m.version !== plan[i - 1].version + 1) || new Set(plan.map((m) => m.name)).size !== plan.length)
|
|
10494
11334
|
throw new ConfigRepositoryError("migration_failed", "invalid configuration migration plan");
|
|
@@ -10508,6 +11348,9 @@ function migrateConfigurationDatabase(db, plan = CONFIG_MIGRATIONS, options = {}
|
|
|
10508
11348
|
if (plan === CONFIG_MIGRATIONS && applied.length > 0 && applied.at(-1).version < 5) {
|
|
10509
11349
|
convertServiceReferenceRevision(db, options);
|
|
10510
11350
|
}
|
|
11351
|
+
if (plan.length > applied.length && db.query("PRAGMA foreign_key_check").all().length > 0) {
|
|
11352
|
+
throw new ConfigRepositoryError("schema_corrupt", "configuration migration left invalid references");
|
|
11353
|
+
}
|
|
10511
11354
|
}).immediate();
|
|
10512
11355
|
} catch (error) {
|
|
10513
11356
|
if (error instanceof ConfigRepositoryError)
|
|
@@ -10515,6 +11358,8 @@ function migrateConfigurationDatabase(db, plan = CONFIG_MIGRATIONS, options = {}
|
|
|
10515
11358
|
if (isSqliteBusyError(error))
|
|
10516
11359
|
throw repositoryFailure("configuration migration was blocked by SQLite", error);
|
|
10517
11360
|
throw new ConfigRepositoryError("migration_failed", "configuration migration failed", error);
|
|
11361
|
+
} finally {
|
|
11362
|
+
db.run("PRAGMA foreign_keys = ON");
|
|
10518
11363
|
}
|
|
10519
11364
|
}
|
|
10520
11365
|
|
|
@@ -10830,9 +11675,7 @@ class ConfigRepository {
|
|
|
10830
11675
|
const result = commitTransaction(this.db, command, this.options, snapshot, true);
|
|
10831
11676
|
if (result.kind !== "committed")
|
|
10832
11677
|
throw new ConfigRepositoryError("invalid_operation", `plugin catalog reconciliation cannot proceed (${result.kind})`);
|
|
10833
|
-
|
|
10834
|
-
markDraining(this.db, operationId, now);
|
|
10835
|
-
finalizePublication(this.db, operationId, { outcome: "converged", old_workers_exited: true }, now);
|
|
11678
|
+
finalizeOfflineOperation(this.db, operationId, now);
|
|
10836
11679
|
}));
|
|
10837
11680
|
this.snapshot = freezeSnapshot(readRepositorySnapshot(this.db));
|
|
10838
11681
|
}
|
|
@@ -10883,11 +11726,9 @@ class ConfigRepository {
|
|
|
10883
11726
|
};
|
|
10884
11727
|
const result = commitTransaction(this.db, offlinePrepared, this.options, snapshot, true);
|
|
10885
11728
|
if (result.kind !== "committed") {
|
|
10886
|
-
throw new ConfigRepositoryError(
|
|
11729
|
+
throw new ConfigRepositoryError("invalid_operation", `offline management change cannot proceed (${result.kind})`);
|
|
10887
11730
|
}
|
|
10888
|
-
|
|
10889
|
-
markDraining(this.db, operationId, now);
|
|
10890
|
-
finalizePublication(this.db, operationId, { outcome: "converged", old_workers_exited: true }, now);
|
|
11731
|
+
finalizeOfflineOperation(this.db, operationId, now);
|
|
10891
11732
|
}));
|
|
10892
11733
|
return this.getControlProjection();
|
|
10893
11734
|
}
|
|
@@ -10913,7 +11754,25 @@ class ConfigRepository {
|
|
|
10913
11754
|
return runRepositoryAction(() => consumeControllerClaimCapability(capability, () => this.mutationTransaction(() => this.supervision.claim(controllerId, updatedAt))));
|
|
10914
11755
|
}
|
|
10915
11756
|
getActivePublication() {
|
|
10916
|
-
return runRepositoryAction(() => withConsistentRead(this.db, () => readActivePublication(this.db
|
|
11757
|
+
return runRepositoryAction(() => withConsistentRead(this.db, () => readActivePublication(this.db)));
|
|
11758
|
+
}
|
|
11759
|
+
claimPublicationTarget(pluginCatalogHash, updatedAt) {
|
|
11760
|
+
return runRepositoryAction(() => this.publicationTransaction(null, () => claimPublicationTarget(this.db, this.snapshot, pluginCatalogHash, updatedAt)));
|
|
11761
|
+
}
|
|
11762
|
+
requestPublicationCancellation(mutationId, committedRevision, updatedAt) {
|
|
11763
|
+
return runRepositoryAction(() => this.publicationTransaction(mutationId, () => requestPublicationCancellation(this.db, mutationId, committedRevision, updatedAt)));
|
|
11764
|
+
}
|
|
11765
|
+
enterPublicationPrepare(mutationId, committedRevision, updatedAt) {
|
|
11766
|
+
return runRepositoryAction(() => this.publicationTransaction(mutationId, () => enterPublicationPrepare(this.db, mutationId, committedRevision, updatedAt)));
|
|
11767
|
+
}
|
|
11768
|
+
recordPublicationCandidateExit(mutationId, committedRevision, workerSlot, attemptNo, evidence, updatedAt) {
|
|
11769
|
+
return runRepositoryAction(() => this.mutationTransaction(() => recordPublicationCandidateExit(this.db, mutationId, committedRevision, workerSlot, attemptNo, evidence, updatedAt)));
|
|
11770
|
+
}
|
|
11771
|
+
confirmPublicationCandidateExited(mutationId, committedRevision, updatedAt) {
|
|
11772
|
+
return runRepositoryAction(() => this.mutationTransaction(() => confirmPublicationCandidateExited(this.db, mutationId, committedRevision, updatedAt)));
|
|
11773
|
+
}
|
|
11774
|
+
getOutstandingPublicationCandidates() {
|
|
11775
|
+
return runRepositoryAction(() => withConsistentRead(this.db, () => readOutstandingPublicationCandidates(this.db)));
|
|
10917
11776
|
}
|
|
10918
11777
|
commit(command) {
|
|
10919
11778
|
return this.commitPrepared(prepareCommitCommand(command, this.options.compileOptions));
|
|
@@ -10961,10 +11820,10 @@ class ConfigRepository {
|
|
|
10961
11820
|
}));
|
|
10962
11821
|
}
|
|
10963
11822
|
getCurrentRecovery() {
|
|
10964
|
-
return runRepositoryAction(() => withConsistentRead(this.db, () =>
|
|
10965
|
-
|
|
10966
|
-
|
|
10967
|
-
|
|
11823
|
+
return runRepositoryAction(() => withConsistentRead(this.db, () => readCurrentRecovery(this.db)));
|
|
11824
|
+
}
|
|
11825
|
+
getPublicationRecoveryBarrier(excludeRecoveryId = null) {
|
|
11826
|
+
return runRepositoryAction(() => withConsistentRead(this.db, () => readPublicationRecoveryBarrier(this.db, excludeRecoveryId)));
|
|
10968
11827
|
}
|
|
10969
11828
|
getLatestRecovery(targetRevision) {
|
|
10970
11829
|
return runRepositoryAction(() => withConsistentRead(this.db, () => {
|
|
@@ -11046,6 +11905,30 @@ class ConfigRepository {
|
|
|
11046
11905
|
return operation;
|
|
11047
11906
|
}));
|
|
11048
11907
|
}
|
|
11908
|
+
registerWorkerLaunch(identity, guard, allocation, updatedAt) {
|
|
11909
|
+
return runRepositoryAction(() => this.mutationTransaction(() => registerWorkerLaunch(this.db, identity, guard, allocation, updatedAt)));
|
|
11910
|
+
}
|
|
11911
|
+
fenceWorkerLaunchNotStarted(mutationId, workerSlot, attemptNo, updatedAt) {
|
|
11912
|
+
return runRepositoryAction(() => this.mutationTransaction(() => fenceWorkerLaunchNotStarted(this.db, mutationId, workerSlot, attemptNo, updatedAt)));
|
|
11913
|
+
}
|
|
11914
|
+
recordWorkerLaunchAdmitted(workerInstanceId, updatedAt) {
|
|
11915
|
+
return runRepositoryAction(() => this.mutationTransaction(() => recordWorkerLaunchAdmitted(this.db, workerInstanceId, updatedAt)));
|
|
11916
|
+
}
|
|
11917
|
+
recordWorkerLaunchExit(workerInstanceId, evidence, updatedAt) {
|
|
11918
|
+
return runRepositoryAction(() => this.mutationTransaction(() => recordWorkerLaunchExit(this.db, workerInstanceId, evidence, updatedAt)));
|
|
11919
|
+
}
|
|
11920
|
+
getWorkerLaunch(workerInstanceId) {
|
|
11921
|
+
return runRepositoryAction(() => withConsistentRead(this.db, () => readWorkerLaunch(this.db, workerInstanceId)));
|
|
11922
|
+
}
|
|
11923
|
+
getWorkerLaunchAllocationFacts(allocation) {
|
|
11924
|
+
return runRepositoryAction(() => withConsistentRead(this.db, () => readWorkerLaunchAllocationFacts(this.db, allocation)));
|
|
11925
|
+
}
|
|
11926
|
+
getUnsettledWorkerLaunches() {
|
|
11927
|
+
return runRepositoryAction(() => withConsistentRead(this.db, () => readUnsettledWorkerLaunches(this.db)));
|
|
11928
|
+
}
|
|
11929
|
+
getWorkerLaunchInventory() {
|
|
11930
|
+
return runRepositoryAction(() => withConsistentRead(this.db, () => readWorkerLaunchInventory(this.db)));
|
|
11931
|
+
}
|
|
11049
11932
|
recordWorkerResult(mutationId, workerSlot, result, updatedAt) {
|
|
11050
11933
|
return runRepositoryAction(() => this.publicationTransaction(mutationId, () => {
|
|
11051
11934
|
const worker = recordWorkerResult(this.db, mutationId, workerSlot, result, updatedAt);
|
|
@@ -11053,12 +11936,17 @@ class ConfigRepository {
|
|
|
11053
11936
|
}));
|
|
11054
11937
|
}
|
|
11055
11938
|
finalizePublication(mutationId, outcome, updatedAt) {
|
|
11056
|
-
return runRepositoryAction(() => this.
|
|
11939
|
+
return runRepositoryAction(() => this.mutationTransaction(() => {
|
|
11057
11940
|
const before = getOperation(this.db, mutationId);
|
|
11058
11941
|
if (before === null)
|
|
11059
11942
|
throw new ConfigRepositoryError("invalid_operation", "configuration operation was not found");
|
|
11943
|
+
if (before.state !== "converged" && before.state !== "degraded" && before.state !== "superseded") {
|
|
11944
|
+
this.requirePublicationOwner(mutationId);
|
|
11945
|
+
if (outcome.outcome === "degraded")
|
|
11946
|
+
assertPublicationLaunchDebtSettled(this.db, mutationId);
|
|
11947
|
+
}
|
|
11060
11948
|
const operation = finalizePublication(this.db, mutationId, outcome, updatedAt);
|
|
11061
|
-
if (before.state !== "converged" && before.state !== "degraded" && outcome.outcome === "degraded" && (outcome.error_code === "replacement_convergence_failed" || outcome.error_code === "control_readiness_failed")) {
|
|
11949
|
+
if (before.state !== "converged" && before.state !== "degraded" && before.state !== "superseded" && outcome.outcome === "degraded" && (outcome.error_code === "replacement_convergence_failed" || outcome.error_code === "control_readiness_failed")) {
|
|
11062
11950
|
switch (outcome.recovery_disposition) {
|
|
11063
11951
|
case "retryable":
|
|
11064
11952
|
createAutomaticRecovery(this.db, randomUUID3(), mutationId, operation.committed_revision, updatedAt);
|
|
@@ -11154,10 +12042,19 @@ class ConfigRepository {
|
|
|
11154
12042
|
}
|
|
11155
12043
|
publicationTransaction(mutationId, action) {
|
|
11156
12044
|
return this.mutationTransaction(() => {
|
|
11157
|
-
|
|
11158
|
-
|
|
12045
|
+
if (mutationId !== null)
|
|
12046
|
+
this.requirePublicationOwner(mutationId);
|
|
11159
12047
|
const result = action();
|
|
11160
|
-
|
|
12048
|
+
if (mutationId !== null) {
|
|
12049
|
+
const operation = getOperation(this.db, mutationId);
|
|
12050
|
+
if (operation === null)
|
|
12051
|
+
throw new ConfigRepositoryError("repository_failure", "publication operation disappeared");
|
|
12052
|
+
if (operation.state === "committed" || operation.state === "publishing" || operation.state === "draining") {
|
|
12053
|
+
readActivePublication(this.db);
|
|
12054
|
+
}
|
|
12055
|
+
} else if (readPublicationOwner(this.db) !== null) {
|
|
12056
|
+
readActivePublication(this.db);
|
|
12057
|
+
}
|
|
11161
12058
|
return result;
|
|
11162
12059
|
});
|
|
11163
12060
|
}
|
|
@@ -11169,12 +12066,12 @@ class ConfigRepository {
|
|
|
11169
12066
|
return action();
|
|
11170
12067
|
}).immediate();
|
|
11171
12068
|
}
|
|
11172
|
-
|
|
11173
|
-
const
|
|
11174
|
-
if (
|
|
11175
|
-
throw new ConfigRepositoryError("invalid_operation", "only the
|
|
12069
|
+
requirePublicationOwner(mutationId) {
|
|
12070
|
+
const owner = readPublicationOwner(this.db);
|
|
12071
|
+
if (owner === null || owner.operation.mutation_id !== mutationId) {
|
|
12072
|
+
throw new ConfigRepositoryError("invalid_operation", "only the current publication owner may publish");
|
|
11176
12073
|
}
|
|
11177
|
-
|
|
12074
|
+
readActivePublication(this.db);
|
|
11178
12075
|
}
|
|
11179
12076
|
}
|
|
11180
12077
|
|
|
@@ -11192,11 +12089,26 @@ var STORAGE_METHODS = [
|
|
|
11192
12089
|
"getServingSnapshot",
|
|
11193
12090
|
"claimController",
|
|
11194
12091
|
"getActivePublication",
|
|
12092
|
+
"claimPublicationTarget",
|
|
12093
|
+
"requestPublicationCancellation",
|
|
12094
|
+
"enterPublicationPrepare",
|
|
12095
|
+
"recordPublicationCandidateExit",
|
|
12096
|
+
"confirmPublicationCandidateExited",
|
|
12097
|
+
"getOutstandingPublicationCandidates",
|
|
12098
|
+
"registerWorkerLaunch",
|
|
12099
|
+
"fenceWorkerLaunchNotStarted",
|
|
12100
|
+
"recordWorkerLaunchAdmitted",
|
|
12101
|
+
"recordWorkerLaunchExit",
|
|
12102
|
+
"getWorkerLaunch",
|
|
12103
|
+
"getWorkerLaunchAllocationFacts",
|
|
12104
|
+
"getUnsettledWorkerLaunches",
|
|
12105
|
+
"getWorkerLaunchInventory",
|
|
11195
12106
|
"getOperation",
|
|
11196
12107
|
"getOperationState",
|
|
11197
12108
|
"getCurrentOperationState",
|
|
11198
12109
|
"getRecovery",
|
|
11199
12110
|
"getCurrentRecovery",
|
|
12111
|
+
"getPublicationRecoveryBarrier",
|
|
11200
12112
|
"getLatestRecovery",
|
|
11201
12113
|
"createManualRecovery",
|
|
11202
12114
|
"claimRecoveryAttempt",
|
|
@@ -11234,11 +12146,17 @@ var READ_METHODS = new Set([
|
|
|
11234
12146
|
"getPublicationServingSet",
|
|
11235
12147
|
"getServingSnapshot",
|
|
11236
12148
|
"getActivePublication",
|
|
12149
|
+
"getOutstandingPublicationCandidates",
|
|
12150
|
+
"getWorkerLaunch",
|
|
12151
|
+
"getWorkerLaunchAllocationFacts",
|
|
12152
|
+
"getUnsettledWorkerLaunches",
|
|
12153
|
+
"getWorkerLaunchInventory",
|
|
11237
12154
|
"getOperation",
|
|
11238
12155
|
"getOperationState",
|
|
11239
12156
|
"getCurrentOperationState",
|
|
11240
12157
|
"getRecovery",
|
|
11241
12158
|
"getCurrentRecovery",
|
|
12159
|
+
"getPublicationRecoveryBarrier",
|
|
11242
12160
|
"getLatestRecovery",
|
|
11243
12161
|
"verify",
|
|
11244
12162
|
"getRetirementDescriptorCleanupState",
|