mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-19 22:28:45 +05:00
LoadIDs use time.UnixNanoseconds instead of GenUUID
This commit is contained in:
committed by
Dan Christian Bogos
parent
01857c4d8a
commit
93cb87bece
@@ -470,8 +470,8 @@ func (chS *CacheS) V1FlushCache(args utils.AttrReloadCache, reply *string) (err
|
||||
}
|
||||
|
||||
//populateCacheLoadIDs populate cacheLoadIDs based on attrs
|
||||
func populateCacheLoadIDs(loadIDs map[string]string, attrs utils.AttrReloadCache) (cacheLoadIDs map[string]string) {
|
||||
cacheLoadIDs = make(map[string]string)
|
||||
func populateCacheLoadIDs(loadIDs map[string]int64, attrs utils.AttrReloadCache) (cacheLoadIDs map[string]int64) {
|
||||
cacheLoadIDs = make(map[string]int64)
|
||||
//based on IDs of each type populate cacheLoadIDs and add into cache
|
||||
if attrs.DestinationIDs == nil || len(*attrs.DestinationIDs) != 0 {
|
||||
cacheLoadIDs[utils.CacheDestinations] = loadIDs[utils.CacheDestinations]
|
||||
|
||||
@@ -1363,7 +1363,7 @@ func (dm *DataManager) RemoveDispatcherHost(tenant, id string,
|
||||
return
|
||||
}
|
||||
|
||||
func (dm *DataManager) GetItemLoadIDs(itemIDPrefix string, cacheWrite bool) (loadIDs map[string]string, err error) {
|
||||
func (dm *DataManager) GetItemLoadIDs(itemIDPrefix string, cacheWrite bool) (loadIDs map[string]int64, err error) {
|
||||
loadIDs, err = dm.DataDB().GetItemLoadIDsDrv(itemIDPrefix)
|
||||
if err != nil {
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
@@ -1383,6 +1383,6 @@ func (dm *DataManager) GetItemLoadIDs(itemIDPrefix string, cacheWrite bool) (loa
|
||||
return
|
||||
}
|
||||
|
||||
func (dm *DataManager) SetLoadIDs(loadIDs map[string]string) error {
|
||||
func (dm *DataManager) SetLoadIDs(loadIDs map[string]int64) error {
|
||||
return dm.DataDB().SetLoadIDsDrv(loadIDs)
|
||||
}
|
||||
|
||||
@@ -128,8 +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
|
||||
GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]int64, err error)
|
||||
SetLoadIDsDrv(loadIDs map[string]int64) error
|
||||
GetDispatcherHostDrv(string, string) (*DispatcherHost, error)
|
||||
SetDispatcherHostDrv(*DispatcherHost) error
|
||||
RemoveDispatcherHostDrv(string, string) error
|
||||
|
||||
@@ -1423,7 +1423,7 @@ func (ms *MapStorage) GetStorageType() string {
|
||||
return utils.MAPSTOR
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]string, err error) {
|
||||
func (ms *MapStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]int64, err error) {
|
||||
ms.mu.Lock()
|
||||
defer ms.mu.Unlock()
|
||||
values, ok := ms.dict[utils.LoadIDs]
|
||||
@@ -1435,12 +1435,12 @@ func (ms *MapStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string
|
||||
return nil, err
|
||||
}
|
||||
if itemIDPrefix != "" {
|
||||
return map[string]string{itemIDPrefix: loadIDs[itemIDPrefix]}, nil
|
||||
return map[string]int64{itemIDPrefix: loadIDs[itemIDPrefix]}, nil
|
||||
}
|
||||
return loadIDs, nil
|
||||
}
|
||||
|
||||
func (ms *MapStorage) SetLoadIDsDrv(loadIDs map[string]string) (err error) {
|
||||
func (ms *MapStorage) SetLoadIDsDrv(loadIDs map[string]int64) (err error) {
|
||||
var result []byte
|
||||
result, err = ms.ms.Marshal(loadIDs)
|
||||
if err != nil {
|
||||
|
||||
@@ -2191,7 +2191,7 @@ func (ms *MongoStorage) RemoveDispatcherHostDrv(tenant, id string) (err error) {
|
||||
})
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]string, err error) {
|
||||
func (ms *MongoStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]int64, err error) {
|
||||
fop := options.FindOne()
|
||||
if itemIDPrefix != "" {
|
||||
fop.SetProjection(bson.M{itemIDPrefix: 1, "_id": 0})
|
||||
@@ -2216,7 +2216,7 @@ func (ms *MongoStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[stri
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) SetLoadIDsDrv(loadIDs map[string]string) (err error) {
|
||||
func (ms *MongoStorage) SetLoadIDsDrv(loadIDs map[string]int64) (err error) {
|
||||
return ms.query(func(sctx mongo.SessionContext) (err error) {
|
||||
_, err = ms.getCol(colLID).UpdateOne(sctx, bson.D{}, bson.M{"$set": loadIDs},
|
||||
options.Update().SetUpsert(true),
|
||||
|
||||
@@ -1594,27 +1594,35 @@ func (rs *RedisStorage) GetStorageType() string {
|
||||
return utils.REDIS
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]string, err error) {
|
||||
func (rs *RedisStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]int64, err error) {
|
||||
if itemIDPrefix != "" {
|
||||
fldVal, err := rs.Cmd("HGET", utils.LoadIDs, itemIDPrefix).Str()
|
||||
fldVal, err := rs.Cmd("HGET", utils.LoadIDs, itemIDPrefix).Int64()
|
||||
if err != nil {
|
||||
if err == redis.ErrRespNil {
|
||||
err = utils.ErrNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return map[string]string{itemIDPrefix: fldVal}, nil
|
||||
return map[string]int64{itemIDPrefix: fldVal}, nil
|
||||
}
|
||||
loadIDs, err = rs.Cmd("HGETALL", utils.LoadIDs).Map()
|
||||
mpLoadIDs, err := rs.Cmd("HGETALL", utils.LoadIDs).Map()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
loadIDs = make(map[string]int64)
|
||||
for key, val := range mpLoadIDs {
|
||||
intVal, err := strconv.ParseInt(val, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
loadIDs[key] = intVal
|
||||
}
|
||||
if len(loadIDs) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) SetLoadIDsDrv(loadIDs map[string]string) error {
|
||||
func (rs *RedisStorage) SetLoadIDsDrv(loadIDs map[string]int64) error {
|
||||
return rs.Cmd("HMSET", utils.LoadIDs, loadIDs).Err
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/structmatcher"
|
||||
@@ -1413,8 +1414,8 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose, disable_reverse bool) (err
|
||||
// }
|
||||
}
|
||||
//generate a loadID
|
||||
loadID := utils.UUIDSha1Prefix()
|
||||
loadIDs := make(map[string]string)
|
||||
loadID := time.Now().UnixNano()
|
||||
loadIDs := make(map[string]int64)
|
||||
if verbose {
|
||||
log.Print("Destinations:")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user