@@ -80,26 +80,25 @@ where
80
80
self . effective . membership . is_voter ( id)
81
81
}
82
82
83
- /// Build a new membership config by applying changes to the current config .
83
+ /// Builds a new membership configuration by applying changes to the current configuration .
84
84
///
85
- /// The removed voter is left in membership config as learner if `removed_to_learner` is true.
86
- pub ( crate ) fn next_membership (
85
+ /// * `changes`: The changes to apply to the current membership configuration.
86
+ /// * `convert_removed_to_learner`: Indicates whether the removed voter should be left in the
87
+ /// membership configuration as a learner.
88
+ ///
89
+ /// A Result containing the new membership configuration if the operation succeeds, or a
90
+ /// `ChangeMembershipError` if an error occurs.
91
+ ///
92
+ /// This function ensures that the cluster will have at least one voter in the new membership
93
+ /// configuration.
94
+ pub ( crate ) fn create_updated_membership (
87
95
& self ,
88
96
changes : ChangeMembers < NID > ,
89
- removed_to_learner : bool ,
97
+ convert_removed_to_learner : bool ,
90
98
) -> Result < Membership < NID , N > , ChangeMembershipError < NID > > {
91
99
let effective = self . effective ( ) ;
92
- let committed = self . committed ( ) ;
93
100
94
- if committed. log_id == effective. log_id {
95
- // Ok: last membership(effective) is committed
96
- } else {
97
- return Err ( InProgress {
98
- committed : committed. log_id ,
99
- membership_log_id : effective. log_id ,
100
- }
101
- . into ( ) ) ;
102
- }
101
+ self . ensure_last_membership_committed ( ) ?;
103
102
104
103
let last = effective. membership . get_joint_config ( ) . last ( ) . unwrap ( ) ;
105
104
let new_voter_ids = changes. apply_to ( last) ;
@@ -109,12 +108,31 @@ where
109
108
return Err ( EmptyMembership { } . into ( ) ) ;
110
109
}
111
110
112
- let new_membership = effective. membership . next_safe ( new_voter_ids, removed_to_learner ) ?;
111
+ let new_membership = effective. membership . next_safe ( new_voter_ids, convert_removed_to_learner ) ?;
113
112
114
113
tracing:: debug!( ?new_membership, "new membership config" ) ;
115
114
Ok ( new_membership)
116
115
}
117
116
117
+ /// Ensures that the latest membership configuration has been committed.
118
+ ///
119
+ /// Returns Ok if the last membership configuration is committed, or an InProgress error
120
+ /// otherwise.
121
+ pub ( crate ) fn ensure_last_membership_committed ( & self ) -> Result < ( ) , InProgress < NID > > {
122
+ let effective = self . effective ( ) ;
123
+ let committed = self . committed ( ) ;
124
+
125
+ if self . committed ( ) . log_id == self . effective ( ) . log_id {
126
+ // Ok: last membership(effective) is committed
127
+ Ok ( ( ) )
128
+ } else {
129
+ Err ( InProgress {
130
+ committed : committed. log_id ,
131
+ membership_log_id : effective. log_id ,
132
+ } )
133
+ }
134
+ }
135
+
118
136
/// Update membership state if the specified committed_log_id is greater than `self.effective`
119
137
pub ( crate ) fn commit ( & mut self , committed_log_id : & Option < LogId < NID > > ) {
120
138
if committed_log_id >= & self . effective ( ) . log_id {
0 commit comments