Commit 9173ad79 authored by Kirill Smelkov's avatar Kirill Smelkov

X maintain per-root holeIdx

Else in case of two files used simultaneously the index is messed up.
Fixes test_wcfs_watch_2files and now all wcfs tests pass again.
parent 8db3f96a
......@@ -174,11 +174,10 @@ type ΔBtail struct {
// tracked nodes index: node -> parent + accessed holes under this node XXX -> holeIdx
// we only allow single parent/root case and report "tree corrupt" otherwise.
// trackIdx describes @head state
//trackIdx map[zodb.Oid]nodeTrack
trackIdx trackIndex
// XXX tracked holes
holeIdx treeSetKey
// XXX root -> tracked holes
holeIdxByRoot map[zodb.Oid]treeSetKey
// // tracked objects that are not yet taken into account in current δBtail
// trackNew SetOid
......@@ -355,7 +354,7 @@ func NewΔBtail(at0 zodb.Tid, db *zodb.DB) *ΔBtail {
δZtail: zodb.NewΔTail(at0),
byRoot: map[zodb.Oid]*ΔTtail{},
trackIdx: trackIndex{},
holeIdx: treeSetKey{SetKey{}},
holeIdxByRoot: map[zodb.Oid]treeSetKey{},
db: db,
}
}
......@@ -402,8 +401,9 @@ func (δBtail *ΔBtail) Track(key Key, keyPresent bool, path []Node) error { //
// track is track of path[-1] (i.e. leaf)
// remember missing keys in track of leaf node (bucket or top-level ø tree)
holeIdx := δBtail.holeIdxFor(root)
if !keyPresent {
δBtail.holeIdx.Add(key)
holeIdx.Add(key)
//track.holes.Add(key)
} else {
/*
......@@ -411,7 +411,7 @@ func (δBtail *ΔBtail) Track(key Key, keyPresent bool, path []Node) error { //
panicf("[%v] was previously requested to be tracked as ø", key)
}
*/
if δBtail.holeIdx.Has(key) {
if holeIdx.Has(key) {
panicf("[%v] was previously requested to be tracked as ø", key)
}
}
......@@ -426,6 +426,15 @@ func (δBtail *ΔBtail) Track(key Key, keyPresent bool, path []Node) error { //
return nil
}
func (δBtail *ΔBtail) holeIdxFor(root zodb.Oid) treeSetKey {
holeIdx, ok := δBtail.holeIdxByRoot[root]
if !ok {
holeIdx = treeSetKey{SetKey{}}
δBtail.holeIdxByRoot[root] = holeIdx
}
return holeIdx
}
// XXX place
// XXX doc
func (tidx trackIndex) AddNodePath(path []Node) { // XXX Tree|Bucket; path[0] = root
......@@ -504,7 +513,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
tracef("Update δZ: %v\n", δZ.Changev)
tracef("trackIdx: %v\n", δBtail.trackIdx)
tracef("holeIdx: %v\n", δBtail.holeIdx)
tracef("holeIdxByRoot: %v\n", δBtail.holeIdxByRoot)
δZTC, δtopsByRoot := δBtail.δZConnectTracked(δZ)
......@@ -529,7 +538,8 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
}
for root, δtops := range δtopsByRoot {
δT, err := treediff(ctx, root, δtops, δZTC, δBtail.trackIdx, δBtail.holeIdx, zconnOld, zconnNew)
holeIdx := δBtail.holeIdxByRoot[root]
δT, err := treediff(ctx, root, δtops, δZTC, δBtail.trackIdx, holeIdx, zconnOld, zconnNew)
if err != nil {
return ΔB{}, err
}
......
......@@ -678,8 +678,9 @@ func xverifyΔBTail1(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid,
// verify δbtail.holeIdx against @at1
// holes1 = tracked1 \ kv1
holes1 := xkv1.holeIdx(initialTrackedKeys)
if !reflect.DeepEqual(holes1, δbtail.holeIdx.SetKey) {
badf("δbtail.holeIdx1 wrong ; holeIdx=%v holeIdxOK=%v", δbtail.holeIdx, holes1)
holeIdx := δbtail.holeIdxFor(treeRoot)
if !reflect.DeepEqual(holes1, holeIdx.SetKey) {
badf("δbtail.holeIdx1 wrong ; holeIdx=%v holeIdxOK=%v", holeIdx, holes1)
}
// verify δbtail.trackIdx against @at1
......@@ -700,8 +701,8 @@ func xverifyΔBTail1(t *testing.T, subj string, db *zodb.DB, treeRoot zodb.Oid,
// verify δbtail.holeIdx against @at2
// holes2 = tracked2 \ kv2 ( = kadj[tracked1] \ kv2)
holes2 := xkv2.holeIdx(kadjTracked)
if !reflect.DeepEqual(holes2, δbtail.holeIdx.SetKey) {
badf("δbtail.holeIdx2 wrong ; holeIdx=%v holeIdxOK=%v", δbtail.holeIdx, holes2)
if !reflect.DeepEqual(holes2, holeIdx.SetKey) {
badf("δbtail.holeIdx2 wrong ; holeIdx=%v holeIdxOK=%v", holeIdx, holes2)
}
// verify δbtail.trackIdx against @at2
......
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