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