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
87ce9b7b
Commit
87ce9b7b
authored
2 years ago
by
Georgy Moshkin
Committed by
Georgy Moshkin
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feature(discovery): support case when raft node is initialized
parent
f8e30cd1
No related branches found
No related tags found
1 merge request
!82
Feature/discovery/when raft initialized
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/discovery.rs
+23
-3
23 additions, 3 deletions
src/discovery.rs
src/traft/node.rs
+8
-0
8 additions, 0 deletions
src/traft/node.rs
with
31 additions
and
3 deletions
src/discovery.rs
+
23
−
3
View file @
87ce9b7b
...
...
@@ -2,11 +2,13 @@ use ::tarantool::fiber::{mutex::MutexGuard, Mutex};
use
::
tarantool
::
proc
;
use
::
tarantool
::
uuid
::
Uuid
;
use
serde
::{
Deserialize
,
Serialize
};
use
std
::
borrow
::
Cow
;
use
std
::
collections
::
BTreeSet
;
use
std
::
error
::
Error
as
StdError
;
use
crate
::
stringify_cfunc
;
use
crate
::
tarantool
;
use
crate
::
traft
;
type
Address
=
String
;
...
...
@@ -17,6 +19,14 @@ pub enum Role {
}
impl
Role
{
fn
new
(
address
:
Address
,
is_leader
:
bool
)
->
Self
{
if
is_leader
{
Self
::
Leader
{
address
}
}
else
{
Self
::
NonLeader
{
leader
:
address
}
}
}
fn
leader_address
(
&
self
)
->
&
Address
{
match
self
{
Self
::
Leader
{
address
}
=>
address
,
...
...
@@ -190,9 +200,19 @@ fn proc_discover<'a>(
#[inject(
&
mut
discovery())]
discovery
:
&
'a
mut
Option
<
MutexGuard
<
'a
,
Discovery
>>
,
request
:
Request
,
request_to
:
Address
,
)
->
Result
<&
'a
Response
,
Box
<
dyn
StdError
>>
{
let
discovery
=
discovery
.as_mut
()
.ok_or
(
"discovery uninitialized"
)
?
;
Ok
(
discovery
.handle_request
(
request
,
request_to
))
)
->
Result
<
Cow
<
'a
,
Response
>
,
Box
<
dyn
StdError
>>
{
if
let
Ok
(
node
)
=
traft
::
node
::
global
()
{
let
status
=
node
.status
();
let
leader
=
traft
::
Storage
::
peer_by_raft_id
(
status
.leader_id
)
?
.ok_or
(
"leader id is present, but it's address is unknown"
)
?
;
Ok
(
Cow
::
Owned
(
Response
::
Done
(
Role
::
new
(
leader
.peer_address
,
status
.am_leader
(),
))))
}
else
{
let
discovery
=
discovery
.as_mut
()
.ok_or
(
"discovery uninitialized"
)
?
;
Ok
(
Cow
::
Borrowed
(
discovery
.handle_request
(
request
,
request_to
)))
}
}
#[cfg(test)]
...
...
This diff is collapsed.
Click to expand it.
src/traft/node.rs
+
8
−
0
View file @
87ce9b7b
...
...
@@ -51,12 +51,20 @@ pub enum Error {
#[derive(Clone,
Debug,
tlua::Push,
tlua::PushInto)]
pub
struct
Status
{
/// `raft_id` of the current instance
pub
id
:
u64
,
/// `raft_id` of the leader instance
pub
leader_id
:
u64
,
pub
raft_state
:
String
,
pub
is_ready
:
bool
,
}
impl
Status
{
pub
fn
am_leader
(
&
self
)
->
bool
{
self
.id
==
self
.leader_id
}
}
/// The heart of `traft` module - the Node.
#[derive(Debug)]
pub
struct
Node
{
...
...
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