ResourceS with indexedFields for faster queries on string indexes

This commit is contained in:
DanB
2017-10-27 16:14:11 +02:00
parent e01ab48a8f
commit 404c366f57
2 changed files with 4 additions and 3 deletions

View File

@@ -541,7 +541,7 @@ func startResourceService(internalRsChan, internalThresholdSChan chan rpcclient.
return
}
}
rS, err := engine.NewResourceService(dm, cfg.ResourceSCfg().StoreInterval, thdSConn, filterS)
rS, err := engine.NewResourceService(dm, cfg.ResourceSCfg().StoreInterval, thdSConn, filterS, cfg.ResourceSCfg().IndexedFields)
if err != nil {
utils.Logger.Crit(fmt.Sprintf("<ResourceS> Could not init, error: %s", err.Error()))
exitChan <- true

View File

@@ -279,7 +279,7 @@ func (rs Resources) allocateResource(ru *ResourceUsage, dryRun bool) (alcMessage
// Pas the config as a whole so we can ask access concurrently
func NewResourceService(dm *DataManager, storeInterval time.Duration,
thdS rpcclient.RpcClientConnection, filterS *FilterS) (*ResourceService, error) {
thdS rpcclient.RpcClientConnection, filterS *FilterS, indexedFields []string) (*ResourceService, error) {
if thdS != nil && reflect.ValueOf(thdS).IsNil() {
thdS = nil
}
@@ -296,6 +296,7 @@ type ResourceService struct {
dm *DataManager // So we can load the data in cache and index it
thdS rpcclient.RpcClientConnection // allows applying filters based on stats
filterS *FilterS
indexedFields []string // speed up query on indexes
lcEventResources map[string][]*utils.TenantID // cache recording resources for events in alocation phase
lcERMux sync.RWMutex // protects the lcEventResources
storedResources utils.StringMap // keep a record of resources which need saving, map[resID]bool
@@ -433,7 +434,7 @@ func (rS *ResourceService) cachedResourcesForEvent(evUUID string) (rs Resources)
// matchingResourcesForEvent returns ordered list of matching resources which are active by the time of the call
func (rS *ResourceService) matchingResourcesForEvent(tenant string, ev map[string]interface{}) (rs Resources, err error) {
matchingResources := make(map[string]*Resource)
rIDs, err := matchingItemIDsForEvent(ev, nil, rS.dm, utils.ResourceProfilesStringIndex+tenant)
rIDs, err := matchingItemIDsForEvent(ev, rS.indexedFields, rS.dm, utils.ResourceProfilesStringIndex+tenant)
if err != nil {
return nil, err
}