Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
083aed66
Commit
083aed66
authored
Dec 17, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
9003ac50
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
81 deletions
+91
-81
go/zodb/storage/fs1/filestorage.go
go/zodb/storage/fs1/filestorage.go
+91
-81
No files found.
go/zodb/storage/fs1/filestorage.go
View file @
083aed66
...
@@ -101,7 +101,7 @@ type FileStorage struct {
...
@@ -101,7 +101,7 @@ type FileStorage struct {
txnhMax
TxnHeader
txnhMax
TxnHeader
// driver client <- watcher: data file updates.
// driver client <- watcher: data file updates.
watchq
chan
interface
{}
// XXX
watchq
chan
watchEvent
}
}
// IStorageDriver
// IStorageDriver
...
@@ -450,14 +450,14 @@ func (fs *FileStorage) watcher() {
...
@@ -450,14 +450,14 @@ func (fs *FileStorage) watcher() {
_
=
err
_
=
err
}
}
// watch watches updates to
fs.file and notifies subscriber about new transaction via fs.watchq
.
// watch watches updates to
.file and notifies Watch about new transactions
.
//
//
// watch is the only place that mutates index and txnh{Min,Max}.
// watch is the only place that mutates index and txnh{Min,Max}.
// XXX ^^^ will change after commit is implemented.
// XXX ^^^ will change after commit is implemented.
func
(
fs
*
FileStorage
)
watch
()
(
err
error
)
{
func
(
fs
*
FileStorage
)
watch
()
(
err
error
)
{
f
:=
fs
.
file
f
:=
fs
.
file
idx
:=
fs
.
index
idx
:=
fs
.
index
defer
xerr
.
Contextf
(
&
err
,
"%s: watch"
,
f
.
Name
())
defer
xerr
.
Contextf
(
&
err
,
"%s: watch
er
"
,
f
.
Name
())
// XXX race -> start watching before FileStorage is returned to user
// XXX race -> start watching before FileStorage is returned to user
...
@@ -477,15 +477,10 @@ func (fs *FileStorage) watch() (err error) {
...
@@ -477,15 +477,10 @@ func (fs *FileStorage) watch() (err error) {
//
//
// besides relying on notify we also check file periodically to avoid
// besides relying on notify we also check file periodically to avoid
// stalls due to e.g. OS notification errors.
// stalls due to e.g. OS notification errors.
var
it
*
Iter
itReset
:=
func
()
{
// reset it to (re)start from toppos with empty buffer
it
=
Iterate
(
seqReadAt
(
f
),
idx
.
TopPos
,
IterForward
)
}
itReset
()
tick
:=
time
.
NewTicker
(
1
*
time
.
Second
)
tick
:=
time
.
NewTicker
(
1
*
time
.
Second
)
defer
tick
.
Stop
()
defer
tick
.
Stop
()
var
t0partial
time
.
Time
var
t0partial
time
.
Time
mainloop
:
for
{
for
{
// XXX select here
// XXX select here
...
@@ -503,7 +498,10 @@ func (fs *FileStorage) watch() (err error) {
...
@@ -503,7 +498,10 @@ func (fs *FileStorage) watch() (err error) {
return
fmt
.
Errorf
(
"file truncated (%d -> %d)"
,
idx
.
TopPos
,
fsize
)
return
fmt
.
Errorf
(
"file truncated (%d -> %d)"
,
idx
.
TopPos
,
fsize
)
}
}
// there is some data after toppos - try to read it.
// there is some data after toppos - try to advance as much as we can.
// start iterating afresh with empty buffer.
it
:=
Iterate
(
seqReadAt
(
f
),
idx
.
TopPos
,
IterForward
)
for
{
err
=
it
.
NextTxn
(
LoadNoStrings
)
err
=
it
.
NextTxn
(
LoadNoStrings
)
if
err
!=
nil
{
if
err
!=
nil
{
// transaction header could not be fully read.
// transaction header could not be fully read.
...
@@ -523,20 +521,17 @@ func (fs *FileStorage) watch() (err error) {
...
@@ -523,20 +521,17 @@ func (fs *FileStorage) watch() (err error) {
}
}
}
else
{
}
else
{
// not ok - e.g. IO error
// not ok - e.g. IO error
// only EOF is ok - it is e.g.
when transaction was aborted
// only EOF is ok - it can happen
when transaction was aborted
if
err
!=
io
.
EOF
{
if
err
!=
io
.
EOF
{
return
err
return
err
}
}
// EOF - reset t₀(partial)
// EOF - reset t₀(partial)
t0partial
=
time
.
Time
{}
t0partial
=
time
.
Time
{}
}
}
// after any error (EOF, partial read) we have to retry with
// after any error (EOF, partial read) we have to resync
// reset bufferring.
continue
mainloop
itReset
()
continue
}
}
// read ok - reset t₀(partial)
// read ok - reset t₀(partial)
...
@@ -547,10 +542,9 @@ func (fs *FileStorage) watch() (err error) {
...
@@ -547,10 +542,9 @@ func (fs *FileStorage) watch() (err error) {
// we could successfully read the transaction header. Try to see now,
// we could successfully read the transaction header. Try to see now,
// whether it is finished transaction or not.
// whether it is finished transaction or not.
if
it
.
Txnh
.
Status
==
zodb
.
TxnInprogress
{
if
it
.
Txnh
.
Status
==
zodb
.
TxnInprogress
{
// not yet. we have to reset
because transaction finish writes
// not yet. we have to resync
because transaction finish writes
// to what we have already buffered.
// to what we have already buffered.
itReset
()
continue
mainloop
continue
}
}
// it is fully-committed transaction. scan its data records to update
// it is fully-committed transaction. scan its data records to update
...
@@ -583,10 +577,12 @@ func (fs *FileStorage) watch() (err error) {
...
@@ -583,10 +577,12 @@ func (fs *FileStorage) watch() (err error) {
}
}
fs
.
mu
.
Unlock
()
fs
.
mu
.
Unlock
()
// XXX -> watchq
// XXX cancel on close
fs
.
watchq
<-
watchEvent
{
it
.
Txnh
.
Tid
,
oidv
}
}
select
{
select
{
// XXX handle
quit
// XXX handle
close
case
err
:=
<-
w
.
Errors
:
case
err
:=
<-
w
.
Errors
:
if
err
==
fsnotify
.
ErrEventOverflow
{
if
err
==
fsnotify
.
ErrEventOverflow
{
...
@@ -609,9 +605,23 @@ func (fs *FileStorage) watch() (err error) {
...
@@ -609,9 +605,23 @@ func (fs *FileStorage) watch() (err error) {
}
}
}
}
func
(
fs
*
FileStorage
)
Watch
(
ctx
context
.
Context
)
(
zodb
.
Tid
,
[]
zodb
.
Oid
,
error
)
{
// watchEvent is one event from watch to Watch
panic
(
"TODO"
)
type
watchEvent
struct
{
// <-fs.watchq
tid
zodb
.
Tid
oidv
[]
zodb
.
Oid
}
func
(
fs
*
FileStorage
)
Watch
(
ctx
context
.
Context
)
(
_
zodb
.
Tid
,
_
[]
zodb
.
Oid
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"%s: watch"
,
fs
.
file
.
Name
())
// XXX handle close
select
{
case
<-
ctx
.
Done
()
:
return
zodb
.
InvalidTid
,
nil
,
ctx
.
Err
()
case
w
:=
<-
fs
.
watchq
:
return
w
.
tid
,
w
.
oidv
,
nil
}
}
}
// --- open + rebuild index ---
// --- open + rebuild index ---
...
...
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