diff --git a/agent/consul/state/catalog.go b/agent/consul/state/catalog.go index 49201494b..4b94b3421 100644 --- a/agent/consul/state/catalog.go +++ b/agent/consul/state/catalog.go @@ -1368,7 +1368,7 @@ func (s *Store) deleteServiceTxn(tx WriteTxn, idx uint64, nodeName, serviceID st return fmt.Errorf("failed to clean up mesh-topology associations for %q: %v", name.String(), err) } - if _, remainingService, err := firstWatchWithTxn(tx, tableServices, "service", svc.ServiceName, entMeta); err == nil { + if _, remainingService, err := firstWatchWithTxn(tx, tableServices, indexService, svc.ServiceName, entMeta); err == nil { if remainingService != nil { // We have at least one remaining service, update the index if err := catalogUpdateServiceIndexes(tx, svc.ServiceName, idx, entMeta); err != nil { diff --git a/agent/consul/state/catalog_oss_test.go b/agent/consul/state/catalog_oss_test.go index 925c130c4..7285a6250 100644 --- a/agent/consul/state/catalog_oss_test.go +++ b/agent/consul/state/catalog_oss_test.go @@ -168,6 +168,12 @@ func testIndexerTableNodes() map[string]indexerTestCase { } func testIndexerTableServices() map[string]indexerTestCase { + obj := &structs.ServiceNode{ + Node: "NoDeId", + ServiceID: "SeRviCe", + ServiceName: "ServiceName", + } + return map[string]indexerTestCase{ indexID: { read: indexValue{ @@ -178,10 +184,7 @@ func testIndexerTableServices() map[string]indexerTestCase { expected: []byte("nodeid\x00service\x00"), }, write: indexValue{ - source: &structs.ServiceNode{ - Node: "NoDeId", - ServiceID: "SeRviCe", - }, + source: obj, expected: []byte("nodeid\x00service\x00"), }, prefix: []indexValue{ @@ -202,16 +205,36 @@ func testIndexerTableServices() map[string]indexerTestCase { indexNode: { read: indexValue{ source: Query{ - Value: "NoDe", + Value: "NoDeId", }, - expected: []byte("node\x00"), + expected: []byte("nodeid\x00"), + }, + write: indexValue{ + source: obj, + expected: []byte("nodeid\x00"), + }, + }, + indexService: { + read: indexValue{ + source: "ServiceName", + expected: []byte("servicename\x00"), + }, + write: indexValue{ + source: obj, + expected: []byte("servicename\x00"), + }, + }, + indexConnect: { + read: indexValue{ + source: Query{Value: "ConnectName"}, + expected: []byte("connectname\x00"), }, write: indexValue{ source: &structs.ServiceNode{ - Node: "NoDe", - ServiceID: "SeRvIcE", + ServiceName: "ConnectName", + ServiceConnect: structs.ServiceConnect{Native: true}, }, - expected: []byte("node\x00"), + expected: []byte("connectname\x00"), }, }, } diff --git a/agent/consul/state/usage.go b/agent/consul/state/usage.go index 11604fe55..3be474428 100644 --- a/agent/consul/state/usage.go +++ b/agent/consul/state/usage.go @@ -107,7 +107,7 @@ func updateUsage(tx WriteTxn, changes Changes) error { func updateServiceNameUsage(tx WriteTxn, usageDeltas map[string]int, serviceNameChanges map[structs.ServiceName]int) (map[structs.ServiceName]uniqueServiceState, error) { serviceStates := make(map[structs.ServiceName]uniqueServiceState, len(serviceNameChanges)) for svc, delta := range serviceNameChanges { - serviceIter, err := getWithTxn(tx, tableServices, "service", svc.Name, &svc.EnterpriseMeta) + serviceIter, err := getWithTxn(tx, tableServices, indexService, svc.Name, &svc.EnterpriseMeta) if err != nil { return nil, err }