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
4841f886
Commit
4841f886
authored
Jan 28, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
48faf697
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
43 deletions
+58
-43
go/neo/client.go
go/neo/client.go
+32
-19
go/neo/mastered.go
go/neo/mastered.go
+26
-24
No files found.
go/neo/client.go
View file @
4841f886
...
@@ -113,19 +113,41 @@ func NewClient(clusterName, masterAddr string, net xnet.Networker) *Client {
...
@@ -113,19 +113,41 @@ func NewClient(clusterName, masterAddr string, net xnet.Networker) *Client {
// Run starts client node and runs it until either ctx is canceled or master
// Run starts client node and runs it until either ctx is canceled or master
// commands it to shutdown. (TODO verify M->shutdown)
// commands it to shutdown. (TODO verify M->shutdown)
func
(
c
li
*
Client
)
Run
(
ctx
context
.
Context
)
(
err
error
)
{
func
(
c
*
Client
)
Run
(
ctx
context
.
Context
)
(
err
error
)
{
defer
task
.
Running
(
&
ctx
,
"client"
)(
&
err
)
defer
task
.
Running
(
&
ctx
,
"client"
)(
&
err
)
// run process which performs master talk
// run process which performs master talk
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
cli
.
runCancel
=
cancel
c
.
runCancel
=
cancel
// cli.node.OnShutdown = cancel // XXX ok?
// c.node.OnShutdown = cancel // XXX ok?
// return cli.talkMaster(ctx)
// return c.talkMaster(ctx)
cli
.
runWG
=
xsync
.
NewWorkGroup
(
ctx
)
// XXX create it in NewClient ? (Close also uses it)
// c.runWG = xsync.NewWorkGroup(ctx) // XXX create it in NewClient ? (Close also uses it)
cli
.
runWG
.
Go
(
cli
.
node
.
talkMaster
)
// c.runWG.Go(c.node.talkMaster)
cli
.
runWG
.
Go
(
cli
.
recvMaster
)
// c.runWG.Go(c.recvMaster)
return
cli
.
runWG
.
Wait
()
return
c
.
node
.
TalkMaster
(
ctx
,
func
(
ctx
context
.
Context
,
mlink
*
neonet
.
NodeLink
)
error
{
// XXX errctx ("on redial"? "connected"?)
c
.
head0
=
c
.
head
wg
:=
xsync
.
NewWorkGroup
(
ctx
)
// launch master notifications receiver
wg
.
Go
(
func
(
ctx
context
.
Context
)
error
{
return
c
.
recvMaster
(
ctx
)
})
// init lastTid from master
// TODO better change protocol for master to send us head via notify
// channel right after identification.
wg
.
Go
(
func
(
ctx
context
.
Context
)
error
{
return
c
.
initFromMaster
(
ctx
,
mlink
)
})
return
wg
.
Wait
()
})
// return c.runWG.Wait()
}
}
// Close implements zodb.IStorageDriver.
// Close implements zodb.IStorageDriver.
...
@@ -368,16 +390,7 @@ func (c *Client) recvMaster(ctx context.Context) (err error) {
...
@@ -368,16 +390,7 @@ func (c *Client) recvMaster(ctx context.Context) (err error) {
for
{
for
{
req
,
err
:=
c
.
node
.
RecvM1
()
req
,
err
:=
c
.
node
.
RecvM1
()
if
err
!=
nil
{
if
err
!=
nil
{
switch
{
return
err
// reconnected to master
case
errors
.
Is
(
err
,
eventMasterReconnect
)
:
c
.
head0
=
c
.
head
// XXX -> initFromMaster
default
:
return
err
}
continue
}
}
err
=
c
.
recvMaster1
(
req
.
Msg
)
err
=
c
.
recvMaster1
(
req
.
Msg
)
...
...
go/neo/mastered.go
View file @
4841f886
...
@@ -29,6 +29,7 @@ import (
...
@@ -29,6 +29,7 @@ import (
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/go123/xsync"
"lab.nexedi.com/kirr/neo/go/internal/log"
"lab.nexedi.com/kirr/neo/go/internal/log"
"lab.nexedi.com/kirr/neo/go/internal/task"
"lab.nexedi.com/kirr/neo/go/internal/task"
...
@@ -132,17 +133,19 @@ func newMasteredNode(typ proto.NodeType, clusterName string, net xnet.Networker,
...
@@ -132,17 +133,19 @@ func newMasteredNode(typ proto.NodeType, clusterName string, net xnet.Networker,
//
t
alkMaster dials master, identifies to it, and receives master notifications and requests.
//
T
alkMaster dials master, identifies to it, and receives master notifications and requests.
//
//
// Notifications to node/partition tables and cluster state are automatically
// Notifications to node/partition tables and cluster state are automatically
// handled, while other notifications and requests are passed through to RecvM1.
// handled, while other notifications and requests are passed through to RecvM1.
//
//
// The connection to master is persisted by redial as needed.
// The connection to master is persisted by redial as needed.
func
(
node
*
_MasteredNode
)
talkMaster
(
ctx
context
.
Context
)
(
err
error
)
{
//
// f is called on every reconnection after identification and protocol prologue. XXX
func
(
node
*
_MasteredNode
)
TalkMaster
(
ctx
context
.
Context
,
f
func
(
context
.
Context
,
*
neonet
.
NodeLink
)
error
)
(
err
error
)
{
defer
task
.
Runningf
(
&
ctx
,
"talk master(%s)"
,
node
.
MasterAddr
)(
&
err
)
defer
task
.
Runningf
(
&
ctx
,
"talk master(%s)"
,
node
.
MasterAddr
)(
&
err
)
for
{
for
{
err
:=
node
.
talkMaster1
(
ctx
)
err
:=
node
.
talkMaster1
(
ctx
,
f
)
log
.
Warning
(
ctx
,
err
)
// XXX Warning ok? -> Error?
log
.
Warning
(
ctx
,
err
)
// XXX Warning ok? -> Error?
// TODO if err == "reject identification / protocol error" -> shutdown client
// TODO if err == "reject identification / protocol error" -> shutdown client
// TODO if err == shutdown -> return
// TODO if err == shutdown -> return
...
@@ -160,7 +163,7 @@ func (node *_MasteredNode) talkMaster(ctx context.Context) (err error) {
...
@@ -160,7 +163,7 @@ func (node *_MasteredNode) talkMaster(ctx context.Context) (err error) {
}
}
}
}
func
(
node
*
_MasteredNode
)
talkMaster1
(
ctx
context
.
Context
)
error
{
func
(
node
*
_MasteredNode
)
talkMaster1
(
ctx
context
.
Context
,
f
func
(
context
.
Context
,
*
neonet
.
NodeLink
)
error
)
error
{
reqID
:=
&
proto
.
RequestIdentification
{
reqID
:=
&
proto
.
RequestIdentification
{
NodeType
:
node
.
myInfo
.
Type
,
NodeType
:
node
.
myInfo
.
Type
,
NID
:
node
.
myInfo
.
NID
,
NID
:
node
.
myInfo
.
NID
,
...
@@ -220,28 +223,27 @@ func (node *_MasteredNode) talkMaster1(ctx context.Context) error {
...
@@ -220,28 +223,27 @@ func (node *_MasteredNode) talkMaster1(ctx context.Context) error {
// XXX update .masterLink + notify waiters
// XXX update .masterLink + notify waiters
// RecvM1 <- eventReconnect
wg
:=
xsync
.
NewWorkGroup
(
ctx
)
select
{
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
case
node
.
rxm
<-
_RxM
{
Err
:
eventMasterReconnect
}
:
// ok
}
// receive and handle notifications from master
// receive and handle notifications from master
defer
task
.
Running
(
&
ctx
,
"rx"
)(
&
err
)
wg
.
Go
(
func
(
ctx
context
.
Context
)
error
{
for
{
defer
task
.
Running
(
&
ctx
,
"rx"
)(
&
err
)
req
,
err
:=
mlink
.
Recv1
()
for
{
if
err
!=
nil
{
req
,
err
:=
mlink
.
Recv1
()
return
err
if
err
!=
nil
{
return
err
}
err
=
node
.
recvMaster1
(
ctx
,
req
)
// req ownership is passed in
if
err
!=
nil
{
return
err
}
}
}
err
=
node
.
recvMaster1
(
ctx
,
req
)
// req ownership is passed in
})
if
err
!=
nil
{
// run user code
return
err
wg
.
Go
(
func
(
ctx
context
.
Context
)
error
{
}
return
f
(
ctx
,
mlink
)
}
})
return
wg
.
Wait
()
})
})
}
}
...
...
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