Commit dc1ad0d9 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 26e8e3d3
...@@ -507,8 +507,8 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) ( ...@@ -507,8 +507,8 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (
return nil, fmt.Errorf("neo: %s: TODO write mode not implemented", u) return nil, fmt.Errorf("neo: %s: TODO write mode not implemented", u)
} }
// XXX handle opt.WatchQ // XXX handle opt.Watchq
if opt.WatchQ != nil { if opt.Watchq != nil {
panic("TODO watchq") panic("TODO watchq")
} }
......
...@@ -49,7 +49,7 @@ type Backend struct { ...@@ -49,7 +49,7 @@ type Backend struct {
var _ storage.Backend = (*Backend)(nil) var _ storage.Backend = (*Backend)(nil)
func Open(ctx context.Context, path string) (*Backend, error) { func Open(ctx context.Context, path string) (*Backend, error) {
zstor, err := fs1.Open(ctx, path) zstor, err := fs1.Open(ctx, path, &zodb.DriverOptions{ReadOnly: true}) // XXX RO? +Watchq?
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
"context" "context"
"math" "math"
"lab.nexedi.com/kirr/neo/go/zodb"
zfs1 "lab.nexedi.com/kirr/neo/go/zodb/storage/fs1" zfs1 "lab.nexedi.com/kirr/neo/go/zodb/storage/fs1"
bfs1 "lab.nexedi.com/kirr/neo/go/neo/storage/fs1" bfs1 "lab.nexedi.com/kirr/neo/go/neo/storage/fs1"
"lab.nexedi.com/kirr/go123/exc" "lab.nexedi.com/kirr/go123/exc"
...@@ -40,7 +41,7 @@ func gox(wg interface { Go(func() error) }, xf func()) { ...@@ -40,7 +41,7 @@ func gox(wg interface { Go(func() error) }, xf func()) {
} }
func xfs1stor(path string) *zfs1.FileStorage { func xfs1stor(path string) *zfs1.FileStorage {
stor, err := zfs1.Open(bg, path) stor, err := zfs1.Open(bg, path, &zodb.DriverOptions{ReadOnly: true}) // XXX opts = ?
exc.Raiseif(err) exc.Raiseif(err)
return stor return stor
} }
......
...@@ -40,12 +40,13 @@ type DriverOptions struct { ...@@ -40,12 +40,13 @@ type DriverOptions struct {
ReadOnly bool // whether to open storage as read-only ReadOnly bool // whether to open storage as read-only
// Channel where watched storage events have to be delivered. // Channel where watched storage events have to be delivered.
// WatchQ can be nil to ignore such events. However if WatchQ != nil, the events //
// Watchq can be nil to ignore such events. However if Watchq != nil, the events
// have to be consumed or else the storage driver will misbehave - e.g. // have to be consumed or else the storage driver will misbehave - e.g.
// it can get out of sync with the on-disk database file. // it can get out of sync with the on-disk database file.
// //
// XXX the channel will be closed after ... ? // The storage driver closes !nil Watchq when the driver is closed.
WatchQ chan WatchEvent Watchq chan<- WatchEvent
} }
// DriverOpener is a function to open a storage driver. // DriverOpener is a function to open a storage driver.
......
...@@ -97,7 +97,7 @@ type FileStorage struct { ...@@ -97,7 +97,7 @@ type FileStorage struct {
txnhMax TxnHeader // (both with .Len=0 & .Tid=0 if database is empty) txnhMax TxnHeader // (both with .Len=0 & .Tid=0 if database is empty)
// driver client <- watcher: data file updates. // driver client <- watcher: data file updates.
watchq chan zodb.WatchEvent watchq chan<- zodb.WatchEvent
down chan struct{} // ready when FileStorage is no longer operational down chan struct{} // ready when FileStorage is no longer operational
downOnce sync.Once downOnce sync.Once
...@@ -464,6 +464,10 @@ func (fs *FileStorage) watcher(w *fsnotify.Watcher) { ...@@ -464,6 +464,10 @@ func (fs *FileStorage) watcher(w *fsnotify.Watcher) {
if err != nil { if err != nil {
log.Print(err) log.Print(err)
} }
if fs.watchq != nil {
close(fs.watchq)
}
} }
func (fs *FileStorage) _watcher(w *fsnotify.Watcher) (err error) { func (fs *FileStorage) _watcher(w *fsnotify.Watcher) (err error) {
...@@ -666,7 +670,7 @@ func Open(ctx context.Context, path string, opt *zodb.DriverOptions) (_ *FileSto ...@@ -666,7 +670,7 @@ func Open(ctx context.Context, path string, opt *zodb.DriverOptions) (_ *FileSto
} }
fs := &FileStorage{ fs := &FileStorage{
watchq: opt.WatchQ, watchq: opt.Watchq,
down: make(chan struct{}), down: make(chan struct{}),
} }
......
...@@ -426,7 +426,7 @@ func TestWatch(t *testing.T) { ...@@ -426,7 +426,7 @@ func TestWatch(t *testing.T) {
at := xcommit(0, Object{0, "data0"}) at := xcommit(0, Object{0, "data0"})
watchq := make(chan zodb.WatchEvent) watchq := make(chan zodb.WatchEvent)
fs := xfsopenopt(t, tfs, &zodb.DriverOptions{ReadOnly: true, WatchQ: watchq}) fs := xfsopenopt(t, tfs, &zodb.DriverOptions{ReadOnly: true, Watchq: watchq})
ctx := context.Background() ctx := context.Background()
checkLastTid := func(lastOk zodb.Tid) { checkLastTid := func(lastOk zodb.Tid) {
...@@ -471,8 +471,10 @@ func TestWatch(t *testing.T) { ...@@ -471,8 +471,10 @@ func TestWatch(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
e := <-watchq e, ok := <-watchq
_ = e if ok {
t.Fatalf("watch after close -> %v; want closed", e)
}
_ = errors.Cause(nil) _ = errors.Cause(nil)
// XXX e.Err == ErrClosed // XXX e.Err == ErrClosed
......
...@@ -310,8 +310,8 @@ func openByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (_ zodb ...@@ -310,8 +310,8 @@ func openByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (_ zodb
return nil, fmt.Errorf("TODO write mode not implemented") return nil, fmt.Errorf("TODO write mode not implemented")
} }
// XXX handle opt.WatchQ // XXX handle opt.Watchq
if opt.WatchQ != nil { if opt.Watchq != nil {
panic("TODO watchq") panic("TODO watchq")
} }
......
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