mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
feat: report capacity waits in function refresh job status (#5154)
An Enterprise Function refresh can spend time waiting for execution workers. Applications polling `job.status()` currently see `running` during that wait. Return `waiting_for_capacity` when the server reports that phase for an active Function refresh. The next status request reports `running` when execution resumes. Applications can use `job.wait()` to wait through both states until completion. Rust, Python and Node read the phase from the existing job description response. ## Validation Two HTTP regression tests exercise the public job handle. They cover the wait, work resuming, completion after another wait, a stale phase at completion, queued and paused refreshes, other job types, and servers that omit the phase. The Rust CI remote job runs these tests.
This commit is contained in:
@@ -449,8 +449,8 @@ Select this exact attempt's pinned successor. Requires backend support.
|
||||
status(): Promise<string>
|
||||
```
|
||||
|
||||
The operation's current lifecycle state: "running", "finished", "failed",
|
||||
or "cancelled".
|
||||
The current status, usually "running", "finished", "failed", or "cancelled".
|
||||
A Function refresh waiting for execution workers reports "waiting_for_capacity".
|
||||
|
||||
A point snapshot; unlike [Job.wait](Job.md#wait) it does not block or reject on a
|
||||
terminal failure state. Also refreshes the getters above.
|
||||
|
||||
@@ -106,10 +106,10 @@ print(result, job.spec())
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
The four lifecycle strings below are the usual SDK contract; newer server
|
||||
states may pass through an older client. Do not infer execution progress from
|
||||
`state` alone. Structured progress methods and queue fields require matching
|
||||
SDK/server support; see [refresh admission](/feature-engineering/refresh-column#admission).
|
||||
`job.state()` reports the last observed lifecycle state, usually `running`,
|
||||
`finished`, `failed`, or `cancelled`. Newer server states may pass through an
|
||||
older client. For execution progress and queue details, use `job.progress()`
|
||||
with a supporting SDK and server. See [refresh admission](/feature-engineering/refresh-column#admission).
|
||||
|
||||
## Submit and wait for a job {#waiting}
|
||||
|
||||
@@ -120,11 +120,12 @@ SDK/server support; see [refresh admission](/feature-engineering/refresh-column#
|
||||
result. If it failed or was cancelled, inspect the failure details and any
|
||||
results it committed before stopping.
|
||||
|
||||
In Python, `job.status()` returns the current state:
|
||||
In Python, `job.status()` reports the current status.
|
||||
|
||||
| State | Meaning |
|
||||
| Status | Meaning |
|
||||
| --- | --- |
|
||||
| `running` | The operation is in progress. |
|
||||
| `waiting_for_capacity` | An Enterprise Function refresh is waiting for execution workers. This status is nonterminal. It returns to `running` when execution resumes. |
|
||||
| `finished` | The operation completed successfully. |
|
||||
| `failed` | The operation failed. |
|
||||
| `cancelled` | The operation was cancelled. |
|
||||
|
||||
@@ -251,8 +251,8 @@ export class Job<T = void> {
|
||||
}
|
||||
|
||||
/**
|
||||
* The operation's current lifecycle state: "running", "finished", "failed",
|
||||
* or "cancelled".
|
||||
* The current status, usually "running", "finished", "failed", or "cancelled".
|
||||
* A Function refresh waiting for execution workers reports "waiting_for_capacity".
|
||||
*
|
||||
* A point snapshot; unlike {@link Job.wait} it does not block or reject on a
|
||||
* terminal failure state. Also refreshes the getters above.
|
||||
|
||||
+2
-2
@@ -106,8 +106,8 @@ impl Job {
|
||||
self.inner.execution_epoch()
|
||||
}
|
||||
|
||||
/// The operation's current lifecycle state: "running", "finished",
|
||||
/// "failed", or "cancelled".
|
||||
/// The current status, usually "running", "finished", "failed", or "cancelled".
|
||||
/// A Function refresh waiting for execution workers reports "waiting_for_capacity".
|
||||
///
|
||||
/// A point snapshot; unlike {@link Job.wait} it does not block or reject
|
||||
/// on a terminal failure state. States a newer server reports that this
|
||||
|
||||
@@ -316,8 +316,9 @@ class AsyncJob(Generic[T]):
|
||||
return self._inner.id if self._inner is not None else None
|
||||
|
||||
async def status(self) -> str:
|
||||
"""The operation's current lifecycle state: "running", "finished",
|
||||
"failed", or "cancelled".
|
||||
"""Return the current status, usually "running", "finished", "failed",
|
||||
or "cancelled". A Function refresh waiting for execution workers reports
|
||||
"waiting_for_capacity".
|
||||
|
||||
A point snapshot; unlike `wait` it does not block or raise on a
|
||||
terminal failure state. States a newer server reports that this
|
||||
@@ -384,8 +385,7 @@ class AsyncJob(Generic[T]):
|
||||
Queue metadata and counters are included when supplied by the server.
|
||||
Older servers may
|
||||
omit counters, and in-process operations return ``None``. A missing
|
||||
counter is unknown rather than zero. This is additive to :meth:`status`,
|
||||
whose string contract is unchanged.
|
||||
counter is unknown rather than zero.
|
||||
"""
|
||||
if self._inner is None:
|
||||
return None
|
||||
@@ -1070,8 +1070,9 @@ class Job(Generic[T]):
|
||||
return self._inner._id if self._inner is not None else None
|
||||
|
||||
def status(self) -> str:
|
||||
"""The operation's current lifecycle state: "running", "finished",
|
||||
"failed", or "cancelled".
|
||||
"""Return the current status, usually "running", "finished", "failed",
|
||||
or "cancelled". A Function refresh waiting for execution workers reports
|
||||
"waiting_for_capacity".
|
||||
|
||||
See :meth:`AsyncJob.status`.
|
||||
"""
|
||||
|
||||
+15
-6
@@ -516,17 +516,25 @@ where
|
||||
};
|
||||
match handle.describe().await {
|
||||
Ok(description) => {
|
||||
let state = description.state.clone();
|
||||
let mut cache = self.cache_write();
|
||||
cache.state = Some(state.clone());
|
||||
cache.state = Some(description.state.clone());
|
||||
cache.lifecycle_state = Some(
|
||||
description
|
||||
.lifecycle_state
|
||||
.clone()
|
||||
.unwrap_or_else(|| JobState::from(state.as_str())),
|
||||
.unwrap_or_else(|| JobState::from(description.state.as_str())),
|
||||
);
|
||||
let status = if cache.lifecycle_state == Some(JobState::InProgress)
|
||||
&& description.job_type == "function_refresh"
|
||||
&& description.paused_at_millis.is_none()
|
||||
&& description.phase.as_deref() == Some("waiting_for_capacity")
|
||||
{
|
||||
"waiting_for_capacity".to_owned()
|
||||
} else {
|
||||
description.state.clone()
|
||||
};
|
||||
cache.description = Some(description);
|
||||
Ok(state)
|
||||
Ok(status)
|
||||
}
|
||||
// An in-process job knows its own state and nothing more.
|
||||
Err(Error::NotSupported { .. }) => {
|
||||
@@ -540,8 +548,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// The operation's current lifecycle state: "running", "finished",
|
||||
/// "failed", or "cancelled".
|
||||
/// The current status, usually "running", "finished", "failed", or "cancelled".
|
||||
/// A running Function refresh reports "waiting_for_capacity" while it
|
||||
/// waits for execution workers. [`Job::wait`] continues polling during this wait.
|
||||
///
|
||||
/// A point snapshot; unlike [`Job::wait`] it does not block, raise on a
|
||||
/// terminal failure state, or retry. States a newer server reports that
|
||||
|
||||
@@ -5126,6 +5126,75 @@ mod tests {
|
||||
));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn function_refresh_status_tracks_capacity_without_ending_wait() {
|
||||
let polls = Arc::new(AtomicUsize::new(0));
|
||||
let count = polls.clone();
|
||||
let conn = Connection::new_with_handler(move |request| {
|
||||
assert_eq!(request.url().path(), "/v1/jobs/describe");
|
||||
// Open, status while waiting, status after admission, another wait
|
||||
// observed inside wait(), and finally a successful completion.
|
||||
let (state, phase) = match count.fetch_add(1, Ordering::SeqCst) {
|
||||
0 | 1 | 3 => ("IN_PROGRESS", "waiting_for_capacity"),
|
||||
2 => ("IN_PROGRESS", "running"),
|
||||
_ => ("SUCCEEDED", "waiting_for_capacity"),
|
||||
};
|
||||
http::Response::builder()
|
||||
.status(200)
|
||||
.body(
|
||||
serde_json::json!({
|
||||
"job_id": "job-1", "job_type": "function_refresh",
|
||||
"job_state": state, "phase": phase, "creation_ms": 1
|
||||
})
|
||||
.to_string(),
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
let job = conn.open_job("job-1").await.unwrap();
|
||||
assert_eq!(job.status().await.unwrap(), "waiting_for_capacity");
|
||||
assert_eq!(job.state().as_deref(), Some("running"));
|
||||
assert_eq!(job.status().await.unwrap(), "running");
|
||||
job.wait().await.unwrap();
|
||||
assert_eq!(job.status().await.unwrap(), "finished");
|
||||
assert!(polls.load(Ordering::SeqCst) >= 6);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn capacity_status_requires_an_active_function_refresh() {
|
||||
for (job_type, lifecycle, phase, paused_at) in [
|
||||
(
|
||||
"create_index",
|
||||
"in_progress",
|
||||
Some("waiting_for_capacity"),
|
||||
None,
|
||||
),
|
||||
(
|
||||
"function_refresh",
|
||||
"in_progress",
|
||||
Some("waiting_for_capacity"),
|
||||
Some(42),
|
||||
),
|
||||
(
|
||||
"function_refresh",
|
||||
"queued",
|
||||
Some("waiting_for_capacity"),
|
||||
None,
|
||||
),
|
||||
("function_refresh", "in_progress", None, None),
|
||||
] {
|
||||
let conn = Connection::new_with_handler(move |_| {
|
||||
http::Response::builder().status(200).body(
|
||||
serde_json::json!({
|
||||
"job_id": "job-1", "job_type": job_type, "job_state": "IN_PROGRESS",
|
||||
"lifecycle_state": lifecycle, "phase": phase, "paused_at_millis": paused_at
|
||||
}).to_string()
|
||||
).unwrap()
|
||||
});
|
||||
let job = conn.open_job("job-1").await.unwrap();
|
||||
assert_eq!(job.status().await.unwrap(), "running");
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_conn_job_waits_to_done() {
|
||||
let polls = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
Reference in New Issue
Block a user