Only update services if tags are different

This commit is contained in:
Pierre Souchay 2018-02-20 23:08:04 +01:00
parent 5dd77e132f
commit 60454b570a
1 changed files with 9 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package state
import ( import (
"fmt" "fmt"
"reflect"
"strings" "strings"
"github.com/hashicorp/consul/agent/structs" "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. // conversion doesn't populate any of the node-specific information.
// That's always populated when we read from the state store. // That's always populated when we read from the state store.
entry := svc.ToServiceNode(node) entry := svc.ToServiceNode(node)
hasSameTags := false
if existing != nil { if existing != nil {
entry.CreateIndex = existing.(*structs.ServiceNode).CreateIndex entry.CreateIndex = existing.(*structs.ServiceNode).CreateIndex
entry.ModifyIndex = idx entry.ModifyIndex = idx
eSvc := existing.(*structs.ServiceNode)
hasSameTags = reflect.DeepEqual(eSvc.ServiceTags, svc.Tags)
} else { } else {
entry.CreateIndex = idx entry.CreateIndex = idx
entry.ModifyIndex = idx entry.ModifyIndex = idx
@ -639,9 +643,12 @@ func (s *Store) ensureServiceTxn(tx *memdb.Txn, idx uint64, node string, svc *st
if err := tx.Insert("services", entry); err != nil { if err := tx.Insert("services", entry); err != nil {
return fmt.Errorf("failed inserting service: %s", err) return fmt.Errorf("failed inserting service: %s", err)
} }
if !hasSameTags {
// We need to update /catalog/services only tags are different
if err := tx.Insert("index", &IndexEntry{"services", idx}); err != nil { if err := tx.Insert("index", &IndexEntry{"services", idx}); err != nil {
return fmt.Errorf("failed updating index: %s", err) return fmt.Errorf("failed updating index: %s", err)
} }
}
if err := tx.Insert("index", &IndexEntry{serviceIndexName(svc.Service), idx}); err != nil { if err := tx.Insert("index", &IndexEntry{serviceIndexName(svc.Service), idx}); err != nil {
return fmt.Errorf("failed updating index: %s", err) return fmt.Errorf("failed updating index: %s", err)
} }