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
34fb46aa
Commit
34fb46aa
authored
Jan 28, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
ef4fc1b4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
+22
-19
go/zodb/db.go
go/zodb/db.go
+22
-19
No files found.
go/zodb/db.go
View file @
34fb46aa
...
@@ -260,24 +260,25 @@ func (db *DB) Open(ctx context.Context, opt *ConnOptions) (_ *Connection, err er
...
@@ -260,24 +260,25 @@ func (db *DB) Open(ctx context.Context, opt *ConnOptions) (_ *Connection, err er
at
=
head
at
=
head
}
}
db
.
mu
.
Lock
()
// XXX no - back to resync
db
.
mu
.
Lock
()
defer
db
.
mu
.
Unlock
()
// unlock is either in db.open -> err, or in resyncAndDBUnlock
conn
,
err
:=
db
.
open
(
ctx
,
at
,
opt
.
NoPool
)
conn
,
err
:=
db
.
open
OrDBUnlock
(
ctx
,
at
,
opt
.
NoPool
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
conn
.
resync
(
txn
,
at
)
conn
.
resync
AndDBUnlock
(
txn
,
at
)
return
conn
,
nil
return
conn
,
nil
}
}
// open is internal worker for Open.
// open
OrDBUnlock
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 neccessarily have .at=at, and have to go through .resync().
// returned connection does not neccessarily have .at=at, and have to go through .resync().
//
//
// must be called with db.mu locked.
// must be called with db.mu locked.
func
(
db
*
DB
)
open
(
ctx
context
.
Context
,
at
Tid
,
noPool
bool
)
(
*
Connection
,
error
)
{
// db.mu is unlocked on error.
func
(
db
*
DB
)
openOrDBUnlock
(
ctx
context
.
Context
,
at
Tid
,
noPool
bool
)
(
*
Connection
,
error
)
{
// NoPool connection - create anew
// NoPool connection - create anew
if
noPool
{
if
noPool
{
conn
:=
newConnection
(
db
,
at
)
conn
:=
newConnection
(
db
,
at
)
...
@@ -320,7 +321,7 @@ retry:
...
@@ -320,7 +321,7 @@ retry:
select
{
select
{
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
//
XXX double unlock
//
leave db.mu unlocked
return
nil
,
ctx
.
Err
()
return
nil
,
ctx
.
Err
()
case
<-
δready
:
case
<-
δready
:
...
@@ -364,17 +365,21 @@ func (conn *Connection) Resync(txn transaction.Transaction, at Tid) {
...
@@ -364,17 +365,21 @@ func (conn *Connection) Resync(txn transaction.Transaction, at Tid) {
}
}
conn
.
db
.
mu
.
Lock
()
conn
.
db
.
mu
.
Lock
()
defer
conn
.
db
.
mu
.
Unlock
()
conn
.
resyncAndDBUnlock
(
txn
,
at
)
conn
.
resync
(
txn
,
at
)
}
}
// resync serves Connection.resync and DB.Open .
// resyncAndDBUnlock serves Connection.Resync and DB.Open .
func
(
conn
*
Connection
)
resync
(
txn
transaction
.
Transaction
,
at
Tid
)
{
//
// must be called with conn.db locked and unlocks it at the end.
func
(
conn
*
Connection
)
resyncAndDBUnlock
(
txn
transaction
.
Transaction
,
at
Tid
)
{
db
:=
conn
.
db
if
conn
.
txn
!=
nil
{
if
conn
.
txn
!=
nil
{
db
.
mu
.
Unlock
()
panic
(
"Conn.resync: previous transaction is not yet complete"
)
panic
(
"Conn.resync: previous transaction is not yet complete"
)
}
}
// upon exit, with all locks released, register conn to txn.
defer
func
()
{
defer
func
()
{
conn
.
at
=
at
conn
.
at
=
at
conn
.
txn
=
txn
conn
.
txn
=
txn
...
@@ -383,11 +388,13 @@ func (conn *Connection) resync(txn transaction.Transaction, at Tid) {
...
@@ -383,11 +388,13 @@ func (conn *Connection) resync(txn transaction.Transaction, at Tid) {
// conn.at == at - nothing to do (even if out of δtail coverage)
// conn.at == at - nothing to do (even if out of δtail coverage)
if
conn
.
at
==
at
{
if
conn
.
at
==
at
{
db
.
mu
.
Unlock
()
return
return
}
}
// conn.at != at - have to invalidate objects in live cache.
δtail
:=
db
.
δtail
δtail
:=
db
.
δtail
δobj
:=
make
(
map
[
Oid
]
struct
{})
// what to invalidate
δobj
:=
make
(
map
[
Oid
]
struct
{})
//
set(oid) -
what to invalidate
δall
:=
false
// if we have to invalidate all objects
δall
:=
false
// if we have to invalidate all objects
// both conn.at and at are covered by δtail - we can invalidate selectively
// both conn.at and at are covered by δtail - we can invalidate selectively
...
@@ -413,7 +420,7 @@ func (conn *Connection) resync(txn transaction.Transaction, at Tid) {
...
@@ -413,7 +420,7 @@ func (conn *Connection) resync(txn transaction.Transaction, at Tid) {
δall
=
true
δall
=
true
}
}
//
XXX unlock db before txn.RegisterSync (it locks txn.mu)
//
unlock db before locking cache and txn
db
.
mu
.
Unlock
()
db
.
mu
.
Unlock
()
conn
.
cache
.
Lock
()
conn
.
cache
.
Lock
()
...
@@ -423,7 +430,7 @@ func (conn *Connection) resync(txn transaction.Transaction, at Tid) {
...
@@ -423,7 +430,7 @@ func (conn *Connection) resync(txn transaction.Transaction, at Tid) {
// XXX keep synced with LiveCache details
// XXX keep synced with LiveCache details
// XXX -> conn.cache.forEach?
// XXX -> conn.cache.forEach?
// XXX should we wait for db.stor.head to cover at?
// XXX should we wait for db.stor.head to cover at?
// or leave this wait till
load
time?
// or leave this wait till
.Load()
time?
for
_
,
wobj
:=
range
conn
.
cache
.
objtab
{
for
_
,
wobj
:=
range
conn
.
cache
.
objtab
{
obj
,
_
:=
wobj
.
Get
()
.
(
IPersistent
)
obj
,
_
:=
wobj
.
Get
()
.
(
IPersistent
)
if
obj
!=
nil
{
if
obj
!=
nil
{
...
@@ -441,10 +448,6 @@ func (conn *Connection) resync(txn transaction.Transaction, at Tid) {
...
@@ -441,10 +448,6 @@ func (conn *Connection) resync(txn transaction.Transaction, at Tid) {
// all done
// all done
return
return
// conn.at = at
// conn.txn = txn
// txn.RegisterSync((*connTxnSync)(conn))
}
}
// get returns connection from db pool most close to at.
// get returns connection from db pool most close to at.
...
...
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