From ce631d0bba6689dcc0ea8bea7bcc5fdde6eb1603 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 26 Mar 2021 19:33:10 -0400 Subject: [PATCH] state: use constants for table checks --- agent/consul/state/catalog.go | 2 +- agent/consul/state/catalog_events.go | 2 +- agent/consul/state/catalog_oss.go | 14 +++++++------- agent/consul/state/catalog_test.go | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/agent/consul/state/catalog.go b/agent/consul/state/catalog.go index 3824095c05..d701649ca2 100644 --- a/agent/consul/state/catalog.go +++ b/agent/consul/state/catalog.go @@ -1857,7 +1857,7 @@ func (s *Store) deleteCheckTxn(tx WriteTxn, idx uint64, node string, checkID typ } // Delete the check from the DB and update the index. - if err := tx.Delete("checks", hc); err != nil { + if err := tx.Delete(tableChecks, hc); err != nil { return fmt.Errorf("failed removing check: %s", err) } diff --git a/agent/consul/state/catalog_events.go b/agent/consul/state/catalog_events.go index 92f4745795..038f8ea158 100644 --- a/agent/consul/state/catalog_events.go +++ b/agent/consul/state/catalog_events.go @@ -175,7 +175,7 @@ func ServiceHealthEventsFromChanges(tx ReadTxn, changes Changes) ([]stream.Event srvChange := serviceChange{changeType: changeTypeFromChange(change), change: change} markService(newNodeServiceTupleFromServiceNode(sn), srvChange) - case "checks": + case tableChecks: // For health we only care about the scope for now to know if it's just // affecting a single service or every service on a node. There is a // subtle edge case where the check with same ID changes from being node diff --git a/agent/consul/state/catalog_oss.go b/agent/consul/state/catalog_oss.go index 49b0f6d2df..98d37d3abd 100644 --- a/agent/consul/state/catalog_oss.go +++ b/agent/consul/state/catalog_oss.go @@ -107,28 +107,28 @@ func catalogServiceLastExtinctionIndex(tx ReadTxn, _ *structs.EnterpriseMeta) (i func catalogMaxIndex(tx ReadTxn, _ *structs.EnterpriseMeta, checks bool) uint64 { if checks { - return maxIndexTxn(tx, "nodes", tableServices, "checks") + return maxIndexTxn(tx, "nodes", tableServices, tableChecks) } return maxIndexTxn(tx, "nodes", tableServices) } func catalogMaxIndexWatch(tx ReadTxn, ws memdb.WatchSet, _ *structs.EnterpriseMeta, checks bool) uint64 { if checks { - return maxIndexWatchTxn(tx, ws, "nodes", tableServices, "checks") + return maxIndexWatchTxn(tx, ws, "nodes", tableServices, tableChecks) } return maxIndexWatchTxn(tx, ws, "nodes", tableServices) } func catalogUpdateCheckIndexes(tx WriteTxn, idx uint64, _ *structs.EnterpriseMeta) error { // update the universal index entry - if err := tx.Insert(tableIndex, &IndexEntry{"checks", idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableChecks, idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) } return nil } func catalogChecksMaxIndex(tx ReadTxn, _ *structs.EnterpriseMeta) uint64 { - return maxIndexTxn(tx, "checks") + return maxIndexTxn(tx, tableChecks) } func catalogListChecksByNode(tx ReadTxn, q Query) (memdb.ResultIterator, error) { @@ -136,17 +136,17 @@ func catalogListChecksByNode(tx ReadTxn, q Query) (memdb.ResultIterator, error) } func catalogListChecksByService(tx ReadTxn, service string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) { - return tx.Get("checks", "service", service) + return tx.Get(tableChecks, indexService, service) } func catalogListChecksInState(tx ReadTxn, state string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) { // simpler than normal due to the use of the CompoundMultiIndex - return tx.Get("checks", "status", state) + return tx.Get(tableChecks, indexStatus, state) } func catalogInsertCheck(tx WriteTxn, chk *structs.HealthCheck, idx uint64) error { // Insert the check - if err := tx.Insert("checks", chk); err != nil { + if err := tx.Insert(tableChecks, chk); err != nil { return fmt.Errorf("failed inserting check: %s", err) } diff --git a/agent/consul/state/catalog_test.go b/agent/consul/state/catalog_test.go index ee3f8db14b..96f3122e14 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", tableServices, "checks"} { + for _, tbl := range []string{"nodes", tableServices, tableChecks} { if idx := s.maxIndex(tbl); idx != 3 { t.Fatalf("bad index: %d (%s)", idx, tbl) } @@ -2076,7 +2076,7 @@ func TestStateStore_DeleteService(t *testing.T) { if idx := s.maxIndex(tableServices); idx != 4 { t.Fatalf("bad index: %d", idx) } - if idx := s.maxIndex("checks"); idx != 4 { + if idx := s.maxIndex(tableChecks); idx != 4 { t.Fatalf("bad index: %d", idx) } @@ -2411,7 +2411,7 @@ func TestStateStore_EnsureCheck(t *testing.T) { testCheckOutput(t, 5, 5, "bbbmodified") // Index tables were updated - if idx := s.maxIndex("checks"); idx != 5 { + if idx := s.maxIndex(tableChecks); idx != 5 { t.Fatalf("bad index: %d", idx) } } @@ -2894,7 +2894,7 @@ func TestStateStore_DeleteCheck(t *testing.T) { if idx, check, err := s.NodeCheck("node1", "check1", nil); idx != 3 || err != nil || check != nil { t.Fatalf("Node check should have been deleted idx=%d, node=%v, err=%s", idx, check, err) } - if idx := s.maxIndex("checks"); idx != 3 { + if idx := s.maxIndex(tableChecks); idx != 3 { t.Fatalf("bad index for checks: %d", idx) } if !watchFired(ws) { @@ -2914,7 +2914,7 @@ func TestStateStore_DeleteCheck(t *testing.T) { } // Index tables were updated. - if idx := s.maxIndex("checks"); idx != 3 { + if idx := s.maxIndex(tableChecks); idx != 3 { t.Fatalf("bad index: %d", idx) } @@ -2923,7 +2923,7 @@ func TestStateStore_DeleteCheck(t *testing.T) { if err := s.DeleteCheck(4, "node1", "check1", nil); err != nil { t.Fatalf("err: %s", err) } - if idx := s.maxIndex("checks"); idx != 3 { + if idx := s.maxIndex(tableChecks); idx != 3 { t.Fatalf("bad index: %d", idx) } if watchFired(ws) {