Commit 9ac61959 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 93941125
......@@ -61,6 +61,11 @@ type nodeInTree struct {
// XXX + [lo,hi) range this node is coming under in its parent XXX -> in its tree ?
}
// Has returns whether node is in the set.
func (S PPTreeSubSet) Has(oid zodb.Oid) bool {
_, ok := S[oid]
return ok
}
// Path returns path leading to the node specified by oid.
//
......
......@@ -234,8 +234,7 @@ func (δBtail *ΔBtail) Tail() zodb.Tid { return δBtail.δZtail.Tail() }
// XXX path -> []oid ?
//
// XXX catch cycles on add?
// XXX no need to pass keyPresent since holeIdx was removed
func (δBtail *ΔBtail) Track(key Key, keyPresent bool, nodePath []Node) error { // XXX Tree|Bucket; path[0] = root
func (δBtail *ΔBtail) Track(key Key, nodePath []Node) error { // XXX Tree|Bucket; path[0] = root
path := nodePathToPath(nodePath)
......@@ -243,13 +242,25 @@ func (δBtail *ΔBtail) Track(key Key, keyPresent bool, nodePath []Node) error {
for _, node := range nodePath { pathv = append(pathv, vnode(node)) }
tracefΔBtail("\nTrack [%v] %s\n", key, strings.Join(pathv, " -> "))
return δBtail.track(key, keyPresent, path)
return δBtail.track(key, path)
}
func (δBtail *ΔBtail) track(key Key, keyPresent bool, path []zodb.Oid) error {
func (δBtail *ΔBtail) track(key Key, path []zodb.Oid) error {
// XXX locking
root := path[0]
// nothing to do if key is already tracked
leaf := path[len(path)-1]
if δBtail.trackSet.Has(leaf) {
path_ := δBtail.trackSet.Path(leaf)
if !pathEqual(path, path_) {
panicf("BUG: key %s is already tracked via path=%v\ntrack requests path=%v", kstr(key), path_, path)
}
return nil
}
// queue path into trackNew
δTtail, ok := δBtail.vδTbyRoot[root]
if !ok {
δTtail = newΔTtail()
......@@ -258,11 +269,6 @@ func (δBtail *ΔBtail) track(key Key, keyPresent bool, path []zodb.Oid) error {
δBtail.trackNewRoots.Add(root)
δTtail.trackNew.AddPath(path)
// track is track of path[-1] (i.e. leaf)
// XXX update diff XXX here? or as separate step?
// XXX update lastRevOf
return nil
}
......@@ -289,7 +295,7 @@ func (δBtail *ΔBtail) rebuildAll() (err error) {
// rebuild rebuilds ΔTtail taking trackNew requests into account.
//
// It returns set of nodes that must be added to ΔBtail.trackSet to account for
// keys that becomes tracked. Note: this set is potentially wider compared to .trackNew.
// keys that becomes tracked. Note: this set is potentially wider compared to what was in .trackNew.
// XXX place
func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet PPTreeSubSet, err error) {
defer xerr.Context(&err, "ΔTtail rebuild")
......@@ -351,6 +357,7 @@ func (δTtail *ΔTtail) rebuild(δZtail *zodb.ΔTail, db *zodb.DB) (δtrackSet P
}
// FIXME use δtkeycov to recompute track coverage
_ = δtkeycov
debugfΔBtail(" -> root<%s> δkv*: %v δtrack*: %v\n", root, δT, δtrack)
......@@ -501,6 +508,7 @@ if XXX_killWhenRebuildWorks {
δB.ΔByRoot[root] = δT
δTtail, ok := δBtail.vδTbyRoot[root]
if !ok {
// XXX should not happen (only roots requested to be present are present in δ)
// this root was not tracked before -> create δTtail for it with empty changes
δTtail = newΔTtail()
δBtail.vδTbyRoot[root] = δTtail
......@@ -514,6 +522,8 @@ if XXX_killWhenRebuildWorks {
δBtail.trackSet.ApplyΔ(δtrack)
δTKeyCov.ByRoot[root] = δtkeycov
// XXX if δtkeycov != ø -> rebuild δTtail
}
return δB, δTKeyCov, nil
......
......@@ -720,8 +720,8 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
for k := range initialTrackedKeys {
if ztree != nil {
_, ok, path, err := ZTreeGetBlkData(ctx, ztree, k); X(err)
err = δbtail.Track(k, ok, path); X(err)
_, _, path, err := ZTreeGetBlkData(ctx, ztree, k); X(err)
err = δbtail.Track(k, path); X(err)
} else {
// if treeRoot is deleted - add it to tracked set with every key
// being a hole. This aligns with the following situation
......@@ -732,7 +732,7 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
// continues to be tracked and all keys migrate to holes in the
// tracking set. By aligning initial state to the same as after
// T1->ø, we test what will happen on ø->T2.
err = δbtail.track(k, false, []zodb.Oid{treeRoot}); X(err)
err = δbtail.track(k, []zodb.Oid{treeRoot}); X(err)
}
}
......@@ -1108,8 +1108,8 @@ func xverifyΔBTail_rebuild_TR(t *testing.T, db *zodb.DB, δbtail *ΔBtail, tj *
xtree, err := zconn.Get(ctx, treeRoot); X(err)
ztree := xtree.(*Tree)
for k := range keys {
_, ok, path, err := ZTreeGetBlkData(ctx, ztree, k); X(err)
err = δbtail.Track(k, ok, path); X(err)
_, _, path, err := ZTreeGetBlkData(ctx, ztree, k); X(err)
err = δbtail.Track(k, path); X(err)
}
δbtail.assertTrack(t, fmt.Sprintf("@%s: after Track%v", xat[tj.at], keys), trackSet, trackNew)
......@@ -1218,8 +1218,8 @@ func xverifyΔBTail_GetAt1(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, vt []*t
ztree := xtree.(*Tree)
for k := range keys {
_, ok, path, err := ZTreeGetBlkData(ctx, ztree, k); X(err)
err = δbtail.Track(k, ok, path); X(err)
_, _, path, err := ZTreeGetBlkData(ctx, ztree, k); X(err)
err = δbtail.Track(k, path); X(err)
}
// verify GetAt(k, @at) for all keys and @at
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment