mirror of https://github.com/hashicorp/consul
state: handle wildcard for services.ID index
When listing services, use the id_prefix directly if wildcards are allowed. Error if a wildcard is used for a query that does not index the wildcardpull/9866/head
parent
627c469f08
commit
dbd3cef1ed
|
@ -691,7 +691,7 @@ func (s *Store) Services(ws memdb.WatchSet, entMeta *structs.EnterpriseMeta) (ui
|
|||
idx := catalogServicesMaxIndex(tx, entMeta)
|
||||
|
||||
// List all the services.
|
||||
services, err := catalogServiceList(tx, entMeta, false)
|
||||
services, err := catalogServiceListNoWildcard(tx, entMeta)
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("failed querying services: %s", err)
|
||||
}
|
||||
|
@ -735,7 +735,7 @@ func serviceListTxn(tx ReadTxn, ws memdb.WatchSet,
|
|||
include func(svc *structs.ServiceNode) bool, entMeta *structs.EnterpriseMeta) (uint64, structs.ServiceList, error) {
|
||||
idx := catalogServicesMaxIndex(tx, entMeta)
|
||||
|
||||
services, err := catalogServiceList(tx, entMeta, true)
|
||||
services, err := tx.Get(tableServices, indexID+"_prefix", entMeta)
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("failed querying services: %s", err)
|
||||
}
|
||||
|
@ -784,7 +784,7 @@ func (s *Store) ServicesByNodeMeta(ws memdb.WatchSet, filters map[string]string,
|
|||
|
||||
// We don't want to track an unlimited number of services, so we pull a
|
||||
// top-level watch to use as a fallback.
|
||||
allServices, err := catalogServiceList(tx, entMeta, false)
|
||||
allServices, err := catalogServiceListNoWildcard(tx, entMeta)
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("failed services lookup: %s", err)
|
||||
}
|
||||
|
@ -1052,7 +1052,7 @@ func (s *Store) ServiceAddressNodes(ws memdb.WatchSet, address string, entMeta *
|
|||
defer tx.Abort()
|
||||
|
||||
// List all the services.
|
||||
services, err := catalogServiceList(tx, entMeta, true)
|
||||
services, err := tx.Get(tableServices, indexID+"_prefix", entMeta)
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("failed service lookup: %s", err)
|
||||
}
|
||||
|
@ -2256,7 +2256,7 @@ func serviceDumpAllTxn(tx ReadTxn, ws memdb.WatchSet, entMeta *structs.Enterpris
|
|||
// Get the table index
|
||||
idx := catalogMaxIndexWatch(tx, ws, entMeta, true)
|
||||
|
||||
services, err := catalogServiceList(tx, entMeta, true)
|
||||
services, err := tx.Get(tableServices, indexID+"_prefix", entMeta)
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("failed service lookup: %s", err)
|
||||
}
|
||||
|
|
|
@ -106,6 +106,10 @@ func indexFromServiceNode(raw interface{}) ([]byte, error) {
|
|||
func prefixIndexFromQuery(arg interface{}) ([]byte, error) {
|
||||
var b indexBuilder
|
||||
switch v := arg.(type) {
|
||||
case *structs.EnterpriseMeta:
|
||||
return nil, nil
|
||||
case structs.EnterpriseMeta:
|
||||
return nil, nil
|
||||
case Query:
|
||||
b.String(strings.ToLower(v.Value))
|
||||
return b.Bytes(), nil
|
||||
|
@ -195,7 +199,7 @@ func catalogServiceKindMaxIndex(tx ReadTxn, ws memdb.WatchSet, kind structs.Serv
|
|||
return maxIndexWatchTxn(tx, ws, serviceKindIndexName(kind, nil))
|
||||
}
|
||||
|
||||
func catalogServiceList(tx ReadTxn, _ *structs.EnterpriseMeta, _ bool) (memdb.ResultIterator, error) {
|
||||
func catalogServiceListNoWildcard(tx ReadTxn, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
||||
return tx.Get(tableServices, indexID)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue