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
2799f995
Commit
2799f995
authored
Jan 29, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/zodb: DB.connv -> DB.pool
pool is a better name for "pool of unused connections" compared to connv.
parent
0806740d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
17 deletions
+19
-17
go/zodb/db.go
go/zodb/db.go
+19
-17
No files found.
go/zodb/db.go
View file @
2799f995
...
...
@@ -48,7 +48,9 @@ type DB struct {
stor
IStorage
mu
sync
.
Mutex
connv
[]
*
Connection
// order by ↑= .at
// pool of unused connections.
pool
[]
*
Connection
// order by ↑= .at
// information about invalidations
// XXX -> Storage. XXX or -> Cache? (so it is not duplicated many times for many DB case)
...
...
@@ -161,12 +163,12 @@ func (db *DB) get(at Tid) *Connection {
db
.
mu
.
Lock
()
defer
db
.
mu
.
Unlock
()
l
:=
len
(
db
.
connv
)
l
:=
len
(
db
.
pool
)
// find
connv
index corresponding to at:
// find
pool
index corresponding to at:
// [i-1].at ≤ at < [i].at
i
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
return
at
<
db
.
connv
[
i
]
.
at
return
at
<
db
.
pool
[
i
]
.
at
})
// search through window of X previous connections and find out the one
...
...
@@ -188,15 +190,15 @@ func (db *DB) get(at Tid) *Connection {
// 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
{
if
jδmin
<
0
||
tabs
(
δtid
(
at
,
db
.
pool
[
jδmin
]
.
at
))
>
Tnear
{
return
newConnection
(
db
,
at
)
}
// 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
]
conn
:=
db
.
pool
[
jδmin
]
copy
(
db
.
pool
[
jδmin
:
],
db
.
pool
[
jδmin
+
1
:
])
db
.
pool
[
l
-
1
]
=
nil
db
.
pool
=
db
.
pool
[
:
l
-
1
]
if
conn
.
db
!=
db
{
panic
(
"DB.get: foreign connection in the pool"
)
...
...
@@ -223,16 +225,16 @@ func (db *DB) put(conn *Connection) {
db
.
mu
.
Lock
()
defer
db
.
mu
.
Unlock
()
// XXX check if len(
connv
) > X, and drop conn if yes
// XXX check if len(
pool
) > X, and drop conn if yes
// [i-1].at ≤ at < [i].at
i
:=
sort
.
Search
(
len
(
db
.
connv
),
func
(
i
int
)
bool
{
return
conn
.
at
<
db
.
connv
[
i
]
.
at
i
:=
sort
.
Search
(
len
(
db
.
pool
),
func
(
i
int
)
bool
{
return
conn
.
at
<
db
.
pool
[
i
]
.
at
})
//db.
connv = append(db.connv[:i], conn, db.connv
[i:]...)
db
.
connv
=
append
(
db
.
connv
,
nil
)
copy
(
db
.
connv
[
i
+
1
:
],
db
.
connv
[
i
:
])
db
.
connv
[
i
]
=
conn
//db.
pool = append(db.pool[:i], conn, db.pool
[i:]...)
db
.
pool
=
append
(
db
.
pool
,
nil
)
copy
(
db
.
pool
[
i
+
1
:
],
db
.
pool
[
i
:
])
db
.
pool
[
i
]
=
conn
// XXX GC too idle connections here?
}
...
...
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