From b846743da398407097d4549617485f59067281c2 Mon Sep 17 00:00:00 2001 From: fys <40801205+Fengys123@users.noreply.github.com> Date: Fri, 10 Feb 2023 16:10:30 +0800 Subject: [PATCH] feat: add lock.proto (#3) --- build.rs | 1 + proto/greptime/v1/meta/lock.proto | 43 +++++++++++++++++++++++++++++++ src/v1/meta.rs | 2 ++ 3 files changed, 46 insertions(+) create mode 100644 proto/greptime/v1/meta/lock.proto diff --git a/build.rs b/build.rs index b9cc3af..281ed8a 100644 --- a/build.rs +++ b/build.rs @@ -21,6 +21,7 @@ fn main() { "proto/greptime/v1/meta/heartbeat.proto", "proto/greptime/v1/meta/route.proto", "proto/greptime/v1/meta/store.proto", + "proto/greptime/v1/meta/lock.proto", "proto/greptime/v1/meta/cluster.proto", "proto/prometheus/remote/remote.proto", ], diff --git a/proto/greptime/v1/meta/lock.proto b/proto/greptime/v1/meta/lock.proto new file mode 100644 index 0000000..ed881f7 --- /dev/null +++ b/proto/greptime/v1/meta/lock.proto @@ -0,0 +1,43 @@ +syntax = "proto3"; + +package greptime.v1.meta; + +import "greptime/v1/meta/common.proto"; + +service Lock { + // Lock acquires a distributed shared lock on a given named lock. On success, it + // will return a unique key that exists so long as the lock is held by the caller. + rpc Lock(LockRequest) returns (LockResponse); + + // Unlock takes a key returned by Lock and releases the hold on lock. + rpc Unlock(UnlockRequest) returns (UnlockResponse); +} + +message LockRequest { + RequestHeader header = 1; + + // Name is the identifier for the distributed shared lock to be acquired. + bytes name = 2; + + // If the expiration time is exceeded and currently holds the lock, the lock is + // aytomatically released. The unit is second. + int64 expire = 3; +} + +message LockResponse { + ResponseHeader header = 1; + + // Key will exist as long as lock is held by the caller. + bytes key = 2; +} + +message UnlockRequest { + RequestHeader header = 1; + + // key is the lock ownership key granted by Lock. + bytes key = 2; +} + +message UnlockResponse { + ResponseHeader header = 1; +} diff --git a/src/v1/meta.rs b/src/v1/meta.rs index dafe6f6..a3ad29d 100644 --- a/src/v1/meta.rs +++ b/src/v1/meta.rs @@ -151,6 +151,8 @@ gen_set_header!(BatchPutRequest); gen_set_header!(CompareAndPutRequest); gen_set_header!(DeleteRangeRequest); gen_set_header!(MoveValueRequest); +gen_set_header!(LockRequest); +gen_set_header!(UnlockRequest); #[cfg(test)] mod tests {