From bbd3436440e41fff97015f5d237f754c1d76fc7d Mon Sep 17 00:00:00 2001 From: DanB Date: Fri, 2 Mar 2018 19:22:11 +0100 Subject: [PATCH] DataManager.SetFilterIndexes with cacheID and itemIDPrefix --- engine/datamanager.go | 5 +++-- engine/filterindexer.go | 6 +++--- engine/storage_interface.go | 4 ++-- engine/storage_map.go | 9 +++++---- engine/storage_mongo_datadb.go | 9 +++++---- engine/storage_redis.go | 5 +++-- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/engine/datamanager.go b/engine/datamanager.go index 0c1c84873..fb64af4a5 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -1112,8 +1112,9 @@ func (dm *DataManager) GetFilterIndexes(cacheID, itemIDPrefix, filterType string return dm.DataDB().GetFilterIndexesDrv(cacheID, itemIDPrefix, filterType, fldNameVal) } -func (dm *DataManager) SetFilterIndexes(dbKey string, indexes map[string]utils.StringMap, commit bool, transactionID string) (err error) { - return dm.DataDB().SetFilterIndexesDrv(dbKey, indexes, commit, transactionID) +func (dm *DataManager) SetFilterIndexes(cacheID, itemIDPrefix string, + indexes map[string]utils.StringMap, commit bool, transactionID string) (err error) { + return dm.DataDB().SetFilterIndexesDrv(cacheID, itemIDPrefix, indexes, commit, transactionID) } func (dm *DataManager) RemoveFilterIndexes(dbKey string) (err error) { diff --git a/engine/filterindexer.go b/engine/filterindexer.go index 72f6225be..75b31e11a 100644 --- a/engine/filterindexer.go +++ b/engine/filterindexer.go @@ -126,8 +126,8 @@ func (rfi *FilterIndexer) cacheRemItemType() { // ToDo: tune here by removing pe // StoreIndexes handles storing the indexes to dataDB func (rfi *FilterIndexer) StoreIndexes(commit bool, transactionID string) (err error) { if err = rfi.dm.SetFilterIndexes( - GetDBIndexKey(rfi.itemType, rfi.dbKeySuffix, false), - rfi.indexes, commit, transactionID); err != nil { + utils.PrefixToIndexCache[rfi.itemType], rfi.dbKeySuffix, + rfi.indexes, commit, utils.NonTransactional); err != nil { return } if err = rfi.dm.SetFilterReverseIndexes( @@ -196,7 +196,7 @@ func (rfi *FilterIndexer) RemoveItemFromIndex(itemID string) (err error) { } rfi.reveseIndex[itemID] = make(utils.StringMap) //Force deleting in driver if err = rfi.dm.SetFilterIndexes( - GetDBIndexKey(rfi.itemType, rfi.dbKeySuffix, false), + utils.PrefixToIndexCache[rfi.itemType], rfi.dbKeySuffix, rfi.indexes, false, utils.NonTransactional); err != nil { return } diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 0c79f5c3c..230e6a370 100755 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -120,8 +120,8 @@ type DataDB interface { AddLoadHistory(*utils.LoadInstance, int, string) error GetFilterIndexesDrv(cacheID, itemIDPrefix, filterType string, fldNameVal map[string]string) (indexes map[string]utils.StringMap, err error) - SetFilterIndexesDrv(dbKey string, indexes map[string]utils.StringMap, - commit bool, transactionID string) (err error) + SetFilterIndexesDrv(cacheID, itemIDPrefix string, + indexes map[string]utils.StringMap, commit bool, transactionID string) (err error) RemoveFilterIndexesDrv(id string) (err error) GetFilterReverseIndexesDrv(dbKey string, fldNameVal map[string]string) (indexes map[string]utils.StringMap, err error) diff --git a/engine/storage_map.go b/engine/storage_map.go index bf9047381..76e654657 100755 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -1267,12 +1267,13 @@ func (ms *MapStorage) GetFilterIndexesDrv(cacheID, itemIDPrefix, filterType stri } //SetFilterIndexesDrv stores Indexes into DataDB -func (ms *MapStorage) SetFilterIndexesDrv(originKey string, indexes map[string]utils.StringMap, commit bool, transactionID string) (err error) { +func (ms *MapStorage) SetFilterIndexesDrv(cacheID, itemIDPrefix string, + indexes map[string]utils.StringMap, commit bool, transactionID string) (err error) { ms.mu.Lock() defer ms.mu.Unlock() - dbKey := originKey + dbKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix if transactionID != "" { - dbKey = "tmp_" + utils.ConcatenatedKey(originKey, transactionID) + dbKey = "tmp_" + utils.ConcatenatedKey(dbKey, transactionID) } if commit && transactionID != "" { delete(ms.dict, dbKey) @@ -1280,7 +1281,7 @@ func (ms *MapStorage) SetFilterIndexesDrv(originKey string, indexes map[string]u if err != nil { return err } - ms.dict[originKey] = result + ms.dict[dbKey] = result return nil } else { for key, strMp := range indexes { diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 88ed07cd5..feb0b163a 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -1976,13 +1976,14 @@ func (ms *MongoStorage) GetFilterIndexesDrv(cacheID, itemIDPrefix, filterType st } // SetFilterIndexesDrv stores Indexes into DataDB -func (ms *MongoStorage) SetFilterIndexesDrv(originKey string, +func (ms *MongoStorage) SetFilterIndexesDrv(cacheID, itemIDPrefix string, indexes 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(originKey, transactionID) + dbKey = "tmp_" + utils.ConcatenatedKey(dbKey, transactionID) } if commit && transactionID != "" { oldKey := "tmp_" + utils.ConcatenatedKey(originKey, transactionID) @@ -1993,8 +1994,8 @@ func (ms *MongoStorage) SetFilterIndexesDrv(originKey string, pairs := []interface{}{} for key, itmMp := range indexes { 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()}}) + pairs = append(pairs, bson.M{"key": dbKey}) + pairs = append(pairs, bson.M{"$set": bson.M{"key": dbKey, param: itmMp.Slice()}}) } if len(pairs) != 0 { bulk := col.Bulk() diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 340ef33c5..62baec6c4 100755 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -1408,8 +1408,9 @@ func (rs *RedisStorage) GetFilterIndexesDrv(cacheID, itemIDPrefix, filterType st } //SetFilterIndexesDrv stores Indexes into DataDB -func (rs *RedisStorage) SetFilterIndexesDrv(originKey string, indexes map[string]utils.StringMap, commit bool, transactionID string) (err error) { - dbKey := originKey +func (rs *RedisStorage) SetFilterIndexesDrv(cacheID, itemIDPrefix string, + indexes map[string]utils.StringMap, commit bool, transactionID string) (err error) { + dbKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix if transactionID != "" { dbKey = "tmp_" + utils.ConcatenatedKey(dbKey, transactionID) }