|
1 | 1 | /** |
2 | | - * This test will ensure that a failed a batch apply will remove the any oplog |
| 2 | + * This test will ensure that recovery from a failed batch application will remove the oplog |
3 | 3 | * entries from that batch. |
4 | 4 | * |
5 | 5 | * To do this we: |
6 | 6 | * -- Create single node replica set |
7 | | - * -- Set minvalid manually on primary way ahead (5 minutes) |
| 7 | + * -- Set minvalid manually on primary way ahead (5 days) |
8 | 8 | * -- Write some oplog entries newer than minvalid.start |
9 | 9 | * -- Ensure restarted primary comes up in recovering and truncates the oplog |
10 | 10 | * -- Success! |
|
54 | 54 | } |
55 | 55 | }))); |
56 | 56 |
|
57 | | - // Set minvalid to something far in the future for the current primary, to |
58 | | - // simulate recovery. |
59 | | - // Note: This is so far in the future (5 days) that it will never become |
60 | | - // secondary. |
| 57 | + // Set minvalid to something far in the future for the current primary, to simulate recovery. |
| 58 | + // Note: This is so far in the future (5 days) that it will never become secondary. |
61 | 59 | var farFutureTS = new Timestamp(Math.floor(new Date().getTime() / 1000) |
62 | 60 | + (60 * 60 * 24 * 5 /* in five days */), 0); |
63 | 61 | var rsgs = assert.commandWorked(localDB.adminCommand("replSetGetStatus")); |
64 | 62 | log(rsgs); |
65 | 63 | var primaryOpTime = rsgs.members[0].optime; |
66 | | - var primaryLastTS = rsgs.members[0].optime.ts; |
67 | | - log(primaryLastTS); |
| 64 | + log(primaryOpTime); |
68 | 65 |
|
69 | 66 | // Set the start of the failed batch |
70 | | - primaryOpTime.ts = new Timestamp(primaryOpTime.ts.t, primaryOpTime.ts.i + 1); |
71 | 67 |
|
72 | | - log(primaryLastTS); |
73 | 68 | jsTest.log("future TS: " + tojson(farFutureTS) + ", date:" + tsToDate(farFutureTS)); |
74 | | - // We do an update in case there is a minvalid document on the primary |
75 | | - // already. |
76 | | - // If the doc doesn't exist then upsert:true will create it, and the |
77 | | - // writeConcern ensures |
78 | | - // that update returns details of the write, like whether an update or |
79 | | - // insert was performed. |
| 69 | + // We do an update in case there is a minvalid document on the primary already. |
| 70 | + // If the doc doesn't exist then upsert:true will create it, and the writeConcern ensures |
| 71 | + // that update returns details of the write, like whether an update or insert was performed. |
80 | 72 | log(assert.writeOK(minvalidColl.update( |
81 | 73 | {}, |
82 | 74 | { |
|
92 | 84 | } |
93 | 85 | }))); |
94 | 86 |
|
| 87 | + // Insert a diverged oplog entry that will be truncated after restart. |
| 88 | + var divergedTS = new Timestamp(primaryOpTime.ts.t, primaryOpTime.ts.i + 1); |
95 | 89 | log(assert.writeOK(localDB.oplog.rs.insert( |
96 | 90 | { |
97 | 91 | _id : 0, |
98 | | - ts : primaryOpTime.ts, |
| 92 | + ts : divergedTS, |
99 | 93 | op : "n", |
100 | | - term : -1 |
| 94 | + h: NumberLong(0), |
| 95 | + t : NumberLong(-1) |
101 | 96 | }))); |
102 | 97 | log(localDB.oplog.rs.find().toArray()); |
103 | 98 | log(assert.commandWorked(localDB.adminCommand("replSetGetStatus"))); |
|
122 | 117 | $natural : -1 |
123 | 118 | }).limit(-1).next().ts; |
124 | 119 | log(localDB.oplog.rs.find().toArray()); |
125 | | - assert.eq(primaryLastTS, lastTS); |
| 120 | + assert.eq(primaryOpTime.ts, lastTS); |
126 | 121 | return true; |
127 | 122 | }); |
128 | 123 |
|
|
0 commit comments