Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
5feee2b8
Commit
5feee2b8
authored
Mar 17, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
92543fae
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
6 deletions
+28
-6
go/zodb/storage/demo/demo.go
go/zodb/storage/demo/demo.go
+28
-6
No files found.
go/zodb/storage/demo/demo.go
View file @
5feee2b8
...
@@ -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
})
})
...
...
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