From 08ddcdb7d7e26c79289a298d49edd6f95c84b24b Mon Sep 17 00:00:00 2001 From: Yang Cen Date: Sun, 22 Nov 2026 15:40:22 +0800 Subject: [PATCH] feat: resume a failed Function refresh from its table (#5153) LanceDB Enterprise users can resume a failed Function refresh from its table with `table.resume_refresh(job_id)`. The synchronous and asynchronous Python APIs return a typed job handle. Waiting on that handle uses the same table freshness tracking as a newly submitted refresh. The request carries the current table identifier and branch to the server. The server decides whether the original attempt can be resumed and supplies the reason when it cannot. The Python refresh methods also accept a positive `max_job_attempts` option for automatic recovery. These features require server support for Function refresh recovery. The PR adds remote request, branch, error propagation, and typed result tests. Python and Rust validation runs in PR CI. --- docs/web/management/function-failures.mdx | 30 ++++++ python/python/lancedb/_lancedb.pyi | 3 + python/python/lancedb/remote/table.py | 7 ++ python/python/lancedb/table.py | 39 ++++++++ python/python/tests/test_remote_db.py | 52 +++++++++++ python/src/table.rs | 19 +++- rust/lancedb/src/remote/table.rs | 109 ++++++++++++++++------ rust/lancedb/src/table.rs | 28 ++++++ rust/lancedb/src/table/refresh.rs | 15 +++ 9 files changed, 270 insertions(+), 32 deletions(-) diff --git a/docs/web/management/function-failures.mdx b/docs/web/management/function-failures.mdx index b7f554402..793563414 100644 --- a/docs/web/management/function-failures.mdx +++ b/docs/web/management/function-failures.mdx @@ -135,6 +135,36 @@ views, with errors identified by Function invocation and source input. Column retry and upgrade helpers apply to Function columns; use the materialized-view refresh reference for view refresh options. +## Resume a failed refresh job {#resume-refresh} + +Job recovery requires a Python or Rust SDK that exposes `resume_refresh` and +an Enterprise deployment that supports `POST /v1/table/{id}/resume_refresh`. +The `workflow_version` reported by `function_errors` covers row-error +operations. Check your server release for job recovery support separately. + +Open the original table on the branch where the refresh failed. Pass the +failed job ID to get a handle for the successor attempt and wait for its result. + +```python +resumed = table.resume_refresh(failed_job_id) +result = resumed.wait() +``` + +```rust +async fn resume(table: &lancedb::Table, failed_job_id: &str) -> lancedb::Result<()> { + let resumed = table.resume_refresh(failed_job_id).await?; + let result = resumed.wait().await?; + println!("Assigned {} rows", result.rows_assigned); + Ok(()) +} +``` + +The server reuses confirmed outputs. If it reports that an external call may +already have run, check the external result before starting another refresh. +For a Function with external effects, set `max_job_attempts=1` when submitting +the refresh until you have verified replay safety on your deployment. A limit +of `1` counts the initial attempt and disables automatic job retries. + ## Older-deployment recipes {#older-deployments} The following sections describe deployments without workflow version 1. Their diff --git a/python/python/lancedb/_lancedb.pyi b/python/python/lancedb/_lancedb.pyi index a1d4c2445..12bd81fdd 100644 --- a/python/python/lancedb/_lancedb.pyi +++ b/python/python/lancedb/_lancedb.pyi @@ -804,6 +804,7 @@ class Table: row_timeout_seconds: Optional[float] = None, init_timeout_seconds: Optional[float] = None, num_workers: Optional[int] = None, + max_job_attempts: Optional[int] = None, max_executor_processes_per_worker: Optional[int] = None, retry_errors: bool = False, retry_job_id: Optional[str] = None, @@ -834,6 +835,7 @@ class Table: row_timeout_seconds: Optional[float] = None, init_timeout_seconds: Optional[float] = None, num_workers: Optional[int] = None, + max_job_attempts: Optional[int] = None, max_executor_processes_per_worker: Optional[int] = None, retry_errors: bool = False, retry_job_id: Optional[str] = None, @@ -842,6 +844,7 @@ class Table: function_version: Optional[str] = None, recompute: Optional[Literal["failed", "all", "none"]] = None, ) -> Job: ... + async def resume_refresh(self, job_id: str) -> Job: ... async def function_errors( self, job_id: Optional[str] = None, diff --git a/python/python/lancedb/remote/table.py b/python/python/lancedb/remote/table.py index 2b723d0d4..715804e4b 100644 --- a/python/python/lancedb/remote/table.py +++ b/python/python/lancedb/remote/table.py @@ -1237,6 +1237,7 @@ class RemoteTable(Table): row_timeout_seconds: Optional[float] = None, init_timeout_seconds: Optional[float] = None, num_workers: Optional[int] = None, + max_job_attempts: Optional[int] = None, max_executor_processes_per_worker: Optional[int] = None, retry_errors: bool = False, retry_job_id: Optional[str] = None, @@ -1265,6 +1266,7 @@ class RemoteTable(Table): row_timeout_seconds=row_timeout_seconds, init_timeout_seconds=init_timeout_seconds, num_workers=num_workers, + max_job_attempts=max_job_attempts, max_executor_processes_per_worker=max_executor_processes_per_worker, retry_errors=retry_errors, retry_job_id=retry_job_id, @@ -1296,6 +1298,7 @@ class RemoteTable(Table): row_timeout_seconds: Optional[float] = None, init_timeout_seconds: Optional[float] = None, num_workers: Optional[int] = None, + max_job_attempts: Optional[int] = None, max_executor_processes_per_worker: Optional[int] = None, retry_errors: bool = False, retry_job_id: Optional[str] = None, @@ -1325,6 +1328,7 @@ class RemoteTable(Table): row_timeout_seconds=row_timeout_seconds, init_timeout_seconds=init_timeout_seconds, num_workers=num_workers, + max_job_attempts=max_job_attempts, max_executor_processes_per_worker=max_executor_processes_per_worker, retry_errors=retry_errors, retry_job_id=retry_job_id, @@ -1336,6 +1340,9 @@ class RemoteTable(Table): ) ) + def resume_refresh(self, job_id: str) -> Job[RefreshColumnResult]: + return Job(LOOP.run(self._table.resume_refresh(job_id))) + def function_errors( self, job_id: Optional[str] = None, diff --git a/python/python/lancedb/table.py b/python/python/lancedb/table.py index bcc540517..fad89db49 100644 --- a/python/python/lancedb/table.py +++ b/python/python/lancedb/table.py @@ -3591,6 +3591,7 @@ class Table(ABC): row_timeout_seconds: Optional[float] = None, init_timeout_seconds: Optional[float] = None, num_workers: Optional[int] = None, + max_job_attempts: Optional[int] = None, max_executor_processes_per_worker: Optional[int] = None, retry_errors: bool = False, retry_job_id: Optional[str] = None, @@ -3686,6 +3687,9 @@ class Table(ABC): Worker count for an expression column; registered Function columns reject it and set the corresponding ``total_*`` options. LanceDB Enterprise only. + max_job_attempts: int, optional + Total automatic Function refresh attempts, including the initial job. + Set to 1 to disable automatic job recovery. max_executor_processes_per_worker: int, optional Cap on executor processes per Function worker. LanceDB Enterprise only. @@ -3737,6 +3741,7 @@ class Table(ABC): row_timeout_seconds: Optional[float] = None, init_timeout_seconds: Optional[float] = None, num_workers: Optional[int] = None, + max_job_attempts: Optional[int] = None, max_executor_processes_per_worker: Optional[int] = None, retry_errors: bool = False, retry_job_id: Optional[str] = None, @@ -3831,6 +3836,9 @@ class Table(ABC): Worker count for an expression column; registered Function columns reject it and set the corresponding ``total_*`` options. LanceDB Enterprise only. + max_job_attempts: int, optional + Total automatic Function refresh attempts, including the initial job. + Set to 1 to disable automatic job recovery. max_executor_processes_per_worker: int, optional Cap on executor processes per Function worker. LanceDB Enterprise only. @@ -3873,6 +3881,16 @@ class Table(ABC): 'finished' """ + def resume_refresh(self, job_id: str) -> Job[RefreshColumnJobResult]: + """Resume a failed Function refresh on this table's current branch. + + Returns the successor job. Call its ``wait()`` method for the refresh + result. Requires LanceDB Enterprise. + """ + raise NotImplementedError( + "resuming a Function refresh requires LanceDB Enterprise" + ) + def retry_failed( self, column: str, @@ -6541,6 +6559,7 @@ class LanceTable(Table): row_timeout_seconds: Optional[float] = None, init_timeout_seconds: Optional[float] = None, num_workers: Optional[int] = None, + max_job_attempts: Optional[int] = None, max_executor_processes_per_worker: Optional[int] = None, retry_errors: bool = False, retry_job_id: Optional[str] = None, @@ -6572,6 +6591,7 @@ class LanceTable(Table): row_timeout_seconds=row_timeout_seconds, init_timeout_seconds=init_timeout_seconds, num_workers=num_workers, + max_job_attempts=max_job_attempts, max_executor_processes_per_worker=max_executor_processes_per_worker, retry_errors=retry_errors, retry_job_id=retry_job_id, @@ -6605,6 +6625,7 @@ class LanceTable(Table): row_timeout_seconds: Optional[float] = None, init_timeout_seconds: Optional[float] = None, num_workers: Optional[int] = None, + max_job_attempts: Optional[int] = None, max_executor_processes_per_worker: Optional[int] = None, retry_errors: bool = False, retry_job_id: Optional[str] = None, @@ -6638,6 +6659,7 @@ class LanceTable(Table): row_timeout_seconds=row_timeout_seconds, init_timeout_seconds=init_timeout_seconds, num_workers=num_workers, + max_job_attempts=max_job_attempts, max_executor_processes_per_worker=max_executor_processes_per_worker, retry_errors=retry_errors, retry_job_id=retry_job_id, @@ -9274,6 +9296,7 @@ class AsyncTable: row_timeout_seconds: Optional[float] = None, init_timeout_seconds: Optional[float] = None, num_workers: Optional[int] = None, + max_job_attempts: Optional[int] = None, max_executor_processes_per_worker: Optional[int] = None, retry_errors: bool = False, retry_job_id: Optional[str] = None, @@ -9369,6 +9392,9 @@ class AsyncTable: Worker count for an expression column; registered Function columns reject it and set the corresponding ``total_*`` options. LanceDB Enterprise only. + max_job_attempts: int, optional + Total automatic Function refresh attempts, including the initial job. + Set to 1 to disable automatic job recovery. max_executor_processes_per_worker: int, optional Cap on executor processes per Function worker. LanceDB Enterprise only. @@ -9423,6 +9449,7 @@ class AsyncTable: row_timeout_seconds=row_timeout_seconds, init_timeout_seconds=init_timeout_seconds, num_workers=num_workers, + max_job_attempts=max_job_attempts, max_executor_processes_per_worker=max_executor_processes_per_worker, retry_errors=retry_errors, retry_job_id=retry_job_id, @@ -9433,6 +9460,13 @@ class AsyncTable: gpu_count=gpu_count, ) + async def resume_refresh(self, job_id: str) -> AsyncJob[RefreshColumnJobResult]: + """Resume a failed Enterprise Function refresh on this table and branch.""" + return _typed_job( + await self._inner.resume_refresh(job_id), + RefreshColumnJobResult.from_json, + ) + async def retry_failed( self, column: str, @@ -9652,6 +9686,7 @@ class AsyncTable: row_timeout_seconds: Optional[float] = None, init_timeout_seconds: Optional[float] = None, num_workers: Optional[int] = None, + max_job_attempts: Optional[int] = None, max_executor_processes_per_worker: Optional[int] = None, retry_errors: bool = False, retry_job_id: Optional[str] = None, @@ -9746,6 +9781,9 @@ class AsyncTable: Worker count for an expression column; registered Function columns reject it and set the corresponding ``total_*`` options. LanceDB Enterprise only. + max_job_attempts: int, optional + Total automatic Function refresh attempts, including the initial job. + Set to 1 to disable automatic job recovery. max_executor_processes_per_worker: int, optional Cap on executor processes per Function worker. LanceDB Enterprise only. @@ -9817,6 +9855,7 @@ class AsyncTable: row_timeout_seconds=row_timeout_seconds, init_timeout_seconds=init_timeout_seconds, num_workers=num_workers, + max_job_attempts=max_job_attempts, max_executor_processes_per_worker=max_executor_processes_per_worker, retry_errors=retry_errors, retry_job_id=retry_job_id, diff --git a/python/python/tests/test_remote_db.py b/python/python/tests/test_remote_db.py index e72487a41..f8d264e31 100644 --- a/python/python/tests/test_remote_db.py +++ b/python/python/tests/test_remote_db.py @@ -2391,6 +2391,7 @@ def test_remote_create_index_async_returns_job(): "row_timeout_seconds": 30, "init_timeout_seconds": 120, "num_workers": 4, + "max_job_attempts": 4, "max_executor_processes_per_worker": 2, }, ], @@ -2438,6 +2439,7 @@ async def test_remote_refresh_async_returns_typed_terminal_result( "row_timeout_seconds", "init_timeout_seconds", "num_workers", + "max_job_attempts", "max_executor_processes_per_worker", ): if refresh_kwargs.get(key) is not None: @@ -2510,6 +2512,56 @@ async def test_remote_refresh_async_returns_typed_terminal_result( assert result.version == 8 +@pytest.mark.asyncio +@pytest.mark.parametrize("async_table", [True, False]) +async def test_resume_refresh_returns_typed_successor(async_table): + terminal = { + "rows_assigned": 12, + "rows_failed": 0, + "rows_remaining": 0, + "source_version": 7, + "published_version": 8, + } + + def handler(request): + length = int(request.headers.get("Content-Length", 0)) + body = json.loads(request.rfile.read(length)) if length else {} + if request.path == "/v1/table/test/describe/": + response = {"version": 1, "schema": {"fields": []}} + elif request.path == "/v1/table/test/resume_refresh": + assert body == {"job_id": "failed"} + response = {"job_id": "successor"} + elif request.path == "/v1/jobs/describe": + assert body["job_id"] == "successor" + response = { + "job_id": "successor", + "job_type": "function_refresh", + "job_state": "DONE", + "result": terminal, + } + else: + raise AssertionError(f"Unexpected request: {request.path}") + request.send_response(200) + request.send_header("Content-Type", "application/json") + request.end_headers() + request.wfile.write(json.dumps(response).encode()) + + if async_table: + async with mock_lancedb_connection_async(handler) as db: + table = await db.open_table("test") + job = await table.resume_refresh("failed") + result = await job.wait(timeout=timedelta(seconds=30)) + else: + with mock_lancedb_connection(handler) as db: + table = db.open_table("test") + job = table.resume_refresh("failed") + result = job.wait(timeout=timedelta(seconds=30)) + + assert job.id() == "successor" + assert isinstance(result, lancedb.RefreshColumnResult) + assert result.model_dump(exclude_defaults=True) == terminal + + def test_remote_refresh_async_forwards_progress_from_submitted_handle(): terminal_result = { "rows_assigned": 12, diff --git a/python/src/table.rs b/python/src/table.rs index a0ca2d73e..63eb45c4e 100644 --- a/python/src/table.rs +++ b/python/src/table.rs @@ -57,6 +57,7 @@ struct RefreshColumnArgs { where_clause: Option, batch_size: Option, max_concurrency: Option, + max_job_attempts: Option, publication_interval_rows: Option, total_cpu_millis: Option, total_memory_bytes: Option, @@ -217,6 +218,7 @@ fn refresh_column_options(args: RefreshColumnArgs) -> PyResult PyResult( self_: PyRef<'py, Self>, @@ -2770,6 +2773,7 @@ impl Table { init_timeout_seconds: Option, num_workers: Option, max_executor_processes_per_worker: Option, + max_job_attempts: Option>, retry_errors: bool, retry_job_id: Option, retry_error_type: Option, @@ -2803,6 +2807,7 @@ impl Table { init_timeout_seconds, num_workers, max_executor_processes_per_worker, + max_job_attempts: positive_u32_integer(max_job_attempts.as_ref(), "max_job_attempts")?, })?; let inner = self_.inner_ref()?.clone(); future_into_py(self_.py(), async move { @@ -2814,7 +2819,7 @@ impl Table { }) } - #[pyo3(signature = (column, *, r#where=None, batch_size=None, max_concurrency=None, publication_interval_rows=None, total_cpu_millis=None, total_memory_bytes=None, supervisor_resources=None, planning_workers=None, gpu_class=None, gpu_count=None, total_gpu_count=None, retry_policy=None, error_policy=None, max_failed_fraction=None, max_failed_rows=None, row_timeout_seconds=None, init_timeout_seconds=None, num_workers=None, max_executor_processes_per_worker=None, retry_errors=false, retry_job_id=None, retry_error_type=None, include_quarantined=false, function_version=None, recompute=None))] + #[pyo3(signature = (column, *, r#where=None, batch_size=None, max_concurrency=None, publication_interval_rows=None, total_cpu_millis=None, total_memory_bytes=None, supervisor_resources=None, planning_workers=None, gpu_class=None, gpu_count=None, total_gpu_count=None, retry_policy=None, error_policy=None, max_failed_fraction=None, max_failed_rows=None, row_timeout_seconds=None, init_timeout_seconds=None, num_workers=None, max_executor_processes_per_worker=None, max_job_attempts=None, retry_errors=false, retry_job_id=None, retry_error_type=None, include_quarantined=false, function_version=None, recompute=None))] #[allow(clippy::too_many_arguments)] pub fn refresh_column_async<'py>( self_: PyRef<'py, Self>, @@ -2838,6 +2843,7 @@ impl Table { init_timeout_seconds: Option, num_workers: Option, max_executor_processes_per_worker: Option, + max_job_attempts: Option>, retry_errors: bool, retry_job_id: Option, retry_error_type: Option, @@ -2871,6 +2877,7 @@ impl Table { init_timeout_seconds, num_workers, max_executor_processes_per_worker, + max_job_attempts: positive_u32_integer(max_job_attempts.as_ref(), "max_job_attempts")?, })?; let inner = self_.inner_ref()?.clone(); future_into_py(self_.py(), async move { @@ -2882,6 +2889,14 @@ impl Table { }) } + pub fn resume_refresh(self_: PyRef<'_, Self>, job_id: String) -> PyResult> { + let inner = self_.inner_ref()?.clone(); + future_into_py(self_.py(), async move { + let job = inner.resume_refresh(job_id).await.infer_error()?; + Ok(crate::job::Job::new_typed(job)) + }) + } + #[pyo3(signature = (job_id=None, column=None, limit=None, history=false, page_token=None))] pub fn function_errors( self_: PyRef<'_, Self>, diff --git a/rust/lancedb/src/remote/table.rs b/rust/lancedb/src/remote/table.rs index 3793612c6..3642fb950 100644 --- a/rust/lancedb/src/remote/table.rs +++ b/rust/lancedb/src/remote/table.rs @@ -920,6 +920,45 @@ impl RemoteTable { Ok(job_id) } + async fn submit_refresh( + &self, + operation: &str, + mut body: serde_json::Value, + ) -> Result> { + self.apply_branch_body(&mut body); + let request = self + .client + .post(&format!("/v1/table/{}/{operation}", self.identifier)) + .json(&body); + let (request_id, response) = self.send(request, true).await?; + // Preserve dependency errors: a deleted bound Function also returns 404. + let response = self + .client + .check_response(&request_id, response) + .await + .inspect_err(|error| self.handle_error_invalidation(error))?; + let body = response.text().await.err_to_http(request_id.clone())?; + + #[derive(serde::Deserialize)] + struct RefreshJobResponse { + job_id: String, + } + let response: RefreshJobResponse = + serde_json::from_str(&body).map_err(|e| Error::Http { + source: format!("Failed to parse {operation} response: {}", e).into(), + request_id, + status_code: None, + })?; + + Ok(Job::new_typed(Box::new(FreshnessJob { + inner: RemoteJob::new(self.client.clone(), response.job_id), + freshness: self.freshness.clone(), + version: self.version.clone(), + tracked_result: TrackedJobResult::RefreshColumn, + freshness_request: self.snapshot_freshness_headers(), + }))) + } + fn index_job(&self, job_id: String) -> Job { Job::new(Box::new(FreshnessJob { inner: RemoteJob::new(self.client.clone(), job_id), @@ -4569,37 +4608,16 @@ impl BaseTable for RemoteTable { message: format!("failed to serialize refresh options: {e}"), })?; body["column"] = serde_json::json!(column); - self.apply_branch_body(&mut body); - let request = self - .client - .post(&format!("/v1/table/{}/backfill_column", self.identifier)) - .json(&body); - let (request_id, response) = self.send(request, true).await?; - // Preserve dependency errors: a deleted bound Function also returns 404. - let response = self - .client - .check_response(&request_id, response) + self.submit_refresh("backfill_column", body).await + } + + async fn resume_refresh( + &self, + job_id: &str, + ) -> Result> { + self.check_mutable().await?; + self.submit_refresh("resume_refresh", serde_json::json!({ "job_id": job_id })) .await - .inspect_err(|error| self.handle_error_invalidation(error))?; - let body = response.text().await.err_to_http(request_id.clone())?; - - #[derive(serde::Deserialize)] - struct BackfillResponse { - job_id: String, - } - let response: BackfillResponse = serde_json::from_str(&body).map_err(|e| Error::Http { - source: format!("Failed to parse backfill_column response: {}", e).into(), - request_id, - status_code: None, - })?; - - Ok(Job::new_typed(Box::new(FreshnessJob { - inner: RemoteJob::new(self.client.clone(), response.job_id), - freshness: self.freshness.clone(), - version: self.version.clone(), - tracked_result: TrackedJobResult::RefreshColumn, - freshness_request: self.snapshot_freshness_headers(), - }))) } async fn function_errors( @@ -12386,6 +12404,10 @@ mod tests { RefreshColumnOptions::default().max_concurrency(0), "max_concurrency", ), + ( + RefreshColumnOptions::default().max_job_attempts(0), + "max_job_attempts", + ), ( RefreshColumnOptions::default().max_executor_processes_per_worker(0), "max_executor_processes_per_worker", @@ -18802,6 +18824,33 @@ mod tests { assert_eq!(branch.current_branch(), Some("exp".to_string())); } + #[tokio::test] + async fn resume_refresh_preserves_the_branch_and_server_rejection() { + let table = Table::new_with_handler("my_table", |request| { + match request.url().path() { + "/v1/table/my_table/branches/list/" => http::Response::builder() + .status(200) + .body(r#"{"branches":{"exp":{"parentBranch":null,"parentVersion":1,"createAt":1,"manifestSize":1}}}"#) + .unwrap(), + "/v1/table/my_table/resume_refresh" => { + let payload: serde_json::Value = serde_json::from_slice(request.body().unwrap().as_bytes().unwrap()).unwrap(); + assert_eq!(payload, json!({"job_id":"failed","branch":"exp"})); + http::Response::builder() + .status(400) + .body("Check the external result before issuing another refresh") + .unwrap() + } + path => panic!("unexpected path {path}"), + } + }); + let branch = table.checkout_branch("exp", None).await.unwrap(); + let error = branch.resume_refresh("failed").await.unwrap_err(); + assert!( + error.to_string().contains("Check the external result"), + "{error}" + ); + } + #[tokio::test] async fn test_checkout_branch_missing() { let table = Table::new_with_handler("my_table", |_| { diff --git a/rust/lancedb/src/table.rs b/rust/lancedb/src/table.rs index 8ad9a0d65..0728484da 100644 --- a/rust/lancedb/src/table.rs +++ b/rust/lancedb/src/table.rs @@ -1021,6 +1021,15 @@ pub trait BaseTable: std::fmt::Display + std::fmt::Debug + Send + Sync { } self.refresh_column_async(column).await } + /// Resume a failed Function refresh on this table and branch. + async fn resume_refresh( + &self, + _job_id: &str, + ) -> Result> { + Err(Error::NotSupported { + message: "resuming a Function refresh requires LanceDB Enterprise".into(), + }) + } /// The per-row errors Function refreshes recorded on this table; see /// [`Table::function_errors`]. The default returns `NotSupported`. async fn function_errors( @@ -2424,6 +2433,25 @@ impl Table { self.inner.refresh_column_async(column.as_ref()).await } + /// Resume a failed Function refresh on this table and its current branch. + /// Returns the successor attempt. Its result includes the published table version. + /// + /// ``` + /// # use lancedb::Table; + /// # async fn resume(table: &Table, failed_job_id: &str) -> lancedb::Result<()> { + /// let job = table.resume_refresh(failed_job_id).await?; + /// let result = job.wait().await?; + /// println!("assigned {} rows", result.rows_assigned); + /// # Ok(()) + /// # } + /// ``` + pub async fn resume_refresh( + &self, + job_id: impl AsRef, + ) -> Result> { + self.inner.resume_refresh(job_id.as_ref()).await + } + /// Like [`Table::refresh_column_async`], with explicit refresh options. /// /// Set [`RefreshColumnOptions::batch_size()`] to cap the rows each remote diff --git a/rust/lancedb/src/table/refresh.rs b/rust/lancedb/src/table/refresh.rs index 15991dfe8..bf0c84e8f 100644 --- a/rust/lancedb/src/table/refresh.rs +++ b/rust/lancedb/src/table/refresh.rs @@ -233,6 +233,9 @@ pub struct RefreshColumnOptions { /// Only refresh the rows matching this SQL filter. Enterprise only. #[serde(rename = "where", skip_serializing_if = "Option::is_none")] pub where_clause: Option, + /// Total Function refresh attempts, including the initial job. Enterprise only. + #[serde(skip_serializing_if = "Option::is_none")] + pub max_job_attempts: Option, /// Override the Function's default user-code retry policy. Enterprise only. #[serde(skip_serializing_if = "Option::is_none")] pub retry_policy: Option, @@ -382,6 +385,12 @@ impl RefreshColumnOptions { self } + /// Set the total job attempt limit for automatic Function refresh recovery. + pub fn max_job_attempts(mut self, attempts: u32) -> Self { + self.max_job_attempts = Some(attempts); + self + } + /// Cap executor processes per Function worker at `processes`. pub fn max_executor_processes_per_worker(mut self, processes: u32) -> Self { self.max_executor_processes_per_worker = Some(processes); @@ -478,6 +487,7 @@ impl RefreshColumnOptions { ("row_timeout_seconds", self.row_timeout_seconds.is_some()), ("init_timeout_seconds", self.init_timeout_seconds.is_some()), ("num_workers", self.num_workers.is_some()), + ("max_job_attempts", self.max_job_attempts.is_some()), ( "max_executor_processes_per_worker", self.max_executor_processes_per_worker.is_some(), @@ -559,6 +569,11 @@ impl RefreshColumnOptions { message: "num_workers must be greater than zero".into(), }); } + if self.max_job_attempts == Some(0) { + return Err(Error::InvalidInput { + message: "max_job_attempts must be greater than zero".into(), + }); + } if self.max_executor_processes_per_worker == Some(0) { return Err(Error::InvalidInput { message: "max_executor_processes_per_worker must be greater than zero".into(),