coreos/etcd — pull request #1153 by jonboulle (2014-09-24 21:07:57+00:00)
Title: X-Etcd-Index off by one

Consider the following requests:

```
% curl -i -L http://127.0.0.1:4001/v2/keys/message -XPUT -d value="Hello world"
HTTP/1.1 200 OK
Content-Type: application/json
X-Etcd-Index: 2
Date: Wed, 24 Sep 2014 21:00:10 GMT
Transfer-Encoding: chunked

{"action":"set","node":{"key":"/message","value":"Hello world","modifiedIndex":2,"createdIndex":2},"prevNode":{"key":"/message","value":"Hello world","modifiedIndex":1,"createdIndex":1}}

% curl -i -L http://127.0.0.1:4001/v2/keys/message\?prevExist\=true -XPUT -d value="Hello world"
HTTP/1.1 200 OK
Content-Type: application/json
X-Etcd-Index: 2
Date: Wed, 24 Sep 2014 21:01:16 GMT
Transfer-Encoding: chunked

{"action":"update","node":{"key":"/message","value":"Hello world","modifiedIndex":3,"createdIndex":2},"prevNode":{"key":"/message","value":"Hello world","modifiedIndex":2,"createdIndex":2}}

% curl -i -L http://127.0.0.1:4001/v2/keys/message\?prevExist\=true -XPUT -d value="Hello world"
HTTP/1.1 200 OK
Content-Type: application/json
X-Etcd-Index: 3
Date: Wed, 24 Sep 2014 21:01:21 GMT
Transfer-Encoding: chunked

{"action":"update","node":{"key":"/message","value":"Hello world","modifiedIndex":4,"createdIndex":2},"prevNode":{"key":"/message","value":"Hello world","modifiedIndex":3,"createdIndex":2}}
```

the "message" key is created, then updated twice. The last request provides an `X-Etcd-Index` of `3`, while the `node` object's `modifiedIndex` is 4 and `createdIndex` is 2. The header should not be 3.