doc.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 ordering is a clientv3 wrapper that caches response header revisions
  15. // to detect ordering violations from stale responses. Users may define a
  16. // policy on how to handle the ordering violation, but typically the client
  17. // should connect to another endpoint and reissue the request.
  18. //
  19. // The most common situation where an ordering violation happens is a client
  20. // reconnects to a partitioned member and issues a serializable read. Since the
  21. // partitioned member is likely behind the last member, it may return a Get
  22. // response based on a store revision older than the store revision used to
  23. // service a prior Get on the former endpoint.
  24. //
  25. // First, create a client:
  26. //
  27. // cli, err := clientv3.New(clientv3.Config{Endpoints: []string{"localhost:2379"}})
  28. // if err != nil {
  29. // // handle error!
  30. // }
  31. //
  32. // Next, override the client interface with the ordering wrapper:
  33. //
  34. // vf := func(op clientv3.Op, resp clientv3.OpResponse, prevRev int64) error {
  35. // return fmt.Errorf("ordering: issued %+v, got %+v, expected rev=%v", op, resp, prevRev)
  36. // }
  37. // cli.KV = ordering.NewKV(cli.KV, vf)
  38. //
  39. // Now calls using 'cli' will reject order violations with an error.
  40. //
  41. package ordering