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
e38d6b5a
Commit
e38d6b5a
authored
Jul 30, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
073b3f12
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
23 deletions
+30
-23
go/zodb/db.go
go/zodb/db.go
+30
-23
No files found.
go/zodb/db.go
View file @
e38d6b5a
...
...
@@ -68,18 +68,31 @@ func NewDB(stor IStorage) *DB {
// XXX text
//
// XXX +OpenAt ?
func
(
db
*
DB
)
Open
(
ctx
context
.
Context
)
*
Connection
{
func
(
db
*
DB
)
Open
(
ctx
context
.
Context
)
(
*
Connection
,
error
)
{
// XXX err ctx
txn
:=
transaction
.
Current
(
ctx
)
// XXX sync storage for lastTid
var
lastTid
Tid
// XXX wait till invTab.Head() >= lastTid
conn
:=
db
.
get
(
lastTid
)
// sync storage for lastTid
// XXX open option not to sync and just get lastTid as .invTab.Head() ?
at
,
err
:=
db
.
stor
.
LastTid
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
// wait till .invTab is up to date covering ≥ lastTid
err
=
db
.
invTab
.
Wait
(
ctx
,
at
)
if
err
!=
nil
{
return
nil
,
err
}
// now we have both at and invalidation data covering it -> proceed to
// get connection from the pool.
conn
:=
db
.
get
(
at
)
conn
.
txn
=
txn
txn
.
RegisterSync
((
*
connTxnSync
)(
conn
))
return
conn
return
conn
,
nil
}
// get returns connection from db pool most close to at.
...
...
@@ -89,9 +102,11 @@ func (db *DB) get(at Tid) *Connection {
db
.
mu
.
Lock
()
defer
db
.
mu
.
Unlock
()
l
:=
len
(
db
.
connv
)
// find connv index corresponding to at:
// [i-1].at ≤ at < [i].at
i
:=
sort
.
Search
(
l
en
(
db
.
connv
)
,
func
(
i
int
)
bool
{
i
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
return
at
<
db
.
connv
[
i
]
.
at
})
...
...
@@ -108,7 +123,7 @@ func (db *DB) get(at Tid) *Connection {
}
// TODO search for max N(live) - N(live, that will need to be invalidated)
jδmin
=
j
// XXX stub
jδmin
=
j
// XXX stub
(using rightmost j)
}
// nothing found or too distant
...
...
@@ -117,23 +132,15 @@ func (db *DB) get(at Tid) *Connection {
return
&
Connection
{
stor
:
db
.
stor
,
db
:
db
}
}
// reuse the connection
conn
:=
db
.
connv
[
jδmin
]
copy
(
db
.
connv
[
jδmin
:
],
db
.
connv
[
jδmin
+
1
:
])
db
.
connv
[
l
-
1
]
=
nil
db
.
connv
=
db
.
connv
[
:
l
-
1
]
var
conn
*
Connection
if
l
:=
len
(
db
.
connv
);
l
>
0
{
// pool is !empty - use latest closed conn.
// XXX zodb/py orders conn ↑ by conn._cache.cache_non_ghost_count.
// XXX this way top of the stack is the "most live".
conn
=
db
.
connv
[
l
-
1
]
db
.
connv
[
l
-
1
]
=
nil
db
.
connv
=
db
.
connv
[
:
l
-
1
]
// XXX assert conn.txn == nil
}
else
{
conn
=
&
Connection
{
stor
:
db
.
stor
,
db
:
db
}
}
// XXX assert conn.txn == nil
// XXX assert conn.db == db
return
conn
}
...
...
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