state: convert checks.service index to new pattern
This commit is contained in:
parent
f859ba6d4b
commit
d785c86db1
|
@ -1638,8 +1638,11 @@ func (s *Store) ServiceChecks(ws memdb.WatchSet, serviceName string, entMeta *st
|
|||
// Get the table index.
|
||||
idx := catalogChecksMaxIndex(tx, entMeta)
|
||||
|
||||
// Return the checks.
|
||||
iter, err := catalogListChecksByService(tx, serviceName, entMeta)
|
||||
if entMeta == nil {
|
||||
entMeta = structs.DefaultEnterpriseMeta()
|
||||
}
|
||||
q := Query{Value: serviceName, EnterpriseMeta: *entMeta}
|
||||
iter, err := tx.Get(tableChecks, indexService, q)
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("failed check lookup: %s", err)
|
||||
}
|
||||
|
@ -1663,8 +1666,12 @@ func (s *Store) ServiceChecksByNodeMeta(ws memdb.WatchSet, serviceName string,
|
|||
|
||||
// Get the table index.
|
||||
idx := maxIndexForService(tx, serviceName, true, true, entMeta)
|
||||
// Return the checks.
|
||||
iter, err := catalogListChecksByService(tx, serviceName, entMeta)
|
||||
|
||||
if entMeta == nil {
|
||||
entMeta = structs.DefaultEnterpriseMeta()
|
||||
}
|
||||
q := Query{Value: serviceName, EnterpriseMeta: *entMeta}
|
||||
iter, err := tx.Get(tableChecks, indexService, q)
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("failed check lookup: %s", err)
|
||||
}
|
||||
|
|
|
@ -135,10 +135,6 @@ func catalogListChecksByNode(tx ReadTxn, q Query) (memdb.ResultIterator, error)
|
|||
return tx.Get(tableChecks, indexNode, q)
|
||||
}
|
||||
|
||||
func catalogListChecksByService(tx ReadTxn, service string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
||||
return tx.Get(tableChecks, indexService, service)
|
||||
}
|
||||
|
||||
func catalogInsertCheck(tx WriteTxn, chk *structs.HealthCheck, idx uint64) error {
|
||||
// Insert the check
|
||||
if err := tx.Insert(tableChecks, chk); err != nil {
|
||||
|
|
|
@ -50,9 +50,7 @@ func testIndexerTableChecks() map[string]indexerTestCase {
|
|||
},
|
||||
indexService: {
|
||||
read: indexValue{
|
||||
source: []interface{}{
|
||||
"ServiceName",
|
||||
},
|
||||
source: Query{Value: "ServiceName"},
|
||||
expected: []byte("servicename\x00"),
|
||||
},
|
||||
write: indexValue{
|
||||
|
|
|
@ -267,9 +267,9 @@ func checksTableSchema() *memdb.TableSchema {
|
|||
Name: indexService,
|
||||
AllowMissing: true,
|
||||
Unique: false,
|
||||
Indexer: &memdb.StringFieldIndex{
|
||||
Field: "ServiceName",
|
||||
Lowercase: true,
|
||||
Indexer: indexerSingle{
|
||||
readIndex: indexFromQuery,
|
||||
writeIndex: indexServiceNameFromHealthCheck,
|
||||
},
|
||||
},
|
||||
indexNode: {
|
||||
|
@ -357,6 +357,21 @@ func indexStatusFromHealthCheck(raw interface{}) ([]byte, error) {
|
|||
return b.Bytes(), nil
|
||||
}
|
||||
|
||||
func indexServiceNameFromHealthCheck(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.ServiceName == "" {
|
||||
return nil, errMissingValueForIndex
|
||||
}
|
||||
|
||||
var b indexBuilder
|
||||
b.String(strings.ToLower(hc.ServiceName))
|
||||
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