From 4cd784ca0598ab61e24e09e82daa1fe0f9cca259 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Tue, 17 Aug 2021 16:48:23 +0300 Subject: [PATCH] Fixed index health code --- engine/datamanager.go | 4 ++-- engine/libindex_health.go | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/engine/datamanager.go b/engine/datamanager.go index 157e0ff47..7d2987142 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -740,7 +740,7 @@ func (dm *DataManager) GetThresholdProfile(tenant, id string, cacheRead, cacheWr } if err != nil { err = utils.CastRPCErr(err) - if err == utils.ErrNotFound && cacheWrite { + if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL { Cache.Set(utils.CacheThresholdProfiles, tntID, nil, nil, cacheCommit(transactionID), transactionID) @@ -2105,7 +2105,7 @@ func (dm *DataManager) GetChargerProfile(tenant, id string, cacheRead, cacheWrit } if err != nil { err = utils.CastRPCErr(err) - if err == utils.ErrNotFound && cacheWrite { + if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL{ Cache.Set(utils.CacheChargerProfiles, tntID, nil, nil, cacheCommit(transactionID), transactionID) diff --git a/engine/libindex_health.go b/engine/libindex_health.go index 015e91419..d3b84ea91 100644 --- a/engine/libindex_health.go +++ b/engine/libindex_health.go @@ -447,10 +447,11 @@ func getFilterAsIndexSet(dm *DataManager, fltrIdxCache *ltcache.Cache, idxItmTyp } // updateFilterIHMisingIndx updates the reply with the missing indexes for a specific object( obj->filter->index relation) -func updateFilterIHMisingIndx(dm *DataManager, fltrCache, fltrIdxCache *ltcache.Cache, filterIDs []string, indxType, tnt, tntCtx, itmID string, rply *FilterIHReply) (_ *FilterIHReply, err error) { +func updateFilterIHMisingIndx(dm *DataManager, fltrCache, fltrIdxCache *ltcache.Cache, filterIDs []string, + indxType, tnt, tntCtx, itmID string, missingFltrs utils.StringSet, rply *FilterIHReply) (_ *FilterIHReply, err error) { if len(filterIDs) == 0 { // no filter so check the *none:*any:*any index var rcvIndx utils.StringMap - if rcvIndx, err = getIHFltrIdxFromCache(dm, nil, indxType, tntCtx, utils.META_NONE, utils.META_ANY, utils.META_ANY); err != nil { + if rcvIndx, err = getIHFltrIdxFromCache(dm, fltrIdxCache, indxType, tntCtx, utils.META_NONE, utils.META_ANY, utils.META_ANY); err != nil { if err != utils.ErrNotFound { return } @@ -469,8 +470,10 @@ func updateFilterIHMisingIndx(dm *DataManager, fltrCache, fltrIdxCache *ltcache. if err != utils.ErrNotFound { return } - fltrID = utils.ConcatenatedKey(tnt, fltrID) - rply.MissingFilters[fltrID] = append(rply.MissingFilters[fltrID], itmID) + if tntIdxFltr := utils.ConcatenatedKey(fltrID, itmID); !missingFltrs.Has(tntIdxFltr) { // tntIdxFltr = tnt:idx:id verification to not set the same ID + missingFltrs.Add(tntIdxFltr) + rply.MissingFilters[fltrID] = append(rply.MissingFilters[fltrID], itmID) + } continue } var indexes map[string]utils.StringMap @@ -500,6 +503,7 @@ func GetFltrIdxHealth(dm *DataManager, fltrCache, fltrIdxCache, objCache *ltcach if ids, err = dm.dataDB.GetKeysForPrefix(objPrfx); err != nil { return } + missingFltrs := utils.StringSet{} // for checking multiple filters that are missing(to not append the same ID in case) for _, id := range ids { // get all the objects from DB id = strings.TrimPrefix(id, objPrfx) tntID := utils.NewTenantID(id) @@ -509,12 +513,14 @@ func GetFltrIdxHealth(dm *DataManager, fltrCache, fltrIdxCache, objCache *ltcach } if obj.contexts == nil { // update the reply - if rply, err = updateFilterIHMisingIndx(dm, fltrCache, fltrIdxCache, obj.filterIDs, indxType, tntID.Tenant, tntID.Tenant, tntID.ID, rply); err != nil { + if rply, err = updateFilterIHMisingIndx(dm, fltrCache, fltrIdxCache, obj.filterIDs, indxType, + tntID.Tenant, tntID.Tenant, tntID.ID, missingFltrs, rply); err != nil { return } } else { for _, ctx := range *obj.contexts { - if rply, err = updateFilterIHMisingIndx(dm, fltrCache, fltrIdxCache, obj.filterIDs, indxType, tntID.Tenant, utils.ConcatenatedKey(tntID.Tenant, ctx), tntID.ID, rply); err != nil { + if rply, err = updateFilterIHMisingIndx(dm, fltrCache, fltrIdxCache, obj.filterIDs, indxType, + tntID.Tenant, utils.ConcatenatedKey(tntID.Tenant, ctx), tntID.ID, missingFltrs, rply); err != nil { return } } @@ -527,6 +533,7 @@ func GetFltrIdxHealth(dm *DataManager, fltrCache, fltrIdxCache, objCache *ltcach if indexKeys, err = dm.dataDB.GetKeysForPrefix(idxPrfx); err != nil { return } + missingObj := utils.StringSet{} for _, dataID := range indexKeys { // get all the indexes dataID = strings.TrimPrefix(dataID, idxPrfx) @@ -559,11 +566,12 @@ func GetFltrIdxHealth(dm *DataManager, fltrCache, fltrIdxCache, objCache *ltcach if err != utils.ErrNotFound { return } - rply.MissingObjects = append(rply.MissingObjects, utils.ConcatenatedKey(tnt, itmID)) + missingObj.Add(utils.ConcatenatedKey(tnt, itmID)) + //rply.MissingObjects = append(rply.MissingObjects, utils.ConcatenatedKey(tnt, itmID)) err = nil continue } - if ctx != nil || + if ctx != nil && (obj.contexts == nil || !utils.IsSliceMember(*obj.contexts, *ctx)) { // check the contexts if present key := utils.ConcatenatedKey(tntCtx, idxKey) rply.MissingIndexes[key] = append(rply.MissingIndexes[key], itmID) @@ -600,6 +608,6 @@ func GetFltrIdxHealth(dm *DataManager, fltrCache, fltrIdxCache, objCache *ltcach } } } - + rply.MissingObjects = missingObj.AsSlice() return }