Commit 3275f8a0 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f3ae2f0c
......@@ -769,8 +769,6 @@ func (δBtail *ΔBtail) GetAt(ctx context.Context, root *Tree, key Key, at zodb.
// XXX key not tracked -> panic
// XXX at not ∈ (tail, head] -> panic
// XXX handle deletion
// XXX dirty -> rebuild
rootAt := root.PJar().At()
......@@ -784,35 +782,41 @@ func (δBtail *ΔBtail) GetAt(ctx context.Context, root *Tree, key Key, at zodb.
}
// XXX -> index lastXXXOf(key) | linear scan ↓ looking for change <= at
rev = δBtail.Tail()
revExact = false
for i := len(δTtail.vδT)-1; i >= 0; i-- {
δT := δTtail.vδT[i]
if at < δT.Rev {
continue
}
var δvalue ΔValue
δvalue, ok = δT.ΔKV[key]
if ok {
value = δvalue.New
rev = δT.Rev
revExact = true
break
δvalue, ok_ := δT.ΔKV[key]
if ok_ {
ok = true
if δT.Rev > at {
value = δvalue.Old
} else {
value = δvalue.New
rev = δT.Rev
revExact = true
break
}
}
}
// key was found in δT ∈ δTtail
if ok {
if value == VDEL {
ok = false
}
return
}
// key not in history tail.
// either use @tail[key], if it is present, or @head[key]
rev = δBtail.Tail()
revExact = false
// key not in history tail at all.
// use @head[key]
/*
// XXX kill KVAtTail completely
value, ok = δTtail.KVAtTail[key] // XXX kill - just use δvalue.Old from next-to-at entry
if ok {
return
}
*/
// @tail[key] is not present - key was not changing in (tail, head].
// since at ∈ (tail, head] we can use @head[key] as the result
......
......@@ -75,7 +75,8 @@ 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
fileIdx map[zodb.Oid]setOid // tree-root -> {} ZBigFile<oid> as of @head
rootIdx map[zodb.Oid]zodb.Oid // file -> tree-root
trackSetZFile setOid // set of tracked ZBigFiles as of @head
trackSetZBlk map[zodb.Oid]*zblkTrack // zblk -> {} root -> {}blk as of @head
......@@ -114,6 +115,7 @@ 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{},
trackSetZBlk: map[zodb.Oid]*zblkTrack{},
}
......@@ -158,6 +160,16 @@ 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.trackSetZFile.Add(foid)
// associate zblk with file, if it was not hole
......@@ -343,7 +355,7 @@ func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*reado
// XXX needs activate zfile
root := zfile.blktab.POid()
root := δFtail.rootIdx[zfile.POid()]
vδT := δFtail.δBtail.SliceByRootRev(root, lo, δFtail.Head()) // NOTE @head, not hi
vδZ := δFtail.δBtail.ΔZtail().SliceByRev(lo, hi)
......@@ -464,9 +476,15 @@ func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*reado
func (δFtail *ΔFtail) LastBlkRev(ctx context.Context, zf *ZBigFile, blk int64, at zodb.Tid) (_ zodb.Tid, exact bool) {
//defer xerr.Contextf(&err, "") // XXX text
err := zf.PActivate(ctx)
if err != nil {
panic(err) // XXX
}
defer zf.PDeactivate()
// XXX tabRev -> treeRev ?
// XXX activate zfile?
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)
if err != nil {
panic(err) // XXX
}
......@@ -480,6 +498,7 @@ func (δFtail *ΔFtail) LastBlkRev(ctx context.Context, zf *ZBigFile, blk int64,
// blktab[blk] was changed to point to a zblk @rev.
// blk revision is max rev and when zblk changed last in (rev, at] range.
zblkRev, zblkRevExact := δFtail.δBtail.ΔZtail().LastRevOf(zblkOid, at)
//fmt.Printf("ZRevOf %s @%s -> @%s, %v\n", zblkOid, at, zblkRev, zblkRevExact)
if zblkRev > tabRev {
return zblkRev, zblkRevExact
} else {
......
......@@ -178,19 +178,19 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
// load zfile via root['treegen/file']
txn, ctx := transaction.New(context.Background())
defer txn.Abort()
zconn, err := t.DB.Open(ctx, &zodb.ConnOptions{At: t.Head().At}); X(err)
zconn, err := t.DB.Open(ctx, &zodb.ConnOptions{At: t.Head().At, NoPool: true}); X(err)
xzroot, err := zconn.Get(ctx, 0); X(err)
zroot := xzroot.(*zodb.Map)
err = zroot.PActivate(ctx); X(err)
defer zroot.PDeactivate()
zfile := zroot.Data["treegen/file"].(*ZBigFile)
zroot.PDeactivate()
zfileOid := zfile.POid()
err = zfile.PActivate(ctx); X(err)
defer zfile.PDeactivate()
if treeOid := zfile.blktab.POid(); treeOid != t.Root() {
t.Fatalf("BUG: zfile.blktab (%s) != treeroot (%s)", treeOid, t.Root())
blktabOid := zfile.blktab.POid()
if blktabOid != t.Root() {
t.Fatalf("BUG: zfile.blktab (%s) != treeroot (%s)", blktabOid, t.Root())
}
zfile.PDeactivate()
// track zfile[-∞,∞) from the beginning
// this should make ΔFtail to see all zfile changes
......@@ -301,6 +301,11 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
}
blkRevAt[commit.At] = blkRev
// update zfile
txn.Abort()
txn, ctx = transaction.New(context.Background())
err = zconn.Resync(ctx, commit.At); X(err)
var δfok *ΔFile
if len(δblk) != 0 {
δfok = &ΔFile{
......@@ -313,7 +318,7 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
xat[commit.At] = fmt.Sprintf("at%d", i)
t.Logf("# → @%s (%s) δT%s δD%s\t; %s\tδ%s", xat[commit.At], commit.At, xbtreetest.KVTxt(test.δblkTab), test.δdataTab, tTxt, δblk)
t.Logf("# vδf: %s", vδfstr(vδf))
//t.Logf("# vδf: %s", vδfstr(vδf))
//fmt.Printf("Zinblk: %v\n", Zinblk)
......@@ -348,8 +353,8 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
for oid, zt := range δftail.trackSetZBlk {
zblki := commit.ZBlkTab[oid]
for root, blocks := range zt.inroot {
if root != zfile.blktab.POid() {
t.Errorf(".trackSetZBlk: zblk %s points to unexpected blktab %s", zblki.Name, zfile.blktab.POid())
if root != blktabOid {
t.Errorf(".trackSetZBlk: zblk %s points to unexpected blktab %s", zblki.Name, blktabOid)
continue
}
......@@ -372,8 +377,8 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
t.Logf("# forget ≤ @%s", xat[revcut])
δftail.ForgetPast(revcut)
vδf = vδf[1:]
t.Logf("# vδf: %s", vδfstr(vδf))
t.Logf("# vδt: %s", vδfstr(δftail.SliceByFileRev(zfile, δftail.Tail(), δftail.Head())))
//t.Logf("# vδf: %s", vδfstr(vδf))
//t.Logf("# vδt: %s", vδfstr(δftail.SliceByFileRev(zfile, δftail.Tail(), δftail.Head())))
}
// SliceByFileRev
......@@ -399,10 +404,12 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
// LastBlkRev
blkv := []int64{} // all blocks
for blk := range blkRevAt[vδf[len(vδf)-1].Rev] {
blkv = append(blkv, blk)
if l := len(vδf); l > 0 {
for blk := range blkRevAt[vδf[l-1].Rev] {
blkv = append(blkv, blk)
}
}
blkv = append(blkv, 1E4/*this block is hole*/)
blkv = append(blkv, 1E4/*this block is always hole*/)
sort.Slice(blkv, func(i, j int) bool {
return blkv[i] < blkv[j]
})
......
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