Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
picodata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
picodata
Merge requests
!349
refactor: simplify conf_change even more
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
refactor: simplify conf_change even more
raft-conf-change
into
master
Overview
0
Commits
1
Pipelines
2
Changes
1
Merged
Yaroslav Dynnikov
requested to merge
raft-conf-change
into
master
2 years ago
Overview
0
Commits
1
Pipelines
2
Changes
1
Expand
Extract part of changes from
!300 (merged)
.
Edited
2 years ago
by
Yaroslav Dynnikov
0
0
Merge request reports
Compare
master
version 1
d34f0a15
2 years ago
master (base)
and
latest version
latest version
3427af80
1 commit,
2 years ago
version 1
d34f0a15
1 commit,
2 years ago
1 file
+
19
−
28
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/traft/governor.rs
+
19
−
28
Options
@@ -77,14 +77,17 @@ pub(crate) fn raft_conf_change(
// Remove / replace voters
for
voter_id
in
raft_conf
.voters
.clone
()
.iter
()
{
let
peer
=
raft_conf
.all
.get
(
voter_id
);
match
peer
{
#[rustfmt::skip]
Some
(
Peer
{
target_grade
:
TargetGrade
::
Online
,
..
})
=>
{
let
Some
(
peer
)
=
raft_conf
.all
.get
(
voter_id
)
else
{
// Nearly impossible, but rust forces me to check it.
let
ccs
=
raft_conf
.change_single
(
RemoveNode
,
*
voter_id
);
changes
.push
(
ccs
);
continue
;
};
match
peer
.target_grade
{
TargetGrade
::
Online
=>
{
// Do nothing
}
#[rustfmt::skip]
Some
(
peer
@
Peer
{
target_grade
:
TargetGrade
::
Offline
,
..
})
=>
{
TargetGrade
::
Offline
=>
{
// A voter goes offline. Replace it with
// another online instance if possible.
let
Some
(
replacement
)
=
peers
.iter
()
.find
(|
peer
|
{
@@ -96,17 +99,11 @@ pub(crate) fn raft_conf_change(
let
ccs2
=
raft_conf
.change_single
(
AddNode
,
replacement
.raft_id
);
changes
.extend_from_slice
(
&
[
ccs1
,
ccs2
]);
}
#[rustfmt::skip]
Some
(
peer
@
Peer
{
target_grade
:
TargetGrade
::
Expelled
,
..
})
=>
{
TargetGrade
::
Expelled
=>
{
// Expelled instance is removed unconditionally.
let
ccs
=
raft_conf
.change_single
(
RemoveNode
,
peer
.raft_id
);
changes
.push
(
ccs
);
}
None
=>
{
// Nearly impossible, but rust forces me to check it.
let
ccs
=
raft_conf
.change_single
(
RemoveNode
,
*
voter_id
);
changes
.push
(
ccs
);
}
}
}
@@ -119,27 +116,21 @@ pub(crate) fn raft_conf_change(
// Remove unknown / expelled learners
for
learner_id
in
raft_conf
.learners
.clone
()
.iter
()
{
let
peer
=
raft_conf
.all
.get
(
learner_id
)
;
match
peer
{
#[rustfmt::skip]
Some
(
Peer
{
target_grade
:
TargetGrade
::
Online
,
..
})
=>
{
// Do nothing
}
#[rustfmt::skip]
Some
(
Peer
{
t
arget
_g
rade
:
TargetGrade
::
Offline
,
..
})
=>
{
let
Some
(
peer
)
=
raft_conf
.all
.get
(
learner_id
)
else
{
// Nearly impossible, but rust forces me to check it.
let
ccs
=
raft_conf
.change_single
(
RemoveNode
,
*
learner_id
);
changes
.push
(
ccs
);
continue
;
}
;
match
peer
.target_grade
{
T
arget
G
rade
:
:
Online
|
TargetGrade
::
Offline
=>
{
// Do nothing
}
#[rustfmt::skip]
Some
(
peer
@
Peer
{
target_grade
:
TargetGrade
::
Expelled
,
..
})
=>
{
TargetGrade
::
Expelled
=>
{
// Expelled instance is removed unconditionally.
let
ccs
=
raft_conf
.change_single
(
RemoveNode
,
peer
.raft_id
);
changes
.push
(
ccs
);
}
None
=>
{
// Nearly impossible, but rust forces me to check it.
let
ccs
=
raft_conf
.change_single
(
RemoveNode
,
*
learner_id
);
changes
.push
(
ccs
);
}
}
}
Loading