diff --git a/config/config.go b/config/config.go index 5f4554762..3ef056733 100755 --- a/config/config.go +++ b/config/config.go @@ -446,17 +446,19 @@ func (cfg *CGRConfig) loadDataDBCfg(jsnCfg *CgrJsonCfg) (err error) { if err = cfg.dataDbCfg.loadFromJsonCfg(jsnDataDbCfg); err != nil { return } - // in case of internalDB we need to disable the cache - // so we enforce it here - if cfg.dataDbCfg.DataDbType == utils.INTERNAL { - // overwrite only DataDBPartitions and leave other unmodified ( e.g. *diameter_messages, *closed_sessions, etc... ) - for key := range utils.CacheDataDBPartitions { - if _, has := cfg.cacheCfg.Partitions[key]; has { - cfg.cacheCfg.Partitions[key] = &CacheParamCfg{Limit: 0, - TTL: time.Duration(0), StaticTTL: false, Precache: false} + /* + // in case of internalDB we need to disable the cache + // so we enforce it here + if cfg.dataDbCfg.DataDbType == utils.INTERNAL { + // overwrite only DataDBPartitions and leave other unmodified ( e.g. *diameter_messages, *closed_sessions, etc... ) + for key := range utils.CacheDataDBPartitions { + if _, has := cfg.cacheCfg.Partitions[key]; has { + cfg.cacheCfg.Partitions[key] = &CacheParamCfg{Limit: 0, + TTL: time.Duration(0), StaticTTL: false, Precache: false} + } } } - } + */ return } diff --git a/config/configsanity.go b/config/configsanity.go index 10cbf15e3..995c5bdc3 100644 --- a/config/configsanity.go +++ b/config/configsanity.go @@ -592,11 +592,13 @@ func (cfg *CGRConfig) checkConfigSanity() error { } // DataDB sanity checks if cfg.dataDbCfg.DataDbType == utils.INTERNAL { - for key, config := range cfg.cacheCfg.Partitions { - if utils.CacheDataDBPartitions.Has(key) && config.Limit != 0 { - return fmt.Errorf("<%s> %s needs to be 0 when DataBD is *internal, received : %d", utils.CacheS, key, config.Limit) + /* + for key, config := range cfg.cacheCfg.Partitions { + if utils.CacheDataDBPartitions.Has(key) && config.Limit != 0 { + return fmt.Errorf("<%s> %s needs to be 0 when DataBD is *internal, received : %d", utils.CacheS, key, config.Limit) + } } - } + */ if cfg.resourceSCfg.Enabled == true && cfg.resourceSCfg.StoreInterval != -1 { return fmt.Errorf("<%s> the StoreInterval field needs to be -1 when DataBD is *internal, received : %d", utils.ResourceS, cfg.resourceSCfg.StoreInterval) } diff --git a/config/configsanity_test.go b/config/configsanity_test.go index 62ba04514..407150569 100644 --- a/config/configsanity_test.go +++ b/config/configsanity_test.go @@ -737,7 +737,6 @@ func TestConfigSanityDataDB(t *testing.T) { if err := cfg.checkConfigSanity(); err != nil { t.Error(err) } - cfg.cacheCfg = &CacheCfg{ Partitions: map[string]*CacheParamCfg{ utils.CacheAccounts: &CacheParamCfg{ @@ -746,9 +745,10 @@ func TestConfigSanityDataDB(t *testing.T) { }, } expected := " *accounts needs to be 0 when DataBD is *internal, received : 1" - if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected { - t.Errorf("Expecting: %+q received: %+q", expected, err) - } + /* + if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected { + t.Errorf("Expecting: %+q received: %+q", expected, err) + }*/ cfg.cacheCfg.Partitions[utils.CacheAccounts].Limit = 0 cfg.resourceSCfg.Enabled = true expected = " the StoreInterval field needs to be -1 when DataBD is *internal, received : 0" diff --git a/engine/caches.go b/engine/caches.go index 298ac3ad0..9188dc388 100644 --- a/engine/caches.go +++ b/engine/caches.go @@ -134,6 +134,13 @@ func (chS *CacheS) Set(chID, itmID string, value interface{}, return chS.ReplicateSet(chID, itmID, value) } +// SetWithoutReplicate is an exported method from TransCache +// handled Replicate functionality +func (chS *CacheS) SetWithoutReplicate(chID, itmID string, value interface{}, + groupIDs []string, commit bool, transID string) { + chS.tCache.Set(chID, itmID, value, groupIDs, commit, transID) +} + // HasItem is an exported method from TransCache func (chS *CacheS) HasItem(chID, itmID string) (has bool) { return chS.tCache.HasItem(chID, itmID) @@ -155,6 +162,11 @@ func (chS *CacheS) Remove(chID, itmID string, commit bool, transID string) (err return chS.ReplicateRemove(chID, itmID) } +// RemoveWithoutReplicate is an exported method from TransCache +func (chS *CacheS) RemoveWithoutReplicate(chID, itmID string, commit bool, transID string) { + chS.tCache.Remove(chID, itmID, commit, transID) +} + // Clear is an exported method from TransCache func (chS *CacheS) Clear(chIDs []string) { chS.tCache.Clear(chIDs) diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 21b1aed60..fe9041d3e 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -112,7 +112,7 @@ func init() { if err := csvr.WriteToDatabase(false, false); err != nil { log.Print("error when writing into database", err) } - Cache.Clear(nil) + // Cache.Clear(nil) } func TestLoadDestinations(t *testing.T) { diff --git a/engine/storage_internal_datadb.go b/engine/storage_internal_datadb.go index 2e76efa0c..1197c74d6 100644 --- a/engine/storage_internal_datadb.go +++ b/engine/storage_internal_datadb.go @@ -212,135 +212,130 @@ func newInternalDBCfg(itemsCacheCfg map[string]*config.ItemOpt, isDataDB bool) m StaticTTL: itemsCacheCfg[utils.MetaIndexes].StaticTTL, }, } - } else { - return map[string]*ltcache.CacheConfig{ - utils.TBLVersions: { - MaxItems: itemsCacheCfg[utils.TBLVersions].Limit, - TTL: itemsCacheCfg[utils.TBLVersions].TTL, - StaticTTL: itemsCacheCfg[utils.TBLVersions].StaticTTL, - }, - utils.TBLTPTimings: { - MaxItems: itemsCacheCfg[utils.TBLTPTimings].Limit, - TTL: itemsCacheCfg[utils.TBLTPTimings].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPTimings].StaticTTL, - }, - utils.TBLTPDestinations: { - MaxItems: itemsCacheCfg[utils.TBLTPDestinations].Limit, - TTL: itemsCacheCfg[utils.TBLTPDestinations].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPDestinations].StaticTTL, - }, - utils.TBLTPRates: { - MaxItems: itemsCacheCfg[utils.TBLTPRates].Limit, - TTL: itemsCacheCfg[utils.TBLTPRates].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPRates].StaticTTL, - }, - utils.TBLTPDestinationRates: { - MaxItems: itemsCacheCfg[utils.TBLTPDestinationRates].Limit, - TTL: itemsCacheCfg[utils.TBLTPDestinationRates].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPDestinationRates].StaticTTL, - }, - utils.TBLTPRatingPlans: { - MaxItems: itemsCacheCfg[utils.TBLTPRatingPlans].Limit, - TTL: itemsCacheCfg[utils.TBLTPRatingPlans].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPRatingPlans].StaticTTL, - }, - utils.TBLTPRatingProfiles: { - MaxItems: itemsCacheCfg[utils.TBLTPRatingProfiles].Limit, - TTL: itemsCacheCfg[utils.TBLTPRatingProfiles].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPRatingProfiles].StaticTTL, - }, - utils.TBLTPSharedGroups: { - MaxItems: itemsCacheCfg[utils.TBLTPSharedGroups].Limit, - TTL: itemsCacheCfg[utils.TBLTPSharedGroups].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPSharedGroups].StaticTTL, - }, - utils.TBLTPActions: { - MaxItems: itemsCacheCfg[utils.TBLTPActions].Limit, - TTL: itemsCacheCfg[utils.TBLTPActions].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPActions].StaticTTL, - }, - utils.TBLTPActionTriggers: { - MaxItems: itemsCacheCfg[utils.TBLTPActionTriggers].Limit, - TTL: itemsCacheCfg[utils.TBLTPActionTriggers].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPActionTriggers].StaticTTL, - }, - utils.TBLTPAccountActions: { - MaxItems: itemsCacheCfg[utils.TBLTPAccountActions].Limit, - TTL: itemsCacheCfg[utils.TBLTPAccountActions].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPAccountActions].StaticTTL, - }, - utils.TBLTPResources: { - MaxItems: itemsCacheCfg[utils.TBLTPResources].Limit, - TTL: itemsCacheCfg[utils.TBLTPResources].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPResources].StaticTTL, - }, - utils.TBLTPStats: { - MaxItems: itemsCacheCfg[utils.TBLTPStats].Limit, - TTL: itemsCacheCfg[utils.TBLTPStats].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPStats].StaticTTL, - }, - utils.TBLTPThresholds: { - MaxItems: itemsCacheCfg[utils.TBLTPThresholds].Limit, - TTL: itemsCacheCfg[utils.TBLTPThresholds].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPThresholds].StaticTTL, - }, - utils.TBLTPFilters: { - MaxItems: itemsCacheCfg[utils.TBLTPFilters].Limit, - TTL: itemsCacheCfg[utils.TBLTPFilters].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPFilters].StaticTTL, - }, - utils.SessionCostsTBL: { - MaxItems: itemsCacheCfg[utils.SessionCostsTBL].Limit, - TTL: itemsCacheCfg[utils.SessionCostsTBL].TTL, - StaticTTL: itemsCacheCfg[utils.SessionCostsTBL].StaticTTL, - }, - utils.TBLTPActionPlans: { - MaxItems: itemsCacheCfg[utils.TBLTPActionPlans].Limit, - TTL: itemsCacheCfg[utils.TBLTPActionPlans].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPActionPlans].StaticTTL, - }, - utils.TBLTPRoutes: { - MaxItems: itemsCacheCfg[utils.TBLTPRoutes].Limit, - TTL: itemsCacheCfg[utils.TBLTPRoutes].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPRoutes].StaticTTL, - }, - utils.TBLTPAttributes: { - MaxItems: itemsCacheCfg[utils.TBLTPAttributes].Limit, - TTL: itemsCacheCfg[utils.TBLTPAttributes].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPAttributes].StaticTTL, - }, - utils.TBLTPChargers: { - MaxItems: itemsCacheCfg[utils.TBLTPChargers].Limit, - TTL: itemsCacheCfg[utils.TBLTPChargers].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPChargers].StaticTTL, - }, - utils.TBLTPDispatchers: { - MaxItems: itemsCacheCfg[utils.TBLTPDispatchers].Limit, - TTL: itemsCacheCfg[utils.TBLTPDispatchers].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPDispatchers].StaticTTL, - }, - utils.TBLTPDispatcherHosts: { - MaxItems: itemsCacheCfg[utils.TBLTPDispatcherHosts].Limit, - TTL: itemsCacheCfg[utils.TBLTPDispatcherHosts].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPDispatcherHosts].StaticTTL, - }, - utils.TBLTPRateProfiles: { - MaxItems: itemsCacheCfg[utils.TBLTPRateProfiles].Limit, - TTL: itemsCacheCfg[utils.TBLTPRateProfiles].TTL, - StaticTTL: itemsCacheCfg[utils.TBLTPRateProfiles].StaticTTL, - }, - utils.CDRsTBL: { - MaxItems: itemsCacheCfg[utils.CDRsTBL].Limit, - TTL: itemsCacheCfg[utils.CDRsTBL].TTL, - StaticTTL: itemsCacheCfg[utils.CDRsTBL].StaticTTL, - }, - } + } + return map[string]*ltcache.CacheConfig{ + utils.TBLVersions: { + MaxItems: itemsCacheCfg[utils.TBLVersions].Limit, + TTL: itemsCacheCfg[utils.TBLVersions].TTL, + StaticTTL: itemsCacheCfg[utils.TBLVersions].StaticTTL, + }, + utils.TBLTPTimings: { + MaxItems: itemsCacheCfg[utils.TBLTPTimings].Limit, + TTL: itemsCacheCfg[utils.TBLTPTimings].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPTimings].StaticTTL, + }, + utils.TBLTPDestinations: { + MaxItems: itemsCacheCfg[utils.TBLTPDestinations].Limit, + TTL: itemsCacheCfg[utils.TBLTPDestinations].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPDestinations].StaticTTL, + }, + utils.TBLTPRates: { + MaxItems: itemsCacheCfg[utils.TBLTPRates].Limit, + TTL: itemsCacheCfg[utils.TBLTPRates].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPRates].StaticTTL, + }, + utils.TBLTPDestinationRates: { + MaxItems: itemsCacheCfg[utils.TBLTPDestinationRates].Limit, + TTL: itemsCacheCfg[utils.TBLTPDestinationRates].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPDestinationRates].StaticTTL, + }, + utils.TBLTPRatingPlans: { + MaxItems: itemsCacheCfg[utils.TBLTPRatingPlans].Limit, + TTL: itemsCacheCfg[utils.TBLTPRatingPlans].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPRatingPlans].StaticTTL, + }, + utils.TBLTPRateProfiles: { + MaxItems: itemsCacheCfg[utils.TBLTPRateProfiles].Limit, + TTL: itemsCacheCfg[utils.TBLTPRateProfiles].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPRateProfiles].StaticTTL, + }, + utils.TBLTPSharedGroups: { + MaxItems: itemsCacheCfg[utils.TBLTPSharedGroups].Limit, + TTL: itemsCacheCfg[utils.TBLTPSharedGroups].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPSharedGroups].StaticTTL, + }, + utils.TBLTPActions: { + MaxItems: itemsCacheCfg[utils.TBLTPActions].Limit, + TTL: itemsCacheCfg[utils.TBLTPActions].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPActions].StaticTTL, + }, + utils.TBLTPActionTriggers: { + MaxItems: itemsCacheCfg[utils.TBLTPActionTriggers].Limit, + TTL: itemsCacheCfg[utils.TBLTPActionTriggers].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPActionTriggers].StaticTTL, + }, + utils.TBLTPAccountActions: { + MaxItems: itemsCacheCfg[utils.TBLTPAccountActions].Limit, + TTL: itemsCacheCfg[utils.TBLTPAccountActions].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPAccountActions].StaticTTL, + }, + utils.TBLTPResources: { + MaxItems: itemsCacheCfg[utils.TBLTPResources].Limit, + TTL: itemsCacheCfg[utils.TBLTPResources].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPResources].StaticTTL, + }, + utils.TBLTPStats: { + MaxItems: itemsCacheCfg[utils.TBLTPStats].Limit, + TTL: itemsCacheCfg[utils.TBLTPStats].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPStats].StaticTTL, + }, + utils.TBLTPThresholds: { + MaxItems: itemsCacheCfg[utils.TBLTPThresholds].Limit, + TTL: itemsCacheCfg[utils.TBLTPThresholds].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPThresholds].StaticTTL, + }, + utils.TBLTPFilters: { + MaxItems: itemsCacheCfg[utils.TBLTPFilters].Limit, + TTL: itemsCacheCfg[utils.TBLTPFilters].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPFilters].StaticTTL, + }, + utils.SessionCostsTBL: { + MaxItems: itemsCacheCfg[utils.SessionCostsTBL].Limit, + TTL: itemsCacheCfg[utils.SessionCostsTBL].TTL, + StaticTTL: itemsCacheCfg[utils.SessionCostsTBL].StaticTTL, + }, + utils.TBLTPActionPlans: { + MaxItems: itemsCacheCfg[utils.TBLTPActionPlans].Limit, + TTL: itemsCacheCfg[utils.TBLTPActionPlans].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPActionPlans].StaticTTL, + }, + utils.TBLTPRoutes: { + MaxItems: itemsCacheCfg[utils.TBLTPRoutes].Limit, + TTL: itemsCacheCfg[utils.TBLTPRoutes].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPRoutes].StaticTTL, + }, + utils.TBLTPAttributes: { + MaxItems: itemsCacheCfg[utils.TBLTPAttributes].Limit, + TTL: itemsCacheCfg[utils.TBLTPAttributes].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPAttributes].StaticTTL, + }, + utils.TBLTPChargers: { + MaxItems: itemsCacheCfg[utils.TBLTPChargers].Limit, + TTL: itemsCacheCfg[utils.TBLTPChargers].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPChargers].StaticTTL, + }, + utils.TBLTPDispatchers: { + MaxItems: itemsCacheCfg[utils.TBLTPDispatchers].Limit, + TTL: itemsCacheCfg[utils.TBLTPDispatchers].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPDispatchers].StaticTTL, + }, + utils.TBLTPDispatcherHosts: { + MaxItems: itemsCacheCfg[utils.TBLTPDispatcherHosts].Limit, + TTL: itemsCacheCfg[utils.TBLTPDispatcherHosts].TTL, + StaticTTL: itemsCacheCfg[utils.TBLTPDispatcherHosts].StaticTTL, + }, + utils.CDRsTBL: { + MaxItems: itemsCacheCfg[utils.CDRsTBL].Limit, + TTL: itemsCacheCfg[utils.CDRsTBL].TTL, + StaticTTL: itemsCacheCfg[utils.CDRsTBL].StaticTTL, + }, } } +// InternalDB is used as a DataDB and a StorDB type InternalDB struct { - tasks []*Task - db *ltcache.TransCache + tasks []*Task + // db *ltcache.TransCache mu sync.RWMutex stringIndexedFields []string prefixIndexedFields []string @@ -354,7 +349,7 @@ func NewInternalDB(stringIndexedFields, prefixIndexedFields []string, isDataDB bool, itemsCacheCfg map[string]*config.ItemOpt) (iDB *InternalDB) { ms, _ := NewMarshaler(config.CgrConfig().GeneralCfg().DBDataEncoding) iDB = &InternalDB{ - db: ltcache.NewTransCache(newInternalDBCfg(itemsCacheCfg, isDataDB)), + // db: ltcache.NewTransCache(newInternalDBCfg(itemsCacheCfg, isDataDB)), stringIndexedFields: stringIndexedFields, prefixIndexedFields: prefixIndexedFields, cnter: utils.NewCounter(time.Now().UnixNano(), 0), @@ -377,97 +372,104 @@ func (iDB *InternalDB) SetPrefixIndexedFields(prefixIndexedFields []string) { iDB.indexedFieldsMutex.Unlock() } +// Close only to implement Storage interface func (iDB *InternalDB) Close() {} -func (iDB *InternalDB) Flush(_ string) error { - iDB.db.Clear(nil) +// Flush clears the cache +func (iDB *InternalDB) Flush(string) error { + Cache.Clear(nil) return nil } -func (iDB *InternalDB) SelectDatabase(dbName string) (err error) { +// SelectDatabase only to implement Storage interface +func (iDB *InternalDB) SelectDatabase(string) (err error) { return nil } -func (iDB *InternalDB) GetKeysForPrefix(prefix string) ([]string, error) { +// GetKeysForPrefix returns the keys from cache that have the given prefix +func (iDB *InternalDB) GetKeysForPrefix(prefix string) (ids []string, err error) { keyLen := len(utils.DESTINATION_PREFIX) if len(prefix) < keyLen { - return nil, fmt.Errorf("unsupported prefix in GetKeysForPrefix: %s", prefix) + err = fmt.Errorf("unsupported prefix in GetKeysForPrefix: %s", prefix) + return } category := prefix[:keyLen] // prefix length queryPrefix := prefix[keyLen:] - ids := iDB.db.GetItemIDs(utils.CachePrefixToInstance[category], queryPrefix) + ids = Cache.GetItemIDs(utils.CachePrefixToInstance[category], queryPrefix) for i := range ids { ids[i] = category + ids[i] } - return ids, nil + return } +// RebuildReverseForPrefix will build the reverse destinations func (iDB *InternalDB) RebuildReverseForPrefix(prefix string) (err error) { - keys, err := iDB.GetKeysForPrefix(prefix) - if err != nil { - return err - } - for _, key := range keys { - iDB.db.Remove(utils.CacheReverseDestinations, key, - cacheCommit(utils.NonTransactional), utils.NonTransactional) - } switch prefix { case utils.REVERSE_DESTINATION_PREFIX: - keys, err = iDB.GetKeysForPrefix(utils.DESTINATION_PREFIX) - if err != nil { - return err + var keys []string + if keys, err = iDB.GetKeysForPrefix(prefix); err != nil { + return } for _, key := range keys { - dest, err := iDB.GetDestinationDrv(key[len(utils.DESTINATION_PREFIX):], false, utils.NonTransactional) - if err != nil { - return err + Cache.RemoveWithoutReplicate(utils.CacheReverseDestinations, key, + cacheCommit(utils.NonTransactional), utils.NonTransactional) + } + + if keys, err = iDB.GetKeysForPrefix(utils.DESTINATION_PREFIX); err != nil { + return + } + for _, key := range keys { + var dest *Destination + if dest, err = iDB.GetDestinationDrv(key[len(utils.DESTINATION_PREFIX):], + false, utils.NonTransactional); err != nil { + return } - if err := iDB.SetReverseDestinationDrv(dest, utils.NonTransactional); err != nil { - return err + if err = iDB.SetReverseDestinationDrv(dest, utils.NonTransactional); err != nil { + return } } case utils.AccountActionPlansPrefix: - return nil default: return utils.ErrInvalidKey } - return nil + return } +// RemoveReverseForPrefix implementation func (iDB *InternalDB) RemoveReverseForPrefix(prefix string) (err error) { - keys, err := iDB.GetKeysForPrefix(prefix) - if err != nil { - return err - } - for _, key := range keys { - iDB.db.Remove(utils.CacheReverseDestinations, key, - cacheCommit(utils.NonTransactional), utils.NonTransactional) - } switch prefix { case utils.REVERSE_DESTINATION_PREFIX: + var keys []string + if keys, err = iDB.GetKeysForPrefix(prefix); err != nil { + return + } + for _, key := range keys { + Cache.RemoveWithoutReplicate(utils.CacheReverseDestinations, key, + cacheCommit(utils.NonTransactional), utils.NonTransactional) + } keys, err = iDB.GetKeysForPrefix(utils.DESTINATION_PREFIX) if err != nil { return err } for _, key := range keys { - dest, err := iDB.GetDestinationDrv(key[len(utils.DESTINATION_PREFIX):], false, utils.NonTransactional) - if err != nil { - return err + var dest *Destination + if dest, err = iDB.GetDestinationDrv(key[len(utils.DESTINATION_PREFIX):], + false, utils.NonTransactional); err != nil { + return } - if err := iDB.RemoveDestinationDrv(dest.Id, utils.NonTransactional); err != nil { - return err + if err = iDB.RemoveDestinationDrv(dest.Id, utils.NonTransactional); err != nil { + return } } case utils.AccountActionPlansPrefix: - return nil default: return utils.ErrInvalidKey } - return nil + return } func (iDB *InternalDB) GetVersions(itm string) (vrs Versions, err error) { - x, ok := iDB.db.Get(utils.TBLVersions, utils.Version) + x, ok := Cache.Get(utils.CacheVersions, utils.Version) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -484,12 +486,12 @@ func (iDB *InternalDB) GetVersions(itm string) (vrs Versions, err error) { func (iDB *InternalDB) SetVersions(vrs Versions, overwrite bool) (err error) { if overwrite { if err = iDB.RemoveVersions(nil); err != nil { - return err + return } } - x, ok := iDB.db.Get(utils.TBLVersions, utils.Version) + x, ok := Cache.Get(utils.CacheVersions, utils.Version) if !ok || x == nil { - iDB.db.Set(utils.TBLVersions, utils.Version, vrs, nil, + Cache.SetWithoutReplicate(utils.CacheVersions, utils.Version, vrs, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } @@ -497,7 +499,7 @@ func (iDB *InternalDB) SetVersions(vrs Versions, overwrite bool) (err error) { for key, val := range vrs { provVrs[key] = val } - iDB.db.Set(utils.TBLVersions, utils.Version, provVrs, nil, + Cache.SetWithoutReplicate(utils.CacheVersions, utils.Version, provVrs, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } @@ -505,7 +507,7 @@ func (iDB *InternalDB) SetVersions(vrs Versions, overwrite bool) (err error) { func (iDB *InternalDB) RemoveVersions(vrs Versions) (err error) { if len(vrs) != 0 { var internalVersions Versions - x, ok := iDB.db.Get(utils.TBLVersions, utils.Version) + x, ok := Cache.Get(utils.CacheVersions, utils.Version) if !ok || x == nil { return utils.ErrNotFound } @@ -513,44 +515,47 @@ func (iDB *InternalDB) RemoveVersions(vrs Versions) (err error) { for key := range vrs { delete(internalVersions, key) } - iDB.db.Set(utils.TBLVersions, utils.Version, internalVersions, nil, + Cache.SetWithoutReplicate(utils.CacheVersions, utils.Version, internalVersions, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) - return nil + return } - iDB.db.Remove(utils.TBLVersions, utils.Version, + Cache.RemoveWithoutReplicate(utils.CacheVersions, utils.Version, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } +// GetStorageType returns the storage type func (iDB *InternalDB) GetStorageType() string { return utils.INTERNAL } -func (iDB *InternalDB) IsDBEmpty() (resp bool, err error) { - for cacheInstance, _ := range utils.CacheInstanceToPrefix { - if len(iDB.db.GetItemIDs(cacheInstance, utils.EmptyString)) != 0 { - return false, nil +// IsDBEmpty returns true if the cache is empty +func (iDB *InternalDB) IsDBEmpty() (isEmpty bool, err error) { + for cacheInstance := range utils.CacheInstanceToPrefix { + if len(Cache.GetItemIDs(cacheInstance, utils.EmptyString)) != 0 { + return } } - return true, nil + isEmpty = true + return } func (iDB *InternalDB) HasDataDrv(category, subject, tenant string) (bool, error) { switch category { case utils.DESTINATION_PREFIX, utils.RATING_PLAN_PREFIX, utils.RATING_PROFILE_PREFIX, utils.ACTION_PREFIX, utils.ACTION_PLAN_PREFIX, utils.ACCOUNT_PREFIX: - return iDB.db.HasItem(utils.CachePrefixToInstance[category], subject), nil + return Cache.HasItem(utils.CachePrefixToInstance[category], subject), nil case utils.ResourcesPrefix, utils.ResourceProfilesPrefix, utils.StatQueuePrefix, utils.StatQueueProfilePrefix, utils.ThresholdPrefix, utils.ThresholdProfilePrefix, utils.FilterPrefix, utils.RouteProfilePrefix, utils.AttributeProfilePrefix, utils.ChargerProfilePrefix, utils.DispatcherProfilePrefix, utils.DispatcherHostPrefix: - return iDB.db.HasItem(utils.CachePrefixToInstance[category], utils.ConcatenatedKey(tenant, subject)), nil + return Cache.HasItem(utils.CachePrefixToInstance[category], utils.ConcatenatedKey(tenant, subject)), nil } return false, errors.New("Unsupported HasData category") } func (iDB *InternalDB) GetRatingPlanDrv(id string) (rp *RatingPlan, err error) { - x, ok := iDB.db.Get(utils.CacheRatingPlans, id) + x, ok := Cache.Get(utils.CacheRatingPlans, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -558,19 +563,19 @@ func (iDB *InternalDB) GetRatingPlanDrv(id string) (rp *RatingPlan, err error) { } func (iDB *InternalDB) SetRatingPlanDrv(rp *RatingPlan) (err error) { - iDB.db.Set(utils.CacheRatingPlans, rp.Id, rp, nil, + Cache.SetWithoutReplicate(utils.CacheRatingPlans, rp.Id, rp, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveRatingPlanDrv(id string) (err error) { - iDB.db.Remove(utils.CacheRatingPlans, id, + Cache.RemoveWithoutReplicate(utils.CacheRatingPlans, id, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetRatingProfileDrv(id string) (rp *RatingProfile, err error) { - x, ok := iDB.db.Get(utils.CacheRatingProfiles, id) + x, ok := Cache.Get(utils.CacheRatingProfiles, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -578,69 +583,41 @@ func (iDB *InternalDB) GetRatingProfileDrv(id string) (rp *RatingProfile, err er } func (iDB *InternalDB) SetRatingProfileDrv(rp *RatingProfile) (err error) { - iDB.db.Set(utils.CacheRatingProfiles, rp.Id, rp, nil, + Cache.SetWithoutReplicate(utils.CacheRatingProfiles, rp.Id, rp, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveRatingProfileDrv(id string) (err error) { - iDB.db.Remove(utils.CacheRatingProfiles, id, + Cache.RemoveWithoutReplicate(utils.CacheRatingProfiles, id, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } -func (iDB *InternalDB) GetDestinationDrv(key string, skipCache bool, transactionID string) (dest *Destination, err error) { - cCommit := cacheCommit(transactionID) - - if !skipCache { - if x, ok := Cache.Get(utils.CacheDestinations, key); ok { - if x != nil { - return x.(*Destination), nil - } - return nil, utils.ErrNotFound - } +func (iDB *InternalDB) GetDestinationDrv(key string, _ bool, _ string) (dest *Destination, err error) { + if x, ok := Cache.Get(utils.CacheDestinations, key); ok && x != nil { + return x.(*Destination), nil } - - x, ok := iDB.db.Get(utils.CacheDestinations, key) - if !ok || x == nil { - if errCh := Cache.Set(utils.CacheDestinations, key, nil, nil, cCommit, transactionID); errCh != nil { - return nil, errCh - } - return nil, utils.ErrNotFound - } - dest = x.(*Destination) - if errCh := Cache.Set(utils.CacheDestinations, key, dest, nil, cCommit, transactionID); errCh != nil { - return nil, errCh - } - return + return nil, utils.ErrNotFound } func (iDB *InternalDB) SetDestinationDrv(dest *Destination, transactionID string) (err error) { - iDB.db.Set(utils.CacheDestinations, dest.Id, dest, nil, + Cache.SetWithoutReplicate(utils.CacheDestinations, dest.Id, dest, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) - if errCh := Cache.Remove(utils.CacheDestinations, dest.Id, - cacheCommit(transactionID), transactionID); errCh != nil { - return errCh - } return } func (iDB *InternalDB) RemoveDestinationDrv(destID string, transactionID string) (err error) { // get destination for prefix list - d, err := iDB.GetDestinationDrv(destID, false, transactionID) - if err != nil { + var d *Destination + if d, err = iDB.GetDestinationDrv(destID, false, transactionID); err != nil { return } - iDB.db.Remove(utils.CacheDestinations, destID, - cacheCommit(utils.NonTransactional), utils.NonTransactional) - if errCh := Cache.Remove(utils.CacheDestinations, destID, - cacheCommit(transactionID), transactionID); errCh != nil { - return errCh - } + Cache.RemoveWithoutReplicate(utils.CacheDestinations, destID, + cacheCommit(transactionID), transactionID) for _, prefix := range d.Prefixes { - iDB.db.Remove(utils.CacheReverseDestinations, prefix, + Cache.RemoveWithoutReplicate(utils.CacheReverseDestinations, prefix, cacheCommit(utils.NonTransactional), utils.NonTransactional) - iDB.GetReverseDestinationDrv(prefix, true, transactionID) // it will recache the destination } return } @@ -648,8 +625,8 @@ func (iDB *InternalDB) RemoveDestinationDrv(destID string, transactionID string) func (iDB *InternalDB) SetReverseDestinationDrv(dest *Destination, transactionID string) (err error) { var mpRevDst utils.StringMap for _, p := range dest.Prefixes { - if iDB.db.HasItem(utils.CacheReverseDestinations, p) { - x, ok := iDB.db.Get(utils.CacheReverseDestinations, p) + if Cache.HasItem(utils.CacheReverseDestinations, p) { + x, ok := Cache.Get(utils.CacheReverseDestinations, p) if !ok || x == nil { return utils.ErrNotFound } @@ -659,7 +636,7 @@ func (iDB *InternalDB) SetReverseDestinationDrv(dest *Destination, transactionID } mpRevDst[dest.Id] = true // for ReverseDestination we will use Groups - iDB.db.Set(utils.CacheReverseDestinations, p, mpRevDst, nil, + Cache.SetWithoutReplicate(utils.CacheReverseDestinations, p, mpRevDst, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -667,35 +644,17 @@ func (iDB *InternalDB) SetReverseDestinationDrv(dest *Destination, transactionID func (iDB *InternalDB) GetReverseDestinationDrv(prefix string, skipCache bool, transactionID string) (ids []string, err error) { - if !skipCache { - if x, ok := Cache.Get(utils.CacheReverseDestinations, prefix); ok { - if x != nil { - return x.([]string), nil - } - return nil, utils.ErrNotFound + if x, ok := Cache.Get(utils.CacheReverseDestinations, prefix); ok && x != nil { + ids := x.(utils.StringMap).Slice() + if len(ids) != 0 { + return ids, nil } } - x, ok := iDB.db.Get(utils.CacheReverseDestinations, prefix) - if !ok || x == nil { - return nil, utils.ErrNotFound - } - ids = x.(utils.StringMap).Slice() - if len(ids) == 0 { - if errCh := Cache.Set(utils.CacheReverseDestinations, prefix, nil, nil, - cacheCommit(transactionID), transactionID); errCh != nil { - return nil, errCh - } - return nil, utils.ErrNotFound - } - if errCh := Cache.Set(utils.CacheReverseDestinations, prefix, ids, nil, - cacheCommit(transactionID), transactionID); errCh != nil { - return nil, errCh - } - return + return nil, utils.ErrNotFound } func (iDB *InternalDB) UpdateReverseDestinationDrv(oldDest, newDest *Destination, - transactionID string) error { + transactionID string) (err error) { var obsoletePrefixes []string var mpRevDst utils.StringMap var addedPrefixes []string @@ -729,10 +688,9 @@ func (iDB *InternalDB) UpdateReverseDestinationDrv(oldDest, newDest *Destination } // remove id for all obsolete prefixes cCommit := cacheCommit(transactionID) - var err error for _, obsoletePrefix := range obsoletePrefixes { - if iDB.db.HasItem(utils.CacheReverseDestinations, obsoletePrefix) { - x, ok := iDB.db.Get(utils.CacheReverseDestinations, obsoletePrefix) + if Cache.HasItem(utils.CacheReverseDestinations, obsoletePrefix) { + x, ok := Cache.Get(utils.CacheReverseDestinations, obsoletePrefix) if !ok || x == nil { return utils.ErrNotFound } @@ -741,19 +699,17 @@ func (iDB *InternalDB) UpdateReverseDestinationDrv(oldDest, newDest *Destination delete(mpRevDst, oldDest.Id) } // for ReverseDestination we will use Groups - iDB.db.Set(utils.CacheReverseDestinations, obsoletePrefix, mpRevDst, nil, + Cache.SetWithoutReplicate(utils.CacheReverseDestinations, obsoletePrefix, mpRevDst, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } - if errCh := Cache.Remove(utils.CacheReverseDestinations, obsoletePrefix, - cCommit, transactionID); errCh != nil { - return errCh - } + Cache.RemoveWithoutReplicate(utils.CacheReverseDestinations, obsoletePrefix, + cCommit, transactionID) } // add the id to all new prefixes for _, addedPrefix := range addedPrefixes { - if iDB.db.HasItem(utils.CacheReverseDestinations, addedPrefix) { - x, ok := iDB.db.Get(utils.CacheReverseDestinations, addedPrefix) + if Cache.HasItem(utils.CacheReverseDestinations, addedPrefix) { + x, ok := Cache.Get(utils.CacheReverseDestinations, addedPrefix) if !ok || x == nil { return utils.ErrNotFound } @@ -763,109 +719,83 @@ func (iDB *InternalDB) UpdateReverseDestinationDrv(oldDest, newDest *Destination } mpRevDst[newDest.Id] = true // for ReverseDestination we will use Groups - iDB.db.Set(utils.CacheReverseDestinations, addedPrefix, mpRevDst, nil, + Cache.SetWithoutReplicate(utils.CacheReverseDestinations, addedPrefix, mpRevDst, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } - return err + return } func (iDB *InternalDB) GetActionsDrv(id string) (acts Actions, err error) { - x, ok := iDB.db.Get(utils.CacheActions, id) - if !ok || x == nil { - return nil, utils.ErrNotFound + if x, ok := Cache.Get(utils.CacheActions, id); ok && x != nil { + return x.(Actions), err } - return x.(Actions), err + return nil, utils.ErrNotFound } func (iDB *InternalDB) SetActionsDrv(id string, acts Actions) (err error) { - iDB.db.Set(utils.CacheActions, id, acts, nil, + Cache.SetWithoutReplicate(utils.CacheActions, id, acts, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveActionsDrv(id string) (err error) { - iDB.db.Remove(utils.CacheActions, id, + Cache.RemoveWithoutReplicate(utils.CacheActions, id, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetSharedGroupDrv(id string) (sh *SharedGroup, err error) { - x, ok := iDB.db.Get(utils.CacheSharedGroups, id) - if !ok || x == nil { - return nil, utils.ErrNotFound + if x, ok := Cache.Get(utils.CacheSharedGroups, id); ok && x != nil { + return x.(*SharedGroup).Clone(), err } - return x.(*SharedGroup).Clone(), nil + return nil, utils.ErrNotFound } func (iDB *InternalDB) SetSharedGroupDrv(sh *SharedGroup) (err error) { - iDB.db.Set(utils.CacheSharedGroups, sh.Id, sh, nil, + Cache.SetWithoutReplicate(utils.CacheSharedGroups, sh.Id, sh, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveSharedGroupDrv(id string) (err error) { - iDB.db.Remove(utils.CacheSharedGroups, id, + Cache.RemoveWithoutReplicate(utils.CacheSharedGroups, id, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetActionTriggersDrv(id string) (at ActionTriggers, err error) { - x, ok := iDB.db.Get(utils.CacheActionTriggers, id) - if !ok || x == nil { - return nil, utils.ErrNotFound + if x, ok := Cache.Get(utils.CacheActionTriggers, id); ok && x != nil { + return x.(ActionTriggers).Clone(), err } - return x.(ActionTriggers).Clone(), nil + return nil, utils.ErrNotFound } func (iDB *InternalDB) SetActionTriggersDrv(id string, at ActionTriggers) (err error) { - iDB.db.Set(utils.CacheActionTriggers, id, at, nil, + Cache.SetWithoutReplicate(utils.CacheActionTriggers, id, at, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveActionTriggersDrv(id string) (err error) { - iDB.db.Remove(utils.CacheActionTriggers, id, + Cache.RemoveWithoutReplicate(utils.CacheActionTriggers, id, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetActionPlanDrv(key string, skipCache bool, transactionID string) (ats *ActionPlan, err error) { - if !skipCache { - if x, ok := Cache.Get(utils.CacheActionPlans, key); ok { - if x != nil { - return x.(*ActionPlan), nil - } - return nil, utils.ErrNotFound - } + if x, ok := Cache.Get(utils.CacheActionPlans, key); ok && x != nil { + return x.(*ActionPlan), nil } - cCommit := cacheCommit(transactionID) - x, ok := iDB.db.Get(utils.CacheActionPlans, key) - if !ok || x == nil { - if errCh := Cache.Set(utils.CacheActionPlans, key, nil, nil, - cCommit, transactionID); errCh != nil { - return nil, errCh - } - return nil, utils.ErrNotFound - } - ats = x.(*ActionPlan) - if errCh := Cache.Set(utils.CacheActionPlans, key, ats, nil, - cCommit, transactionID); errCh != nil { - return nil, errCh - } - return + return nil, utils.ErrNotFound } func (iDB *InternalDB) SetActionPlanDrv(key string, ats *ActionPlan, overwrite bool, transactionID string) (err error) { cCommit := cacheCommit(transactionID) if len(ats.ActionTimings) == 0 { - iDB.db.Remove(utils.CacheActionPlans, key, - cacheCommit(utils.NonTransactional), utils.NonTransactional) - if errCh := Cache.Remove(utils.CacheActionPlans, key, - cCommit, transactionID); errCh != nil { - return errCh - } + Cache.RemoveWithoutReplicate(utils.CacheActionPlans, key, + cCommit, transactionID) return } if !overwrite { @@ -880,31 +810,28 @@ func (iDB *InternalDB) SetActionPlanDrv(key string, ats *ActionPlan, } } } - iDB.db.Set(utils.CacheActionPlans, key, ats, nil, + Cache.SetWithoutReplicate(utils.CacheActionPlans, key, ats, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveActionPlanDrv(key string, transactionID string) (err error) { - iDB.db.Remove(utils.CacheActionPlans, key, - cacheCommit(utils.NonTransactional), utils.NonTransactional) - if errCh := Cache.Remove(utils.CacheActionPlans, key, cacheCommit(transactionID), transactionID); errCh != nil { - return errCh - } + Cache.RemoveWithoutReplicate(utils.CacheActionPlans, key, cacheCommit(transactionID), transactionID) return } func (iDB *InternalDB) GetAllActionPlansDrv() (ats map[string]*ActionPlan, err error) { - keys, err := iDB.GetKeysForPrefix(utils.ACTION_PLAN_PREFIX) - if err != nil { - return nil, err + var keys []string + if keys, err = iDB.GetKeysForPrefix(utils.ACTION_PLAN_PREFIX); err != nil { + return } ats = make(map[string]*ActionPlan, len(keys)) for _, key := range keys { - ap, err := iDB.GetActionPlanDrv(key[len(utils.ACTION_PLAN_PREFIX):], false, utils.NonTransactional) - if err != nil { - return nil, err + var ap *ActionPlan + if ap, err = iDB.GetActionPlanDrv(key[len(utils.ACTION_PLAN_PREFIX):], false, utils.NonTransactional); err != nil { + ats = nil + return } ats[key[len(utils.ACTION_PLAN_PREFIX):]] = ap } @@ -913,56 +840,41 @@ func (iDB *InternalDB) GetAllActionPlansDrv() (ats map[string]*ActionPlan, err e func (iDB *InternalDB) GetAccountActionPlansDrv(acntID string, skipCache bool, transactionID string) (apIDs []string, err error) { - if !skipCache { - if x, ok := Cache.Get(utils.CacheAccountActionPlans, acntID); ok { - if x == nil { - return nil, utils.ErrNotFound - } - return x.([]string), nil - } + if x, ok := Cache.Get(utils.CacheAccountActionPlans, acntID); ok && x != nil { + return x.([]string), nil } - x, ok := iDB.db.Get(utils.CacheAccountActionPlans, acntID) - if !ok || x == nil { - if errCh := Cache.Set(utils.CacheAccountActionPlans, acntID, nil, nil, - cacheCommit(transactionID), transactionID); errCh != nil { - return nil, errCh - } - return nil, utils.ErrNotFound - } - apIDs = x.([]string) - if errCh := Cache.Set(utils.CacheAccountActionPlans, acntID, apIDs, nil, - cacheCommit(transactionID), transactionID); errCh != nil { - return nil, errCh - } - return + return nil, utils.ErrNotFound } func (iDB *InternalDB) SetAccountActionPlansDrv(acntID string, apIDs []string, overwrite bool) (err error) { if !overwrite { - if oldaPlIDs, err := iDB.GetAccountActionPlansDrv(acntID, true, utils.NonTransactional); err != nil && err != utils.ErrNotFound { - return err - } else { - for _, oldAPid := range oldaPlIDs { - if !utils.IsSliceMember(apIDs, oldAPid) { - apIDs = append(apIDs, oldAPid) - } + var oldaPlIDs []string + if oldaPlIDs, err = iDB.GetAccountActionPlansDrv(acntID, + true, utils.NonTransactional); err != nil && err != utils.ErrNotFound { + return + } + err = nil + for _, oldAPid := range oldaPlIDs { + if !utils.IsSliceMember(apIDs, oldAPid) { + apIDs = append(apIDs, oldAPid) } } } - iDB.db.Set(utils.CacheAccountActionPlans, acntID, apIDs, nil, + Cache.SetWithoutReplicate(utils.CacheAccountActionPlans, acntID, apIDs, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemAccountActionPlansDrv(acntID string, apIDs []string) (err error) { if len(apIDs) == 0 { - iDB.db.Remove(utils.CacheAccountActionPlans, acntID, + Cache.RemoveWithoutReplicate(utils.CacheAccountActionPlans, acntID, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } - oldaPlIDs, err := iDB.GetAccountActionPlansDrv(acntID, true, utils.NonTransactional) - if err != nil { - return err + var oldaPlIDs []string + if oldaPlIDs, err = iDB.GetAccountActionPlansDrv(acntID, + true, utils.NonTransactional); err != nil { + return } for i := 0; i < len(oldaPlIDs); { if utils.IsSliceMember(apIDs, oldaPlIDs[i]) { @@ -972,11 +884,11 @@ func (iDB *InternalDB) RemAccountActionPlansDrv(acntID string, apIDs []string) ( i++ } if len(oldaPlIDs) == 0 { - iDB.db.Remove(utils.CacheAccountActionPlans, acntID, + Cache.RemoveWithoutReplicate(utils.CacheAccountActionPlans, acntID, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } - iDB.db.Set(utils.CacheAccountActionPlans, acntID, oldaPlIDs, nil, + Cache.SetWithoutReplicate(utils.CacheAccountActionPlans, acntID, oldaPlIDs, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } @@ -1002,11 +914,10 @@ func (iDB *InternalDB) PopTask() (t *Task, err error) { } func (iDB *InternalDB) GetAccountDrv(id string) (acc *Account, err error) { - x, ok := iDB.db.Get(utils.CacheAccounts, id) - if !ok || x == nil { - return nil, utils.ErrNotFound + if x, ok := Cache.Get(utils.CacheAccounts, id); ok && x != nil { + return x.(*Account).Clone(), nil } - return x.(*Account).Clone(), nil + return nil, utils.ErrNotFound } func (iDB *InternalDB) SetAccountDrv(acc *Account) (err error) { @@ -1023,59 +934,57 @@ func (iDB *InternalDB) SetAccountDrv(acc *Account) (err error) { } } acc.UpdateTime = time.Now() - iDB.db.Set(utils.CacheAccounts, acc.ID, acc, nil, + Cache.SetWithoutReplicate(utils.CacheAccounts, acc.ID, acc, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveAccountDrv(id string) (err error) { - iDB.db.Remove(utils.CacheAccounts, id, + Cache.RemoveWithoutReplicate(utils.CacheAccounts, id, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetResourceProfileDrv(tenant, id string) (rp *ResourceProfile, err error) { - x, ok := iDB.db.Get(utils.CacheResourceProfiles, utils.ConcatenatedKey(tenant, id)) - if !ok || x == nil { - return nil, utils.ErrNotFound + if x, ok := Cache.Get(utils.CacheResourceProfiles, utils.ConcatenatedKey(tenant, id)); ok && x != nil { + return x.(*ResourceProfile), nil } - return x.(*ResourceProfile), nil + return nil, utils.ErrNotFound } func (iDB *InternalDB) SetResourceProfileDrv(rp *ResourceProfile) (err error) { - iDB.db.Set(utils.CacheResourceProfiles, rp.TenantID(), rp, nil, + Cache.SetWithoutReplicate(utils.CacheResourceProfiles, rp.TenantID(), rp, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveResourceProfileDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheResourceProfiles, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheResourceProfiles, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetResourceDrv(tenant, id string) (r *Resource, err error) { - x, ok := iDB.db.Get(utils.CacheResources, utils.ConcatenatedKey(tenant, id)) - if !ok || x == nil { - return nil, utils.ErrNotFound + if x, ok := Cache.Get(utils.CacheResources, utils.ConcatenatedKey(tenant, id)); ok && x != nil { + return x.(*Resource), nil } - return x.(*Resource), nil + return nil, utils.ErrNotFound } func (iDB *InternalDB) SetResourceDrv(r *Resource) (err error) { - iDB.db.Set(utils.CacheResources, r.TenantID(), r, nil, + Cache.SetWithoutReplicate(utils.CacheResources, r.TenantID(), r, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveResourceDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheResources, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheResources, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetTimingDrv(id string) (tmg *utils.TPTiming, err error) { - x, ok := iDB.db.Get(utils.CacheTimings, id) + x, ok := Cache.Get(utils.CacheTimings, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1083,13 +992,13 @@ func (iDB *InternalDB) GetTimingDrv(id string) (tmg *utils.TPTiming, err error) } func (iDB *InternalDB) SetTimingDrv(timing *utils.TPTiming) (err error) { - iDB.db.Set(utils.CacheTimings, timing.ID, timing, nil, + Cache.SetWithoutReplicate(utils.CacheTimings, timing.ID, timing, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveTimingDrv(id string) (err error) { - iDB.db.Remove(utils.CacheTimings, id, + Cache.RemoveWithoutReplicate(utils.CacheTimings, id, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } @@ -1103,7 +1012,7 @@ func (iDB *InternalDB) AddLoadHistory(*utils.LoadInstance, int, string) error { } func (iDB *InternalDB) GetStatQueueProfileDrv(tenant string, id string) (sq *StatQueueProfile, err error) { - x, ok := iDB.db.Get(utils.CacheStatQueueProfiles, utils.ConcatenatedKey(tenant, id)) + x, ok := Cache.Get(utils.CacheStatQueueProfiles, utils.ConcatenatedKey(tenant, id)) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1111,19 +1020,19 @@ func (iDB *InternalDB) GetStatQueueProfileDrv(tenant string, id string) (sq *Sta } func (iDB *InternalDB) SetStatQueueProfileDrv(sq *StatQueueProfile) (err error) { - iDB.db.Set(utils.CacheStatQueueProfiles, sq.TenantID(), sq, nil, + Cache.SetWithoutReplicate(utils.CacheStatQueueProfiles, sq.TenantID(), sq, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemStatQueueProfileDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheStatQueueProfiles, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheStatQueueProfiles, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetStatQueueDrv(tenant, id string) (sq *StatQueue, err error) { - x, ok := iDB.db.Get(utils.CacheStatQueues, utils.ConcatenatedKey(tenant, id)) + x, ok := Cache.Get(utils.CacheStatQueues, utils.ConcatenatedKey(tenant, id)) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1136,18 +1045,18 @@ func (iDB *InternalDB) SetStatQueueDrv(ssq *StoredStatQueue, sq *StatQueue) (err return } } - iDB.db.Set(utils.CacheStatQueues, utils.ConcatenatedKey(sq.Tenant, sq.ID), sq, nil, + Cache.SetWithoutReplicate(utils.CacheStatQueues, utils.ConcatenatedKey(sq.Tenant, sq.ID), sq, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemStatQueueDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheStatQueues, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheStatQueues, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetThresholdProfileDrv(tenant, id string) (tp *ThresholdProfile, err error) { - x, ok := iDB.db.Get(utils.CacheThresholdProfiles, utils.ConcatenatedKey(tenant, id)) + x, ok := Cache.Get(utils.CacheThresholdProfiles, utils.ConcatenatedKey(tenant, id)) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1155,19 +1064,19 @@ func (iDB *InternalDB) GetThresholdProfileDrv(tenant, id string) (tp *ThresholdP } func (iDB *InternalDB) SetThresholdProfileDrv(tp *ThresholdProfile) (err error) { - iDB.db.Set(utils.CacheThresholdProfiles, tp.TenantID(), tp, nil, + Cache.SetWithoutReplicate(utils.CacheThresholdProfiles, tp.TenantID(), tp, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemThresholdProfileDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheThresholdProfiles, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheThresholdProfiles, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetThresholdDrv(tenant, id string) (th *Threshold, err error) { - x, ok := iDB.db.Get(utils.CacheThresholds, utils.ConcatenatedKey(tenant, id)) + x, ok := Cache.Get(utils.CacheThresholds, utils.ConcatenatedKey(tenant, id)) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1175,19 +1084,19 @@ func (iDB *InternalDB) GetThresholdDrv(tenant, id string) (th *Threshold, err er } func (iDB *InternalDB) SetThresholdDrv(th *Threshold) (err error) { - iDB.db.Set(utils.CacheThresholds, th.TenantID(), th, nil, + Cache.SetWithoutReplicate(utils.CacheThresholds, th.TenantID(), th, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveThresholdDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheThresholds, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheThresholds, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetFilterDrv(tenant, id string) (fltr *Filter, err error) { - x, ok := iDB.db.Get(utils.CacheFilters, utils.ConcatenatedKey(tenant, id)) + x, ok := Cache.Get(utils.CacheFilters, utils.ConcatenatedKey(tenant, id)) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1196,19 +1105,19 @@ func (iDB *InternalDB) GetFilterDrv(tenant, id string) (fltr *Filter, err error) } func (iDB *InternalDB) SetFilterDrv(fltr *Filter) (err error) { - iDB.db.Set(utils.CacheFilters, fltr.TenantID(), fltr, nil, + Cache.SetWithoutReplicate(utils.CacheFilters, fltr.TenantID(), fltr, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveFilterDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheFilters, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheFilters, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetRouteProfileDrv(tenant, id string) (spp *RouteProfile, err error) { - x, ok := iDB.db.Get(utils.CacheRouteProfiles, utils.ConcatenatedKey(tenant, id)) + x, ok := Cache.Get(utils.CacheRouteProfiles, utils.ConcatenatedKey(tenant, id)) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1216,19 +1125,19 @@ func (iDB *InternalDB) GetRouteProfileDrv(tenant, id string) (spp *RouteProfile, } func (iDB *InternalDB) SetRouteProfileDrv(spp *RouteProfile) (err error) { - iDB.db.Set(utils.CacheRouteProfiles, spp.TenantID(), spp, nil, + Cache.SetWithoutReplicate(utils.CacheRouteProfiles, spp.TenantID(), spp, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveRouteProfileDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheRouteProfiles, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheRouteProfiles, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetAttributeProfileDrv(tenant, id string) (attr *AttributeProfile, err error) { - x, ok := iDB.db.Get(utils.CacheAttributeProfiles, utils.ConcatenatedKey(tenant, id)) + x, ok := Cache.Get(utils.CacheAttributeProfiles, utils.ConcatenatedKey(tenant, id)) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1236,19 +1145,19 @@ func (iDB *InternalDB) GetAttributeProfileDrv(tenant, id string) (attr *Attribut } func (iDB *InternalDB) SetAttributeProfileDrv(attr *AttributeProfile) (err error) { - iDB.db.Set(utils.CacheAttributeProfiles, attr.TenantID(), attr, nil, + Cache.SetWithoutReplicate(utils.CacheAttributeProfiles, attr.TenantID(), attr, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveAttributeProfileDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheAttributeProfiles, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheAttributeProfiles, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetChargerProfileDrv(tenant, id string) (ch *ChargerProfile, err error) { - x, ok := iDB.db.Get(utils.CacheChargerProfiles, utils.ConcatenatedKey(tenant, id)) + x, ok := Cache.Get(utils.CacheChargerProfiles, utils.ConcatenatedKey(tenant, id)) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1256,19 +1165,19 @@ func (iDB *InternalDB) GetChargerProfileDrv(tenant, id string) (ch *ChargerProfi } func (iDB *InternalDB) SetChargerProfileDrv(chr *ChargerProfile) (err error) { - iDB.db.Set(utils.CacheChargerProfiles, chr.TenantID(), chr, nil, + Cache.SetWithoutReplicate(utils.CacheChargerProfiles, chr.TenantID(), chr, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveChargerProfileDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheChargerProfiles, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheChargerProfiles, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetDispatcherProfileDrv(tenant, id string) (dpp *DispatcherProfile, err error) { - x, ok := iDB.db.Get(utils.CacheDispatcherProfiles, utils.ConcatenatedKey(tenant, id)) + x, ok := Cache.Get(utils.CacheDispatcherProfiles, utils.ConcatenatedKey(tenant, id)) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1276,19 +1185,19 @@ func (iDB *InternalDB) GetDispatcherProfileDrv(tenant, id string) (dpp *Dispatch } func (iDB *InternalDB) SetDispatcherProfileDrv(dpp *DispatcherProfile) (err error) { - iDB.db.Set(utils.CacheDispatcherProfiles, dpp.TenantID(), dpp, nil, + Cache.SetWithoutReplicate(utils.CacheDispatcherProfiles, dpp.TenantID(), dpp, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveDispatcherProfileDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheDispatcherProfiles, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheDispatcherProfiles, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]int64, err error) { - x, ok := iDB.db.Get(utils.CacheLoadIDs, utils.LoadIDs) + x, ok := Cache.Get(utils.CacheLoadIDs, utils.LoadIDs) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1300,13 +1209,13 @@ func (iDB *InternalDB) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[strin } func (iDB *InternalDB) SetLoadIDsDrv(loadIDs map[string]int64) (err error) { - iDB.db.Set(utils.CacheLoadIDs, utils.LoadIDs, loadIDs, nil, + Cache.SetWithoutReplicate(utils.CacheLoadIDs, utils.LoadIDs, loadIDs, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) GetDispatcherHostDrv(tenant, id string) (dpp *DispatcherHost, err error) { - x, ok := iDB.db.Get(utils.CacheDispatcherHosts, utils.ConcatenatedKey(tenant, id)) + x, ok := Cache.Get(utils.CacheDispatcherHosts, utils.ConcatenatedKey(tenant, id)) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1314,13 +1223,13 @@ func (iDB *InternalDB) GetDispatcherHostDrv(tenant, id string) (dpp *DispatcherH } func (iDB *InternalDB) SetDispatcherHostDrv(dpp *DispatcherHost) (err error) { - iDB.db.Set(utils.CacheDispatcherHosts, dpp.TenantID(), dpp, nil, + Cache.SetWithoutReplicate(utils.CacheDispatcherHosts, dpp.TenantID(), dpp, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveDispatcherHostDrv(tenant, id string) (err error) { - iDB.db.Remove(utils.CacheDispatcherHosts, utils.ConcatenatedKey(tenant, id), + Cache.RemoveWithoutReplicate(utils.CacheDispatcherHosts, utils.ConcatenatedKey(tenant, id), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } diff --git a/engine/storage_internal_stordb.go b/engine/storage_internal_stordb.go index c5ced0c9e..60a5a113f 100644 --- a/engine/storage_internal_stordb.go +++ b/engine/storage_internal_stordb.go @@ -32,14 +32,14 @@ func (iDB *InternalDB) GetTpIds(colName string) (ids []string, err error) { tpIDs := utils.NewStringSet(nil) if colName == "" { // if colName is empty we need to parse all partitions for _, conNm := range utils.CacheStorDBPartitions.AsSlice() { - keys := iDB.db.GetItemIDs(conNm, utils.EmptyString) + keys := Cache.GetItemIDs(conNm, utils.EmptyString) for _, key := range keys { tpIDs.Add(strings.Split(key, utils.InInFieldSep)[0]) } } // iterate through all columns } else { - keys := iDB.db.GetItemIDs(colName, utils.EmptyString) + keys := Cache.GetItemIDs(colName, utils.EmptyString) for _, key := range keys { tpIDs.Add(strings.Split(key, utils.InInFieldSep)[0]) } @@ -49,7 +49,7 @@ func (iDB *InternalDB) GetTpIds(colName string) (ids []string, err error) { func (iDB *InternalDB) GetTpTableIds(tpid, table string, distinct utils.TPDistinctIds, filters map[string]string, paginator *utils.PaginatorWithSearch) (ids []string, err error) { - fullIDs := iDB.db.GetItemIDs(table, tpid) + fullIDs := Cache.GetItemIDs(table, tpid) idSet := utils.NewStringSet(nil) for _, fullID := range fullIDs { switch table { @@ -76,9 +76,9 @@ func (iDB *InternalDB) GetTPTimings(tpid, id string) (timings []*utils.ApierTPTi key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPTimings, key) + ids := Cache.GetItemIDs(utils.TBLTPTimings, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPTimings, id) + x, ok := Cache.Get(utils.TBLTPTimings, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -95,9 +95,9 @@ func (iDB *InternalDB) GetTPDestinations(tpid, id string) (dsts []*utils.TPDesti if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPDestinations, key) + ids := Cache.GetItemIDs(utils.TBLTPDestinations, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPDestinations, id) + x, ok := Cache.Get(utils.TBLTPDestinations, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -115,9 +115,9 @@ func (iDB *InternalDB) GetTPRates(tpid, id string) (rates []*utils.TPRateRALs, e if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPRates, key) + ids := Cache.GetItemIDs(utils.TBLTPRates, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPRates, id) + x, ok := Cache.Get(utils.TBLTPRates, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -140,9 +140,9 @@ func (iDB *InternalDB) GetTPDestinationRates(tpid, id string, if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPDestinationRates, key) + ids := Cache.GetItemIDs(utils.TBLTPDestinationRates, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPDestinationRates, id) + x, ok := Cache.Get(utils.TBLTPDestinationRates, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -185,9 +185,9 @@ func (iDB *InternalDB) GetTPRatingPlans(tpid, id string, paginator *utils.Pagina if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPRatingPlans, key) + ids := Cache.GetItemIDs(utils.TBLTPRatingPlans, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPRatingPlans, id) + x, ok := Cache.Get(utils.TBLTPRatingPlans, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -239,9 +239,9 @@ func (iDB *InternalDB) GetTPRatingProfiles(filter *utils.TPRatingProfile) (rProf if filter.Subject != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + filter.Subject } - ids := iDB.db.GetItemIDs(utils.TBLTPRatingProfiles, key) + ids := Cache.GetItemIDs(utils.TBLTPRatingProfiles, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPRatingProfiles, id) + x, ok := Cache.Get(utils.TBLTPRatingProfiles, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -259,9 +259,9 @@ func (iDB *InternalDB) GetTPSharedGroups(tpid, id string) (sGroups []*utils.TPSh if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPSharedGroups, key) + ids := Cache.GetItemIDs(utils.TBLTPSharedGroups, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPSharedGroups, id) + x, ok := Cache.Get(utils.TBLTPSharedGroups, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -279,9 +279,9 @@ func (iDB *InternalDB) GetTPActions(tpid, id string) (actions []*utils.TPActions if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPActions, key) + ids := Cache.GetItemIDs(utils.TBLTPActions, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPActions, id) + x, ok := Cache.Get(utils.TBLTPActions, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -299,9 +299,9 @@ func (iDB *InternalDB) GetTPActionPlans(tpid, id string) (aPlans []*utils.TPActi if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPActionPlans, key) + ids := Cache.GetItemIDs(utils.TBLTPActionPlans, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPActionPlans, id) + x, ok := Cache.Get(utils.TBLTPActionPlans, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -319,9 +319,9 @@ func (iDB *InternalDB) GetTPActionTriggers(tpid, id string) (aTriggers []*utils. if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPActionTriggers, key) + ids := Cache.GetItemIDs(utils.TBLTPActionTriggers, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPActionTriggers, id) + x, ok := Cache.Get(utils.TBLTPActionTriggers, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -344,9 +344,9 @@ func (iDB *InternalDB) GetTPAccountActions(filter *utils.TPAccountActions) (acco if filter.Account != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + filter.Account } - ids := iDB.db.GetItemIDs(utils.TBLTPAccountActions, key) + ids := Cache.GetItemIDs(utils.TBLTPAccountActions, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPAccountActions, id) + x, ok := Cache.Get(utils.TBLTPAccountActions, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -367,9 +367,9 @@ func (iDB *InternalDB) GetTPResources(tpid, tenant, id string) (resources []*uti if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPResources, key) + ids := Cache.GetItemIDs(utils.TBLTPResources, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPResources, id) + x, ok := Cache.Get(utils.TBLTPResources, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -390,9 +390,9 @@ func (iDB *InternalDB) GetTPStats(tpid, tenant, id string) (stats []*utils.TPSta if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPStats, key) + ids := Cache.GetItemIDs(utils.TBLTPStats, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPStats, id) + x, ok := Cache.Get(utils.TBLTPStats, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -413,9 +413,9 @@ func (iDB *InternalDB) GetTPThresholds(tpid, tenant, id string) (ths []*utils.TP if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPThresholds, key) + ids := Cache.GetItemIDs(utils.TBLTPThresholds, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPThresholds, id) + x, ok := Cache.Get(utils.TBLTPThresholds, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -436,9 +436,9 @@ func (iDB *InternalDB) GetTPFilters(tpid, tenant, id string) (fltrs []*utils.TPF if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPFilters, key) + ids := Cache.GetItemIDs(utils.TBLTPFilters, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPFilters, id) + x, ok := Cache.Get(utils.TBLTPFilters, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -459,9 +459,9 @@ func (iDB *InternalDB) GetTPRoutes(tpid, tenant, id string) (supps []*utils.TPRo if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPRoutes, key) + ids := Cache.GetItemIDs(utils.TBLTPRoutes, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPRoutes, id) + x, ok := Cache.Get(utils.TBLTPRoutes, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -482,9 +482,9 @@ func (iDB *InternalDB) GetTPAttributes(tpid, tenant, id string) (attrs []*utils. if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPAttributes, key) + ids := Cache.GetItemIDs(utils.TBLTPAttributes, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPAttributes, id) + x, ok := Cache.Get(utils.TBLTPAttributes, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -505,9 +505,9 @@ func (iDB *InternalDB) GetTPChargers(tpid, tenant, id string) (cpps []*utils.TPC if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPChargers, key) + ids := Cache.GetItemIDs(utils.TBLTPChargers, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPChargers, id) + x, ok := Cache.Get(utils.TBLTPChargers, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -528,9 +528,9 @@ func (iDB *InternalDB) GetTPDispatcherProfiles(tpid, tenant, id string) (dpps [] if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPDispatchers, key) + ids := Cache.GetItemIDs(utils.TBLTPDispatchers, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPDispatchers, id) + x, ok := Cache.Get(utils.TBLTPDispatchers, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -551,9 +551,9 @@ func (iDB *InternalDB) GetTPDispatcherHosts(tpid, tenant, id string) (dpps []*ut if id != utils.EmptyString { key += utils.CONCATENATED_KEY_SEP + id } - ids := iDB.db.GetItemIDs(utils.TBLTPDispatcherHosts, key) + ids := Cache.GetItemIDs(utils.TBLTPDispatcherHosts, key) for _, id := range ids { - x, ok := iDB.db.Get(utils.TBLTPDispatcherHosts, id) + x, ok := Cache.Get(utils.TBLTPDispatcherHosts, id) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -599,9 +599,9 @@ func (iDB *InternalDB) RemTpData(table, tpid string, args map[string]string) (er key += utils.CONCATENATED_KEY_SEP + val } } - ids := iDB.db.GetItemIDs(table, key) + ids := Cache.GetItemIDs(table, key) for _, id := range ids { - iDB.db.Remove(table, id, + Cache.Remove(table, id, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -612,7 +612,7 @@ func (iDB *InternalDB) SetTPTimings(timings []*utils.ApierTPTiming) (err error) return nil } for _, timing := range timings { - iDB.db.Set(utils.TBLTPTimings, utils.ConcatenatedKey(timing.TPid, timing.ID), timing, nil, + Cache.Set(utils.TBLTPTimings, utils.ConcatenatedKey(timing.TPid, timing.ID), timing, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -622,7 +622,7 @@ func (iDB *InternalDB) SetTPDestinations(dests []*utils.TPDestination) (err erro return nil } for _, destination := range dests { - iDB.db.Set(utils.TBLTPDestinations, utils.ConcatenatedKey(destination.TPid, destination.ID), destination, nil, + Cache.Set(utils.TBLTPDestinations, utils.ConcatenatedKey(destination.TPid, destination.ID), destination, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -633,7 +633,7 @@ func (iDB *InternalDB) SetTPRates(rates []*utils.TPRateRALs) (err error) { return nil } for _, rate := range rates { - iDB.db.Set(utils.TBLTPRates, utils.ConcatenatedKey(rate.TPid, rate.ID), rate, nil, + Cache.Set(utils.TBLTPRates, utils.ConcatenatedKey(rate.TPid, rate.ID), rate, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -644,7 +644,7 @@ func (iDB *InternalDB) SetTPDestinationRates(dRates []*utils.TPDestinationRate) return nil } for _, dRate := range dRates { - iDB.db.Set(utils.TBLTPDestinationRates, utils.ConcatenatedKey(dRate.TPid, dRate.ID), dRate, nil, + Cache.Set(utils.TBLTPDestinationRates, utils.ConcatenatedKey(dRate.TPid, dRate.ID), dRate, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -655,7 +655,7 @@ func (iDB *InternalDB) SetTPRatingPlans(ratingPlans []*utils.TPRatingPlan) (err return nil } for _, rPlan := range ratingPlans { - iDB.db.Set(utils.TBLTPRatingPlans, utils.ConcatenatedKey(rPlan.TPid, rPlan.ID), rPlan, nil, + Cache.Set(utils.TBLTPRatingPlans, utils.ConcatenatedKey(rPlan.TPid, rPlan.ID), rPlan, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -666,7 +666,7 @@ func (iDB *InternalDB) SetTPRatingProfiles(ratingProfiles []*utils.TPRatingProfi return nil } for _, rProfile := range ratingProfiles { - iDB.db.Set(utils.TBLTPRatingProfiles, utils.ConcatenatedKey(rProfile.TPid, + Cache.Set(utils.TBLTPRatingProfiles, utils.ConcatenatedKey(rProfile.TPid, rProfile.LoadId, rProfile.Tenant, rProfile.Category, rProfile.Subject), rProfile, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } @@ -678,7 +678,7 @@ func (iDB *InternalDB) SetTPSharedGroups(groups []*utils.TPSharedGroups) (err er return nil } for _, group := range groups { - iDB.db.Set(utils.TBLTPSharedGroups, utils.ConcatenatedKey(group.TPid, group.ID), group, nil, + Cache.Set(utils.TBLTPSharedGroups, utils.ConcatenatedKey(group.TPid, group.ID), group, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -689,7 +689,7 @@ func (iDB *InternalDB) SetTPActions(acts []*utils.TPActions) (err error) { return nil } for _, action := range acts { - iDB.db.Set(utils.TBLTPActions, utils.ConcatenatedKey(action.TPid, action.ID), action, nil, + Cache.Set(utils.TBLTPActions, utils.ConcatenatedKey(action.TPid, action.ID), action, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -700,7 +700,7 @@ func (iDB *InternalDB) SetTPActionPlans(aPlans []*utils.TPActionPlan) (err error return nil } for _, aPlan := range aPlans { - iDB.db.Set(utils.TBLTPActionPlans, utils.ConcatenatedKey(aPlan.TPid, aPlan.ID), aPlan, nil, + Cache.Set(utils.TBLTPActionPlans, utils.ConcatenatedKey(aPlan.TPid, aPlan.ID), aPlan, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -711,7 +711,7 @@ func (iDB *InternalDB) SetTPActionTriggers(aTriggers []*utils.TPActionTriggers) return nil } for _, aTrigger := range aTriggers { - iDB.db.Set(utils.TBLTPActionTriggers, utils.ConcatenatedKey(aTrigger.TPid, aTrigger.ID), aTrigger, nil, + Cache.Set(utils.TBLTPActionTriggers, utils.ConcatenatedKey(aTrigger.TPid, aTrigger.ID), aTrigger, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -722,7 +722,7 @@ func (iDB *InternalDB) SetTPAccountActions(accActions []*utils.TPAccountActions) return nil } for _, accAction := range accActions { - iDB.db.Set(utils.TBLTPAccountActions, utils.ConcatenatedKey(accAction.TPid, + Cache.Set(utils.TBLTPAccountActions, utils.ConcatenatedKey(accAction.TPid, accAction.LoadId, accAction.Tenant, accAction.Account), accAction, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } @@ -734,7 +734,7 @@ func (iDB *InternalDB) SetTPResources(resources []*utils.TPResourceProfile) (err return nil } for _, resource := range resources { - iDB.db.Set(utils.TBLTPResources, utils.ConcatenatedKey(resource.TPid, resource.Tenant, resource.ID), resource, nil, + Cache.Set(utils.TBLTPResources, utils.ConcatenatedKey(resource.TPid, resource.Tenant, resource.ID), resource, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -744,7 +744,7 @@ func (iDB *InternalDB) SetTPStats(stats []*utils.TPStatProfile) (err error) { return nil } for _, stat := range stats { - iDB.db.Set(utils.TBLTPStats, utils.ConcatenatedKey(stat.TPid, stat.Tenant, stat.ID), stat, nil, + Cache.Set(utils.TBLTPStats, utils.ConcatenatedKey(stat.TPid, stat.Tenant, stat.ID), stat, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -755,7 +755,7 @@ func (iDB *InternalDB) SetTPThresholds(thresholds []*utils.TPThresholdProfile) ( } for _, threshold := range thresholds { - iDB.db.Set(utils.TBLTPThresholds, utils.ConcatenatedKey(threshold.TPid, threshold.Tenant, threshold.ID), threshold, nil, + Cache.Set(utils.TBLTPThresholds, utils.ConcatenatedKey(threshold.TPid, threshold.Tenant, threshold.ID), threshold, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -766,7 +766,7 @@ func (iDB *InternalDB) SetTPFilters(filters []*utils.TPFilterProfile) (err error } for _, filter := range filters { - iDB.db.Set(utils.TBLTPFilters, utils.ConcatenatedKey(filter.TPid, filter.Tenant, filter.ID), filter, nil, + Cache.Set(utils.TBLTPFilters, utils.ConcatenatedKey(filter.TPid, filter.Tenant, filter.ID), filter, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -777,7 +777,7 @@ func (iDB *InternalDB) SetTPRoutes(routes []*utils.TPRouteProfile) (err error) { return nil } for _, route := range routes { - iDB.db.Set(utils.TBLTPRoutes, utils.ConcatenatedKey(route.TPid, route.Tenant, route.ID), route, nil, + Cache.Set(utils.TBLTPRoutes, utils.ConcatenatedKey(route.TPid, route.Tenant, route.ID), route, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -789,7 +789,7 @@ func (iDB *InternalDB) SetTPAttributes(attributes []*utils.TPAttributeProfile) ( } for _, attribute := range attributes { - iDB.db.Set(utils.TBLTPAttributes, utils.ConcatenatedKey(attribute.TPid, attribute.Tenant, attribute.ID), attribute, nil, + Cache.Set(utils.TBLTPAttributes, utils.ConcatenatedKey(attribute.TPid, attribute.Tenant, attribute.ID), attribute, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -800,7 +800,7 @@ func (iDB *InternalDB) SetTPChargers(cpps []*utils.TPChargerProfile) (err error) } for _, cpp := range cpps { - iDB.db.Set(utils.TBLTPChargers, utils.ConcatenatedKey(cpp.TPid, cpp.Tenant, cpp.ID), cpp, nil, + Cache.Set(utils.TBLTPChargers, utils.ConcatenatedKey(cpp.TPid, cpp.Tenant, cpp.ID), cpp, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -811,7 +811,7 @@ func (iDB *InternalDB) SetTPDispatcherProfiles(dpps []*utils.TPDispatcherProfile } for _, dpp := range dpps { - iDB.db.Set(utils.TBLTPDispatchers, utils.ConcatenatedKey(dpp.TPid, dpp.Tenant, dpp.ID), dpp, nil, + Cache.Set(utils.TBLTPDispatchers, utils.ConcatenatedKey(dpp.TPid, dpp.Tenant, dpp.ID), dpp, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -821,7 +821,7 @@ func (iDB *InternalDB) SetTPDispatcherHosts(dpps []*utils.TPDispatcherHost) (err return nil } for _, dpp := range dpps { - iDB.db.Set(utils.TBLTPDispatcherHosts, utils.ConcatenatedKey(dpp.TPid, dpp.Tenant, dpp.ID), dpp, nil, + Cache.Set(utils.TBLTPDispatcherHosts, utils.ConcatenatedKey(dpp.TPid, dpp.Tenant, dpp.ID), dpp, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return @@ -845,7 +845,7 @@ func (iDB *InternalDB) SetCDR(cdr *CDR, allowUpdate bool) (err error) { } cdrKey := utils.ConcatenatedKey(cdr.CGRID, cdr.RunID, cdr.OriginID) if !allowUpdate { - if _, has := iDB.db.Get(utils.CDRsTBL, cdrKey); has { + if _, has := Cache.Get(utils.CDRsTBL, cdrKey); has { return utils.ErrExists } } @@ -882,14 +882,14 @@ func (iDB *InternalDB) SetCDR(cdr *CDR, allowUpdate bool) (err error) { } iDB.indexedFieldsMutex.RUnlock() - iDB.db.Set(utils.CDRsTBL, cdrKey, cdr, idxs.AsSlice(), + Cache.Set(utils.CDRsTBL, cdrKey, cdr, idxs.AsSlice(), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } func (iDB *InternalDB) RemoveSMCost(smc *SMCost) (err error) { - iDB.db.Remove(utils.SessionCostsTBL, utils.ConcatenatedKey(smc.CGRID, smc.RunID, smc.OriginHost, smc.OriginID), + Cache.Remove(utils.SessionCostsTBL, utils.ConcatenatedKey(smc.CGRID, smc.RunID, smc.OriginHost, smc.OriginID), cacheCommit(utils.NonTransactional), utils.NonTransactional) return } @@ -912,7 +912,7 @@ func (iDB *InternalDB) RemoveSMCosts(qryFltr *utils.SMCostFilter) error { } grpMpIDs := make(utils.StringMap) for _, id := range fltrSlc.ids { - grpIDs := iDB.db.GetGroupItemIDs(utils.SessionCostsTBL, utils.ConcatenatedKey(fltrSlc.key, id)) + grpIDs := Cache.tCache.GetGroupItemIDs(utils.SessionCostsTBL, utils.ConcatenatedKey(fltrSlc.key, id)) for _, id := range grpIDs { grpMpIDs[id] = true } @@ -935,7 +935,7 @@ func (iDB *InternalDB) RemoveSMCosts(qryFltr *utils.SMCostFilter) error { } if smMpIDs == nil { - smMpIDs = utils.StringMapFromSlice(iDB.db.GetItemIDs(utils.SessionCostsTBL, utils.EmptyString)) + smMpIDs = utils.StringMapFromSlice(Cache.GetItemIDs(utils.SessionCostsTBL, utils.EmptyString)) } // check for Not filters @@ -953,7 +953,7 @@ func (iDB *InternalDB) RemoveSMCosts(qryFltr *utils.SMCostFilter) error { continue } for _, id := range fltrSlc.ids { - grpIDs := iDB.db.GetGroupItemIDs(utils.CDRsTBL, utils.ConcatenatedKey(fltrSlc.key, id)) + grpIDs := Cache.tCache.GetGroupItemIDs(utils.CDRsTBL, utils.ConcatenatedKey(fltrSlc.key, id)) for _, id := range grpIDs { if smMpIDs.HasKey(id) { delete(smMpIDs, id) @@ -970,7 +970,7 @@ func (iDB *InternalDB) RemoveSMCosts(qryFltr *utils.SMCostFilter) error { } for key := range smMpIDs { - iDB.db.Remove(utils.SessionCostsTBL, key, + Cache.Remove(utils.SessionCostsTBL, key, cacheCommit(utils.NonTransactional), utils.NonTransactional) } return nil @@ -1137,7 +1137,7 @@ func (iDB *InternalDB) GetCDRs(filter *utils.CDRsFilter, remove bool) (cdrs []*C } grpMpIDs := utils.NewStringSet([]string{}) for _, id := range fltrSlc.ids { - grpIDs := iDB.db.GetGroupItemIDs(utils.CDRsTBL, utils.ConcatenatedKey(fltrSlc.key, id)) + grpIDs := Cache.tCache.GetGroupItemIDs(utils.CDRsTBL, utils.ConcatenatedKey(fltrSlc.key, id)) grpMpIDs.AddSlice(grpIDs) } if grpMpIDs.Size() == 0 { @@ -1159,7 +1159,7 @@ func (iDB *InternalDB) GetCDRs(filter *utils.CDRsFilter, remove bool) (cdrs []*C } } if cdrMpIDs == nil { - cdrMpIDs = utils.NewStringSet(iDB.db.GetItemIDs(utils.CDRsTBL, utils.EmptyString)) + cdrMpIDs = utils.NewStringSet(Cache.GetItemIDs(utils.CDRsTBL, utils.EmptyString)) } // check for Not filters for _, fltrSlc := range notPairSlice { @@ -1167,7 +1167,7 @@ func (iDB *InternalDB) GetCDRs(filter *utils.CDRsFilter, remove bool) (cdrs []*C continue } for _, id := range fltrSlc.ids { - grpIDs := iDB.db.GetGroupItemIDs(utils.CDRsTBL, utils.ConcatenatedKey(fltrSlc.key, id)) + grpIDs := Cache.tCache.GetGroupItemIDs(utils.CDRsTBL, utils.ConcatenatedKey(fltrSlc.key, id)) for _, id := range grpIDs { if cdrMpIDs.Has(id) { cdrMpIDs.Remove(id) @@ -1207,7 +1207,7 @@ func (iDB *InternalDB) GetCDRs(filter *utils.CDRsFilter, remove bool) (cdrs []*C paginatorOffsetCounter := 0 for key := range cdrMpIDs { - x, ok := iDB.db.Get(utils.CDRsTBL, key) + x, ok := Cache.Get(utils.CDRsTBL, key) if !ok || x == nil { return nil, 0, utils.ErrNotFound } @@ -1653,7 +1653,7 @@ func (iDB *InternalDB) GetCDRs(filter *utils.CDRsFilter, remove bool) (cdrs []*C } if remove { for _, cdr := range cdrs { - iDB.db.Remove(utils.CDRsTBL, utils.ConcatenatedKey(cdr.CGRID, cdr.RunID, cdr.OriginID), + Cache.Remove(utils.CDRsTBL, utils.ConcatenatedKey(cdr.CGRID, cdr.RunID, cdr.OriginID), cacheCommit(utils.NonTransactional), utils.NonTransactional) } return nil, 0, nil @@ -1742,7 +1742,7 @@ func (iDB *InternalDB) GetSMCosts(cgrid, runid, originHost, originIDPrfx string) } grpMpIDs := make(utils.StringMap) - grpIDs := iDB.db.GetGroupItemIDs(utils.SessionCostsTBL, utils.ConcatenatedKey(fltrSlc.key, fltrSlc.id)) + grpIDs := Cache.tCache.GetGroupItemIDs(utils.SessionCostsTBL, utils.ConcatenatedKey(fltrSlc.key, fltrSlc.id)) for _, id := range grpIDs { grpMpIDs[id] = true } @@ -1764,13 +1764,13 @@ func (iDB *InternalDB) GetSMCosts(cgrid, runid, originHost, originIDPrfx string) } } if smMpIDs == nil { - smMpIDs = utils.StringMapFromSlice(iDB.db.GetItemIDs(utils.SessionCostsTBL, utils.EmptyString)) + smMpIDs = utils.StringMapFromSlice(Cache.GetItemIDs(utils.SessionCostsTBL, utils.EmptyString)) } if len(smMpIDs) == 0 { return nil, utils.ErrNotFound } for key := range smMpIDs { - x, ok := iDB.db.Get(utils.SessionCostsTBL, key) + x, ok := Cache.Get(utils.SessionCostsTBL, key) if !ok || x == nil { return nil, utils.ErrNotFound } @@ -1793,7 +1793,7 @@ func (iDB *InternalDB) SetSMCost(smCost *SMCost) (err error) { idxs.Add(utils.ConcatenatedKey(utils.OriginHost, smCost.OriginHost)) idxs.Add(utils.ConcatenatedKey(utils.OriginID, smCost.OriginID)) idxs.Add(utils.ConcatenatedKey(utils.CostSource, smCost.CostSource)) - iDB.db.Set(utils.SessionCostsTBL, utils.ConcatenatedKey(smCost.CGRID, smCost.RunID, smCost.OriginHost, smCost.OriginID), smCost, idxs.AsSlice(), + Cache.Set(utils.SessionCostsTBL, utils.ConcatenatedKey(smCost.CGRID, smCost.RunID, smCost.OriginHost, smCost.OriginID), smCost, idxs.AsSlice(), cacheCommit(utils.NonTransactional), utils.NonTransactional) return err } diff --git a/utils/consts.go b/utils/consts.go index e446ccb75..1e519ade3 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -1648,6 +1648,7 @@ const ( CacheSTIR = "*stir" CacheEventCharges = "*event_charges" CacheReverseFilterIndexes = "*reverse_filter_indexes" + CacheVersions = "*versions" ) // Prefix for indexing