Merge pull request #3535 from xiang90/rev

storage: add rev into kv interface
This commit is contained in:
Xiang Li 2015-09-15 12:54:29 -07:00
commit 867954f3ad
3 changed files with 22 additions and 0 deletions

View File

@ -11,6 +11,9 @@ import (
type CancelFunc func()
type KV interface {
// Rev returns the current revision of the KV.
Rev() int64
// Range gets the keys in the range at rangeRev.
// If rangeRev <=0, range gets the keys at currentRev.
// If `end` is nil, the request returns the key.

View File

@ -69,6 +69,13 @@ func newStore(path string) *store {
return s
}
func (s *store) Rev() int64 {
s.mu.RLock()
defer s.mu.RUnlock()
return s.currentRev.main
}
func (s *store) Put(key, value []byte) int64 {
id := s.TxnBegin()
s.put(key, value)

View File

@ -16,6 +16,18 @@ import (
"github.com/coreos/etcd/storage/storagepb"
)
func TestStoreRev(t *testing.T) {
s := newStore(tmpPath)
defer os.Remove(tmpPath)
for i := 0; i < 3; i++ {
s.Put([]byte("foo"), []byte("bar"))
if r := s.Rev(); r != int64(i+1) {
t.Errorf("#%d: rev = %d, want %d", i, r, i+1)
}
}
}
func TestStorePut(t *testing.T) {
tests := []struct {
rev revision