StorageMongo creating indexes based on storDBType

This commit is contained in:
DanB
2016-11-17 13:18:43 +01:00
parent 6e535f11af
commit 443c594edc
3 changed files with 126 additions and 110 deletions

View File

@@ -93,12 +93,13 @@ func (self DiameterAgent) processCCR(ccr *CCR, reqProcessor *config.DARequestPro
}
smgEv, err := ccr.AsSMGenericEvent(reqProcessor.CCRFields)
if err != nil {
utils.Logger.Err(fmt.Sprintf("<DiameterAgent> Processing message: %+v AsSMGenericEvent, error: %s", ccr.diamMessage, err))
*cca = *NewBareCCAFromCCR(ccr, self.cgrCfg.DiameterAgentCfg().OriginHost, self.cgrCfg.DiameterAgentCfg().OriginRealm)
if err := messageSetAVPsWithPath(cca.diamMessage, []interface{}{"Result-Code"}, strconv.Itoa(DiameterRatingFailed),
false, self.cgrCfg.DiameterAgentCfg().Timezone); err != nil {
utils.Logger.Err(fmt.Sprintf("<DiameterAgent> Processing message: %+v messageSetAVPsWithPath, error: %s", cca.diamMessage, err.Error()))
return false, err
}
utils.Logger.Err(fmt.Sprintf("<DiameterAgent> Processing message: %+v AsSMGenericEvent, error: %s", ccr.diamMessage, err))
return false, ErrDiameterRatingFailed
}
if len(reqProcessor.Flags) != 0 {

View File

@@ -124,7 +124,13 @@ func (ms *MongoStorage) EnsureIndexes() (err error) {
Background: false, // Build index in background and return immediately
Sparse: false, // Only index documents containing the Key fields
}
for _, col := range []string{colAct, colApl, colAtr, colDcs, colAls, colRls, colUsr, colLcr, colLht, colRpl, colDst, colRds} {
var colectNames []string // collection names containing this index
if ms.storageType == utils.TariffPlanDB {
colectNames = []string{colAct, colApl, colAtr, colDcs, colRls, colRpl, colLcr, colDst, colRds}
} else if ms.storageType == utils.DataDB {
colectNames = []string{colAls, colUsr, colLht}
}
for _, col := range colectNames {
if err = db.C(col).EnsureIndex(idx); err != nil {
return
}
@@ -136,98 +142,94 @@ func (ms *MongoStorage) EnsureIndexes() (err error) {
Background: false,
Sparse: false,
}
for _, col := range []string{colRpf, colShg, colAcc, colCrs} {
if ms.storageType == utils.TariffPlanDB {
colectNames = []string{colRpf, colShg, colCrs}
} else if ms.storageType == utils.DataDB {
colectNames = []string{colAcc}
}
for _, col := range colectNames {
if err = db.C(col).EnsureIndex(idx); err != nil {
return
}
}
idx = mgo.Index{
Key: []string{"tpid", "tag"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
for _, col := range []string{utils.TBL_TP_TIMINGS, utils.TBL_TP_DESTINATIONS, utils.TBL_TP_DESTINATION_RATES, utils.TBL_TP_RATING_PLANS,
utils.TBL_TP_SHARED_GROUPS, utils.TBL_TP_CDR_STATS, utils.TBL_TP_ACTIONS, utils.TBL_TP_ACTION_PLANS, utils.TBL_TP_ACTION_TRIGGERS} {
if err = db.C(col).EnsureIndex(idx); err != nil {
return
}
}
idx = mgo.Index{
Key: []string{"tpid", "direction", "tenant", "category", "subject", "loadid"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_RATE_PROFILES).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{"tpid", "direction", "tenant", "category", "account", "subject"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_LCRS).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{"tpid", "tenant", "username"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_USERS).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{"tpid", "direction", "tenant", "category", "account", "subject", "context"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_LCRS).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{"tpid", "direction", "tenant", "category", "subject", "account", "loadid"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_DERIVED_CHARGERS).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{"tpid", "direction", "tenant", "account", "loadid"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_DERIVED_CHARGERS).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{CGRIDLow, RunIDLow, OriginIDLow},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_CDRS).EnsureIndex(idx); err != nil {
return
}
for _, idxKey := range ms.cdrsIndexes {
if ms.storageType == utils.StorDB {
idx = mgo.Index{
Key: []string{idxKey},
Unique: false,
Key: []string{"tpid", "tag"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
for _, col := range []string{utils.TBL_TP_TIMINGS, utils.TBL_TP_DESTINATIONS, utils.TBL_TP_DESTINATION_RATES, utils.TBL_TP_RATING_PLANS,
utils.TBL_TP_SHARED_GROUPS, utils.TBL_TP_CDR_STATS, utils.TBL_TP_ACTIONS, utils.TBL_TP_ACTION_PLANS, utils.TBL_TP_ACTION_TRIGGERS} {
if err = db.C(col).EnsureIndex(idx); err != nil {
return
}
}
idx = mgo.Index{
Key: []string{"tpid", "direction", "tenant", "category", "subject", "loadid"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_RATE_PROFILES).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{"tpid", "direction", "tenant", "category", "account", "subject"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_LCRS).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{"tpid", "tenant", "username"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_USERS).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{"tpid", "direction", "tenant", "category", "account", "subject", "context"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_LCRS).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{"tpid", "direction", "tenant", "category", "subject", "account", "loadid"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_DERIVED_CHARGERS).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{"tpid", "direction", "tenant", "account", "loadid"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_TP_DERIVED_CHARGERS).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{CGRIDLow, RunIDLow, OriginIDLow},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
@@ -235,26 +237,38 @@ func (ms *MongoStorage) EnsureIndexes() (err error) {
if err = db.C(utils.TBL_CDRS).EnsureIndex(idx); err != nil {
return
}
}
idx = mgo.Index{
Key: []string{CGRIDLow, RunIDLow},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBLSMCosts).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{OriginHostLow, OriginIDLow},
Unique: false,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBLSMCosts).EnsureIndex(idx); err != nil {
return
for _, idxKey := range ms.cdrsIndexes {
idx = mgo.Index{
Key: []string{idxKey},
Unique: false,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBL_CDRS).EnsureIndex(idx); err != nil {
return
}
}
idx = mgo.Index{
Key: []string{CGRIDLow, RunIDLow},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBLSMCosts).EnsureIndex(idx); err != nil {
return
}
idx = mgo.Index{
Key: []string{OriginHostLow, OriginIDLow},
Unique: false,
DropDups: false,
Background: false,
Sparse: false,
}
if err = db.C(utils.TBLSMCosts).EnsureIndex(idx); err != nil {
return
}
}
return
}

View File

@@ -242,7 +242,8 @@ func (smg *SMGeneric) indexSession(s *SMGSession, passiveSessions bool) {
if _, hasIt := ssRIdx[s.CGRID]; !hasIt {
ssRIdx[s.CGRID] = make([]*riFieldNameVal, 0)
}
ssRIdx[s.CGRID] = append(ssRIdx[s.CGRID], &riFieldNameVal{runID: s.RunID, fieldName: fieldName, fieldValue: fieldVal})
riFlds := ssRIdx[s.CGRID] // attempt to avoid map concurrency write panic
ssRIdx[s.CGRID] = append(riFlds, &riFieldNameVal{runID: s.RunID, fieldName: fieldName, fieldValue: fieldVal})
}
return
}