[−][src]Struct raftlog::ReplicatedLog
Raftアルゴリズムに基づく分散複製ログ.
利用者はpropose_command
メソッドを使って、コマンドをログに複製保存し、
発生するEvent
をハンドリングすることで、
整合性のある複製状態機械を実現することが可能となる.
ReplicatedLog
はStream
トレイトを実装しているが、
これは無限ストリームであり、エラー時を除いて終了することはない.
ただし、構成変更によりノードがクラスタから切り離された場合は、
最終的には、イベントが生成されることは無くなる.
this.local_history().config().is_known_node()
メソッドを使うことで、
クラスタ内に属しているかどうかは判定可能なので、利用者側が明示的に確認して、
不要になったReplicatedLog
インスタンスを回収することは可能.
Methods
impl<IO: Io> ReplicatedLog<IO>
[src]
pub fn new(
node_id: NodeId,
members: ClusterMembers,
io: IO,
metric_builder: &MetricBuilder
) -> Result<Self>
[src]
node_id: NodeId,
members: ClusterMembers,
io: IO,
metric_builder: &MetricBuilder
) -> Result<Self>
members
で指定されたクラスタに属するReplicatedLog
のローカルインスタンス(ノード)を生成する.
ローカルノードのIDはnode_id
で指定するが、これがmembers
の含まれている必要は必ずしもない.
例えば、クラスタの構成変更に伴い、新規ノードを追加したい場合には、
members
に現行構成を指定することが望ましいが、このケースでは、
node_id
はmembers
の中には含まれないことになる.
なお、ノードの再起動時を除いて、node_id
には対象クラスタの歴史の中でユニークなIDを
割り当てるのが望ましい.
(レアケースではあるが、新規追加ノードを、以前に存在したノードと誤認識されてしまうと、
分散ログの整合性が壊れてしまう危険性があるため)
また、以前のノードを再起動したい場合でも、もし永続ストレージが壊れている等の理由で、 前回の状態を正確に復元できないのであれば、 ノード名を変更して、新規ノード追加扱いにした方が安全である.
pub fn metrics(&self) -> &Arc<RaftlogMetrics>
[src]
raftlog
のメトリクスを返す。
pub fn propose_command(&mut self, command: Vec<u8>) -> Result<ProposalId>
[src]
新しいコマンドを提案する.
提案が承認(コミット)された場合には、返り値のLogPosition
を含む
Event::Committed
イベントが返される.
もし返り値のLogPosition
とは分岐したEvent::Committed
が返された場合には、
この提案が棄却されたことを示している.
Errors
非リーダノードに対して、このメソッドが実行された場合には、
ErrorKind::NotLeader
を理由としたエラーが返される.
pub fn propose_config(
&mut self,
new_members: ClusterMembers
) -> Result<ProposalId>
[src]
&mut self,
new_members: ClusterMembers
) -> Result<ProposalId>
新しいクラスタ構成(新メンバ群)を提案する.
提案が承認(コミット)された場合には、返り値のLogPosition
を含む
Event::Committed
イベントが返される.
ただし、承認された場合であっても、それは新旧混合状態の構成が承認されただけであり、
新メンバのみの構成への移行完了を把握したい場合には、後続のコミットイベントの
追跡を行う必要がある.
もし返り値のLogPosition
とは分岐したEvent::Committed
が返された場合には、
この提案が棄却されたことを示している.
複数の構成変更を並行して実施することは可能だが、 その場合は、最後に提案されたものが最終的な構成として採用される.
Errors
非リーダノードに対して、このメソッドが実行された場合には、
ErrorKind::NotLeader
を理由としたエラーが返される.
pub fn heartbeat(&mut self) -> Result<SequenceNumber>
[src]
強制的にハートビートメッセージ(i.e., AppendEntriesCall)をブロードキャストする.
返り値は、送信メッセージのシーケンス番号.
last_heartbeat_ack
メソッドを用いることで、
このハートビートに対して、過半数以上の応答を得られた
タイミングを把握することが可能.
また、リーダのコミットを即座にフォロワーに伝えたい場合にも、
このメソッドが活用可能。
(Event::Committed
をリーダが生成した直後にheartbeat
メソッドを呼び出せば良い)
なおノードの役割が非リーダに変わった場合には、 応答待機中のハートビートは全て破棄されるので注意が必要.
Errors
非リーダノードに対して、このメソッドが実行された場合には、
ErrorKind::NotLeader
を理由としたエラーが返される.
pub fn install_snapshot(
&mut self,
new_head: LogIndex,
snapshot: Vec<u8>
) -> Result<()>
[src]
&mut self,
new_head: LogIndex,
snapshot: Vec<u8>
) -> Result<()>
ローカルログにスナップショットをインストールする.
new_head
が新しいローカルログの先頭位置となり、
snapshot
はその地点までのコマンド群が適用済みの状態機械のスナップショット、となる.
Errors
既にローカルログに対するスナップショットのインストールが進行中の場合には、
ErrorKind::Busy
を理由としてエラーが返される.
また現在のログの先頭よりも前の地点のスナップショットをインストールしようとした場合には、
ErrorKind::InvalidInput
を理由としたエラーが返される.
pub fn start_election(&mut self)
[src]
新しい選挙を開始する.
何らかの手段で現在のリーダのダウンを検知した場合に呼び出される.
pub fn local_node(&self) -> &Node
[src]
ローカルノードの情報を返す.
pub fn local_history(&self) -> &LogHistory
[src]
ローカルログの履歴を返す.
pub fn proposal_queue_len(&self) -> usize
[src]
ローカルログへの書き込み待ちの状態の提案群の数を返す.
この値は、ローカルストレージの詰まり具合を把握するために有用である.
「ローカルログへは追記完了 and コミット待ち」の個数は
知りたい場合にはlocal_history
メソッド経由で取得可能.
ローカルノードが非リーダである場合には、常に0
が返される.
pub fn is_snapshot_installing(&self) -> bool
[src]
スナップショットをインストール中の場合にはtrue
を返す.
このメソッドがtrue
を返している間は、
新しいスナップショットのインストールを行うことはできない.
pub fn last_heartbeat_ack(&self) -> SequenceNumber
[src]
過半数以上の応答を得られた最新のハートビート(i.e., AppendEntriesCall) のシーケンス番号を返す.
この値は、同じ選挙期間に関しては減少することはないことが保証されている.
注意
ハートビートを行うのはリーダノードのみなので、それ以外のノードに関しては、 このメソッドが返す値は意味を持たない.
pub fn cluster_config(&self) -> &ClusterConfig
[src]
現在のクラスタ構成を返す.
pub fn io(&self) -> &IO
[src]
I/O実装に対する参照を返す.
pub unsafe fn io_mut(&mut self) -> &mut IO
[src]
Trait Implementations
impl<IO: Io> Stream for ReplicatedLog<IO>
[src]
type Item = Event
The type of item this stream will yield on success.
type Error = Error
The type of error this stream may generate.
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn wait(self) -> Wait<Self>
[src]
fn into_future(self) -> StreamFuture<Self>
[src]
fn map<U, F>(self, f: F) -> Map<Self, F> where
F: FnMut(Self::Item) -> U,
[src]
F: FnMut(Self::Item) -> U,
fn map_err<U, F>(self, f: F) -> MapErr<Self, F> where
F: FnMut(Self::Error) -> U,
[src]
F: FnMut(Self::Error) -> U,
fn filter<F>(self, f: F) -> Filter<Self, F> where
F: FnMut(&Self::Item) -> bool,
[src]
F: FnMut(&Self::Item) -> bool,
fn filter_map<F, B>(self, f: F) -> FilterMap<Self, F> where
F: FnMut(Self::Item) -> Option<B>,
[src]
F: FnMut(Self::Item) -> Option<B>,
fn then<F, U>(self, f: F) -> Then<Self, F, U> where
F: FnMut(Result<Self::Item, Self::Error>) -> U,
U: IntoFuture,
[src]
F: FnMut(Result<Self::Item, Self::Error>) -> U,
U: IntoFuture,
fn and_then<F, U>(self, f: F) -> AndThen<Self, F, U> where
F: FnMut(Self::Item) -> U,
U: IntoFuture<Error = Self::Error>,
[src]
F: FnMut(Self::Item) -> U,
U: IntoFuture<Error = Self::Error>,
fn or_else<F, U>(self, f: F) -> OrElse<Self, F, U> where
F: FnMut(Self::Error) -> U,
U: IntoFuture<Item = Self::Item>,
[src]
F: FnMut(Self::Error) -> U,
U: IntoFuture<Item = Self::Item>,
fn collect(self) -> Collect<Self>
[src]
fn concat2(self) -> Concat2<Self> where
Self::Item: Extend<<Self::Item as IntoIterator>::Item>,
Self::Item: IntoIterator,
Self::Item: Default,
[src]
Self::Item: Extend<<Self::Item as IntoIterator>::Item>,
Self::Item: IntoIterator,
Self::Item: Default,
fn concat(self) -> Concat<Self> where
Self::Item: Extend<<Self::Item as IntoIterator>::Item>,
Self::Item: IntoIterator,
[src]
Self::Item: Extend<<Self::Item as IntoIterator>::Item>,
Self::Item: IntoIterator,
fn fold<F, T, Fut>(self, init: T, f: F) -> Fold<Self, F, Fut, T> where
F: FnMut(T, Self::Item) -> Fut,
Fut: IntoFuture<Item = T>,
Self::Error: From<<Fut as IntoFuture>::Error>,
[src]
F: FnMut(T, Self::Item) -> Fut,
Fut: IntoFuture<Item = T>,
Self::Error: From<<Fut as IntoFuture>::Error>,
fn flatten(self) -> Flatten<Self> where
Self::Item: Stream,
<Self::Item as Stream>::Error: From<Self::Error>,
[src]
Self::Item: Stream,
<Self::Item as Stream>::Error: From<Self::Error>,
fn skip_while<P, R>(self, pred: P) -> SkipWhile<Self, P, R> where
P: FnMut(&Self::Item) -> R,
R: IntoFuture<Item = bool, Error = Self::Error>,
[src]
P: FnMut(&Self::Item) -> R,
R: IntoFuture<Item = bool, Error = Self::Error>,
fn take_while<P, R>(self, pred: P) -> TakeWhile<Self, P, R> where
P: FnMut(&Self::Item) -> R,
R: IntoFuture<Item = bool, Error = Self::Error>,
[src]
P: FnMut(&Self::Item) -> R,
R: IntoFuture<Item = bool, Error = Self::Error>,
fn for_each<F, U>(self, f: F) -> ForEach<Self, F, U> where
F: FnMut(Self::Item) -> U,
U: IntoFuture<Item = (), Error = Self::Error>,
[src]
F: FnMut(Self::Item) -> U,
U: IntoFuture<Item = (), Error = Self::Error>,
fn from_err<E>(self) -> FromErr<Self, E> where
E: From<Self::Error>,
[src]
E: From<Self::Error>,
fn take(self, amt: u64) -> Take<Self>
[src]
fn skip(self, amt: u64) -> Skip<Self>
[src]
fn fuse(self) -> Fuse<Self>
[src]
fn by_ref(&mut self) -> &mut Self
[src]
fn catch_unwind(self) -> CatchUnwind<Self> where
Self: UnwindSafe,
[src]
Self: UnwindSafe,
fn buffered(self, amt: usize) -> Buffered<Self> where
Self::Item: IntoFuture,
<Self::Item as IntoFuture>::Error == Self::Error,
[src]
Self::Item: IntoFuture,
<Self::Item as IntoFuture>::Error == Self::Error,
fn buffer_unordered(self, amt: usize) -> BufferUnordered<Self> where
Self::Item: IntoFuture,
<Self::Item as IntoFuture>::Error == Self::Error,
[src]
Self::Item: IntoFuture,
<Self::Item as IntoFuture>::Error == Self::Error,
fn merge<S>(self, other: S) -> Merge<Self, S> where
S: Stream<Error = Self::Error>,
[src]
S: Stream<Error = Self::Error>,
fn zip<S>(self, other: S) -> Zip<Self, S> where
S: Stream<Error = Self::Error>,
[src]
S: Stream<Error = Self::Error>,
fn chain<S>(self, other: S) -> Chain<Self, S> where
S: Stream<Item = Self::Item, Error = Self::Error>,
[src]
S: Stream<Item = Self::Item, Error = Self::Error>,
fn peekable(self) -> Peekable<Self>
[src]
fn chunks(self, capacity: usize) -> Chunks<Self>
[src]
fn select<S>(self, other: S) -> Select<Self, S> where
S: Stream<Item = Self::Item, Error = Self::Error>,
[src]
S: Stream<Item = Self::Item, Error = Self::Error>,
fn forward<S>(self, sink: S) -> Forward<Self, S> where
S: Sink<SinkItem = Self::Item>,
Self::Error: From<<S as Sink>::SinkError>,
[src]
S: Sink<SinkItem = Self::Item>,
Self::Error: From<<S as Sink>::SinkError>,
fn split(self) -> (SplitSink<Self>, SplitStream<Self>) where
Self: Sink,
[src]
Self: Sink,
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
[src]
F: FnMut(&Self::Item),
fn inspect_err<F>(self, f: F) -> InspectErr<Self, F> where
F: FnMut(&Self::Error),
[src]
F: FnMut(&Self::Error),
Auto Trait Implementations
impl<IO> RefUnwindSafe for ReplicatedLog<IO> where
IO: RefUnwindSafe,
<IO as Io>::LoadBallot: RefUnwindSafe,
<IO as Io>::LoadLog: RefUnwindSafe,
<IO as Io>::SaveBallot: RefUnwindSafe,
<IO as Io>::SaveLog: RefUnwindSafe,
<IO as Io>::Timeout: RefUnwindSafe,
IO: RefUnwindSafe,
<IO as Io>::LoadBallot: RefUnwindSafe,
<IO as Io>::LoadLog: RefUnwindSafe,
<IO as Io>::SaveBallot: RefUnwindSafe,
<IO as Io>::SaveLog: RefUnwindSafe,
<IO as Io>::Timeout: RefUnwindSafe,
impl<IO> Send for ReplicatedLog<IO> where
IO: Send,
<IO as Io>::LoadBallot: Send,
<IO as Io>::LoadLog: Send,
<IO as Io>::SaveBallot: Send,
<IO as Io>::SaveLog: Send,
<IO as Io>::Timeout: Send,
IO: Send,
<IO as Io>::LoadBallot: Send,
<IO as Io>::LoadLog: Send,
<IO as Io>::SaveBallot: Send,
<IO as Io>::SaveLog: Send,
<IO as Io>::Timeout: Send,
impl<IO> Sync for ReplicatedLog<IO> where
IO: Sync,
<IO as Io>::LoadBallot: Sync,
<IO as Io>::LoadLog: Sync,
<IO as Io>::SaveBallot: Sync,
<IO as Io>::SaveLog: Sync,
<IO as Io>::Timeout: Sync,
IO: Sync,
<IO as Io>::LoadBallot: Sync,
<IO as Io>::LoadLog: Sync,
<IO as Io>::SaveBallot: Sync,
<IO as Io>::SaveLog: Sync,
<IO as Io>::Timeout: Sync,
impl<IO> Unpin for ReplicatedLog<IO> where
IO: Unpin,
<IO as Io>::LoadBallot: Unpin,
<IO as Io>::LoadLog: Unpin,
<IO as Io>::SaveBallot: Unpin,
<IO as Io>::SaveLog: Unpin,
<IO as Io>::Timeout: Unpin,
IO: Unpin,
<IO as Io>::LoadBallot: Unpin,
<IO as Io>::LoadLog: Unpin,
<IO as Io>::SaveBallot: Unpin,
<IO as Io>::SaveLog: Unpin,
<IO as Io>::Timeout: Unpin,
impl<IO> UnwindSafe for ReplicatedLog<IO> where
IO: UnwindSafe,
<IO as Io>::LoadBallot: UnwindSafe,
<IO as Io>::LoadLog: RefUnwindSafe + UnwindSafe,
<IO as Io>::SaveBallot: UnwindSafe,
<IO as Io>::SaveLog: UnwindSafe,
<IO as Io>::Timeout: UnwindSafe,
IO: UnwindSafe,
<IO as Io>::LoadBallot: UnwindSafe,
<IO as Io>::LoadLog: RefUnwindSafe + UnwindSafe,
<IO as Io>::SaveBallot: UnwindSafe,
<IO as Io>::SaveLog: UnwindSafe,
<IO as Io>::Timeout: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,