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
688c2f87
Commit
688c2f87
authored
Mar 05, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
63f11c8c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
55 deletions
+29
-55
go/zodb/db.go
go/zodb/db.go
+29
-55
No files found.
go/zodb/db.go
View file @
688c2f87
...
@@ -277,6 +277,7 @@ type hwaiter struct {
...
@@ -277,6 +277,7 @@ type hwaiter struct {
// headWait waits till db.Head becomes ≥ at.
// headWait waits till db.Head becomes ≥ at.
//
//
// must be called with db.mu locked and can release/relock it in the process.
// must be called with db.mu locked and can release/relock it in the process.
// on error db.mu remains unlocked.
func
(
db
*
DB
)
headWait
(
ctx
context
.
Context
,
at
Tid
)
(
err
error
)
{
func
(
db
*
DB
)
headWait
(
ctx
context
.
Context
,
at
Tid
)
(
err
error
)
{
if
at
<=
db
.
δtail
.
Head
()
{
if
at
<=
db
.
δtail
.
Head
()
{
return
nil
// we already have the coverage
return
nil
// we already have the coverage
...
@@ -357,17 +358,13 @@ func (db *DB) Open(ctx context.Context, opt *ConnOptions) (_ *Connection, err er
...
@@ -357,17 +358,13 @@ func (db *DB) Open(ctx context.Context, opt *ConnOptions) (_ *Connection, err er
// proceed to open(at)
// proceed to open(at)
db
.
mu
.
Lock
()
// unlocked in *DBUnlock
db
.
mu
.
Lock
()
// unlocked in *DBUnlock
/*
// wait for δtail.head ≥ at
err := db.
needHeadOrDBUnlock(ctx, at) XXX wait for δtail.head >= at
err
:=
db
.
waitHeadOrDBUnlock
(
ctx
,
at
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
*/
conn
,
err
:=
db
.
openOrDBUnlock
(
ctx
,
at
,
opt
.
NoPool
)
conn
:=
db
.
open
(
at
,
opt
.
NoPool
)
if
err
!=
nil
{
return
nil
,
err
}
err
=
conn
.
resyncAndDBUnlock
(
ctx
,
at
)
err
=
conn
.
resyncAndDBUnlock
(
ctx
,
at
)
if
err
!=
nil
{
if
err
!=
nil
{
// XXX release conn?
// XXX release conn?
...
@@ -376,29 +373,25 @@ func (db *DB) Open(ctx context.Context, opt *ConnOptions) (_ *Connection, err er
...
@@ -376,29 +373,25 @@ func (db *DB) Open(ctx context.Context, opt *ConnOptions) (_ *Connection, err er
return
conn
,
nil
return
conn
,
nil
}
}
// open
OrDBUnlock
is internal worker for Open.
// open is internal worker for Open.
//
//
// it returns either new connection, or connection from the pool.
// it returns either new connection, or connection from the pool.
// returned connection does not necessarily have .at=at, and have to go through .resync().
// returned connection does not necessarily have .at=at, and have to go through .resync().
//
//
// must be called with db.mu locked.
// must be called with db.mu locked.
// db.mu is unlocked on error.
func
(
db
*
DB
)
open
(
at
Tid
,
noPool
bool
)
*
Connection
{
func
(
db
*
DB
)
openOrDBUnlock
(
ctx
context
.
Context
,
at
Tid
,
noPool
bool
)
(
*
Connection
,
error
)
{
fmt
.
Printf
(
"db.open @%s nopool=%v
\t
; δtail (%s, %s]
\n
"
,
at
,
noPool
,
db
.
δtail
.
Tail
(),
db
.
δtail
.
Head
())
fmt
.
Printf
(
"db.openx %s nopool=%v
\t
; δtail (%s, %s]
\n
"
,
at
,
noPool
,
db
.
δtail
.
Tail
(),
db
.
δtail
.
Head
())
// NoPool connection - create one anew
// NoPool connection - create one anew
if
noPool
{
if
noPool
{
// XXX wait for at to be covered
conn
:=
newConnection
(
db
,
at
)
conn
:=
newConnection
(
db
,
at
)
conn
.
noPool
=
true
conn
.
noPool
=
true
return
conn
,
nil
return
conn
}
}
retry
:
for
{
// check if we already have an exact match
// check if we already have an exact match
conn
:=
db
.
get
(
at
,
at
)
conn
:=
db
.
get
(
at
,
at
)
if
conn
!=
nil
{
if
conn
!=
nil
{
return
conn
,
nil
return
conn
}
}
// no exact match - let's try to find nearest
// no exact match - let's try to find nearest
...
@@ -407,30 +400,12 @@ retry:
...
@@ -407,30 +400,12 @@ retry:
// too far in the past, and we know there is no exact match
// too far in the past, and we know there is no exact match
// -> new historic connection.
// -> new historic connection.
if
at
<=
δtail
.
Tail
()
{
if
at
<=
δtail
.
Tail
()
{
return
newConnection
(
db
,
at
),
nil
return
newConnection
(
db
,
at
)
}
}
// we have some δtail coverage, but at is ahead of that.
// at should be ≤ head (we waited for it before calling here)
if
at
>
δtail
.
Head
()
{
if
head
:=
δtail
.
Head
();
at
>
head
{
// wait till δtail.head is up to date covering ≥ at,
panic
(
"open: head (%s) < at (%s)"
,
head
,
at
)
// and retry the loop (δtail.tail might go over at while we are waiting)
δready
:=
make
(
chan
struct
{})
db
.
hwait
[
hwaiter
{
at
,
δready
}]
=
struct
{}{}
db
.
mu
.
Unlock
()
select
{
case
<-
δready
:
// ok - δtail.head went over at; relock db and retry
db
.
mu
.
Lock
()
continue
retry
// on error leave db.mu unlocked
case
<-
ctx
.
Done
()
:
return
nil
,
ctx
.
Err
()
case
<-
db
.
down
:
return
nil
,
db
.
downErr
}
}
}
// at ∈ (δtail, δhead] ; try to get nearby idle connection or make a new one
// at ∈ (δtail, δhead] ; try to get nearby idle connection or make a new one
...
@@ -438,8 +413,7 @@ retry:
...
@@ -438,8 +413,7 @@ retry:
if
conn
==
nil
{
if
conn
==
nil
{
conn
=
newConnection
(
db
,
at
)
conn
=
newConnection
(
db
,
at
)
}
}
return
conn
,
nil
return
conn
}
}
}
// Resync resyncs the connection onto different database view and transaction.
// Resync resyncs the connection onto different database view and transaction.
...
...
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