mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #3535 from xiang90/rev
storage: add rev into kv interface
This commit is contained in:
commit
867954f3ad
@ -11,6 +11,9 @@ import (
|
|||||||
type CancelFunc func()
|
type CancelFunc func()
|
||||||
|
|
||||||
type KV interface {
|
type KV interface {
|
||||||
|
// Rev returns the current revision of the KV.
|
||||||
|
Rev() int64
|
||||||
|
|
||||||
// Range gets the keys in the range at rangeRev.
|
// Range gets the keys in the range at rangeRev.
|
||||||
// If rangeRev <=0, range gets the keys at currentRev.
|
// If rangeRev <=0, range gets the keys at currentRev.
|
||||||
// If `end` is nil, the request returns the key.
|
// If `end` is nil, the request returns the key.
|
||||||
|
@ -69,6 +69,13 @@ func newStore(path string) *store {
|
|||||||
return s
|
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 {
|
func (s *store) Put(key, value []byte) int64 {
|
||||||
id := s.TxnBegin()
|
id := s.TxnBegin()
|
||||||
s.put(key, value)
|
s.put(key, value)
|
||||||
|
@ -16,6 +16,18 @@ import (
|
|||||||
"github.com/coreos/etcd/storage/storagepb"
|
"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) {
|
func TestStorePut(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
rev revision
|
rev revision
|
||||||
|
Loading…
x
Reference in New Issue
Block a user