Commit b98706ad authored by Kirill Smelkov's avatar Kirill Smelkov

X Track should be nop if keycov/path is already in krebuildJobs

parent 2370caa6
...@@ -248,8 +248,9 @@ type _ΔTtail struct { ...@@ -248,8 +248,9 @@ type _ΔTtail struct {
// _RebuildJob represents currently in-progress vδT rebuilding job. // _RebuildJob represents currently in-progress vδT rebuilding job.
type _RebuildJob struct { type _RebuildJob struct {
ready chan struct{} // closed when job completes trackNew blib.PPTreeSubSet // rebuilding for this trackNew
err error ready chan struct{} // closed when job completes
err error
} }
// _ΔBroots represents roots-only part of ΔB. // _ΔBroots represents roots-only part of ΔB.
...@@ -437,35 +438,49 @@ func (δBtail *ΔBtail) track(path []zodb.Oid, keycov KeyRange) { ...@@ -437,35 +438,49 @@ func (δBtail *ΔBtail) track(path []zodb.Oid, keycov KeyRange) {
} }
root := path[0] root := path[0]
// nothing to do if keycov is already tracked
leaf := path[len(path)-1] leaf := path[len(path)-1]
if δBtail.trackSet.Has(leaf) {
tracefΔBtail("->T: nop\n") // assertSamePathToLeaf asserts that T.Path(leaf) == path.
path_ := δBtail.trackSet.Path(leaf) assertSamePathToLeaf := func(T blib.PPTreeSubSet, Tname string) {
path_ := T.Path(leaf)
if !pathEqual(path, path_) { if !pathEqual(path, path_) {
panicf("BUG: keycov %s is already tracked via path=%v\ntrack requests path=%v", keycov, path_, path) panicf("BUG: keycov %s is already in %s via path=%v\ntrack requests path=%v", keycov, Tname, path_, path)
} }
}
// nothing to do if keycov is already tracked
if δBtail.trackSet.Has(leaf) {
tracefΔBtail("->T: nop (already in trackSet)\n")
assertSamePathToLeaf(δBtail.trackSet, "trackSet")
return return
} }
// queue path into trackNew, if not there already
δTtail, ok := δBtail.byRoot[root] δTtail, ok := δBtail.byRoot[root]
if !ok { if !ok {
δTtail = newΔTtail() δTtail = newΔTtail()
δBtail.byRoot[root] = δTtail δBtail.byRoot[root] = δTtail
} }
if δTtail.trackNew.Has(leaf) { // nothing to do if keycov is already queued to be tracked in trackNew or krebuildJobs
tracefΔBtail("->T: nop\n") inJobs := δTtail.krebuildJobs.IntersectsRange(keycov)
path_ := δTtail.trackNew.Path(leaf) if inJobs {
if !pathEqual(path, path_) { tracefΔBtail("->T: nop (already in krebuildJobs)\n")
panicf("BUG: keycov %s is already in trackNew via path=%v\ntrack requests path=%v", keycov, path_, path) job, r, ok := δTtail.krebuildJobs.Get_(keycov.Lo)
if !(ok && r == keycov) {
panicf("BUG: keycov is present in krebuildJobs only partly\nkeycov: %s\nkrebuildJobs: %v",
keycov, δTtail.krebuildJobs)
} }
assertSamePathToLeaf(job.trackNew, "job.trackNew")
return return
} }
// XXX also check if keycov ∈ krebuildJobs
if δTtail.trackNew.Has(leaf) {
tracefΔBtail("->T: nop (already in trackNew)\n")
assertSamePathToLeaf(δTtail.trackNew, "trackNew")
return
}
// keycov not in trackSet/trackNew/krebuildJobs -> queue it into trackNew
δBtail.trackNewRoots.Add(root) δBtail.trackNewRoots.Add(root)
δTtail.trackNew.AddPath(path) δTtail.trackNew.AddPath(path)
δTtail.ktrackNew.AddRange(keycov) δTtail.ktrackNew.AddRange(keycov)
...@@ -577,13 +592,14 @@ func (δTtail *_ΔTtail) _rebuild(root zodb.Oid, δBtail *ΔBtail) (err error) { ...@@ -577,13 +592,14 @@ func (δTtail *_ΔTtail) _rebuild(root zodb.Oid, δBtail *ΔBtail) (err error) {
} }
func (δTtail *_ΔTtail) __rebuild(root zodb.Oid, δBtail *ΔBtail, releaseLock bool) (err error) { func (δTtail *_ΔTtail) __rebuild(root zodb.Oid, δBtail *ΔBtail, releaseLock bool) (err error) {
defer xerr.Contextf(&err, "ΔBtail._rebuild root<%s>", root) defer xerr.Contextf(&err, "ΔBtail._rebuild root<%s>", root)
job := &_RebuildJob{ready: make(chan struct{})}
trackNew := δTtail.trackNew trackNew := δTtail.trackNew
ktrackNew := δTtail.ktrackNew ktrackNew := δTtail.ktrackNew
δTtail.trackNew = blib.PPTreeSubSet{} δTtail.trackNew = blib.PPTreeSubSet{}
δTtail.ktrackNew = blib.RangedKeySet{} δTtail.ktrackNew = blib.RangedKeySet{}
job := &_RebuildJob{trackNew: trackNew, ready: make(chan struct{})}
// krebuildJobs += ktrackNew // krebuildJobs += ktrackNew
for _, r := range ktrackNew.AllRanges() { for _, r := range ktrackNew.AllRanges() {
// assert krebuildJobs ^ r = ø // assert krebuildJobs ^ r = ø
......
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