Commit da05eb37 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 58b5b848
...@@ -281,7 +281,8 @@ package main ...@@ -281,7 +281,8 @@ package main
// - if retrieved successfully -> store retrieved data back into OS file // - if retrieved successfully -> store retrieved data back into OS file
// cache for @<rev>/bigfile/file[blk], where // cache for @<rev>/bigfile/file[blk], where
// //
// rev = max(δFtail.by(#blk)) || min(rev ∈ δFtail) || zhead.at ; see below about δFtail // # see below about file.δtail
// rev = max(file.δtail.by(#blk)) || min(rev ∈ file.δtail) || zhead.at
// //
// - invalidate head/bigfile/file[blk] in OS file cache. // - invalidate head/bigfile/file[blk] in OS file cache.
// //
...@@ -300,15 +301,17 @@ package main ...@@ -300,15 +301,17 @@ package main
// 5) after OS file cache was invalidated, we resync zhead to new database // 5) after OS file cache was invalidated, we resync zhead to new database
// view corresponding to tid. // view corresponding to tid.
// //
// 6) for every file δFtail invalidation info about head/data is maintained: // 6) for every file δtail invalidation info about head/data is maintained:
// //
// - tailv: [](rev↑, []#blk) // - tailv: [](rev↑, []#blk)
// - by: {} #blk -> []rev↑ in tail // - by: {} #blk -> []rev↑ in tail
// //
// δFtail.tail describes invalidations to file we learned from ZODB invalidation. // δtail.tail describes invalidations to file we learned from ZODB invalidation.
// δFtail.by allows to quickly lookup information by #blk. // δtail.by allows to quickly lookup information by #blk.
// //
// min(rev) in δFtail is min(@at) at which head/bigfile/file is currently mmapped (see below). // min(rev) in δtail is min(@at) at which head/bigfile/file is currently mmapped (see below).
//
// XXX δtail can miss ...
// //
// to support initial openings with @at being slightly in the past, we also // to support initial openings with @at being slightly in the past, we also
// make sure that min(rev) is enough to cover last 10 minutes of history // make sure that min(rev) is enough to cover last 10 minutes of history
...@@ -326,13 +329,13 @@ package main ...@@ -326,13 +329,13 @@ package main
// it is not exact because BTree/Bucket can change (e.g. rebalance) // it is not exact because BTree/Bucket can change (e.g. rebalance)
// but still point to the same k->ZBlk. // but still point to the same k->ZBlk.
// //
// we also use file.δFtail to find either exact blk revision: // we also use file.δtail to find either exact blk revision:
// //
// rev(blk) = max(file.δFtail.by(#blk) -> []rev↑) // rev(blk) = max(file.δtail.by(#blk) -> []rev↑)
// //
// or another upper bound if #blk ∉ δFtail: // or another upper bound if #blk ∉ δtail:
// //
// rev(blk) ≤ min(rev ∈ δFtail) ; #blk ∉ δFtail // rev(blk) ≤ min(rev ∈ δtail) ; #blk ∉ δtail
// //
// //
// below rev'(blk) is min(of the estimates found): // below rev'(blk) is min(of the estimates found):
...@@ -345,7 +348,7 @@ package main ...@@ -345,7 +348,7 @@ package main
// - rev'(blk) ≤ at: -> do nothing // - rev'(blk) ≤ at: -> do nothing
// - rev'(blk) > at: // - rev'(blk) > at:
// - if blk ∈ watcher.pinned -> do nothing // - if blk ∈ watcher.pinned -> do nothing
// - rev = max(δFtail.by(#blk) : _ ≤ at) || min(rev ∈ δFtail : rev ≤ at) || at // - rev = max(δtail.by(#blk) : _ ≤ at) || min(rev ∈ δtail : rev ≤ at) || at
// - watcher.pin(file, #blk, @rev) // - watcher.pin(file, #blk, @rev)
// - watcher.pinned += blk // - watcher.pinned += blk
// //
...@@ -513,7 +516,7 @@ type BigFile struct { ...@@ -513,7 +516,7 @@ type BigFile struct {
rev zodb.Tid // last revision that modified zfile data rev zodb.Tid // last revision that modified zfile data
// tail change history of this file. // tail change history of this file.
δFtail *ΔTailI64 // [](rev↑, []#blk) δtail *ΔTailI64 // [](rev↑, []#blk)
// inflight loadings of ZBigFile from ZODB. // inflight loadings of ZBigFile from ZODB.
// successful load results are kept here until blkdata is put into OS pagecache. // successful load results are kept here until blkdata is put into OS pagecache.
...@@ -919,7 +922,7 @@ func (f *BigFile) invalidateBlk(ctx context.Context, blk int64) (err error) { ...@@ -919,7 +922,7 @@ func (f *BigFile) invalidateBlk(ctx context.Context, blk int64) (err error) {
if int64(len(blkdata)) == blksize { if int64(len(blkdata)) == blksize {
func() { func() {
// store retrieved data back to OS cache for file @<rev>/file[blk] // store retrieved data back to OS cache for file @<rev>/file[blk]
blkrev, _ := f.δFtail.LastRevOf(blk, f.head.zconn.At()) blkrev, _ := f.δtail.LastRevOf(blk, f.head.zconn.At())
frev, frelease, err := groot.mkrevfile(blkrev, f.zfile.POid()) frev, frelease, err := groot.mkrevfile(blkrev, f.zfile.POid())
if err != nil { if err != nil {
log.Errorf("BUG: %s: invalidate blk #%d: %s (ignoring, but reading @revX/bigfile will be slow)", f.path(), blk, err) log.Errorf("BUG: %s: invalidate blk #%d: %s (ignoring, but reading @revX/bigfile will be slow)", f.path(), blk, err)
...@@ -1146,7 +1149,7 @@ func (f *BigFile) updateWatchers(ctx context.Context, blk int64, treepath []zodb ...@@ -1146,7 +1149,7 @@ func (f *BigFile) updateWatchers(ctx context.Context, blk int64, treepath []zodb
bfdir.indexLooked.Add(f, treepath) bfdir.indexLooked.Add(f, treepath)
bfdir.indexMu.Unlock() bfdir.indexMu.Unlock()
blkrevmax, _ := f.δFtail.LastRevOf(blk, f.zfile.PJar().At()) // XXX = f.head.zconn.At() blkrevmax, _ := f.δtail.LastRevOf(blk, f.zfile.PJar().At()) // XXX = f.head.zconn.At()
blkrevmax = tidmin(blkrevmax, pathRevMax) blkrevmax = tidmin(blkrevmax, pathRevMax)
wg, ctx := errgroup.WithContext(ctx) wg, ctx := errgroup.WithContext(ctx)
...@@ -1257,7 +1260,7 @@ func (w *Watch) pin(ctx context.Context, blk int64, rev zodb.Tid) (err error) { ...@@ -1257,7 +1260,7 @@ func (w *Watch) pin(ctx context.Context, blk int64, rev zodb.Tid) (err error) {
} }
// XXX comment // XXX comment
rev, _ = w.file.δFtail.LastRevOf(blk, w.at) rev, _ = w.file.δtail.LastRevOf(blk, w.at)
ack, err := w.link.sendReq(ctx, fmt.Sprintf("pin %s #%d @%s", foid, blk, rev)) ack, err := w.link.sendReq(ctx, fmt.Sprintf("pin %s #%d @%s", foid, blk, rev))
if err != nil { if err != nil {
...@@ -1272,7 +1275,9 @@ func (w *Watch) pin(ctx context.Context, blk int64, rev zodb.Tid) (err error) { ...@@ -1272,7 +1275,9 @@ func (w *Watch) pin(ctx context.Context, blk int64, rev zodb.Tid) (err error) {
return nil return nil
} }
// setupWatch sets up a Watch when client sends `watch <file> @<at>`. // setupWatch sets up a Watch when client sends `watch <file> @<at>` request.
//
// XXX called synchronously - only 1 setupWatch call at a time?
func (wlink *WatchLink) setupWatch(ctx context.Context, foid zodb.Oid, at zodb.Tid) (err error) { func (wlink *WatchLink) setupWatch(ctx context.Context, foid zodb.Oid, at zodb.Tid) (err error) {
defer xerr.Contextf(&err, "setup watch f<%s> @%s", foid, at) defer xerr.Contextf(&err, "setup watch f<%s> @%s", foid, at)
// XXX locking // XXX locking
...@@ -1294,6 +1299,22 @@ func (wlink *WatchLink) setupWatch(ctx context.Context, foid zodb.Oid, at zodb.T ...@@ -1294,6 +1299,22 @@ func (wlink *WatchLink) setupWatch(ctx context.Context, foid zodb.Oid, at zodb.T
} }
// XXX wait wlink.head.zconn.At() ≥ at // XXX wait wlink.head.zconn.At() ≥ at
// XXX <~> f.δtail.Head() ≥ at (?)
// XXX locking
if f.δtail.Tail() < at {
return fmt.Errorf("at is too far away back from head/at")
}
toPin := SetI64{} // f's blocks that have been changed after at
// XXX f.δtail.Head() not neccessarily = head.At()
// (if f was not changed by a txn, f.δtail stays not updated) XXX correct?
f.δtail.SliceByRev(at, f.δtail.Head())
panic("TODO") panic("TODO")
} }
...@@ -1609,7 +1630,7 @@ func (head *Head) bigopen(ctx context.Context, oid zodb.Oid) (_ *BigFile, err er ...@@ -1609,7 +1630,7 @@ func (head *Head) bigopen(ctx context.Context, oid zodb.Oid) (_ *BigFile, err er
rev: rev, rev: rev,
// XXX this is needed only for head/ // XXX this is needed only for head/
δFtail: NewΔTailI64(zconn.At()), δtail: NewΔTailI64(zconn.At()),
loading: make(map[int64]*blkLoadState), loading: make(map[int64]*blkLoadState),
} }
......
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