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
379cc163
Commit
379cc163
authored
Aug 29, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
59333e47
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
41 deletions
+63
-41
go/neo/connection.go
go/neo/connection.go
+1
-0
go/neo/server/cluster_test.go
go/neo/server/cluster_test.go
+5
-5
go/neo/server/server.go
go/neo/server/server.go
+1
-15
go/neo/server/storage.go
go/neo/server/storage.go
+6
-20
go/xcommon/xcontext/xcontext.go
go/xcommon/xcontext/xcontext.go
+27
-1
go/xcommon/xio/xio.go
go/xcommon/xio/xio.go
+23
-0
No files found.
go/neo/connection.go
View file @
379cc163
...
@@ -403,6 +403,7 @@ func (c *Conn) errRecvShutdown() error {
...
@@ -403,6 +403,7 @@ func (c *Conn) errRecvShutdown() error {
// recvPkt receives raw packet from connection
// recvPkt receives raw packet from connection
func
(
c
*
Conn
)
recvPkt
()
(
*
PktBuf
,
error
)
{
func
(
c
*
Conn
)
recvPkt
()
(
*
PktBuf
,
error
)
{
select
{
select
{
// XXX maybe possible to detect "down" by seeing c.rxq is closed?
case
<-
c
.
down
:
case
<-
c
.
down
:
return
nil
,
c
.
err
(
"recv"
,
c
.
errRecvShutdown
())
return
nil
,
c
.
err
(
"recv"
,
c
.
errRecvShutdown
())
...
...
go/neo/server/cluster_test.go
View file @
379cc163
...
@@ -250,7 +250,7 @@ func TestMasterStorage(t *testing.T) {
...
@@ -250,7 +250,7 @@ func TestMasterStorage(t *testing.T) {
tc
.
Expect
(
netconnect
(
"s:2"
,
"m:2"
,
"m:1"
))
tc
.
Expect
(
netconnect
(
"s:2"
,
"m:2"
,
"m:1"
))
tc
.
Expect
(
conntx
(
"s:2"
,
"m:2"
,
1
,
&
neo
.
RequestIdentification
{
tc
.
Expect
(
conntx
(
"s:2"
,
"m:2"
,
1
,
&
neo
.
RequestIdentification
{
NodeType
:
neo
.
STORAGE
,
NodeType
:
neo
.
STORAGE
,
NodeUUID
:
0
,
UUID
:
0
,
Address
:
xnaddr
(
"s:1"
),
Address
:
xnaddr
(
"s:1"
),
ClusterName
:
"abc1"
,
ClusterName
:
"abc1"
,
IdTimestamp
:
0
,
IdTimestamp
:
0
,
...
@@ -260,10 +260,10 @@ func TestMasterStorage(t *testing.T) {
...
@@ -260,10 +260,10 @@ func TestMasterStorage(t *testing.T) {
tc
.
Expect
(
conntx
(
"m:2"
,
"s:2"
,
1
,
&
neo
.
AcceptIdentification
{
tc
.
Expect
(
conntx
(
"m:2"
,
"s:2"
,
1
,
&
neo
.
AcceptIdentification
{
NodeType
:
neo
.
MASTER
,
NodeType
:
neo
.
MASTER
,
My
NodeUUID
:
neo
.
UUID
(
neo
.
MASTER
,
1
),
My
UUID
:
neo
.
UUID
(
neo
.
MASTER
,
1
),
NumPartitions
:
1
,
NumPartitions
:
1
,
NumReplicas
:
1
,
NumReplicas
:
1
,
Your
Node
UUID
:
neo
.
UUID
(
neo
.
STORAGE
,
1
),
YourUUID
:
neo
.
UUID
(
neo
.
STORAGE
,
1
),
}))
}))
// TODO test ID rejects (uuid already registered, ...)
// TODO test ID rejects (uuid already registered, ...)
...
@@ -313,8 +313,8 @@ func TestMasterStorage(t *testing.T) {
...
@@ -313,8 +313,8 @@ func TestMasterStorage(t *testing.T) {
TidDict
:
nil
,
// map[zodb.Tid]zodb.Tid{},
TidDict
:
nil
,
// map[zodb.Tid]zodb.Tid{},
}))
}))
lastOid
,
err1
:=
zstor
.
LastOid
()
lastOid
,
err1
:=
zstor
.
LastOid
(
context
.
TODO
()
)
lastTid
,
err2
:=
zstor
.
LastTid
()
lastTid
,
err2
:=
zstor
.
LastTid
(
context
.
TODO
()
)
exc
.
Raiseif
(
xerr
.
Merge
(
err1
,
err2
))
exc
.
Raiseif
(
xerr
.
Merge
(
err1
,
err2
))
tc
.
Expect
(
conntx
(
"m:2"
,
"s:2"
,
1
,
&
neo
.
LastIDs
{}))
tc
.
Expect
(
conntx
(
"m:2"
,
"s:2"
,
1
,
&
neo
.
LastIDs
{}))
tc
.
Expect
(
conntx
(
"s:2"
,
"m:2"
,
1
,
&
neo
.
AnswerLastIDs
{
tc
.
Expect
(
conntx
(
"s:2"
,
"m:2"
,
1
,
&
neo
.
AnswerLastIDs
{
...
...
go/neo/server/server.go
View file @
379cc163
...
@@ -47,21 +47,7 @@ type Server interface {
...
@@ -47,21 +47,7 @@ type Server interface {
// the listener is closed when Serve returns.
// the listener is closed when Serve returns.
func Serve(ctx context.Context, l *neo.Listener, srv Server) error {
func Serve(ctx context.Context, l *neo.Listener, srv Server) error {
fmt.Printf("xxx: serving on %s ...\n", l.Addr()) // XXX 'xxx' -> ?
fmt.Printf("xxx: serving on %s ...\n", l.Addr()) // XXX 'xxx' -> ?
defer xio.CloseWhenDone(ctx, l)()
// close listener when either cancelling or returning (e.g. due to an error)
// ( when cancelling - listener close will signal to all accepts to
// terminate with an error )
// XXX dup -> utility
retch := make(chan struct{})
defer func() { close(retch) }()
go func() {
select {
case <-ctx.Done():
// XXX err = cancelled
case <-retch:
}
l.Close() // XXX err
}()
// main Accept -> ServeLink loop
// main Accept -> ServeLink loop
for {
for {
...
...
go/neo/server/storage.go
View file @
379cc163
...
@@ -32,6 +32,7 @@ import (
...
@@ -32,6 +32,7 @@ import (
"lab.nexedi.com/kirr/neo/go/xcommon/task"
"lab.nexedi.com/kirr/neo/go/xcommon/task"
"lab.nexedi.com/kirr/neo/go/xcommon/xnet"
"lab.nexedi.com/kirr/neo/go/xcommon/xnet"
"lab.nexedi.com/kirr/neo/go/xcommon/xcontext"
"lab.nexedi.com/kirr/neo/go/xcommon/xcontext"
"lab.nexedi.com/kirr/neo/go/xcommon/xio"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xerr"
)
)
...
@@ -410,26 +411,9 @@ func (stor *Storage) m1serve(ctx context.Context, Mconn *neo.Conn) (err error) {
...
@@ -410,26 +411,9 @@ func (stor *Storage) m1serve(ctx context.Context, Mconn *neo.Conn) (err error) {
// --- serve incoming connections from other nodes ---
// --- serve incoming connections from other nodes ---
// ServeLink serves incoming node-node link connection
// ServeLink serves incoming node-node link connection
// XXX +error return?
func
(
stor
*
Storage
)
ServeLink
(
ctx
context
.
Context
,
link
*
neo
.
NodeLink
)
(
err
error
)
{
func
(
stor
*
Storage
)
ServeLink
(
ctx
context
.
Context
,
link
*
neo
.
NodeLink
)
{
defer
task
.
Runningf
(
&
ctx
,
"serve %s"
,
link
)(
&
err
)
log
.
Infof
(
ctx
,
"%s: serving new node"
,
link
)
// XXX -> running?
defer
xio
.
CloseWhenDone
(
ctx
,
link
)()
// close link when either cancelling or returning (e.g. due to an error)
// ( when cancelling - link.Close will signal to all current IO to
// terminate with an error )
// XXX dup -> utility
retch
:=
make
(
chan
struct
{})
defer
func
()
{
close
(
retch
)
}()
go
func
()
{
select
{
case
<-
ctx
.
Done
()
:
// XXX tell peers we are shutting down?
// XXX ret err = ctx.Err()
case
<-
retch
:
}
log
.
Info
(
ctx
,
"%v: closing link"
,
link
)
link
.
Close
()
// XXX err
}()
// XXX only accept clients
// XXX only accept clients
// XXX only accept when operational (?)
// XXX only accept when operational (?)
...
@@ -463,6 +447,8 @@ func (stor *Storage) ServeLink(ctx context.Context, link *neo.NodeLink) {
...
@@ -463,6 +447,8 @@ func (stor *Storage) ServeLink(ctx context.Context, link *neo.NodeLink) {
}
}
// TODO wait all spawned serveConn
// TODO wait all spawned serveConn
return
nil
}
}
// withWhileOperational derives new context from ctx which will be cancelled, when either
// withWhileOperational derives new context from ctx which will be cancelled, when either
...
...
go/xcommon/xcontext/xcontext.go
View file @
379cc163
...
@@ -170,3 +170,29 @@ func Canceled(err error) bool {
...
@@ -170,3 +170,29 @@ func Canceled(err error) bool {
return
false
return
false
}
}
// WhenDone arranges f to be called either when ctx is cancelled or surrounding
// function returns.
//
// To work as intended it should be called under defer like this:
//
// func myfunc(ctx, ...) {
// defer xcontext.WhenDone(ctx, func() { ... })()
func
WhenDone
(
ctx
context
.
Context
,
f
func
())
func
()
{
done
:=
make
(
chan
struct
{})
go
func
()
{
select
{
case
<-
ctx
.
Done
()
:
// ok
case
<-
done
:
// ok
}
f
()
}()
return
func
()
{
close
(
done
)
}
}
go/xcommon/xio/xio.go
View file @
379cc163
...
@@ -4,10 +4,14 @@
...
@@ -4,10 +4,14 @@
package
xio
package
xio
import
(
import
(
"context"
"fmt"
"fmt"
"io"
"io"
"net"
"net"
"os"
"os"
"lab.nexedi.com/kirr/neo/go/xcommon/log"
"lab.nexedi.com/kirr/neo/go/xcommon/xcontext"
)
)
// XXX interface for a Reader/Writer which can report position
// XXX interface for a Reader/Writer which can report position
...
@@ -82,3 +86,22 @@ func Name(f interface {}) string {
...
@@ -82,3 +86,22 @@ func Name(f interface {}) string {
return
fmt
.
Sprintf
(
"%#v"
,
f
)
return
fmt
.
Sprintf
(
"%#v"
,
f
)
}
}
}
}
// CloseWhenDone arranges for c to be closed either when ctx is cancelled or
// surrounding function returns.
//
// To work as intended it should be called under defer like this:
//
// func myfunc(ctx, ...) {
// defer xio.CloseWhenDone(ctx, c)()
//
// The error - if c.Close() returns with any - is logged.
func
CloseWhenDone
(
ctx
context
.
Context
,
c
io
.
Closer
)
func
()
{
return
xcontext
.
WhenDone
(
ctx
,
func
()
{
err
:=
c
.
Close
()
if
err
!=
nil
{
log
.
Error
(
ctx
,
err
)
}
})
}
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