Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joshua
wendelin.core
Commits
6b6f98c5
Commit
6b6f98c5
authored
Apr 16, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
08da1d81
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
35 deletions
+46
-35
wcfs/wcfs.go
wcfs/wcfs.go
+39
-29
wcfs/zblk.go
wcfs/zblk.go
+7
-6
No files found.
wcfs/wcfs.go
View file @
6b6f98c5
...
...
@@ -1101,7 +1101,7 @@ func (f *BigFile) readBlk(ctx context.Context, blk int64, dest []byte) (err erro
}
// noone was loading - we became responsible to load this block
blkdata
,
treepath
,
zblkrev
,
err
:=
f
.
zfile
.
LoadBlk
(
ctx
,
blk
)
blkdata
,
treepath
,
blkrevMax
,
err
:=
f
.
zfile
.
LoadBlk
(
ctx
,
blk
)
loading
.
blkdata
=
blkdata
loading
.
err
=
err
...
...
@@ -1116,7 +1116,7 @@ func (f *BigFile) readBlk(ctx context.Context, blk int64, dest []byte) (err erro
// we have the data - it can be used after watchers are updated
// XXX should we use ctx here? (see updateWatcher comments)
f
.
updateWatchers
(
ctx
,
blk
,
treepath
,
zblkrev
)
f
.
updateWatchers
(
ctx
,
blk
,
treepath
,
blkrevMax
)
// data can be used now
close
(
loading
.
ready
)
...
...
@@ -1153,8 +1153,7 @@ func (f *BigFile) readBlk(ctx context.Context, blk int64, dest []byte) (err erro
// XXX do we really need to use/propagate caller contex here? ideally update
// watchers should be synchronous, and in practice we just use 30s timeout.
// Should a READ interrupt cause watch update failure?
//func (f *BigFile) updateWatchers(ctx context.Context, blk int64, treepath []btree.LONode, pathRevMax zodb.Tid) {
func
(
f
*
BigFile
)
updateWatchers
(
ctx
context
.
Context
,
blk
int64
,
treepath
[]
btree
.
LONode
,
zblkrev
zodb
.
Tid
)
{
func
(
f
*
BigFile
)
updateWatchers
(
ctx
context
.
Context
,
blk
int64
,
treepath
[]
btree
.
LONode
,
blkrevMax
zodb
.
Tid
)
{
// only head/ is being watched for
if
f
.
head
.
rev
!=
0
{
return
...
...
@@ -1166,15 +1165,48 @@ func (f *BigFile) updateWatchers(ctx context.Context, blk int64, treepath []btre
bfdir
.
δFtail
.
Track
(
f
,
treepath
)
// XXX pass in zblk.oid / zblk.rev here?
bfdir
.
δFmu
.
Unlock
()
blkrev
,
_
:=
f
.
LastBlkRev
(
blk
,
f
.
head
.
zconn
.
At
())
// XXX ^^^ merge in zblkrev
// makes sure that file[blk] on clients side stays as of @w.at state.
// try to use blkrevMax only as the first cheap criteria to skip updating watchers.
// This is likely to be the case, since most watchers should be usually close to head.
// If using blkrevMax only turns out to be not sufficient, we'll
// consult δFtail, which might involve recomputing it.
blkrev
:=
blkrevMax
blkrevRough
:=
true
wg
,
ctx
:=
errgroup
.
WithContext
(
ctx
)
for
w
:=
range
f
.
watches
{
w
:=
w
// XXX locking
// the block is already covered by @w.at database view
if
blkrev
<=
w
.
at
{
continue
}
// if blkrev is rough estimation and that upper bound is > w.at
// we have to recompute ~exact file[blk] revision @head.
if
blkrevRough
{
blkrev
,
_
=
f
.
LastBlkRev
(
blk
,
f
.
head
.
zconn
.
At
())
blkrevRough
=
false
if
blkrev
<=
w
.
at
{
continue
}
}
// the block is newer - find out its revision as of @w.at and pin to that.
//
// We don't pin to w.at since if we would do so for several clients,
// and most of them would be on different w.at - cache of the file will
// be lost. Via pinning to particular block revision, we make sure the
// revision to pin is the same on all clients, and so file cache is shared.
pinrev
,
_
:=
w
.
file
.
LastBlkRev
(
blk
,
w
.
at
)
// XXX move into go?
wg
.
Go
(
func
()
error
{
// XXX close watcher on any error
return
w
.
pin
IfNewer
(
ctx
,
blk
,
blk
rev
)
return
w
.
pin
(
ctx
,
blk
,
pin
rev
)
})
}
err
:=
wg
.
Wait
()
...
...
@@ -1293,28 +1325,6 @@ func (w *Watch) pin(ctx context.Context, blk int64, rev zodb.Tid) (err error) {
return
nil
}
// pinIfNewer makes sure that file[blk] on client side stays as of @w.at state.
//
// rev is blk revision as of head. If rev > w.at the block is pinned on client side.
func
(
w
*
Watch
)
pinIfNewer
(
ctx
context
.
Context
,
blk
int64
,
rev
zodb
.
Tid
)
error
{
// XXX locking
// the block is already covered by @w.at database view
if
rev
<=
w
.
at
{
return
nil
}
// the block is newer - find out its revision as of @w.at and pin to that.
//
// We don't pin to w.at since if we would do so for several clients,
// and most of them would be on different w.at - cache of the file will
// be lost. Via pinning to particular block revision, we make sure the
// revision to pin is the same on all clients, and so file cache is shared.
rev
,
_
=
w
.
file
.
LastBlkRev
(
blk
,
w
.
at
)
return
w
.
pin
(
ctx
,
blk
,
rev
)
}
// setupWatch sets up a Watch when client sends `watch <file> @<at>` request.
//
// XXX sends "pin" notifications; final "ok" must be sent by caller.
...
...
wcfs/zblk.go
View file @
6b6f98c5
...
...
@@ -445,9 +445,10 @@ func (bf *zBigFileState) PySetState(pystate interface{}) (err error) {
//
// - BTree path in .blktab for loaded block,
// - max(_.serial for _ in ZBlk(#blk), all BTree/Bucket that lead to ZBlk)
// which provides a rough upper-bound estimate for file[blk] revision.
//
// XXX load into user-provided buf.
func
(
bf
*
ZBigFile
)
LoadBlk
(
ctx
context
.
Context
,
blk
int64
)
(
_
[]
byte
,
treePath
[]
btree
.
LONode
,
path
RevMax
zodb
.
Tid
,
err
error
)
{
func
(
bf
*
ZBigFile
)
LoadBlk
(
ctx
context
.
Context
,
blk
int64
)
(
_
[]
byte
,
treePath
[]
btree
.
LONode
,
blk
RevMax
zodb
.
Tid
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"bigfile %s: loadblk %d"
,
bf
.
POid
(),
blk
)
err
=
bf
.
PActivate
(
ctx
)
...
...
@@ -456,16 +457,16 @@ func (bf *ZBigFile) LoadBlk(ctx context.Context, blk int64) (_ []byte, treePath
}
defer
bf
.
PDeactivate
()
path
RevMax
=
0
blk
RevMax
=
0
xzblk
,
ok
,
err
:=
bf
.
blktab
.
VGet
(
ctx
,
blk
,
func
(
node
btree
.
LONode
)
{
treePath
=
append
(
treePath
,
node
)
pathRevMax
=
tidmax
(
path
RevMax
,
node
.
PSerial
())
blkRevMax
=
tidmax
(
blk
RevMax
,
node
.
PSerial
())
})
if
err
!=
nil
{
return
nil
,
nil
,
0
,
err
}
if
!
ok
{
return
make
([]
byte
,
bf
.
blksize
),
treePath
,
path
RevMax
,
nil
return
make
([]
byte
,
bf
.
blksize
),
treePath
,
blk
RevMax
,
nil
}
zblk
,
ok
:=
xzblk
.
(
zBlk
)
...
...
@@ -477,7 +478,7 @@ func (bf *ZBigFile) LoadBlk(ctx context.Context, blk int64) (_ []byte, treePath
if
err
!=
nil
{
return
nil
,
nil
,
0
,
err
}
pathRevMax
=
tidmax
(
path
RevMax
,
zblkrev
)
blkRevMax
=
tidmax
(
blk
RevMax
,
zblkrev
)
l
:=
int64
(
len
(
blkdata
))
if
l
>
bf
.
blksize
{
...
...
@@ -494,7 +495,7 @@ func (bf *ZBigFile) LoadBlk(ctx context.Context, blk int64) (_ []byte, treePath
zblk
.
bindZFile
(
bf
,
blk
)
//log.Printf("ZBigFile.loadblk(%d) -> %dB", blk, len(blkdata))
return
blkdata
,
treePath
,
path
RevMax
,
nil
return
blkdata
,
treePath
,
blk
RevMax
,
nil
}
// Size returns whole file size.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment