Commit 5db40e09 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c4532d1a
......@@ -70,6 +70,10 @@ type ΔFtail struct {
// data with δF changes. Actual for part of tracked set that was taken
// into account.
vδF []ΔF
// tracked ZBlk that are not yet taken into account in current vδF.
// grows on new track requests; flushes on queries and update.
trackNew map[*BigFile]map[zodb.Oid]*zblkInΔFtail // {} file -> {} oid -> zblk
}
// ΔF represents a change in files space.
......@@ -105,8 +109,9 @@ func (z *zblkInΔFtail) inΔFtail() *zblkInΔFtail { return z }
// Initial coverage of created ΔFtail is (at₀, at₀].
func NewΔFtail(at0 zodb.Tid) *ΔFtail {
return &ΔFtail{
δBtail: NewΔBtail(at0),
fileIdx: make(map[*btree.LOBTree]SetBigFile),
δBtail: NewΔBtail(at0),
fileIdx: make(map[*btree.LOBTree]SetBigFile),
trackNew: make(map[*BigFile]map[zodb.Oid]*zblkInΔFtail),
}
}
......@@ -149,6 +154,17 @@ func (δFtail *ΔFtail) Track(file *BigFile, blk int64, path []btree.LONode, zbl
}
blocks.Add(blk)
z.mu.Unlock()
// XXX locking
if !ok {
// zblk was not associated with this file
zt := δFtail.trackNew[file]
if zt == nil {
zt = make(map[zodb.Oid]*zblkInΔFtail, 1)
δFtail.trackNew[file] = zt
}
zt[zblk.POid()] = z
}
}
// XXX mark something dirty so that LastBlkRev and Slice* know what to rebuild?
......@@ -246,6 +262,50 @@ func (δFtail *ΔFtail) Update(δZ *zodb.EventCommit, zhead *ZConn) ΔF {
return δF
}
// update processes new track requests and updates vδF.
//
// If file != nil only track requests related to file are processed.
// Otherwise all track requests are processed.
func (δFtail *ΔFtail) update(file *BigFile) {
if file == nil {
panic("TODO")
}
// let's see if we need to rebuild .vδF due to not-yet processed track requests
// XXX locking
// XXX dumb
zt, dirty := δFtail.trackNew[file]
if !dirty {
return
}
delete(δFtail.trackNew, file)
// XXX unlock here
for i, δZ := range δFtail.δBtail.δZtail.Data() {
δF := δFtail.vδF[i]
// XXX assert δF.Rev == δZ.Rev
for _, oid := range δZ.Changev {
z, ok := zt[oid]
if !ok {
continue
}
// XXX locking
// XXX -> func δF.δfile(file) ?
δfile, ok := δF.ByFile[file]
if !ok {
δfile = &ΔFile{Rev: δF.Rev, Blocks: make(SetI64)}
δF.ByFile[file] = δfile
}
δfile.Blocks.Update(z.infile[file])
}
}
}
// ForgetPast discards all δFtail entries with rev ≤ revCut.
func (δFtail *ΔFtail) ForgetPast(revCut zodb.Tid) {
panic("TODO")
......@@ -270,6 +330,9 @@ func (δFtail *ΔFtail) SliceByRev(lo, hi zodb.Tid) /*readonly*/ []ΔF {
func (δFtail *ΔFtail) SliceByFileRev(file *BigFile, lo, hi zodb.Tid) /*readonly*/[]*ΔFile {
δassertSlice(δFtail, lo, hi)
// XXX locking?
δFtail.update(file)
// find vδF range corresponding to (lo, hi]
// XXX linear scan
vδF := δFtail.vδF
......
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