@@ -190,6 +190,65 @@ class OplogApplier {
190
190
StatusWith<OpTime> multiApply (OperationContext* opCtx, Operations ops);
191
191
192
192
const Options& getOptions () const ;
193
+ /* *
194
+ * Step-up
195
+ * =======
196
+ * On stepup, repl coord enters catch-up mode. It's the same as the secondary mode from
197
+ * the perspective of producer and applier, so there's nothing to do with them.
198
+ * When a node enters drain mode, producer state = Stopped, applier state = Draining.
199
+ *
200
+ * If the applier state is Draining, it will signal repl coord when there's nothing to apply.
201
+ * The applier goes into Stopped state at the same time.
202
+ *
203
+ * The states go like the following:
204
+ * - secondary and during catchup mode
205
+ * (producer: Running, applier: Running)
206
+ * |
207
+ * | finish catch-up, enter drain mode
208
+ * V
209
+ * - drain mode
210
+ * (producer: Stopped, applier: Draining)
211
+ * |
212
+ * | applier signals drain is complete
213
+ * V
214
+ * - primary is in master mode
215
+ * (producer: Stopped, applier: Stopped)
216
+ *
217
+ *
218
+ * Step-down
219
+ * =========
220
+ * The state transitions become:
221
+ * - primary is in master mode
222
+ * (producer: Stopped, applier: Stopped)
223
+ * |
224
+ * | step down
225
+ * V
226
+ * - secondary mode, starting bgsync
227
+ * (producer: Starting, applier: Running)
228
+ * |
229
+ * | bgsync runs start()
230
+ * V
231
+ * - secondary mode, normal
232
+ * (producer: Running, applier: Running)
233
+ *
234
+ * When a node steps down during draining mode, it's OK to change from (producer: Stopped,
235
+ * applier: Draining) to (producer: Starting, applier: Running).
236
+ *
237
+ * When a node steps down during catchup mode, the states remain the same (producer: Running,
238
+ * applier: Running).
239
+ */
240
+ enum class ApplierState { Running, Draining, Stopped };
241
+
242
+ /* *
243
+ * In normal cases: Running -> Draining -> Stopped -> Running.
244
+ * Draining -> Running is also possible if a node steps down during drain mode.
245
+ *
246
+ * Only the applier can make the transition from Draining to Stopped by calling
247
+ * signalDrainComplete().
248
+ */
249
+ virtual ApplierState getApplierState () const ;
250
+
251
+ virtual void setApplierState (ApplierState st);
193
252
194
253
private:
195
254
/* *
@@ -228,6 +287,8 @@ class OplogApplier {
228
287
229
288
// Configures this OplogApplier.
230
289
const Options _options;
290
+
291
+ ApplierState _applierState = ApplierState::Running;
231
292
};
232
293
233
294
/* *
0 commit comments