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: DurationQuorum Write 타임아웃 (기본 5초, ReplicationConfig에서 설정 가능)
Implementations§
Source§impl ReplicationNode
impl ReplicationNode
Sourcepub fn new(
node_id: u32,
cluster_size: usize,
initial_role: NodeRole,
tx: Sender<ReplicationMessage>,
) -> Self
pub fn new( node_id: u32, cluster_size: usize, initial_role: NodeRole, tx: Sender<ReplicationMessage>, ) -> Self
새로운 노드 생성
Sourcepub fn new_from_config(
node_id: u32,
initial_role: NodeRole,
tx: Sender<ReplicationMessage>,
config: &ReplicationConfig,
) -> Self
pub fn new_from_config( node_id: u32, initial_role: NodeRole, tx: Sender<ReplicationMessage>, config: &ReplicationConfig, ) -> Self
[ReplicationConfig]에서 timeout을 읽어 노드를 생성하는 편의 팩토리
DbConfig::replication을 통해 quorum_write_timeout을 설정하려면 이 메서드를 사용하세요.
Sourcepub async fn replicate(&self, data: Vec<u8>) -> Result<u64, String>
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를 반환한다.
Sourcepub async fn send_heartbeat(&self)
pub async fn send_heartbeat(&self)
(Master 용) Heartbeat 송신
Sourcepub async fn run_receiver_loop<F>(
&self,
rx: Receiver<ReplicationMessage>,
apply_fn: F,
) -> Result<(), NodeError>
pub async fn run_receiver_loop<F>( &self, rx: Receiver<ReplicationMessage>, apply_fn: F, ) -> Result<(), NodeError>
클러스터 메시지 수신 및 적용 루프
Sourcepub async fn start_election(&self) -> bool
pub async fn start_election(&self) -> bool
(Slave/Candidate용) Heartbeat 타임아웃 시 선거 시작
- 자신을 Candidate로 승격
- term 증가
- 자신에게 투표 (자가 투표)
- VoteRequest 브로드캐스트
Auto Trait Implementations§
impl Freeze for ReplicationNode
impl !RefUnwindSafe for ReplicationNode
impl Send for ReplicationNode
impl Sync for ReplicationNode
impl Unpin for ReplicationNode
impl UnsafeUnpin for ReplicationNode
impl !UnwindSafe for ReplicationNode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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