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

.

parent 2716a284
......@@ -637,22 +637,96 @@ func (tidx trackIndex) AddPath(path []zodb.Oid) {
// rebuild rebuilds ΔBtail taking trackNew requests into account. XXX
// XXX place
func (δBtail *ΔBtail) rebuild() {
func (δBtail *ΔBtail) rebuild() (err error) {
defer xerr.Context(&err, "ΔBtail rebuild")
// XXX locking
/*
// vδT <- merge treediff(lo..hi/trackNew)
trackNew := δBtail.trackNew
δBtail.trackNew = trackIndex{}
// go backwards and merge vδT <- treediff(lo..hi/trackNew)
vδZ := δBtail.δZtail.Data()
for i := len(vδZ)-1; i>=0; i-- {
δZ := vδZ[i]
δZTC, δtopsByRoot := δBtail.δZConnectTracked(δZ, trackNew)
// XXX dup wrt Update?
δZTC, δtopsByRoot := δZConnectTracked(δZ.Changev, trackNew)
// XXX len(δtopsByRoot) == 0 -> skip
var atPrev zodb.Tid
if i > 0 {
atPrev = vδZ[i-1].Rev
} else {
atPrev = δBtail.δZtail.Tail()
}
// open ZODB connection corresponding to "current" and "prev" states
txn, ctx := transaction.New(context.TODO())
defer txn.Abort() // XXX -> into func() or don't use defer
zconnPrev, err := δBtail.db.Open(ctx, &zodb.ConnOptions{At: atPrev})
if err != nil {
return err
}
zconnCurr, err := δBtail.db.Open(ctx, &zodb.ConnOptions{At: δZ.Rev})
if err != nil {
return err
}
for root, δtops := range δtopsByRoot {
holeIdx := treeSetKey{} // XXX stub
// diff backwards curr -> prev
δT, err := treediff(ctx, root, δtops, δZTC, trackNew, holeIdx, zconnCurr, zconnPrev)
if err != nil {
return err
}
if len(δT) == 0 { // an object might be resaved without change
continue
}
δTtail, ok := δBtail.byRoot[root]
if !ok {
// this root was not tracked before -> create δTtail for it with empty changes
var vδT []ΔTree
for i := 0; i < len(vδZ); i++ {
vδT = append(vδT, ΔTree{Rev: vδZ[i].Rev, ΔKV: make(map[Key]ΔValue)})
}
δTtail = &ΔTtail{
vδT: vδT,
// XXX KVAtTail: ...,
// XXX lastRevOf: ...,
}
δBtail.byRoot[root] = δTtail
}
// δTtail.vδT[i] <- merge δT*
δTi := δTtail.vδT[i]
for k, δv := range δT {
// the diff was backward; δTtail entries are with diff forward
δv.New, δv.Old = δv.Old, δv.New
δv_, already := δTi.ΔKV[k]
if already {
if δv != δv_ {
panicf("[%v] inconsistent δv:\nδTi: %v\nδT: %v", k, δTi, δT)
}
} else {
δTi.ΔKV[k] = δv
}
}
// XXX update .KVAtTail, .lastRevOf
}
}
*/
// merge .trackNew into .trackIdx
δBtail.trackIdx.Update(δBtail.trackNew)
δBtail.trackNew = trackIndex{}
// merge trackNew into .trackIdx
δBtail.trackIdx.Update(trackNew)
return nil
}
// Update updates δB with per-object level ZODB changes.
......@@ -677,7 +751,10 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
tracef("trackIdx: %v\n", δBtail.trackIdx)
tracef("holeIdxByRoot: %v\n", δBtail.holeIdxByRoot)
δZTC, δtopsByRoot := δZConnectTracked(δZ, δBtail.trackIdx)
// XXX dup wrt rebuild?
δZTC, δtopsByRoot := δZConnectTracked(δZ.Changev, δBtail.trackIdx)
δB := ΔB{Rev: δZ.Tid, ByRoot: make(map[zodb.Oid]map[Key]ΔValue)}
......@@ -726,8 +803,8 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
// for example for e.g. t₀->t₁->b₂ if δZ/T={t₀ b₂} -> δZ/TC=δZ/T+{t₁}
//
// δtopsByRoot = {} root -> {top changed nodes in that tree}
func δZConnectTracked(δZv *zodb.EventCommit, T trackIndex) (δZTC SetOid, δtopsByRoot map[zodb.Oid]SetOid) {
δZ := SetOid{}; for _, δ := range δZv.Changev { δZ.Add(δ) }
func δZConnectTracked(δZv []zodb.Oid, T trackIndex) (δZTC SetOid, δtopsByRoot map[zodb.Oid]SetOid) {
δZ := SetOid{}; for _, δ := range δZv { δZ.Add(δ) }
δZTC = SetOid{}
δtopsByRoot = map[zodb.Oid]SetOid{}
......@@ -951,6 +1028,9 @@ func (rs rangeSplit) String() string {
// δtops is set of top nodes for changed subtrees.
// δZTC is connected(δZ/T) - connected closure for subset of δZ(old..new) that
// touches tracked nodes of T.
//
// XXX trackIdx is updated
// XXX holeIdx is updated
func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, trackIdx trackIndex, holeIdx treeSetKey, zconnOld, zconnNew *zodb.Connection) (δT map[Key]ΔValue, err error) {
defer xerr.Contextf(&err, "treediff %s..%s %s", zconnOld.At(), zconnNew.At(), root)
......
......@@ -1020,6 +1020,7 @@ func xverifyΔBTail_rebuild_TR(t *testing.T, db *zodb.DB, δbtail *ΔBtail, tj *
// XXX verify Get
// verify SliceByRootRev XXX -> verify δbtail.byRoot[treeRoot] directly
// XXX +KVAtTail, +lastRevOf
l := len(vδTok)
vatOK := make([]zodb.Tid, l)
t0 := tj
......
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