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
028fdbf0
Commit
028fdbf0
authored
Mar 10, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
7f56c92b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
65 deletions
+68
-65
go/zodb/persistent_test.go
go/zodb/persistent_test.go
+0
-1
go/zodb/storage.go
go/zodb/storage.go
+68
-64
No files found.
go/zodb/persistent_test.go
View file @
028fdbf0
...
@@ -428,7 +428,6 @@ func testPersistentDB(t0 *testing.T, rawcache bool) {
...
@@ -428,7 +428,6 @@ func testPersistentDB(t0 *testing.T, rawcache bool) {
at2
,
err
:=
ZPyCommit
(
zurl
,
at1
,
_obj2
);
X
(
err
)
at2
,
err
:=
ZPyCommit
(
zurl
,
at1
,
_obj2
);
X
(
err
)
// new db connection should see the change
// new db connection should see the change
// XXX currently there is a race because db.Open does not do proper Sync
t2
:=
testopen
(
&
ConnOptions
{})
t2
:=
testopen
(
&
ConnOptions
{})
assert
.
Equal
(
t2
.
conn
.
At
(),
at2
)
assert
.
Equal
(
t2
.
conn
.
At
(),
at2
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
(
nil
))
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
(
nil
))
...
...
go/zodb/storage.go
View file @
028fdbf0
...
@@ -155,8 +155,10 @@ type storage struct {
...
@@ -155,8 +155,10 @@ type storage struct {
downErr
error
// reason for shutdown
downErr
error
// reason for shutdown
// watcher
// watcher
headMu
sync
.
Mutex
head
Tid
// local view of storage head; mutated by watcher only
headMu
sync
.
Mutex
head
Tid
// local view of storage head; mutated by watcher only
drvWatchq
chan
Event
// watchq passed to driver
drvWatchq
chan
Event
// watchq passed to driver
watchReq
chan
watchRequest
// {Add,Del}Watch requests go here
watchReq
chan
watchRequest
// {Add,Del}Watch requests go here
watchTab
map
[
chan
<-
Event
]
struct
{}
// registered watchers
watchTab
map
[
chan
<-
Event
]
struct
{}
// registered watchers
...
@@ -191,68 +193,6 @@ func (s *storage) Close() error {
...
@@ -191,68 +193,6 @@ func (s *storage) Close() error {
// loading goes through cache - this way prefetching can work
// loading goes through cache - this way prefetching can work
func
(
s
*
storage
)
Head
()
Tid
{
s
.
headMu
.
Lock
()
head
:=
s
.
head
s
.
headMu
.
Unlock
()
return
head
}
// XXX place -> near watcher
func
(
s
*
storage
)
Sync
(
ctx
context
.
Context
)
(
err
error
)
{
defer
func
()
{
if
err
!=
nil
{
err
=
s
.
zerr
(
"sync"
,
nil
,
err
)
}
}()
// XXX better -> xcontext.Merge(ctx, s.opCtx) but currently it costs 1+ goroutine
if
ready
(
s
.
down
)
{
return
s
.
downErr
}
head
,
err
:=
s
.
driver
.
Sync
(
ctx
)
if
err
!=
nil
{
return
err
}
// XXX check that driver returns head↑
// wait till .head >= head
watchq
:=
make
(
chan
Event
)
at
:=
s
.
AddWatch
(
watchq
)
defer
s
.
DelWatch
(
watchq
)
for
at
<
head
{
select
{
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
case
<-
s
.
down
:
return
s
.
downErr
case
event
,
ok
:=
<-
watchq
:
if
!
ok
{
// closed
return
s
.
downErr
// XXX ok? sync on .down?
}
switch
e
:=
event
.
(
type
)
{
default
:
panic
(
"XXX"
)
// XXX
case
*
EventError
:
return
e
.
Err
case
*
EventCommit
:
at
=
e
.
Tid
}
}
}
return
nil
}
// Load implements Loader.
// Load implements Loader.
func
(
s
*
storage
)
Load
(
ctx
context
.
Context
,
xid
Xid
)
(
*
mem
.
Buf
,
Tid
,
error
)
{
func
(
s
*
storage
)
Load
(
ctx
context
.
Context
,
xid
Xid
)
(
*
mem
.
Buf
,
Tid
,
error
)
{
// XXX better -> xcontext.Merge(ctx, s.opCtx) but currently it costs 1+ goroutine
// XXX better -> xcontext.Merge(ctx, s.opCtx) but currently it costs 1+ goroutine
...
@@ -483,6 +423,70 @@ func (s *storage) DelWatch(watchq chan<- Event) {
...
@@ -483,6 +423,70 @@ func (s *storage) DelWatch(watchq chan<- Event) {
}
}
}
}
// Head implements IStorage.
func
(
s
*
storage
)
Head
()
Tid
{
s
.
headMu
.
Lock
()
head
:=
s
.
head
s
.
headMu
.
Unlock
()
return
head
}
// Sync implements IStorage.
func
(
s
*
storage
)
Sync
(
ctx
context
.
Context
)
(
err
error
)
{
defer
func
()
{
if
err
!=
nil
{
err
=
s
.
zerr
(
"sync"
,
nil
,
err
)
}
}()
// XXX better -> xcontext.Merge(ctx, s.opCtx) but currently it costs 1+ goroutine
if
ready
(
s
.
down
)
{
return
s
.
downErr
}
head
,
err
:=
s
.
driver
.
Sync
(
ctx
)
if
err
!=
nil
{
return
err
}
// XXX check that driver returns head↑
// wait till .head >= head
watchq
:=
make
(
chan
Event
)
at
:=
s
.
AddWatch
(
watchq
)
defer
s
.
DelWatch
(
watchq
)
for
at
<
head
{
select
{
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
case
<-
s
.
down
:
return
s
.
downErr
case
event
,
ok
:=
<-
watchq
:
if
!
ok
{
// closed
<-
s
.
down
return
s
.
downErr
}
switch
e
:=
event
.
(
type
)
{
default
:
panic
(
fmt
.
Sprintf
(
"unexpected event %T"
,
e
))
case
*
EventError
:
return
e
.
Err
case
*
EventCommit
:
at
=
e
.
Tid
}
}
}
return
nil
}
// ---- misc ----
// ---- misc ----
...
...
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