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
04cd9562
Commit
04cd9562
authored
2 years ago
by
Georgy Moshkin
Browse files
Options
Downloads
Patches
Plain Diff
chore: add doc comments for yielding functions
parent
9fba1c89
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!183
Refactor/remove mailbox
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/traft/node.rs
+18
-0
18 additions, 0 deletions
src/traft/node.rs
with
18 additions
and
0 deletions
src/traft/node.rs
+
18
−
0
View file @
04cd9562
...
@@ -89,6 +89,8 @@ impl std::fmt::Debug for Node {
...
@@ -89,6 +89,8 @@ impl std::fmt::Debug for Node {
impl
Node
{
impl
Node
{
pub
const
TICK
:
Duration
=
Duration
::
from_millis
(
100
);
pub
const
TICK
:
Duration
=
Duration
::
from_millis
(
100
);
/// Initialize the raft node.
/// **This function yields**
pub
fn
new
(
cfg
:
&
raft
::
Config
)
->
Result
<
Self
,
RaftError
>
{
pub
fn
new
(
cfg
:
&
raft
::
Config
)
->
Result
<
Self
,
RaftError
>
{
let
raw_node
=
RawNode
::
new
(
cfg
,
Storage
,
&
tlog
::
root
())
?
;
let
raw_node
=
RawNode
::
new
(
cfg
,
Storage
,
&
tlog
::
root
())
?
;
let
raw_node
=
Rc
::
new
(
Mutex
::
new
(
raw_node
));
let
raw_node
=
Rc
::
new
(
Mutex
::
new
(
raw_node
));
...
@@ -151,10 +153,13 @@ impl Node {
...
@@ -151,10 +153,13 @@ impl Node {
event
::
broadcast
(
Event
::
StatusChanged
);
event
::
broadcast
(
Event
::
StatusChanged
);
}
}
/// Wait for the status to be changed.
/// **This function yields**
pub
fn
wait_status
(
&
self
)
{
pub
fn
wait_status
(
&
self
)
{
event
::
wait
(
Event
::
StatusChanged
)
.expect
(
"Events system wasn't initialized"
);
event
::
wait
(
Event
::
StatusChanged
)
.expect
(
"Events system wasn't initialized"
);
}
}
/// **This function yields**
pub
fn
read_index
(
&
self
,
timeout
:
Duration
)
->
Result
<
RaftIndex
,
Error
>
{
pub
fn
read_index
(
&
self
,
timeout
:
Duration
)
->
Result
<
RaftIndex
,
Error
>
{
self
.raw_operation
(|
raw_node
|
{
self
.raw_operation
(|
raw_node
|
{
// In some states `raft-rs` ignores the ReadIndex request.
// In some states `raft-rs` ignores the ReadIndex request.
...
@@ -181,6 +186,8 @@ impl Node {
...
@@ -181,6 +186,8 @@ impl Node {
.recv_timeout
::
<
RaftIndex
>
(
timeout
)
.recv_timeout
::
<
RaftIndex
>
(
timeout
)
}
}
/// Propose an operation and wait for it's result.
/// **This function yields**
pub
fn
propose
<
T
:
OpResult
+
Into
<
traft
::
Op
>>
(
pub
fn
propose
<
T
:
OpResult
+
Into
<
traft
::
Op
>>
(
&
self
,
&
self
,
op
:
T
,
op
:
T
,
...
@@ -195,6 +202,9 @@ impl Node {
...
@@ -195,6 +202,9 @@ impl Node {
.recv_timeout
::
<
T
::
Result
>
(
timeout
)
.recv_timeout
::
<
T
::
Result
>
(
timeout
)
}
}
/// Become a candidate and wait for a main loop round so that there's a
/// chance we become the leader.
/// **This function yields**
pub
fn
campaign
(
&
self
)
->
Result
<
(),
Error
>
{
pub
fn
campaign
(
&
self
)
->
Result
<
(),
Error
>
{
self
.raw_operation
(|
raw_node
|
raw_node
.campaign
()
.map_err
(
Into
::
into
))
?
;
self
.raw_operation
(|
raw_node
|
raw_node
.campaign
()
.map_err
(
Into
::
into
))
?
;
// Even though we don't expect a response, we still should let the
// Even though we don't expect a response, we still should let the
...
@@ -205,6 +215,7 @@ impl Node {
...
@@ -205,6 +215,7 @@ impl Node {
Ok
(())
Ok
(())
}
}
/// **This function yields**
pub
fn
step
(
&
self
,
msg
:
raft
::
Message
)
{
pub
fn
step
(
&
self
,
msg
:
raft
::
Message
)
{
self
.raw_operation
(|
raw_node
|
{
self
.raw_operation
(|
raw_node
|
{
if
msg
.to
!=
raw_node
.raft.id
{
if
msg
.to
!=
raw_node
.raft.id
{
...
@@ -221,6 +232,7 @@ impl Node {
...
@@ -221,6 +232,7 @@ impl Node {
fiber
::
reschedule
();
fiber
::
reschedule
();
}
}
/// **This function yields**
pub
fn
tick
(
&
self
,
n_times
:
u32
)
{
pub
fn
tick
(
&
self
,
n_times
:
u32
)
{
self
.raw_operation
(|
raw_node
|
{
self
.raw_operation
(|
raw_node
|
{
for
_
in
0
..
n_times
{
for
_
in
0
..
n_times
{
...
@@ -234,6 +246,7 @@ impl Node {
...
@@ -234,6 +246,7 @@ impl Node {
fiber
::
reschedule
();
fiber
::
reschedule
();
}
}
/// **This function yields**
pub
fn
timeout_now
(
&
self
)
{
pub
fn
timeout_now
(
&
self
)
{
self
.step
(
raft
::
Message
{
self
.step
(
raft
::
Message
{
to
:
self
.raft_id
,
to
:
self
.raft_id
,
...
@@ -243,6 +256,9 @@ impl Node {
...
@@ -243,6 +256,9 @@ impl Node {
})
})
}
}
/// Process the topology request and propose [`PersistPeer`] entry if
/// appropriate.
/// **This function yields**
pub
fn
handle_topology_request
(
&
self
,
req
:
TopologyRequest
)
->
Result
<
traft
::
Peer
,
Error
>
{
pub
fn
handle_topology_request
(
&
self
,
req
:
TopologyRequest
)
->
Result
<
traft
::
Peer
,
Error
>
{
self
.raw_operation
(|
raw_node
|
{
self
.raw_operation
(|
raw_node
|
{
if
raw_node
.raft.state
!=
RaftStateRole
::
Leader
{
if
raw_node
.raft.state
!=
RaftStateRole
::
Leader
{
...
@@ -296,6 +312,7 @@ impl Node {
...
@@ -296,6 +312,7 @@ impl Node {
.recv
::
<
Peer
>
()
.recv
::
<
Peer
>
()
}
}
/// **This function yields**
fn
propose_conf_change
(
fn
propose_conf_change
(
&
self
,
&
self
,
term
:
RaftTerm
,
term
:
RaftTerm
,
...
@@ -359,6 +376,7 @@ impl Node {
...
@@ -359,6 +376,7 @@ impl Node {
.recv
()
.recv
()
}
}
/// This function **may yield** if `self.raw_node` is acquired.
#[inline]
#[inline]
fn
raw_operation
<
R
>
(
fn
raw_operation
<
R
>
(
&
self
,
&
self
,
...
...
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