Commit 5feee2b8 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 92543fae
...@@ -55,15 +55,25 @@ type Storage struct { ...@@ -55,15 +55,25 @@ type Storage struct {
// baseMutatedError is reported when Storage.base is detected to change. // baseMutatedError is reported when Storage.base is detected to change.
type baseMutatedError struct { type baseMutatedError struct {
baseAt0 zodb.Tid baseAt0 zodb.Tid
// baseHead zodb.Tid baseHead zodb.Tid
baseEvent zodb.Event
} }
func (e *baseMutatedError) Error() string { func (e *baseMutatedError) Error() string {
// return fmt.Sprintf("base.head mutated from @%s to @%s", e.baseAt0, e.baseHead) return fmt.Sprintf("base.head mutated from @%s to @%s", e.baseAt0, e.baseHead)
return fmt.Sprintf("base mutated from @%s: %s", e.baseAt0, e.baseEvent)
} }
// baseError is reported on error detected on Storage.base .
type baseError struct {
err error
}
func (e *baseError) Error() string {
return fmt.Sprintf("base: error: %s", e.err)
}
func (e *baseError) Cause() error { return e.err }
func (e *baseError) Unwrap() error { return e.err }
// watcher detects base mutation and proxies δ events to user. // watcher detects base mutation and proxies δ events to user.
// it runs as separate goroutine. // it runs as separate goroutine.
func (d *Storage) watcher(ctx context.Context) error { func (d *Storage) watcher(ctx context.Context) error {
...@@ -85,7 +95,18 @@ func (d *Storage) watcher(ctx context.Context) error { ...@@ -85,7 +95,18 @@ func (d *Storage) watcher(ctx context.Context) error {
continue continue
} }
edown := &baseMutatedError{d.baseAt0, event} var edown error
switch event := event.(type) {
case *zodb.EventCommit:
edown = &baseMutatedError{d.baseAt0, event.Tid}
case *zodb.EventError:
edown = &baseError{event.Err}
default:
edown = fmt.Errorf("base: unexpected event %T", event)
}
ev := &zodb.EventError{edown} // XXX + context ev := &zodb.EventError{edown} // XXX + context
if d.watchq != nil { if d.watchq != nil {
d.watchq <- ev d.watchq <- ev
...@@ -101,6 +122,7 @@ func (d *Storage) watcher(ctx context.Context) error { ...@@ -101,6 +122,7 @@ func (d *Storage) watcher(ctx context.Context) error {
continue continue
} }
// XXX +select on close
d.watchq <- event // !nil becase d.δWatchq != nil d.watchq <- event // !nil becase d.δWatchq != nil
} }
} }
...@@ -143,7 +165,7 @@ func (d *Storage) Sync(ctx context.Context) (_ zodb.Tid, err error) { ...@@ -143,7 +165,7 @@ func (d *Storage) Sync(ctx context.Context) (_ zodb.Tid, err error) {
return err return err
} }
if baseHead != d.baseAt0 { if baseHead != d.baseAt0 {
return &baseMutatedError{d.baseAt0, fmt.Errorf("to @%s", baseHead)} return &baseMutatedError{d.baseAt0, baseHead}
} }
return nil return nil
}) })
......
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