From e4a60a2a8d3f0154ec0f588fc4fb43b9e6f19376 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 8 Mar 2021 13:02:41 -0500 Subject: [PATCH] state: use tableIndex constant --- agent/consul/state/catalog_test.go | 2 +- agent/consul/state/config_entry.go | 2 +- agent/consul/state/connect_ca.go | 10 +++++----- agent/consul/state/coordinate.go | 2 +- agent/consul/state/federation_state.go | 4 ++-- agent/consul/state/graveyard_oss.go | 2 +- agent/consul/state/intention.go | 8 ++++---- agent/consul/state/prepared_query.go | 4 ++-- agent/consul/state/session_oss.go | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/agent/consul/state/catalog_test.go b/agent/consul/state/catalog_test.go index b68a76aca..054e3a5e8 100644 --- a/agent/consul/state/catalog_test.go +++ b/agent/consul/state/catalog_test.go @@ -2950,7 +2950,7 @@ func ensureIndexForService(t *testing.T, s *Store, serviceName string, expectedI t.Helper() tx := s.db.Txn(false) defer tx.Abort() - transaction, err := tx.First("index", "id", serviceIndexName(serviceName, nil)) + transaction, err := tx.First(tableIndex, "id", serviceIndexName(serviceName, nil)) if err == nil { if idx, ok := transaction.(*IndexEntry); ok { if expectedIndex != idx.Value { diff --git a/agent/consul/state/config_entry.go b/agent/consul/state/config_entry.go index 318178a2f..e396ab7b2 100644 --- a/agent/consul/state/config_entry.go +++ b/agent/consul/state/config_entry.go @@ -295,7 +295,7 @@ func deleteConfigEntryTxn(tx WriteTxn, idx uint64, kind, name string, entMeta *s if err := tx.Delete(tableConfigEntries, existing); err != nil { return fmt.Errorf("failed removing config entry: %s", err) } - if err := tx.Insert("index", &IndexEntry{tableConfigEntries, idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableConfigEntries, idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) } diff --git a/agent/consul/state/connect_ca.go b/agent/consul/state/connect_ca.go index 44225ddd3..e3e89f852 100644 --- a/agent/consul/state/connect_ca.go +++ b/agent/consul/state/connect_ca.go @@ -326,7 +326,7 @@ func (s *Store) CARootSetCAS(idx, cidx uint64, rs []*structs.CARoot) (bool, erro } // Update the index - if err := tx.Insert("index", &IndexEntry{tableConnectCARoots, idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableConnectCARoots, idx}); err != nil { return false, fmt.Errorf("failed updating index: %s", err) } @@ -407,7 +407,7 @@ func (s *Store) CASetProviderState(idx uint64, state *structs.CAConsulProviderSt } // Update the index - if err := tx.Insert("index", &IndexEntry{tableConnectCABuiltin, idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableConnectCABuiltin, idx}); err != nil { return false, fmt.Errorf("failed updating index: %s", err) } @@ -436,7 +436,7 @@ func (s *Store) CADeleteProviderState(idx uint64, id string) error { if err := tx.Delete(tableConnectCABuiltin, providerState); err != nil { return err } - if err := tx.Insert("index", &IndexEntry{tableConnectCABuiltin, idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableConnectCABuiltin, idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) } @@ -476,7 +476,7 @@ func (s *Store) CAIncrementProviderSerialNumber(idx uint64) (uint64, error) { tx := s.db.WriteTxn(idx) defer tx.Abort() - existing, err := tx.First("index", "id", tableConnectCABuiltinSerial) + existing, err := tx.First(tableIndex, "id", tableConnectCABuiltinSerial) if err != nil { return 0, fmt.Errorf("failed built-in CA serial number lookup: %s", err) } @@ -491,7 +491,7 @@ func (s *Store) CAIncrementProviderSerialNumber(idx uint64) (uint64, error) { } next := last + 1 - if err := tx.Insert("index", &IndexEntry{tableConnectCABuiltinSerial, next}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableConnectCABuiltinSerial, next}); err != nil { return 0, fmt.Errorf("failed updating index: %s", err) } diff --git a/agent/consul/state/coordinate.go b/agent/consul/state/coordinate.go index 0a9c43d09..e5b3ec746 100644 --- a/agent/consul/state/coordinate.go +++ b/agent/consul/state/coordinate.go @@ -160,7 +160,7 @@ func (s *Store) CoordinateBatchUpdate(idx uint64, updates structs.Coordinates) e } // Update the index. - if err := tx.Insert("index", &IndexEntry{"coordinates", idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{"coordinates", idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) } diff --git a/agent/consul/state/federation_state.go b/agent/consul/state/federation_state.go index c4026e406..c7eababf2 100644 --- a/agent/consul/state/federation_state.go +++ b/agent/consul/state/federation_state.go @@ -117,7 +117,7 @@ func federationStateSetTxn(tx WriteTxn, idx uint64, config *structs.FederationSt if err := tx.Insert(tableFederationStates, config); err != nil { return fmt.Errorf("failed inserting federation state: %s", err) } - if err := tx.Insert("index", &IndexEntry{tableFederationStates, idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableFederationStates, idx}); err != nil { return fmt.Errorf("failed updating index: %v", err) } @@ -216,7 +216,7 @@ func federationStateDeleteTxn(tx WriteTxn, idx uint64, datacenter string) error if err := tx.Delete(tableFederationStates, existing); err != nil { return fmt.Errorf("failed removing federation state: %s", err) } - if err := tx.Insert("index", &IndexEntry{tableFederationStates, idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableFederationStates, idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) } return nil diff --git a/agent/consul/state/graveyard_oss.go b/agent/consul/state/graveyard_oss.go index d4ee5848a..201f77dc0 100644 --- a/agent/consul/state/graveyard_oss.go +++ b/agent/consul/state/graveyard_oss.go @@ -16,7 +16,7 @@ func (g *Graveyard) insertTombstoneWithTxn(tx WriteTxn, _ string, stone *Tombsto return fmt.Errorf("failed updating tombstone index: %v", err) } } else { - if err := tx.Insert("index", &IndexEntry{"tombstones", stone.Index}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{"tombstones", stone.Index}); err != nil { return fmt.Errorf("failed updating tombstone index: %s", err) } } diff --git a/agent/consul/state/intention.go b/agent/consul/state/intention.go index 5e661a90b..418e3ee8d 100644 --- a/agent/consul/state/intention.go +++ b/agent/consul/state/intention.go @@ -561,7 +561,7 @@ func legacyIntentionSetTxn(tx WriteTxn, idx uint64, ixn *structs.Intention) erro if err := tx.Insert(tableConnectIntentions, ixn); err != nil { return err } - if err := tx.Insert("index", &IndexEntry{tableConnectIntentions, idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableConnectIntentions, idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) } @@ -689,7 +689,7 @@ func legacyIntentionDeleteTxn(tx WriteTxn, idx uint64, queryID string) error { if err := tx.Delete(tableConnectIntentions, wrapped); err != nil { return fmt.Errorf("failed intention delete: %s", err) } - if err := tx.Insert("index", &IndexEntry{tableConnectIntentions, idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableConnectIntentions, idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) } @@ -706,13 +706,13 @@ func (s *Store) LegacyIntentionDeleteAll(idx uint64) error { if _, err := tx.DeleteAll(tableConnectIntentions, "id"); err != nil { return fmt.Errorf("failed intention delete-all: %s", err) } - if err := tx.Insert("index", &IndexEntry{tableConnectIntentions, idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableConnectIntentions, idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) } // Also bump the index for the config entry table so that // secondaries can correctly know when they've replicated all of the service-intentions // config entries that USED to exist in the old intentions table. - if err := tx.Insert("index", &IndexEntry{tableConfigEntries, idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{tableConfigEntries, idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) } diff --git a/agent/consul/state/prepared_query.go b/agent/consul/state/prepared_query.go index 0bbcb1d74..8d2364511 100644 --- a/agent/consul/state/prepared_query.go +++ b/agent/consul/state/prepared_query.go @@ -234,7 +234,7 @@ func preparedQuerySetTxn(tx WriteTxn, idx uint64, query *structs.PreparedQuery) if err := tx.Insert("prepared-queries", &queryWrapper{query, ct}); err != nil { return fmt.Errorf("failed inserting prepared query: %s", err) } - if err := tx.Insert("index", &IndexEntry{"prepared-queries", idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{"prepared-queries", idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) } @@ -269,7 +269,7 @@ func preparedQueryDeleteTxn(tx WriteTxn, idx uint64, queryID string) error { if err := tx.Delete("prepared-queries", wrapped); err != nil { return fmt.Errorf("failed prepared query delete: %s", err) } - if err := tx.Insert("index", &IndexEntry{"prepared-queries", idx}); err != nil { + if err := tx.Insert(tableIndex, &IndexEntry{"prepared-queries", idx}); err != nil { return fmt.Errorf("failed updating index: %s", err) } diff --git a/agent/consul/state/session_oss.go b/agent/consul/state/session_oss.go index 52c0593f8..16eb026dd 100644 --- a/agent/consul/state/session_oss.go +++ b/agent/consul/state/session_oss.go @@ -42,7 +42,7 @@ func sessionDeleteWithSession(tx WriteTxn, session *structs.Session, idx uint64) } // Update the indexes - err := tx.Insert("index", &IndexEntry{"sessions", idx}) + err := tx.Insert(tableIndex, &IndexEntry{"sessions", idx}) if err != nil { return fmt.Errorf("failed updating sessions index: %v", err) } @@ -72,7 +72,7 @@ func insertSessionTxn(tx WriteTxn, session *structs.Session, idx uint64, updateM return fmt.Errorf("failed updating sessions index: %v", err) } } else { - err := tx.Insert("index", &IndexEntry{"sessions", idx}) + err := tx.Insert(tableIndex, &IndexEntry{"sessions", idx}) if err != nil { return fmt.Errorf("failed updating sessions index: %v", err) }