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
5feee2b8
Commit
5feee2b8
authored
Mar 17, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
92543fae
Changes
1
Hide 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 {
// baseMutatedError is reported when Storage.base is detected to change.
type
baseMutatedError
struct
{
baseAt0
zodb
.
Tid
// baseHead zodb.Tid
baseEvent
zodb
.
Event
baseHead
zodb
.
Tid
}
func
(
e
*
baseMutatedError
)
Error
()
string
{
// 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
)
return
fmt
.
Sprintf
(
"base.head mutated from @%s to @%s"
,
e
.
baseAt0
,
e
.
baseHead
)
}
// 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.
// it runs as separate goroutine.
func
(
d
*
Storage
)
watcher
(
ctx
context
.
Context
)
error
{
...
...
@@ -85,7 +95,18 @@ func (d *Storage) watcher(ctx context.Context) error {
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
if
d
.
watchq
!=
nil
{
d
.
watchq
<-
ev
...
...
@@ -101,6 +122,7 @@ func (d *Storage) watcher(ctx context.Context) error {
continue
}
// XXX +select on close
d
.
watchq
<-
event
// !nil becase d.δWatchq != nil
}
}
...
...
@@ -143,7 +165,7 @@ func (d *Storage) Sync(ctx context.Context) (_ zodb.Tid, err error) {
return
err
}
if
baseHead
!=
d
.
baseAt0
{
return
&
baseMutatedError
{
d
.
baseAt0
,
fmt
.
Errorf
(
"to @%s"
,
baseHead
)
}
return
&
baseMutatedError
{
d
.
baseAt0
,
baseHead
}
}
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