|
6 | 6 | (function() { |
7 | 7 | "use strict"; |
8 | 8 |
|
9 | | - var checkOplog = function(oplog, lsid, uid, txnNum, stmtId, prevTs) { |
| 9 | + var checkOplog = function(oplog, lsid, uid, txnNum, stmtId, prevTs, prevTerm) { |
10 | 10 | assert(oplog != null); |
11 | 11 | assert(oplog.lsid != null); |
12 | 12 | assert.eq(lsid, oplog.lsid.id); |
13 | 13 | assert.eq(uid, oplog.lsid.uid); |
14 | 14 | assert.eq(txnNum, oplog.txnNumber); |
15 | 15 | assert.eq(stmtId, oplog.stmtId); |
16 | | - assert.eq(prevTs.getTime(), oplog.prevTs.getTime()); |
17 | | - assert.eq(prevTs.getInc(), oplog.prevTs.getInc()); |
| 16 | + |
| 17 | + var oplogPrevTs = oplog.prevOpTime.ts; |
| 18 | + assert.eq(prevTs.getTime(), oplogPrevTs.getTime()); |
| 19 | + assert.eq(prevTs.getInc(), oplogPrevTs.getInc()); |
| 20 | + assert.eq(prevTerm, oplog.prevOpTime.t); |
18 | 21 | }; |
19 | 22 |
|
20 | | - var checkSessionCatalog = function(conn, sessionId, uid, txnNum, expectedTs) { |
| 23 | + var checkSessionCatalog = function(conn, sessionId, uid, txnNum, expectedTs, expectedTerm) { |
21 | 24 | var coll = conn.getDB('config').transactions; |
22 | 25 | var sessionDoc = coll.findOne({'_id': {id: sessionId, uid: uid}}); |
23 | 26 |
|
24 | 27 | assert.eq(txnNum, sessionDoc.txnNum); |
25 | | - assert.eq(expectedTs.getTime(), sessionDoc.lastWriteOpTimeTs.getTime()); |
26 | | - assert.eq(expectedTs.getInc(), sessionDoc.lastWriteOpTimeTs.getInc()); |
| 28 | + |
| 29 | + var oplogTs = sessionDoc.lastWriteOpTime.ts; |
| 30 | + assert.eq(expectedTs.getTime(), oplogTs.getTime()); |
| 31 | + assert.eq(expectedTs.getInc(), oplogTs.getInc()); |
| 32 | + |
| 33 | + assert.eq(expectedTerm, sessionDoc.lastWriteOpTime.t); |
27 | 34 | }; |
28 | 35 |
|
29 | 36 | var runTests = function(mainConn, priConn) { |
|
61 | 68 | var oplog = priConn.getDB('local').oplog.rs; |
62 | 69 |
|
63 | 70 | var firstDoc = oplog.findOne({ns: 'test.user', 'o._id': 10}); |
64 | | - checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0)); |
| 71 | + checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0), -1); |
65 | 72 |
|
66 | 73 | var secondDoc = oplog.findOne({ns: 'test.user', 'o._id': 30}); |
67 | | - checkOplog(secondDoc, lsid, uid, txnNumber, 1, firstDoc.ts); |
| 74 | + checkOplog(secondDoc, lsid, uid, txnNumber, 1, firstDoc.ts, firstDoc.t); |
68 | 75 |
|
69 | | - checkSessionCatalog(priConn, lsid, uid, txnNumber, secondDoc.ts); |
| 76 | + checkSessionCatalog(priConn, lsid, uid, txnNumber, secondDoc.ts, secondDoc.t); |
70 | 77 |
|
71 | 78 | //////////////////////////////////////////////////////////////////////// |
72 | 79 | // Test update command |
|
87 | 94 | assert.commandWorked(mainConn.getDB('test').runCommand(cmd)); |
88 | 95 |
|
89 | 96 | firstDoc = oplog.findOne({ns: 'test.user', op: 'u', 'o2._id': 10}); |
90 | | - checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0)); |
| 97 | + checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0), -1); |
91 | 98 |
|
92 | 99 | secondDoc = oplog.findOne({ns: 'test.user', op: 'i', 'o._id': 20}); |
93 | | - checkOplog(secondDoc, lsid, uid, txnNumber, 1, firstDoc.ts); |
| 100 | + checkOplog(secondDoc, lsid, uid, txnNumber, 1, firstDoc.ts, firstDoc.t); |
94 | 101 |
|
95 | 102 | var thirdDoc = oplog.findOne({ns: 'test.user', op: 'u', 'o2._id': 30}); |
96 | | - checkOplog(thirdDoc, lsid, uid, txnNumber, 2, secondDoc.ts); |
| 103 | + checkOplog(thirdDoc, lsid, uid, txnNumber, 2, secondDoc.ts, secondDoc.t); |
97 | 104 |
|
98 | | - checkSessionCatalog(priConn, lsid, uid, txnNumber, thirdDoc.ts); |
| 105 | + checkSessionCatalog(priConn, lsid, uid, txnNumber, thirdDoc.ts, thirdDoc.t); |
99 | 106 |
|
100 | 107 | //////////////////////////////////////////////////////////////////////// |
101 | 108 | // Test delete command |
|
112 | 119 | assert.commandWorked(mainConn.getDB('test').runCommand(cmd)); |
113 | 120 |
|
114 | 121 | firstDoc = oplog.findOne({ns: 'test.user', op: 'd', 'o._id': 10}); |
115 | | - checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0)); |
| 122 | + checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0), -1); |
116 | 123 |
|
117 | 124 | secondDoc = oplog.findOne({ns: 'test.user', op: 'd', 'o._id': 20}); |
118 | | - checkOplog(secondDoc, lsid, uid, txnNumber, 1, firstDoc.ts); |
| 125 | + checkOplog(secondDoc, lsid, uid, txnNumber, 1, firstDoc.ts, firstDoc.t); |
119 | 126 |
|
120 | | - checkSessionCatalog(priConn, lsid, uid, txnNumber, secondDoc.ts); |
| 127 | + checkSessionCatalog(priConn, lsid, uid, txnNumber, secondDoc.ts, secondDoc.t); |
121 | 128 |
|
122 | 129 | //////////////////////////////////////////////////////////////////////// |
123 | 130 | // Test findAndModify command (upsert) |
|
136 | 143 | assert.commandWorked(mainConn.getDB('test').runCommand(cmd)); |
137 | 144 |
|
138 | 145 | firstDoc = oplog.findOne({ns: 'test.user', op: 'i', 'o._id': 40}); |
139 | | - checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0)); |
| 146 | + checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0), -1); |
140 | 147 |
|
141 | 148 | assert.eq(null, firstDoc.preImageTs); |
142 | 149 | assert.eq(null, firstDoc.postImageTs); |
143 | 150 |
|
144 | | - checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts); |
| 151 | + checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts, firstDoc.t); |
145 | 152 | var lastTs = firstDoc.ts; |
146 | 153 |
|
147 | 154 | //////////////////////////////////////////////////////////////////////// |
|
162 | 169 | var res = assert.commandWorked(mainConn.getDB('test').runCommand(cmd)); |
163 | 170 |
|
164 | 171 | firstDoc = oplog.findOne({ns: 'test.user', op: 'u', 'o2._id': 40, ts: {$gt: lastTs}}); |
165 | | - checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0)); |
| 172 | + checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0), -1); |
166 | 173 |
|
167 | 174 | assert.eq(null, firstDoc.postImageTs); |
168 | 175 |
|
169 | | - var savedDoc = oplog.findOne({ns: 'test.user', op: 'n', ts: firstDoc.preImageTs}); |
| 176 | + var savedDoc = oplog.findOne({ |
| 177 | + ns: 'test.user', |
| 178 | + op: 'n', |
| 179 | + ts: firstDoc.preImageOpTime.ts, |
| 180 | + t: firstDoc.preImageOpTime.t |
| 181 | + }); |
170 | 182 | assert.eq(beforeDoc, savedDoc.o); |
171 | 183 |
|
172 | | - checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts); |
| 184 | + checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts, firstDoc.t); |
173 | 185 | lastTs = firstDoc.ts; |
174 | 186 |
|
175 | 187 | //////////////////////////////////////////////////////////////////////// |
|
190 | 202 | var afterDoc = mainConn.getDB('test').user.findOne({_id: 40}); |
191 | 203 |
|
192 | 204 | firstDoc = oplog.findOne({ns: 'test.user', op: 'u', 'o2._id': 40, ts: {$gt: lastTs}}); |
193 | | - checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0)); |
| 205 | + checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0), -1); |
194 | 206 |
|
195 | 207 | assert.eq(null, firstDoc.preImageTs); |
196 | 208 |
|
197 | | - savedDoc = oplog.findOne({ns: 'test.user', op: 'n', ts: firstDoc.postImageTs}); |
| 209 | + savedDoc = oplog.findOne({ |
| 210 | + ns: 'test.user', |
| 211 | + op: 'n', |
| 212 | + ts: firstDoc.postImageOpTime.ts, |
| 213 | + t: firstDoc.postImageOpTime.t |
| 214 | + }); |
198 | 215 | assert.eq(afterDoc, savedDoc.o); |
199 | 216 |
|
200 | | - checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts); |
| 217 | + checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts, firstDoc.t); |
201 | 218 | lastTs = firstDoc.ts; |
202 | 219 |
|
203 | 220 | //////////////////////////////////////////////////////////////////////// |
|
218 | 235 | res = assert.commandWorked(mainConn.getDB('test').runCommand(cmd)); |
219 | 236 |
|
220 | 237 | firstDoc = oplog.findOne({ns: 'test.user', op: 'u', 'o2._id': 40, ts: {$gt: lastTs}}); |
221 | | - checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0)); |
| 238 | + checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0), -1); |
222 | 239 |
|
223 | 240 | assert.eq(null, firstDoc.postImageTs); |
224 | 241 |
|
225 | | - savedDoc = oplog.findOne({ns: 'test.user', op: 'n', ts: firstDoc.preImageTs}); |
| 242 | + savedDoc = oplog.findOne({ |
| 243 | + ns: 'test.user', |
| 244 | + op: 'n', |
| 245 | + ts: firstDoc.preImageOpTime.ts, |
| 246 | + t: firstDoc.preImageOpTime.t |
| 247 | + }); |
226 | 248 | assert.eq(beforeDoc, savedDoc.o); |
227 | 249 |
|
228 | | - checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts); |
| 250 | + checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts, firstDoc.t); |
229 | 251 | lastTs = firstDoc.ts; |
230 | 252 |
|
231 | 253 | //////////////////////////////////////////////////////////////////////// |
|
246 | 268 | afterDoc = mainConn.getDB('test').user.findOne({_id: 40}); |
247 | 269 |
|
248 | 270 | firstDoc = oplog.findOne({ns: 'test.user', op: 'u', 'o2._id': 40, ts: {$gt: lastTs}}); |
249 | | - checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0)); |
| 271 | + checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0), -1); |
250 | 272 |
|
251 | 273 | assert.eq(null, firstDoc.preImageTs); |
252 | 274 |
|
253 | | - savedDoc = oplog.findOne({ns: 'test.user', op: 'n', ts: firstDoc.postImageTs}); |
| 275 | + savedDoc = oplog.findOne({ |
| 276 | + ns: 'test.user', |
| 277 | + op: 'n', |
| 278 | + ts: firstDoc.postImageOpTime.ts, |
| 279 | + t: firstDoc.postImageOpTime.t |
| 280 | + }); |
254 | 281 | assert.eq(afterDoc, savedDoc.o); |
255 | 282 |
|
256 | | - checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts); |
| 283 | + checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts, firstDoc.t); |
257 | 284 | lastTs = firstDoc.ts; |
258 | 285 |
|
259 | 286 | //////////////////////////////////////////////////////////////////////// |
|
273 | 300 | res = assert.commandWorked(mainConn.getDB('test').runCommand(cmd)); |
274 | 301 |
|
275 | 302 | firstDoc = oplog.findOne({ns: 'test.user', op: 'd', 'o._id': 40, ts: {$gt: lastTs}}); |
276 | | - checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0)); |
| 303 | + checkOplog(firstDoc, lsid, uid, txnNumber, 0, Timestamp(0, 0), -1); |
277 | 304 |
|
278 | 305 | assert.eq(null, firstDoc.postImageTs); |
279 | 306 |
|
280 | | - savedDoc = oplog.findOne({ns: 'test.user', op: 'n', ts: firstDoc.preImageTs}); |
| 307 | + savedDoc = oplog.findOne({ |
| 308 | + ns: 'test.user', |
| 309 | + op: 'n', |
| 310 | + ts: firstDoc.preImageOpTime.ts, |
| 311 | + t: firstDoc.preImageOpTime.t |
| 312 | + }); |
281 | 313 | assert.eq(beforeDoc, savedDoc.o); |
282 | 314 |
|
283 | | - checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts); |
| 315 | + checkSessionCatalog(priConn, lsid, uid, txnNumber, firstDoc.ts, firstDoc.t); |
284 | 316 | lastTs = firstDoc.ts; |
285 | 317 | }; |
286 | 318 |
|
|
0 commit comments