xline-kv / Xline

A geo-distributed KV store for metadata management
https://xline.cloud
Apache License 2.0
565 stars 71 forks source link

[Refactor]: Add a session structure to renew lock lease automatically #684

Closed Phoenix500526 closed 1 week ago

Phoenix500526 commented 4 months ago

Description about the feature

At present, we are addressing issue #664 in PR #666. However, the current implementation is not very user-friendly, as users of the lock feature need to renew the lock lease manually.

For example,

    // omit some code ...
    // grant a lease id
    let lease_resp = lease_client
        .grant(LeaseGrantRequest::new(DEFAULT_SESSION_TTL))
        .await?;
    let lock_lease_id = lease_resp.id;
    // do the lock operation
    let req = build_request(matches).with_lease(lock_lease_id);
    let lock_resp = client.lock_client().lock(req).await?;
    lock_resp.print();
    // renew the lock lease manually.
    let (keeper, stream) = client
        .lease_client()
        .keep_alive(LeaseKeepAliveRequest::new(lock_lease_id))
        .await?;

In fact, a better approach to achieve the same result is to have the lock method return a data structure, such as session or lock_scope. Within the lock method, a LockClient will grant a lease ID and store it in the session. This session will automatically renew the lease ID until it is dropped.

Code of Conduct

rohansx commented 3 months ago

@Phoenix500526 would like to take on this issue

Phoenix500526 commented 3 months ago

Are you interested in this issue? @rohansx

rohansx commented 3 months ago

@Phoenix500526 yeah sure!

Phoenix500526 commented 3 months ago

Oh, sorry for the delay reply. Thank you for your contribution. @rohansx

Phoenix500526 commented 1 month ago

Hi, @rohansx ! Due to the release plan, this issue will be closed after pr #820 is merged. Sorry about that. If you haven't started working on this issue yet, could you please consider picking up another one? We have other good-first-issues available. If you're interested, please feel free to claim one of them.