Skip to content

Commit

Permalink
clientv3 : updated doc.go
Browse files Browse the repository at this point in the history
  • Loading branch information
visheshnp committed Aug 3, 2017
1 parent d65cb87 commit 01384d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions clientv3/integration/leasing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1489,8 +1489,8 @@ func TestLeasingTxnAtomicCache(t *testing.T) {
f := func() {
defer wgPutters.Done()
for i := 0; i < 10; i++ {
if _, err = lkv.Txn(context.TODO()).Then(puts...).Commit(); err != nil {
t.Fatal(err)
if _, puterr := lkv.Txn(context.TODO()).Then(puts...).Commit(); puterr != nil {
t.Fatal(puterr)
}
}
}
Expand Down
48 changes: 27 additions & 21 deletions clientv3/leasing/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,38 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package namespace is a clientv3 wrapper that translates all keys to begin
// with a given prefix.
// Package leasing is a clientv3 wrapper that provides the client exclusive write access to a key by acquiring a lease and be lineraizably
// served locally. This leasing layer can either directly wrap the etcd client
// or it can be exposed through the etcd grace proxy server, granting multiple clients write access.
//
// First, create a client:
// First, create a leasing client interface :
//
// cli, err := clientv3.New(clientv3.Config{Endpoints: []string{"localhost:2379"}})
// if err != nil {
// // handle error!
// }
// leasingCli,error = leasing.NewKV(cli.KV, "leasing-prefix")
// if error ! =nil {
// //handle error
// }
//
// Next, override the client interfaces:
// The first range request acquires the lease by adding the leasing key ("leasing-prefix"/key) on the server and stores the key locally.
// Further linearized read requests using 'cli.leasing' will be served locally as long as the lease exists:
//
// unprefixedKV := cli.KV
// cli.KV = namespace.NewKV(cli.KV, "my-prefix/")
// cli.Watcher = namespace.NewWatcher(cli.Watcher, "my-prefix/")
// cli.Lease = namespace.NewLease(cli.Lease, "my-prefix/")
// cli.Put(context.TODO(), "abc", "123")
//
// Now calls using 'cli' will namespace / prefix all keys with "my-prefix/":
// Lease Acquisition:
//
// cli.Put(context.TODO(), "abc", "123")
// resp, _ := unprefixedKV.Get(context.TODO(), "my-prefix/abc")
// fmt.Printf("%s\n", resp.Kvs[0].Value)
// // Output: 123
// unprefixedKV.Put(context.TODO(), "my-prefix/abc", "456")
// resp, _ = cli.Get("abc")
// fmt.Printf("%s\n", resp.Kvs[0].Value)
// // Output: 456
// leasingCli.Get(context.TODO(), "abc")
//
// Local reads:
//
// resp,_ := leasingCli.Get(context.TODO(), "abc")
// fmt.Printf("%s\n", resp.Kvs[0].Value)
// //Output: 123 (served locally)
//
// Lease Revocation:
// If a client writes to the key owned by the leasing client, then the leasing client gives up its lease allowing the client to modify the key.
//
// cli.Put(context.TODO(), "abc", "456")
// resp, _ = leasingCli.Get("abc")
// fmt.Printf("%s\n", resp.Kvs[0].Value)
// // Output: 456 (fetched from server)
//
package leasing

0 comments on commit 01384d7

Please sign in to comment.