From 2d2c3e1190e63e2e2af9ff88d6a21e1a545f9b59 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 26 Mar 2021 16:04:45 -0400 Subject: [PATCH] state: use constant for tableServices --- agent/consul/state/catalog.go | 4 ++-- agent/consul/state/catalog_events.go | 2 +- agent/consul/state/catalog_oss.go | 18 +++++++++--------- agent/consul/state/catalog_test.go | 10 +++++----- agent/consul/state/state_store_test.go | 2 +- agent/consul/state/usage.go | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/agent/consul/state/catalog.go b/agent/consul/state/catalog.go index 0825f86cc8..49201494bd 100644 --- a/agent/consul/state/catalog.go +++ b/agent/consul/state/catalog.go @@ -1351,7 +1351,7 @@ func (s *Store) deleteServiceTxn(tx WriteTxn, idx uint64, nodeName, serviceID st } // Delete the service and update the index - if err := tx.Delete("services", service); err != nil { + if err := tx.Delete(tableServices, service); err != nil { return fmt.Errorf("failed deleting service: %s", err) } if err := catalogUpdateServicesIndexes(tx, idx, entMeta); err != nil { @@ -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, "services", "service", svc.ServiceName, entMeta); err == nil { + if _, remainingService, err := firstWatchWithTxn(tx, tableServices, "service", 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_events.go b/agent/consul/state/catalog_events.go index 4e407baeb3..e6ab38df1f 100644 --- a/agent/consul/state/catalog_events.go +++ b/agent/consul/state/catalog_events.go @@ -170,7 +170,7 @@ func ServiceHealthEventsFromChanges(tx ReadTxn, changes Changes) ([]stream.Event n := changeObject(change).(*structs.Node) markNode(n.Node, changeTypeFromChange(change)) - case "services": + case tableServices: sn := changeObject(change).(*structs.ServiceNode) srvChange := serviceChange{changeType: changeTypeFromChange(change), change: change} markService(newNodeServiceTupleFromServiceNode(sn), srvChange) diff --git a/agent/consul/state/catalog_oss.go b/agent/consul/state/catalog_oss.go index 7ec173d0e2..d82c9c355d 100644 --- a/agent/consul/state/catalog_oss.go +++ b/agent/consul/state/catalog_oss.go @@ -28,7 +28,7 @@ func serviceKindIndexName(kind structs.ServiceKind, _ *structs.EnterpriseMeta) s func catalogUpdateServicesIndexes(tx WriteTxn, idx uint64, _ *structs.EnterpriseMeta) error { // overall services index - if err := indexUpdateMaxTxn(tx, idx, "services"); err != nil { + if err := indexUpdateMaxTxn(tx, idx, tableServices); err != nil { return fmt.Errorf("failed updating index: %s", err) } @@ -62,7 +62,7 @@ func catalogUpdateServiceExtinctionIndex(tx WriteTxn, idx uint64, _ *structs.Ent func catalogInsertService(tx WriteTxn, svc *structs.ServiceNode) error { // Insert the service and update the index - if err := tx.Insert("services", svc); err != nil { + if err := tx.Insert(tableServices, svc); err != nil { return fmt.Errorf("failed inserting service: %s", err) } @@ -82,7 +82,7 @@ func catalogInsertService(tx WriteTxn, svc *structs.ServiceNode) error { } func catalogServicesMaxIndex(tx ReadTxn, _ *structs.EnterpriseMeta) uint64 { - return maxIndexTxn(tx, "services") + return maxIndexTxn(tx, tableServices) } func catalogServiceMaxIndex(tx ReadTxn, serviceName string, _ *structs.EnterpriseMeta) (<-chan struct{}, interface{}, error) { @@ -98,7 +98,7 @@ func catalogServiceListNoWildcard(tx ReadTxn, _ *structs.EnterpriseMeta) (memdb. } func catalogServiceListByKind(tx ReadTxn, kind structs.ServiceKind, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) { - return tx.Get("services", "kind", string(kind)) + return tx.Get(tableServices, "kind", string(kind)) } func catalogServiceListByNode(tx ReadTxn, node string, _ *structs.EnterpriseMeta, _ bool) (memdb.ResultIterator, error) { @@ -106,7 +106,7 @@ func catalogServiceListByNode(tx ReadTxn, node string, _ *structs.EnterpriseMeta } func catalogServiceNodeList(tx ReadTxn, name string, index string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) { - return tx.Get("services", index, name) + return tx.Get(tableServices, index, name) } func catalogServiceLastExtinctionIndex(tx ReadTxn, _ *structs.EnterpriseMeta) (interface{}, error) { @@ -115,16 +115,16 @@ func catalogServiceLastExtinctionIndex(tx ReadTxn, _ *structs.EnterpriseMeta) (i func catalogMaxIndex(tx ReadTxn, _ *structs.EnterpriseMeta, checks bool) uint64 { if checks { - return maxIndexTxn(tx, "nodes", "services", "checks") + return maxIndexTxn(tx, "nodes", tableServices, "checks") } - return maxIndexTxn(tx, "nodes", "services") + return maxIndexTxn(tx, "nodes", tableServices) } func catalogMaxIndexWatch(tx ReadTxn, ws memdb.WatchSet, _ *structs.EnterpriseMeta, checks bool) uint64 { if checks { - return maxIndexWatchTxn(tx, ws, "nodes", "services", "checks") + return maxIndexWatchTxn(tx, ws, "nodes", tableServices, "checks") } - return maxIndexWatchTxn(tx, ws, "nodes", "services") + return maxIndexWatchTxn(tx, ws, "nodes", tableServices) } func catalogUpdateCheckIndexes(tx WriteTxn, idx uint64, _ *structs.EnterpriseMeta) error { diff --git a/agent/consul/state/catalog_test.go b/agent/consul/state/catalog_test.go index b68a76aca2..ee3f8db14b 100644 --- a/agent/consul/state/catalog_test.go +++ b/agent/consul/state/catalog_test.go @@ -1316,7 +1316,7 @@ func TestStateStore_DeleteNode(t *testing.T) { } // Indexes were updated. - for _, tbl := range []string{"nodes", "services", "checks"} { + for _, tbl := range []string{"nodes", tableServices, "checks"} { if idx := s.maxIndex(tbl); idx != 3 { t.Fatalf("bad index: %d (%s)", idx, tbl) } @@ -1479,7 +1479,7 @@ func TestStateStore_EnsureService(t *testing.T) { } // Index tables were updated. - if idx := s.maxIndex("services"); idx != 30 { + if idx := s.maxIndex(tableServices); idx != 30 { t.Fatalf("bad index: %d", idx) } @@ -1510,7 +1510,7 @@ func TestStateStore_EnsureService(t *testing.T) { } // Index tables were updated. - if idx := s.maxIndex("services"); idx != 40 { + if idx := s.maxIndex(tableServices); idx != 40 { t.Fatalf("bad index: %d", idx) } } @@ -2073,7 +2073,7 @@ func TestStateStore_DeleteService(t *testing.T) { } // Index tables were updated. - if idx := s.maxIndex("services"); idx != 4 { + if idx := s.maxIndex(tableServices); idx != 4 { t.Fatalf("bad index: %d", idx) } if idx := s.maxIndex("checks"); idx != 4 { @@ -2085,7 +2085,7 @@ func TestStateStore_DeleteService(t *testing.T) { if err := s.DeleteService(5, "node1", "service1", nil); err != nil { t.Fatalf("err: %s", err) } - if idx := s.maxIndex("services"); idx != 4 { + if idx := s.maxIndex(tableServices); idx != 4 { t.Fatalf("bad index: %d", idx) } if watchFired(ws) { diff --git a/agent/consul/state/state_store_test.go b/agent/consul/state/state_store_test.go index 985e7540ba..bcc9ad5933 100644 --- a/agent/consul/state/state_store_test.go +++ b/agent/consul/state/state_store_test.go @@ -283,7 +283,7 @@ func TestStateStore_maxIndex(t *testing.T) { testRegisterNode(t, s, 1, "bar") testRegisterService(t, s, 2, "foo", "consul") - if max := s.maxIndex("nodes", "services"); max != 2 { + if max := s.maxIndex("nodes", tableServices); max != 2 { t.Fatalf("bad max: %d", max) } } diff --git a/agent/consul/state/usage.go b/agent/consul/state/usage.go index f9720b3e0f..11604fe556 100644 --- a/agent/consul/state/usage.go +++ b/agent/consul/state/usage.go @@ -70,7 +70,7 @@ func updateUsage(tx WriteTxn, changes Changes) error { switch change.Table { case "nodes": usageDeltas[change.Table] += delta - case "services": + case tableServices: svc := changeObject(change).(*structs.ServiceNode) usageDeltas[change.Table] += delta addEnterpriseServiceInstanceUsage(usageDeltas, change)