VOL-2092 VOL-2116 : Ensure the latest data is updated
This fix resolves the issue when kv/memory does not
reflect the content of what was updated.
- Cleanup data on secondary core when removed from owner core
Amendments:
- Removed Config.Data from hash generation logic (redundant)
Change-Id: I08237e25d565ab0d875a81ad5b25b93cfd89914d
diff --git a/pkg/db/model/non_persisted_revision.go b/pkg/db/model/non_persisted_revision.go
index 88320cb..514b3b3 100644
--- a/pkg/db/model/non_persisted_revision.go
+++ b/pkg/db/model/non_persisted_revision.go
@@ -25,6 +25,7 @@
"github.com/opencord/voltha-lib-go/pkg/log"
"reflect"
"sort"
+ "strings"
"sync"
"time"
)
@@ -284,12 +285,7 @@
npr.mutex.Lock()
defer npr.mutex.Unlock()
- if ctx != nil {
- if ctxTS, ok := ctx.Value(RequestTimestamp).(int64); ok && npr.lastUpdate.UnixNano() > ctxTS {
- log.Warnw("data-is-older-than-current", log.Fields{"ctx-ts": ctxTS, "rev-ts": npr.lastUpdate.UnixNano()})
- return npr
- }
- }
+ log.Debugw("update-data", log.Fields{"hash": npr.GetHash(), "current": npr.Config.Data, "provided": data})
// Do not update the revision if data is the same
if npr.Config.Data != nil && npr.Config.hashData(npr.Root, data) == npr.Config.Hash {
@@ -313,6 +309,8 @@
newRev.Finalize(false)
+ log.Debugw("update-data-complete", log.Fields{"updated": newRev.Config.Data, "provided": data})
+
return &newRev
}
@@ -461,6 +459,25 @@
}
}
+/// ChildDropByName will remove a child entry matching the type and name
+func (npr *NonPersistedRevision) ChildDropByName(childName string) {
+ // Extract device type
+ parts := strings.SplitN(childName, "/", 2)
+ childType := parts[0]
+
+ if childType != "" {
+ children := make([]Revision, len(npr.GetChildren(childType)))
+ copy(children, npr.GetChildren(childType))
+ for i, child := range children {
+ if child.GetName() == childName {
+ children = append(children[:i], children[i+1:]...)
+ npr.SetChildren(childType, children)
+ break
+ }
+ }
+ }
+}
+
func (npr *NonPersistedRevision) SetLastUpdate(ts ...time.Time) {
npr.mutex.Lock()
defer npr.mutex.Unlock()