[VOL-1547] Add port to logical device when device is active
This commit consists of the following changes:
1) Fix the issue where flows were received when the logical
device flow graph was not ready.
2) Update the default kafka config for improved performance
3) Add a lock to the device ownership logic to ensure the
lock map does not get corrupted.
Change-Id: I840d572e06ed5acf0f3bc1ce423a0ada8f335543
diff --git a/rw_core/core/device_ownership.go b/rw_core/core/device_ownership.go
index 4a692d3..0921561 100644
--- a/rw_core/core/device_ownership.go
+++ b/rw_core/core/device_ownership.go
@@ -238,39 +238,34 @@
if id == nil {
return "", status.Error(codes.InvalidArgument, "nil-id")
}
+ da.deviceToKeyMapLock.Lock()
+ defer da.deviceToKeyMapLock.Unlock()
var device *voltha.Device
var lDevice *voltha.LogicalDevice
// The id can either be a device Id or a logical device id.
if dId, ok := id.(*utils.DeviceID); ok {
// Use cache if present
- if val, err := da.getDeviceKey(dId.Id); err == nil {
+ if val, exist := da.deviceToKeyMap[dId.Id]; exist {
return val, nil
}
if device, _ = da.deviceMgr.GetDevice(dId.Id); device == nil {
return "", status.Error(codes.NotFound, fmt.Sprintf("id-absent-%s", dId))
}
if device.Root {
- if err := da.updateDeviceKey(dId.Id, device.Id); err != nil {
- log.Warnw("Error-updating-cache", log.Fields{"id": dId.Id, "key": device.Id, "error": err})
- }
- return device.Id, nil
+ da.deviceToKeyMap[dId.Id] = device.Id
} else {
- if err := da.updateDeviceKey(dId.Id, device.ParentId); err != nil {
- log.Warnw("Error-updating-cache", log.Fields{"id": dId.Id, "key": device.ParentId, "error": err})
- }
- return device.ParentId, nil
+ da.deviceToKeyMap[dId.Id] = device.ParentId
}
+ return da.deviceToKeyMap[dId.Id], nil
} else if ldId, ok := id.(*utils.LogicalDeviceID); ok {
// Use cache if present
- if val, err := da.getDeviceKey(ldId.Id); err == nil {
+ if val, exist := da.deviceToKeyMap[ldId.Id]; exist {
return val, nil
}
if lDevice, _ = da.logicalDeviceMgr.getLogicalDevice(ldId.Id); lDevice == nil {
return "", status.Error(codes.NotFound, fmt.Sprintf("id-absent-%s", ldId))
}
- if err := da.updateDeviceKey(ldId.Id, lDevice.RootDeviceId); err != nil {
- log.Warnw("Error-updating-cache", log.Fields{"id": ldId.Id, "key": lDevice.RootDeviceId, "error": err})
- }
+ da.deviceToKeyMap[ldId.Id] = lDevice.RootDeviceId
return lDevice.RootDeviceId, nil
}
return "", status.Error(codes.NotFound, fmt.Sprintf("id-%s", id))