diff --git a/apier/v1/attributes.go b/apier/v1/attributes.go index d51e50be6..a327d5a6d 100644 --- a/apier/v1/attributes.go +++ b/apier/v1/attributes.go @@ -85,6 +85,9 @@ func (apierV1 *ApierV1) SetAttributeProfile(alsWrp *AttributeWrapper, reply *str if err := apierV1.DataManager.SetAttributeProfile(alsWrp.AttributeProfile, true); err != nil { return utils.APIErrorHandler(err) } + loadId := map[string]string{utils.AttributeProfilePrefix: utils.UUIDSha1Prefix()} + //generez un nou id pentru load_ids + //fac update in datadb args := engine.ArgsGetCacheItem{ CacheID: utils.CacheAttributeProfiles, ItemID: alsWrp.TenantID(), diff --git a/config/config_defaults.go b/config/config_defaults.go index 7a99fdd03..8d6a882c5 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -152,7 +152,8 @@ const CGRATES_CFG_JSON = ` "dispatcher_routes": {"limit": -1, "ttl": "", "static_ttl": false}, // control dispatcher routes caching "diameter_messages": {"limit": -1, "ttl": "3h", "static_ttl": false}, // diameter messages caching "rpc_responses": {"limit": 0, "ttl": "2s", "static_ttl": false}, // RPC responses caching - "closed_sessions": {"limit": -1, "ttl": "10s", "static_ttl": false}, // closed sessions cached for CDRs + "closed_sessions": {"limit": -1, "ttl": "10s", "static_ttl": false}, // closed sessions cached for CDRs + "load_ids": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control the load_ids for items }, diff --git a/engine/caches.go b/engine/caches.go index fc79b4444..fc53e6d71 100644 --- a/engine/caches.go +++ b/engine/caches.go @@ -65,6 +65,7 @@ var precachedPartitions = utils.StringMap{ utils.CacheSupplierFilterIndexes: true, utils.CacheChargerFilterIndexes: true, utils.CacheDispatcherFilterIndexes: true, + utils.CacheLoadIDs: true, } // InitCache will instantiate the cache with specific or default configuraiton diff --git a/engine/storage_interface.go b/engine/storage_interface.go index e1442f247..d220333db 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -128,6 +128,8 @@ type DataDB interface { GetDispatcherProfileDrv(string, string) (*DispatcherProfile, error) SetDispatcherProfileDrv(*DispatcherProfile) error RemoveDispatcherProfileDrv(string, string) error + GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]string, err error) + SetLoadIDsDrv(loadIDs map[string]string) error GetDispatcherHostDrv(string, string) (*DispatcherHost, error) SetDispatcherHostDrv(*DispatcherHost) error RemoveDispatcherHostDrv(string, string) error diff --git a/engine/storage_map_datadb.go b/engine/storage_map_datadb.go index 606145b88..1409ae762 100644 --- a/engine/storage_map_datadb.go +++ b/engine/storage_map_datadb.go @@ -1422,3 +1422,32 @@ func (ms *MapStorage) RemoveVersions(vrs Versions) (err error) { func (ms *MapStorage) GetStorageType() string { return utils.MAPSTOR } + +func (ms *MapStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]string, err error) { + ms.mu.Lock() + defer ms.mu.Unlock() + values, ok := ms.dict[utils.LoadIDs] + if !ok { + return nil, utils.ErrNotFound + } + err = ms.ms.Unmarshal(values, &loadIDs) + if err != nil { + return nil, err + } + if itemIDPrefix != "" { + return map[string]string{itemIDPrefix: loadIDs[itemIDPrefix]}, nil + } + return loadIDs, nil +} + +func (ms *MapStorage) SetLoadIDsDrv(loadIDs map[string]string) (err error) { + var result []byte + result, err = ms.ms.Marshal(loadIDs) + if err != nil { + return err + } + ms.mu.Lock() + ms.dict[utils.LoadIDs] = result + ms.mu.Unlock() + return +} diff --git a/engine/storage_redis.go b/engine/storage_redis.go index e5ad5423f..1046d8b00 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -1593,3 +1593,28 @@ func (rs *RedisStorage) RemoveDispatcherHostDrv(tenant, id string) (err error) { func (rs *RedisStorage) GetStorageType() string { return utils.REDIS } + +func (rs *RedisStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]string, err error) { + if itemIDPrefix != "" { + fldVal, err := rs.Cmd("HGET", utils.LoadIDs, itemIDPrefix).Str() + if err != nil { + if err == redis.ErrRespNil { + err = utils.ErrNotFound + } + return nil, err + } + return map[string]string{itemIDPrefix: fldVal}, nil + } + loadIDs, err = rs.Cmd("HGETALL", utils.LoadIDs).Map() + if err != nil { + return nil, err + } + if len(loadIDs) == 0 { + return nil, utils.ErrNotFound + } + return +} + +func (rs *RedisStorage) SetLoadIDsDrv(loadIDs map[string]string) error { + return rs.Cmd("HMSET", utils.LoadIDs, loadIDs).Err +} diff --git a/utils/consts.go b/utils/consts.go index 9b82e1776..3f4919a40 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -559,6 +559,7 @@ const ( MetaLoad = "*load" MetaRemove = "*remove" MetaClear = "*clear" + LoadIDs = "load_ids" ) // Migrator Action @@ -979,6 +980,7 @@ const ( CacheClosedSessions = "closed_sessions" MetaPrecaching = "*precaching" MetaReady = "*ready" + CacheLoadIDs = "load_ids" ) // Prefix for indexing