ThresholdsPrefix -> ThresholdPrefix

This commit is contained in:
DanB
2017-09-29 09:40:50 +02:00
parent fa02de9bba
commit 7eb6d9600b
5 changed files with 18 additions and 14 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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("<ThresholdS> 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("<ThresholdS> 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

View File

@@ -244,7 +244,7 @@ const (
ResourceProfilesStringIndex = "rsi_"
ResourceProfilesPrefix = "rsp_"
StatQueuesStringIndex = "ssi_"
ThresholdsPrefix = "ths_"
ThresholdPrefix = "ths_"
ThresholdsIndex = "thi_"
TimingsPrefix = "tmg_"
CDR_STATS_PREFIX = "cst_"