@sixb/core 0.2.0 → 0.2.1
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/actions/index.js +11 -11
- package/dist/agents/index.js +12 -12
- package/dist/artifacts/publish/index.js +5 -5
- package/dist/bootstrap/index.js +18 -18
- package/dist/{chunk-fntqb7qy.js → chunk-57g0215c.js} +1 -1
- package/dist/{chunk-fb3m4sa1.js → chunk-8yzhjawq.js} +1 -1
- package/dist/{chunk-xj97s5js.js → chunk-aqyjb86c.js} +2 -2
- package/dist/{chunk-f2w6328x.js → chunk-ax10ft8d.js} +4 -4
- package/dist/{chunk-c78jjzhy.js → chunk-b7a97n8b.js} +1 -1
- package/dist/{chunk-e99kp9jh.js → chunk-cb21tx14.js} +6 -6
- package/dist/{chunk-e99kp9jh.js.map → chunk-cb21tx14.js.map} +4 -4
- package/dist/{chunk-peggaard.js → chunk-e6xgz4h4.js} +20 -2
- package/dist/{chunk-peggaard.js.map → chunk-e6xgz4h4.js.map} +5 -3
- package/dist/{chunk-ekkpzcka.js → chunk-epyfm23v.js} +34 -7
- package/dist/chunk-epyfm23v.js.map +11 -0
- package/dist/{chunk-ztf5vtmp.js → chunk-h05rg3bx.js} +39 -8
- package/dist/chunk-h05rg3bx.js.map +12 -0
- package/dist/{chunk-d3t26vah.js → chunk-j1ny5fwh.js} +35 -11
- package/dist/chunk-j1ny5fwh.js.map +15 -0
- package/dist/{chunk-855n80en.js → chunk-jjmggm9a.js} +1 -1
- package/dist/{chunk-semf1yqn.js → chunk-ks87m383.js} +11 -11
- package/dist/{chunk-vkweppkw.js → chunk-nqnfz3jg.js} +2 -2
- package/dist/{chunk-hjy3dsws.js → chunk-ratj7t3t.js} +3 -3
- package/dist/{chunk-fdkpkkpw.js → chunk-rjeeyssy.js} +2 -2
- package/dist/{chunk-9mab3dvg.js → chunk-s038wa5v.js} +9 -1
- package/dist/{chunk-9mab3dvg.js.map → chunk-s038wa5v.js.map} +3 -3
- package/dist/{chunk-n54k068r.js → chunk-t5daew4g.js} +3 -3
- package/dist/{chunk-8hvfs0fr.js → chunk-t9xyr7y9.js} +2 -2
- package/dist/{chunk-8dcfj58k.js → chunk-tvbmh7tj.js} +1 -1
- package/dist/{chunk-he7g39e5.js → chunk-w53trr0c.js} +4 -4
- package/dist/{chunk-qya541bk.js → chunk-z3evap21.js} +14 -12
- package/dist/{chunk-qya541bk.js.map → chunk-z3evap21.js.map} +3 -3
- package/dist/datasets/execution.d.ts.map +1 -1
- package/dist/events/index.js +1 -1
- package/dist/events/selectors/index.js +1 -1
- package/dist/events/selectors/predicate.d.ts.map +1 -1
- package/dist/events/types/datasets.d.ts +6 -0
- package/dist/events/types/datasets.d.ts.map +1 -1
- package/dist/execution/agent.js +11 -11
- package/dist/execution/primitive.js +11 -11
- package/dist/execution/request.js +11 -11
- package/dist/index.js +21 -21
- package/dist/lake-storage/in-memory.d.ts.map +1 -1
- package/dist/lake-storage/index.d.ts +2 -2
- package/dist/lake-storage/index.d.ts.map +1 -1
- package/dist/lake-storage/index.js +6 -2
- package/dist/lake-storage/index.js.map +1 -1
- package/dist/lake-storage/source-ordering.d.ts +7 -0
- package/dist/lake-storage/source-ordering.d.ts.map +1 -1
- package/dist/lake-storage/types.d.ts +18 -0
- package/dist/lake-storage/types.d.ts.map +1 -1
- package/dist/lake-storage/version-inputs.d.ts +11 -3
- package/dist/lake-storage/version-inputs.d.ts.map +1 -1
- package/dist/materializer/index.js +3 -3
- package/dist/models/execution/index.js +3 -3
- package/dist/objects/index.js +11 -11
- package/dist/objects/query/index.js +3 -3
- package/dist/pipelines/index.js +6 -6
- package/dist/pipelines/run-dispatch.d.ts +2 -0
- package/dist/pipelines/run-dispatch.d.ts.map +1 -1
- package/dist/projections/internal.js +2 -2
- package/dist/runtime/internal.js +7 -7
- package/dist/schedules/index.js +2 -2
- package/dist/shares/internal.js +2 -2
- package/dist/storage/index.js +2 -2
- package/dist/storage/internal.d.ts +2 -0
- package/dist/storage/internal.d.ts.map +1 -1
- package/dist/storage/internal.js +6 -2
- package/dist/storage/internal.js.map +1 -1
- package/dist/storage/pipeline-runs/in-memory.d.ts.map +1 -1
- package/dist/storage/pipeline-runs/transitions.d.ts +7 -0
- package/dist/storage/pipeline-runs/transitions.d.ts.map +1 -0
- package/dist/storage/sync-runs/in-memory.d.ts.map +1 -1
- package/dist/storage/sync-runs/transitions.d.ts +7 -0
- package/dist/storage/sync-runs/transitions.d.ts.map +1 -0
- package/dist/syncs/index.js +6 -6
- package/dist/syncs/run-dispatch.d.ts +2 -0
- package/dist/syncs/run-dispatch.d.ts.map +1 -1
- package/dist/testing/dataset-sequence-contract.d.ts.map +1 -1
- package/dist/testing/index.js +170 -33
- package/dist/testing/index.js.map +5 -5
- package/dist/testing/lake-changes-contract.d.ts.map +1 -1
- package/dist/testing/lake-storage-contract.d.ts.map +1 -1
- package/dist/webhooks/internal.js +2 -2
- package/dist/workers/index.d.ts +1 -0
- package/dist/workers/index.d.ts.map +1 -1
- package/dist/workers/index.js +12 -2
- package/dist/workers/index.js.map +5 -4
- package/dist/workers/unstarted-run.d.ts +10 -0
- package/dist/workers/unstarted-run.d.ts.map +1 -0
- package/dist/workflows/index.js +15 -15
- package/package.json +1 -1
- package/src/datasets/execution.ts +2 -0
- package/src/events/selectors/predicate.ts +15 -0
- package/src/events/types/datasets.ts +6 -0
- package/src/lake-storage/in-memory.ts +30 -20
- package/src/lake-storage/index.ts +2 -1
- package/src/lake-storage/source-ordering.ts +31 -4
- package/src/lake-storage/types.ts +18 -0
- package/src/lake-storage/version-inputs.ts +21 -5
- package/src/pipelines/run-dispatch.ts +53 -6
- package/src/storage/internal.ts +2 -0
- package/src/storage/pipeline-runs/in-memory.ts +2 -5
- package/src/storage/pipeline-runs/transitions.ts +14 -0
- package/src/storage/sync-runs/in-memory.ts +2 -5
- package/src/storage/sync-runs/transitions.ts +11 -0
- package/src/syncs/run-dispatch.ts +68 -13
- package/src/testing/dataset-sequence-contract.ts +81 -0
- package/src/testing/lake-changes-contract.ts +2 -1
- package/src/testing/lake-storage-contract.ts +112 -0
- package/src/workers/index.ts +1 -0
- package/src/workers/unstarted-run.ts +18 -0
- package/dist/chunk-d3t26vah.js.map +0 -15
- package/dist/chunk-ekkpzcka.js.map +0 -11
- package/dist/chunk-ztf5vtmp.js.map +0 -12
- /package/dist/{chunk-fntqb7qy.js.map → chunk-57g0215c.js.map} +0 -0
- /package/dist/{chunk-fb3m4sa1.js.map → chunk-8yzhjawq.js.map} +0 -0
- /package/dist/{chunk-xj97s5js.js.map → chunk-aqyjb86c.js.map} +0 -0
- /package/dist/{chunk-f2w6328x.js.map → chunk-ax10ft8d.js.map} +0 -0
- /package/dist/{chunk-c78jjzhy.js.map → chunk-b7a97n8b.js.map} +0 -0
- /package/dist/{chunk-855n80en.js.map → chunk-jjmggm9a.js.map} +0 -0
- /package/dist/{chunk-semf1yqn.js.map → chunk-ks87m383.js.map} +0 -0
- /package/dist/{chunk-vkweppkw.js.map → chunk-nqnfz3jg.js.map} +0 -0
- /package/dist/{chunk-hjy3dsws.js.map → chunk-ratj7t3t.js.map} +0 -0
- /package/dist/{chunk-fdkpkkpw.js.map → chunk-rjeeyssy.js.map} +0 -0
- /package/dist/{chunk-n54k068r.js.map → chunk-t5daew4g.js.map} +0 -0
- /package/dist/{chunk-8hvfs0fr.js.map → chunk-t9xyr7y9.js.map} +0 -0
- /package/dist/{chunk-8dcfj58k.js.map → chunk-tvbmh7tj.js.map} +0 -0
- /package/dist/{chunk-he7g39e5.js.map → chunk-w53trr0c.js.map} +0 -0
|
@@ -50,6 +50,8 @@ interface DispatchPipelineRunInput extends PipelineRunRequestOptions {
|
|
|
50
50
|
readonly metadata?: Readonly<Record<string, string>>
|
|
51
51
|
readonly createExecution: (executionId: string, runId: string) => Promise<CreateExecutionInput>
|
|
52
52
|
readonly validateExistingRun?: (run: PipelineRunRecord, storage: Storage) => Promise<void>
|
|
53
|
+
/** Return a run of this Pipeline that has not started yet instead of queueing another one. */
|
|
54
|
+
readonly joinQueuedRun?: boolean
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
type PersistedPipelineRun =
|
|
@@ -57,9 +59,10 @@ type PersistedPipelineRun =
|
|
|
57
59
|
| {
|
|
58
60
|
readonly publish: true
|
|
59
61
|
readonly run: PipelineRunRecord
|
|
60
|
-
readonly execution: CreateExecutionInput
|
|
61
62
|
readonly queuedAt: Date
|
|
62
63
|
readonly created: boolean
|
|
64
|
+
/** Defaults to the run id. A trigger that joins a run publishes its own job for it. */
|
|
65
|
+
readonly jobId?: string
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
/** Core-owned durable dispatch boundary used by automatic Pipeline triggers. */
|
|
@@ -81,6 +84,7 @@ export class PipelineRunDispatcher implements PipelineRunDispatchPort {
|
|
|
81
84
|
metadata: input.metadata,
|
|
82
85
|
validateExistingRun: (run, storage) =>
|
|
83
86
|
assertAutomaticExecutionIdentity(storage, this.dependencies.id, input, run),
|
|
87
|
+
joinQueuedRun: true,
|
|
84
88
|
createExecution: async (executionId, runId) =>
|
|
85
89
|
createPrimitiveExecutionRecord({
|
|
86
90
|
id: executionId,
|
|
@@ -130,6 +134,19 @@ async function persistPipelineRun(
|
|
|
130
134
|
return { publish: false, run: raced }
|
|
131
135
|
}
|
|
132
136
|
|
|
137
|
+
if (input.joinQueuedRun) {
|
|
138
|
+
const waiting = await findQueuedPipelineRun(transactionalRuns, input)
|
|
139
|
+
if (waiting) {
|
|
140
|
+
return {
|
|
141
|
+
publish: true,
|
|
142
|
+
run: waiting,
|
|
143
|
+
queuedAt: waiting.queuedAt,
|
|
144
|
+
created: false,
|
|
145
|
+
jobId: joinJobId(waiting, runId),
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
133
150
|
await tx.executions.create(execution)
|
|
134
151
|
const run = await transactionalRuns.queue({
|
|
135
152
|
projectId: input.projectId,
|
|
@@ -138,7 +155,7 @@ async function persistPipelineRun(
|
|
|
138
155
|
pipelineId: input.pipeline.id,
|
|
139
156
|
queuedAt,
|
|
140
157
|
})
|
|
141
|
-
return { publish: true, run,
|
|
158
|
+
return { publish: true, run, queuedAt, created: true }
|
|
142
159
|
},
|
|
143
160
|
{ isolation: "serializable" }
|
|
144
161
|
)
|
|
@@ -152,6 +169,34 @@ async function persistPipelineRun(
|
|
|
152
169
|
}
|
|
153
170
|
}
|
|
154
171
|
|
|
172
|
+
/**
|
|
173
|
+
* A run that has not started reads each input's latest version when its steps start, so it already
|
|
174
|
+
* covers a trigger that arrives now. The oldest one starts first.
|
|
175
|
+
*/
|
|
176
|
+
async function findQueuedPipelineRun(
|
|
177
|
+
pipelineRuns: NonNullable<Storage["pipelineRuns"]>,
|
|
178
|
+
input: Pick<DispatchPipelineRunInput, "projectId" | "pipeline">
|
|
179
|
+
): Promise<PipelineRunRecord | undefined> {
|
|
180
|
+
const { runs } = await pipelineRuns.list({
|
|
181
|
+
projectId: input.projectId,
|
|
182
|
+
pipelineId: input.pipeline.id,
|
|
183
|
+
statuses: ["queued"],
|
|
184
|
+
order: "asc",
|
|
185
|
+
limit: 1,
|
|
186
|
+
})
|
|
187
|
+
return runs[0]
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* The job a trigger publishes for the run it joins. The run's own job may be gone (a provider
|
|
192
|
+
* keeps a settled job id, and ignores a new job under it), so each joining trigger brings a job
|
|
193
|
+
* that can start the run; once it has started, the others complete without doing anything. The id
|
|
194
|
+
* derives from the trigger's run id, so a redelivered trigger publishes the same job.
|
|
195
|
+
*/
|
|
196
|
+
function joinJobId(waiting: PipelineRunRecord, triggerRunId: string): string {
|
|
197
|
+
return `${waiting.id}:join:${triggerRunId}`
|
|
198
|
+
}
|
|
199
|
+
|
|
155
200
|
async function reusePipelineRun(
|
|
156
201
|
input: DispatchPipelineRunInput,
|
|
157
202
|
existing: PipelineRunRecord
|
|
@@ -165,7 +210,7 @@ async function reusePipelineRun(
|
|
|
165
210
|
})
|
|
166
211
|
if (!execution)
|
|
167
212
|
throw new PipelineRunError(`[Sixb] Execution '${existing.executionId}' was not found.`)
|
|
168
|
-
return { publish: true, run: existing,
|
|
213
|
+
return { publish: true, run: existing, queuedAt: existing.queuedAt, created: false }
|
|
169
214
|
}
|
|
170
215
|
if (
|
|
171
216
|
existing.status !== "failed" ||
|
|
@@ -193,26 +238,28 @@ async function reusePipelineRun(
|
|
|
193
238
|
pipelineId: existing.pipelineId,
|
|
194
239
|
queuedAt,
|
|
195
240
|
})
|
|
196
|
-
return { publish: true, run,
|
|
241
|
+
return { publish: true, run, queuedAt, created: false }
|
|
197
242
|
}
|
|
198
243
|
|
|
199
244
|
async function publishPipelineRun(
|
|
200
245
|
input: DispatchPipelineRunInput,
|
|
201
246
|
persisted: Extract<PersistedPipelineRun, { readonly publish: true }>
|
|
202
247
|
): Promise<PipelineRunRequestResult> {
|
|
248
|
+
const jobId = persisted.jobId ?? persisted.run.id
|
|
249
|
+
|
|
203
250
|
try {
|
|
204
251
|
const [job] = await input.queue.enqueue({
|
|
205
252
|
projectId: input.projectId,
|
|
206
253
|
jobs: [
|
|
207
254
|
{
|
|
208
|
-
id:
|
|
255
|
+
id: jobId,
|
|
209
256
|
type: "pipeline.run.requested",
|
|
210
257
|
payload: { runId: persisted.run.id },
|
|
211
258
|
...(input.metadata === undefined ? {} : { metadata: input.metadata }),
|
|
212
259
|
},
|
|
213
260
|
],
|
|
214
261
|
})
|
|
215
|
-
if (!job || job.id !==
|
|
262
|
+
if (!job || job.id !== jobId) {
|
|
216
263
|
throw new PipelineRunError(
|
|
217
264
|
`[Sixb] Queue did not acknowledge Pipeline run '${persisted.run.id}'.`
|
|
218
265
|
)
|
package/src/storage/internal.ts
CHANGED
|
@@ -44,8 +44,10 @@ export {
|
|
|
44
44
|
export { parseFileDownloadGrantRow } from "./file-download-grants/record"
|
|
45
45
|
export { createFileUploadId, createUploadExpiresAt } from "./file-upload-sessions/utils"
|
|
46
46
|
export { canRequeuePipelineRunAfterEnqueueFailure } from "./pipeline-runs/idempotency"
|
|
47
|
+
export { canFinishPipelineRun } from "./pipeline-runs/transitions"
|
|
47
48
|
export { projectionRunObjectTypesVisible, zeroProjectionRunProgress } from "./projection-runs/types"
|
|
48
49
|
export { canRequeueSyncRunAfterEnqueueFailure } from "./sync-runs/idempotency"
|
|
50
|
+
export { canFinishSyncRun } from "./sync-runs/transitions"
|
|
49
51
|
export {
|
|
50
52
|
assertTransactionActive,
|
|
51
53
|
createTransactionStorageProxy,
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import { PipelineRunError } from "./errors"
|
|
15
15
|
import { canRequeuePipelineRunAfterEnqueueFailure } from "./idempotency"
|
|
16
16
|
import { assertPipelineRunExecution } from "./provider"
|
|
17
|
+
import { canFinishPipelineRun } from "./transitions"
|
|
17
18
|
import type {
|
|
18
19
|
FinishPipelineRunInput,
|
|
19
20
|
FinishPipelineStepRunInput,
|
|
@@ -152,11 +153,7 @@ export class InMemoryPipelineRunStorage implements PipelineRunStorage {
|
|
|
152
153
|
|
|
153
154
|
async finish(input: FinishPipelineRunInput): Promise<PipelineRunRecord> {
|
|
154
155
|
const existing = this.requireExistingPipelineRun(input.projectId, input.id)
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
(enqueueFailure && existing.status !== "queued") ||
|
|
158
|
-
(!enqueueFailure && existing.status !== "running")
|
|
159
|
-
) {
|
|
156
|
+
if (!canFinishPipelineRun(existing.status, input)) {
|
|
160
157
|
throw new PipelineRunError(
|
|
161
158
|
`[Sixb] Pipeline run '${input.id}' cannot finish from status '${existing.status}'.`
|
|
162
159
|
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FinishPipelineRunInput, PipelineRunStatus } from "./types"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A run finishes from `running`. One that never started can only fail: its job could not be
|
|
5
|
+
* published (`queue.enqueue_failed`), or the job ended before starting it.
|
|
6
|
+
*/
|
|
7
|
+
export function canFinishPipelineRun(
|
|
8
|
+
status: PipelineRunStatus,
|
|
9
|
+
input: FinishPipelineRunInput
|
|
10
|
+
): boolean {
|
|
11
|
+
if (input.status !== "failed") return status === "running"
|
|
12
|
+
if (input.error.code === "queue.enqueue_failed") return status === "queued"
|
|
13
|
+
return status === "queued" || status === "running"
|
|
14
|
+
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { SyncRunError } from "./errors"
|
|
14
14
|
import { canRequeueSyncRunAfterEnqueueFailure } from "./idempotency"
|
|
15
15
|
import { assertSyncRunExecution } from "./provider"
|
|
16
|
+
import { canFinishSyncRun } from "./transitions"
|
|
16
17
|
import type {
|
|
17
18
|
FinishSyncRunInput,
|
|
18
19
|
ListLatestSyncRunsInput,
|
|
@@ -157,11 +158,7 @@ export class InMemorySyncRunStorage implements SyncRunStorage {
|
|
|
157
158
|
)
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
|
|
161
|
-
if (
|
|
162
|
-
(enqueueFailure && existing.status !== "queued") ||
|
|
163
|
-
(!enqueueFailure && existing.status !== "running")
|
|
164
|
-
) {
|
|
161
|
+
if (!canFinishSyncRun(existing.status, input)) {
|
|
165
162
|
throw new SyncRunError(
|
|
166
163
|
`[Sixb] Sync run '${input.id}' cannot finish from status '${existing.status}'.`
|
|
167
164
|
)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FinishSyncRunInput, SyncRunStatus } from "./types"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A run finishes from `running`. One that never started can only fail: its job could not be
|
|
5
|
+
* published (`queue.enqueue_failed`), or the job ended before starting it.
|
|
6
|
+
*/
|
|
7
|
+
export function canFinishSyncRun(status: SyncRunStatus, input: FinishSyncRunInput): boolean {
|
|
8
|
+
if (input.status !== "failed") return status === "running"
|
|
9
|
+
if (input.error.code === "queue.enqueue_failed") return status === "queued"
|
|
10
|
+
return status === "queued" || status === "running"
|
|
11
|
+
}
|
|
@@ -42,6 +42,8 @@ interface DispatchSyncRunInput extends SyncRunRequestOptions {
|
|
|
42
42
|
readonly metadata?: Readonly<Record<string, string>>
|
|
43
43
|
readonly createExecution: (executionId: string, runId: string) => Promise<CreateExecutionInput>
|
|
44
44
|
readonly validateExistingRun?: (run: SyncRunRecord, storage: Storage) => Promise<void>
|
|
45
|
+
/** Return a matching run of this Sync that has not started yet instead of queueing another one. */
|
|
46
|
+
readonly joinQueuedRun?: boolean
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
type PersistedSyncRun =
|
|
@@ -49,9 +51,10 @@ type PersistedSyncRun =
|
|
|
49
51
|
| {
|
|
50
52
|
readonly publish: true
|
|
51
53
|
readonly run: SyncRunRecord
|
|
52
|
-
readonly execution: CreateExecutionInput
|
|
53
54
|
readonly queuedAt: Date
|
|
54
55
|
readonly created: boolean
|
|
56
|
+
/** Defaults to the run id. A trigger that joins a run publishes its own job for it. */
|
|
57
|
+
readonly jobId?: string
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
/** Core-owned durable dispatch boundary used by automatic Sync triggers. */
|
|
@@ -75,6 +78,7 @@ export class SyncRunDispatcher implements SyncRunDispatchPort {
|
|
|
75
78
|
metadata: input.metadata,
|
|
76
79
|
validateExistingRun: (run, storage) =>
|
|
77
80
|
assertAutomaticExecutionIdentity(storage, this.dependencies.id, input, run),
|
|
81
|
+
joinQueuedRun: true,
|
|
78
82
|
createExecution: async (executionId, runId) =>
|
|
79
83
|
createPrimitiveExecutionRecord({
|
|
80
84
|
id: executionId,
|
|
@@ -122,6 +126,19 @@ async function persistSyncRun(
|
|
|
122
126
|
return { publish: false, run: raced }
|
|
123
127
|
}
|
|
124
128
|
|
|
129
|
+
if (input.joinQueuedRun) {
|
|
130
|
+
const waiting = await findQueuedSyncRun(transactionalRuns, input)
|
|
131
|
+
if (waiting) {
|
|
132
|
+
return {
|
|
133
|
+
publish: true,
|
|
134
|
+
run: waiting,
|
|
135
|
+
queuedAt: waiting.queuedAt,
|
|
136
|
+
created: false,
|
|
137
|
+
jobId: joinJobId(waiting, runId),
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
125
142
|
await tx.executions.create(execution)
|
|
126
143
|
const run = await transactionalRuns.queue({
|
|
127
144
|
projectId: input.projectId,
|
|
@@ -134,7 +151,7 @@ async function persistSyncRun(
|
|
|
134
151
|
expectedLatestVersionId: input.expectedLatestVersionId,
|
|
135
152
|
commitMessage: input.commitMessage,
|
|
136
153
|
})
|
|
137
|
-
return { publish: true, run,
|
|
154
|
+
return { publish: true, run, queuedAt, created: true }
|
|
138
155
|
},
|
|
139
156
|
{ isolation: "serializable" }
|
|
140
157
|
)
|
|
@@ -148,6 +165,35 @@ async function persistSyncRun(
|
|
|
148
165
|
}
|
|
149
166
|
}
|
|
150
167
|
|
|
168
|
+
/**
|
|
169
|
+
* A run that has not started reads its source when it starts, so it already covers a trigger that
|
|
170
|
+
* arrives now. The oldest one starts first; one queued with another request payload is not joined.
|
|
171
|
+
*/
|
|
172
|
+
async function findQueuedSyncRun(
|
|
173
|
+
syncRuns: NonNullable<Storage["syncRuns"]>,
|
|
174
|
+
input: DispatchSyncRunInput
|
|
175
|
+
): Promise<SyncRunRecord | undefined> {
|
|
176
|
+
const { runs } = await syncRuns.list({
|
|
177
|
+
projectId: input.projectId,
|
|
178
|
+
syncId: input.sync.id,
|
|
179
|
+
statuses: ["queued"],
|
|
180
|
+
order: "asc",
|
|
181
|
+
limit: 1,
|
|
182
|
+
})
|
|
183
|
+
const [waiting] = runs
|
|
184
|
+
return waiting && runMatchesRequest(waiting, input) ? waiting : undefined
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The job a trigger publishes for the run it joins. The run's own job may be gone (a provider
|
|
189
|
+
* keeps a settled job id, and ignores a new job under it), so each joining trigger brings a job
|
|
190
|
+
* that can start the run; once it has started, the others complete without doing anything. The id
|
|
191
|
+
* derives from the trigger's run id, so a redelivered trigger publishes the same job.
|
|
192
|
+
*/
|
|
193
|
+
function joinJobId(waiting: SyncRunRecord, triggerRunId: string): string {
|
|
194
|
+
return `${waiting.id}:join:${triggerRunId}`
|
|
195
|
+
}
|
|
196
|
+
|
|
151
197
|
async function reuseSyncRun(
|
|
152
198
|
input: DispatchSyncRunInput,
|
|
153
199
|
existing: SyncRunRecord
|
|
@@ -161,7 +207,7 @@ async function reuseSyncRun(
|
|
|
161
207
|
})
|
|
162
208
|
if (!execution)
|
|
163
209
|
throw new SyncRunError(`[Sixb] Execution '${existing.executionId}' was not found.`)
|
|
164
|
-
return { publish: true, run: existing,
|
|
210
|
+
return { publish: true, run: existing, queuedAt: existing.queuedAt, created: false }
|
|
165
211
|
}
|
|
166
212
|
if (
|
|
167
213
|
existing.status !== "failed" ||
|
|
@@ -193,26 +239,28 @@ async function reuseSyncRun(
|
|
|
193
239
|
expectedLatestVersionId: existing.expectedLatestVersionId,
|
|
194
240
|
commitMessage: existing.commitMessage,
|
|
195
241
|
})
|
|
196
|
-
return { publish: true, run,
|
|
242
|
+
return { publish: true, run, queuedAt, created: false }
|
|
197
243
|
}
|
|
198
244
|
|
|
199
245
|
async function publishSyncRun(
|
|
200
246
|
input: DispatchSyncRunInput,
|
|
201
247
|
persisted: Extract<PersistedSyncRun, { readonly publish: true }>
|
|
202
248
|
): Promise<SyncRunRequestResult> {
|
|
249
|
+
const jobId = persisted.jobId ?? persisted.run.id
|
|
250
|
+
|
|
203
251
|
try {
|
|
204
252
|
const [job] = await input.queue.enqueue({
|
|
205
253
|
projectId: input.projectId,
|
|
206
254
|
jobs: [
|
|
207
255
|
{
|
|
208
|
-
id:
|
|
256
|
+
id: jobId,
|
|
209
257
|
type: "sync.run.requested",
|
|
210
258
|
payload: { runId: persisted.run.id },
|
|
211
259
|
...(input.metadata === undefined ? {} : { metadata: input.metadata }),
|
|
212
260
|
},
|
|
213
261
|
],
|
|
214
262
|
})
|
|
215
|
-
if (!job || job.id !==
|
|
263
|
+
if (!job || job.id !== jobId) {
|
|
216
264
|
throw new SyncRunError(`[Sixb] Queue did not acknowledge Sync run '${persisted.run.id}'.`)
|
|
217
265
|
}
|
|
218
266
|
return {
|
|
@@ -249,19 +297,26 @@ function assertExistingRunMatchesRequest(
|
|
|
249
297
|
existing: SyncRunRecord,
|
|
250
298
|
input: Pick<DispatchSyncRunInput, "sync" | "expectedLatestVersionId" | "commitMessage">
|
|
251
299
|
): void {
|
|
252
|
-
if (
|
|
253
|
-
existing.syncId !== input.sync.id ||
|
|
254
|
-
existing.datasetId !== input.sync.target.dataset.id ||
|
|
255
|
-
existing.mode !== input.sync.config.mode ||
|
|
256
|
-
existing.expectedLatestVersionId !== input.expectedLatestVersionId ||
|
|
257
|
-
existing.commitMessage !== input.commitMessage
|
|
258
|
-
) {
|
|
300
|
+
if (!runMatchesRequest(existing, input)) {
|
|
259
301
|
throw new SyncRunError(
|
|
260
302
|
`[Sixb] Sync run '${existing.id}' already exists with a different request payload.`
|
|
261
303
|
)
|
|
262
304
|
}
|
|
263
305
|
}
|
|
264
306
|
|
|
307
|
+
function runMatchesRequest(
|
|
308
|
+
existing: SyncRunRecord,
|
|
309
|
+
input: Pick<DispatchSyncRunInput, "sync" | "expectedLatestVersionId" | "commitMessage">
|
|
310
|
+
): boolean {
|
|
311
|
+
return (
|
|
312
|
+
existing.syncId === input.sync.id &&
|
|
313
|
+
existing.datasetId === input.sync.target.dataset.id &&
|
|
314
|
+
existing.mode === input.sync.config.mode &&
|
|
315
|
+
existing.expectedLatestVersionId === input.expectedLatestVersionId &&
|
|
316
|
+
existing.commitMessage === input.commitMessage
|
|
317
|
+
)
|
|
318
|
+
}
|
|
319
|
+
|
|
265
320
|
function existingSyncRunResult(existing: SyncRunRecord): SyncRunRequestResult {
|
|
266
321
|
return {
|
|
267
322
|
syncId: existing.syncId,
|
|
@@ -250,6 +250,87 @@ export function runDatasetSequenceContract<TStorage extends LakeStorage>(
|
|
|
250
250
|
expect(await rows(storage)).toEqual([])
|
|
251
251
|
}))
|
|
252
252
|
|
|
253
|
+
test("records a merge that only advances source ordering as changing no rows", () =>
|
|
254
|
+
withStorage(async (storage) => {
|
|
255
|
+
// Red check: record `rowsChanged: true` on every merge version the provider creates.
|
|
256
|
+
const changed = (result: DatasetMergeCommitResult) => ({
|
|
257
|
+
outcome: result.outcome,
|
|
258
|
+
rowsChanged: result.version?.rowsChanged,
|
|
259
|
+
lineageChanged: result.version?.lineageChanged,
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
expect(changed(await merge(storage, [upsert(1)]))).toEqual({
|
|
263
|
+
outcome: "created",
|
|
264
|
+
rowsChanged: true,
|
|
265
|
+
lineageChanged: true,
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
// The delete of a key the dataset does not hold only records its sequence.
|
|
269
|
+
const orderingOnly = await merge(storage, [change.delete({ id: "7" }, { sequence: 3 })])
|
|
270
|
+
expect(changed(orderingOnly)).toEqual({
|
|
271
|
+
outcome: "created",
|
|
272
|
+
rowsChanged: false,
|
|
273
|
+
lineageChanged: false,
|
|
274
|
+
})
|
|
275
|
+
expect(
|
|
276
|
+
(await storage.getVersion(dataset.id, orderingOnly.version!.versionId))?.rowsChanged
|
|
277
|
+
).toBe(false)
|
|
278
|
+
|
|
279
|
+
expect(changed(await merge(storage, [upsert(2, "Ada")]))).toEqual({
|
|
280
|
+
outcome: "created",
|
|
281
|
+
rowsChanged: true,
|
|
282
|
+
lineageChanged: false,
|
|
283
|
+
})
|
|
284
|
+
}))
|
|
285
|
+
|
|
286
|
+
test("keeps a stored row that a newer delivery repeats with only its sequence changed", () =>
|
|
287
|
+
withStorage(async (storage) => {
|
|
288
|
+
// Red check: write every accepted upsert's row (drop `isSequenceOnlyChange` from the
|
|
289
|
+
// provider's merge, or the `sequenceBy` filter from DuckLake's row difference).
|
|
290
|
+
const stored = async () =>
|
|
291
|
+
(await rows(storage))
|
|
292
|
+
.map((row) => ({ id: row.id, revision: String(row.revision), name: row.name }))
|
|
293
|
+
.sort((left, right) => String(left.id).localeCompare(String(right.id)))
|
|
294
|
+
const changed = (result: DatasetMergeCommitResult) => ({
|
|
295
|
+
outcome: result.outcome,
|
|
296
|
+
rowsChanged: result.version?.rowsChanged,
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
await merge(storage, [upsert(10), upsert(1, "Lin", "7")])
|
|
300
|
+
|
|
301
|
+
// A re-read at 12 returns the same content: the row keeps 10, the ordering moves to 12.
|
|
302
|
+
expect(changed(await merge(storage, [upsert(12)]))).toEqual({
|
|
303
|
+
outcome: "created",
|
|
304
|
+
rowsChanged: false,
|
|
305
|
+
})
|
|
306
|
+
expect(await stored()).toEqual([
|
|
307
|
+
{ id: "42", revision: "10", name: "Sam" },
|
|
308
|
+
{ id: "7", revision: "1", name: "Lin" },
|
|
309
|
+
])
|
|
310
|
+
|
|
311
|
+
// A late delivery read at 11 stays ignored, and 12 compares with what was delivered at 12.
|
|
312
|
+
expect((await merge(storage, [upsert(11, "Late")])).outcome).toBe("unchanged")
|
|
313
|
+
expect((await merge(storage, [upsert(12)])).outcome).toBe("unchanged")
|
|
314
|
+
await expect(merge(storage, [upsert(12, "Tie")])).rejects.toThrow("conflicting content")
|
|
315
|
+
|
|
316
|
+
// In one batch, only the row whose content changed is rewritten.
|
|
317
|
+
expect(changed(await merge(storage, [upsert(13), upsert(2, "Grace", "7")]))).toEqual({
|
|
318
|
+
outcome: "created",
|
|
319
|
+
rowsChanged: true,
|
|
320
|
+
})
|
|
321
|
+
expect(await stored()).toEqual([
|
|
322
|
+
{ id: "42", revision: "10", name: "Sam" },
|
|
323
|
+
{ id: "7", revision: "2", name: "Grace" },
|
|
324
|
+
])
|
|
325
|
+
|
|
326
|
+
// Any other difference rewrites the whole row, its sequence included.
|
|
327
|
+
expect(changed(await merge(storage, [upsert(14, "Ada")]))).toEqual({
|
|
328
|
+
outcome: "created",
|
|
329
|
+
rowsChanged: true,
|
|
330
|
+
})
|
|
331
|
+
expect((await stored())[0]).toEqual({ id: "42", revision: "14", name: "Ada" })
|
|
332
|
+
}))
|
|
333
|
+
|
|
253
334
|
test("compares canonical content across JSON order and nullable representations", () =>
|
|
254
335
|
withStorage(async (storage) => {
|
|
255
336
|
await merge(storage, [
|
|
@@ -121,7 +121,8 @@ export function runLakeChangesContractSuite<T extends LakeStorage>(
|
|
|
121
121
|
})
|
|
122
122
|
test("refuses blank identities and invalid column requests", async () => {
|
|
123
123
|
const first = await write([row(" ", "one")])
|
|
124
|
-
|
|
124
|
+
const second = await write([row(" ", "two")])
|
|
125
|
+
expect(await read(first, second)).toBeNull()
|
|
125
126
|
await expect(read(first, first, [])).rejects.toThrow("distinct columns")
|
|
126
127
|
await expect(read(first, first, ["missing"])).rejects.toThrow("distinct columns")
|
|
127
128
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { randomUUID } from "node:crypto"
|
|
2
3
|
import type { FileRef } from "../blob-storage"
|
|
3
4
|
import { col, type DatasetDefinition, defineDataset } from "../datasets"
|
|
4
5
|
import { LakeStorageError } from "../lake-storage/errors"
|
|
@@ -7,6 +8,7 @@ import type {
|
|
|
7
8
|
DatasetColumnRef,
|
|
8
9
|
DatasetProducer,
|
|
9
10
|
DatasetRow,
|
|
11
|
+
DatasetVersion,
|
|
10
12
|
DatasetWriteCommitResult,
|
|
11
13
|
LakeStorage,
|
|
12
14
|
} from "../lake-storage/types"
|
|
@@ -1178,6 +1180,116 @@ export function runLakeStorageContractSuite<TStorage extends LakeStorage>(
|
|
|
1178
1180
|
})
|
|
1179
1181
|
}))
|
|
1180
1182
|
})
|
|
1183
|
+
|
|
1184
|
+
describe("what a version changed", () => {
|
|
1185
|
+
const changed = (version: DatasetVersion | null | undefined) => ({
|
|
1186
|
+
rowsChanged: version?.rowsChanged,
|
|
1187
|
+
lineageChanged: version?.lineageChanged,
|
|
1188
|
+
})
|
|
1189
|
+
|
|
1190
|
+
test("records whether a version changed rows or lineage, across reopening", async () => {
|
|
1191
|
+
// Red check: store `rowsChanged: true` on every version the provider creates.
|
|
1192
|
+
let storage = await options.createStorage()
|
|
1193
|
+
try {
|
|
1194
|
+
await storage.createDataset(writeDataset)
|
|
1195
|
+
await storage.createDataset(definitionDataset)
|
|
1196
|
+
|
|
1197
|
+
const inputVersion = async () => {
|
|
1198
|
+
const session = await storage.beginWrite({ dataset: definitionDataset })
|
|
1199
|
+
await session.writeRows([{ orderId: randomUUID(), customerName: "Input" }])
|
|
1200
|
+
const version = await session.commit()
|
|
1201
|
+
return { datasetId: definitionDataset.id, versionId: version.versionId }
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
const rows = [{ orderId: "ord_1", customerName: "Ada" }]
|
|
1205
|
+
const commit = async (
|
|
1206
|
+
input: Pick<BeginDatasetWriteInput, "producer" | "lineage" | "mode" | "inputs">,
|
|
1207
|
+
written: readonly DatasetRow[] = rows
|
|
1208
|
+
) => {
|
|
1209
|
+
const session = await storage.beginWrite({ dataset: writeDataset, ...input })
|
|
1210
|
+
await session.writeRows(written)
|
|
1211
|
+
const version = await session.commit()
|
|
1212
|
+
expect(version.outcome).toBe("created")
|
|
1213
|
+
return version
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
const first = await commit({ inputs: [await inputVersion()] })
|
|
1217
|
+
expect(changed(first)).toEqual({ rowsChanged: true, lineageChanged: true })
|
|
1218
|
+
|
|
1219
|
+
// Identical rows computed from a new input version.
|
|
1220
|
+
const provenanceOnly = await commit({ inputs: [await inputVersion()] })
|
|
1221
|
+
expect(changed(provenanceOnly)).toEqual({ rowsChanged: false, lineageChanged: false })
|
|
1222
|
+
|
|
1223
|
+
// Identical rows that come from other columns.
|
|
1224
|
+
const lineageOnly = await commit({ producer: pipeline, lineage: copied })
|
|
1225
|
+
expect(changed(lineageOnly)).toEqual({ rowsChanged: false, lineageChanged: true })
|
|
1226
|
+
|
|
1227
|
+
const rowsOnly = await commit({ producer: pipeline, lineage: copied }, [
|
|
1228
|
+
{ orderId: "ord_2", customerName: "Grace" },
|
|
1229
|
+
])
|
|
1230
|
+
expect(changed(rowsOnly)).toEqual({ rowsChanged: true, lineageChanged: false })
|
|
1231
|
+
|
|
1232
|
+
// An append of no rows from a new input version.
|
|
1233
|
+
const emptyAppend = await commit(
|
|
1234
|
+
{ producer: pipeline, lineage: copied, mode: "append", inputs: [await inputVersion()] },
|
|
1235
|
+
[]
|
|
1236
|
+
)
|
|
1237
|
+
expect(changed(emptyAppend)).toEqual({ rowsChanged: false, lineageChanged: false })
|
|
1238
|
+
|
|
1239
|
+
const append = await commit({ producer: pipeline, lineage: copied, mode: "append" }, [
|
|
1240
|
+
{ orderId: "ord_3", customerName: "Lin" },
|
|
1241
|
+
])
|
|
1242
|
+
expect(changed(append)).toEqual({ rowsChanged: true, lineageChanged: false })
|
|
1243
|
+
|
|
1244
|
+
if (options.reopen) storage = await options.reopen(storage)
|
|
1245
|
+
|
|
1246
|
+
const committed = [first, provenanceOnly, lineageOnly, rowsOnly, emptyAppend, append]
|
|
1247
|
+
const expected = Object.fromEntries(committed.map((v) => [v.versionId, changed(v)]))
|
|
1248
|
+
const listed = await storage.listVersions(writeDataset.id)
|
|
1249
|
+
expect(Object.fromEntries(listed.map((v) => [v.versionId, changed(v)]))).toEqual(expected)
|
|
1250
|
+
|
|
1251
|
+
for (const version of committed) {
|
|
1252
|
+
expect(changed(await storage.getVersion(writeDataset.id, version.versionId))).toEqual(
|
|
1253
|
+
changed(version)
|
|
1254
|
+
)
|
|
1255
|
+
}
|
|
1256
|
+
expect(changed(await storage.getLatestVersion(writeDataset.id))).toEqual(changed(append))
|
|
1257
|
+
} finally {
|
|
1258
|
+
await options.teardown?.(storage)
|
|
1259
|
+
}
|
|
1260
|
+
})
|
|
1261
|
+
|
|
1262
|
+
test("a dataset's first version changes rows, even empty", () =>
|
|
1263
|
+
withStorage(async (storage) => {
|
|
1264
|
+
await storage.createDataset(writeDataset)
|
|
1265
|
+
const session = await storage.beginWrite({ dataset: writeDataset })
|
|
1266
|
+
const first = await session.commit()
|
|
1267
|
+
|
|
1268
|
+
expect(changed(first)).toEqual({ rowsChanged: true, lineageChanged: true })
|
|
1269
|
+
}))
|
|
1270
|
+
|
|
1271
|
+
test("a schema change changes rows", () =>
|
|
1272
|
+
withStorage(async (storage) => {
|
|
1273
|
+
if (schemaEvolution === "strict") return
|
|
1274
|
+
|
|
1275
|
+
const initial = defineDataset("contract.changes.schema_evolution", {
|
|
1276
|
+
schema: [col("invoiceId", "string")],
|
|
1277
|
+
})
|
|
1278
|
+
const widened = defineDataset("contract.changes.schema_evolution", {
|
|
1279
|
+
schema: [col("invoiceId", "string"), col("currency", "string", { nullable: true })],
|
|
1280
|
+
})
|
|
1281
|
+
|
|
1282
|
+
await storage.createDataset(initial)
|
|
1283
|
+
const session = await storage.beginWrite({ dataset: initial })
|
|
1284
|
+
await session.writeRows([{ invoiceId: "inv_1" }])
|
|
1285
|
+
await session.commit()
|
|
1286
|
+
|
|
1287
|
+
await storage.createDataset(widened)
|
|
1288
|
+
const [schemaVersion] = await storage.listVersions(initial.id, 1)
|
|
1289
|
+
expect(schemaVersion?.mode).toBe("schema")
|
|
1290
|
+
expect(changed(schemaVersion)).toEqual({ rowsChanged: true, lineageChanged: true })
|
|
1291
|
+
}))
|
|
1292
|
+
})
|
|
1181
1293
|
})
|
|
1182
1294
|
}
|
|
1183
1295
|
|
package/src/workers/index.ts
CHANGED
|
@@ -3,4 +3,5 @@ export type { QueueDelivery, QueueDeliveryState, QueueSettlementResult } from ".
|
|
|
3
3
|
export { QueueDeliveryLeaseLostError } from "./queue-delivery"
|
|
4
4
|
export type { QueueWorkerConfig, QueueWorkerFailureDecision } from "./queue-worker"
|
|
5
5
|
export { isAbortError, QueueWorker } from "./queue-worker"
|
|
6
|
+
export { retryUnstartedRun } from "./unstarted-run"
|
|
6
7
|
export { Worker } from "./worker"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { QueueWorkerFailureDecision } from "./queue-worker"
|
|
2
|
+
|
|
3
|
+
const UNSTARTED_RUN_ATTEMPTS = 3
|
|
4
|
+
const UNSTARTED_RUN_RETRY_INITIAL_DELAY_MS = 250
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A run that has not started has committed nothing, so a job that fails before starting it is
|
|
8
|
+
* retried with a short doubling backoff. Returns `undefined` once its attempts are spent: the
|
|
9
|
+
* worker then fails the run, so that later triggers stop joining it.
|
|
10
|
+
*/
|
|
11
|
+
export function retryUnstartedRun(
|
|
12
|
+
attempt: number
|
|
13
|
+
): Extract<QueueWorkerFailureDecision, { readonly kind: "retry" }> | undefined {
|
|
14
|
+
if (attempt >= UNSTARTED_RUN_ATTEMPTS) return undefined
|
|
15
|
+
|
|
16
|
+
const delayMs = UNSTARTED_RUN_RETRY_INITIAL_DELAY_MS * 2 ** (Math.max(attempt, 1) - 1)
|
|
17
|
+
return { kind: "retry", availableAt: new Date(Date.now() + delayMs).toISOString() }
|
|
18
|
+
}
|