Clearing Cache when removing indexes

This commit is contained in:
porosnicuadrian
2021-05-10 09:41:20 +03:00
committed by Dan Christian Bogos
parent 18d2841670
commit 983f74f8a8
5 changed files with 36 additions and 3 deletions

View File

@@ -17,6 +17,7 @@ package apis
import (
"strings"
"time"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/engine"
@@ -37,6 +38,7 @@ type AttrRemFilterIndexes struct {
Tenant string
Context string
ItemType string
APIOpts map[string]interface{}
}
func (adms *AdminSv1) RemoveFilterIndexes(ctx *context.Context, arg *AttrRemFilterIndexes, reply *string) (err error) {
@@ -75,6 +77,15 @@ func (adms *AdminSv1) RemoveFilterIndexes(ctx *context.Context, arg *AttrRemFilt
if err = adms.dm.RemoveIndexes(ctx, arg.ItemType, tntCtx, utils.EmptyString); err != nil {
return
}
//generate a loadID for CacheFilterIndexes and store it in database
if err := adms.dm.SetLoadIDs(ctx,
map[string]int64{arg.ItemType: time.Now().UnixNano()}); err != nil {
return utils.APIErrorHandler(err)
}
if err := adms.callCacheForIndexes(ctx, utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), arg.Tenant,
arg.ItemType, arg.APIOpts); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
return
}

View File

@@ -578,7 +578,9 @@ func testV1FIdxAttributeSRemoveComputedIndexesIDs(t *testing.T) {
}
if err := tFIdxRpc.Call(context.Background(), utils.AdminSv1RemoveFilterIndexes,
&AttrRemFilterIndexes{Tenant: utils.CGRateSorg, Context: utils.MetaSessionS,
ItemType: utils.MetaAttributes},
ItemType: utils.MetaAttributes, APIOpts: map[string]interface{}{
utils.CacheOpt: utils.MetaClear,
}},
&reply); err != nil {
t.Error(err)
} else if reply != utils.OK {

View File

@@ -137,6 +137,21 @@ func (admS *AdminSv1) composeArgsReload(ctx *context.Context, tnt, cacheID, item
return
}
// callCacheForIndexes will only call CacheClear because don't have access at ItemID
func (admS *AdminSv1) callCacheForIndexes(ctx *context.Context, cacheopt string, tnt, cacheID string,
opts map[string]interface{}) (err error) {
if utils.FirstNonEmpty(cacheopt, admS.cfg.GeneralCfg().DefaultCaching) == utils.MetaClear {
var reply string
return admS.connMgr.Call(ctx, admS.cfg.AdminSCfg().CachesConns,
utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{
Tenant: tnt,
CacheIDs: []string{cacheID},
APIOpts: opts,
}, &reply)
}
return
}
/*
// callCacheRevDestinations used for reverse destination, loadIDs and indexes replication
func (apierSv1 *AdminS) callCacheMultiple(cacheopt, tnt, cacheID string, itemIDs []string, opts map[string]interface{}) (err error) {

View File

@@ -342,6 +342,8 @@ func TestThresholdsmatchingThresholdsForEvent(t *testing.T) {
},
},
}
dmTH.SetFilter(context.TODO(), fltrTh2, true)
dmTH.SetFilter(context.TODO(), fltrTh3, true)
for _, th := range tPrfls {
if err = dmTH.SetThresholdProfile(th, true); err != nil {
t.Errorf("Error: %+v", err)

View File

@@ -154,6 +154,7 @@ func TestFilterMatchingItemIDsForEvent2(t *testing.T) {
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "stringFilter",
Rules: stringFilter}
dmMatch.SetFilter(context.TODO(), attribStringF, true)
x, err = NewFilterRule(utils.MetaPrefix, "~*req.CallCost.Field", []string{"profile"})
if err != nil {
@@ -164,6 +165,7 @@ func TestFilterMatchingItemIDsForEvent2(t *testing.T) {
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "prefFilter",
Rules: prefixFilter}
dmMatch.SetFilter(context.TODO(), attribPrefF, true)
x, err = NewFilterRule(utils.MetaGreaterOrEqual, "~*req.Weight", []string{"200.00"})
if err != nil {
@@ -173,8 +175,9 @@ func TestFilterMatchingItemIDsForEvent2(t *testing.T) {
attribDefaultF := &Filter{
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
ID: "defaultFilter",
Rules: defaultFilter}
Rules: defaultFilter,
}
dmMatch.SetFilter(context.TODO(), attribDefaultF, true)
tnt := config.CgrConfig().GeneralCfg().DefaultTenant
if err = addItemToFilterIndex(context.TODO(), dmMatch, utils.CacheAttributeFilterIndexes,