VOL-3957: Re-org the meter reference count update code to account
for scenarios involing flow replication across multiple p-bits.
Change-Id: I5f97fba1d75e2dc604007a151ed807a05c1165cd
diff --git a/internal/pkg/resourcemanager/resourcemanager.go b/internal/pkg/resourcemanager/resourcemanager.go
index 4e7aa79..a501310 100755
--- a/internal/pkg/resourcemanager/resourcemanager.go
+++ b/internal/pkg/resourcemanager/resourcemanager.go
@@ -1107,13 +1107,25 @@
func (RsrcMgr *OpenOltResourceMgr) HandleMeterInfoRefCntUpdate(ctx context.Context, Direction string,
IntfID uint32, OnuID uint32, UniID uint32, TpID uint32, increment bool) error {
meterInfo, err := RsrcMgr.GetMeterInfoForOnu(ctx, Direction, IntfID, OnuID, UniID, TpID)
- if meterInfo == nil || err != nil {
- return fmt.Errorf("error-fetching-meter-info-for-intf-%d-onu-%d-uni-%d-tp-id-%d-direction-%s", IntfID, OnuID, UniID, TpID, Direction)
+ if err != nil {
+ return err
+ } else if meterInfo == nil {
+ // If we are increasing the reference count, we expect the meter information to be present on KV store.
+ // But if decrementing the reference count, the meter is possibly already cleared from KV store. Just log warn but do not return error.
+ if increment {
+ logger.Errorf(ctx, "error-fetching-meter-info-for-intf-%d-onu-%d-uni-%d-tp-id-%d-direction-%s", IntfID, OnuID, UniID, TpID, Direction)
+ return fmt.Errorf("error-fetching-meter-info-for-intf-%d-onu-%d-uni-%d-tp-id-%d-direction-%s", IntfID, OnuID, UniID, TpID, Direction)
+ }
+ logger.Warnw(ctx, "meter is already cleared",
+ log.Fields{"intfID": IntfID, "onuID": OnuID, "uniID": UniID, "direction": Direction, "increment": increment})
+ return nil
}
+
if increment {
meterInfo.RefCnt++
} else {
meterInfo.RefCnt--
+ // If RefCnt become 0 clear the meter information from the DB.
if meterInfo.RefCnt == 0 {
if err := RsrcMgr.RemoveMeterInfoForOnu(ctx, Direction, IntfID, OnuID, UniID, TpID); err != nil {
return err