mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
fix!: preserve job attempt lineage, retries, and lifecycle states
BREAKING CHANGE: JobDescription, JobEventsRequest, FunctionErrorsRequest, and FunctionErrors gain optional Rust metadata/cursor fields. Existing struct literals must initialize them; use None when unavailable. Preserve typed attempt state, pinned retry lineage, result decoders and freshness fences, and retained diagnostic paging across SDKs. Keep Python job data access method-only.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||
|
||||
import { Job } from "../lancedb/job";
|
||||
import type { Job as NativeJob } from "../lancedb/native";
|
||||
|
||||
describe("Job attempt contract", () => {
|
||||
test("preserves lineage and unknown detailed states", async () => {
|
||||
const inner = {
|
||||
jobId: "attempt-2",
|
||||
operationId: "attempt-1",
|
||||
attempt: 2,
|
||||
retryOf: "attempt-1",
|
||||
lifecycleState: "future_publication_state",
|
||||
sourceTableVersion: 7,
|
||||
executionEpoch: 3,
|
||||
status: jest.fn().mockResolvedValue("future_publication_state"),
|
||||
} as unknown as NativeJob;
|
||||
const job = new Job(inner);
|
||||
expect(job.jobId).toBe("attempt-2");
|
||||
expect(job.operationId).toBe("attempt-1");
|
||||
expect(job.attempt).toBe(2);
|
||||
expect(job.retryOf).toBe("attempt-1");
|
||||
expect(await job.statusTyped()).toBe("future_publication_state");
|
||||
expect(job.sourceTableVersion).toBe(7);
|
||||
expect(job.executionEpoch).toBe(3);
|
||||
});
|
||||
|
||||
test("passes wait deadlines through without cancelling execution", async () => {
|
||||
const wait = jest.fn().mockRejectedValue(new Error("Timeout error"));
|
||||
const cancel = jest.fn();
|
||||
const job = new Job({ wait, cancel } as unknown as NativeJob);
|
||||
await expect(job.wait({ timeoutMs: 1 })).rejects.toThrow("Timeout");
|
||||
expect(wait).toHaveBeenCalledWith(undefined, 1);
|
||||
expect(cancel).not.toHaveBeenCalled();
|
||||
});
|
||||
test("retry retains the typed result decoder", async () => {
|
||||
const successor = {
|
||||
waitResult: jest.fn().mockResolvedValue({ value: 7 }),
|
||||
} as unknown as NativeJob;
|
||||
const inner = {
|
||||
retry: jest.fn().mockResolvedValue(successor),
|
||||
} as unknown as NativeJob;
|
||||
const job = new Job(inner, (value) => (value as { value: number }).value);
|
||||
const retry = await job.retry();
|
||||
expect(await retry.wait()).toBe(7);
|
||||
});
|
||||
});
|
||||
@@ -2398,6 +2398,8 @@ describe("remote connection jobs surface", () => {
|
||||
expect(job.result).toBeNull();
|
||||
expect(job.failure?.message).toEqual("worker died");
|
||||
expect(await job.progress()).toEqual({
|
||||
// biome-ignore lint/style/useNamingConvention: server wire format
|
||||
job_id: "job-1",
|
||||
// biome-ignore lint/style/useNamingConvention: server wire format
|
||||
job_type: "create_index",
|
||||
state: "failed",
|
||||
|
||||
+11
-6
@@ -2,21 +2,21 @@
|
||||
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||
|
||||
import {
|
||||
Connection,
|
||||
type Connection,
|
||||
LocalConnection,
|
||||
cleanseStorageOptions,
|
||||
} from "./connection";
|
||||
|
||||
import {
|
||||
ConnectNamespaceOptions,
|
||||
ConnectionOptions,
|
||||
type ConnectNamespaceOptions,
|
||||
type ConnectionOptions,
|
||||
Connection as LanceDbConnection,
|
||||
JsHeaderProvider as NativeJsHeaderProvider,
|
||||
Session,
|
||||
type Session,
|
||||
tokenize as nativeTokenize,
|
||||
} from "./native.js";
|
||||
|
||||
import { HeaderProvider } from "./header";
|
||||
import type { HeaderProvider } from "./header";
|
||||
import type { BaseTokenizer } from "./indices";
|
||||
import type { FtsToken } from "./table";
|
||||
|
||||
@@ -118,7 +118,12 @@ export {
|
||||
Job,
|
||||
JobEventsOptions,
|
||||
} from "./job";
|
||||
export type { JobProgress, JobProgressCallback, JobWaitOptions } from "./job";
|
||||
export type {
|
||||
JobProgress,
|
||||
JobProgressCallback,
|
||||
JobState,
|
||||
JobWaitOptions,
|
||||
} from "./job";
|
||||
|
||||
export {
|
||||
AutoQuery,
|
||||
|
||||
+89
-2
@@ -4,7 +4,7 @@
|
||||
import { Table as ArrowTable, tableFromIPC } from "apache-arrow";
|
||||
import { decodeCleanupResult } from "./cleanup";
|
||||
import { decodeCompactionResult } from "./compaction";
|
||||
import { JobFailureInfo, Job as NativeJob } from "./native";
|
||||
import type { JobFailureInfo, Job as NativeJob } from "./native";
|
||||
import { decodePrewarmDataResult } from "./prewarm";
|
||||
|
||||
/** Which of a job's events {@link Job.events} returns. */
|
||||
@@ -13,6 +13,8 @@ export interface JobEventsOptions {
|
||||
limit?: number;
|
||||
/** SQL-like filter over the event columns. */
|
||||
filter?: string;
|
||||
/** Opaque continuation from the preceding page's schema metadata. */
|
||||
pageToken?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,6 +95,16 @@ export interface JobWaitOptions {
|
||||
/** Observe progress using the same poller that waits for completion. */
|
||||
onProgress?: JobProgressCallback;
|
||||
}
|
||||
/** Detailed lifecycle state. Unrecognized future values remain strings. */
|
||||
export type JobState =
|
||||
| "created"
|
||||
| "queued"
|
||||
| "in_progress"
|
||||
| "succeeded"
|
||||
| "failed"
|
||||
| "canceled"
|
||||
| "timed_out"
|
||||
| (string & {});
|
||||
|
||||
/**
|
||||
* A handle to an operation that may still be running.
|
||||
@@ -141,6 +153,56 @@ export class Job<T = void> {
|
||||
return this.inner.id ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identity of the selected attempt last observed by this handle.
|
||||
* For operation handles, `refresh()` or `status()` can select a different
|
||||
* attempt while `id` stays unchanged. Save this value after refreshing and
|
||||
* use it throughout paged diagnostics. Local IDs cannot be reopened on a server.
|
||||
*/
|
||||
get jobId(): string | null {
|
||||
return this.inner.jobId ?? null;
|
||||
}
|
||||
|
||||
/** Root of the explicit retry lineage, when reported. */
|
||||
get operationId(): string | null {
|
||||
return this.inner.operationId ?? null;
|
||||
}
|
||||
|
||||
/** One-based attempt ordinal. Worker replacement does not increment it. */
|
||||
get attempt(): number | null {
|
||||
return this.inner.attempt ?? null;
|
||||
}
|
||||
|
||||
/** Immediate predecessor attempt, when reported. */
|
||||
get retryOf(): string | null {
|
||||
return this.inner.retryOf ?? null;
|
||||
}
|
||||
|
||||
/** Detailed state last observed; unknown values never establish success. */
|
||||
get lifecycleState(): JobState | null {
|
||||
return this.inner.lifecycleState ?? null;
|
||||
}
|
||||
|
||||
/** Source snapshot pinned for this attempt, when reported. */
|
||||
get sourceTableVersion(): number | null {
|
||||
return this.inner.sourceTableVersion ?? null;
|
||||
}
|
||||
|
||||
/** Most recent execution's fencing token, when reported. */
|
||||
get executionEpoch(): number | null {
|
||||
return this.inner.executionEpoch ?? null;
|
||||
}
|
||||
|
||||
/** Refresh and return the detailed lifecycle state. */
|
||||
async statusTyped(): Promise<JobState> {
|
||||
const state = await this.status();
|
||||
if (this.lifecycleState !== null) return this.lifecycleState;
|
||||
if (state === "running") return "in_progress";
|
||||
if (state === "finished") return "succeeded";
|
||||
if (state === "cancelled") return "canceled";
|
||||
return state;
|
||||
}
|
||||
|
||||
/** The last observed lifecycle state, without contacting the backend. */
|
||||
get state(): string | null {
|
||||
return this.inner.state ?? null;
|
||||
@@ -277,6 +339,11 @@ export class Job<T = void> {
|
||||
return this.inner.cancel();
|
||||
}
|
||||
|
||||
/** Select this exact attempt's pinned successor. Requires backend support. */
|
||||
async retry(): Promise<Job<T>> {
|
||||
return new Job<T>(await this.inner.retry(), this.resultDecoder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the backend for this job's current state, and for a server-side job
|
||||
* its full record, then cache it for the getters above.
|
||||
@@ -300,13 +367,33 @@ export class Job<T = void> {
|
||||
* `updated_by`, `emitted_from`, `emitted_by`, and `claim_entity` columns.
|
||||
*/
|
||||
async events(options?: JobEventsOptions): Promise<ArrowTable> {
|
||||
const buf = await this.inner.events(options?.limit, options?.filter);
|
||||
const buf = await this.inner.events(
|
||||
options?.limit,
|
||||
options?.filter,
|
||||
options?.pageToken,
|
||||
);
|
||||
if (buf.length === 0) {
|
||||
return new ArrowTable();
|
||||
}
|
||||
return tableFromIPC(buf);
|
||||
}
|
||||
|
||||
/** Walk retained history one page at a time using the server's continuation. */
|
||||
async *history(options?: JobEventsOptions): AsyncGenerator<ArrowTable> {
|
||||
let pageToken = options?.pageToken;
|
||||
for (;;) {
|
||||
const page = await this.events({ ...options, pageToken });
|
||||
yield page;
|
||||
const next = page.schema.metadata.get(
|
||||
"lancedb.job_coordinator.page_token",
|
||||
);
|
||||
if (next === undefined) return;
|
||||
if (next === pageToken)
|
||||
throw new Error("Job history repeated its page token");
|
||||
pageToken = next;
|
||||
}
|
||||
}
|
||||
|
||||
private lastProgress: JobProgress | null = null;
|
||||
|
||||
private enrichProgress(progress: Record<string, unknown>): JobProgress {
|
||||
|
||||
+57
-2
@@ -52,6 +52,45 @@ impl Job {
|
||||
self.inner.id().map(str::to_string)
|
||||
}
|
||||
|
||||
#[napi(getter)]
|
||||
pub fn job_id(&self) -> Option<String> {
|
||||
self.inner.job_id()
|
||||
}
|
||||
|
||||
#[napi(getter)]
|
||||
pub fn operation_id(&self) -> Option<String> {
|
||||
self.inner.operation_id()
|
||||
}
|
||||
|
||||
#[napi(getter)]
|
||||
pub fn attempt(&self) -> Option<u32> {
|
||||
self.inner.attempt()
|
||||
}
|
||||
|
||||
#[napi(getter)]
|
||||
pub fn retry_of(&self) -> Option<String> {
|
||||
self.inner.retry_of()
|
||||
}
|
||||
|
||||
#[napi(getter)]
|
||||
pub fn lifecycle_state(&self) -> Option<String> {
|
||||
self.inner
|
||||
.lifecycle_state()
|
||||
.map(|state| state.as_str().to_string())
|
||||
}
|
||||
|
||||
#[napi(getter)]
|
||||
pub fn source_table_version(&self) -> Option<f64> {
|
||||
self.inner
|
||||
.source_table_version()
|
||||
.map(|version| version as f64)
|
||||
}
|
||||
|
||||
#[napi(getter)]
|
||||
pub fn execution_epoch(&self) -> Option<i64> {
|
||||
self.inner.execution_epoch()
|
||||
}
|
||||
|
||||
/// The operation's current lifecycle state: "running", "finished",
|
||||
/// "failed", or "cancelled".
|
||||
///
|
||||
@@ -137,6 +176,13 @@ impl Job {
|
||||
self.inner.cancel().await.default_error()
|
||||
}
|
||||
|
||||
#[napi(catch_unwind)]
|
||||
pub async fn retry(&self) -> napi::Result<Self> {
|
||||
Ok(Self {
|
||||
inner: Arc::new(self.inner.retry().await.default_error()?),
|
||||
})
|
||||
}
|
||||
|
||||
/// Ask the backend for this job's current state, and for a server-side job
|
||||
/// its full record, then cache it for the getters below.
|
||||
///
|
||||
@@ -190,10 +236,19 @@ impl Job {
|
||||
/// This job's recorded lifecycle events, as an Arrow IPC stream buffer.
|
||||
/// The TypeScript wrapper turns it into an Arrow table.
|
||||
#[napi(catch_unwind)]
|
||||
pub async fn events(&self, limit: Option<u32>, filter: Option<String>) -> napi::Result<Buffer> {
|
||||
pub async fn events(
|
||||
&self,
|
||||
limit: Option<u32>,
|
||||
filter: Option<String>,
|
||||
page_token: Option<String>,
|
||||
) -> napi::Result<Buffer> {
|
||||
let batches = self
|
||||
.inner
|
||||
.events(JobEventsRequest { limit, filter })
|
||||
.events(JobEventsRequest {
|
||||
limit,
|
||||
filter,
|
||||
page_token,
|
||||
})
|
||||
.await
|
||||
.default_error()?;
|
||||
batches_to_ipc_buffer(&batches)
|
||||
|
||||
@@ -661,6 +661,7 @@ impl Table {
|
||||
job_id: options.job_id,
|
||||
column: options.column,
|
||||
limit,
|
||||
page_token: options.page_token,
|
||||
};
|
||||
let errors = self
|
||||
.inner_ref()?
|
||||
@@ -1845,6 +1846,8 @@ pub struct FunctionErrorsOptions {
|
||||
pub column: Option<String>,
|
||||
/// At most this many records (server default 10000, cap 100000).
|
||||
pub limit: Option<i64>,
|
||||
/// Empty starts retained history, including repaired rows, for an exact jobId; otherwise continue that page.
|
||||
pub page_token: Option<String>,
|
||||
}
|
||||
|
||||
/// Aggregate worker resources for one Enterprise Function refresh.
|
||||
@@ -2204,6 +2207,8 @@ pub struct FunctionErrors {
|
||||
pub fragments: Vec<FunctionErrorFragment>,
|
||||
/// Whether the listing stopped at its limit.
|
||||
pub truncated: bool,
|
||||
/// Continue the same job/filter. Absent for complete pages and older servers.
|
||||
pub page_token: Option<String>,
|
||||
}
|
||||
|
||||
/// One exact immutable Function revision attached to a table output.
|
||||
@@ -2322,6 +2327,7 @@ impl From<lancedb::function::FunctionErrors> for FunctionErrors {
|
||||
records: errors.records.into_iter().map(Into::into).collect(),
|
||||
fragments: errors.fragments.into_iter().map(Into::into).collect(),
|
||||
truncated: errors.truncated,
|
||||
page_token: errors.page_token,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user