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