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

.

parent b54817e7
......@@ -23,7 +23,7 @@ package zdata
//
// It translates ZODB object-level changes to information about which blocks of
// 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
......@@ -96,7 +96,7 @@ type setOid = set.Oid
// 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
// 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.
//
// ΔFtail provides the following operations:
......@@ -122,12 +122,13 @@ 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 XXX -> root2file ?
byFile map[zodb.Oid]*_ΔFileTail // file -> vδf tail XXX
byFile map[zodb.Oid]*_ΔFileTail // file -> vδf tail
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
trackNew setOid // {}foid
// set of tracked ZBlk objects reverse-mapped to trees and block numbers
trackSetZBlk map[zodb.Oid]*zblkTrack // zblk -> {} root -> {}blk as of @head
}
......@@ -154,6 +155,7 @@ type zblkTrack struct {
inroot map[zodb.Oid]setI64 // {} root -> {}blk
}
// ΔF represents a change in files space.
type ΔF struct {
Rev zodb.Tid
......@@ -168,6 +170,7 @@ type ΔFile struct {
Size bool // whether file size changed
}
// NewΔFtail creates new ΔFtail object.
//
// Initial tracked set is empty.
......@@ -178,8 +181,8 @@ type ΔFile struct {
func NewΔFtail(at0 zodb.Tid, db *zodb.DB) *ΔFtail {
return &ΔFtail{
δBtail: xbtree.NewΔBtail(at0, db),
fileIdx: map[zodb.Oid]setOid{},
byFile: map[zodb.Oid]*_ΔFileTail{},
filesByRoot: map[zodb.Oid]setOid{},
trackNew: setOid{},
trackSetZBlk: map[zodb.Oid]*zblkTrack{},
}
......@@ -226,10 +229,10 @@ func (δFtail *ΔFtail) Track(file *ZBigFile, blk int64, path []btree.LONode, zb
rootObj := path[0].(*btree.LOBTree)
root := rootObj.POid()
files, ok := δFtail.fileIdx[root]
files, ok := δFtail.filesByRoot[root]
if !ok {
files = setOid{}
δFtail.fileIdx[root] = files
δFtail.filesByRoot[root] = files
}
files.Add(foid)
......@@ -420,7 +423,7 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
//fmt.Printf("δB.ΔByRoot: %v\n", δB.ΔByRoot)
for root, δt := range δB.ΔByRoot {
//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
// deleted, but the tree referenced by zfile.blktab is still
// not-deleted, remains tracked and is changed.
......@@ -484,7 +487,7 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
continue
}
//fmt.Printf("root: %v inblk: %v\n", root, inblk)
files := δFtail.fileIdx[root]
files := δFtail.filesByRoot[root]
for file := range files {
δfile, ok := δF.ByFile[file]
if !ok {
......@@ -510,21 +513,21 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit) (_ ΔF, err error) {
//fmt.Printf("δZBigFile: %v\n", δ)
// update .fileIdx
// update .filesByRoot
if δ.blktabOld != xbtree.VDEL {
files, ok := δFtail.fileIdx[δ.blktabOld]
files, ok := δFtail.filesByRoot[δ.blktabOld]
if ok {
files.Del(foid)
if len(files) == 0 {
delete(δFtail.fileIdx, δ.blktabOld)
delete(δFtail.filesByRoot, δ.blktabOld)
}
}
}
if δ.blktabNew != xbtree.VDEL {
files, ok := δFtail.fileIdx[δ.blktabNew]
files, ok := δFtail.filesByRoot[δ.blktabNew]
if !ok {
files = setOid{}
δFtail.fileIdx[δ.blktabNew] = files
δFtail.filesByRoot[δ.blktabNew] = files
}
files.Add(foid)
}
......
......@@ -485,14 +485,14 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
vδE = vδE[icut:]
}
// verify δFtail.fileIdx
fileIdxOK := map[zodb.Oid]setOid{}
// verify δFtail.filesByRoot
filesByRootOK := map[zodb.Oid]setOid{}
if !delfile {
__ := setOid{}; __.Add(foid)
fileIdxOK[t.Root()] = __
filesByRootOK[t.Root()] = __
}
if !reflect.DeepEqual(δFtail.fileIdx, fileIdxOK) {
t.Errorf("fileIdx:\nhave: %v\nwant: %v", δFtail.fileIdx, fileIdxOK)
if !reflect.DeepEqual(δFtail.filesByRoot, filesByRootOK) {
t.Errorf("filesByRoot:\nhave: %v\nwant: %v", δFtail.filesByRoot, filesByRootOK)
}
// 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