From 7eb6d9600b9723e0b161a40d43f616262bdc84dd Mon Sep 17 00:00:00 2001 From: DanB Date: Fri, 29 Sep 2017 09:40:50 +0200 Subject: [PATCH] ThresholdsPrefix -> ThresholdPrefix --- engine/storage_map.go | 6 +++--- engine/storage_mongo_datadb.go | 8 ++++---- engine/storage_redis.go | 6 +++--- engine/thresholds.go | 10 +++++++--- utils/consts.go | 2 +- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/engine/storage_map.go b/engine/storage_map.go index a97a70357..e7047eb72 100755 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -1627,7 +1627,7 @@ func (ms *MapStorage) RemThresholdProfile(tenant, id, transactionID string) (err func (ms *MapStorage) GetThreshold(tenant, id string, skipCache bool, transactionID string) (r *Threshold, err error) { ms.mu.RLock() defer ms.mu.RUnlock() - key := utils.ThresholdsPrefix + utils.ConcatenatedKey(tenant, id) + key := utils.ThresholdPrefix + utils.ConcatenatedKey(tenant, id) if !skipCache { if x, ok := cache.Get(key); ok { if x != nil { @@ -1656,14 +1656,14 @@ func (ms *MapStorage) SetThreshold(r *Threshold) (err error) { if err != nil { return err } - ms.dict[utils.ThresholdsPrefix+utils.ConcatenatedKey(r.Tenant, r.ID)] = result + ms.dict[utils.ThresholdPrefix+utils.ConcatenatedKey(r.Tenant, r.ID)] = result return } func (ms *MapStorage) RemoveThreshold(tenant, id string, transactionID string) (err error) { ms.mu.Lock() defer ms.mu.Unlock() - key := utils.ThresholdsPrefix + utils.ConcatenatedKey(tenant, id) + key := utils.ThresholdPrefix + utils.ConcatenatedKey(tenant, id) delete(ms.dict, key) cache.RemKey(key, cacheCommit(transactionID), transactionID) return diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 903899e3e..f6345a748 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -331,7 +331,7 @@ func (ms *MongoStorage) getColNameForPrefix(prefix string) (name string, ok bool utils.ResourcesPrefix: colRes, utils.ResourceProfilesPrefix: colRsP, utils.ThresholdProfilePrefix: colTlds, - utils.ThresholdsPrefix: colThs, + utils.ThresholdPrefix: colThs, } name, ok = colMap[prefix] return @@ -539,7 +539,7 @@ func (ms *MongoStorage) CacheDataFromDB(prfx string, ids []string, mustBeCached case utils.ThresholdProfilePrefix: tntID := utils.NewTenantID(dataID) _, err = ms.GetThresholdProfile(tntID.Tenant, tntID.ID, true, utils.NonTransactional) - case utils.ThresholdsPrefix: + case utils.ThresholdPrefix: tntID := utils.NewTenantID(dataID) _, err = ms.GetThreshold(tntID.Tenant, tntID.ID, true, utils.NonTransactional) } @@ -2188,7 +2188,7 @@ func (ms *MongoStorage) RemThresholdProfile(tenant, id, transactionID string) (e } func (ms *MongoStorage) GetThreshold(tenant, id string, skipCache bool, transactionID string) (r *Threshold, err error) { - key := utils.ThresholdsPrefix + utils.ConcatenatedKey(tenant, id) + key := utils.ThresholdPrefix + utils.ConcatenatedKey(tenant, id) if !skipCache { if x, ok := cache.Get(key); ok { if x == nil { @@ -2224,7 +2224,7 @@ func (ms *MongoStorage) RemoveThreshold(tenant, id string, transactionID string) if err = col.Remove(bson.M{"tenant": tenant, "id": id}); err != nil { return } - cache.RemKey(utils.ThresholdsPrefix+utils.ConcatenatedKey(tenant, id), + cache.RemKey(utils.ThresholdPrefix+utils.ConcatenatedKey(tenant, id), cacheCommit(transactionID), transactionID) return nil } diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 710fe5442..dd49f6c21 100755 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -1735,7 +1735,7 @@ func (rs *RedisStorage) RemThresholdProfile(tenant, id, transactionID string) (e } func (rs *RedisStorage) GetThreshold(tenant, id string, skipCache bool, transactionID string) (r *Threshold, err error) { - key := utils.ThresholdsPrefix + utils.ConcatenatedKey(tenant, id) + key := utils.ThresholdPrefix + utils.ConcatenatedKey(tenant, id) if !skipCache { if x, ok := cache.Get(key); ok { if x == nil { @@ -1764,11 +1764,11 @@ func (rs *RedisStorage) SetThreshold(r *Threshold) (err error) { if err != nil { return err } - return rs.Cmd("SET", utils.ThresholdsPrefix+utils.ConcatenatedKey(r.Tenant, r.ID), result).Err + return rs.Cmd("SET", utils.ThresholdPrefix+utils.ConcatenatedKey(r.Tenant, r.ID), result).Err } func (rs *RedisStorage) RemoveThreshold(tenant, id string, transactionID string) (err error) { - key := utils.ThresholdsPrefix + utils.ConcatenatedKey(tenant, id) + key := utils.ThresholdPrefix + utils.ConcatenatedKey(tenant, id) if err = rs.Cmd("DEL", key).Err; err != nil { return } diff --git a/engine/thresholds.go b/engine/thresholds.go index 516c5fa64..6b3ab328f 100644 --- a/engine/thresholds.go +++ b/engine/thresholds.go @@ -133,7 +133,7 @@ func (tS *ThresholdService) storeThresholds() { if tID == "" { break // no more keys, backup completed } - if tIf, ok := cache.Get(utils.ThresholdsPrefix + tID); !ok || tIf == nil { + if tIf, ok := cache.Get(utils.ThresholdPrefix + tID); !ok || tIf == nil { utils.Logger.Warning(fmt.Sprintf(" failed retrieving from cache resource with ID: %s", tID)) } else if err := tS.StoreThreshold(tIf.(*Threshold)); err != nil { failedTdIDs = append(failedTdIDs, tID) // record failure so we can schedule it for next backup @@ -155,8 +155,8 @@ func (tS *ThresholdService) StoreThreshold(t *Threshold) (err error) { if t.dirty == nil || !*t.dirty { return } - guardian.Guardian.GuardIDs(config.CgrConfig().LockingTimeout, utils.ThresholdsPrefix+t.TenantID()) - defer guardian.Guardian.UnguardIDs(utils.ThresholdsPrefix + t.TenantID()) + guardian.Guardian.GuardIDs(config.CgrConfig().LockingTimeout, utils.ThresholdPrefix+t.TenantID()) + defer guardian.Guardian.UnguardIDs(utils.ThresholdPrefix + t.TenantID()) if err = tS.dm.DataDB().SetThreshold(t); err != nil { utils.Logger.Warning( fmt.Sprintf(" failed saving Threshold with tenant: %s and ID: %s, error: %s", @@ -202,14 +202,18 @@ func (tS *ThresholdService) matchingThresholdsForEvent(ev *ThresholdEvent) (ts T if !passAllFilters { continue } + lockThreshold := utils.ThresholdPrefix + tPrfl.TenantID() + guardian.Guardian.GuardIDs(config.CgrConfig().LockingTimeout, lockThreshold) t, err := tS.dm.DataDB().GetThreshold(tPrfl.Tenant, tPrfl.ID, false, "") if err != nil { + guardian.Guardian.UnguardIDs(lockThreshold) return nil, err } if tPrfl.Recurrent && t.dirty == nil { t.dirty = utils.BoolPointer(false) } t.tPrfl = tPrfl + guardian.Guardian.UnguardIDs(lockThreshold) matchingTs[tPrfl.ID] = t } // All good, convert from Map to Slice so we can sort diff --git a/utils/consts.go b/utils/consts.go index d682291d5..b2462568d 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -244,7 +244,7 @@ const ( ResourceProfilesStringIndex = "rsi_" ResourceProfilesPrefix = "rsp_" StatQueuesStringIndex = "ssi_" - ThresholdsPrefix = "ths_" + ThresholdPrefix = "ths_" ThresholdsIndex = "thi_" TimingsPrefix = "tmg_" CDR_STATS_PREFIX = "cst_"