VOL-1283: Fixed callback execution consistency for all proxy levels
- Callbacks are executed at any proxy levels
- Uncovered some issues with the base children fields structure
- cleaned up the root/node structures
- Ensure that a get command returns a clone.
Change-Id: Ic2cd5420c29332bd9b5d6f303a7fd9d0d0ccaf06
diff --git a/db/model/root.go b/db/model/root.go
index 27e4ec4..45eafb9 100644
--- a/db/model/root.go
+++ b/db/model/root.go
@@ -29,18 +29,20 @@
}
type root struct {
- node
+ *node
+
+ Callbacks []CallbackTuple
+ NotificationCallbacks []CallbackTuple
DirtyNodes map[string][]*node
KvStore *Backend
Loading bool
RevisionClass interface{}
- Callbacks []CallbackTuple
- NotificationCallbacks []CallbackTuple
}
func NewRoot(initialData interface{}, kvStore *Backend) *root {
root := &root{}
+
root.KvStore = kvStore
root.DirtyNodes = make(map[string][]*node)
root.Loading = false
@@ -53,23 +55,15 @@
root.Callbacks = []CallbackTuple{}
root.NotificationCallbacks = []CallbackTuple{}
- root.node = *NewNode(root, initialData, false, "")
+ root.node = NewNode(root, initialData,false, "")
return root
}
-func (r *root) MakeRevision(branch *Branch, data interface{}, children map[string][]Revision) Revision {
- if r.RevisionClass.(reflect.Type) == reflect.TypeOf(PersistedRevision{}) {
- return NewPersistedRevision(branch, data, children)
- }
-
- return NewNonPersistedRevision(branch, data, children)
-}
-
func (r *root) MakeTxBranch() string {
txid_bin, _ := uuid.New().MarshalBinary()
txid := hex.EncodeToString(txid_bin)[:12]
- r.DirtyNodes[txid] = []*node{&r.node}
+ r.DirtyNodes[txid] = []*node{r.node}
r.node.MakeBranch(txid)
return txid
}
@@ -135,7 +129,7 @@
result = r.node.Update(path, data, strict, "", nil)
}
- r.ExecuteCallbacks()
+ r.node.ExecuteCallbacks()
return result
}
@@ -161,7 +155,7 @@
result = r.node.Add(path, data, "", nil)
}
- r.ExecuteCallbacks()
+ r.node.ExecuteCallbacks()
return result
}
@@ -187,7 +181,7 @@
result = r.node.Remove(path, "", nil)
}
- r.ExecuteCallbacks()
+ r.node.ExecuteCallbacks()
return result
}
@@ -227,10 +221,6 @@
}
}
-func (r *root) LoadLatest(hash string) {
- r.node.LoadLatest(r.KvStore, hash)
-}
-
type rootData struct {
Latest string `json:latest`
Tags map[string]string `json:tags`
@@ -249,10 +239,10 @@
stop := time.Now()
GetProfiling().AddToInMemoryModelTime(stop.Sub(start).Seconds())
for tag, hash := range data.Tags {
- r.node.LoadLatest(r.KvStore, hash)
- r.node.Tags[tag] = r.node.Latest()
+ r.LoadLatest(hash)
+ r.Tags[tag] = r.Latest()
}
- r.node.LoadLatest(r.KvStore, data.Latest)
+ r.LoadLatest(data.Latest)
r.Loading = false
}