go.etcd.io/etcd@v3.3.27+incompatible/clientv3/leasing/doc.go (about)

     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  
    15  // Package leasing serves linearizable reads from a local cache by acquiring
    16  // exclusive write access to keys through a client-side leasing protocol. This
    17  // leasing layer can either directly wrap the etcd client or it can be exposed
    18  // through the etcd grpc proxy server, granting multiple clients write access.
    19  //
    20  // First, create a leasing KV from a clientv3.Client 'cli':
    21  //
    22  //     lkv, err := leasing.NewKV(cli, "leasing-prefix")
    23  //     if err != nil {
    24  //         // handle error
    25  //     }
    26  //
    27  // A range request for a key "abc" tries to acquire a leasing key so it can cache the range's
    28  // key locally. On the server, the leasing key is stored to "leasing-prefix/abc":
    29  //
    30  //     resp, err := lkv.Get(context.TODO(), "abc")
    31  //
    32  // Future linearized read requests using 'lkv' will be served locally for the lease's lifetime:
    33  //
    34  //     resp, err = lkv.Get(context.TODO(), "abc")
    35  //
    36  // If another leasing client writes to a leased key, then the owner relinquishes its exclusive
    37  // access, permitting the writer to modify the key:
    38  //
    39  //     lkv2, err := leasing.NewKV(cli, "leasing-prefix")
    40  //     if err != nil {
    41  //         // handle error
    42  //     }
    43  //     lkv2.Put(context.TODO(), "abc", "456")
    44  //     resp, err = lkv.Get("abc")
    45  //
    46  package leasing