-
Notifications
You must be signed in to change notification settings - Fork 150
Add sync API for transactional client #517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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 |
|
Welcome @odecode! |
f90bd47 to
20f8737
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a synchronous API wrapper for the TiKV transactional client to address issue #289. The implementation provides blocking alternatives to the existing async transaction APIs.
Changes:
- Introduced
SyncTransactionClient,SyncTransaction, andSyncSnapshotstructs that wrap their async counterparts - Each sync type contains an Arc-wrapped Tokio runtime and uses
block_onto execute async operations synchronously - Added comprehensive integration tests mirroring the async test patterns
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/transaction/sync_client.rs | New synchronous client wrapper providing blocking transaction operations |
| src/transaction/sync_transaction.rs | Synchronous transaction wrapper that blocks on async transaction methods |
| src/transaction/sync_snapshot.rs | Synchronous snapshot wrapper for read-only operations |
| src/transaction/mod.rs | Module declarations for new sync components |
| src/lib.rs | Public API exports for sync types |
| tests/sync_transaction_tests.rs | Comprehensive integration tests covering all sync APIs |
| tests/common/mod.rs | Added init_sync() helper for synchronous test setup |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…th block_on. Signed-off-by: Otto Westerlund <[email protected]>
Signed-off-by: Otto Westerlund <[email protected]>
Signed-off-by: Otto Westerlund <[email protected]>
Signed-off-by: Otto Westerlund <[email protected]>
Signed-off-by: Otto Westerlund <[email protected]>
Signed-off-by: Otto Westerlund <[email protected]>
80170a7 to
2fad975
Compare
|
Thank you for the review comments, I have made changes according to the comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Otto Westerlund <[email protected]>
Signed-off-by: Otto Westerlund <[email protected]>
|
I have made changes requested by the review comments |
Signed-off-by: Otto Westerlund <[email protected]>
|
Thank you for your patience so far! I have made the review's suggested change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Copilot left no new comments. Are some actions required by me for the "tide" pending check? |
Signed-off-by: Otto Westerlund <[email protected]>
Signed-off-by: Otto Westerlund <[email protected]>
Signed-off-by: Otto Westerlund <[email protected]>
… usage limitation Signed-off-by: Otto Westerlund <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Otto Westerlund <[email protected]>
Signed-off-by: Otto Westerlund <[email protected]>
|
Is it possible for me to request review from Copilot myself? Then I could address all its concerns and not bother you on every iteration. EDIT: I figured out that I can ask Copilot to review uncommitted changes in my code editor, I will do that for the next round of changes if Copilot or you request more improvements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Otto Westerlund <[email protected]>
Signed-off-by: Otto Westerlund <[email protected]>
Signed-off-by: Otto Westerlund <[email protected]>
📝 WalkthroughWalkthroughAdds a synchronous transaction API: new types Changes
Sequence Diagram(s)sequenceDiagram
participant U as User Code
participant SC as SyncTransactionClient
participant RT as check_nested_runtime()
participant SB as safe_block_on()
participant TRT as Tokio Runtime
participant AC as Async TransactionClient
U->>SC: call sync method (e.g., begin_optimistic())
SC->>RT: check_nested_runtime()
alt nested runtime detected
RT-->>SC: Err(NestedRuntimeError)
SC-->>U: return Err(NestedRuntimeError)
else no nested runtime
RT-->>SC: Ok(())
SC->>SB: wrap async_op into future
SB->>TRT: block_on(future)
TRT->>AC: execute async operation
AC-->>TRT: result
TRT-->>SB: unblock with result
SB-->>SC: Result<T>
SC-->>U: return Result<T>
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
|
added extra test coverage for the sync snapshot public api surface, and error handling to prevent panic when sync client is called from within an async runtime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/transaction/sync_snapshot.rs`:
- Around line 18-70: SyncSnapshot methods call self.runtime.block_on(...)
directly which will panic if invoked inside an active Tokio runtime; add a
private helper on SyncSnapshot (e.g., safe_block_on_snapshot) that mirrors
sync_client::safe_block_on by checking
tokio::runtime::Handle::try_current().is_ok() and returning
Err(Error::NestedRuntimeError) when a current runtime exists, otherwise invoking
self.runtime.block_on; replace direct self.runtime.block_on(...) calls in the
public methods get, key_exists, batch_get, scan, scan_keys, scan_reverse, and
scan_keys_reverse to use this helper so nested runtime usage is guarded.
In `@src/transaction/sync_transaction.rs`:
- Around line 20-126: All SyncTransaction and SyncSnapshot methods currently
call self.runtime.block_on(...) and can panic if invoked inside an existing
Tokio runtime; make the existing check_nested_runtime/safe_block_on helpers
accessible (move to a shared module or change to pub(crate)), then replace every
direct self.runtime.block_on(self.inner.<method>(...)) call in SyncTransaction
and SyncSnapshot (e.g., get, get_for_update, key_exists, batch_get,
batch_get_for_update, scan, scan_keys, scan_reverse, scan_keys_reverse, put,
insert, delete, batch_mutate, lock_keys, commit, rollback, send_heart_beat) with
the safe helper usage (run the nested-runtime check and call safe_block_on
around the inner async call) so callers get a NestedRuntimeError instead of a
panic.
Signed-off-by: Otto Westerlund <[email protected]>
For issue #289 a synchronous API for transactional client.
I have programmed a fair bit but new to OSS and Rust. I consulted AI heavily for this to try and get an understanding of what this part of the project is about and how it works, but I tried using it a teacher rather than just "vibe coding".
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.