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
Commits
823b775b
Commit
823b775b
authored
2 years ago
by
Georgy Moshkin
Committed by
Georgy Moshkin
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor: add a macro for defining PeerChange
parent
dd1a213c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!299
Feat/poor mans vshard
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/traft/mod.rs
+45
-20
45 additions, 20 deletions
src/traft/mod.rs
src/traft/topology.rs
+14
-19
14 additions, 19 deletions
src/traft/topology.rs
with
59 additions
and
39 deletions
src/traft/mod.rs
+
45
−
20
View file @
823b775b
...
...
@@ -893,11 +893,51 @@ pub struct UpdatePeerRequest {
pub
changes
:
Vec
<
PeerChange
>
,
}
#[derive(Clone,
Debug,
Serialize,
Deserialize)]
pub
enum
PeerChange
{
CurrentGrade
(
CurrentGrade
),
TargetGrade
(
TargetGrade
),
FailureDomain
(
FailureDomain
),
macro_rules!
define_peer_change
{
(
$
(
#[
$
meta:meta]
)
*
pub
enum
$enum:ident
{
$
(
#[setter
=
$
setter:ident,
field
=
$
field:ident]
$variant:ident
(
$type:ty
),
)
*
}
)
=>
{
$
(
#[
$
meta]
)
*
pub
enum
$enum
{
$
(
$variant
(
$type
),
)
*
}
impl
$enum
{
pub
fn
apply
(
self
,
peer
:
&
mut
Peer
)
{
match
self
{
$
(
Self
::
$variant
(
value
)
=>
peer
.
$field
=
value
,
)
*
}
}
}
impl
UpdatePeerRequest
{
$
(
#[inline]
pub
fn
$setter
(
mut
self
,
value
:
$type
)
->
Self
{
self
.changes
.push
(
$enum
::
$variant
(
value
));
self
}
)
*
}
}
}
define_peer_change!
{
#[derive(Clone,
Debug,
Serialize,
Deserialize)]
pub
enum
PeerChange
{
#[setter
=
with_current_grade,
field
=
current_grade]
CurrentGrade
(
CurrentGrade
),
#[setter
=
with_target_grade,
field
=
target_grade]
TargetGrade
(
TargetGrade
),
#[setter
=
with_failure_domain,
field
=
failure_domain]
FailureDomain
(
FailureDomain
),
}
}
impl
Encode
for
UpdatePeerRequest
{}
...
...
@@ -910,21 +950,6 @@ impl UpdatePeerRequest {
changes
:
vec!
[],
}
}
#[inline]
pub
fn
with_current_grade
(
mut
self
,
current_grade
:
CurrentGrade
)
->
Self
{
self
.changes
.push
(
PeerChange
::
CurrentGrade
(
current_grade
));
self
}
#[inline]
pub
fn
with_target_grade
(
mut
self
,
target_grade
:
TargetGrade
)
->
Self
{
self
.changes
.push
(
PeerChange
::
TargetGrade
(
target_grade
));
self
}
#[inline]
pub
fn
with_failure_domain
(
mut
self
,
failure_domain
:
FailureDomain
)
->
Self
{
self
.changes
.push
(
PeerChange
::
FailureDomain
(
failure_domain
));
self
}
}
///////////////////////////////////////////////////////////////////////////////
...
...
This diff is collapsed.
Click to expand it.
src/traft/topology.rs
+
14
−
19
View file @
823b775b
...
...
@@ -193,31 +193,26 @@ impl Topology {
pub
fn
update_peer
(
&
mut
self
,
req
:
UpdatePeerRequest
)
->
Result
<
Peer
,
String
>
{
let
this
=
self
as
*
const
Self
;
let
mut
peer
=
self
let
peer
=
self
.instance_map
.get_mut
(
&
req
.instance_id
)
.ok_or_else
(||
format!
(
"unknown instance {}"
,
req
.instance_id
))
?
;
if
peer
.current_grade
==
CurrentGrade
::
Expelled
{
return
Err
(
format!
(
"cannot update expelled peer
\"
{}
\"
"
,
peer
.instance_id
));
}
for
change
in
req
.changes
{
match
change
{
PeerChange
::
CurrentGrade
(
grade
)
=>
{
if
peer
.current_grade
!=
CurrentGrade
::
Expelled
{
peer
.current_grade
=
grade
;
}
}
PeerChange
::
TargetGrade
(
target_grade
)
=>
{
if
peer
.target_grade
!=
TargetGrade
::
Expelled
{
peer
.target_grade
=
target_grade
;
}
}
PeerChange
::
FailureDomain
(
fd
)
=>
{
// SAFETY: this is safe, because rust doesn't complain if you inline
// the function
unsafe
{
&*
this
}
.check_required_failure_domain
(
&
fd
)
?
;
self
.failure_domain_names
.extend
(
fd
.names
()
.cloned
());
peer
.failure_domain
=
fd
;
}
if
let
PeerChange
::
FailureDomain
(
fd
)
=
&
change
{
// SAFETY: this is safe, because rust doesn't complain if you inline
// the function
unsafe
{
&*
this
}
.check_required_failure_domain
(
fd
)
?
;
self
.failure_domain_names
.extend
(
fd
.names
()
.cloned
());
}
change
.apply
(
peer
);
}
Ok
(
peer
.clone
())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment