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