mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
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.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user