khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 1 | syntax = "proto3"; |
| 2 | package v3lockpb; |
| 3 | |
| 4 | import "gogoproto/gogo.proto"; |
| 5 | import "etcd/etcdserver/etcdserverpb/rpc.proto"; |
| 6 | |
| 7 | // for grpc-gateway |
| 8 | import "google/api/annotations.proto"; |
| 9 | |
| 10 | option (gogoproto.marshaler_all) = true; |
| 11 | option (gogoproto.unmarshaler_all) = true; |
| 12 | |
| 13 | // The lock service exposes client-side locking facilities as a gRPC interface. |
| 14 | service Lock { |
| 15 | // Lock acquires a distributed shared lock on a given named lock. |
| 16 | // On success, it will return a unique key that exists so long as the |
| 17 | // lock is held by the caller. This key can be used in conjunction with |
| 18 | // transactions to safely ensure updates to etcd only occur while holding |
| 19 | // lock ownership. The lock is held until Unlock is called on the key or the |
| 20 | // lease associate with the owner expires. |
| 21 | rpc Lock(LockRequest) returns (LockResponse) { |
| 22 | option (google.api.http) = { |
| 23 | post: "/v3beta/lock/lock" |
| 24 | body: "*" |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | // Unlock takes a key returned by Lock and releases the hold on lock. The |
| 29 | // next Lock caller waiting for the lock will then be woken up and given |
| 30 | // ownership of the lock. |
| 31 | rpc Unlock(UnlockRequest) returns (UnlockResponse) { |
| 32 | option (google.api.http) = { |
| 33 | post: "/v3beta/lock/unlock" |
| 34 | body: "*" |
| 35 | }; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | message LockRequest { |
| 40 | // name is the identifier for the distributed shared lock to be acquired. |
| 41 | bytes name = 1; |
| 42 | // lease is the ID of the lease that will be attached to ownership of the |
| 43 | // lock. If the lease expires or is revoked and currently holds the lock, |
| 44 | // the lock is automatically released. Calls to Lock with the same lease will |
| 45 | // be treated as a single acquistion; locking twice with the same lease is a |
| 46 | // no-op. |
| 47 | int64 lease = 2; |
| 48 | } |
| 49 | |
| 50 | message LockResponse { |
| 51 | etcdserverpb.ResponseHeader header = 1; |
| 52 | // key is a key that will exist on etcd for the duration that the Lock caller |
| 53 | // owns the lock. Users should not modify this key or the lock may exhibit |
| 54 | // undefined behavior. |
| 55 | bytes key = 2; |
| 56 | } |
| 57 | |
| 58 | message UnlockRequest { |
| 59 | // key is the lock ownership key granted by Lock. |
| 60 | bytes key = 1; |
| 61 | } |
| 62 | |
| 63 | message UnlockResponse { |
| 64 | etcdserverpb.ResponseHeader header = 1; |
| 65 | } |