Repository navigation
[TENT] Add a blocking waitTransfer entry point - #5415
Conversation
421633e to
592c93a
Compare
| std::vector<TransferStatus>* status_list = nullptr, | ||
| uint64_t timeout_ms = 0); | ||
|
|
||
| Status transferSync(const std::vector<Request>& request_list, |
There was a problem hiding this comment.
Recommend to use a better name e.g. submitAndWaitTransfer
6b8704b to
fe82305
Compare
| CHECK_STATUS(getTransferStatus(batch_id, statuses)); | ||
| for (size_t task_id = 0; task_id < statuses.size(); ++task_id) | ||
| if (statuses[task_id].s == PENDING) | ||
| (void)cancelTransfer(batch_id, task_id); |
There was a problem hiding this comment.
Could we stop dispatching this batch before starting timeout cleanup?
Cancelling a queued owner calls refillDispatchWindow(), which can submit another request from the same batch before this loop reaches it. The status collection before the loop and progressBatch() during settling can also refill the window.
Could we prevent new dispatches for this batch while letting requests already in flight drain? A regression test could assert that timeout cleanup submits no additional requests from this batch.
There was a problem hiding this comment.
Right — cancelling a queued owner refills the window and could start another request of the same batch. waitTransfer now stops the batch's dispatches before it collects statuses:
- new
cancelQueuedOwners(batch)cancels the batch's queued owners and does not refill the window per owner; - the timeout path is
cancelQueuedOwners->getTransferStatus-> cancel the tasks still in flight -> onerefillDispatchWindow(). By then the batch has no queued owners left, so the cleanup polls can only hand window slots to other batches; CancelQueuedOwnersBeforePollingKeepsBatchIdleintent_runtime_queue_dispatch_testpins this: one-owner dispatch window, the first request completes during the cleanup poll, the second staysCANCELED, and the batch issues no further transport submission.
There was a problem hiding this comment.
Follow-up: the regression test now drives the public waitTransfer (1 ms timeout, the first post-deadline poll returns PENDING), so it checks that cleanup submits no second request; submit_calls stays 1.
fe82305 to
0f531ec
Compare
0f531ec to
2b39e1e
Compare
Add TransferEngine::waitTransfer(), which blocks until every task in a submitted batch reaches a terminal state and reports one status per request. On timeout it stops the batch from dispatching further requests: queued owners are canceled without refilling the dispatch window, then the tasks already in flight are canceled and the call waits briefly for the cancellations to land. A PENDING status means the engine may still touch that request's memory. Bind it to Python as wait_transfer() and cover it with a test that submits a batch, waits for it, and checks both transfer directions. Rename the internal submit-and-wait helper to submitAndWaitTransfer so it is not mistaken for the new blocking wait entry point. Signed-off-by: CAICAIIs <3360776475@qq.com>
2b39e1e to
75c7831
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
staryxchen
left a comment
There was a problem hiding this comment.
Good job. The impl is good to me, but some parts could be further simplified I think.
| self.assertEqual(write_status[0].bytes, len(payload)) | ||
| self.assertEqual(ctypes.string_at(server_addr, len(payload)), payload) | ||
|
|
||
| ctypes.memset(client_addr + read_offset, 0, len(payload)) |
There was a problem hiding this comment.
The write round trip already shows the binding works: status list length, state, bytes, and GIL release. The READ half re-tests the TCP transport rather than any new wait_transfer path, so I'd trim it to keep the test lean.
There was a problem hiding this comment.
Thanks — trimmed to the write round trip; the READ half only re-tested the TCP transport.
| CHECK_STATUS(getTransferStatus(batch_id, statuses)); | ||
| if (status_list) return Status::OK(); | ||
| for (const auto& task_status : statuses) | ||
| if (task_status.s != COMPLETED) | ||
| return Status::InternalError( | ||
| "Transfer via stage buffer failed" LOC_MARK); | ||
| return Status::OK(); |
There was a problem hiding this comment.
When status_list is null, this re-reads every task status and loops over them, but the last progressBatch already gave us the aggregate: getBatchStatus only reports COMPLETED when every task succeeded. Could we keep the last overall_status and check overall_status.s == COMPLETED here instead? Then local_statuses can go, and the per-task fetch only happens when the caller asked for it.
There was a problem hiding this comment.
Thanks — now uses the last progressBatch result and only fetches per-task statuses when status_list is set.
| if (request_list.empty()) | ||
| return Status::InvalidArgument( | ||
| "submitAndWaitTransfer requires at least one request" LOC_MARK); |
There was a problem hiding this comment.
This changes behavior: an empty list used to reach total_tasks == 0 and come back COMPLETED, and now it's an error. The only production caller, onDelegate, always passes one request, so the check never fires. I'd drop it, or move it to its own PR if we actually want to reject empty lists.
There was a problem hiding this comment.
Thanks — dropped the check; an empty list keeps the upstream path and comes back as completed.
| } | ||
| for (const auto owner_id : owner_ids) { | ||
| auto queued_it = queued_owners_.find(owner_id); | ||
| if (queued_it == queued_owners_.end()) continue; |
There was a problem hiding this comment.
owner_ids was just collected from queued_owners_ under the same progress_mutex_, and nothing in this loop erases entries other than the owner being canceled, so this find can't miss. The continue is dead code and can go (indexing via find is still fine).
There was a problem hiding this comment.
Thanks — collected the owners already filtered, so the second lookup is gone.
| if (canceled) { | ||
| const auto settle_deadline = | ||
| std::chrono::steady_clock::now() + kCancelSettleTimeout; | ||
| for (uint64_t poll_count = 0; | ||
| std::chrono::steady_clock::now() < settle_deadline; ++poll_count) { | ||
| TransferStatus overall_status; | ||
| CHECK_STATUS(progressBatch(batch_id, overall_status)); | ||
| if (overall_status.s != PENDING) break; | ||
| waitBeforeNextPoll(poll_count); | ||
| } | ||
| waitBeforeNextPoll(poll_count); | ||
| } |
There was a problem hiding this comment.
With this settle loop, a call can block for up to timeout_ms + 250ms, and the extra 250 ms isn't configurable. The contract already says a PENDING entry means the engine may still touch that request's memory, so a caller can keep polling on its own. Is there a concrete caller that needs this built in? If not, I'd return right after canceling: same semantics, simpler code, and the timeout means what it says.
There was a problem hiding this comment.
Thanks — removed the settle window; the call returns right after canceling and reporting, and PENDING keeps its documented meaning.
| if (!batch_id) | ||
| return Status::TooManyRequests( | ||
| "No free batch slot for a synchronous transfer" LOC_MARK); |
There was a problem hiding this comment.
The clearer error is nice, but before this change submitTransfer already rejected a zero batch id, so this isn't needed for waitTransfer. Fine to keep if you want it, though it would sit better in a separate cleanup.
There was a problem hiding this comment.
Thanks — kept it; it only covers a failed allocateBatch, which submitTransfer cannot see.
| engine.unregisterLocalMemory(buffer.data(), buffer.size()).ok()); | ||
| } | ||
|
|
||
| TEST(RuntimeQueueDispatch, TimeoutDoesNotDispatchQueuedRequestsOfBatch) { |
There was a problem hiding this comment.
Good targeted test. One gap: nothing covers the main status_list contract, where a failed task is reported in the list while the call itself returns OK, and the null-status_list mode fails instead. A small FakeTransport case returning FAILED for one request would cover both, and is worth more than the extra Python READ coverage.
There was a problem hiding this comment.
Thanks — added ReportsFailedTaskOnlyWhenStatusListIsRequested: a FAILED task is reported in the list with an OK call, and the call fails without status_list.
|
Minor: the title still says "Add a blocking transferSync entry point", but the new API is |
Cancel the batch's queued owners and ask its in-flight tasks to stop, then report the per-request statuses without a fixed settle window. Use the overall status from the last progressBatch() when status_list is null, restore the upstream path for an empty request list, and filter in-dispatch-window owners while collecting them in cancelQueuedOwners(). Trim the Python test to the write direction and add a dispatch test that a failed task is reported through status_list instead of failing the call. Signed-off-by: CAICAIIs <3360776475@qq.com>
|
Thanks — title updated to |
| "No free batch slot for a synchronous transfer" LOC_MARK); | ||
| BatchGuard batch_guard(*this, batch_id); | ||
| CHECK_STATUS(submitTransfer(batch_id, request_list)); | ||
| CHECK_STATUS(waitTransfer(batch_id)); |
There was a problem hiding this comment.
Nit: before this change, the failure path did CHECK_STATUS(batch_guard.reset()), so a failed freeBatch was returned to the caller. Now when waitTransfer fails, the guard's destructor frees the batch and a freeBatch error only shows up as a WARNING log. Returning the transfer error is arguably more useful, so this may be intended. I'm just flagging the behavior change.
There was a problem hiding this comment.
This is intentional: the transfer outcome is what the caller acts on, so the guard logs a failed free instead of replacing it.
| const auto deadline = std::chrono::steady_clock::now() + | ||
| std::chrono::milliseconds(timeout_ms); |
There was a problem hiding this comment.
std::chrono::milliseconds(timeout_ms) converts the uint64_t to a signed 64-bit count, and adding it to steady_clock::now() converts again to nanoseconds, so large values overflow. I checked locally: UINT64_MAX and 1 << 62 both give a deadline earlier than now. A caller that passes UINT64_MAX to mean "wait forever" (or wait_transfer(timeout_ms=2**64 - 1) from Python) times out after the first poll and gets the batch canceled. Could we clamp it, e.g. treat anything above some bound such as std::chrono::hours(24 * 365) like 0, or compute the deadline with saturation?
There was a problem hiding this comment.
Fixed in 36e522c: timeouts beyond a year now saturate to an unbounded wait, with a regression test. Thanks.
| if (!status_list) | ||
| return Status::InternalError( | ||
| "Transfer via stage buffer failed" LOC_MARK); |
There was a problem hiding this comment.
With timeout_ms != 0 and no status_list, a timeout comes back as the same InternalError as a failed transfer. The caller can't tell the two apart, and can't tell whether the engine may still touch the buffers, since only a PENDING entry in status_list says that. The message "Transfer via stage buffer failed" also reads oddly now that this is a public API. No internal caller passes a timeout, so nothing hits this today. Could the timeout return its own status (e.g. a timeout code with a neutral message), or could the header say that callers using a timeout without status_list must call getTransferStatus before releasing memory?
There was a problem hiding this comment.
Fixed in 36e522c: a timeout without status_list now returns TimedOut, and the header tells callers to query the batch before reusing the buffers. Thanks.
waitTransfer() returned InternalError when a timeout expired without a status_list, so callers could not tell a timeout from a transfer failure. Return a dedicated TimedOut status instead and document that such callers must query the batch before reusing the buffers. Clamp timeouts beyond a year to an unbounded wait; converting the larger unsigned value to the clock duration wrapped the deadline into the past and canceled the batch on the first poll. Signed-off-by: CAICAIIs <3360776475@qq.com>
The unknown-batch case only re-checked the generic InvalidArgument mapping, which the C++ status contract already covers. Keep the round trip that exercises the new binding end to end. Signed-off-by: CAICAIIs <3360776475@qq.com>
* upstream/main: (95 commits) [Bugfix][TENT] Honor EFA protocol in classic shim (kvcache-ai#5280) [Doc] Add the AMD ATOM integration and homepage blog posts (kvcache-ai#5380) [Store-RS] Fence Store-RS eviction and delete by allocation identity (kvcache-ai#5243) fix: preserve integer map keys in structured non-tensor reads (kvcache-ai#4603) [Bugfix][TE][Store] Fix CXI transport so Mooncake Store works over Slingshot (kvcache-ai#5454) [Store] Coalesce removal KV events before publishing (kvcache-ai#5467) [CI/Build][Doc] Ship EFA in the default wheels only (kvcache-ai#5322) [CI/Build][Doc] Ship EFA in the default wheels only (kvcache-ai#5322) [Store] Shard LeaseEvictionIndex and parallelize memory eviction (kvcache-ai#5448) [TransferEngine] Open intra-node NVLink IPC mappings on the source buffer's device (kvcache-ai#5443) [Bugfix][TENT] Temporarily disable smart scheduling by default (kvcache-ai#5445) [TENT] Add a blocking waitTransfer entry point (kvcache-ai#5415) [EP] Add planned runtime scaling to ElasticBuffer (kvcache-ai#5376) [Store] Persist object upload and cleanup recovery records (kvcache-ai#5310) [TransferEngine] Add opt-in high-priority HIP copy streams (kvcache-ai#5005) [Store] feat: break master key count and value bytes down by configurable key groups (kvcache-ai#5393) [Store] Populate HugeTLB EFA segments in parallel (kvcache-ai#5457) [CI/Build] Prevent OOM in PR unit-tests build on GitHub-hosted runners (kvcache-ai#5420) [Store] Add automatic pipelined gather to ranged reads (kvcache-ai#4502) [Store] Add property tests for structured member byte-range plans (kvcache-ai#5328) ...
Summary
Callers that need to block on a batch currently replay TENT's poll loop themselves: backoff, cancellation and per-task status mapping all live outside the engine. This adds one blocking entry point on an already submitted batch:
waitTransfer(batch_id, status_list = nullptr, timeout_ms = 0)waits until every task in the batch terminates.status_listit receives oneTransferStatusper request, in request order; a failed task is reported there instead of failing the call.status_listthe call fails if any task did not complete. The stage-buffer delegate path uses that mode.timeout_msbounds the wait (0 waits forever). On timeout the batch's queued tasks are canceled before any further polling, and the dispatch window is not refilled per cancellation, so the cleanup polls cannot pull more requests of the timed-out batch out of the queue. Tasks already in flight are then asked to stop, and the call returns one status per request; an entry that is stillPENDINGmeans the engine may still touch that request's memory.status_listreturnsTimedOut, because only the batch query can tell whether the engine still touches the buffers. Timeouts beyond a year saturate to an unbounded wait instead of wrapping the deadline.tent.TransferEngine.wait_transfer(batch_id, timeout_ms=0)returns the status list and releases the GIL while waiting. Submission stays asynchronous throughallocateTransferBatchandsubmitTransfer.submitAndWaitTransfer, so the two blocking paths stay distinguishable at the call site.Testing
tentpyon Linux x86_64 (gcc 11.4, RDMA and CUDA enabled).python mooncake-transfer-engine/tent/tests/test_python_wait_transfer.py -v— one test passes: a write round trip that submits a batch, waits on it and checks the returned status list, bytes and payload. The test is registered with ctest next totent_python_guards_test.tent_runtime_queue_dispatch_testcovers the timeout path's dispatch ordering: with a one-owner dispatch window, the first request completes during the cleanup poll, the second staysCANCELED, and the batch issues no further transport submission. It also covers thestatus_listcontract (aFAILEDtask is reported in the list while the call returns OK, and withoutstatus_listthe same batch fails the call), a timeout withoutstatus_list(TimedOut), and a near-uint64timeout that must not wrap the deadline.