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.
|
// Get the table index.
|
||||||
idx := catalogChecksMaxIndex(tx, entMeta)
|
idx := catalogChecksMaxIndex(tx, entMeta)
|
||||||
|
|
||||||
// Return the checks.
|
if entMeta == nil {
|
||||||
iter, err := catalogListChecksByService(tx, serviceName, entMeta)
|
entMeta = structs.DefaultEnterpriseMeta()
|
||||||
|
}
|
||||||
|
q := Query{Value: serviceName, EnterpriseMeta: *entMeta}
|
||||||
|
iter, err := tx.Get(tableChecks, indexService, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, fmt.Errorf("failed check lookup: %s", err)
|
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.
|
// Get the table index.
|
||||||
idx := maxIndexForService(tx, serviceName, true, true, entMeta)
|
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 {
|
if err != nil {
|
||||||
return 0, nil, fmt.Errorf("failed check lookup: %s", err)
|
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)
|
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 {
|
func catalogInsertCheck(tx WriteTxn, chk *structs.HealthCheck, idx uint64) error {
|
||||||
// Insert the check
|
// Insert the check
|
||||||
if err := tx.Insert(tableChecks, chk); err != nil {
|
if err := tx.Insert(tableChecks, chk); err != nil {
|
||||||
|
|
|
@ -50,9 +50,7 @@ func testIndexerTableChecks() map[string]indexerTestCase {
|
||||||
},
|
},
|
||||||
indexService: {
|
indexService: {
|
||||||
read: indexValue{
|
read: indexValue{
|
||||||
source: []interface{}{
|
source: Query{Value: "ServiceName"},
|
||||||
"ServiceName",
|
|
||||||
},
|
|
||||||
expected: []byte("servicename\x00"),
|
expected: []byte("servicename\x00"),
|
||||||
},
|
},
|
||||||
write: indexValue{
|
write: indexValue{
|
||||||
|
|
|
@ -267,9 +267,9 @@ func checksTableSchema() *memdb.TableSchema {
|
||||||
Name: indexService,
|
Name: indexService,
|
||||||
AllowMissing: true,
|
AllowMissing: true,
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Indexer: &memdb.StringFieldIndex{
|
Indexer: indexerSingle{
|
||||||
Field: "ServiceName",
|
readIndex: indexFromQuery,
|
||||||
Lowercase: true,
|
writeIndex: indexServiceNameFromHealthCheck,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
indexNode: {
|
indexNode: {
|
||||||
|
@ -357,6 +357,21 @@ func indexStatusFromHealthCheck(raw interface{}) ([]byte, error) {
|
||||||
return b.Bytes(), nil
|
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
|
// gatewayServicesTableSchema returns a new table schema used to store information
|
||||||
// about services associated with terminating gateways.
|
// about services associated with terminating gateways.
|
||||||
func gatewayServicesTableSchema() *memdb.TableSchema {
|
func gatewayServicesTableSchema() *memdb.TableSchema {
|
||||||
|
|
Loading…
Reference in New Issue