[VOL-3731] Delete etcd stale data after olt reboot
Change-Id: Ib6669511327870d180262e1f8c2bd6c1e8315496
(cherry picked from commit 4f5ed59bf6dbcacbdef33ed25b4601334364275b)
diff --git a/VERSION b/VERSION
index c492825..3cf5751 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.5.6
+3.5.7
diff --git a/go.mod b/go.mod
index 5eed3b1..cf940c4 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@
github.com/gogo/protobuf v1.3.1
github.com/golang/protobuf v1.3.2
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4
- github.com/opencord/voltha-lib-go/v5 v5.0.5
+ github.com/opencord/voltha-lib-go/v5 v5.0.6
github.com/opencord/voltha-protos/v4 v4.2.0
go.etcd.io/etcd v0.0.0-20190930204107-236ac2a90522
google.golang.org/grpc v1.25.1
diff --git a/go.sum b/go.sum
index 516ef82..c8d8e5b 100644
--- a/go.sum
+++ b/go.sum
@@ -141,8 +141,8 @@
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
-github.com/opencord/voltha-lib-go/v5 v5.0.5 h1:S3m984EaHNGJY68Hrv9LOf0rwd92UiVLFBBbTaL+fNg=
-github.com/opencord/voltha-lib-go/v5 v5.0.5/go.mod h1:i1fwPMicFccG38L200+IQAlfHSbszWg//jF1pDQxTPQ=
+github.com/opencord/voltha-lib-go/v5 v5.0.6 h1:vJ6ZTNSjOiWAViCT5BfxEgv596d4KBov28a3rE5DDPI=
+github.com/opencord/voltha-lib-go/v5 v5.0.6/go.mod h1:i1fwPMicFccG38L200+IQAlfHSbszWg//jF1pDQxTPQ=
github.com/opencord/voltha-protos/v4 v4.2.0 h1:QJZqHPRKa1E1xh40F3UA4xSjBI+6EmW7OfIcJqPNc4A=
github.com/opencord/voltha-protos/v4 v4.2.0/go.mod h1:wNzWqmTwe7+DbYbpmOX6eMlglREtMkNxIDv3lyI2bco=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
diff --git a/internal/pkg/resourcemanager/resourcemanager.go b/internal/pkg/resourcemanager/resourcemanager.go
index 16b2723..72b7d54 100755
--- a/internal/pkg/resourcemanager/resourcemanager.go
+++ b/internal/pkg/resourcemanager/resourcemanager.go
@@ -1072,9 +1072,7 @@
//DeletePacketInGemPortForOnu deletes the packet-in gemport for ONU
func (rsrcMgr *OpenOltResourceMgr) DeletePacketInGemPortForOnu(ctx context.Context, intfID uint32, onuID uint32, logicalPort uint32) error {
-
path := fmt.Sprintf(OnuPacketINPathPrefix, intfID, onuID, logicalPort)
-
value, err := rsrcMgr.KVStore.List(ctx, path)
if err != nil {
logger.Errorf(ctx, "failed-to-read-value-from-path-%s", path)
@@ -1083,8 +1081,9 @@
//remove them one by one
for key := range value {
- // Formulate the right key path suffix ti be delete
- stringToBeReplaced := fmt.Sprintf(BasePathKvStore, rsrcMgr.KVStore.PathPrefix, rsrcMgr.DeviceID) + "/"
+ // Remove the PathPrefix from the path on KV key.
+ // gemPortForPacketInInfo cache uses OnuPacketINPath as the key
+ stringToBeReplaced := rsrcMgr.KVStore.PathPrefix + "/"
replacedWith := ""
key = strings.Replace(key, stringToBeReplaced, replacedWith, 1)
// update cache
@@ -1092,11 +1091,13 @@
delete(rsrcMgr.gemPortForPacketInInfo, key)
rsrcMgr.gemPortForPacketInInfoLock.Unlock()
- logger.Debugf(ctx, "removing-key-%s", key)
- if err := rsrcMgr.KVStore.Delete(ctx, key); err != nil {
- logger.Errorf(ctx, "failed-to-remove-resource-%s", key)
- return err
- }
+ logger.Debugw(ctx, "removed-key-from-packetin-gem-port-cache", log.Fields{"key": key, "cache-len": len(rsrcMgr.gemPortForPacketInInfo)})
+ }
+
+ logger.Debugw(ctx, "delete-packetin-gem-port", log.Fields{"realPath": path})
+ if err := rsrcMgr.KVStore.DeleteWithPrefix(ctx, path); err != nil {
+ logger.Errorf(ctx, "failed-to-remove-resource-%s", path)
+ return err
}
return nil
diff --git a/vendor/github.com/opencord/voltha-lib-go/v5/pkg/ponresourcemanager/ponresourcemanager.go b/vendor/github.com/opencord/voltha-lib-go/v5/pkg/ponresourcemanager/ponresourcemanager.go
index 804a6f3..a8738ee 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v5/pkg/ponresourcemanager/ponresourcemanager.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v5/pkg/ponresourcemanager/ponresourcemanager.go
@@ -1263,12 +1263,10 @@
*/
ByteArray, err := ToByte(Resource[POOL])
if err != nil {
- logger.Error(ctx, "Failed to convert resource to byte array")
return 0, err
}
Data := bitmap.TSFromData(ByteArray, false)
if Data == nil {
- logger.Error(ctx, "Failed to get data from byte array")
return 0, errors.New("Failed to get data from byte array")
}
@@ -1279,6 +1277,9 @@
break
}
}
+ if Idx == Len {
+ return 0, errors.New("resource-exhausted--no-free-id-in-the-pool")
+ }
Data.Set(Idx, true)
res := uint32(Resource[START_IDX].(float64))
Resource[POOL] = Data.Data(false)
@@ -1303,6 +1304,10 @@
return false
}
Idx := Id - uint32(Resource[START_IDX].(float64))
+ if Idx >= uint32(Data.Len()) {
+ logger.Errorf(ctx, "ID %d is out of the boundaries of the pool", Id)
+ return false
+ }
Data.Set(int(Idx), false)
Resource[POOL] = Data.Data(false)
@@ -1320,6 +1325,10 @@
return false
}
Idx := Id - StartIndex
+ if Idx >= uint32(Data.Len()) {
+ logger.Errorf(ctx, "Reservation failed. ID %d is out of the boundaries of the pool", Id)
+ return false
+ }
Data.Set(int(Idx), true)
return true
}
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 3f55ca8..22ca5b8 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -58,7 +58,7 @@
# github.com/jcmturner/gofork v1.0.0
github.com/jcmturner/gofork/encoding/asn1
github.com/jcmturner/gofork/x/crypto/pbkdf2
-# github.com/opencord/voltha-lib-go/v5 v5.0.5
+# github.com/opencord/voltha-lib-go/v5 v5.0.6
## explicit
github.com/opencord/voltha-lib-go/v5/pkg/adapters
github.com/opencord/voltha-lib-go/v5/pkg/adapters/adapterif