Commit cda8c398 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 00bb8991
......@@ -62,6 +62,7 @@ package zdata
// Concurrency
//
// XXX
// XXX note about SliceByFileRev Zinblk snapshotting
import (
"context"
......@@ -138,10 +139,10 @@ type ΔFtail struct {
// ΔFtail merges ΔBtail with history of ZBlk
δBtail *xbtree.ΔBtail
// mu protects ΔFtail data _and_ all _ΔFileTail data for all files.
// mu protects ΔFtail data _and_ all _ΔFileTail/_RootTrack data for all files and roots.
//
// NOTE: even though this lock is global, since ... XXX
// working with retrieved vδE snapshot(?) does not need to hold the lock.
// NOTE: even though this lock is global it is used only for brief periouds of time. In
// particular working with retrieved vδE and Zinblk snapshot does not need to hold the lock.
mu sync.Mutex
byFile map[zodb.Oid]*_ΔFileTail // file -> vδf tail
......@@ -150,9 +151,8 @@ type ΔFtail struct {
// set of files, which are newly tracked and for which byFile[foid].vδE was not yet rebuilt
ftrackNew setOid // {}foid
// set of tracked ZBlk objects mapped to trees as of @head
// XXX -> ztrackInRoot ?
zinroot map[zodb.Oid]setOid // {} zblk -> {}root
// set of tracked ZBlk objects mapped to tree roots as of @head
ztrackInRoot map[zodb.Oid]setOid // {} zblk -> {}root
}
// _ΔFileTail represents tail of revisional changes to one file.
......@@ -171,17 +171,14 @@ type _ΔFileEpoch struct {
oldBlkSize int64 // .blksize was oldBlkSize ; -1 if ZBigFile deleted
newBlkSize int64 // .blksize was changed to newBlkSize ; ----//----
// snapshot of trackSetZBlk for this file right before this epoch
// snapshot of ztrackInBlk for this file right before this epoch
oldZinblk map[zodb.Oid]setI64 // {} zblk -> {}blk
}
// _RootTrack represents tracking information about one particular tree as of @head.
// XXX -> _TreeTrack ? _BlktabTrack ?
type _RootTrack struct {
// XXX -> ftrackSet ?
files setOid // {}foid which ZBigFiles refer to this tree
// XXX -> ztrackInBlk ? trackZInblk ?
Zinblk map[zodb.Oid]setI64 // {} zblk -> {}blk which blocks map to zblk
ftrackSet setOid // {}foid which ZBigFiles refer to this tree
ztrackInBlk map[zodb.Oid]setI64 // {} zblk -> {}blk which blocks map to zblk
}
// _RebuildJob represents currently in-progress vδE rebuilding job.
......@@ -215,11 +212,11 @@ type ΔFile struct {
// ZODB when needed.
func NewΔFtail(at0 zodb.Tid, db *zodb.DB) *ΔFtail {
return &ΔFtail{
δBtail: xbtree.NewΔBtail(at0, db),
byFile: map[zodb.Oid]*_ΔFileTail{},
byRoot: map[zodb.Oid]*_RootTrack{},
ftrackNew: setOid{},
zinroot: map[zodb.Oid]setOid{},
δBtail: xbtree.NewΔBtail(at0, db),
byFile: map[zodb.Oid]*_ΔFileTail{},
byRoot: map[zodb.Oid]*_RootTrack{},
ftrackNew: setOid{},
ztrackInRoot: map[zodb.Oid]setOid{},
}
}
......@@ -266,12 +263,12 @@ func (δFtail *ΔFtail) Track(file *ZBigFile, blk int64, path []btree.LONode, bl
rt, ok := δFtail.byRoot[root]
if !ok {
rt = &_RootTrack{
files: setOid{},
Zinblk: map[zodb.Oid]setI64{},
ftrackSet: setOid{},
ztrackInBlk: map[zodb.Oid]setI64{},
}
δFtail.byRoot[root] = rt
}
rt.files.Add(foid)
rt.ftrackSet.Add(foid)
δftail, ok := δFtail.byFile[foid]
if !ok {
......@@ -289,17 +286,17 @@ func (δFtail *ΔFtail) Track(file *ZBigFile, blk int64, path []btree.LONode, bl
if zblk != nil {
zoid := zblk.POid()
inroot, ok := δFtail.zinroot[zoid]
inroot, ok := δFtail.ztrackInRoot[zoid]
if !ok {
inroot = make(setOid, 1)
δFtail.zinroot[zoid] = inroot
δFtail.ztrackInRoot[zoid] = inroot
}
inroot.Add(root)
inblk, ok := rt.Zinblk[zoid]
inblk, ok := rt.ztrackInBlk[zoid]
if !ok {
inblk = make(setI64, 1)
rt.Zinblk[zoid] = inblk
rt.ztrackInBlk[zoid] = inblk
}
inblk.Add(blk)
}
......@@ -435,20 +432,21 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
rt, ok := δFtail.byRoot[δftail.root]
if ok {
for zoid, inblk := range rt.Zinblk {
for zoid, inblk := range rt.ztrackInBlk {
δE.oldZinblk[zoid] = inblk.Clone()
inroot, ok := δFtail.zinroot[zoid]
inroot, ok := δFtail.ztrackInRoot[zoid]
if ok {
inroot.Del(δftail.root)
if len(inroot) == 0 {
delete(δFtail.zinroot, zoid)
delete(δFtail.ztrackInRoot, zoid)
}
}
}
}
δftail.root = δE.newRoot
δftail.vδE = append(δftail.vδE, δE) // XXX note that we do not change older snapshots
// NOTE no need to clone vδE: we are writer, vδE is not returned to outside
δftail.vδE = append(δftail.vδE, δE)
}
}
......@@ -464,7 +462,7 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
continue
}
for file := range rt.files {
for file := range rt.ftrackSet {
δfile, ok := δF.ByFile[file]
if !ok {
δfile = &ΔFile{Rev: δF.Rev, Blocks: make(setI64)}
......@@ -481,32 +479,32 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
δfile.Size = true
}
// update Zinblk according to btree changes
// update ztrackInBlk according to btree changes
for blk, δzblk := range δt {
if δzblk.Old != xbtree.VDEL {
inblk, ok := rt.Zinblk[δzblk.Old]
inblk, ok := rt.ztrackInBlk[δzblk.Old]
if ok {
inblk.Del(blk)
if len(inblk) == 0 {
delete(rt.Zinblk, δzblk.Old)
inroot := δFtail.zinroot[δzblk.Old]
delete(rt.ztrackInBlk, δzblk.Old)
inroot := δFtail.ztrackInRoot[δzblk.Old]
inroot.Del(root)
if len(inroot) == 0 {
delete(δFtail.zinroot, δzblk.Old)
delete(δFtail.ztrackInRoot, δzblk.Old)
}
}
}
}
if δzblk.New != xbtree.VDEL {
inblk, ok := rt.Zinblk[δzblk.New]
inblk, ok := rt.ztrackInBlk[δzblk.New]
if !ok {
inblk = make(setI64, 1)
rt.Zinblk[δzblk.New] = inblk
inroot, ok := δFtail.zinroot[δzblk.New]
rt.ztrackInBlk[δzblk.New] = inblk
inroot, ok := δFtail.ztrackInRoot[δzblk.New]
if !ok {
inroot = make(setOid, 1)
δFtail.zinroot[δzblk.New] = inroot
δFtail.ztrackInRoot[δzblk.New] = inroot
}
inroot.Add(root)
}
......@@ -517,19 +515,19 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
// take zblk changes into account
for _, oid := range δZ.Changev {
inroot, ok := δFtail.zinroot[oid]
inroot, ok := δFtail.ztrackInRoot[oid]
if !ok {
continue // not tracked
}
for root := range inroot {
rt := δFtail.byRoot[root] // must be there
inblk, ok := rt.Zinblk[oid]
inblk, ok := rt.ztrackInBlk[oid]
if !ok || len(inblk) == 0 {
continue
}
//fmt.Printf("root: %v inblk: %v\n", root, inblk)
for file := range rt.files {
for file := range rt.ftrackSet {
δfile, ok := δF.ByFile[file]
if !ok {
δfile = &ΔFile{Rev: δF.Rev, Blocks: make(setI64)}
......@@ -558,8 +556,8 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
if δ.blktabOld != xbtree.VDEL {
rt, ok := δFtail.byRoot[δ.blktabOld]
if ok {
rt.files.Del(foid)
if len(rt.files) == 0 {
rt.ftrackSet.Del(foid)
if len(rt.ftrackSet) == 0 {
delete(δFtail.byRoot, δ.blktabOld)
// XXX reset Zinroot -= δ.blktabNew
}
......@@ -569,13 +567,13 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
rt, ok := δFtail.byRoot[δ.blktabNew]
if !ok {
rt = &_RootTrack{
files: setOid{},
Zinblk: map[zodb.Oid]setI64{},
ftrackSet: setOid{},
ztrackInBlk: map[zodb.Oid]setI64{},
// XXX reset Zinroot -= δ.blktabNew
}
δFtail.byRoot[δ.blktabNew] = rt
}
rt.files.Add(foid)
rt.ftrackSet.Add(foid)
}
}
......@@ -752,7 +750,7 @@ func (δFtail *ΔFtail) SliceByFileRev(zfile *ZBigFile, lo, hi zodb.Tid) /*reado
rt, ok := δFtail.byRoot[root]
if ok {
for oid := range δZAllOid {
inblk, ok := rt.Zinblk[oid]
inblk, ok := rt.ztrackInBlk[oid]
if ok {
ZinblkSnap[oid] = inblk.Clone()
}
......
......@@ -452,7 +452,7 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
// verify byRoot
trackRfiles := map[zodb.Oid]setOid{}
for root, rt := range δFtail.byRoot {
trackRfiles[root] = rt.files
trackRfiles[root] = rt.ftrackSet
}
filesOK := setOid{}
if !delfile {
......@@ -468,7 +468,7 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
// verify Zinroot
trackZinroot := map[string]setOid{}
for zoid, inroot := range δFtail.zinroot {
for zoid, inroot := range δFtail.ztrackInRoot {
zblki := commit.ZBlkTab[zoid]
trackZinroot[zblki.Name] = inroot.Clone() // XXX clone needed?
}
......@@ -492,7 +492,7 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
if !ok {
t.Errorf(".byRoot points to unexpected blktab")
} else {
for zoid, inblk := range rt.Zinblk {
for zoid, inblk := range rt.ztrackInBlk {
zblki := commit.ZBlkTab[zoid]
trackZinblk[zblki.Name] = inblk.Clone() // XXX clone needed?
}
......
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