[VOL-3833] OnuKVStoreMutex is held for a long period of time

Change-Id: Ifaaba02bef33a6c7699f5ac54770ba2a24044cda
diff --git a/internal/pkg/onuadaptercore/device_handler.go b/internal/pkg/onuadaptercore/device_handler.go
index 7d2d226..3e20883 100644
--- a/internal/pkg/onuadaptercore/device_handler.go
+++ b/internal/pkg/onuadaptercore/device_handler.go
@@ -364,8 +364,6 @@
 	// to possible concurrent access by flow processing
 	dh.pOnuTP.lockTpProcMutex()
 	defer dh.pOnuTP.unlockTpProcMutex()
-	pDevEntry.lockOnuKVStoreMutex()
-	defer pDevEntry.unlockOnuKVStoreMutex()
 
 	if techProfMsg.UniId > 255 {
 		return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
@@ -436,8 +434,6 @@
 	//compare TECH_PROFILE_DOWNLOAD_REQUEST
 	dh.pOnuTP.lockTpProcMutex()
 	defer dh.pOnuTP.unlockTpProcMutex()
-	pDevEntry.lockOnuKVStoreMutex()
-	defer pDevEntry.unlockOnuKVStoreMutex()
 
 	if delGemPortMsg.UniId > 255 {
 		return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
@@ -496,8 +492,6 @@
 	//compare TECH_PROFILE_DOWNLOAD_REQUEST
 	dh.pOnuTP.lockTpProcMutex()
 	defer dh.pOnuTP.unlockTpProcMutex()
-	pDevEntry.lockOnuKVStoreMutex()
-	defer pDevEntry.unlockOnuKVStoreMutex()
 
 	if delTcontMsg.UniId > 255 {
 		return fmt.Errorf(fmt.Sprintf("received UniId value exceeds range: %d, device-id: %s",
@@ -795,6 +789,8 @@
 	}
 	dh.pOnuTP.lockTpProcMutex()
 	defer dh.pOnuTP.unlockTpProcMutex()
+	pDevEntry.persUniConfigMutex.RLock()
+	defer pDevEntry.persUniConfigMutex.RUnlock()
 
 	if len(pDevEntry.sOnuPersistentData.PersUniConfig) == 0 {
 		logger.Debugw(ctx, "reconciling - no uni-configs have been stored before adapter restart - terminate reconcilement",
@@ -841,6 +837,9 @@
 		logger.Errorw(ctx, "No valid OnuDevice - aborting", log.Fields{"device-id": dh.deviceID})
 		return
 	}
+	pDevEntry.persUniConfigMutex.RLock()
+	defer pDevEntry.persUniConfigMutex.RUnlock()
+
 	if len(pDevEntry.sOnuPersistentData.PersUniConfig) == 0 {
 		logger.Debugw(ctx, "reconciling - no uni-configs have been stored before adapter restart - terminate reconcilement",
 			log.Fields{"device-id": dh.deviceID})
@@ -903,8 +902,6 @@
 		logger.Debugw(ctx, "OnuDevice does not exist - nothing to delete", log.Fields{"device-id": dh.deviceID})
 		return nil
 	}
-	pDevEntry.lockOnuKVStoreMutex()
-	defer pDevEntry.unlockOnuKVStoreMutex()
 
 	// deadline context to ensure completion of background routines waited for
 	//20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
@@ -2505,9 +2502,6 @@
 	}
 	pDevEntry.updateOnuUniFlowConfig(aUniID, aUniVlanFlowParams)
 
-	pDevEntry.lockOnuKVStoreMutex()
-	defer pDevEntry.unlockOnuKVStoreMutex()
-
 	// deadline context to ensure completion of background routines waited for
 	//20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
 	deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
@@ -2553,9 +2547,6 @@
 		logger.Warnw(ctx, "No valid OnuDevice", log.Fields{"device-id": dh.deviceID})
 		return fmt.Errorf("no valid OnuDevice: %s", dh.deviceID)
 	}
-	pDevEntry.lockOnuKVStoreMutex()
-	defer pDevEntry.unlockOnuKVStoreMutex()
-
 	deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
 	dctx, cancel := context.WithDeadline(context.Background(), deadline)