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

.

parent 7fbd0360
......@@ -81,13 +81,27 @@ type setOid = set.Oid
type ΔFtail struct {
// ΔFtail merges ΔBtail with history of ZBlk
δBtail *xbtree.ΔBtail
fileIdx map[zodb.Oid]setOid // tree-root -> {} ZBigFile<oid> as of @head
rootIdx map[zodb.Oid]zodb.Oid // file -> tree-root as of @head
fileIdx map[zodb.Oid]setOid // tree-root -> {} ZBigFile<oid> as of @head XXX -> root2file ?
// rootIdx map[zodb.Oid]zodb.Oid // file -> tree-root as of @head
byFile map[zodb.Oid]*_ΔFileTail // file -> δf tail XXX
trackSetZFile setOid // set of tracked ZBigFiles as of @head
// trackSetZFile setOid // set of tracked ZBigFiles as of @head
trackSetZBlk map[zodb.Oid]*zblkTrack // zblk -> {} root -> {}blk as of @head
}
// _ΔFileTail represents tail of revisional changes to one file.
type _ΔFileTail struct {
root zodb.Oid // .blktab as of @head
vδE []_ΔFileEpoch // changes to ZBigFile object itself ; nil if not yet rebuilt
}
// _ΔFileEpoch represent change to ZBigFile object.
type _ΔFileEpoch struct {
Rev zodb.Tid
newRoot zodb.Oid // .blktab was changed to point to newRoot ; VDEL if ZBigFile deleted
newBlkSize int64 // .blksize was changed to newBlkSize ; -1 if ZBigFile deleted
}
// zblkTrack keeps information in which root/blocks ZBlk is present as of @head.
type zblkTrack struct {
inroot map[zodb.Oid]setI64 // {} root -> {}blk
......@@ -118,8 +132,9 @@ func NewΔFtail(at0 zodb.Tid, db *zodb.DB) *ΔFtail {
return &ΔFtail{
δBtail: xbtree.NewΔBtail(at0, db),
fileIdx: map[zodb.Oid]setOid{},
rootIdx: map[zodb.Oid]zodb.Oid{},
trackSetZFile: setOid{},
// rootIdx: map[zodb.Oid]zodb.Oid{},
// trackSetZFile: setOid{},
byFile: map[zodb.Oid]*_ΔFileTail{},
trackSetZBlk: map[zodb.Oid]*zblkTrack{},
}
}
......@@ -163,17 +178,17 @@ func (δFtail *ΔFtail) Track(file *ZBigFile, blk int64, path []btree.LONode, zb
}
files.Add(foid)
roid_, ok := δFtail.rootIdx[foid]
if ok {
if roid != roid_ {
panicf("zfile<%s> changed root from %s -> %s", foid, roid_, roid)
}
} else {
δFtail.rootIdx[foid] = roid
δftail, ok := δFtail.byFile[foid]
if !ok {
δftail = &_ΔFileTail{root: roid, vδE: nil /*will need to be rebuilt till past*/}
δFtail.byFile[foid] = δftail
}
if δftail.root != roid {
panicf("zfile<%s> changed root from %s -> %s", foid, δftail.root, roid)
}
δFtail.trackSetZFile.Add(foid)
// δFtail.trackSetZFile.Add(foid)
// associate zblk with file, if it was not hole
if zblk != nil {
......@@ -282,7 +297,8 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
// take zblk changes into account
δzfile := map[zodb.Oid]*_ΔZBigFile{} // which tracked ZBigFiles are changed
for _, oid := range δZ.Changev {
if δFtail.trackSetZFile.Has(oid) {
δftail, ok := δFtail.byFile[oid]
if ok {
δ, err := zfilediff(δFtail.δBtail.DB(), oid, headOld, δZ.Tid)
if err != nil {
return ΔF{}, err
......@@ -290,6 +306,11 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
if δ != nil {
δzfile[oid] = δ
δftail.vδE = append(δftail.vδE, _ΔFileEpoch{
Rev: δZ.Tid,
newRoot: δ.blktabNew,
newBlkSize: δ.blksizeNew,
})
}
continue
......@@ -373,6 +394,7 @@ func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*reado
// query .δBtail.SliceByRootRev(file.blktab, lo, hi) +
// merge δZBlk history with that.
// merging tree (δT) and Zblk (δZblk) histories into file history (δFile):
// δT ────────·──────────────·─────────────────·────────────
......@@ -387,7 +409,8 @@ func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*reado
// δFile ────────o───────o──────x─────x────────────────────────
root := δFtail.rootIdx[zfile.POid()]
δftail := δFtail.byFile[zfile.POid()]
root := δftail.root // XXX take epochs into account
vδT := δFtail.δBtail.SliceByRootRev(root, lo, δFtail.Head()) // NOTE @head, not hi
vδZ := δFtail.δBtail.ΔZtail().SliceByRev(lo, hi)
......@@ -514,6 +537,8 @@ func (δFtail *ΔFtail) LastBlkRev(ctx context.Context, zf *ZBigFile, blk int64,
}
defer zf.PDeactivate()
// XXX take epochs into account
// XXX tabRev -> treeRev ?
zblkOid, ok, tabRev, tabRevExact, err := δFtail.δBtail.GetAt(ctx, zf.blktab, blk, at)
//fmt.Printf("GetAt #%d @%s -> %s, %v, @%s, %v\n", blk, at, zblkOid, ok, tabRev, tabRevExact)
......
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