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
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
dc719b5e
Commit
dc719b5e
authored
May 08, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
fe52c88f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
14 deletions
+34
-14
go/xcommon/xnet/lonet/registry_sqlite.go
go/xcommon/xnet/lonet/registry_sqlite.go
+29
-11
go/xcommon/xnet/lonet/registry_sqlite_test.go
go/xcommon/xnet/lonet/registry_sqlite_test.go
+5
-3
No files found.
go/xcommon/xnet/lonet/registry_sqlite.go
View file @
dc719b5e
...
...
@@ -48,7 +48,7 @@ type sqliteRegistry struct {
// openRegistrySqlite opens SQLite registry located at dburi.
// XXX network name?
func
openRegistrySQLite
(
dburi
string
)
(
_
*
sqliteRegistry
,
err
error
)
{
func
openRegistrySQLite
(
ctx
context
.
Context
,
dburi
string
)
(
_
*
sqliteRegistry
,
err
error
)
{
r
:=
&
sqliteRegistry
{
uri
:
dburi
}
defer
r
.
regerr
(
&
err
,
"open"
)
...
...
@@ -58,9 +58,14 @@ func openRegistrySQLite(dburi string) (_ *sqliteRegistry, err error) {
}
r
.
dbpool
=
dbpool
return
r
,
nil
// XXX setup
err
=
r
.
setup
(
ctx
)
if
err
!=
nil
{
r
.
Close
()
return
nil
,
err
}
return
r
,
nil
}
func
(
r
*
sqliteRegistry
)
Close
()
(
err
error
)
{
...
...
@@ -69,10 +74,16 @@ func (r *sqliteRegistry) Close() (err error) {
}
func
(
r
*
sqliteRegistry
)
setup
(
ctx
context
.
Context
)
(
err
error
)
{
defer
r
.
regerr
(
&
err
,
"setup"
)
// XXX args?
// XXX get conn
var
conn
*
sqlite
.
Conn
// XXX dup
conn
:=
r
.
dbpool
.
Get
(
ctx
.
Done
())
if
conn
==
nil
{
// either ctx cancel or dbpool close
if
ctx
.
Err
()
!=
nil
{
return
ctx
.
Err
()
}
return
errRegistryDown
// db closed
}
defer
r
.
dbpool
.
Put
(
conn
)
err
=
sqliteutil
.
ExecScript
(
conn
,
`
CREATE TABLE IF NOT EXISTS hosts (
...
...
@@ -98,6 +109,7 @@ func (r *sqliteRegistry) setup(ctx context.Context) (err error) {
func
(
r
*
sqliteRegistry
)
Announce
(
ctx
context
.
Context
,
hostname
,
osladdr
string
)
(
err
error
)
{
defer
r
.
regerr
(
&
err
,
"announce"
,
hostname
,
osladdr
)
// XXX dup
conn
:=
r
.
dbpool
.
Get
(
ctx
.
Done
())
if
conn
==
nil
{
// either ctx cancel or dbpool close
...
...
@@ -108,10 +120,8 @@ func (r *sqliteRegistry) Announce(ctx context.Context, hostname, osladdr string)
}
defer
r
.
dbpool
.
Put
(
conn
)
//sqliteutil.Exec(conn, "SELECT hostname, osladdr FROM hosts WHERE hostname = ?", func (stmt *sqlite.Stmt) error {
err
=
sqliteutil
.
Exec
(
conn
,
"INSERT INTO hosts (hostname, osladdr) VALUES (?, ?)"
,
nil
,
hostname
,
osladdr
)
// XXX -> errNoHost
switch
sqlite
.
ErrCode
(
err
)
{
case
sqlite
.
SQLITE_CONSTRAINT_UNIQUE
:
// XXX test
err
=
errHostDup
...
...
@@ -123,8 +133,16 @@ func (r *sqliteRegistry) Announce(ctx context.Context, hostname, osladdr string)
func
(
r
*
sqliteRegistry
)
Query
(
ctx
context
.
Context
,
hostname
string
)
(
osladdr
string
,
err
error
)
{
defer
r
.
regerr
(
&
err
,
"query"
,
hostname
)
// XXX get conn
var
conn
*
sqlite
.
Conn
// XXX dup
conn
:=
r
.
dbpool
.
Get
(
ctx
.
Done
())
if
conn
==
nil
{
// either ctx cancel or dbpool close
if
ctx
.
Err
()
!=
nil
{
return
""
,
ctx
.
Err
()
}
return
""
,
errRegistryDown
// db closed
}
defer
r
.
dbpool
.
Put
(
conn
)
err
=
sqliteutil
.
Exec
(
conn
,
"SELECT osladdr FROM hosts WHERE hostname = ?"
,
func
(
stmt
*
sqlite
.
Stmt
)
error
{
osladdr
=
stmt
.
ColumnText
(
0
)
...
...
go/xcommon/xnet/lonet/registry_sqlite_test.go
View file @
dc719b5e
...
...
@@ -37,7 +37,9 @@ func TestRegistrySQLite(t *testing.T) {
dbpath
:=
work
+
"/1.db"
r
,
err
:=
openRegistrySQLite
(
dbpath
)
ctx
:=
context
.
Background
()
r
,
err
:=
openRegistrySQLite
(
ctx
,
dbpath
)
X
(
err
)
// quert checks that result of Query(hostname) is as expect
...
...
@@ -49,7 +51,7 @@ func TestRegistrySQLite(t *testing.T) {
// XXX ^^^ -> `r registry` (needs .Network() to get network name) ?
t
.
Helper
()
osladdr
,
err
:=
r
.
Query
(
c
ontext
.
Background
()
,
hostname
)
osladdr
,
err
:=
r
.
Query
(
c
tx
,
hostname
)
if
cause
,
iserr
:=
expect
.
(
error
);
iserr
{
// error expected
e
,
ok
:=
err
.
(
*
registryError
)
...
...
@@ -76,7 +78,7 @@ func TestRegistrySQLite(t *testing.T) {
// r.Query("α") == "alpha:1234")
// r.Query("β") == ø
r2
,
err
:=
openRegistrySQLite
(
dbpath
)
r2
,
err
:=
openRegistrySQLite
(
ctx
,
dbpath
)
// r2.Network() == ...
// r2.Query("α") == "alpha:1234"
// r2.Query("β") == ø
...
...
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