Commit 3c6aaea6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b54817e7
...@@ -23,7 +23,7 @@ package zdata ...@@ -23,7 +23,7 @@ package zdata
// //
// It translates ZODB object-level changes to information about which blocks of // It translates ZODB object-level changes to information about which blocks of
// which ZBigFile were modified, and provides service to query that information. // which ZBigFile were modified, and provides service to query that information.
// See ΔFtail class documentation for details. // See ΔFtail class documentation for usage details.
// //
// //
// ΔFtail organization // ΔFtail organization
...@@ -96,7 +96,7 @@ type setOid = set.Oid ...@@ -96,7 +96,7 @@ type setOid = set.Oid
// tracked, even if it was changed in δZ, is not guaranteed to be present in δF. // tracked, even if it was changed in δZ, is not guaranteed to be present in δF.
// //
// After file epoch (file creation, deletion, or any other change to file // After file epoch (file creation, deletion, or any other change to file
// object) previous track requests for that file become forgotten and has no // object) previous track requests for that file become forgotten and have no
// further effect. // further effect.
// //
// ΔFtail provides the following operations: // ΔFtail provides the following operations:
...@@ -121,14 +121,15 @@ type setOid = set.Oid ...@@ -121,14 +121,15 @@ type setOid = set.Oid
// See also zodb.ΔTail and xbtree.ΔBtail // See also zodb.ΔTail and xbtree.ΔBtail
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 XXX -> root2file ? byFile map[zodb.Oid]*_ΔFileTail // file -> vδf tail
byFile map[zodb.Oid]*_ΔFileTail // file -> vδf tail XXX filesByRoot map[zodb.Oid]setOid // tree-root -> {} ZBigFile<oid> as of @head
// 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
trackNew setOid // {}foid trackNew setOid // {}foid
trackSetZBlk map[zodb.Oid]*zblkTrack // zblk -> {} root -> {}blk as of @head // set of tracked ZBlk objects reverse-mapped to trees and block numbers
trackSetZBlk map[zodb.Oid]*zblkTrack // zblk -> {} root -> {}blk as of @head
} }
// _ΔFileTail represents tail of revisional changes to one file. // _ΔFileTail represents tail of revisional changes to one file.
...@@ -154,6 +155,7 @@ type zblkTrack struct { ...@@ -154,6 +155,7 @@ type zblkTrack struct {
inroot map[zodb.Oid]setI64 // {} root -> {}blk inroot map[zodb.Oid]setI64 // {} root -> {}blk
} }
// ΔF represents a change in files space. // ΔF represents a change in files space.
type ΔF struct { type ΔF struct {
Rev zodb.Tid Rev zodb.Tid
...@@ -168,6 +170,7 @@ type ΔFile struct { ...@@ -168,6 +170,7 @@ type ΔFile struct {
Size bool // whether file size changed Size bool // whether file size changed
} }
// NewΔFtail creates new ΔFtail object. // NewΔFtail creates new ΔFtail object.
// //
// Initial tracked set is empty. // Initial tracked set is empty.
...@@ -178,8 +181,8 @@ type ΔFile struct { ...@@ -178,8 +181,8 @@ type ΔFile struct {
func NewΔFtail(at0 zodb.Tid, db *zodb.DB) *ΔFtail { 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{},
byFile: map[zodb.Oid]*_ΔFileTail{}, byFile: map[zodb.Oid]*_ΔFileTail{},
filesByRoot: map[zodb.Oid]setOid{},
trackNew: setOid{}, trackNew: setOid{},
trackSetZBlk: map[zodb.Oid]*zblkTrack{}, trackSetZBlk: map[zodb.Oid]*zblkTrack{},
} }
...@@ -226,10 +229,10 @@ func (δFtail *ΔFtail) Track(file *ZBigFile, blk int64, path []btree.LONode, zb ...@@ -226,10 +229,10 @@ func (δFtail *ΔFtail) Track(file *ZBigFile, blk int64, path []btree.LONode, zb
rootObj := path[0].(*btree.LOBTree) rootObj := path[0].(*btree.LOBTree)
root := rootObj.POid() root := rootObj.POid()
files, ok := δFtail.fileIdx[root] files, ok := δFtail.filesByRoot[root]
if !ok { if !ok {
files = setOid{} files = setOid{}
δFtail.fileIdx[root] = files δFtail.filesByRoot[root] = files
} }
files.Add(foid) files.Add(foid)
...@@ -420,7 +423,7 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) { ...@@ -420,7 +423,7 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
//fmt.Printf("δB.ΔByRoot: %v\n", δB.ΔByRoot) //fmt.Printf("δB.ΔByRoot: %v\n", δB.ΔByRoot)
for root, δt := range δB.ΔByRoot { for root, δt := range δB.ΔByRoot {
//fmt.Printf("root: %v δt: %v\n", root, δt) //fmt.Printf("root: %v δt: %v\n", root, δt)
files := δFtail.fileIdx[root] files := δFtail.filesByRoot[root]
// NOTE files might be empty e.g. if a zfile was tracked, then // NOTE files might be empty e.g. if a zfile was tracked, then
// deleted, but the tree referenced by zfile.blktab is still // deleted, but the tree referenced by zfile.blktab is still
// not-deleted, remains tracked and is changed. // not-deleted, remains tracked and is changed.
...@@ -484,7 +487,7 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) { ...@@ -484,7 +487,7 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
continue continue
} }
//fmt.Printf("root: %v inblk: %v\n", root, inblk) //fmt.Printf("root: %v inblk: %v\n", root, inblk)
files := δFtail.fileIdx[root] files := δFtail.filesByRoot[root]
for file := range files { for file := range files {
δfile, ok := δF.ByFile[file] δfile, ok := δF.ByFile[file]
if !ok { if !ok {
...@@ -510,21 +513,21 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) { ...@@ -510,21 +513,21 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
//fmt.Printf("δZBigFile: %v\n", δ) //fmt.Printf("δZBigFile: %v\n", δ)
// update .fileIdx // update .filesByRoot
if δ.blktabOld != xbtree.VDEL { if δ.blktabOld != xbtree.VDEL {
files, ok := δFtail.fileIdx[δ.blktabOld] files, ok := δFtail.filesByRoot[δ.blktabOld]
if ok { if ok {
files.Del(foid) files.Del(foid)
if len(files) == 0 { if len(files) == 0 {
delete(δFtail.fileIdx, δ.blktabOld) delete(δFtail.filesByRoot, δ.blktabOld)
} }
} }
} }
if δ.blktabNew != xbtree.VDEL { if δ.blktabNew != xbtree.VDEL {
files, ok := δFtail.fileIdx[δ.blktabNew] files, ok := δFtail.filesByRoot[δ.blktabNew]
if !ok { if !ok {
files = setOid{} files = setOid{}
δFtail.fileIdx[δ.blktabNew] = files δFtail.filesByRoot[δ.blktabNew] = files
} }
files.Add(foid) files.Add(foid)
} }
......
...@@ -485,14 +485,14 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) { ...@@ -485,14 +485,14 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
vδE = vδE[icut:] vδE = vδE[icut:]
} }
// verify δFtail.fileIdx // verify δFtail.filesByRoot
fileIdxOK := map[zodb.Oid]setOid{} filesByRootOK := map[zodb.Oid]setOid{}
if !delfile { if !delfile {
__ := setOid{}; __.Add(foid) __ := setOid{}; __.Add(foid)
fileIdxOK[t.Root()] = __ filesByRootOK[t.Root()] = __
} }
if !reflect.DeepEqual(δFtail.fileIdx, fileIdxOK) { if !reflect.DeepEqual(δFtail.filesByRoot, filesByRootOK) {
t.Errorf("fileIdx:\nhave: %v\nwant: %v", δFtail.fileIdx, fileIdxOK) t.Errorf("filesByRoot:\nhave: %v\nwant: %v", δFtail.filesByRoot, filesByRootOK)
} }
// verify δftail.root // verify δftail.root
......
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