From: Anssi Mannila Date: Thu, 14 Oct 2021 09:35:41 +0000 (+0300) Subject: Fix for Submgr crash added X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F24%2F7024%2F1;hp=568d260371fd14454e5a3e41133e65bc7099a1b9;p=ric-plt%2Fsubmgr.git Fix for Submgr crash added - Submgr crashed if it received REST Subscription Request while it was still starting Change-Id: Ie434333ccf2b269c9f8dcf7a82fd60f12fa87ebc Signed-off-by: Anssi Mannila --- diff --git a/pkg/control/control.go b/pkg/control/control.go index 5dedb1e..27b2157 100755 --- a/pkg/control/control.go +++ b/pkg/control/control.go @@ -71,22 +71,22 @@ var waitRouteCleanup_ms time.Duration var e2tMaxSubReqTryCount uint64 // Initial try + retry var e2tMaxSubDelReqTryCount uint64 // Initial try + retry var readSubsFromDb string -var restDuplicateCtrl duplicateCtrl var dbRetryForever string var dbTryCount int type Control struct { *xapp.RMRClient - e2ap *E2ap - registry *Registry - tracker *Tracker - e2SubsDb Sdlnterface - restSubsDb Sdlnterface - CntRecvMsg uint64 - ResetTestFlag bool - Counters map[string]xapp.Counter - LoggerLevel uint32 - UTTesting bool + e2ap *E2ap + registry *Registry + tracker *Tracker + restDuplicateCtrl *DuplicateCtrl + e2SubsDb Sdlnterface + restSubsDb Sdlnterface + CntRecvMsg uint64 + ResetTestFlag bool + Counters map[string]xapp.Counter + LoggerLevel uint32 + UTTesting bool } type RMRMeid struct { @@ -117,13 +117,17 @@ func NewControl() *Control { tracker := new(Tracker) tracker.Init() + restDuplicateCtrl := new(DuplicateCtrl) + restDuplicateCtrl.Init() + c := &Control{e2ap: new(E2ap), - registry: registry, - tracker: tracker, - e2SubsDb: CreateSdl(), - restSubsDb: CreateRESTSdl(), - Counters: xapp.Metric.RegisterCounterGroup(GetMetricsOpts(), "SUBMGR"), - LoggerLevel: 3, + registry: registry, + tracker: tracker, + restDuplicateCtrl: restDuplicateCtrl, + e2SubsDb: CreateSdl(), + restSubsDb: CreateRESTSdl(), + Counters: xapp.Metric.RegisterCounterGroup(GetMetricsOpts(), "SUBMGR"), + LoggerLevel: 4, } c.ReadConfigParameters("") @@ -132,17 +136,16 @@ func NewControl() *Control { xapp.Resource.InjectRoute("/ric/v1/restsubscriptions", c.GetAllRestSubscriptions, "GET") xapp.Resource.InjectRoute("/ric/v1/symptomdata", c.SymptomDataHandler, "GET") - go xapp.Subscription.Listen(c.SubscriptionHandler, c.QueryHandler, c.SubscriptionDeleteHandlerCB) - if readSubsFromDb == "false" { return c } - restDuplicateCtrl.Init() - // Read subscriptions from db c.ReadE2Subscriptions() c.ReadRESTSubscriptions() + + go xapp.Subscription.Listen(c.SubscriptionHandler, c.QueryHandler, c.SubscriptionDeleteHandlerCB) + return c } @@ -308,7 +311,7 @@ func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5s var restSubscription *RESTSubscription var err error - prevRestSubsId, exists := restDuplicateCtrl.GetLastKnownRestSubsIdBasedOnMd5sum(md5sum) + prevRestSubsId, exists := c.restDuplicateCtrl.GetLastKnownRestSubsIdBasedOnMd5sum(md5sum) if p.SubscriptionID == "" { if exists { restSubscription, err = c.registry.GetRESTSubscription(prevRestSubsId, false) @@ -321,7 +324,7 @@ func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5s } } else { xapp.Logger.Info("None existing restSubId %s referred by MD5sum %s for a request without subscription ID - deleting cached entry", prevRestSubsId, md5sum) - restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum) + c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum) } } @@ -400,13 +403,13 @@ func (c *Control) SubscriptionHandler(params interface{}) (*models.SubscriptionR err = c.e2ap.FillSubscriptionReqMsgs(params, &subReqList, restSubscription) if err != nil { xapp.Logger.Error("%s", err.Error()) - restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum) + c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum) c.registry.DeleteRESTSubscription(&restSubId) c.UpdateCounter(cRestSubFailToXapp) return nil, err } - duplicate := restDuplicateCtrl.IsDuplicateToOngoingTransaction(restSubId, md5sum) + duplicate := c.restDuplicateCtrl.IsDuplicateToOngoingTransaction(restSubId, md5sum) if duplicate { xapp.Logger.Info("Retransmission blocker direct ACK for request of restSubsId %s restSubId MD5sum %s as retransmission", restSubId, md5sum) c.UpdateCounter(cRestSubRespToXapp) @@ -434,7 +437,7 @@ func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription var xAppEventInstanceID int64 var e2EventInstanceID int64 - defer restDuplicateCtrl.SetMd5sumFromLastOkRequest(*restSubId, md5sum) + defer c.restDuplicateCtrl.SetMd5sumFromLastOkRequest(*restSubId, md5sum) for index := 0; index < len(subReqList.E2APSubscriptionRequests); index++ { subReqMsg := subReqList.E2APSubscriptionRequests[index] @@ -630,7 +633,7 @@ func (c *Control) SubscriptionDeleteHandlerCB(restSubId string) error { restSubscription.DeleteXappIdToE2Id(xAppEventInstanceID) restSubscription.DeleteE2InstanceId(instanceId) } - restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(restSubscription.lastReqMd5sum) + c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(restSubscription.lastReqMd5sum) c.registry.DeleteRESTSubscription(&restSubId) c.RemoveRESTSubscriptionFromDb(restSubId) }() diff --git a/pkg/control/duplicate.go b/pkg/control/duplicate.go index 6900941..51c6bac 100644 --- a/pkg/control/duplicate.go +++ b/pkg/control/duplicate.go @@ -30,24 +30,24 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" ) -type retransEntry struct { +type RetransEntry struct { restSubsId string startTime time.Time } -type duplicateCtrl struct { +type DuplicateCtrl struct { mutex sync.Mutex - ongoingRequestMap map[string]retransEntry + ongoingRequestMap map[string]RetransEntry previousRequestMap map[string]string collCount int } -func (d *duplicateCtrl) Init() { - d.ongoingRequestMap = make(map[string]retransEntry) +func (d *DuplicateCtrl) Init() { + d.ongoingRequestMap = make(map[string]RetransEntry) d.previousRequestMap = make(map[string]string) } -func (d *duplicateCtrl) SetMd5sumFromLastOkRequest(restSubsId string, md5sum string) { +func (d *DuplicateCtrl) SetMd5sumFromLastOkRequest(restSubsId string, md5sum string) { d.mutex.Lock() defer d.mutex.Unlock() @@ -74,7 +74,7 @@ func (d *duplicateCtrl) SetMd5sumFromLastOkRequest(restSubsId string, md5sum str d.previousRequestMap[md5sum] = restSubsId } -func (d *duplicateCtrl) GetLastKnownRestSubsIdBasedOnMd5sum(md5sum string) (string, bool) { +func (d *DuplicateCtrl) GetLastKnownRestSubsIdBasedOnMd5sum(md5sum string) (string, bool) { d.mutex.Lock() defer d.mutex.Unlock() @@ -88,7 +88,7 @@ func (d *duplicateCtrl) GetLastKnownRestSubsIdBasedOnMd5sum(md5sum string) (stri return m, e } -func (d *duplicateCtrl) DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum string) { +func (d *DuplicateCtrl) DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum string) { d.mutex.Lock() defer d.mutex.Unlock() @@ -121,7 +121,7 @@ func CalculateRequestMd5sum(payload interface{}) (string, error) { return hex.EncodeToString(hash[:]), nil } -func (d *duplicateCtrl) IsDuplicateToOngoingTransaction(restSubsId string, md5sum string) bool { +func (d *DuplicateCtrl) IsDuplicateToOngoingTransaction(restSubsId string, md5sum string) bool { if md5sum == "" { return false @@ -138,7 +138,7 @@ func (d *duplicateCtrl) IsDuplicateToOngoingTransaction(restSubsId string, md5su return true } - entry = retransEntry{restSubsId: restSubsId, startTime: time.Now()} + entry = RetransEntry{restSubsId: restSubsId, startTime: time.Now()} xapp.Logger.Debug("No collision detected against ongoing transaction. Added md5sum %s for restSubsId %s at %s\n", md5sum, entry.restSubsId, entry.startTime) @@ -147,7 +147,7 @@ func (d *duplicateCtrl) IsDuplicateToOngoingTransaction(restSubsId string, md5su return false } -func (d *duplicateCtrl) TransactionComplete(md5sum string) error { +func (d *DuplicateCtrl) TransactionComplete(md5sum string) error { if md5sum == "" { return nil @@ -159,7 +159,7 @@ func (d *duplicateCtrl) TransactionComplete(md5sum string) error { return d.removeOngoingTransaction(md5sum) } -func (d *duplicateCtrl) removeOngoingTransaction(md5sum string) error { +func (d *DuplicateCtrl) removeOngoingTransaction(md5sum string) error { entry, present := d.ongoingRequestMap[md5sum] diff --git a/pkg/control/duplicate_test.go b/pkg/control/duplicate_test.go index f072881..1498af0 100644 --- a/pkg/control/duplicate_test.go +++ b/pkg/control/duplicate_test.go @@ -36,7 +36,7 @@ func TestDefaultUseCase(t *testing.T) { fmt.Println("##################### TestRetransmissionChecker #####################") - var retransCtrl duplicateCtrl + var retransCtrl DuplicateCtrl restSubdId := "898dfkjashntgkjasgho4" var name string = "yolo" var someVal int64 = 98765 @@ -61,7 +61,7 @@ func TestDuplicate(t *testing.T) { fmt.Println("##################### TestDuplicate #####################") - var retransCtrl duplicateCtrl + var retransCtrl DuplicateCtrl restSubdId := "898dfkjashntgkjasgho4" var name string = "yolo" var someVal int64 = 98765 @@ -101,7 +101,7 @@ func TestNoneDuplicate(t *testing.T) { fmt.Println("##################### TestNoneDuplicate #####################") - var retransCtrl duplicateCtrl + var retransCtrl DuplicateCtrl restSubdId := "898dfkjashntgkjasgho4" var name string = "yolo" var someVal int64 = 98765 @@ -142,7 +142,7 @@ func TestEncodingError(t *testing.T) { fmt.Println("##################### TestEncodingError #####################") - var retransCtrl duplicateCtrl + var retransCtrl DuplicateCtrl var data interface{} retransCtrl.Init() @@ -155,7 +155,7 @@ func TestRemovalError(t *testing.T) { fmt.Println("##################### TestRemovalError #####################") - var retransCtrl duplicateCtrl + var retransCtrl DuplicateCtrl restSubdId := "898dfkjashntgkjasgho4" var data testData @@ -179,7 +179,7 @@ func TestXappRestReqDuplicate(t *testing.T) { fmt.Println("##################### TestXappRestReqDuplicate #####################") - var retransCtrl duplicateCtrl + var retransCtrl DuplicateCtrl msg1 := new(models.SubscriptionParams) msg2 := new(models.SubscriptionParams) diff --git a/pkg/control/sdl_restSubsDb.go b/pkg/control/sdl_restSubsDb.go index f9d837b..2348303 100644 --- a/pkg/control/sdl_restSubsDb.go +++ b/pkg/control/sdl_restSubsDb.go @@ -94,7 +94,7 @@ func (c *Control) ReadRESTSubscriptionFromSdl(restSubId string) (*RESTSubscripti restSubs = c.CreateRESTSubscription(restSubscriptionInfo, &jsonSubscriptionInfo) - restDuplicateCtrl.SetMd5sumFromLastOkRequest(restSubId, restSubs.lastReqMd5sum) + c.restDuplicateCtrl.SetMd5sumFromLastOkRequest(restSubId, restSubs.lastReqMd5sum) } return restSubs, nil } diff --git a/pkg/control/ut_ctrl_submgr_test.go b/pkg/control/ut_ctrl_submgr_test.go index 73b26e3..66df576 100644 --- a/pkg/control/ut_ctrl_submgr_test.go +++ b/pkg/control/ut_ctrl_submgr_test.go @@ -71,7 +71,7 @@ func (mc *testingSubmgrControl) SimulateRestart(t *testing.T) { mainCtrl.c.registry.subIds = nil // Initialize subIds slice and subscription map mainCtrl.c.registry.Initialize() - restDuplicateCtrl.Init() + mainCtrl.c.restDuplicateCtrl.Init() // Read subIds and subscriptions from database subIds, register, err := mainCtrl.c.ReadAllSubscriptionsFromSdl() if err != nil { diff --git a/pkg/control/ut_messaging_test.go b/pkg/control/ut_messaging_test.go index bc1b6d3..4fdb605 100644 --- a/pkg/control/ut_messaging_test.go +++ b/pkg/control/ut_messaging_test.go @@ -39,7 +39,7 @@ func TestSuiteSetup(t *testing.T) { SetPackerIf(e2ap_wrapper.NewUtAsn1E2APPacker()) - restDuplicateCtrl.Init() + mainCtrl.c.restDuplicateCtrl.Init() }