/
replication_coordinator_impl_test.cpp
8311 lines (7146 loc) · 399 KB
/
replication_coordinator_impl_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (C) 2018-present MongoDB, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*
* As a special exception, the copyright holders give permission to link the
* code of portions of this program with the OpenSSL library under certain
* conditions as described in each individual source file and distribute
* linked combinations including the program with the OpenSSL library. You
* must comply with the Server Side Public License in all respects for
* all of the code used other than as permitted herein. If you modify file(s)
* with this exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do so,
* delete this exception statement from your version. If you delete this
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
#include "mongo/platform/basic.h"
#include <boost/optional/optional_io.hpp>
#include <functional>
#include <iostream>
#include <memory>
#include <set>
#include <vector>
#include "mongo/bson/util/bson_extract.h"
#include "mongo/db/catalog/commit_quorum_options.h"
#include "mongo/db/concurrency/lock_state.h"
#include "mongo/db/concurrency/replication_state_transition_lock_guard.h"
#include "mongo/db/repl/bson_extract_optime.h"
#include "mongo/db/repl/data_replicator_external_state_impl.h"
#include "mongo/db/repl/is_master_response.h"
#include "mongo/db/repl/optime.h"
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/repl/repl_set_config.h"
#include "mongo/db/repl/repl_set_heartbeat_args_v1.h"
#include "mongo/db/repl/repl_set_request_votes_args.h"
#include "mongo/db/repl/repl_settings.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/repl/replication_coordinator_external_state_mock.h"
#include "mongo/db/repl/replication_coordinator_impl.h"
#include "mongo/db/repl/replication_coordinator_test_fixture.h"
#include "mongo/db/repl/replication_metrics.h"
#include "mongo/db/repl/storage_interface_mock.h"
#include "mongo/db/repl/topology_coordinator.h"
#include "mongo/db/repl/update_position_args.h"
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
#include "mongo/db/write_concern_options.h"
#include "mongo/executor/network_interface_mock.h"
#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/oplog_query_metadata.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/stdx/future.h"
#include "mongo/stdx/thread.h"
#include "mongo/unittest/barrier.h"
#include "mongo/unittest/death_test.h"
#include "mongo/unittest/ensure_fcv.h"
#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/scopeguard.h"
#include "mongo/util/time_support.h"
#include "mongo/util/timer.h"
namespace mongo {
namespace repl {
namespace {
using executor::NetworkInterfaceMock;
using executor::RemoteCommandRequest;
using executor::RemoteCommandResponse;
using rpc::OplogQueryMetadata;
using rpc::ReplSetMetadata;
using unittest::assertGet;
using unittest::EnsureFCV;
typedef ReplicationCoordinator::ReplSetReconfigArgs ReplSetReconfigArgs;
// Helper class to wrap Timestamp as an OpTime with term 1.
struct OpTimeWithTermOne {
OpTimeWithTermOne(unsigned int sec, unsigned int i) : timestamp(sec, i) {}
operator OpTime() const {
return OpTime(timestamp, 1);
}
operator boost::optional<OpTime>() const {
return OpTime(timestamp, 1);
}
OpTime asOpTime() const {
return this->operator mongo::repl::OpTime();
}
Timestamp timestamp;
};
OpTimeAndWallTime makeOpTimeAndWallTime(OpTime opTime, Date_t wallTime = Date_t()) {
return {opTime, wallTime};
}
/**
* Helper that kills an operation, taking the necessary locks.
*/
void killOperation(OperationContext* opCtx) {
stdx::lock_guard<Client> lkClient(*opCtx->getClient());
opCtx->getServiceContext()->killOperation(lkClient, opCtx);
}
TEST_F(ReplCoordTest, IsMasterIsFalseDuringStepdown) {
BSONObj configObj = BSON("_id"
<< "mySet"
<< "version" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
<< "node1:12345")
<< BSON("_id" << 2 << "host"
<< "node2:12345"))
<< "protocolVersion" << 1);
assertStartSuccess(configObj, HostAndPort("node1", 12345));
ReplSetConfig config = assertMakeRSConfig(configObj);
auto replCoord = getReplCoord();
ASSERT_OK(replCoord->setFollowerMode(MemberState::RS_SECONDARY));
replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
simulateSuccessfulV1Election();
ASSERT(replCoord->getMemberState().primary());
// Primary begins stepping down due to new term, but cannot finish.
globalFailPointRegistry().find("blockHeartbeatStepdown")->setMode(FailPoint::alwaysOn);
TopologyCoordinator::UpdateTermResult updateTermResult;
replCoord->updateTerm_forTest(replCoord->getTerm() + 1, &updateTermResult);
ASSERT(TopologyCoordinator::UpdateTermResult::kTriggerStepDown == updateTermResult);
// Test that "ismaster" is immediately false, although "secondary" is not yet true.
auto opCtx = makeOperationContext();
const auto response =
getReplCoord()->awaitIsMasterResponse(opCtx.get(), {}, boost::none, boost::none);
ASSERT_TRUE(response->isConfigSet());
BSONObj responseObj = response->toBSON();
ASSERT_FALSE(responseObj["ismaster"].Bool());
ASSERT_FALSE(responseObj["secondary"].Bool());
ASSERT_FALSE(responseObj.hasField("isreplicaset"));
globalFailPointRegistry().find("blockHeartbeatStepdown")->setMode(FailPoint::off);
}
TEST_F(ReplCoordTest, NodeEntersStartup2StateWhenStartingUpWithValidLocalConfig) {
assertStartSuccess(BSON("_id"
<< "mySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
<< "node1:12345"))),
HostAndPort("node1", 12345));
ASSERT_TRUE(getExternalState()->threadsStarted());
ASSERT_EQUALS(MemberState::RS_STARTUP2, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest, NodeEntersArbiterStateWhenStartingUpWithValidLocalConfigWhereItIsAnArbiter) {
assertStartSuccess(BSON("_id"
<< "mySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
<< "node1:12345"
<< "arbiterOnly" << true)
<< BSON("_id" << 2 << "host"
<< "node2:12345"))),
HostAndPort("node1", 12345));
ASSERT_FALSE(getExternalState()->threadsStarted());
ASSERT_EQUALS(MemberState::RS_ARBITER, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest, NodeEntersRemovedStateWhenStartingUpWithALocalConfigWhichLacksItAsAMember) {
startCapturingLogMessages();
assertStartSuccess(BSON("_id"
<< "mySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
<< "node1:12345")
<< BSON("_id" << 2 << "host"
<< "node2:54321"))),
HostAndPort("node3", 12345));
stopCapturingLogMessages();
ASSERT_EQUALS(1,
countTextFormatLogLinesContaining("Locally stored replica set configuration does "
"not have a valid entry for the current node"));
ASSERT_EQUALS(MemberState::RS_REMOVED, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest,
NodeEntersRemovedStateWhenStartingUpWithALocalConfigContainingTheWrongSetName) {
init("mySet");
startCapturingLogMessages();
assertStartSuccess(BSON("_id"
<< "notMySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
<< "node1:12345"))),
HostAndPort("node1", 12345));
stopCapturingLogMessages();
ASSERT_EQUALS(1,
countTextFormatLogLinesContaining("Local replica set configuration document set "
"name differs from command line set name"));
ASSERT_EQUALS(MemberState::RS_REMOVED, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest, NodeEntersStartupStateWhenStartingUpWithNoLocalConfig) {
startCapturingLogMessages();
start();
stopCapturingLogMessages();
ASSERT_EQUALS(3, countTextFormatLogLinesContaining("Did not find local "));
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest, NodeReturnsInvalidReplicaSetConfigWhenInitiatedWithAnEmptyConfig) {
init("mySet");
start(HostAndPort("node1", 12345));
auto opCtx = makeOperationContext();
BSONObjBuilder result;
ASSERT_EQUALS(ErrorCodes::InvalidReplicaSetConfig,
getReplCoord()->processReplSetInitiate(opCtx.get(), BSONObj(), &result));
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest,
NodeReturnsAlreadyInitiatedWhenReceivingAnInitiateCommandAfterHavingAValidConfig) {
init("mySet");
start(HostAndPort("node1", 12345));
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
auto opCtx = makeOperationContext();
// Starting uninitialized, show that we can perform the initiate behavior.
BSONObjBuilder result1;
ASSERT_OK(
getReplCoord()->processReplSetInitiate(opCtx.get(),
BSON("_id"
<< "mySet"
<< "version" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node1:12345"))),
&result1));
ASSERT_EQUALS(ReplicationCoordinator::modeReplSet, getReplCoord()->getReplicationMode());
ASSERT_TRUE(getExternalState()->threadsStarted());
// Show that initiate fails after it has already succeeded.
BSONObjBuilder result2;
ASSERT_EQUALS(
ErrorCodes::AlreadyInitialized,
getReplCoord()->processReplSetInitiate(opCtx.get(),
BSON("_id"
<< "mySet"
<< "version" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node1:12345"))),
&result2));
// Still in repl set mode, even after failed reinitiate.
ASSERT_EQUALS(ReplicationCoordinator::modeReplSet, getReplCoord()->getReplicationMode());
}
TEST_F(ReplCoordTest,
NodeReturnsInvalidReplicaSetConfigWhenInitiatingViaANodeThatCannotBecomePrimary) {
init("mySet");
start(HostAndPort("node1", 12345));
auto opCtx = makeOperationContext();
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
// Starting uninitialized, show that we can perform the initiate behavior.
BSONObjBuilder result1;
auto status =
getReplCoord()->processReplSetInitiate(opCtx.get(),
BSON("_id"
<< "mySet"
<< "version" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node1:12345"
<< "arbiterOnly"
<< true)
<< BSON("_id" << 1 << "host"
<< "node2:12345"))),
&result1);
ASSERT_EQUALS(ErrorCodes::InvalidReplicaSetConfig, status);
ASSERT_STRING_CONTAINS(status.reason(), "is not electable under the new configuration with");
ASSERT_FALSE(getExternalState()->threadsStarted());
}
TEST_F(ReplCoordTest,
InitiateShouldSucceedWithAValidConfigEvenIfItHasFailedWithAnInvalidConfigPreviously) {
init("mySet");
start(HostAndPort("node1", 12345));
auto opCtx = makeOperationContext();
BSONObjBuilder result;
ASSERT_EQUALS(ErrorCodes::InvalidReplicaSetConfig,
getReplCoord()->processReplSetInitiate(opCtx.get(), BSONObj(), &result));
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
// Having failed to initiate once, show that we can now initiate.
BSONObjBuilder result1;
ASSERT_OK(
getReplCoord()->processReplSetInitiate(opCtx.get(),
BSON("_id"
<< "mySet"
<< "version" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node1:12345"))),
&result1));
ASSERT_EQUALS(ReplicationCoordinator::modeReplSet, getReplCoord()->getReplicationMode());
}
TEST_F(ReplCoordTest,
NodeReturnsInvalidReplicaSetConfigWhenInitiatingWithAConfigTheNodeIsAbsentFrom) {
BSONObjBuilder result;
init("mySet");
start(HostAndPort("node1", 12345));
auto opCtx = makeOperationContext();
ASSERT_EQUALS(
ErrorCodes::InvalidReplicaSetConfig,
getReplCoord()->processReplSetInitiate(opCtx.get(),
BSON("_id"
<< "mySet"
<< "version" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node4"))),
&result));
}
void doReplSetInitiate(ReplicationCoordinatorImpl* replCoord, Status* status) {
BSONObjBuilder garbage;
auto client = getGlobalServiceContext()->makeClient("rsi");
auto opCtx = client->makeOperationContext();
*status =
replCoord->processReplSetInitiate(opCtx.get(),
BSON("_id"
<< "mySet"
<< "version" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node1:12345")
<< BSON("_id" << 1 << "host"
<< "node2:54321"))),
&garbage);
}
TEST_F(ReplCoordTest, NodeReturnsNodeNotFoundWhenQuorumCheckFailsWhileInitiating) {
init("mySet");
start(HostAndPort("node1", 12345));
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
ReplSetHeartbeatArgsV1 hbArgs;
hbArgs.setSetName("mySet");
hbArgs.setConfigVersion(1);
hbArgs.setConfigTerm(0);
hbArgs.setCheckEmpty();
hbArgs.setSenderHost(HostAndPort("node1", 12345));
hbArgs.setSenderId(0);
hbArgs.setTerm(0);
hbArgs.setHeartbeatVersion(1);
Status status(ErrorCodes::InternalError, "Not set");
stdx::thread prsiThread([&] { doReplSetInitiate(getReplCoord(), &status); });
const Date_t startDate = getNet()->now();
getNet()->enterNetwork();
const NetworkInterfaceMock::NetworkOperationIterator noi = getNet()->getNextReadyRequest();
ASSERT_EQUALS(HostAndPort("node2", 54321), noi->getRequest().target);
ASSERT_EQUALS("admin", noi->getRequest().dbname);
ASSERT_BSONOBJ_EQ(hbArgs.toBSON(), noi->getRequest().cmdObj);
getNet()->scheduleResponse(noi,
startDate + Milliseconds(10),
RemoteCommandResponse(ErrorCodes::NoSuchKey, "No response"));
getNet()->runUntil(startDate + Milliseconds(10));
getNet()->exitNetwork();
ASSERT_EQUALS(startDate + Milliseconds(10), getNet()->now());
prsiThread.join();
ASSERT_EQUALS(ErrorCodes::NodeNotFound, status);
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest, InitiateSucceedsWhenQuorumCheckPasses) {
init("mySet");
start(HostAndPort("node1", 12345));
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
ReplSetHeartbeatArgsV1 hbArgs;
hbArgs.setSetName("mySet");
hbArgs.setConfigVersion(1);
hbArgs.setConfigTerm(0);
hbArgs.setCheckEmpty();
hbArgs.setSenderHost(HostAndPort("node1", 12345));
hbArgs.setSenderId(0);
hbArgs.setTerm(0);
hbArgs.setHeartbeatVersion(1);
auto appliedTS = Timestamp(3, 3);
replCoordSetMyLastAppliedOpTime(OpTime(appliedTS, 1), Date_t() + Seconds(100));
Status status(ErrorCodes::InternalError, "Not set");
stdx::thread prsiThread([&] { doReplSetInitiate(getReplCoord(), &status); });
const Date_t startDate = getNet()->now();
getNet()->enterNetwork();
const NetworkInterfaceMock::NetworkOperationIterator noi = getNet()->getNextReadyRequest();
ASSERT_EQUALS(HostAndPort("node2", 54321), noi->getRequest().target);
ASSERT_EQUALS("admin", noi->getRequest().dbname);
ASSERT_BSONOBJ_EQ(hbArgs.toBSON(), noi->getRequest().cmdObj);
ReplSetHeartbeatResponse hbResp;
hbResp.setConfigVersion(0);
hbResp.setAppliedOpTimeAndWallTime({OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)});
hbResp.setDurableOpTimeAndWallTime({OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100)});
getNet()->scheduleResponse(
noi, startDate + Milliseconds(10), RemoteCommandResponse(hbResp.toBSON(), Milliseconds(8)));
getNet()->runUntil(startDate + Milliseconds(10));
getNet()->exitNetwork();
ASSERT_EQUALS(startDate + Milliseconds(10), getNet()->now());
prsiThread.join();
ASSERT_OK(status);
ASSERT_EQUALS(ReplicationCoordinator::modeReplSet, getReplCoord()->getReplicationMode());
ASSERT_EQUALS(getStorageInterface()->getInitialDataTimestamp(), appliedTS);
}
TEST_F(ReplCoordTest,
NodeReturnsInvalidReplicaSetConfigWhenInitiatingWithAConfigWithAMismatchedSetName) {
init("mySet");
start(HostAndPort("node1", 12345));
auto opCtx = makeOperationContext();
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
BSONObjBuilder result1;
ASSERT_EQUALS(
ErrorCodes::InvalidReplicaSetConfig,
getReplCoord()->processReplSetInitiate(opCtx.get(),
BSON("_id"
<< "wrongSet"
<< "version" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node1:12345"))),
&result1));
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest, NodeReturnsInvalidReplicaSetConfigWhenInitiatingWithAnEmptyConfig) {
init("mySet");
start(HostAndPort("node1", 12345));
auto opCtx = makeOperationContext();
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
BSONObjBuilder result1;
auto status = getReplCoord()->processReplSetInitiate(opCtx.get(), BSONObj(), &result1);
ASSERT_EQUALS(ErrorCodes::InvalidReplicaSetConfig, status);
ASSERT_STRING_CONTAINS(status.reason(), "'ReplSetConfig._id' is missing but a required field");
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest, NodeReturnsInvalidReplicaSetConfigWhenInitiatingWithoutAn_idField) {
init("mySet");
start(HostAndPort("node1", 12345));
auto opCtx = makeOperationContext();
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
BSONObjBuilder result1;
auto status = getReplCoord()->processReplSetInitiate(
opCtx.get(),
BSON("version" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node1:12345"))),
&result1);
ASSERT_EQUALS(ErrorCodes::InvalidReplicaSetConfig, status);
ASSERT_STRING_CONTAINS(status.reason(), "'ReplSetConfig._id' is missing but a required field");
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest,
NodeReturnsInvalidReplicaSetConfigWhenInitiatingWithAConfigVersionNotEqualToOne) {
init("mySet");
start(HostAndPort("node1", 12345));
auto opCtx = makeOperationContext();
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
BSONObjBuilder result1;
auto status =
getReplCoord()->processReplSetInitiate(opCtx.get(),
BSON("_id"
<< "mySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node1:12345"))),
&result1);
ASSERT_EQUALS(ErrorCodes::InvalidReplicaSetConfig, status);
ASSERT_STRING_CONTAINS(status.reason(), "have version 1, but found 2");
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest, InitiateFailsWithoutReplSetFlag) {
init("");
start(HostAndPort("node1", 12345));
auto opCtx = makeOperationContext();
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
BSONObjBuilder result1;
ASSERT_EQUALS(
ErrorCodes::NoReplicationEnabled,
getReplCoord()->processReplSetInitiate(opCtx.get(),
BSON("_id"
<< "mySet"
<< "version" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node1:12345"))),
&result1));
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest, NodeReturnsOutOfDiskSpaceWhenInitiateCannotWriteConfigToDisk) {
init("mySet");
start(HostAndPort("node1", 12345));
auto opCtx = makeOperationContext();
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
BSONObjBuilder result1;
getExternalState()->setStoreLocalConfigDocumentStatus(
Status(ErrorCodes::OutOfDiskSpace, "The test set this"));
ASSERT_EQUALS(
ErrorCodes::OutOfDiskSpace,
getReplCoord()->processReplSetInitiate(opCtx.get(),
BSON("_id"
<< "mySet"
<< "version" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node1:12345"))),
&result1));
ASSERT_EQUALS(MemberState::RS_STARTUP, getReplCoord()->getMemberState().s);
}
TEST_F(ReplCoordTest,
NodeReturnsNoReplicationEnabledWhenCheckReplEnabledForCommandWhileNotRunningWithRepl) {
// pass in settings to avoid having a replSet
ReplSettings settings;
init(settings);
start();
// check status NoReplicationEnabled and empty result
BSONObjBuilder result;
Status status = getReplCoord()->checkReplEnabledForCommand(&result);
ASSERT_EQUALS(status, ErrorCodes::NoReplicationEnabled);
ASSERT_TRUE(result.obj().isEmpty());
}
TEST_F(
ReplCoordTest,
NodeReturnsNoReplicationEnabledAndInfoConfigsvrWhenCheckReplEnabledForCommandWhileConfigsvr) {
ReplSettings settings;
serverGlobalParams.clusterRole = ClusterRole::ConfigServer;
init(settings);
start();
// check status NoReplicationEnabled and result mentions configsrv
BSONObjBuilder result;
Status status = getReplCoord()->checkReplEnabledForCommand(&result);
ASSERT_EQUALS(status, ErrorCodes::NoReplicationEnabled);
ASSERT_EQUALS(result.obj()["info"].String(), "configsvr");
serverGlobalParams.clusterRole = ClusterRole::None;
}
TEST_F(
ReplCoordTest,
NodeReturnsNotYetInitializedAndInfoNeedToInitiatedWhenCheckReplEnabledForCommandWithoutConfig) {
start();
// check status NotYetInitialized and result mentions rs.initiate
BSONObjBuilder result;
Status status = getReplCoord()->checkReplEnabledForCommand(&result);
ASSERT_EQUALS(status, ErrorCodes::NotYetInitialized);
ASSERT_TRUE(result.obj()["info"].String().find("rs.initiate") != std::string::npos);
}
TEST_F(ReplCoordTest, NodeReturnsOkWhenCheckReplEnabledForCommandAfterReceivingAConfig) {
assertStartSuccess(BSON("_id"
<< "mySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("host"
<< "node1:12345"
<< "_id" << 0))),
HostAndPort("node1", 12345));
// check status OK and result is empty
BSONObjBuilder result;
Status status = getReplCoord()->checkReplEnabledForCommand(&result);
ASSERT_EQUALS(status, Status::OK());
ASSERT_TRUE(result.obj().isEmpty());
}
TEST_F(ReplCoordTest, NodeReturnsImmediatelyWhenAwaitReplicationIsRanAgainstAStandaloneNode) {
init("");
auto opCtx = makeOperationContext();
OpTimeWithTermOne time(100, 1);
WriteConcernOptions writeConcern;
writeConcern.wTimeout = WriteConcernOptions::kNoWaiting;
writeConcern.wNumNodes = 2;
// Because we didn't set ReplSettings.replSet, it will think we're a standalone so
// awaitReplication will always work.
ReplicationCoordinator::StatusAndDuration statusAndDur =
getReplCoord()->awaitReplication(opCtx.get(), time, writeConcern);
ASSERT_OK(statusAndDur.status);
}
TEST_F(ReplCoordTest, NodeReturnsNotMasterWhenRunningAwaitReplicationAgainstASecondaryNode) {
assertStartSuccess(BSON("_id"
<< "mySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("host"
<< "node1:12345"
<< "_id" << 0)
<< BSON("host"
<< "node2:12345"
<< "_id" << 1)
<< BSON("host"
<< "node3:12345"
<< "_id" << 2))),
HostAndPort("node1", 12345));
auto opCtx = makeOperationContext();
OpTimeWithTermOne time(100, 1);
WriteConcernOptions writeConcern;
writeConcern.wTimeout = WriteConcernOptions::kNoWaiting;
writeConcern.wNumNodes = 0; // Waiting for 0 nodes always works
writeConcern.wMode = "";
// Node should fail to awaitReplication when not primary.
ReplicationCoordinator::StatusAndDuration statusAndDur =
getReplCoord()->awaitReplication(opCtx.get(), time, writeConcern);
ASSERT_EQUALS(ErrorCodes::PrimarySteppedDown, statusAndDur.status);
}
TEST_F(ReplCoordTest, NodeReturnsOkWhenRunningAwaitReplicationAgainstPrimaryWithWTermOne) {
assertStartSuccess(BSON("_id"
<< "mySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("host"
<< "node1:12345"
<< "_id" << 0)
<< BSON("host"
<< "node2:12345"
<< "_id" << 1)
<< BSON("host"
<< "node3:12345"
<< "_id" << 2))),
HostAndPort("node1", 12345));
OpTimeWithTermOne time(100, 1);
WriteConcernOptions writeConcern;
writeConcern.wTimeout = WriteConcernOptions::kNoWaiting;
writeConcern.wNumNodes = 0; // Waiting for 0 nodes always works
writeConcern.wMode = "";
// Become primary.
ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
simulateSuccessfulV1Election();
ASSERT(getReplCoord()->getMemberState().primary());
auto opCtx = makeOperationContext();
ReplicationCoordinator::StatusAndDuration statusAndDur =
getReplCoord()->awaitReplication(opCtx.get(), time, writeConcern);
ASSERT_OK(statusAndDur.status);
}
TEST_F(ReplCoordTest,
NodeReturnsWriteConcernFailedUntilASufficientNumberOfNodesHaveTheWriteDurable) {
assertStartSuccess(BSON("_id"
<< "mySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("host"
<< "node1:12345"
<< "_id" << 0)
<< BSON("host"
<< "node2:12345"
<< "_id" << 1)
<< BSON("host"
<< "node3:12345"
<< "_id" << 2)
<< BSON("host"
<< "node4:12345"
<< "_id" << 3))),
HostAndPort("node1", 12345));
ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
simulateSuccessfulV1Election();
OpTimeWithTermOne time1(100, 2);
OpTimeWithTermOne time2(100, 3);
WriteConcernOptions writeConcern;
writeConcern.wTimeout = WriteConcernOptions::kNoWaiting;
writeConcern.wNumNodes = 1;
writeConcern.syncMode = WriteConcernOptions::SyncMode::JOURNAL;
auto opCtx = makeOperationContext();
// 1 node waiting for time 1
ReplicationCoordinator::StatusAndDuration statusAndDur =
getReplCoord()->awaitReplication(opCtx.get(), time1, writeConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
replCoordSetMyLastAppliedOpTime(time1, Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(time1, Date_t() + Seconds(100));
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, writeConcern);
ASSERT_OK(statusAndDur.status);
// 2 nodes waiting for time1
writeConcern.wNumNodes = 2;
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, writeConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
// Applied is not durable and will not satisfy WriteConcern with SyncMode JOURNAL.
ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(2, 1, time1));
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, writeConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
ASSERT_OK(getReplCoord()->setLastDurableOptime_forTest(2, 1, time1));
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, writeConcern);
ASSERT_OK(statusAndDur.status);
// 2 nodes waiting for time2
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
replCoordSetMyLastAppliedOpTime(time2, Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(time2, Date_t() + Seconds(100));
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(2, 2, time2));
ASSERT_OK(getReplCoord()->setLastDurableOptime_forTest(2, 2, time2));
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern);
ASSERT_OK(statusAndDur.status);
// 3 nodes waiting for time2
writeConcern.wNumNodes = 3;
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(2, 3, time2));
ASSERT_OK(getReplCoord()->setLastDurableOptime_forTest(2, 3, time2));
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern);
ASSERT_OK(statusAndDur.status);
}
TEST_F(ReplCoordTest, NodeReturnsWriteConcernFailedUntilASufficientNumberOfNodesHaveTheWrite) {
assertStartSuccess(BSON("_id"
<< "mySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("host"
<< "node1:12345"
<< "_id" << 0)
<< BSON("host"
<< "node2:12345"
<< "_id" << 1)
<< BSON("host"
<< "node3:12345"
<< "_id" << 2)
<< BSON("host"
<< "node4:12345"
<< "_id" << 3))),
HostAndPort("node1", 12345));
ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
simulateSuccessfulV1Election();
OpTimeWithTermOne time1(100, 2);
OpTimeWithTermOne time2(100, 3);
WriteConcernOptions writeConcern;
writeConcern.wTimeout = WriteConcernOptions::kNoWaiting;
writeConcern.wNumNodes = 1;
auto opCtx = makeOperationContext();
// 1 node waiting for time 1
ReplicationCoordinator::StatusAndDuration statusAndDur =
getReplCoord()->awaitReplication(opCtx.get(), time1, writeConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
replCoordSetMyLastAppliedOpTime(time1, Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(time1, Date_t() + Seconds(100));
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, writeConcern);
ASSERT_OK(statusAndDur.status);
// 2 nodes waiting for time1
writeConcern.wNumNodes = 2;
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, writeConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(2, 1, time1));
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, writeConcern);
ASSERT_OK(statusAndDur.status);
// 2 nodes waiting for time2
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
replCoordSetMyLastAppliedOpTime(time2, Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(time2, Date_t() + Seconds(100));
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(2, 2, time2));
ASSERT_OK(getReplCoord()->setLastDurableOptime_forTest(2, 2, time2));
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern);
ASSERT_OK(statusAndDur.status);
// 3 nodes waiting for time2
writeConcern.wNumNodes = 3;
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(2, 3, time2));
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, writeConcern);
ASSERT_OK(statusAndDur.status);
}
TEST_F(ReplCoordTest,
NodeReturnsUnknownReplWriteConcernWhenAwaitReplicationReceivesAnInvalidWriteConcernMode) {
assertStartSuccess(BSON("_id"
<< "mySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node0")
<< BSON("_id" << 1 << "host"
<< "node1")
<< BSON("_id" << 2 << "host"
<< "node2")
<< BSON("_id" << 3 << "host"
<< "node3")
<< BSON("_id" << 4 << "host"
<< "node4"))),
HostAndPort("node0"));
ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100));
simulateSuccessfulV1Election();
OpTime time1(Timestamp(100, 1), 1);
OpTime time2(Timestamp(100, 2), 1);
// Test invalid write concern
WriteConcernOptions invalidWriteConcern;
invalidWriteConcern.wTimeout = WriteConcernOptions::kNoWaiting;
invalidWriteConcern.wMode = "fakemode";
auto opCtx = makeOperationContext();
ReplicationCoordinator::StatusAndDuration statusAndDur =
getReplCoord()->awaitReplication(opCtx.get(), time1, invalidWriteConcern);
ASSERT_EQUALS(ErrorCodes::UnknownReplWriteConcern, statusAndDur.status);
}
TEST_F(
ReplCoordTest,
NodeReturnsWriteConcernFailedUntilASufficientSetOfNodesHaveTheWriteAndTheWriteIsInACommittedSnapshot) {
assertStartSuccess(
BSON("_id"
<< "mySet"
<< "version" << 2 << "members"
<< BSON_ARRAY(BSON("_id" << 0 << "host"
<< "node0"
<< "tags"
<< BSON("dc"
<< "NA"
<< "rack"
<< "rackNA1"))
<< BSON("_id" << 1 << "host"
<< "node1"
<< "tags"
<< BSON("dc"
<< "NA"
<< "rack"
<< "rackNA2"))
<< BSON("_id" << 2 << "host"
<< "node2"
<< "tags"
<< BSON("dc"
<< "NA"
<< "rack"
<< "rackNA3"))
<< BSON("_id" << 3 << "host"
<< "node3"
<< "tags"
<< BSON("dc"
<< "EU"
<< "rack"
<< "rackEU1"))
<< BSON("_id" << 4 << "host"
<< "node4"
<< "tags"
<< BSON("dc"
<< "EU"
<< "rack"
<< "rackEU2")))
<< "settings"
<< BSON("getLastErrorModes" << BSON("multiDC" << BSON("dc" << 2) << "multiDCAndRack"
<< BSON("dc" << 2 << "rack" << 3)))),
HostAndPort("node0"));
ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
replCoordSetMyLastAppliedOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(OpTime(Timestamp(100, 1), 0), Date_t() + Seconds(100));
simulateSuccessfulV1Election();
OpTime time1(Timestamp(100, 2), 1);
OpTime time2(Timestamp(100, 3), 1);
// Set up valid write concerns for the rest of the test
WriteConcernOptions majorityWriteConcern;
majorityWriteConcern.wTimeout = WriteConcernOptions::kNoWaiting;
majorityWriteConcern.wMode = WriteConcernOptions::kMajority;
majorityWriteConcern.syncMode = WriteConcernOptions::SyncMode::JOURNAL;
WriteConcernOptions multiDCWriteConcern;
multiDCWriteConcern.wTimeout = WriteConcernOptions::kNoWaiting;
multiDCWriteConcern.wMode = "multiDC";
WriteConcernOptions multiRackWriteConcern;
multiRackWriteConcern.wTimeout = WriteConcernOptions::kNoWaiting;
multiRackWriteConcern.wMode = "multiDCAndRack";
auto opCtx = makeOperationContext();
// Nothing satisfied
replCoordSetMyLastAppliedOpTime(time1, Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(time1, Date_t() + Seconds(100));
ReplicationCoordinator::StatusAndDuration statusAndDur =
getReplCoord()->awaitReplication(opCtx.get(), time1, majorityWriteConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, multiDCWriteConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, multiRackWriteConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
// Majority satisfied but not either custom mode
getReplCoord()->setLastAppliedOptime_forTest(2, 1, time1).transitional_ignore();
getReplCoord()->setLastDurableOptime_forTest(2, 1, time1).transitional_ignore();
getReplCoord()->setLastAppliedOptime_forTest(2, 2, time1).transitional_ignore();
getReplCoord()->setLastDurableOptime_forTest(2, 2, time1).transitional_ignore();
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, majorityWriteConcern);
ASSERT_OK(statusAndDur.status);
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, multiDCWriteConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, multiRackWriteConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
// All modes satisfied
getReplCoord()->setLastAppliedOptime_forTest(2, 3, time1).transitional_ignore();
getReplCoord()->setLastDurableOptime_forTest(2, 3, time1).transitional_ignore();
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, majorityWriteConcern);
ASSERT_OK(statusAndDur.status);
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, multiDCWriteConcern);
ASSERT_OK(statusAndDur.status);
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time1, multiRackWriteConcern);
ASSERT_OK(statusAndDur.status);
// multiDC satisfied but not majority or multiRack
replCoordSetMyLastAppliedOpTime(time2, Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(time2, Date_t() + Seconds(100));
getReplCoord()->setLastAppliedOptime_forTest(2, 3, time2).transitional_ignore();
getReplCoord()->setLastDurableOptime_forTest(2, 3, time2).transitional_ignore();
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, majorityWriteConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, multiDCWriteConcern);
ASSERT_OK(statusAndDur.status);
statusAndDur = getReplCoord()->awaitReplication(opCtx.get(), time2, multiRackWriteConcern);
ASSERT_EQUALS(ErrorCodes::WriteConcernFailed, statusAndDur.status);
}
/**
* Used to wait for replication in a separate thread without blocking execution of the test.
* To use, set the optime and write concern to be passed to awaitReplication and then call
* start(), which will spawn a thread that calls awaitReplication. No calls may be made
* on the ReplicationAwaiter instance between calling start and getResult(). After returning
* from getResult(), you can call reset() to allow the awaiter to be reused for another
* awaitReplication call.
*/
class ReplicationAwaiter {
public:
ReplicationAwaiter(ReplicationCoordinatorImpl* replCoord, ServiceContext* service)
: _replCoord(replCoord),
_service(service),
_client(service->makeClient("replAwaiter")),