From 404c366f5758b5cfb22a683a4e96dab6b9751a8c Mon Sep 17 00:00:00 2001 From: DanB Date: Fri, 27 Oct 2017 16:14:11 +0200 Subject: [PATCH] ResourceS with indexedFields for faster queries on string indexes --- cmd/cgr-engine/cgr-engine.go | 2 +- engine/resources.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index ec8e2b116..a060deb28 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -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(" Could not init, error: %s", err.Error())) exitChan <- true diff --git a/engine/resources.go b/engine/resources.go index 301f23f07..b4450d26c 100755 --- a/engine/resources.go +++ b/engine/resources.go @@ -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 }