mirror of https://github.com/status-im/consul.git
state: use constants for table checks
This commit is contained in:
parent
cf2646e0d1
commit
ce631d0bba
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue