From 4f10fae3c3ac17d60d8b2d1f9b6650753c68b78b Mon Sep 17 00:00:00 2001 From: Pierre Souchay Date: Mon, 19 Feb 2018 22:44:49 +0100 Subject: [PATCH] Get only first service to test whether we have to cleanup index of a service --- agent/consul/state/catalog.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/consul/state/catalog.go b/agent/consul/state/catalog.go index 9c3cb3a29d..cd0ff2f0a1 100644 --- a/agent/consul/state/catalog.go +++ b/agent/consul/state/catalog.go @@ -1052,8 +1052,8 @@ func (s *Store) deleteServiceTxn(tx *memdb.Txn, idx uint64, nodeName, serviceID } svc := service.(*structs.ServiceNode) - if remainingServicesItr, err := tx.Get("services", "service", svc.ServiceName); err == nil { - if remainingServicesItr != nil && remainingServicesItr.Next() != nil { + if remainingService, err := tx.First("services", "service", svc.ServiceName); err == nil { + if remainingService != nil { // We have at least one remaining service, update the index if err := tx.Insert("index", &IndexEntry{serviceIndexName(svc.ServiceName), idx}); err != nil { return fmt.Errorf("failed updating index: %s", err)