Repository navigation
feat: create_index returns a Job handle - #3742
Conversation
wjones127
left a comment
There was a problem hiding this comment.
I'd like to understand a little more expected usage, and have various non-blocking suggestions.
| #[snafu(display("Job was cancelled"))] | ||
| JobCancelled, |
There was a problem hiding this comment.
suggestion: is there at least a job id that could be exposed here? That way if it's unknown why the job was cancelled we might be able to find the answer in logs.
| table | ||
| .create_index(&["vector"], Index::Auto) | ||
| .execute() | ||
| .await?; |
There was a problem hiding this comment.
question(blocking): what does this .await wait for? The job to start? or the completion of the job?
My initial idea was that Job itself implemented IntoFuture, but that might make an awkward API like:
table
.create_index(&["vector"], Index::Auto)
.execute()
.await?
.await?;(double await)
Alternatively the API now is:
table
.create_index(&["vector"], Index::Auto)
.execute()
.await?
.wait()
.await?;There was a problem hiding this comment.
.await here is awaiting submission of the job in the remote SDK. That is not the same as start or completion necessarily. In general I have been thinking of the usual calling style as less pipelined, like
let job = table.create_index(...).execute().await?
job.wait().await?;
// ... or
job.cancel().await?;
Chaining cancel() doesn't make much sense and having styles for the two seems a bit odd to me. What do you think, do you prefer the first?
| pub struct Job { | ||
| handle: Option<Box<dyn JobHandle>>, | ||
| } |
There was a problem hiding this comment.
thought: part of me wonders whether we need both layers. Maybe we should just return Box<dyn JobHandle>, and local operations just have a job handle where wait() returns immediately and cancel() errors.
There was a problem hiding this comment.
Returning Box<dyn JobHandle> seems like a less clean and less extensible public API than returning a concrete Job to me. What do you see as the advantage?
There was a problem hiding this comment.
I was seeing them as roughly equivalent to the user, and Box<dyn JobHandle> just seemed like strictly less code.
There was a problem hiding this comment.
suggestion: should we have a test that has two tasks one calling wait() and then another starting a bit later concurrently calling cancel(). What happens to the wait() future? Does that error? (This might be defined more by server behavior, I suppose.)
There was a problem hiding this comment.
yeah, defined by the server I think. We should add this test in enterprise though.
6ff4454 to
2a58d82
Compare
|
@wjones127 thanks for the review, updated/responded to your comments |
|
In the past we talked about having the remote API block in a similar fashion to the local API. In other words, making non-blocking an option, while blocking was the default. This PR seems to go in a different direction by continuing the existing behavior of treating enterprise as a special case with different rules from local. I also don't understand the thinking behind not exposing the job ID, can you clarify? It seems like something users would certainly want. Or did I misunderstand and the ID will be accessible through a future API? |
957ae8c to
74a737e
Compare
IndexBuilder::execute_async returns a Job exposing wait and cancel, leaving execute unchanged. Local tables build the index synchronously and return an already-done job. Remote tables read the job id the server returns from create_index and track it through the /v1/jobs API: wait polls describe until the job reaches a terminal state and cancel posts a cancellation. Servers that return no job id yield a done job. The job id is not exposed on the handle. Keeping execute as it is means a future release can give OSS tables a live job without silently changing what an existing call waits for. Co-Authored-By: Claude Fable 5 <[email protected]>
Parse the describe response into a typed struct with a JobState enum; states this client does not know count as still running. The job error variants carry the job id so a failure or cancellation can be traced in server logs. Rename Job::done to new_done. Co-Authored-By: Claude Fable 5 <[email protected]>
74a737e to
e12a8f8
Compare
create_index is unchanged. create_index_async returns an AsyncJob on async tables and a Job on sync ones, each with wait and cancel. Job failures raise JobFailedError and cancellations JobCancelledError. Co-Authored-By: Claude Fable 5 <[email protected]>
createIndex is unchanged. createIndexAsync returns a Job exposing wait and cancel. Co-Authored-By: Claude Fable 5 <[email protected]>
e12a8f8 to
29dc516
Compare
execute_async on a local table now spawns the index build instead of building it inline, so wait and cancel do the same thing they do against a server: wait resolves when the build finishes, and cancel aborts it. Input is validated before spawning so bad arguments still surface from execute_async itself. Job ids are server-side, so the error variants carry an optional one. Co-Authored-By: Claude Fable 5 <[email protected]>
02447e1 to
192c11a
Compare
Job::id returns the id the server assigned, for correlating with server logs or the jobs API. Jobs that run in this process have none and return None. The value is opaque; resuming a job from an id is not supported. Co-Authored-By: Claude Fable 5 <[email protected]>
| #[async_trait] | ||
| impl JobHandle for SpawnedJob { | ||
| async fn wait(&self) -> Result<()> { | ||
| let Some(task) = self.task.lock().await.take() else { |
There was a problem hiding this comment.
issue (blocking): self.task.lock().await.take() means only the first caller of wait() on a given Job ever observes the real outcome — every subsequent (or concurrently racing) caller gets a spurious Ok(()) even if the build actually failed or was cancelled; acceptance criterion: add a test with two tasks both awaiting the same Job::wait() (or one wait() racing a cancel()) and make every caller see the correct terminal result, e.g. by storing the result behind a tokio::sync::watch/OnceCell instead of consuming the JoinHandle.
There was a problem hiding this comment.
I'm open to multiple ways to solve this, but I think the current behavior seems wrong. We could either make it impossible for multiple calls to wait() to happen or else support multiple callers.
There was a problem hiding this comment.
added in 070c096. Multiple callers are now supported and the same result is returned to all via a tokio::sync::watch.
| ) | ||
| ) | ||
|
|
||
| def create_index_async( |
There was a problem hiding this comment.
question (non-blocking): Local Table.create_index_async exposes replace, but this remote counterpart doesn't — is that intentional (matching submit_create_index in Rust, which never reads index.replace for remote tables), or a gap that should be closed for parity?
| async def test_create_index_async_returns_done_job(some_table: AsyncTable): | ||
| job = await some_table.create_index_async("id", config=BTree()) | ||
| await job.wait() | ||
| await job.cancel() |
There was a problem hiding this comment.
nitpick: Add an assertion that the index actually exists after wait() so this test can't pass if index creation silently no-ops.
| await job.cancel() | |
| job = await some_table.create_index_async("id", config=BTree()) | |
| await job.wait() | |
| assert len(await some_table.list_indices()) == 1 | |
| await job.cancel() |
| pub struct Job { | ||
| handle: Option<Box<dyn JobHandle>>, | ||
| } |
There was a problem hiding this comment.
I was seeing them as roughly equivalent to the user, and Box<dyn JobHandle> just seemed like strictly less code.
| const job = await tbl.createIndexAsync("vec"); | ||
| expect(job.id).toBeNull(); | ||
| await job.wait(); | ||
| await job.cancel(); |
There was a problem hiding this comment.
question(blocking): is the behavior of cancel after completion to silently pass? Maybe worth a comment here that's what's going on. It does seem consistent with some other systems that cancelling something that finished silently succeeds.
There was a problem hiding this comment.
yes, that's intended. I'll make sure it's documented, thanks.
| #[serde(other)] | ||
| Other, |
There was a problem hiding this comment.
suggestion: I wonder if this could somehow be:
| #[serde(other)] | |
| Other, | |
| #[serde(other)] | |
| Other(String), |
so we an print it.
wait took the JoinHandle, so only the first caller saw the real outcome and later ones were told the job succeeded even when it had failed or been cancelled. A second task now watches the first and publishes the outcome, which every waiter reads. Watching also gives an aborted job an outcome, which it previously only had for the caller that consumed it. Co-Authored-By: Claude Fable 5 <[email protected]>
An unknown state was collapsed into a unit variant, so a client polling a state it does not know had nothing to report. It now carries the name and is logged while polling continues. Co-Authored-By: Claude Fable 5 <[email protected]>
The local counterpart takes it, and the remote create_index already accepts it. Co-Authored-By: Claude Fable 5 <[email protected]>
Also note in the nodejs test that cancelling a finished job is a no-op. Co-Authored-By: Claude Fable 5 <[email protected]>
The method was only on the concrete tables, so it was missing from the abstract base the docs point at, and the job types were not importable from the package. Co-Authored-By: Claude Fable 5 <[email protected]>
wjones127
left a comment
There was a problem hiding this comment.
On piece of non-blocking feedback. Nice work on this!
| tokio::spawn(async move { | ||
| let outcome = match task.await { | ||
| Ok(Ok(())) => Outcome::Succeeded, | ||
| Ok(Err(err)) => Outcome::Failed(err.to_string()), |
There was a problem hiding this comment.
issue (non-blocking): Local job failures now always collapse to a generic Error::JobFailed{message}, losing the original error's variant (previously Ok(result) => result preserved it) — necessitated by Outcome needing Clone. Consider Outcome::Failed(Arc<Error>) instead of stringifying, so callers can still match on the underlying error kind.
There was a problem hiding this comment.
I'm a little bit stumped on this because the remote SDK won't be able to do that with the same fidelity as local. I wonder if we may need some kind of error protocol in the public API to address this correctly.
There was a problem hiding this comment.
actually, I guess this same problem must exist in a lot of places in the SDK so it shouldn't be a design blocker here. We can afford some divergence and standardize it all later.
There was a problem hiding this comment.
Added more info to the failure message and attached the source error for the local case.
A failed job reported "job reached the FAILED state", a string invented to satisfy a non-optional message field, and locally the real error was stringified so its type was lost. JobFailed now carries a JobFailure whose fields are absent when the backend cannot supply them: a local job keeps the error it failed with, a remote job carries what the server reported, and a server that reports nothing yields "Job <id> failed" with nothing invented. The shape is the same on both backends so callers need not branch. Phase and retryability stay absent locally, since everything reaching wait() is the build stage and classifying retryability here could disagree with the server. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Adds job operations to the connection surface, building on the Job handle from #3742: job(id), list_jobs, get_job, cancel_job, and job_history, plus a non-blocking Job.status(). Implemented on the Database trait (defaulting to NotSupported), the remote backend (/v1/jobs), and the Python and Node bindings; job_history returns Arrow batches. errors() and progress() are not included. Tested with mocked endpoints in all three languages. --------- Co-authored-by: Claude Fable 5 <[email protected]>
IndexBuilder::execute now returns a Job with wait and cancel methods. Local tables build the index synchronously and return an already-done job. Remote tables read the job id the server returns from create_index and track it through the /v1/jobs API: wait polls describe until the job reaches a terminal state and cancel posts a cancellation. Servers that return no job id yield a done job, so behavior against older servers is unchanged. The job id is not exposed on the handle.
The Python and TypeScript bindings keep their current signatures and discard the handle; exposing Job there is left to follow-ups.