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
d41f328d
Commit
d41f328d
authored
Aug 08, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
48e38f91
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
18 deletions
+42
-18
go/neo/server/master.go
go/neo/server/master.go
+26
-18
go/neo/server/storage.go
go/neo/server/storage.go
+1
-0
go/xcommon/xcontext/xcontext.go
go/xcommon/xcontext/xcontext.go
+15
-0
No files found.
go/neo/server/master.go
View file @
d41f328d
...
...
@@ -150,9 +150,9 @@ func (m *Master) Run(ctx context.Context) error {
if
err
!=
nil
{
return
err
// XXX err ctx
}
m
.
logf
(
"serving on %s ..."
,
l
.
Addr
())
m
.
node
.
MasterAddr
=
l
.
Addr
()
.
String
()
m
.
logf
(
"serving on %s ..."
,
m
.
node
.
MasterAddr
)
// accept incoming connections and pass them to main driver
wg
:=
sync
.
WaitGroup
{}
...
...
@@ -231,7 +231,7 @@ func (m *Master) runMain(ctx context.Context) (err error) {
// XXX shutdown ?
}
return
fmt
.
Errorf
(
"master: run: %v
\n
"
,
ctx
.
Err
())
// XXX run -> runmain ?
return
errors
.
WithMessage
(
ctx
.
Err
(),
"master: run"
)
}
...
...
@@ -259,7 +259,8 @@ type storRecovery struct {
// - !nil: recovery was cancelled
func
(
m
*
Master
)
recovery
(
ctx
context
.
Context
)
(
err
error
)
{
m
.
log
(
"recovery"
)
defer
xerr
.
Context
(
&
err
,
"master: recovery"
)
//defer xerr.Context(&err, "master: recovery")
defer
m
.
errctx
(
&
err
,
"recovery"
)
m
.
setClusterState
(
neo
.
ClusterRecovering
)
rctx
,
rcancel
:=
context
.
WithCancel
(
ctx
)
...
...
@@ -299,17 +300,17 @@ loop:
err
:=
m
.
accept
(
n
.
conn
,
resp
)
if
err
!=
nil
{
// XXX better m.nodeLeave <- nodeLeave{node, err} ?
// XXX move this m.nodeLeave <- to accept() ?
recovery
<-
storRecovery
{
node
:
node
,
err
:
err
}
return
}
// start recovery
storCtlRecovery
(
rctx
,
node
,
recovery
)
}()
// XXX calrify who sends here
/*
// XXX calrify who sends here
case n := <-m.nodeLeave:
// TODO close n.node.Link
//
...
...
@@ -324,8 +325,8 @@ loop:
if
r
.
err
!=
nil
{
m
.
logf
(
"%v"
,
r
.
err
)
// XXX only if not cancelled
m
.
logf
(
"master:
%v: closing link"
,
r
.
node
.
Link
)
if
!
xcontext
.
Canceled
(
errors
.
Cause
(
r
.
err
))
{
m
.
logf
(
"
%v: closing link"
,
r
.
node
.
Link
)
// close stor link / update .nodeTab
err
:=
r
.
node
.
Link
.
Close
()
...
...
@@ -334,6 +335,7 @@ loop:
}
m
.
nodeTab
.
SetNodeState
(
r
.
node
,
DOWN
)
}
}
else
{
// we are interested in latest partTab
...
...
@@ -393,10 +395,7 @@ loop:
// we do not care errors here - they are either cancelled or IO errors
// we just log them and return - in case it is IO error
// on link it will be caught on next send/recv XXX
switch
errors
.
Cause
(
r
.
err
)
{
case
context
.
Canceled
,
context
.
DeadlineExceeded
:
// ok
default
:
if
!
xcontext
.
Canceled
(
errors
.
Cause
(
r
.
err
))
{
// XXX not so ok
}
...
...
@@ -1267,7 +1266,7 @@ func (m *Master) ServeMaster(ctx context.Context, conn *neo.Conn) {
func
(
m
*
Master
)
logf
(
format
string
,
argv
...
interface
{})
{
// TODO support custom log.Logger
log
.
Output
(
2
,
fmt
.
Sprintf
(
"master
@%v
: "
+
format
,
append
([]
string
{
m
.
MasterAddr
},
argv
...
)
...
))
log
.
Output
(
2
,
fmt
.
Sprintf
(
"master
(%v)
: "
+
format
,
append
([]
string
{
m
.
MasterAddr
},
argv
...
)
...
))
}
func
(
m
*
Master
)
vlogf
(
format
string
,
argv
...
interface
{})
{
...
...
@@ -1277,3 +1276,12 @@ func (m *Master) vlogf(format string, argv ...interface{}) {
}
m
.
log
(
format
,
argv
)
}
func
(
m
*
Master
)
errctx
(
errp
*
error
,
context
string
)
{
if
*
errp
==
nil
{
return
}
xerr
.
Contextf
(
errp
,
"master(%v): %s"
,
m
.
node
.
MasterAddr
,
context
)
}
go/neo/server/storage.go
View file @
d41f328d
...
...
@@ -92,6 +92,7 @@ func (stor *Storage) Run(ctx context.Context) error {
if
err
!=
nil
{
return
err
// XXX err ctx
}
stor
.
logf
(
"serving on %s ..."
,
l
.
Addr
())
// start serving incoming connections
wg
:=
sync
.
WaitGroup
{}
...
...
go/xcommon/xcontext/xcontext.go
View file @
d41f328d
...
...
@@ -120,3 +120,18 @@ func (mc *mergeCtx) Value(key interface{}) interface{} {
}
return
mc
.
ctx2
.
Value
(
key
)
}
// Cancelled reports whether an error is due to a canceled context.
//
// Since both cancellation - explicit and due to exceeding context deadline -
// result in the same signal to work being done under context, Canceled treats
// both context.Canceled and context.DeadlineExceeded as errors indicating
// context cancellation.
func
Canceled
(
err
error
)
bool
{
switch
err
{
case
context
.
Canceled
,
context
.
DeadlineExceeded
:
return
true
}
return
false
}
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