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
9003ac50
Commit
9003ac50
authored
Dec 17, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
5167f79c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
31 deletions
+41
-31
go/zodb/storage/fs1/filestorage.go
go/zodb/storage/fs1/filestorage.go
+41
-31
No files found.
go/zodb/storage/fs1/filestorage.go
View file @
9003ac50
...
...
@@ -71,6 +71,7 @@ import (
"log"
"os"
"sync"
"time"
"lab.nexedi.com/kirr/neo/go/zodb"
...
...
@@ -78,6 +79,7 @@ import (
"lab.nexedi.com/kirr/go123/xerr"
"github.com/fsnotify/fsnotify"
"github.com/pkg/errors"
)
// FileStorage is a ZODB storage which stores data in simple append-only file
...
...
@@ -98,7 +100,8 @@ type FileStorage struct {
txnhMin
TxnHeader
txnhMax
TxnHeader
watchq
chan
XXX
// driver client <- watcher: data file updates.
watchq
chan
interface
{}
// XXX
}
// IStorageDriver
...
...
@@ -447,13 +450,18 @@ func (fs *FileStorage) watcher() {
_
=
err
}
// watch watches updates to fs.file and notifies subscriber about new transaction via fs.watchq.
//
// watch is the only place that mutates index and txnh{Min,Max}.
// XXX ^^^ will change after commit is implemented.
func
(
fs
*
FileStorage
)
watch
()
(
err
error
)
{
f
:=
fs
.
file
idx
:=
fs
.
index
defer
xerr
.
Contextf
(
&
err
,
"%s: watch"
,
f
.
Name
())
// XXX race -> start watching before FileStorage is returned to user
// setup watcher to changes on f
// setup watcher to
observe
changes on f
w
,
err
:=
fsnotify
.
NewWatcher
()
if
err
!=
nil
{
return
err
...
...
@@ -469,34 +477,33 @@ func (fs *FileStorage) watch() (err error) {
//
// besides relying on notify we also check file periodically to avoid
// stalls due to e.g. OS notification errors.
toppos
:=
fs
.
index
.
TopPos
var
it
*
Iter
resetit
:=
func
()
{
// reset it to
start from toppos with empty buffer
it
=
Iterate
(
seqReadAt
(
f
),
topp
os
,
IterForward
)
itReset
:=
func
()
{
// reset it to (re)
start from toppos with empty buffer
it
=
Iterate
(
seqReadAt
(
f
),
idx
.
TopP
os
,
IterForward
)
}
reseti
t
()
itRese
t
()
tick
:=
time
.
NewTicker
(
1
*
time
.
Second
)
defer
tick
.
Stop
()
var
t
partWrite
time
.
Time
var
t
0partial
time
.
Time
for
{
// XXX select here
// check f size, to see whether there could be any updates.
fi
,
err
:=
f
.
Stat
()
if
err
!=
nil
{
return
err
}
fsize
:=
fi
.
Size
()
switch
{
case
fsize
==
topp
os
:
case
fsize
==
idx
.
TopP
os
:
continue
// same as before
case
fsize
<
topp
os
:
case
fsize
<
idx
.
TopP
os
:
// XXX add pack support
return
fmt
.
Errorf
(
"file truncated (%d -> %d)"
,
topp
os
,
fsize
)
return
fmt
.
Errorf
(
"file truncated (%d -> %d)"
,
idx
.
TopP
os
,
fsize
)
}
// there is some data after toppos - try to read it. always create buffer
// anew, since there could be written and then aborted transactions.
// there is some data after toppos - try to read it.
err
=
it
.
NextTxn
(
LoadNoStrings
)
if
err
!=
nil
{
// transaction header could not be fully read.
...
...
@@ -506,33 +513,34 @@ func (fs *FileStorage) watch() (err error) {
// region overlaps page boundary.
//
// we check for some time to distinguish in-progress write from just
// garbage.
//
trailing
garbage.
if
errors
.
Cause
(
err
)
==
io
.
ErrUnexpectedEOF
{
now
:=
time
.
Now
()
if
t
partWrite
.
IsZero
()
{
t
partWrite
=
now
}
else
if
now
.
Sub
(
t
partialStart
)
>
3
*
time
.
Second
{
return
err
if
t
0partial
.
IsZero
()
{
t
0partial
=
now
}
else
if
now
.
Sub
(
t
0partial
)
>
3
*
time
.
Second
{
return
err
// garbage
}
}
else
{
// not ok - e.g. IO error
// EOF is ok - it is e.g. when transaction was aborted
//
only
EOF is ok - it is e.g. when transaction was aborted
if
err
!=
io
.
EOF
{
return
err
}
// EOF - reset t(partial)
t
partWrite
=
time
.
Time
{}
// EOF - reset t
₀
(partial)
t
0partial
=
time
.
Time
{}
}
// after an error (EOF, partial read) we have to retry with
// after an
y
error (EOF, partial read) we have to retry with
// reset bufferring.
reseti
t
()
itRese
t
()
continue
}
tpartWrite
=
time
.
Time
{}
// reset
// read ok - reset t₀(partial)
t0partial
=
time
.
Time
{}
// XXX dup wrt Index.Update
...
...
@@ -540,8 +548,8 @@ func (fs *FileStorage) watch() (err error) {
// whether it is finished transaction or not.
if
it
.
Txnh
.
Status
==
zodb
.
TxnInprogress
{
// not yet. we have to reset because transaction finish writes
// what we have already buffered.
reseti
t
()
//
to
what we have already buffered.
itRese
t
()
continue
}
...
...
@@ -563,11 +571,15 @@ func (fs *FileStorage) watch() (err error) {
oidv
=
append
(
oidv
,
it
.
Datah
.
Oid
)
}
// update index
// update index
& txnh{MinMax}
fs
.
mu
.
Lock
()
i
nde
x
.
TopPos
=
it
.
Txnh
.
Pos
+
it
.
Txnh
.
Len
i
d
x
.
TopPos
=
it
.
Txnh
.
Pos
+
it
.
Txnh
.
Len
for
oid
,
pos
:=
range
update
{
index
.
Set
(
oid
,
pos
)
idx
.
Set
(
oid
,
pos
)
}
fs
.
txnhMax
.
CloneFrom
(
&
it
.
Txnh
)
if
fs
.
txnhMin
.
Len
==
0
{
// was empty
fs
.
txnhMin
.
CloneFrom
(
&
it
.
Txnh
)
}
fs
.
mu
.
Unlock
()
...
...
@@ -597,11 +609,9 @@ func (fs *FileStorage) watch() (err error) {
}
}
//func (fs *FileStorage) readUpdates() {
//}
func
(
fs
*
FileStorage
)
Watch
(
ctx
context
.
Context
)
(
zodb
.
Tid
,
[]
zodb
.
Oid
,
error
)
{
panic
(
"TODO"
)
// <-fs.watchq
}
// --- 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