Browse Source

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.
Gyu-Ho Lee 8 years ago
parent
commit
6431382a75
2 changed files with 30 additions and 1 deletions
  1. 3 1
      auth/store.go
  2. 27 0
      auth/store_test.go

+ 3 - 1
auth/store.go

@@ -916,7 +916,9 @@ func NewAuthStore(be backend.Backend, indexWaiter func(uint64) <-chan struct{})
 		as.simpleTokenKeeper = NewSimpleTokenTTLKeeper(newDeleterFunc(as))
 		as.simpleTokenKeeper = NewSimpleTokenTTLKeeper(newDeleterFunc(as))
 	}
 	}
 
 
-	as.commitRevision(tx)
+	if as.revision == 0 {
+		as.commitRevision(tx)
+	}
 
 
 	tx.Unlock()
 	tx.Unlock()
 	be.ForceCommit()
 	be.ForceCommit()

+ 27 - 0
auth/store_test.go

@@ -38,6 +38,33 @@ func dummyIndexWaiter(index uint64) <-chan struct{} {
 	return ch
 	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)) {
 func setupAuthStore(t *testing.T) (store *authStore, teardownfunc func(t *testing.T)) {
 	b, tPath := backend.NewDefaultTmpBackend()
 	b, tPath := backend.NewDefaultTmpBackend()