Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
fe3f42be
Unverified
Commit
fe3f42be
authored
Jul 23, 2024
by
Zach Howard
Committed by
GitHub
Jul 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-conductor: Adds connection test to conductor addServer* apis (#11210)
parent
0db615dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
+18
-0
raft.go
op-conductor/consensus/raft.go
+18
-0
No files found.
op-conductor/consensus/raft.go
View file @
fe3f42be
...
@@ -32,6 +32,16 @@ type RaftConsensus struct {
...
@@ -32,6 +32,16 @@ type RaftConsensus struct {
unsafeTracker
*
unsafeHeadTracker
unsafeTracker
*
unsafeHeadTracker
}
}
// checkTCPPortOpen attempts to connect to the specified address and returns an error if the connection fails.
func
checkTCPPortOpen
(
address
string
)
error
{
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
address
,
5
*
time
.
Second
)
if
err
!=
nil
{
return
err
}
defer
conn
.
Close
()
return
nil
}
// NewRaftConsensus creates a new RaftConsensus instance.
// NewRaftConsensus creates a new RaftConsensus instance.
func
NewRaftConsensus
(
log
log
.
Logger
,
serverID
,
serverAddr
,
storageDir
string
,
bootstrap
bool
,
rollupCfg
*
rollup
.
Config
)
(
*
RaftConsensus
,
error
)
{
func
NewRaftConsensus
(
log
log
.
Logger
,
serverID
,
serverAddr
,
storageDir
string
,
bootstrap
bool
,
rollupCfg
*
rollup
.
Config
)
(
*
RaftConsensus
,
error
)
{
rc
:=
raft
.
DefaultConfig
()
rc
:=
raft
.
DefaultConfig
()
...
@@ -113,6 +123,10 @@ func NewRaftConsensus(log log.Logger, serverID, serverAddr, storageDir string, b
...
@@ -113,6 +123,10 @@ func NewRaftConsensus(log log.Logger, serverID, serverAddr, storageDir string, b
// AddNonVoter implements Consensus, it tries to add a non-voting member into the cluster.
// AddNonVoter implements Consensus, it tries to add a non-voting member into the cluster.
func
(
rc
*
RaftConsensus
)
AddNonVoter
(
id
string
,
addr
string
,
version
uint64
)
error
{
func
(
rc
*
RaftConsensus
)
AddNonVoter
(
id
string
,
addr
string
,
version
uint64
)
error
{
if
err
:=
checkTCPPortOpen
(
addr
);
err
!=
nil
{
rc
.
log
.
Error
(
"connection test to member addr failed"
,
"id"
,
id
,
"addr"
,
addr
,
"err"
,
err
)
return
err
}
if
err
:=
rc
.
r
.
AddNonvoter
(
raft
.
ServerID
(
id
),
raft
.
ServerAddress
(
addr
),
version
,
defaultTimeout
)
.
Error
();
err
!=
nil
{
if
err
:=
rc
.
r
.
AddNonvoter
(
raft
.
ServerID
(
id
),
raft
.
ServerAddress
(
addr
),
version
,
defaultTimeout
)
.
Error
();
err
!=
nil
{
rc
.
log
.
Error
(
"failed to add non-voter"
,
"id"
,
id
,
"addr"
,
addr
,
"version"
,
version
,
"err"
,
err
)
rc
.
log
.
Error
(
"failed to add non-voter"
,
"id"
,
id
,
"addr"
,
addr
,
"version"
,
version
,
"err"
,
err
)
return
err
return
err
...
@@ -122,6 +136,10 @@ func (rc *RaftConsensus) AddNonVoter(id string, addr string, version uint64) err
...
@@ -122,6 +136,10 @@ func (rc *RaftConsensus) AddNonVoter(id string, addr string, version uint64) err
// AddVoter implements Consensus, it tries to add a voting member into the cluster.
// AddVoter implements Consensus, it tries to add a voting member into the cluster.
func
(
rc
*
RaftConsensus
)
AddVoter
(
id
string
,
addr
string
,
version
uint64
)
error
{
func
(
rc
*
RaftConsensus
)
AddVoter
(
id
string
,
addr
string
,
version
uint64
)
error
{
if
err
:=
checkTCPPortOpen
(
addr
);
err
!=
nil
{
rc
.
log
.
Error
(
"connection test to member addr failed"
,
"id"
,
id
,
"addr"
,
addr
,
"err"
,
err
)
return
err
}
if
err
:=
rc
.
r
.
AddVoter
(
raft
.
ServerID
(
id
),
raft
.
ServerAddress
(
addr
),
version
,
defaultTimeout
)
.
Error
();
err
!=
nil
{
if
err
:=
rc
.
r
.
AddVoter
(
raft
.
ServerID
(
id
),
raft
.
ServerAddress
(
addr
),
version
,
defaultTimeout
)
.
Error
();
err
!=
nil
{
rc
.
log
.
Error
(
"failed to add voter"
,
"id"
,
id
,
"addr"
,
addr
,
"version"
,
version
,
"err"
,
err
)
rc
.
log
.
Error
(
"failed to add voter"
,
"id"
,
id
,
"addr"
,
addr
,
"version"
,
version
,
"err"
,
err
)
return
err
return
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