opened
nrc
username_0
For long-running transactions, the client should send heartbeat messages to the server. This should be optional (similar to retrying) and on by default. It should still be possible to manually send heartbeats.
Automatically send heartbeats
issue
created
andylokandy
username_1
comment
created
nrc
username_0
My philosophy for the client is that the default API should make things as easy as possible for the user and so things like heartbeats and retries should happen automatically. However, it should be possible to customise the workflow up to the level of the gRPC API. The use cases here are for somebody re-implementing TiDB in Rust, or more likely implementing some other, equally complex, DB on top of TiKV, or using the Rust client to automatically test edge cases in TiKV where we might want to simulate missing heart beats or heart beats which are out of order or duplicated or have incorrect timestamps or whatever.
comment
created
TszKitLo40
username_2
Where the API should be added in the `rust-client`?
comment
created
ekexium
username_3
@username_2 You can add a field in `TransactionOptions`
comment
created
TszKitLo40
username_2
Do you mean it should be a `bool`  to indicate whether is will send heartbeats automatically? But where should the API be added?
comment
created
ekexium
username_3
@username_2 I think it can be a bool.
The interface should be the `TransactionOptions` that users supply. Do you mean where to implement it? One initial idea is to make use of the `bg_worker`.
comment
created
TszKitLo40
username_2
Yes, I mean where to implement this API. Do you mean we should implement it as a method in the `Client` in `transaction/client.rs` and make use of `bg_worker`?
comment
created
ekexium
username_3
@username_2 
Heartbeats are for transactions, so I think it shouldn't be implemented in `Client`. 
Each transaction has its `TransactionOptions` which is the place that users can specify the behavior.
I think we can start periodically sending heartbeats since one transaction starts, and stop when the transaction is rolled back or committed. It can be implemented in `transaction.rs`, I guess.
comment
created
TszKitLo40
username_2
Should we also define a variable for the heartbeat interval?
comment
created
ekexium
username_3
@username_2 
Yes there should be a constant variable for the default interval.
Personally I don't think it needs to be configurable (for now).
comment
created
TszKitLo40
username_2
I want to start periodically sending heartbeats in the `new method` of Transaction. And it seems that the `bg_worker` which is a `ThreadPool` can't be executed at a fixed rate, any example for me to refer?
comment
created
ekexium
username_3
How about spawning a task that periodically do something in the thread pool?
comment
created
TszKitLo40
username_2
When should we spawn the task? Should we distinguish the optimistic lock and pessimistic lock? @username_3
comment
created
ekexium
username_3
@username_2 Similar to TiDB, after the prewrite, and after each pessimistic lock acquisition.
comment
closed
nrc
username_0
issue