From 6431382a7564a4fc941a0d655788a3705d4b708a Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Tue, 21 Feb 2017 14:37:15 -0800 Subject: [PATCH] auth: keep old revision in 'NewAuthStore' When there's no changes yet (right after auth store initialization), we should commit old revision. Fix https://github.com/coreos/etcd/issues/7359. --- auth/store.go | 4 +++- auth/store_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/auth/store.go b/auth/store.go index 6d218d313..255404760 100644 --- a/auth/store.go +++ b/auth/store.go @@ -916,7 +916,9 @@ func NewAuthStore(be backend.Backend, indexWaiter func(uint64) <-chan struct{}) as.simpleTokenKeeper = NewSimpleTokenTTLKeeper(newDeleterFunc(as)) } - as.commitRevision(tx) + if as.revision == 0 { + as.commitRevision(tx) + } tx.Unlock() be.ForceCommit() diff --git a/auth/store_test.go b/auth/store_test.go index 3bc3a0014..7116347b8 100644 --- a/auth/store_test.go +++ b/auth/store_test.go @@ -38,6 +38,33 @@ func dummyIndexWaiter(index uint64) <-chan struct{} { return ch } +// TestNewAuthStoreRevision ensures newly auth store +// keeps the old revision when there are no changes. +func TestNewAuthStoreRevision(t *testing.T) { + b, tPath := backend.NewDefaultTmpBackend() + defer os.Remove(tPath) + + as := NewAuthStore(b, dummyIndexWaiter) + err := enableAuthAndCreateRoot(as) + if err != nil { + t.Fatal(err) + } + old := as.Revision() + b.Close() + as.Close() + + // no changes to commit + b2 := backend.NewDefaultBackend(tPath) + as = NewAuthStore(b2, dummyIndexWaiter) + new := as.Revision() + b2.Close() + as.Close() + + if old != new { + t.Fatalf("expected revision %d, got %d", old, new) + } +} + func setupAuthStore(t *testing.T) (store *authStore, teardownfunc func(t *testing.T)) { b, tPath := backend.NewDefaultTmpBackend()