VOL-4670: Fix for flowIDsForGem cache in openolt adapter
          resource manager is not updated on adapter restarts

- The cache flowIDsForGem is empty on adapter restarts.
  So use GetFlowIDsForGem API to update the cache and use it.

VOL-4672: Stale etcd data in openolt adapter after olt device delete

- If OLT device is getting deleted ignore ChildDeviceLost processing.
  The ChildDeviceLost could create entries already cleaned up by
  OLT device delete processing under some race conditions.

Change-Id: I535d9c968acb6bcee897fea49c78362230a52ac9
diff --git a/internal/pkg/resourcemanager/resourcemanager.go b/internal/pkg/resourcemanager/resourcemanager.go
index 9566637..af281f4 100755
--- a/internal/pkg/resourcemanager/resourcemanager.go
+++ b/internal/pkg/resourcemanager/resourcemanager.go
@@ -1236,29 +1236,27 @@
 }
 
 // IsGemPortUsedByAnotherFlow returns true if given gem is used by another flow
-func (rsrcMgr *OpenOltResourceMgr) IsGemPortUsedByAnotherFlow(gemPortID uint32, flowID uint64) bool {
-	rsrcMgr.flowIDsForGemLock.RLock()
-	flowIDList := rsrcMgr.flowIDsForGem[gemPortID]
-	rsrcMgr.flowIDsForGemLock.RUnlock()
+func (rsrcMgr *OpenOltResourceMgr) IsGemPortUsedByAnotherFlow(ctx context.Context, gemPortID uint32, flowID uint64) (bool, error) {
+	flowIDList, err := rsrcMgr.GetFlowIDsForGem(ctx, gemPortID)
+	if err != nil {
+		return false, err
+	}
 	for _, id := range flowIDList {
 		if flowID != id {
-			return true
+			return true, nil
 		}
 	}
-	return false
+	return false, nil
 }
 
 // RegisterFlowIDForGem updates both cache and KV store for flowIDsForGem map
 func (rsrcMgr *OpenOltResourceMgr) RegisterFlowIDForGem(ctx context.Context, gemPortID uint32, flowFromCore *ofp.OfpFlowStats) error {
-	// get from cache
-	rsrcMgr.flowIDsForGemLock.RLock()
-	flowIDs, ok := rsrcMgr.flowIDsForGem[gemPortID]
-	rsrcMgr.flowIDsForGemLock.RUnlock()
-	if !ok {
-		flowIDs = []uint64{flowFromCore.Id}
-	} else {
-		flowIDs = appendUnique64bit(flowIDs, flowFromCore.Id)
+	flowIDs, err := rsrcMgr.GetFlowIDsForGem(ctx, gemPortID)
+	if err != nil {
+		return err
 	}
+
+	flowIDs = appendUnique64bit(flowIDs, flowFromCore.Id)
 	// update the flowids for a gem to the KVstore
 	return rsrcMgr.UpdateFlowIDsForGem(ctx, gemPortID, flowIDs)
 }