diff --git a/apier/v1/apier.go b/apier/v1/apier.go index df067422d..70dc714b5 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -1034,10 +1034,7 @@ func (self *ApierV1) LoadCache(args utils.AttrReloadCache, reply *string) (err e resIDs = *args.ResourceIDs } - if err := self.DataDB.LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aapIDs, atrgIDs, sgIDs, lcrIDs, dcIDs); err != nil { - return utils.NewErrServerError(err) - } - if err := self.DataDB.LoadAccountingCache(alsIDs, rvAlsIDs, rspIDs, resIDs); err != nil { + if err := self.DataDB.LoadDataDBCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aapIDs, atrgIDs, sgIDs, lcrIDs, dcIDs, alsIDs, rvAlsIDs, rspIDs, resIDs); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK diff --git a/cmd/cgr-engine/rater.go b/cmd/cgr-engine/rater.go index c65813a11..7c54317af 100755 --- a/cmd/cgr-engine/rater.go +++ b/cmd/cgr-engine/rater.go @@ -90,16 +90,11 @@ func startRater(internalRaterChan chan rpcclient.RpcClientConnection, cacheDoneC } // ToDo: Add here timings - if err := dataDB.LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aapIDs, atrgIDs, sgIDs, lcrIDs, dcIDs); err != nil { + if err := dataDB.LoadDataDBCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aapIDs, atrgIDs, sgIDs, lcrIDs, dcIDs, alsIDs, rvAlsIDs, rspIDs, resIDs); err != nil { utils.Logger.Crit(fmt.Sprintf(" Cache rating error: %s", err.Error())) exitChan <- true return } - if err := dataDB.LoadAccountingCache(alsIDs, rvAlsIDs, rspIDs, resIDs); err != nil { - utils.Logger.Crit(fmt.Sprintf(" Cache accounting error: %s", err.Error())) - exitChan <- true - return - } cacheDoneChan <- struct{}{} }() diff --git a/cmd/cgr-tester/cgr-tester.go b/cmd/cgr-tester/cgr-tester.go index 9ab67df3b..d02cd2a01 100644 --- a/cmd/cgr-tester/cgr-tester.go +++ b/cmd/cgr-tester/cgr-tester.go @@ -65,12 +65,9 @@ func durInternalRater(cd *engine.CallDescriptor) (time.Duration, error) { } defer dataDb.Close() engine.SetDataStorage(dataDb) - if err := dataDb.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil); err != nil { + if err := dataDb.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil); err != nil { return nilDuration, fmt.Errorf("Cache rating error: %s", err.Error()) } - if err := dataDb.LoadAccountingCache(nil, nil, nil, nil); err != nil { - return nilDuration, fmt.Errorf("Cache accounting error: %s", err.Error()) - } log.Printf("Runnning %d cycles...", *runs) var result *engine.CallCost j := 0 diff --git a/engine/libtest.go b/engine/libtest.go index b80b0c088..a44c67771 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -40,7 +40,7 @@ func InitDataDb(cfg *config.CGRConfig) error { if err := dataDB.Flush(""); err != nil { return err } - dataDB.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) + dataDB.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) CheckVersion(dataDB) // Write version before starting return nil } diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index a8a76580b..6a79b3b9e 100755 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -348,8 +348,7 @@ func init() { } csvr.WriteToDatabase(false, false, false) cache.Flush() - dataStorage.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) - dataStorage.LoadAccountingCache(nil, nil, nil, nil) + dataStorage.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) } func TestLoadDestinations(t *testing.T) { diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 92853f240..73f50a48a 100755 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -45,7 +45,7 @@ type DataDB interface { Storage Marshaler() Marshaler HasData(string, string) (bool, error) - LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aapIDs, atrgIDs, sgIDs, lcrIDs, dcIDs []string) error + LoadDataDBCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aapIDs, atrgIDs, sgIDs, lcrIDs, dcIDs, alsIDs, rvAlsIDs, rlIDs, resIDs []string) error GetRatingPlan(string, bool, string) (*RatingPlan, error) SetRatingPlan(*RatingPlan, string) error GetRatingProfile(string, bool, string) (*RatingProfile, error) @@ -80,7 +80,6 @@ type DataDB interface { RemAccountActionPlans(acntID string, apIDs []string) (err error) PushTask(*Task) error PopTask() (*Task, error) - LoadAccountingCache(alsIDs, rvAlsIDs, rspIDs, resIDs []string) error GetAccount(string) (*Account, error) SetAccount(*Account) error RemoveAccount(string) error diff --git a/engine/storage_map.go b/engine/storage_map.go index d79793221..870b5df99 100755 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -146,7 +146,7 @@ func (ms *MapStorage) RebuildReverseForPrefix(prefix string) error { return nil } -func (ms *MapStorage) LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aapIDs, atrgIDs, sgIDs, lcrIDs, dcIDs []string) (err error) { +func (ms *MapStorage) LoadDataDBCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aapIDs, atrgIDs, sgIDs, lcrIDs, dcIDs, alsIDs, rvAlsIDs, rlIDs, resIDs []string) (err error) { if ms.cacheCfg == nil { return } @@ -155,7 +155,7 @@ func (ms *MapStorage) LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, if utils.IsSliceMember([]string{utils.DESTINATION_PREFIX, utils.REVERSE_DESTINATION_PREFIX, utils.RATING_PLAN_PREFIX, utils.RATING_PROFILE_PREFIX, utils.LCR_PREFIX, utils.CDR_STATS_PREFIX, utils.ACTION_PREFIX, utils.ACTION_PLAN_PREFIX, utils.ACTION_TRIGGER_PREFIX, - utils.SHARED_GROUP_PREFIX}, k) && cacheCfg.Precache { + utils.SHARED_GROUP_PREFIX, utils.ALIASES_PREFIX, utils.REVERSE_ALIASES_PREFIX}, k) && cacheCfg.Precache { if err := ms.PreloadCacheForPrefix(k); err != nil && err != utils.ErrInvalidKey { return err } @@ -165,21 +165,6 @@ func (ms *MapStorage) LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, return } -func (ms *MapStorage) LoadAccountingCache(alsIDs, rvAlsIDs, rlIDs, resIDs []string) error { - if ms.cacheCfg == nil { - return nil - } - for k, cacheCfg := range ms.cacheCfg { - k = utils.CacheInstanceToPrefix[k] // alias into prefixes understood by storage - if utils.IsSliceMember([]string{utils.ALIASES_PREFIX, utils.REVERSE_ALIASES_PREFIX}, k) && cacheCfg.Precache { - if err := ms.PreloadCacheForPrefix(k); err != nil && err != utils.ErrInvalidKey { - return err - } - } - } - return nil -} - func (ms *MapStorage) PreloadCacheForPrefix(prefix string) error { transID := cache.BeginTransaction() cache.RemPrefixKey(prefix, false, transID) diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 4f965fb8e..5cc1a4540 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -417,7 +417,7 @@ func (ms *MongoStorage) RebuildReverseForPrefix(prefix string) (err error) { return nil } -func (ms *MongoStorage) LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aaPlIDs, atrgIDs, sgIDs, lcrIDs, dcIDs []string) (err error) { +func (ms *MongoStorage) LoadDataDBCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aaPlIDs, atrgIDs, sgIDs, lcrIDs, dcIDs, alsIDs, rvAlsIDs, rpIDs, resIDs []string) (err error) { for key, ids := range map[string][]string{ utils.DESTINATION_PREFIX: dstIDs, utils.REVERSE_DESTINATION_PREFIX: rvDstIDs, @@ -430,20 +430,10 @@ func (ms *MongoStorage) LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs utils.SHARED_GROUP_PREFIX: sgIDs, utils.LCR_PREFIX: lcrIDs, utils.DERIVEDCHARGERS_PREFIX: dcIDs, - } { - if err = ms.CacheDataFromDB(key, ids, false); err != nil { - return - } - } - return -} - -func (ms *MongoStorage) LoadAccountingCache(alsIDs, rvAlsIDs, rpIDs, resIDs []string) (err error) { - for key, ids := range map[string][]string{ - utils.ALIASES_PREFIX: alsIDs, - utils.REVERSE_ALIASES_PREFIX: rvAlsIDs, - utils.ResourceProfilesPrefix: rpIDs, - utils.ResourcesPrefix: resIDs, + utils.ALIASES_PREFIX: alsIDs, + utils.REVERSE_ALIASES_PREFIX: rvAlsIDs, + utils.ResourceProfilesPrefix: rpIDs, + utils.ResourcesPrefix: resIDs, } { if err = ms.CacheDataFromDB(key, ids, false); err != nil { return diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 9b335582d..20ae74e88 100755 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -118,8 +118,8 @@ func (rs *RedisStorage) SelectDatabase(dbName string) (err error) { return rs.Cmd("SELECT", dbName).Err } -func (rs *RedisStorage) LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, - aplIDs, aaPlIDs, atrgIDs, sgIDs, lcrIDs, dcIDs []string) (err error) { +func (rs *RedisStorage) LoadDataDBCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, + aplIDs, aaPlIDs, atrgIDs, sgIDs, lcrIDs, dcIDs, alsIDs, rvAlsIDs, rpIDs, resIDs []string) (err error) { for key, ids := range map[string][]string{ utils.DESTINATION_PREFIX: dstIDs, utils.REVERSE_DESTINATION_PREFIX: rvDstIDs, @@ -132,20 +132,10 @@ func (rs *RedisStorage) LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs utils.SHARED_GROUP_PREFIX: sgIDs, utils.LCR_PREFIX: lcrIDs, utils.DERIVEDCHARGERS_PREFIX: dcIDs, - } { - if err = rs.CacheDataFromDB(key, ids, false); err != nil { - return - } - } - return -} - -func (rs *RedisStorage) LoadAccountingCache(alsIDs, rvAlsIDs, rpIDs, resIDs []string) (err error) { - for key, ids := range map[string][]string{ - utils.ALIASES_PREFIX: alsIDs, - utils.REVERSE_ALIASES_PREFIX: rvAlsIDs, - utils.ResourceProfilesPrefix: rpIDs, - utils.ResourcesPrefix: resIDs, + utils.ALIASES_PREFIX: alsIDs, + utils.REVERSE_ALIASES_PREFIX: rvAlsIDs, + utils.ResourceProfilesPrefix: rpIDs, + utils.ResourcesPrefix: resIDs, } { if err = rs.CacheDataFromDB(key, ids, false); err != nil { return diff --git a/engine/storage_test.go b/engine/storage_test.go index 76e81381b..f6f9e02af 100644 --- a/engine/storage_test.go +++ b/engine/storage_test.go @@ -102,7 +102,7 @@ func TestStorageCacheRefresh(t *testing.T) { dataStorage.GetDestination("T11", false, utils.NonTransactional) dataStorage.SetDestination(&Destination{"T11", []string{"1"}}, utils.NonTransactional) t.Log("Test cache refresh") - err := dataStorage.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) + err := dataStorage.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) if err != nil { t.Error("Error cache rating: ", err) } diff --git a/general_tests/acntacts_test.go b/general_tests/acntacts_test.go index 1c2bc6dfb..450071c05 100644 --- a/general_tests/acntacts_test.go +++ b/general_tests/acntacts_test.go @@ -63,8 +63,7 @@ ENABLE_ACNT,*enable_account,,,,,,,,,,,,,,false,false,10` csvr.WriteToDatabase(false, false, false) cache.Flush() - dbAcntActs.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) - dbAcntActs.LoadAccountingCache(nil, nil, nil, nil) + dbAcntActs.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) expectAcnt := &engine.Account{ID: "cgrates.org:1"} if acnt, err := dbAcntActs.GetAccount("cgrates.org:1"); err != nil { diff --git a/general_tests/auth_test.go b/general_tests/auth_test.go index 009e06513..224a71e36 100644 --- a/general_tests/auth_test.go +++ b/general_tests/auth_test.go @@ -75,8 +75,7 @@ RP_ANY,DR_ANY_1CNT,*any,10` } cache.Flush() - dbAuth.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) - dbAuth.LoadAccountingCache(nil, nil, nil, nil) + dbAuth.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) if cachedDests := cache.CountEntries(utils.DESTINATION_PREFIX); cachedDests != 0 { t.Error("Wrong number of cached destinations found", cachedDests) diff --git a/general_tests/costs1_test.go b/general_tests/costs1_test.go index 92ef56747..5c270ac5e 100644 --- a/general_tests/costs1_test.go +++ b/general_tests/costs1_test.go @@ -73,8 +73,7 @@ RP_SMS1,DR_SMS_1,ALWAYS,10` } csvr.WriteToDatabase(false, false, false) cache.Flush() - dataDB.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) - dataDB.LoadAccountingCache(nil, nil, nil, nil) + dataDB.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) if cachedRPlans := cache.CountEntries(utils.RATING_PLAN_PREFIX); cachedRPlans != 3 { t.Error("Wrong number of cached rating plans found", cachedRPlans) diff --git a/general_tests/datachrg1_test.go b/general_tests/datachrg1_test.go index a7384e9e0..6f2e0ebc4 100644 --- a/general_tests/datachrg1_test.go +++ b/general_tests/datachrg1_test.go @@ -60,8 +60,7 @@ RP_DATA1,DR_DATA_2,TM2,10` } csvr.WriteToDatabase(false, false, false) cache.Flush() - dataDB.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) - dataDB.LoadAccountingCache(nil, nil, nil, nil) + dataDB.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) if cachedRPlans := cache.CountEntries(utils.RATING_PLAN_PREFIX); cachedRPlans != 1 { t.Error("Wrong number of cached rating plans found", cachedRPlans) diff --git a/general_tests/ddazmbl1_test.go b/general_tests/ddazmbl1_test.go index 7bd6d307e..cb3295890 100644 --- a/general_tests/ddazmbl1_test.go +++ b/general_tests/ddazmbl1_test.go @@ -110,8 +110,7 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10` t.Error("No account saved") } cache.Flush() - dataDB.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) - dataDB.LoadAccountingCache(nil, nil, nil, nil) + dataDB.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) if cachedDests := cache.CountEntries(utils.DESTINATION_PREFIX); cachedDests != 0 { t.Error("Wrong number of cached destinations found", cachedDests) diff --git a/general_tests/ddazmbl2_test.go b/general_tests/ddazmbl2_test.go index 831761d4a..890359e80 100644 --- a/general_tests/ddazmbl2_test.go +++ b/general_tests/ddazmbl2_test.go @@ -110,8 +110,7 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10` t.Error("No account saved") } cache.Flush() - dataDB2.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) - dataDB2.LoadAccountingCache(nil, nil, nil, nil) + dataDB2.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) if cachedDests := cache.CountEntries(utils.DESTINATION_PREFIX); cachedDests != 0 { t.Error("Wrong number of cached destinations found", cachedDests) diff --git a/general_tests/ddazmbl3_test.go b/general_tests/ddazmbl3_test.go index 19537e324..145f554b5 100644 --- a/general_tests/ddazmbl3_test.go +++ b/general_tests/ddazmbl3_test.go @@ -108,8 +108,7 @@ RP_UK,DR_UK_Mobile_BIG5,ALWAYS,10` t.Error("No account saved") } cache.Flush() - dataDB3.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) - dataDB3.LoadAccountingCache(nil, nil, nil, nil) + dataDB3.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) if cachedDests := cache.CountEntries(utils.DESTINATION_PREFIX); cachedDests != 0 { t.Error("Wrong number of cached destinations found", cachedDests) diff --git a/general_tests/smschrg1_test.go b/general_tests/smschrg1_test.go index 4f11b2787..e02c08c8c 100644 --- a/general_tests/smschrg1_test.go +++ b/general_tests/smschrg1_test.go @@ -58,8 +58,7 @@ func TestSMSLoadCsvTpSmsChrg1(t *testing.T) { } csvr.WriteToDatabase(false, false, false) cache.Flush() - dataDB.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) - dataDB.LoadAccountingCache(nil, nil, nil, nil) + dataDB.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) if cachedRPlans := cache.CountEntries(utils.RATING_PLAN_PREFIX); cachedRPlans != 1 { t.Error("Wrong number of cached rating plans found", cachedRPlans)