diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 7889d7a26..dbebe3d50 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -24,6 +24,7 @@ import ( "fmt" "io/ioutil" "strings" + "time" "github.com/cgrates/cgrates/cache" "github.com/cgrates/cgrates/config" @@ -112,7 +113,7 @@ func NewMongoStorage(host, port, db, user, pass, storageType string, cdrsIndexes return nil, err } } - ms.cnter = utils.NewCounterGen(1000) + ms.cnter = utils.NewCounterGen(time.Now().UnixNano(), 0) return } diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index 3791d60d7..30eb49feb 100644 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -883,7 +883,7 @@ func (ms *MongoStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix stri func (ms *MongoStorage) SetCDR(cdr *CDR, allowUpdate bool) (err error) { if cdr.OrderID == 0 { - cdr.OrderID = time.Now().UnixNano() + ms.cnter.Gen() + cdr.OrderID = ms.cnter.Gen() } session, col := ms.conn(utils.TBL_CDRS) defer session.Close() diff --git a/utils/coreutils.go b/utils/coreutils.go index bdd1d6624..45ac42777 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -40,8 +40,11 @@ import ( "time" ) -func NewCounterGen(limit int64) *CounterGen { - return &CounterGen{limit: limit} +func NewCounterGen(start, limit int64) *CounterGen { + return &CounterGen{ + cnt: start, + limit: limit, + } } type CounterGen struct { @@ -53,7 +56,7 @@ func (cg *CounterGen) Gen() int64 { cg.Lock() defer cg.Unlock() cg.cnt += 1 - if cg.cnt > cg.limit { + if cg.limit > 0 && cg.cnt > cg.limit { cg.cnt = 0 } return cg.cnt