state: convert checks.status indexer
As part of this change the indexer will now be case insensitive by using the lower case value. This should be safe because previously we always had lower case strings. This change was made out of convenience. All the other indexers use lowercase, so we can re-use the indexFromQuery function by using lowercase here as well.
This commit is contained in:
parent
9251ac881a
commit
f859ba6d4b
|
@ -1709,13 +1709,18 @@ func checksInStateTxn(tx ReadTxn, ws memdb.WatchSet, state string, entMeta *stru
|
|||
// Get the table index.
|
||||
idx := catalogChecksMaxIndex(tx, entMeta)
|
||||
|
||||
if entMeta == nil {
|
||||
entMeta = structs.DefaultEnterpriseMeta()
|
||||
}
|
||||
|
||||
// Query all checks if HealthAny is passed, otherwise use the index.
|
||||
var iter memdb.ResultIterator
|
||||
var err error
|
||||
if state == api.HealthAny {
|
||||
iter, err = tx.Get(tableChecks, indexID+"_prefix", entMeta)
|
||||
} else {
|
||||
iter, err = catalogListChecksInState(tx, state, entMeta)
|
||||
q := Query{Value: state, EnterpriseMeta: *entMeta}
|
||||
iter, err = tx.Get(tableChecks, indexStatus, q)
|
||||
}
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("failed check lookup: %s", err)
|
||||
|
|
|
@ -139,11 +139,6 @@ func catalogListChecksByService(tx ReadTxn, service string, _ *structs.Enterpris
|
|||
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(tableChecks, indexStatus, state)
|
||||
}
|
||||
|
||||
func catalogInsertCheck(tx WriteTxn, chk *structs.HealthCheck, idx uint64) error {
|
||||
// Insert the check
|
||||
if err := tx.Insert(tableChecks, chk); err != nil {
|
||||
|
|
|
@ -40,14 +40,12 @@ func testIndexerTableChecks() map[string]indexerTestCase {
|
|||
},
|
||||
indexStatus: {
|
||||
read: indexValue{
|
||||
source: []interface{}{
|
||||
"PASSING",
|
||||
},
|
||||
expected: []byte("PASSING\x00"),
|
||||
source: Query{Value: "PASSING"},
|
||||
expected: []byte("passing\x00"),
|
||||
},
|
||||
write: indexValue{
|
||||
source: obj,
|
||||
expected: []byte("PASSING\x00"),
|
||||
expected: []byte("passing\x00"),
|
||||
},
|
||||
},
|
||||
indexService: {
|
||||
|
|
|
@ -258,9 +258,9 @@ func checksTableSchema() *memdb.TableSchema {
|
|||
Name: indexStatus,
|
||||
AllowMissing: false,
|
||||
Unique: false,
|
||||
Indexer: &memdb.StringFieldIndex{
|
||||
Field: "Status",
|
||||
Lowercase: false,
|
||||
Indexer: indexerSingle{
|
||||
readIndex: indexFromQuery,
|
||||
writeIndex: indexStatusFromHealthCheck,
|
||||
},
|
||||
},
|
||||
indexService: {
|
||||
|
@ -342,6 +342,21 @@ func indexNodeServiceFromHealthCheck(raw interface{}) ([]byte, error) {
|
|||
return b.Bytes(), nil
|
||||
}
|
||||
|
||||
func indexStatusFromHealthCheck(raw interface{}) ([]byte, error) {
|
||||
hc, ok := raw.(*structs.HealthCheck)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected type %T for structs.HealthCheck index", raw)
|
||||
}
|
||||
|
||||
if hc.Status == "" {
|
||||
return nil, errMissingValueForIndex
|
||||
}
|
||||
|
||||
var b indexBuilder
|
||||
b.String(strings.ToLower(hc.Status))
|
||||
return b.Bytes(), nil
|
||||
}
|
||||
|
||||
// gatewayServicesTableSchema returns a new table schema used to store information
|
||||
// about services associated with terminating gateways.
|
||||
func gatewayServicesTableSchema() *memdb.TableSchema {
|
||||
|
|
Loading…
Reference in New Issue