Repository navigation
Conversation
Signed-off-by: lance6716 <lance6716@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
lance6716
left a comment
There was a problem hiding this comment.
C-only review notes for this draft. The first two comments are request-lifetime safety issues; the others cover cancellation, observability, tests, and maintainability.
Signed-off-by: lance6716 <lance6716@gmail.com>
| .cancel_inflight | ||
| .load(Ordering::Acquire) | ||
| { | ||
| let request = unsafe { &*request_ptr }; |
There was a problem hiding this comment.
This post-spawn dereference can race with a fast completion. The C contract allows the callback to destroy the request; after it returns, finalize_request can release the last references before the submit thread reaches this block (when cancel_inflight is true). Please set the cancellation state before spawning, or retain an independent submit-side reference until all post-spawn access is finished.
| .requests | ||
| .lock() | ||
| .unwrap_or_else(|poisoned| poisoned.into_inner()) | ||
| .clone(); |
There was a problem hiding this comment.
Cloning this vector copies bare request addresses without retaining their states. A request can finish, be removed, and be freed before the loop dereferences the copied address, causing a use-after-free. tikv_async_client_destroy has the same pattern. Please keep each request alive while marking cancellation, or avoid traversing these pointers.
| || keepalive.lifecycle.cancel_inflight.load(Ordering::Acquire) | ||
| }; | ||
|
|
||
| let (status, output, error_message) = match result { |
There was a problem hiding this comment.
Cancellation is only checked after the underlying future finishes, so a write may already have taken effect when the callback reports CANCELLED. The Ok(Err(error)) arm also reports ERROR despite a cancellation request, contrary to the stronger guarantee in the C header. Please settle and document the terminal-status rule, including partial batch effects, and test both success and error after cancellation.
| })) as *mut tikv_async_request_t | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
The current 12 unit tests do not exercise an accepted request's concurrent lifecycle. Please add deterministic tests for destruction inside the callback, shutdown racing with completion, exactly-once callback delivery, and cancellation outcomes. A C compile-and-link smoke check in CI would also protect the public ABI.
| fn collect_metrics_snapshot() -> MetricsSnapshot { | ||
| let mut samples = Vec::new(); | ||
|
|
||
| for family in prometheus::gather() { |
There was a problem hiding this comment.
This gathers the whole process-wide registry, but the C sample retains only the type label and the match below drops gauges, summaries, and other metric types. Two series differing in another label become indistinguishable. Please either narrow the public contract to known client-rust counter/histogram families or preserve the full label/type information; the C header should state whichever scope is chosen.
| let mut completion = lock_completion(request); | ||
| completion.complete = true; | ||
| completion.callback_running = true; | ||
| completion.completion_status = Some(status); |
There was a problem hiding this comment.
The existing metrics describe underlying TiKV/PD RPCs, but this async binding has no outcome or in-flight metric for accepted/rejected submissions, cancellation, panics, or callback completion. An RPC may be counted as successful even when the FFI reports CANCELLED. Please consider a small set of binding-level counters and an in-flight gauge so operators can reconcile the two layers.
|
|
||
| assert_eq!(raw_get_total, Some(3.0)); | ||
| assert_eq!(raw_get_duration_count, Some(1.0)); | ||
| assert!(saw_inf_bucket); |
There was a problem hiding this comment.
This test checks that an infinite histogram bucket exists, but not its cumulative value, finite bucket values, or the histogram sum. Asserting these with a known observation, plus the intended label behavior, would catch incorrect monitoring output rather than only missing samples.
Summary
This extracts the C layer from draft #571. The C++ wrapper remains in that draft for follow-up work.
Validation
cargo test -p tikv-client-rust-c --lib(12 passed)cargo fmt --all -- --checkclang -std=c11 -Wall -Wextra -Werror -fsyntax-only -Ibindings/c/include bindings/c/examples/raw_async_demo.cThe TiKV-backed example was not run in this split. This PR remains a draft while the inline review findings on request lifetime, cancellation semantics, and metrics are addressed.