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
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
Hide 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
...
@@ -47,8 +47,10 @@ import (
...
@@ -47,8 +47,10 @@ import (
type
DB
struct
{
type
DB
struct
{
stor
IStorage
stor
IStorage
mu
sync
.
Mutex
mu
sync
.
Mutex
connv
[]
*
Connection
// order by ↑= .at
// pool of unused connections.
pool
[]
*
Connection
// order by ↑= .at
// information about invalidations
// information about invalidations
// XXX -> Storage. XXX or -> Cache? (so it is not duplicated many times for many DB case)
// 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 {
...
@@ -161,12 +163,12 @@ func (db *DB) get(at Tid) *Connection {
db
.
mu
.
Lock
()
db
.
mu
.
Lock
()
defer
db
.
mu
.
Unlock
()
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-1].at ≤ at < [i].at
i
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
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
// search through window of X previous connections and find out the one
...
@@ -188,15 +190,15 @@ func (db *DB) get(at Tid) *Connection {
...
@@ -188,15 +190,15 @@ func (db *DB) get(at Tid) *Connection {
// nothing found or too distant
// nothing found or too distant
const
Tnear
=
10
*
time
.
Minute
// XXX hardcoded
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
)
return
newConnection
(
db
,
at
)
}
}
// reuse the connection
// reuse the connection
conn
:=
db
.
connv
[
jδmin
]
conn
:=
db
.
pool
[
jδmin
]
copy
(
db
.
connv
[
jδmin
:
],
db
.
connv
[
jδmin
+
1
:
])
copy
(
db
.
pool
[
jδmin
:
],
db
.
pool
[
jδmin
+
1
:
])
db
.
connv
[
l
-
1
]
=
nil
db
.
pool
[
l
-
1
]
=
nil
db
.
connv
=
db
.
connv
[
:
l
-
1
]
db
.
pool
=
db
.
pool
[
:
l
-
1
]
if
conn
.
db
!=
db
{
if
conn
.
db
!=
db
{
panic
(
"DB.get: foreign connection in the pool"
)
panic
(
"DB.get: foreign connection in the pool"
)
...
@@ -223,16 +225,16 @@ func (db *DB) put(conn *Connection) {
...
@@ -223,16 +225,16 @@ func (db *DB) put(conn *Connection) {
db
.
mu
.
Lock
()
db
.
mu
.
Lock
()
defer
db
.
mu
.
Unlock
()
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-1].at ≤ at < [i].at
i
:=
sort
.
Search
(
len
(
db
.
connv
),
func
(
i
int
)
bool
{
i
:=
sort
.
Search
(
len
(
db
.
pool
),
func
(
i
int
)
bool
{
return
conn
.
at
<
db
.
connv
[
i
]
.
at
return
conn
.
at
<
db
.
pool
[
i
]
.
at
})
})
//db.
connv = append(db.connv[:i], conn, db.connv
[i:]...)
//db.
pool = append(db.pool[:i], conn, db.pool
[i:]...)
db
.
connv
=
append
(
db
.
connv
,
nil
)
db
.
pool
=
append
(
db
.
pool
,
nil
)
copy
(
db
.
connv
[
i
+
1
:
],
db
.
connv
[
i
:
])
copy
(
db
.
pool
[
i
+
1
:
],
db
.
pool
[
i
:
])
db
.
connv
[
i
]
=
conn
db
.
pool
[
i
]
=
conn
// XXX GC too idle connections here?
// 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