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
d315f583
Commit
d315f583
authored
2 years ago
by
Georgy Moshkin
Committed by
Georgy Moshkin
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor: Grade and TargetGrade using define_str_enum!
parent
ff7d882b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!244
attempt at topology governor
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/traft/failover.rs
+1
-1
1 addition, 1 deletion
src/traft/failover.rs
src/traft/mod.rs
+30
-48
30 additions, 48 deletions
src/traft/mod.rs
with
31 additions
and
49 deletions
src/traft/failover.rs
+
1
−
1
View file @
d315f583
...
@@ -115,7 +115,7 @@ fn raft_update_peer(
...
@@ -115,7 +115,7 @@ fn raft_update_peer(
super
::
PeerChange
::
Grade
(
grade
)
=>
{
super
::
PeerChange
::
Grade
(
grade
)
=>
{
tlog!
(
Warning
,
"attempt to change grade by peer"
;
tlog!
(
Warning
,
"attempt to change grade by peer"
;
"instance_id"
=>
instance_id
,
"instance_id"
=>
instance_id
,
"grade"
=>
grade
.
to
_str
(),
"grade"
=>
grade
.
as
_str
(),
);
);
false
false
}
}
...
...
This diff is collapsed.
Click to expand it.
src/traft/mod.rs
+
30
−
48
View file @
d315f583
...
@@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
...
@@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
use
std
::
any
::
Any
;
use
std
::
any
::
Any
;
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
std
::
convert
::
TryFrom
;
use
std
::
convert
::
TryFrom
;
use
std
::
fmt
::
{
Debug
,
Display
}
;
use
std
::
fmt
::
Debug
;
use
std
::
time
::
Duration
;
use
std
::
time
::
Duration
;
use
uuid
::
Uuid
;
use
uuid
::
Uuid
;
...
@@ -834,35 +834,24 @@ pub struct SyncRaftResponse {
...
@@ -834,35 +834,24 @@ pub struct SyncRaftResponse {
impl
Encode
for
SyncRaftResponse
{}
impl
Encode
for
SyncRaftResponse
{}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Activity state of an instance.
crate
::
define_str_enum!
{
#[derive(PartialEq,
Eq,
Clone,
Debug,
Deserialize,
Serialize)]
/// Activity state of an instance.
pub
enum
Grade
{
pub
enum
Grade
{
// Instance has gracefully shut down or has not been started yet.
// Instance has gracefully shut down or has not been started yet.
Offline
,
Offline
=
"Offline"
,
// Instance has synced by commit index.
// Instance has synced by commit index.
RaftSynced
,
RaftSynced
=
"RaftSynced"
,
// Instance is active and is handling requests.
// Instance is active and is handling requests.
Online
,
Online
=
"Online"
,
// Instance has permanently removed from cluster.
// Instance has permanently removed from cluster.
Expelled
,
Expelled
=
"Expelled"
,
}
impl
Grade
{
const
fn
to_str
(
&
self
)
->
&
str
{
match
self
{
Self
::
Offline
=>
"Offline"
,
Self
::
RaftSynced
=>
"RaftSynced"
,
Self
::
Online
=>
"Online"
,
Self
::
Expelled
=>
"Expelled"
,
}
}
}
FromStr
::
Err
=
UnknownGrade
;
}
}
impl
Display
for
Grade
{
#[derive(thiserror::Error,
Debug)]
fn
fmt
(
&
self
,
f
:
&
mut
std
::
fmt
::
Formatter
)
->
std
::
fmt
::
Result
{
#[error(
"unknown grade {0:?}"
)]
f
.write_str
(
self
.to_str
())
pub
struct
UnknownGrade
(
pub
String
);
}
}
impl
Default
for
Grade
{
impl
Default
for
Grade
{
fn
default
()
->
Self
{
fn
default
()
->
Self
{
...
@@ -870,29 +859,22 @@ impl Default for Grade {
...
@@ -870,29 +859,22 @@ impl Default for Grade {
}
}
}
}
#[derive(PartialEq,
Eq,
Clone,
Debug,
Deserialize,
Serialize)]
crate
::
define_str_enum!
{
pub
enum
TargetGrade
{
pub
enum
TargetGrade
{
// Instance should be configured up
// Instance should be configured up
Online
,
Online
=
"Online"
,
// Instance should be gracefully shut down
// Instance should be gracefully shut down
Offline
,
Offline
=
"Offline"
,
// Instance should be removed from cluster
// Instance should be removed from cluster
Expelled
,
Expelled
=
"Expelled"
,
}
impl
TargetGrade
{
const
fn
to_str
(
&
self
)
->
&
str
{
match
self
{
Self
::
Online
=>
"Online"
,
Self
::
Offline
=>
"Offline"
,
Self
::
Expelled
=>
"Expelled"
,
}
}
}
impl
Display
for
TargetGrade
{
fn
fmt
(
&
self
,
f
:
&
mut
std
::
fmt
::
Formatter
)
->
std
::
fmt
::
Result
{
f
.write_str
(
self
.to_str
())
}
}
FromStr
::
Err
=
UnknownTargetGrade
;
}
}
#[derive(thiserror::Error,
Debug)]
#[error(
"unknown target grade {0:?}"
)]
pub
struct
UnknownTargetGrade
(
pub
String
);
impl
Default
for
TargetGrade
{
impl
Default
for
TargetGrade
{
fn
default
()
->
Self
{
fn
default
()
->
Self
{
Self
::
Online
Self
::
Online
...
...
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