From 842bf62587cb7e07151f66b062e760c60bb61d93 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Wed, 8 Jan 2014 10:37:16 -0800 Subject: [PATCH] Delete node in a transaction --- consul/state_store.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/consul/state_store.go b/consul/state_store.go index 847a32cfdc..6399202f19 100644 --- a/consul/state_store.go +++ b/consul/state_store.go @@ -280,13 +280,19 @@ func (s *StateStore) DeleteNodeService(node, id string) error { // DeleteNode is used to delete a node and all it's services func (s *StateStore) DeleteNode(node string) error { - if _, err := s.serviceTable.Delete("id", node); err != nil { + tx, err := s.tables.StartTxn(false) + if err != nil { + panic(fmt.Errorf("Failed to start txn: %v", err)) + } + defer tx.Abort() + + if _, err := s.serviceTable.DeleteTxn(tx, "id", node); err != nil { return err } - if _, err := s.nodeTable.Delete("id", node); err != nil { + if _, err := s.nodeTable.DeleteTxn(tx, "id", node); err != nil { return err } - return nil + return tx.Commit() } // Services is used to return all the services with a list of associated tags