From 86159c6ed8ebbe3de844fe8993a5027037e4efb1 Mon Sep 17 00:00:00 2001 From: Dhia Ayachi Date: Fri, 3 Dec 2021 15:36:07 -0500 Subject: [PATCH] sessions partitioning tests (#11734) * state: port KV and Tombstone tables to new pattern * go fmt'ed * handle wildcards for tombstones * Fix graveyard ent vs oss * fix oss compilation error * add partition to tombstones and kv state store indexes * refactor to use `indexWithEnterpriseIndexable` * Apply suggestions from code review Co-authored-by: Chris S. Kim Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com> * add `singleValueID` implementation assertions * partition `tableSessions` table * fix sessions to use UUID and fix prefix index * fix oss build * clean up unused functions * fix oss compilation * add a partition indexer for sessions * Fix oss to not have partition index * fix oss tests * remove unused operations_ent.go and operations_oss.go func * remove unused const * convert `IndexID` of `session_checks` table * convert `indexSession` of `session_checks` table * convert `indexNodeCheck` of `session_checks` table * partition `indexID` and `indexSession` of `tableSessionChecks` * fix oss linter * fix review comments * remove partition for Checks as it's always use the session partition * fix tests * fix tests * do not namespace nodeChecks index Co-authored-by: Daniel Nephin Co-authored-by: Chris S. Kim Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com> --- agent/consul/state/catalog.go | 4 ++-- agent/consul/state/session.go | 2 +- agent/consul/state/session_oss.go | 2 +- agent/consul/state/state_store_test.go | 18 ++++++++++++------ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/agent/consul/state/catalog.go b/agent/consul/state/catalog.go index 4aa99a9e5c..d0974c30e7 100644 --- a/agent/consul/state/catalog.go +++ b/agent/consul/state/catalog.go @@ -666,7 +666,7 @@ func (s *Store) deleteNodeTxn(tx WriteTxn, idx uint64, nodeName string, entMeta } // Invalidate any sessions for this node. - toDelete, err := allNodeSessionsTxn(tx, nodeName) + toDelete, err := allNodeSessionsTxn(tx, nodeName, entMeta.PartitionOrDefault()) if err != nil { return err } @@ -2792,7 +2792,7 @@ func parseNodes(tx ReadTxn, ws memdb.WatchSet, idx uint64, // checkSessionsTxn returns the IDs of all sessions associated with a health check func checkSessionsTxn(tx ReadTxn, hc *structs.HealthCheck) ([]*sessionCheck, error) { mappings, err := tx.Get(tableSessionChecks, indexNodeCheck, MultiQuery{Value: []string{hc.Node, string(hc.CheckID)}, - EnterpriseMeta: hc.EnterpriseMeta}) + EnterpriseMeta: *structs.DefaultEnterpriseMetaInPartition(hc.PartitionOrDefault())}) if err != nil { return nil, fmt.Errorf("failed session checks lookup: %s", err) } diff --git a/agent/consul/state/session.go b/agent/consul/state/session.go index 043d86f80a..876e67f50f 100644 --- a/agent/consul/state/session.go +++ b/agent/consul/state/session.go @@ -268,7 +268,7 @@ func sessionCreateTxn(tx WriteTxn, idx uint64, sess *structs.Session) error { sess.ModifyIndex = idx // Check that the node exists - node, err := tx.First(tableNodes, indexID, Query{Value: sess.Node}) + node, err := tx.First(tableNodes, indexID, Query{Value: sess.Node, EnterpriseMeta: *structs.DefaultEnterpriseMetaInPartition(sess.PartitionOrDefault())}) if err != nil { return fmt.Errorf("failed node lookup: %s", err) } diff --git a/agent/consul/state/session_oss.go b/agent/consul/state/session_oss.go index 2955a598bb..a706f2c14b 100644 --- a/agent/consul/state/session_oss.go +++ b/agent/consul/state/session_oss.go @@ -116,7 +116,7 @@ func insertSessionTxn(tx WriteTxn, session *structs.Session, idx uint64, updateM return nil } -func allNodeSessionsTxn(tx ReadTxn, node string) (structs.Sessions, error) { +func allNodeSessionsTxn(tx ReadTxn, node string, _ string) (structs.Sessions, error) { return nodeSessionsTxn(tx, nil, node, nil) } diff --git a/agent/consul/state/state_store_test.go b/agent/consul/state/state_store_test.go index 42cd3cbbbe..b617e0e460 100644 --- a/agent/consul/state/state_store_test.go +++ b/agent/consul/state/state_store_test.go @@ -170,14 +170,20 @@ func testRegisterIngressService(t *testing.T, s *Store, idx uint64, nodeID, serv t.Fatalf("bad service: %#v", result) } } - func testRegisterCheck(t *testing.T, s *Store, idx uint64, nodeID string, serviceID string, checkID types.CheckID, state string) { + testRegisterCheckWithPartition(t, s, idx, + nodeID, serviceID, checkID, state, "") +} + +func testRegisterCheckWithPartition(t *testing.T, s *Store, idx uint64, + nodeID string, serviceID string, checkID types.CheckID, state string, partition string) { chk := &structs.HealthCheck{ - Node: nodeID, - CheckID: checkID, - ServiceID: serviceID, - Status: state, + Node: nodeID, + CheckID: checkID, + ServiceID: serviceID, + Status: state, + EnterpriseMeta: *structs.DefaultEnterpriseMetaInPartition(partition), } if err := s.EnsureCheck(idx, chk); err != nil { t.Fatalf("err: %s", err) @@ -185,7 +191,7 @@ func testRegisterCheck(t *testing.T, s *Store, idx uint64, tx := s.db.Txn(false) defer tx.Abort() - c, err := tx.First(tableChecks, indexID, NodeCheckQuery{Node: nodeID, CheckID: string(checkID)}) + c, err := tx.First(tableChecks, indexID, NodeCheckQuery{Node: nodeID, CheckID: string(checkID), EnterpriseMeta: *structs.DefaultEnterpriseMetaInPartition(partition)}) if err != nil { t.Fatalf("err: %s", err) }