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
688c2f87
Commit
688c2f87
authored
Mar 05, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
63f11c8c
Changes
1
Hide 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,70 +373,47 @@ func (db *DB) Open(ctx context.Context, opt *ConnOptions) (_ *Connection, err er
...
@@ -376,70 +373,47 @@ 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
:
// check if we already have an exact match
for
{
conn
:=
db
.
get
(
at
,
at
)
// check if we already have an exact match
if
conn
!=
nil
{
conn
:=
db
.
get
(
at
,
at
)
return
conn
if
conn
!=
nil
{
}
return
conn
,
nil
}
// no exact match - let's try to find nearest
δtail
:=
db
.
δtail
// too far in the past, and we know there is no exact match
// -> new historic connection.
if
at
<=
δtail
.
Tail
()
{
return
newConnection
(
db
,
at
),
nil
}
// we have some δtail coverage, but at is ahead of that.
if
at
>
δtail
.
Head
()
{
// wait till δtail.head is up to date covering ≥ 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
{
// no exact match - let's try to find nearest
case
<-
δready
:
δtail
:=
db
.
δtail
// ok - δtail.head went over at; relock db and retry
db
.
mu
.
Lock
()
continue
retry
// on error leave db.mu unlocked
// too far in the past, and we know there is no exact match
case
<-
ctx
.
Done
()
:
// -> new historic connection.
return
nil
,
ctx
.
Err
()
if
at
<=
δtail
.
Tail
()
{
return
newConnection
(
db
,
at
)
}
case
<-
db
.
down
:
// at should be ≤ head (we waited for it before calling here)
return
nil
,
db
.
downErr
if
head
:=
δtail
.
Head
();
at
>
head
{
}
panic
(
"open: head (%s) < at (%s)"
,
head
,
at
)
}
}
// 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
conn
=
db
.
get
(
δtail
.
Tail
(),
at
)
conn
=
db
.
get
(
δtail
.
Tail
(),
at
)
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