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