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
073b3f12
Commit
073b3f12
authored
Jul 30, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
f5fb51db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
5 deletions
+60
-5
go/zodb/db.go
go/zodb/db.go
+43
-5
go/zodb/time.go
go/zodb/time.go
+17
-0
No files found.
go/zodb/db.go
View file @
073b3f12
...
...
@@ -18,6 +18,7 @@ import (
"context"
"sort"
"sync"
"time"
"lab.nexedi.com/kirr/neo/go/transaction"
)
...
...
@@ -65,11 +66,15 @@ func NewDB(stor IStorage) *DB {
// XXX connectin must be used under the same transaction only.
//
// XXX text
//
// XXX +OpenAt ?
func
(
db
*
DB
)
Open
(
ctx
context
.
Context
)
*
Connection
{
txn
:=
transaction
.
Current
(
ctx
)
conn
:=
db
.
get
()
// XXX sync storage for lastTid; process invalidations [conn.at, lastTid]
// XXX sync storage for lastTid
var
lastTid
Tid
// XXX wait till invTab.Head() >= lastTid
conn
:=
db
.
get
(
lastTid
)
conn
.
txn
=
txn
txn
.
RegisterSync
((
*
connTxnSync
)(
conn
))
...
...
@@ -77,12 +82,43 @@ func (db *DB) Open(ctx context.Context) *Connection {
return
conn
}
// get returns connection from db pool, or creates new one if pool was empty.
func
(
db
*
DB
)
get
()
*
Connection
{
// get returns connection from db pool most close to at.
//
// it creates new one if there is no close-enough connection in the pool.
func
(
db
*
DB
)
get
(
at
Tid
)
*
Connection
{
db
.
mu
.
Lock
()
defer
db
.
mu
.
Unlock
()
// find connv index corresponding to at:
// [i-1].at ≤ at < [i].at
i
:=
sort
.
Search
(
len
(
db
.
connv
),
func
(
i
int
)
bool
{
return
at
<
db
.
connv
[
i
]
.
at
})
// search through window of X previous connections and find out the one
// with minimal distance to get to state @at. If all connections are to
// distant - create connection anew.
// XXX search not only previous, but future too? (we can get back to
// past by invalidating what was later changed)
const
X
=
10
// XXX hardcoded
jδmin
:=
-
1
for
j
:=
i
-
X
;
j
<
i
;
j
++
{
if
j
<
0
{
continue
}
// TODO search for max N(live) - N(live, that will need to be invalidated)
jδmin
=
j
// XXX stub
}
// nothing found or too distant
const
Tnear
=
10
*
time
.
Minute
// XXX hardcoded
if
jδmin
<
0
||
tabs
(
δtid
(
at
,
db
.
connv
[
jδmin
]
.
at
))
>
Tnear
{
return
&
Connection
{
stor
:
db
.
stor
,
db
:
db
}
}
var
conn
*
Connection
if
l
:=
len
(
db
.
connv
);
l
>
0
{
// pool is !empty - use latest closed conn.
...
...
@@ -119,6 +155,8 @@ func (db *DB) put(conn *Connection) {
db
.
connv
=
append
(
db
.
connv
,
nil
)
copy
(
db
.
connv
[
i
+
1
:
],
db
.
connv
[
i
:
])
db
.
connv
[
i
]
=
conn
// XXX GC too idle connections here?
}
// ---- txn sync ----
...
...
go/zodb/time.go
View file @
073b3f12
...
...
@@ -77,3 +77,20 @@ func (tid Tid) Time() TimeStamp {
// TODO TidFromTime()
// TODO TidFromTimeStamp()
// TODO TidForNow() ?
// δtid returns distance from tid1 to tid2 in term of time.
//
// it can be thought as (tid2 - tid1).
func
δtid
(
tid1
,
tid2
Tid
)
time
.
Duration
{
d
:=
tid2
.
Time
()
.
Sub
(
tid1
.
Time
()
.
Time
)
return
d
}
// tabs returns abs value of time.Duration .
func
tabs
(
δt
time
.
Duration
)
time
.
Duration
{
if
δt
<
0
{
δt
=
-
δt
}
return
δt
}
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