From 903e8668357e17aa82078d53f2e59c1301fb8dd1 Mon Sep 17 00:00:00 2001
From: Pierre Souchay
Date: Tue, 20 Feb 2018 23:08:04 +0100
Subject: [PATCH] Only update services if tags are different
---
agent/consul/state/catalog.go | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/agent/consul/state/catalog.go b/agent/consul/state/catalog.go
index 07975f53c..8e3b20d98 100644
--- a/agent/consul/state/catalog.go
+++ b/agent/consul/state/catalog.go
@@ -2,6 +2,7 @@ package state
import (
"fmt"
+ "reflect"
"strings"
"github.com/hashicorp/consul/agent/structs"
@@ -618,9 +619,12 @@ func (s *Store) ensureServiceTxn(tx *memdb.Txn, idx uint64, node string, svc *st
// conversion doesn't populate any of the node-specific information.
// That's always populated when we read from the state store.
entry := svc.ToServiceNode(node)
+ hasSameTags := false
if existing != nil {
entry.CreateIndex = existing.(*structs.ServiceNode).CreateIndex
entry.ModifyIndex = idx
+ eSvc := existing.(*structs.ServiceNode)
+ hasSameTags = reflect.DeepEqual(eSvc.ServiceTags, svc.Tags)
} else {
entry.CreateIndex = idx
entry.ModifyIndex = idx
@@ -639,8 +643,11 @@ func (s *Store) ensureServiceTxn(tx *memdb.Txn, idx uint64, node string, svc *st
if err := tx.Insert("services", entry); err != nil {
return fmt.Errorf("failed inserting service: %s", err)
}
- if err := tx.Insert("index", &IndexEntry{"services", idx}); err != nil {
- return fmt.Errorf("failed updating index: %s", err)
+ if !hasSameTags {
+ // We need to update /catalog/services only tags are different
+ if err := tx.Insert("index", &IndexEntry{"services", idx}); err != nil {
+ return fmt.Errorf("failed updating index: %s", err)
+ }
}
if err := tx.Insert("index", &IndexEntry{serviceIndexName(svc.Service), idx}); err != nil {
return fmt.Errorf("failed updating index: %s", err)