From 4498814843e242d7bb9b13c600f4fab5b6ba9182 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Tue, 25 Jul 2017 21:54:11 -0500 Subject: [PATCH] Don't insert tombstone for empty prefix delete. Other minor unit test fixes --- agent/consul/state/kvs.go | 8 +++++--- agent/consul/state/txn_test.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/agent/consul/state/kvs.go b/agent/consul/state/kvs.go index 909126cc46..d282ec3a42 100644 --- a/agent/consul/state/kvs.go +++ b/agent/consul/state/kvs.go @@ -426,12 +426,14 @@ func (s *Store) kvsDeleteTreeTxn(tx *memdb.Txn, idx uint64, prefix string) error deleted, err := tx.DeletePrefix("kvs", "id_prefix", prefix) if err != nil { - return fmt.Errorf("failed recursive deleting kvs entry: %s", err) + return fmt.Errorf("failed recursive deleting kvs entry: %s", err) } if deleted { - if err := s.kvsGraveyard.InsertTxn(tx, prefix, idx); err != nil { - return fmt.Errorf("failed adding to graveyard: %s", err) + if prefix != "" { // don't insert a tombstone if the entire tree is deleted, all watchers on keys will see the max_index of the tree + if err := s.kvsGraveyard.InsertTxn(tx, prefix, idx); err != nil { + return fmt.Errorf("failed adding to graveyard: %s", err) + } } if err := tx.Insert("index", &IndexEntry{"kvs", idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) diff --git a/agent/consul/state/txn_test.go b/agent/consul/state/txn_test.go index 8c9936961e..17cd1da581 100644 --- a/agent/consul/state/txn_test.go +++ b/agent/consul/state/txn_test.go @@ -698,7 +698,7 @@ func TestStateStore_Txn_KVS_RO_Safety(t *testing.T) { expected := []string{ "cannot insert in read-only transaction", "cannot insert in read-only transaction", - "cannot insert in read-only transaction", + "failed recursive deleting kvs entry", } if len(errors) != len(expected) { t.Fatalf("bad len: %d != %d", len(errors), len(expected))