doc.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2017 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Package leasing serves linearizable reads from a local cache by acquiring
  15. // exclusive write access to keys through a client-side leasing protocol. This
  16. // leasing layer can either directly wrap the etcd client or it can be exposed
  17. // through the etcd grpc proxy server, granting multiple clients write access.
  18. //
  19. // First, create a leasing KV from a clientv3.Client 'cli':
  20. //
  21. // lkv, err := leasing.NewKV(cli, "leasing-prefix")
  22. // if err != nil {
  23. // // handle error
  24. // }
  25. //
  26. // A range request for a key "abc" tries to acquire a leasing key so it can cache the range's
  27. // key locally. On the server, the leasing key is stored to "leasing-prefix/abc":
  28. //
  29. // resp, err := lkv.Get(context.TODO(), "abc")
  30. //
  31. // Future linearized read requests using 'lkv' will be served locally for the lease's lifetime:
  32. //
  33. // resp, err = lkv.Get(context.TODO(), "abc")
  34. //
  35. // If another leasing client writes to a leased key, then the owner relinquishes its exclusive
  36. // access, permitting the writer to modify the key:
  37. //
  38. // lkv2, err := leasing.NewKV(cli, "leasing-prefix")
  39. // if err != nil {
  40. // // handle error
  41. // }
  42. // lkv2.Put(context.TODO(), "abc", "456")
  43. // resp, err = lkv.Get("abc")
  44. //
  45. package leasing