Updated cache handling on tariffplan load

This commit is contained in:
Trial97
2021-04-29 16:29:00 +03:00
committed by Dan Christian Bogos
parent f1eb30a3bd
commit 08cd8fdf6d
2 changed files with 72 additions and 128 deletions

View File

@@ -1248,51 +1248,23 @@ func (tpr *TpReader) ReloadCache(ctx *context.Context, caching string, verbose b
accountPrfIDs, _ := tpr.GetLoadedIds(utils.AccountPrefix)
//compose Reload Cache argument
cacheArgs := utils.AttrReloadCacheWithAPIOpts{
APIOpts: opts,
ArgsCache: map[string][]string{
utils.DestinationIDs: dstIds,
utils.ReverseDestinationIDs: revDstIDs,
utils.ResourceProfileIDs: rspIDs,
utils.ResourceIDs: resIDs,
utils.StatsQueueIDs: stqIDs,
utils.StatsQueueProfileIDs: stqpIDs,
utils.ThresholdIDs: trsIDs,
utils.ThresholdProfileIDs: trspfIDs,
utils.FilterIDs: flrIDs,
utils.RouteProfileIDs: routeIDs,
utils.AttributeProfileIDs: apfIDs,
utils.ChargerProfileIDs: chargerIDs,
utils.DispatcherProfileIDs: dppIDs,
utils.DispatcherHostIDs: dphIDs,
utils.RateProfileIDs: ratePrfIDs,
utils.ActionProfileIDs: actionPrfIDs,
},
}
if verbose {
log.Print("Reloading cache")
}
var reply string
switch caching {
case utils.MetaNone:
return
case utils.MetaReload:
if err = connMgr.Call(ctx, tpr.cacheConns, utils.CacheSv1ReloadCache, cacheArgs, &reply); err != nil {
return
}
case utils.MetaLoad:
if err = connMgr.Call(ctx, tpr.cacheConns, utils.CacheSv1LoadCache, cacheArgs, &reply); err != nil {
return
}
case utils.MetaRemove:
if err = connMgr.Call(ctx, tpr.cacheConns, utils.CacheSv1RemoveItems, cacheArgs, &reply); err != nil {
return
}
case utils.MetaClear:
if err = connMgr.Call(ctx, tpr.cacheConns, utils.CacheSv1Clear, new(utils.AttrCacheIDsWithAPIOpts), &reply); err != nil {
return
}
cacheArgs := map[string][]string{
utils.DestinationIDs: dstIds,
utils.ReverseDestinationIDs: revDstIDs,
utils.ResourceProfileIDs: rspIDs,
utils.ResourceIDs: resIDs,
utils.StatsQueueIDs: stqIDs,
utils.StatsQueueProfileIDs: stqpIDs,
utils.ThresholdIDs: trsIDs,
utils.ThresholdProfileIDs: trspfIDs,
utils.FilterIDs: flrIDs,
utils.RouteProfileIDs: routeIDs,
utils.AttributeProfileIDs: apfIDs,
utils.ChargerProfileIDs: chargerIDs,
utils.DispatcherProfileIDs: dppIDs,
utils.DispatcherHostIDs: dphIDs,
utils.RateProfileIDs: ratePrfIDs,
utils.ActionProfileIDs: actionPrfIDs,
}
// verify if we need to clear indexes
@@ -1331,23 +1303,16 @@ func (tpr *TpReader) ReloadCache(ctx *context.Context, caching string, verbose b
if len(flrIDs) != 0 {
cacheIDs = append(cacheIDs, utils.CacheReverseFilterIndexes)
}
if verbose {
log.Print("Clearing indexes")
}
clearArgs := &utils.AttrCacheIDsWithAPIOpts{
APIOpts: opts,
CacheIDs: cacheIDs,
}
if err = connMgr.Call(ctx, tpr.cacheConns, utils.CacheSv1Clear, clearArgs, &reply); err != nil {
log.Printf("WARNING: Got error on cache clear: %s\n", err.Error())
}
if err = CallCache(connMgr, ctx, tpr.cacheConns, caching, cacheArgs, cacheIDs, opts, verbose); err != nil {
return
}
//get loadIDs for all types
var loadIDs map[string]int64
if loadIDs, err = tpr.dm.GetItemLoadIDs(ctx, utils.EmptyString, false); err != nil {
return
}
cacheLoadIDs := populateCacheLoadIDs(loadIDs, cacheArgs.ArgsCache)
cacheLoadIDs := populateCacheLoadIDs(loadIDs, cacheArgs)
for key, val := range cacheLoadIDs {
if err = Cache.Set(ctx, utils.CacheLoadIDs, key, val, nil,
cacheCommit(utils.NonTransactional), utils.NonTransactional); err != nil {
@@ -1357,6 +1322,55 @@ func (tpr *TpReader) ReloadCache(ctx *context.Context, caching string, verbose b
return
}
// CallCache call the cache reload after data load
func CallCache(connMgr *ConnManager, ctx *context.Context, cacheConns []string, caching string, args map[string][]string, cacheIDs []string, opts map[string]interface{}, verbose bool) (err error) {
for k, v := range args {
if len(v) == 0 {
delete(args, k)
}
}
var method, reply string
var cacheArgs interface{} = utils.AttrReloadCacheWithAPIOpts{
APIOpts: opts,
ArgsCache: args,
}
switch caching {
case utils.MetaNone:
return
case utils.MetaReload:
method = utils.CacheSv1ReloadCache
case utils.MetaLoad:
method = utils.CacheSv1LoadCache
case utils.MetaRemove:
method = utils.CacheSv1RemoveItems
case utils.MetaClear:
method = utils.CacheSv1Clear
cacheArgs = &utils.AttrCacheIDsWithAPIOpts{APIOpts: opts}
}
if verbose {
log.Print("Reloading cache")
}
if err = connMgr.Call(ctx, cacheConns, method, cacheArgs, &reply); err != nil {
return
}
if len(cacheIDs) != 0 {
if verbose {
log.Print("Clearing indexes")
}
if err = connMgr.Call(ctx, cacheConns, utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{
APIOpts: opts,
CacheIDs: cacheIDs,
}, &reply); err != nil {
if verbose {
log.Printf("WARNING: Got error on cache clear: %s\n", err.Error())
}
}
}
return
}
func (tpr *TpReader) ReloadScheduler(verbose bool) (err error) { // ToDoNext: add reload to new actions
// var reply string
// aps, _ := tpr.GetLoadedIds(utils.ActionPlanPrefix)