Commit cda8c398 authored by Kirill Smelkov's avatar Kirill Smelkov

.

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