Repository navigation
Conversation
|
[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.
Pre-PR review: the first two inline comments identify request-lifetime races to fix before marking this draft ready. The remaining comments cover cancellation semantics, tests, structure, and documentation.
| .cancel_inflight | ||
| .load(Ordering::Acquire) | ||
| { | ||
| let request = unsafe { &*request_ptr }; |
There was a problem hiding this comment.
This dereference can race with a fast completion. The C contract allows the callback to destroy the request; after that callback, finalize_request can release the last references before this submit thread reaches the block (when cancel_inflight is true). Please set the cancellation state before spawning, or hold a separate submit-side reference until all post-spawn access is finished.
| .lock() | ||
| .unwrap_or_else(|poisoned| poisoned.into_inner()) | ||
| .clone(); | ||
| for request_addr in requests { |
There was a problem hiding this comment.
Cloning requests copies bare addresses without retaining the request states. A request may finish, be removed, and be destroyed before the loop dereferences its copied address, causing a use-after-free. The same pattern occurs in tikv_async_client_destroy. Please keep each request alive while setting its cancellation flag (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 checked only after the underlying future finishes, so a write may already have taken effect when the callback reports CANCELLED. Also, the Ok(Err(error)) arm below reports ERROR even if cancellation was requested, whereas the C header promises CANCELLED for pending requests. Please define the intended logical-cancellation contract, document possible side effects/partial batches, and cover both success and error after cancellation.
| wait_drain(&handle.core); | ||
| } | ||
|
|
||
| #[cfg(test)] |
There was a problem hiding this comment.
The current unit tests cover parsing, batch grouping, metrics, and result ownership, but not an accepted request's concurrent lifecycle. Before this ABI is ready, please add deterministic tests for destruction inside the callback, shutdown racing with completion, exactly-once callback delivery, and cancellation outcomes. A C/C++ compile-and-link smoke check in CI would also protect the public headers.
| @@ -0,0 +1,2475 @@ | |||
| // Copyright (c) 2026 PingCAP, Inc. | |||
There was a problem hiding this comment.
This file currently combines ABI types, request lifetime management, RawKV operations, metrics, and tests in about 2,475 lines. Splitting the lifetime state machine and metrics code into focused modules would make the unsafe ownership invariants easier to audit and test.
| @@ -0,0 +1,390 @@ | |||
| # TiKV Rust Client C Binding | |||
There was a problem hiding this comment.
Could we provide an English binding README and link to it from the repository's top-level README? That will make the new API discoverable and reviewable for upstream contributors. The build artifact list below should also include tikv_client_async.hpp, the main C++ wrapper.
| } | ||
|
|
||
| /* | ||
| * Query whether the request callback has completed. |
There was a problem hiding this comment.
is_complete() can return true before the callback finishes: Rust sets completion.complete = true immediately before invoking it. Please describe this as terminal status availability; drain() is the operation that waits for callbacks to return.
lance6716
left a comment
There was a problem hiding this comment.
Additional observability review: these comments focus on what the metrics snapshot represents and what remains invisible at the C/C++ boundary.
| 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 entire process-wide default registry, but MetricSample retains only the type label and the match below silently omits gauges, summaries, and other metric types. Two series that differ only in another label become indistinguishable to C/C++ consumers. Please either limit and document this as a snapshot of the known client-rust counter/histogram families, or preserve all labels and supported metric types in the ABI. A test with two series differing in a non-type label would make the contract clear.
| || keepalive.lifecycle.cancel_inflight.load(Ordering::Acquire) | ||
| }; | ||
|
|
||
| let (status, output, error_message) = match result { |
There was a problem hiding this comment.
From a monitoring perspective, this maps an underlying successful RPC to an FFI CANCELLED completion, while the existing tikv_request_total/duration metrics still count the RPC as successful. The binding also has no outcome metrics for rejected submits, cancellations, panics, or in-flight requests. Please consider binding-level outcome and in-flight metrics so operators can reconcile API outcomes with TiKV RPC activity.
| TTL 的批量 put/delete、真实到期,以及无 TTL key 在等待期间持续存在。测试 | ||
| 使用最长 10 秒的轮询等待到期,不依赖固定时长的 sleep。 | ||
|
|
||
| `metrics_snapshot_demo` 会在同一进程内发起一次 raw put/get/delete, |
There was a problem hiding this comment.
Please document the scope of these values for monitoring consumers: prometheus::gather() is process-wide across client instances, and tikv_request_total counts underlying TiKV RPC attempts rather than one sample per C/C++ API call (retries and multi-phase batches can produce multiple samples). This distinction matters when using the snapshot for request rates and error ratios.
| raw_get_duration_count = Some(sample.value); | ||
| } | ||
|
|
||
| if name == "tikv_request_duration_seconds" |
There was a problem hiding this comment.
The snapshot test confirms that an infinite bucket exists, but does not check its cumulative value, finite buckets, or histogram sum. Please assert those values with a known observation and test the intended label behavior; that would catch monitoring output regressions rather than only metric presence.
Signed-off-by: lance6716 <lance6716@gmail.com>
00c9ea1 to
29d9d90
Compare
Summary
Review status
This is a draft for reviewing the API and implementation. Inline review comments identify concurrency and cancellation issues that should be resolved before it is marked ready.
Testing
The binding includes Rust unit tests and C/C++ examples. The examples require a running TiKV cluster; no tests were rerun while creating this PR.