Commit 6e63c63d authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 34aecd3a
......@@ -366,7 +366,7 @@ func (δBtail *ΔBtail) Track(key Key, keyPresent bool, path []Node) error { //
for _, node := range path { pathv = append(pathv, vnode(node)) }
tracef("Track [%v] %s\n", key, strings.Join(pathv, " -> "))
δBtail.trackIdx.AddPath(path)
δBtail.trackIdx.AddNodePath(path)
// parent := zodb.InvalidOid
// var ptrack *nodeTrack = nil
......@@ -432,21 +432,28 @@ func (δBtail *ΔBtail) Track(key Key, keyPresent bool, path []Node) error { //
// XXX place
// XXX doc
func (tidx trackIndex) AddPath(path []Node) { // XXX Tree|Bucket; path[0] = root
func (tidx trackIndex) AddNodePath(path []Node) { // XXX Tree|Bucket; path[0] = root
// XXX assert Tree Tree ... Tree Bucket
// root := path[0].(*Tree).POid()
oidv := []zodb.Oid{}
for _, node := range path {
oidv = append(oidv, node.POid())
}
tidx.AddPath(oidv)
}
func (tidx trackIndex) AddPath(path []zodb.Oid) {
l := len(path)
if l == 0 {
panic("empty path")
}
// XXX assert Tree Tree ... Tree Bucket
// root := path[0].(*Tree).POid()
parent := zodb.InvalidOid
var ptrack *nodeTrack = nil
var track *nodeTrack // XXX kill here
var oldTrack bool
for _, node := range path { // XXX -> trackIndex.AddPath(path) ?
oid := node.POid()
for _, oid := range path {
// XXX skip InvalidOid ?
// InvalidOid means embedded bucket - e.g. T/B1:a with bucket not having its own oid.
......@@ -600,13 +607,14 @@ func (δBtail *ΔBtail) δZConnectTracked(δZv *zodb.EventCommit) (δZTC SetOid,
// XXX place
// nodeInRange represents a Node coming under [lo, hi_] key range in its tree.
type nodeInRange struct {
parent *nodeInRange
prefix []zodb.Oid // path to this node goes via this objects
lo, hi_ Key // [lo, hi_] NOTE _not_ hi) not to overflow at ∞
node Node
done bool // whether this node was already taken into account while computing diff
}
// XXX place, doc
/*
func (n *nodeInRange) NodePath() []Node {
path := []Node{}
for n != nil {
......@@ -615,6 +623,10 @@ func (n *nodeInRange) NodePath() []Node {
}
return path
}
*/
func (n *nodeInRange) Path() []zodb.Oid {
return append(n.prefix, n.node.POid())
}
// rangeSplit represents set of nodes covering a range.
// nodes come with key↑ and no intersection in between their [lo,hi)
......@@ -681,7 +693,7 @@ func (prs *rangeSplit) Expand(rnode *nodeInRange) (children rangeSplit) {
}
children = append(children, &nodeInRange{
parent: rnode,
prefix: rnode.Path(),
lo: lo,
hi_: hi_,
node: treev[i].Child(),
......@@ -814,31 +826,6 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t
trackIdx.ApplyΔ(δtrack)
}
/*
for leaf := range trackAdd {
node := leaf
for node != nil {
parent := node.parent
oid := node.node.POid()
poid := zodb.InvalidOid
if parent != nil {
poid = parent.node.POid()
}
track, already := trackIdx[oid]
if !already {
track = nodeTrack{parent: poid}
trackIdx[oid] = track
}
if track.parent != poid {
// XXX -> error (e.g. data corruption in ZODB)
panicf("node %s has multiple parents: %s %s", oid, poid, track.parent)
}
// XXX incref trackIdx[track.parent]
node = parent
}
}
*/
return δT, nil
}
......@@ -917,10 +904,18 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h
δtrack = &δtrackIndex{DelLeaf: SetOid{}, Add: trackIndex{}}
defer tracef(" -> δ: %v\n", δ)
// path prefix to A and B
prefix := []zodb.Oid{}
t := trackIdx[A.POid()]
for t.parent != zodb.InvalidOid {
prefix = append([]zodb.Oid{t.parent}, prefix...)
t = trackIdx[t.parent]
}
// initial split ranges for A and B
// XXX maybe walk till a from root to get more precise initial range?
atop := &nodeInRange{lo: KeyMin, hi_: KeyMax, node: A} // [-∞, ∞) XXX parent?
btop := &nodeInRange{lo: KeyMin, hi_: KeyMax, node: B} // [-∞, ∞) XXX parent?
atop := &nodeInRange{prefix: prefix, lo: KeyMin, hi_: KeyMax, node: A} // [-∞, ∞)
btop := &nodeInRange{prefix: prefix, lo: KeyMin, hi_: KeyMax, node: B} // [-∞, ∞)
Av := rangeSplit{atop} // nodes expanded from A
Bv := rangeSplit{btop} // nodes expanded from B
......@@ -1094,7 +1089,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h
// δ <- δB
err = δMerge(δ, δB); /*X*/if err != nil { return nil,nil, err }
δtrack.Add.AddPath(b.NodePath())
δtrack.Add.AddPath(b.Path())
// trackAdd.Add(b)
// Akqueue <- δB
......
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