Skip to main content

ReplicationNode

Struct ReplicationNode 

Source
pub struct ReplicationNode {
    pub node_id: u32,
    pub cluster_size: usize,
    pub quorum_write_timeout: Duration,
    /* private fields */
}
Expand description

클러스터 노드 (Quorum 기반 리더 선출)

Fields§

§node_id: u32

자기 자신의 노드 ID

§cluster_size: usize

클러스터 전체 노드 수 (Quorum 계산용)

§quorum_write_timeout: Duration

Quorum Write 타임아웃 (기본 5초, ReplicationConfig에서 설정 가능)

Implementations§

Source§

impl ReplicationNode

Source

pub fn new( node_id: u32, cluster_size: usize, initial_role: NodeRole, tx: Sender<ReplicationMessage>, ) -> Self

새로운 노드 생성

Source

pub fn new_from_config( node_id: u32, initial_role: NodeRole, tx: Sender<ReplicationMessage>, config: &ReplicationConfig, ) -> Self

[ReplicationConfig]에서 timeout을 읽어 노드를 생성하는 편의 팩토리

DbConfig::replication을 통해 quorum_write_timeout을 설정하려면 이 메서드를 사용하세요.

Source

pub async fn role(&self) -> NodeRole

현재 역할 조회

Source

pub fn term(&self) -> u64

현재 임기 번호 조회

Source

pub async fn replicate(&self, data: Vec<u8>) -> Result<u64, String>

(Master 용) WAL 레코드 발행 — Quorum Write

cluster_size == 1 (또는 quorum == 1) 이면 기존과 동일하게 즉시 반환. 그 외에는 quorum 수만큼의 Slave ACK를 받은 뒤 반환한다. quorum_write_timeout 내에 ACK를 받지 못하면 Err를 반환한다.

Source

pub async fn send_heartbeat(&self)

(Master 용) Heartbeat 송신

Source

pub async fn run_receiver_loop<F>( &self, rx: Receiver<ReplicationMessage>, apply_fn: F, ) -> Result<(), NodeError>
where F: FnMut(u64, u64, &[u8]) -> Result<(), String>,

클러스터 메시지 수신 및 적용 루프

Source

pub async fn start_election(&self) -> bool

(Slave/Candidate용) Heartbeat 타임아웃 시 선거 시작

  1. 자신을 Candidate로 승격
  2. term 증가
  3. 자신에게 투표 (자가 투표)
  4. VoteRequest 브로드캐스트

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> Upcast<T> for U
where T: UpcastFrom<U>,

Source§

fn upcast(self) -> T

Source§

impl<T, B> UpcastFrom<Counter<T, B>> for T

Source§

fn upcast_from(value: Counter<T, B>) -> T

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more