mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Clarify cacheRead/cacheWrite for threshold
This commit is contained in:
committed by
Dan Christian Bogos
parent
cb3e76e6c2
commit
2425734dcd
@@ -232,7 +232,7 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b
|
||||
_, err = dm.GetThresholdProfile(tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
|
||||
case utils.ThresholdPrefix:
|
||||
tntID := utils.NewTenantID(dataID)
|
||||
_, err = dm.GetThreshold(tntID.Tenant, tntID.ID, true, utils.NonTransactional)
|
||||
_, err = dm.GetThreshold(tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
|
||||
case utils.FilterPrefix:
|
||||
tntID := utils.NewTenantID(dataID)
|
||||
_, err = dm.GetFilter(tntID.Tenant, tntID.ID, true, utils.NonTransactional)
|
||||
@@ -353,9 +353,9 @@ func (dm *DataManager) RemoveFilter(tenant, id, transactionID string) (err error
|
||||
}
|
||||
|
||||
func (dm *DataManager) GetThreshold(tenant, id string,
|
||||
skipCache bool, transactionID string) (th *Threshold, err error) {
|
||||
cacheRead, cacheWrite bool, transactionID string) (th *Threshold, err error) {
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if !skipCache {
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheThresholds, tntID); ok {
|
||||
if x == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
@@ -365,14 +365,16 @@ func (dm *DataManager) GetThreshold(tenant, id string,
|
||||
}
|
||||
th, err = dm.dataDB.GetThresholdDrv(tenant, id)
|
||||
if err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
Cache.Set(utils.CacheThresholds, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
Cache.Set(utils.CacheThresholds, tntID, th, nil,
|
||||
cacheCommit(transactionID), transactionID)
|
||||
if cacheWrite {
|
||||
Cache.Set(utils.CacheThresholds, tntID, th, nil,
|
||||
cacheCommit(transactionID), transactionID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -2202,7 +2202,7 @@ func testOnStorITThreshold(t *testing.T) {
|
||||
Hits: 10,
|
||||
}
|
||||
if _, rcvErr := onStor.GetThreshold("cgrates.org", "TH1",
|
||||
false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
|
||||
true, false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
if err := onStor.SetThreshold(th); err != nil {
|
||||
@@ -2210,14 +2210,14 @@ func testOnStorITThreshold(t *testing.T) {
|
||||
}
|
||||
//get from cache
|
||||
if rcv, err := onStor.GetThreshold("cgrates.org", "TH1",
|
||||
false, utils.NonTransactional); err != nil {
|
||||
true, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(th, rcv)) {
|
||||
t.Errorf("Expecting: %v, received: %v", th, rcv)
|
||||
}
|
||||
//get from database
|
||||
if rcv, err := onStor.GetThreshold("cgrates.org", "TH1",
|
||||
true, utils.NonTransactional); err != nil {
|
||||
false, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(th, rcv)) {
|
||||
t.Errorf("Expecting: %v, received: %v", th, rcv)
|
||||
@@ -2236,14 +2236,14 @@ func testOnStorITThreshold(t *testing.T) {
|
||||
time.Sleep(sleepDelay)
|
||||
//get from cache
|
||||
if rcv, err := onStor.GetThreshold("cgrates.org", "TH1",
|
||||
false, utils.NonTransactional); err != nil {
|
||||
true, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(th, rcv)) {
|
||||
t.Errorf("Expecting: %v, received: %v", th, rcv)
|
||||
}
|
||||
//get from database
|
||||
if rcv, err := onStor.GetThreshold("cgrates.org", "TH1",
|
||||
true, utils.NonTransactional); err != nil {
|
||||
false, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(th, rcv)) {
|
||||
t.Errorf("Expecting: %v, received: %v", th, rcv)
|
||||
@@ -2253,12 +2253,12 @@ func testOnStorITThreshold(t *testing.T) {
|
||||
}
|
||||
//check cache if removed
|
||||
if _, rcvErr := onStor.GetThreshold(th.Tenant, th.ID,
|
||||
false, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
true, false, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
//check database if removed
|
||||
if _, rcvErr := onStor.GetThreshold(th.Tenant, th.ID,
|
||||
true, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
false, false, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ func (tS *ThresholdService) matchingThresholdsForEvent(args *ArgsProcessEvent) (
|
||||
} else if !pass {
|
||||
continue
|
||||
}
|
||||
t, err := tS.dm.GetThreshold(tPrfl.Tenant, tPrfl.ID, false, "")
|
||||
t, err := tS.dm.GetThreshold(tPrfl.Tenant, tPrfl.ID, true, true, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -375,7 +375,7 @@ func (tS *ThresholdService) V1GetThresholdIDs(tenant string, tIDs *[]string) (er
|
||||
|
||||
// V1GetThreshold retrieves a Threshold
|
||||
func (tS *ThresholdService) V1GetThreshold(tntID *utils.TenantID, t *Threshold) (err error) {
|
||||
if thd, err := tS.dm.GetThreshold(tntID.Tenant, tntID.ID, false, ""); err != nil {
|
||||
if thd, err := tS.dm.GetThreshold(tntID.Tenant, tntID.ID, true, true, ""); err != nil {
|
||||
return err
|
||||
} else {
|
||||
*t = *thd
|
||||
|
||||
@@ -228,7 +228,7 @@ func TestThresholdsCache(t *testing.T) {
|
||||
//Test each threshold profile from cache
|
||||
for _, th := range ths {
|
||||
if temptTh, err := dmTH.GetThreshold(th.Tenant,
|
||||
th.ID, false, utils.NonTransactional); err != nil {
|
||||
th.ID, true, false, utils.NonTransactional); err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else if !reflect.DeepEqual(th, temptTh) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", th, temptTh)
|
||||
|
||||
@@ -57,7 +57,7 @@ func (m *Migrator) migrateCurrentThresholds() (err error) {
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.ThresholdPrefix+tenant+":")
|
||||
ths, err := m.dmIN.DataManager().GetThreshold(tenant, idg, true, utils.NonTransactional)
|
||||
ths, err := m.dmIN.DataManager().GetThreshold(tenant, idg, false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user