1
1
//! Public Raft interface and data types.
2
2
3
- use std:: collections:: HashSet ;
3
+ use std:: collections:: BTreeSet ;
4
4
use std:: sync:: Arc ;
5
5
use std:: time:: Duration ;
6
6
@@ -214,7 +214,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
214
214
/// free, and Raft guarantees that the first node to become the cluster leader will propagate
215
215
/// only its own config.
216
216
#[ tracing:: instrument( level = "debug" , skip( self ) ) ]
217
- pub async fn initialize ( & self , members : HashSet < NodeId > ) -> Result < ( ) , InitializeError > {
217
+ pub async fn initialize ( & self , members : BTreeSet < NodeId > ) -> Result < ( ) , InitializeError > {
218
218
let ( tx, rx) = oneshot:: channel ( ) ;
219
219
self . inner . tx_api . send ( RaftMsg :: Initialize { members, tx } ) . map_err ( |_| RaftError :: ShuttingDown ) ?;
220
220
rx. await . map_err ( |_| InitializeError :: RaftError ( RaftError :: ShuttingDown ) ) . and_then ( |res| res)
@@ -251,7 +251,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
251
251
/// If this Raft node is not the cluster leader, then the proposed configuration change will be
252
252
/// rejected.
253
253
#[ tracing:: instrument( level = "debug" , skip( self ) ) ]
254
- pub async fn change_membership ( & self , members : HashSet < NodeId > ) -> Result < ( ) , ChangeConfigError > {
254
+ pub async fn change_membership ( & self , members : BTreeSet < NodeId > ) -> Result < ( ) , ChangeConfigError > {
255
255
let ( tx, rx) = oneshot:: channel ( ) ;
256
256
self . inner
257
257
. tx_api
@@ -339,15 +339,15 @@ pub(crate) enum RaftMsg<D: AppData, R: AppDataResponse> {
339
339
tx : ClientReadResponseTx ,
340
340
} ,
341
341
Initialize {
342
- members : HashSet < NodeId > ,
342
+ members : BTreeSet < NodeId > ,
343
343
tx : oneshot:: Sender < Result < ( ) , InitializeError > > ,
344
344
} ,
345
345
AddNonVoter {
346
346
id : NodeId ,
347
347
tx : ChangeMembershipTx ,
348
348
} ,
349
349
ChangeMembership {
350
- members : HashSet < NodeId > ,
350
+ members : BTreeSet < NodeId > ,
351
351
tx : ChangeMembershipTx ,
352
352
} ,
353
353
}
@@ -484,16 +484,16 @@ pub struct EntrySnapshotPointer {
484
484
#[ derive( Clone , Default , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
485
485
pub struct MembershipConfig {
486
486
/// All members of the Raft cluster.
487
- pub members : HashSet < NodeId > ,
487
+ pub members : BTreeSet < NodeId > ,
488
488
/// All members of the Raft cluster after joint consensus is finalized.
489
489
///
490
490
/// The presence of a value here indicates that the config is in joint consensus.
491
- pub members_after_consensus : Option < HashSet < NodeId > > ,
491
+ pub members_after_consensus : Option < BTreeSet < NodeId > > ,
492
492
}
493
493
494
494
impl MembershipConfig {
495
495
/// Get an iterator over all nodes in the current config.
496
- pub fn all_nodes ( & self ) -> HashSet < u64 > {
496
+ pub fn all_nodes ( & self ) -> BTreeSet < u64 > {
497
497
let mut all = self . members . clone ( ) ;
498
498
if let Some ( members) = & self . members_after_consensus {
499
499
all. extend ( members) ;
@@ -520,7 +520,7 @@ impl MembershipConfig {
520
520
521
521
/// Create a new initial config containing only the given node ID.
522
522
pub fn new_initial ( id : NodeId ) -> Self {
523
- let mut members = HashSet :: new ( ) ;
523
+ let mut members = BTreeSet :: new ( ) ;
524
524
members. insert ( id) ;
525
525
Self {
526
526
members,
0 commit comments