From b7ddb2c06673bccdb92b3bb450cf41cc3f1aed11 Mon Sep 17 00:00:00 2001 From: TeoV Date: Tue, 21 Aug 2018 10:29:17 -0400 Subject: [PATCH] Remove from config filter reverse indexes and update integration test --- apier/v1/filter_indexes_it_test.go | 10 +- apier/v1/filterindexecache_it_test.go | 16 +-- apier/v1/sessionsv1_it_test.go | 4 + config/config_defaults.go | 6 -- config/config_json_test.go | 12 --- config/config_test.go | 12 --- data/conf/samples/mongoatlas/cgrates.json | 6 +- data/conf/samples/mongoreplica/cgrates.json | 6 +- data/conf/samples/tutmongo/cgrates.json | 6 +- data/conf/samples/tutmongojson/cgrates.json | 6 +- data/conf/samples/tutmysql/cgrates.json | 6 +- data/conf/samples/tutmysqljson/cgrates.json | 6 +- engine/datamanager.go | 2 +- engine/storage_mongo_datadb.go | 105 -------------------- engine/storage_redis.go | 80 --------------- 15 files changed, 24 insertions(+), 259 deletions(-) diff --git a/apier/v1/filter_indexes_it_test.go b/apier/v1/filter_indexes_it_test.go index 9a7e60b54..b981e8833 100644 --- a/apier/v1/filter_indexes_it_test.go +++ b/apier/v1/filter_indexes_it_test.go @@ -57,11 +57,11 @@ var sTestsFilterIndexesSV1 = []func(t *testing.T){ testV1FIdxThirdComputeThresholdsIndexes, testV1FIdxRemoveThresholdProfile, - // testV1FIdxSetStatQueueProfileIndexes, - // testV1FIdxComputeStatQueueProfileIndexes, - // testV1FIdxSetSecondStatQueueProfileIndexes, - // testV1FIdxSecondComputeStatQueueProfileIndexes, - // testV1FIdxRemoveStatQueueProfile, + testV1FIdxSetStatQueueProfileIndexes, + testV1FIdxComputeStatQueueProfileIndexes, + testV1FIdxSetSecondStatQueueProfileIndexes, + testV1FIdxSecondComputeStatQueueProfileIndexes, + testV1FIdxRemoveStatQueueProfile, testV1FIdxSetResourceProfileIndexes, testV1FIdxComputeResourceProfileIndexes, diff --git a/apier/v1/filterindexecache_it_test.go b/apier/v1/filterindexecache_it_test.go index c057ca93e..cf95b5420 100644 --- a/apier/v1/filterindexecache_it_test.go +++ b/apier/v1/filterindexecache_it_test.go @@ -51,14 +51,14 @@ var sTestsFilterIndexesSV1Ca = []func(t *testing.T){ testV1FIdxCaUpdateThresholdProfileFromTP, testV1FIdxCaRemoveThresholdProfile, - // testFlush, - // testV1FIdxCaGetStatQueuesWithNotFound, - // testV1FIdxCaSetStatQueueProfile, - // testV1FIdxCaFromFolder, - // testV1FIdxCaGetStatQueuesFromTP, - // testV1FIdxCaUpdateStatQueueProfile, - // testV1FIdxCaUpdateStatQueueProfileFromTP, - // testV1FIdxCaRemoveStatQueueProfile, + testFlush, + testV1FIdxCaGetStatQueuesWithNotFound, + testV1FIdxCaSetStatQueueProfile, + testV1FIdxCaFromFolder, + testV1FIdxCaGetStatQueuesFromTP, + testV1FIdxCaUpdateStatQueueProfile, + testV1FIdxCaUpdateStatQueueProfileFromTP, + testV1FIdxCaRemoveStatQueueProfile, testFlush, testV1FIdxCaProcessAttributeProfileEventWithNotFound, diff --git a/apier/v1/sessionsv1_it_test.go b/apier/v1/sessionsv1_it_test.go index fdfc83172..13481806e 100644 --- a/apier/v1/sessionsv1_it_test.go +++ b/apier/v1/sessionsv1_it_test.go @@ -190,6 +190,7 @@ func TestSSv1ItAuth(t *testing.T) { ID: "TestSSv1ItAuth", Context: utils.StringPointer(utils.MetaSessionS), Event: map[string]interface{}{ + utils.CGRID: "5668666d6b8e44eb949042f25ce0796ec3592ff9", utils.Tenant: "cgrates.org", utils.Category: "call", utils.ToR: utils.VOICE, @@ -295,6 +296,7 @@ func TestSSv1ItInitiateSession(t *testing.T) { ID: "TestSSv1ItInitiateSession", Context: utils.StringPointer(utils.MetaSessionS), Event: map[string]interface{}{ + utils.CGRID: "5668666d6b8e44eb949042f25ce0796ec3592ff9", utils.Tenant: "cgrates.org", utils.Category: "call", utils.ToR: utils.VOICE, @@ -391,6 +393,7 @@ func TestSSv1ItUpdateSession(t *testing.T) { ID: "TestSSv1ItUpdateSession", Context: utils.StringPointer(utils.MetaSessionS), Event: map[string]interface{}{ + utils.CGRID: "5668666d6b8e44eb949042f25ce0796ec3592ff9", utils.Tenant: "cgrates.org", utils.Category: "call", utils.ToR: utils.VOICE, @@ -514,6 +517,7 @@ func TestSSv1ItProcessEvent(t *testing.T) { ID: "TestSSv1ItProcessEvent", Context: utils.StringPointer(utils.MetaSessionS), Event: map[string]interface{}{ + utils.CGRID: "c87609aa1cb6e9529ab1836cfeeeb0ab7aa7ebaf", utils.Tenant: "cgrates.org", utils.Category: "call", utils.ToR: utils.VOICE, diff --git a/config/config_defaults.go b/config/config_defaults.go index 092cd8395..1940abb93 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -135,17 +135,11 @@ const CGRATES_CFG_JSON = ` "attribute_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control attribute profile caching "charger_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control charger profile caching "resource_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control resource filter indexes caching - "resource_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control resource filter reverse indexes caching "stat_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control stat filter indexes caching - "stat_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control stat filter reverse indexes caching "threshold_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control threshold filter indexes caching - "threshold_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control threshold filter reverse indexes caching "supplier_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control supplier filter indexes caching - "supplier_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control supplier filter reverse indexes caching "attribute_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control attribute filter indexes caching - "attribute_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control attribute filter reverse indexes caching "charger_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control charger filter indexes caching - "charger_filter_revindexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control charger filter reverse indexes caching }, diff --git a/config/config_json_test.go b/config/config_json_test.go index b16435389..493c0fbea 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -149,28 +149,16 @@ func TestCacheJsonCfg(t *testing.T) { Precache: utils.BoolPointer(false)}, utils.CacheResourceFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, - utils.CacheResourceFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, utils.CacheStatFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, - utils.CacheStatFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, utils.CacheThresholdFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, - utils.CacheThresholdFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, utils.CacheSupplierFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, - utils.CacheSupplierFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, utils.CacheAttributeFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, - utils.CacheAttributeFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, utils.CacheChargerFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, - utils.CacheChargerFilterRevIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, } if gCfg, err := dfCgrJsonCfg.CacheJsonCfg(); err != nil { diff --git a/config/config_test.go b/config/config_test.go index 4e28be270..76cd395cd 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -684,28 +684,16 @@ func TestCgrCfgJSONDefaultsCacheCFG(t *testing.T) { TTL: time.Duration(0), StaticTTL: false, Precache: false}, utils.CacheResourceFilterIndexes: &CacheParamConfig{Limit: -1, TTL: time.Duration(0), StaticTTL: false, Precache: false}, - utils.CacheResourceFilterRevIndexes: &CacheParamConfig{Limit: -1, - TTL: time.Duration(0), StaticTTL: false, Precache: false}, utils.CacheStatFilterIndexes: &CacheParamConfig{Limit: -1, TTL: time.Duration(0), StaticTTL: false, Precache: false}, - utils.CacheStatFilterRevIndexes: &CacheParamConfig{Limit: -1, - TTL: time.Duration(0), StaticTTL: false, Precache: false}, utils.CacheThresholdFilterIndexes: &CacheParamConfig{Limit: -1, TTL: time.Duration(0), StaticTTL: false, Precache: false}, - utils.CacheThresholdFilterRevIndexes: &CacheParamConfig{Limit: -1, - TTL: time.Duration(0), StaticTTL: false, Precache: false}, utils.CacheSupplierFilterIndexes: &CacheParamConfig{Limit: -1, TTL: time.Duration(0), StaticTTL: false, Precache: false}, - utils.CacheSupplierFilterRevIndexes: &CacheParamConfig{Limit: -1, - TTL: time.Duration(0), StaticTTL: false, Precache: false}, utils.CacheAttributeFilterIndexes: &CacheParamConfig{Limit: -1, TTL: time.Duration(0), StaticTTL: false, Precache: false}, - utils.CacheAttributeFilterRevIndexes: &CacheParamConfig{Limit: -1, - TTL: time.Duration(0), StaticTTL: false, Precache: false}, utils.CacheChargerFilterIndexes: &CacheParamConfig{Limit: -1, TTL: time.Duration(0), StaticTTL: false, Precache: false}, - utils.CacheChargerFilterRevIndexes: &CacheParamConfig{Limit: -1, - TTL: time.Duration(0), StaticTTL: false, Precache: false}, } if !reflect.DeepEqual(eCacheCfg, cgrCfg.CacheCfg()) { diff --git a/data/conf/samples/mongoatlas/cgrates.json b/data/conf/samples/mongoatlas/cgrates.json index 48d5ebfcf..d3898c750 100755 --- a/data/conf/samples/mongoatlas/cgrates.json +++ b/data/conf/samples/mongoatlas/cgrates.json @@ -60,15 +60,11 @@ "supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "resource_filter_indexes" :{"limit": 10000, "ttl":"0s"}, - "resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "stat_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"}, "attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, + "charger_filter_indexes" : {"limit": 10000, "ttl":"0s"}, }, diff --git a/data/conf/samples/mongoreplica/cgrates.json b/data/conf/samples/mongoreplica/cgrates.json index d36703179..70774fdc4 100755 --- a/data/conf/samples/mongoreplica/cgrates.json +++ b/data/conf/samples/mongoreplica/cgrates.json @@ -61,15 +61,11 @@ "supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "resource_filter_indexes" :{"limit": 10000, "ttl":"0s"}, - "resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "stat_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"}, "attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, + "charger_filter_indexes" : {"limit": 10000, "ttl":"0s"}, }, diff --git a/data/conf/samples/tutmongo/cgrates.json b/data/conf/samples/tutmongo/cgrates.json index c764754a9..5a7ad36c5 100644 --- a/data/conf/samples/tutmongo/cgrates.json +++ b/data/conf/samples/tutmongo/cgrates.json @@ -54,15 +54,11 @@ "supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "resource_filter_indexes" :{"limit": 10000, "ttl":"0s"}, - "resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "stat_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"}, "attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, + "charger_filter_indexes" : {"limit": 10000, "ttl":"0s"}, }, diff --git a/data/conf/samples/tutmongojson/cgrates.json b/data/conf/samples/tutmongojson/cgrates.json index c771a05e9..b8aab7d1d 100644 --- a/data/conf/samples/tutmongojson/cgrates.json +++ b/data/conf/samples/tutmongojson/cgrates.json @@ -54,15 +54,11 @@ "supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "resource_filter_indexes" :{"limit": 10000, "ttl":"0s"}, - "resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "stat_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"}, "attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, + "charger_filter_indexes" : {"limit": 10000, "ttl":"0s"}, }, diff --git a/data/conf/samples/tutmysql/cgrates.json b/data/conf/samples/tutmysql/cgrates.json index 0922f5a05..8273f91a3 100644 --- a/data/conf/samples/tutmysql/cgrates.json +++ b/data/conf/samples/tutmysql/cgrates.json @@ -51,15 +51,11 @@ "supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "resource_filter_indexes" :{"limit": 10000, "ttl":"0s"}, - "resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "stat_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"}, "attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, + "charger_filter_indexes" : {"limit": 10000, "ttl":"0s"}, }, diff --git a/data/conf/samples/tutmysqljson/cgrates.json b/data/conf/samples/tutmysqljson/cgrates.json index d97fd819d..ef14b663b 100644 --- a/data/conf/samples/tutmysqljson/cgrates.json +++ b/data/conf/samples/tutmysqljson/cgrates.json @@ -52,15 +52,11 @@ "supplier_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "attribute_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, "resource_filter_indexes" :{"limit": 10000, "ttl":"0s"}, - "resource_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "stat_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "stat_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "threshold_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "threshold_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, "supplier_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "supplier_filter_revindexes" :{"limit": 10000, "ttl":"0s"}, "attribute_filter_indexes" : {"limit": 10000, "ttl":"0s"}, - "attribute_filter_revindexes" : {"limit": 10000, "ttl":"0s"}, + "charger_filter_indexes" : {"limit": 10000, "ttl":"0s"}, }, diff --git a/engine/datamanager.go b/engine/datamanager.go index 0073a356a..808985b51 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -527,7 +527,7 @@ func (dm *DataManager) SetStatQueueProfile(sqp *StatQueueProfile, withIndex bool func (dm *DataManager) RemoveStatQueueProfile(tenant, id, transactionID string, withIndex bool) (err error) { - oldSts, err := dm.GetResourceProfile(tenant, id, true, utils.NonTransactional) + oldSts, err := dm.GetStatQueueProfile(tenant, id, true, utils.NonTransactional) if err != nil && err != utils.ErrNotFound { return err } diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 728619fb0..309482192 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -2113,111 +2113,6 @@ func (ms *MongoStorage) RemoveFilterIndexesDrv(cacheID, itemIDPrefix string) (er return } -// GetFilterReverseIndexesDrv retrieves ReverseIndexes from dataDB -func (ms *MongoStorage) GetFilterReverseIndexesDrv(cacheID, itemIDPrefix string, - fldNameVal map[string]string) (revIdx map[string]utils.StringMap, err error) { - session, col := ms.conn(colRFI) - defer session.Close() - dbKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix - var result struct { - Key string - Value map[string][]string - } - findParam := bson.M{"key": dbKey} - if len(fldNameVal) != 0 { - for fldName, _ := range fldNameVal { - qryFltr := fmt.Sprintf("value.%s", fldName) - if err = col.Find(bson.M{"key": dbKey, qryFltr: bson.M{"$exists": true}}).Select( - bson.M{qryFltr: true}).One(&result); err != nil { - if err == mgo.ErrNotFound { - return nil, utils.ErrNotFound - } - } - } - } else { - if err = col.Find(findParam).One(&result); err != nil { - if err == mgo.ErrNotFound || len(result.Value) == 0 { - return nil, utils.ErrNotFound - } - } - } - revIdx = make(map[string]utils.StringMap) - for key, itmSls := range result.Value { - if _, hasIt := revIdx[key]; !hasIt { - revIdx[key] = make(utils.StringMap) - } - revIdx[key] = utils.StringMapFromSlice(itmSls) - } - if len(revIdx) == 0 { - return nil, utils.ErrNotFound - } - return revIdx, nil -} - -//SetFilterReverseIndexesDrv stores ReverseIndexes into DataDB -func (ms *MongoStorage) SetFilterReverseIndexesDrv(cacheID, itemIDPrefix string, - revIdx map[string]utils.StringMap, commit bool, transactionID string) (err error) { - session, col := ms.conn(colRFI) - defer session.Close() - originKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix - dbKey := originKey - if transactionID != "" { - dbKey = "tmp_" + utils.ConcatenatedKey(dbKey, transactionID) - } - if commit && transactionID != "" { - oldKey := "tmp_" + utils.ConcatenatedKey(originKey, transactionID) - err = col.Remove(bson.M{"key": originKey}) - if err != nil && err != mgo.ErrNotFound { - return - } - pairs := []interface{}{} - for key, itmMp := range revIdx { - param := fmt.Sprintf("value.%s", key) - pairs = append(pairs, bson.M{"key": originKey}) - pairs = append(pairs, bson.M{"$set": bson.M{"key": originKey, - param: itmMp.Slice()}}) - } - if len(pairs) != 0 { - bulk := col.Bulk() - bulk.Unordered() - bulk.Upsert(pairs...) - _, err = bulk.Run() - } - return col.Remove(bson.M{"key": oldKey}) - } else { - pairs := []interface{}{} - for key, itmMp := range revIdx { - param := fmt.Sprintf("value.%s", key) - pairs = append(pairs, bson.M{"key": dbKey}) - if len(itmMp) == 0 { - pairs = append(pairs, bson.M{"$unset": bson.M{param: 1}}) - } else { - pairs = append(pairs, bson.M{"$set": bson.M{"key": dbKey, - param: itmMp.Slice()}}) - } - } - if len(pairs) != 0 { - bulk := col.Bulk() - bulk.Unordered() - bulk.Upsert(pairs...) - _, err = bulk.Run() - } - } - return -} - -//RemoveFilterReverseIndexesDrv removes ReverseIndexes for a specific itemID -func (ms *MongoStorage) RemoveFilterReverseIndexesDrv(cacheID, itemIDPrefix string) (err error) { - session, col := ms.conn(colRFI) - defer session.Close() - err = col.Remove(bson.M{"key": utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix}) - //redis compatibility - if err == mgo.ErrNotFound { - err = nil - } - return -} - func (ms *MongoStorage) MatchFilterIndexDrv(cacheID, itemIDPrefix, filterType, fldName, fldVal string) (itemIDs utils.StringMap, err error) { session, col := ms.conn(colRFI) diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 19e9d111c..050568fa1 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -1448,86 +1448,6 @@ func (rs *RedisStorage) RemoveFilterIndexesDrv(cacheID, itemIDPrefix string) (er return rs.Cmd("DEL", utils.CacheInstanceToPrefix[cacheID]+itemIDPrefix).Err } -//GetFilterReverseIndexesDrv retrieves ReverseIndexes from dataDB -func (rs *RedisStorage) GetFilterReverseIndexesDrv(cacheID, itemIDPrefix string, - fldNameVal map[string]string) (indexes map[string]utils.StringMap, err error) { - mp := make(map[string]string) - dbKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix - if len(fldNameVal) == 0 { - mp, err = rs.Cmd("HGETALL", dbKey).Map() - if err != nil { - return - } else if len(mp) == 0 { - return nil, utils.ErrNotFound - } - } else { - var itmMpStrLst []string - for fldName, _ := range fldNameVal { - itmMpStrLst, err = rs.Cmd("HMGET", dbKey, fldName).List() - if err != nil { - return - } else if itmMpStrLst[0] == "" { - return nil, utils.ErrNotFound - } - mp[fldName] = itmMpStrLst[0] - } - } - indexes = make(map[string]utils.StringMap) - for k, v := range mp { - var sm utils.StringMap - if err = rs.ms.Unmarshal([]byte(v), &sm); err != nil { - return - } - if _, hasKey := indexes[k]; !hasKey { - indexes[k] = make(utils.StringMap) - } - indexes[k] = sm - } - return -} - -//SetFilterReverseIndexesDrv stores ReverseIndexes into DataDB -func (rs *RedisStorage) SetFilterReverseIndexesDrv(cacheID, itemIDPrefix string, - revIdx map[string]utils.StringMap, commit bool, transactionID string) (err error) { - originKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix - dbKey := originKey - if transactionID != "" { - dbKey = "tmp_" + utils.ConcatenatedKey(dbKey, transactionID) - } - if commit && transactionID != "" { - return rs.Cmd("RENAME", dbKey, originKey).Err - } else { - mp := make(map[string]string) - nameValSls := []interface{}{dbKey} - for key, strMp := range revIdx { - if len(strMp) == 0 { // remove with no more elements inside - nameValSls = append(nameValSls, key) - continue - } - if encodedMp, err := rs.ms.Marshal(strMp); err != nil { - return err - } else { - mp[key] = string(encodedMp) - } - } - if len(nameValSls) != 1 { - if err = rs.Cmd("HDEL", nameValSls...).Err; err != nil { - return err - } - } - if len(mp) != 0 { - return rs.Cmd("HMSET", dbKey, mp).Err - } - return - } -} - -//RemoveFilterReverseIndexesDrv removes ReverseIndexes for a specific itemID -func (rs *RedisStorage) RemoveFilterReverseIndexesDrv(cacheID, - itemIDPrefix string) (err error) { - return rs.Cmd("DEL", utils.CacheInstanceToPrefix[cacheID]+itemIDPrefix).Err -} - func (rs *RedisStorage) MatchFilterIndexDrv(cacheID, itemIDPrefix, filterType, fldName, fldVal string) (itemIDs utils.StringMap, err error) { fieldValKey := utils.ConcatenatedKey(filterType, fldName, fldVal)