1/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3/* Do not edit this file. This code generated by logformat.c. Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. */
4#ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
5#include <stdint.h>
6#include <sys/time.h>
7#include <ft/logger/log-internal.h>
8static uint64_t toku_get_timestamp(void) {
9 struct timeval tv; int r = gettimeofday(&tv, NULL);
10 assert(r==0);
11 return tv.tv_sec * 1000000ULL + tv.tv_usec;
12}
13void toku_log_begin_checkpoint (TOKULOGGER logger, LSN *lsnp, int do_fsync, uint64_t timestamp, TXNID last_xid) {
14 if (logger == NULL) {
15 return;
16 }
17 if (!logger->write_log_files) {
18 ml_lock(&logger->input_lock);
19 logger->lsn.lsn++;
20 if (lsnp) *lsnp=logger->lsn;
21 ml_unlock(&logger->input_lock);
22 return;
23 }
24 const unsigned int buflen= (+4 // len at the beginning
25 +1 // log command
26 +8 // lsn
27 +toku_logsizeof_uint64_t(timestamp)
28 +toku_logsizeof_TXNID(last_xid)
29 +8 // crc + len
30 );
31 struct wbuf wbuf;
32 ml_lock(&logger->input_lock);
33 toku_logger_make_space_in_inbuf(logger, buflen);
34 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
35 wbuf_nocrc_int(&wbuf, buflen);
36 wbuf_nocrc_char(&wbuf, 'x');
37 logger->lsn.lsn++;
38 logger->inbuf.max_lsn_in_buf = logger->lsn;
39 wbuf_nocrc_LSN(&wbuf, logger->lsn);
40 if (lsnp) *lsnp=logger->lsn;
41 if (timestamp == 0) timestamp = toku_get_timestamp();
42 wbuf_nocrc_uint64_t(&wbuf, timestamp);
43 wbuf_nocrc_TXNID(&wbuf, last_xid);
44 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
45 wbuf_nocrc_int(&wbuf, buflen);
46 assert(wbuf.ndone==buflen);
47 logger->inbuf.n_in_buf += buflen;
48 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
49}
50
51void toku_log_end_checkpoint (TOKULOGGER logger, LSN *lsnp, int do_fsync, LSN lsn_begin_checkpoint, uint64_t timestamp, uint32_t num_fassociate_entries, uint32_t num_xstillopen_entries) {
52 if (logger == NULL) {
53 return;
54 }
55 if (!logger->write_log_files) {
56 ml_lock(&logger->input_lock);
57 logger->lsn.lsn++;
58 if (lsnp) *lsnp=logger->lsn;
59 ml_unlock(&logger->input_lock);
60 return;
61 }
62 const unsigned int buflen= (+4 // len at the beginning
63 +1 // log command
64 +8 // lsn
65 +toku_logsizeof_LSN(lsn_begin_checkpoint)
66 +toku_logsizeof_uint64_t(timestamp)
67 +toku_logsizeof_uint32_t(num_fassociate_entries)
68 +toku_logsizeof_uint32_t(num_xstillopen_entries)
69 +8 // crc + len
70 );
71 struct wbuf wbuf;
72 ml_lock(&logger->input_lock);
73 toku_logger_make_space_in_inbuf(logger, buflen);
74 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
75 wbuf_nocrc_int(&wbuf, buflen);
76 wbuf_nocrc_char(&wbuf, 'X');
77 logger->lsn.lsn++;
78 logger->inbuf.max_lsn_in_buf = logger->lsn;
79 wbuf_nocrc_LSN(&wbuf, logger->lsn);
80 if (lsnp) *lsnp=logger->lsn;
81 wbuf_nocrc_LSN(&wbuf, lsn_begin_checkpoint);
82 if (timestamp == 0) timestamp = toku_get_timestamp();
83 wbuf_nocrc_uint64_t(&wbuf, timestamp);
84 wbuf_nocrc_uint32_t(&wbuf, num_fassociate_entries);
85 wbuf_nocrc_uint32_t(&wbuf, num_xstillopen_entries);
86 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
87 wbuf_nocrc_int(&wbuf, buflen);
88 assert(wbuf.ndone==buflen);
89 logger->inbuf.n_in_buf += buflen;
90 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
91}
92
93void toku_log_fassociate (TOKULOGGER logger, LSN *lsnp, int do_fsync, FILENUM filenum, uint32_t treeflags, BYTESTRING iname, uint8_t unlink_on_close) {
94 if (logger == NULL) {
95 return;
96 }
97 if (!logger->write_log_files) {
98 ml_lock(&logger->input_lock);
99 logger->lsn.lsn++;
100 if (lsnp) *lsnp=logger->lsn;
101 ml_unlock(&logger->input_lock);
102 return;
103 }
104 const unsigned int buflen= (+4 // len at the beginning
105 +1 // log command
106 +8 // lsn
107 +toku_logsizeof_FILENUM(filenum)
108 +toku_logsizeof_uint32_t(treeflags)
109 +toku_logsizeof_BYTESTRING(iname)
110 +toku_logsizeof_uint8_t(unlink_on_close)
111 +8 // crc + len
112 );
113 struct wbuf wbuf;
114 ml_lock(&logger->input_lock);
115 toku_logger_make_space_in_inbuf(logger, buflen);
116 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
117 wbuf_nocrc_int(&wbuf, buflen);
118 wbuf_nocrc_char(&wbuf, 'f');
119 logger->lsn.lsn++;
120 logger->inbuf.max_lsn_in_buf = logger->lsn;
121 wbuf_nocrc_LSN(&wbuf, logger->lsn);
122 if (lsnp) *lsnp=logger->lsn;
123 wbuf_nocrc_FILENUM(&wbuf, filenum);
124 wbuf_nocrc_uint32_t(&wbuf, treeflags);
125 wbuf_nocrc_BYTESTRING(&wbuf, iname);
126 wbuf_nocrc_uint8_t(&wbuf, unlink_on_close);
127 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
128 wbuf_nocrc_int(&wbuf, buflen);
129 assert(wbuf.ndone==buflen);
130 logger->inbuf.n_in_buf += buflen;
131 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
132}
133
134void toku_log_xstillopen (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, TXNID_PAIR xid, TXNID_PAIR parentxid, uint64_t rollentry_raw_count, FILENUMS open_filenums, uint8_t force_fsync_on_commit, uint64_t num_rollback_nodes, uint64_t num_rollentries, BLOCKNUM spilled_rollback_head, BLOCKNUM spilled_rollback_tail, BLOCKNUM current_rollback) {
135 if (logger == NULL) {
136 return;
137 }
138 //txn can be NULL during tests
139 invariant(!txn || txn->begin_was_logged);
140 invariant(!txn || !txn_declared_read_only(txn));
141 if (!logger->write_log_files) {
142 ml_lock(&logger->input_lock);
143 logger->lsn.lsn++;
144 if (lsnp) *lsnp=logger->lsn;
145 ml_unlock(&logger->input_lock);
146 return;
147 }
148 const unsigned int buflen= (+4 // len at the beginning
149 +1 // log command
150 +8 // lsn
151 +toku_logsizeof_TXNID_PAIR(xid)
152 +toku_logsizeof_TXNID_PAIR(parentxid)
153 +toku_logsizeof_uint64_t(rollentry_raw_count)
154 +toku_logsizeof_FILENUMS(open_filenums)
155 +toku_logsizeof_uint8_t(force_fsync_on_commit)
156 +toku_logsizeof_uint64_t(num_rollback_nodes)
157 +toku_logsizeof_uint64_t(num_rollentries)
158 +toku_logsizeof_BLOCKNUM(spilled_rollback_head)
159 +toku_logsizeof_BLOCKNUM(spilled_rollback_tail)
160 +toku_logsizeof_BLOCKNUM(current_rollback)
161 +8 // crc + len
162 );
163 struct wbuf wbuf;
164 ml_lock(&logger->input_lock);
165 toku_logger_make_space_in_inbuf(logger, buflen);
166 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
167 wbuf_nocrc_int(&wbuf, buflen);
168 wbuf_nocrc_char(&wbuf, 's');
169 logger->lsn.lsn++;
170 logger->inbuf.max_lsn_in_buf = logger->lsn;
171 wbuf_nocrc_LSN(&wbuf, logger->lsn);
172 if (lsnp) *lsnp=logger->lsn;
173 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
174 wbuf_nocrc_TXNID_PAIR(&wbuf, parentxid);
175 wbuf_nocrc_uint64_t(&wbuf, rollentry_raw_count);
176 wbuf_nocrc_FILENUMS(&wbuf, open_filenums);
177 wbuf_nocrc_uint8_t(&wbuf, force_fsync_on_commit);
178 wbuf_nocrc_uint64_t(&wbuf, num_rollback_nodes);
179 wbuf_nocrc_uint64_t(&wbuf, num_rollentries);
180 wbuf_nocrc_BLOCKNUM(&wbuf, spilled_rollback_head);
181 wbuf_nocrc_BLOCKNUM(&wbuf, spilled_rollback_tail);
182 wbuf_nocrc_BLOCKNUM(&wbuf, current_rollback);
183 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
184 wbuf_nocrc_int(&wbuf, buflen);
185 assert(wbuf.ndone==buflen);
186 logger->inbuf.n_in_buf += buflen;
187 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
188}
189
190void toku_log_xstillopenprepared (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, TXNID_PAIR xid, XIDP xa_xid, uint64_t rollentry_raw_count, FILENUMS open_filenums, uint8_t force_fsync_on_commit, uint64_t num_rollback_nodes, uint64_t num_rollentries, BLOCKNUM spilled_rollback_head, BLOCKNUM spilled_rollback_tail, BLOCKNUM current_rollback) {
191 if (logger == NULL) {
192 return;
193 }
194 //txn can be NULL during tests
195 invariant(!txn || txn->begin_was_logged);
196 invariant(!txn || !txn_declared_read_only(txn));
197 if (!logger->write_log_files) {
198 ml_lock(&logger->input_lock);
199 logger->lsn.lsn++;
200 if (lsnp) *lsnp=logger->lsn;
201 ml_unlock(&logger->input_lock);
202 return;
203 }
204 const unsigned int buflen= (+4 // len at the beginning
205 +1 // log command
206 +8 // lsn
207 +toku_logsizeof_TXNID_PAIR(xid)
208 +toku_logsizeof_XIDP(xa_xid)
209 +toku_logsizeof_uint64_t(rollentry_raw_count)
210 +toku_logsizeof_FILENUMS(open_filenums)
211 +toku_logsizeof_uint8_t(force_fsync_on_commit)
212 +toku_logsizeof_uint64_t(num_rollback_nodes)
213 +toku_logsizeof_uint64_t(num_rollentries)
214 +toku_logsizeof_BLOCKNUM(spilled_rollback_head)
215 +toku_logsizeof_BLOCKNUM(spilled_rollback_tail)
216 +toku_logsizeof_BLOCKNUM(current_rollback)
217 +8 // crc + len
218 );
219 struct wbuf wbuf;
220 ml_lock(&logger->input_lock);
221 toku_logger_make_space_in_inbuf(logger, buflen);
222 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
223 wbuf_nocrc_int(&wbuf, buflen);
224 wbuf_nocrc_char(&wbuf, 'p');
225 logger->lsn.lsn++;
226 logger->inbuf.max_lsn_in_buf = logger->lsn;
227 wbuf_nocrc_LSN(&wbuf, logger->lsn);
228 if (lsnp) *lsnp=logger->lsn;
229 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
230 wbuf_nocrc_XIDP(&wbuf, xa_xid);
231 wbuf_nocrc_uint64_t(&wbuf, rollentry_raw_count);
232 wbuf_nocrc_FILENUMS(&wbuf, open_filenums);
233 wbuf_nocrc_uint8_t(&wbuf, force_fsync_on_commit);
234 wbuf_nocrc_uint64_t(&wbuf, num_rollback_nodes);
235 wbuf_nocrc_uint64_t(&wbuf, num_rollentries);
236 wbuf_nocrc_BLOCKNUM(&wbuf, spilled_rollback_head);
237 wbuf_nocrc_BLOCKNUM(&wbuf, spilled_rollback_tail);
238 wbuf_nocrc_BLOCKNUM(&wbuf, current_rollback);
239 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
240 wbuf_nocrc_int(&wbuf, buflen);
241 assert(wbuf.ndone==buflen);
242 logger->inbuf.n_in_buf += buflen;
243 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
244}
245
246void toku_log_xbegin (TOKULOGGER logger, LSN *lsnp, int do_fsync, TXNID_PAIR xid, TXNID_PAIR parentxid) {
247 if (logger == NULL) {
248 return;
249 }
250 if (!logger->write_log_files) {
251 ml_lock(&logger->input_lock);
252 logger->lsn.lsn++;
253 if (lsnp) *lsnp=logger->lsn;
254 ml_unlock(&logger->input_lock);
255 return;
256 }
257 const unsigned int buflen= (+4 // len at the beginning
258 +1 // log command
259 +8 // lsn
260 +toku_logsizeof_TXNID_PAIR(xid)
261 +toku_logsizeof_TXNID_PAIR(parentxid)
262 +8 // crc + len
263 );
264 struct wbuf wbuf;
265 ml_lock(&logger->input_lock);
266 toku_logger_make_space_in_inbuf(logger, buflen);
267 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
268 wbuf_nocrc_int(&wbuf, buflen);
269 wbuf_nocrc_char(&wbuf, 'b');
270 logger->lsn.lsn++;
271 logger->inbuf.max_lsn_in_buf = logger->lsn;
272 wbuf_nocrc_LSN(&wbuf, logger->lsn);
273 if (lsnp) *lsnp=logger->lsn;
274 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
275 wbuf_nocrc_TXNID_PAIR(&wbuf, parentxid);
276 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
277 wbuf_nocrc_int(&wbuf, buflen);
278 assert(wbuf.ndone==buflen);
279 logger->inbuf.n_in_buf += buflen;
280 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
281}
282
283void toku_log_xcommit (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, TXNID_PAIR xid) {
284 if (logger == NULL) {
285 return;
286 }
287 //txn can be NULL during tests
288 invariant(!txn || txn->begin_was_logged);
289 invariant(!txn || !txn_declared_read_only(txn));
290 if (!logger->write_log_files) {
291 ml_lock(&logger->input_lock);
292 logger->lsn.lsn++;
293 if (lsnp) *lsnp=logger->lsn;
294 ml_unlock(&logger->input_lock);
295 return;
296 }
297 const unsigned int buflen= (+4 // len at the beginning
298 +1 // log command
299 +8 // lsn
300 +toku_logsizeof_TXNID_PAIR(xid)
301 +8 // crc + len
302 );
303 struct wbuf wbuf;
304 ml_lock(&logger->input_lock);
305 toku_logger_make_space_in_inbuf(logger, buflen);
306 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
307 wbuf_nocrc_int(&wbuf, buflen);
308 wbuf_nocrc_char(&wbuf, 'C');
309 logger->lsn.lsn++;
310 logger->inbuf.max_lsn_in_buf = logger->lsn;
311 wbuf_nocrc_LSN(&wbuf, logger->lsn);
312 if (lsnp) *lsnp=logger->lsn;
313 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
314 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
315 wbuf_nocrc_int(&wbuf, buflen);
316 assert(wbuf.ndone==buflen);
317 logger->inbuf.n_in_buf += buflen;
318 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
319}
320
321void toku_log_xprepare (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, TXNID_PAIR xid, XIDP xa_xid) {
322 if (logger == NULL) {
323 return;
324 }
325 //txn can be NULL during tests
326 invariant(!txn || txn->begin_was_logged);
327 invariant(!txn || !txn_declared_read_only(txn));
328 if (!logger->write_log_files) {
329 ml_lock(&logger->input_lock);
330 logger->lsn.lsn++;
331 if (lsnp) *lsnp=logger->lsn;
332 ml_unlock(&logger->input_lock);
333 return;
334 }
335 const unsigned int buflen= (+4 // len at the beginning
336 +1 // log command
337 +8 // lsn
338 +toku_logsizeof_TXNID_PAIR(xid)
339 +toku_logsizeof_XIDP(xa_xid)
340 +8 // crc + len
341 );
342 struct wbuf wbuf;
343 ml_lock(&logger->input_lock);
344 toku_logger_make_space_in_inbuf(logger, buflen);
345 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
346 wbuf_nocrc_int(&wbuf, buflen);
347 wbuf_nocrc_char(&wbuf, 'P');
348 logger->lsn.lsn++;
349 logger->inbuf.max_lsn_in_buf = logger->lsn;
350 wbuf_nocrc_LSN(&wbuf, logger->lsn);
351 if (lsnp) *lsnp=logger->lsn;
352 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
353 wbuf_nocrc_XIDP(&wbuf, xa_xid);
354 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
355 wbuf_nocrc_int(&wbuf, buflen);
356 assert(wbuf.ndone==buflen);
357 logger->inbuf.n_in_buf += buflen;
358 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
359}
360
361void toku_log_xabort (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, TXNID_PAIR xid) {
362 if (logger == NULL) {
363 return;
364 }
365 //txn can be NULL during tests
366 invariant(!txn || txn->begin_was_logged);
367 invariant(!txn || !txn_declared_read_only(txn));
368 if (!logger->write_log_files) {
369 ml_lock(&logger->input_lock);
370 logger->lsn.lsn++;
371 if (lsnp) *lsnp=logger->lsn;
372 ml_unlock(&logger->input_lock);
373 return;
374 }
375 const unsigned int buflen= (+4 // len at the beginning
376 +1 // log command
377 +8 // lsn
378 +toku_logsizeof_TXNID_PAIR(xid)
379 +8 // crc + len
380 );
381 struct wbuf wbuf;
382 ml_lock(&logger->input_lock);
383 toku_logger_make_space_in_inbuf(logger, buflen);
384 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
385 wbuf_nocrc_int(&wbuf, buflen);
386 wbuf_nocrc_char(&wbuf, 'q');
387 logger->lsn.lsn++;
388 logger->inbuf.max_lsn_in_buf = logger->lsn;
389 wbuf_nocrc_LSN(&wbuf, logger->lsn);
390 if (lsnp) *lsnp=logger->lsn;
391 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
392 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
393 wbuf_nocrc_int(&wbuf, buflen);
394 assert(wbuf.ndone==buflen);
395 logger->inbuf.n_in_buf += buflen;
396 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
397}
398
399void toku_log_fcreate (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, TXNID_PAIR xid, FILENUM filenum, BYTESTRING iname, uint32_t mode, uint32_t treeflags, uint32_t nodesize, uint32_t basementnodesize, uint32_t compression_method) {
400 if (logger == NULL) {
401 return;
402 }
403 //txn can be NULL during tests
404 //never null when not checkpoint.
405 if (txn && !txn->begin_was_logged) {
406 invariant(!txn_declared_read_only(txn));
407 toku_maybe_log_begin_txn_for_write_operation(txn);
408 }
409 if (!logger->write_log_files) {
410 ml_lock(&logger->input_lock);
411 logger->lsn.lsn++;
412 if (lsnp) *lsnp=logger->lsn;
413 ml_unlock(&logger->input_lock);
414 return;
415 }
416 const unsigned int buflen= (+4 // len at the beginning
417 +1 // log command
418 +8 // lsn
419 +toku_logsizeof_TXNID_PAIR(xid)
420 +toku_logsizeof_FILENUM(filenum)
421 +toku_logsizeof_BYTESTRING(iname)
422 +toku_logsizeof_uint32_t(mode)
423 +toku_logsizeof_uint32_t(treeflags)
424 +toku_logsizeof_uint32_t(nodesize)
425 +toku_logsizeof_uint32_t(basementnodesize)
426 +toku_logsizeof_uint32_t(compression_method)
427 +8 // crc + len
428 );
429 struct wbuf wbuf;
430 ml_lock(&logger->input_lock);
431 toku_logger_make_space_in_inbuf(logger, buflen);
432 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
433 wbuf_nocrc_int(&wbuf, buflen);
434 wbuf_nocrc_char(&wbuf, 'F');
435 logger->lsn.lsn++;
436 logger->inbuf.max_lsn_in_buf = logger->lsn;
437 wbuf_nocrc_LSN(&wbuf, logger->lsn);
438 if (lsnp) *lsnp=logger->lsn;
439 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
440 wbuf_nocrc_FILENUM(&wbuf, filenum);
441 wbuf_nocrc_BYTESTRING(&wbuf, iname);
442 wbuf_nocrc_uint32_t(&wbuf, mode);
443 wbuf_nocrc_uint32_t(&wbuf, treeflags);
444 wbuf_nocrc_uint32_t(&wbuf, nodesize);
445 wbuf_nocrc_uint32_t(&wbuf, basementnodesize);
446 wbuf_nocrc_uint32_t(&wbuf, compression_method);
447 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
448 wbuf_nocrc_int(&wbuf, buflen);
449 assert(wbuf.ndone==buflen);
450 logger->inbuf.n_in_buf += buflen;
451 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
452}
453
454void toku_log_fopen (TOKULOGGER logger, LSN *lsnp, int do_fsync, BYTESTRING iname, FILENUM filenum, uint32_t treeflags) {
455 if (logger == NULL) {
456 return;
457 }
458 if (!logger->write_log_files) {
459 ml_lock(&logger->input_lock);
460 logger->lsn.lsn++;
461 if (lsnp) *lsnp=logger->lsn;
462 ml_unlock(&logger->input_lock);
463 return;
464 }
465 const unsigned int buflen= (+4 // len at the beginning
466 +1 // log command
467 +8 // lsn
468 +toku_logsizeof_BYTESTRING(iname)
469 +toku_logsizeof_FILENUM(filenum)
470 +toku_logsizeof_uint32_t(treeflags)
471 +8 // crc + len
472 );
473 struct wbuf wbuf;
474 ml_lock(&logger->input_lock);
475 toku_logger_make_space_in_inbuf(logger, buflen);
476 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
477 wbuf_nocrc_int(&wbuf, buflen);
478 wbuf_nocrc_char(&wbuf, 'O');
479 logger->lsn.lsn++;
480 logger->inbuf.max_lsn_in_buf = logger->lsn;
481 wbuf_nocrc_LSN(&wbuf, logger->lsn);
482 if (lsnp) *lsnp=logger->lsn;
483 wbuf_nocrc_BYTESTRING(&wbuf, iname);
484 wbuf_nocrc_FILENUM(&wbuf, filenum);
485 wbuf_nocrc_uint32_t(&wbuf, treeflags);
486 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
487 wbuf_nocrc_int(&wbuf, buflen);
488 assert(wbuf.ndone==buflen);
489 logger->inbuf.n_in_buf += buflen;
490 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
491}
492
493void toku_log_fclose (TOKULOGGER logger, LSN *lsnp, int do_fsync, BYTESTRING iname, FILENUM filenum) {
494 if (logger == NULL) {
495 return;
496 }
497 if (!logger->write_log_files) {
498 ml_lock(&logger->input_lock);
499 logger->lsn.lsn++;
500 if (lsnp) *lsnp=logger->lsn;
501 ml_unlock(&logger->input_lock);
502 return;
503 }
504 const unsigned int buflen= (+4 // len at the beginning
505 +1 // log command
506 +8 // lsn
507 +toku_logsizeof_BYTESTRING(iname)
508 +toku_logsizeof_FILENUM(filenum)
509 +8 // crc + len
510 );
511 struct wbuf wbuf;
512 ml_lock(&logger->input_lock);
513 toku_logger_make_space_in_inbuf(logger, buflen);
514 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
515 wbuf_nocrc_int(&wbuf, buflen);
516 wbuf_nocrc_char(&wbuf, 'e');
517 logger->lsn.lsn++;
518 logger->inbuf.max_lsn_in_buf = logger->lsn;
519 wbuf_nocrc_LSN(&wbuf, logger->lsn);
520 if (lsnp) *lsnp=logger->lsn;
521 wbuf_nocrc_BYTESTRING(&wbuf, iname);
522 wbuf_nocrc_FILENUM(&wbuf, filenum);
523 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
524 wbuf_nocrc_int(&wbuf, buflen);
525 assert(wbuf.ndone==buflen);
526 logger->inbuf.n_in_buf += buflen;
527 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
528}
529
530void toku_log_fdelete (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, TXNID_PAIR xid, FILENUM filenum) {
531 if (logger == NULL) {
532 return;
533 }
534 //txn can be NULL during tests
535 //never null when not checkpoint.
536 if (txn && !txn->begin_was_logged) {
537 invariant(!txn_declared_read_only(txn));
538 toku_maybe_log_begin_txn_for_write_operation(txn);
539 }
540 if (!logger->write_log_files) {
541 ml_lock(&logger->input_lock);
542 logger->lsn.lsn++;
543 if (lsnp) *lsnp=logger->lsn;
544 ml_unlock(&logger->input_lock);
545 return;
546 }
547 const unsigned int buflen= (+4 // len at the beginning
548 +1 // log command
549 +8 // lsn
550 +toku_logsizeof_TXNID_PAIR(xid)
551 +toku_logsizeof_FILENUM(filenum)
552 +8 // crc + len
553 );
554 struct wbuf wbuf;
555 ml_lock(&logger->input_lock);
556 toku_logger_make_space_in_inbuf(logger, buflen);
557 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
558 wbuf_nocrc_int(&wbuf, buflen);
559 wbuf_nocrc_char(&wbuf, 'U');
560 logger->lsn.lsn++;
561 logger->inbuf.max_lsn_in_buf = logger->lsn;
562 wbuf_nocrc_LSN(&wbuf, logger->lsn);
563 if (lsnp) *lsnp=logger->lsn;
564 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
565 wbuf_nocrc_FILENUM(&wbuf, filenum);
566 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
567 wbuf_nocrc_int(&wbuf, buflen);
568 assert(wbuf.ndone==buflen);
569 logger->inbuf.n_in_buf += buflen;
570 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
571}
572
573void toku_log_frename (TOKULOGGER logger, LSN *lsnp, int do_fsync, TXNID_PAIR xid, BYTESTRING old_iname, FILENUM old_filenum, BYTESTRING new_iname) {
574 if (logger == NULL) {
575 return;
576 }
577 if (!logger->write_log_files) {
578 ml_lock(&logger->input_lock);
579 logger->lsn.lsn++;
580 if (lsnp) *lsnp=logger->lsn;
581 ml_unlock(&logger->input_lock);
582 return;
583 }
584 const unsigned int buflen= (+4 // len at the beginning
585 +1 // log command
586 +8 // lsn
587 +toku_logsizeof_TXNID_PAIR(xid)
588 +toku_logsizeof_BYTESTRING(old_iname)
589 +toku_logsizeof_FILENUM(old_filenum)
590 +toku_logsizeof_BYTESTRING(new_iname)
591 +8 // crc + len
592 );
593 struct wbuf wbuf;
594 ml_lock(&logger->input_lock);
595 toku_logger_make_space_in_inbuf(logger, buflen);
596 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
597 wbuf_nocrc_int(&wbuf, buflen);
598 wbuf_nocrc_char(&wbuf, 'n');
599 logger->lsn.lsn++;
600 logger->inbuf.max_lsn_in_buf = logger->lsn;
601 wbuf_nocrc_LSN(&wbuf, logger->lsn);
602 if (lsnp) *lsnp=logger->lsn;
603 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
604 wbuf_nocrc_BYTESTRING(&wbuf, old_iname);
605 wbuf_nocrc_FILENUM(&wbuf, old_filenum);
606 wbuf_nocrc_BYTESTRING(&wbuf, new_iname);
607 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
608 wbuf_nocrc_int(&wbuf, buflen);
609 assert(wbuf.ndone==buflen);
610 logger->inbuf.n_in_buf += buflen;
611 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
612}
613
614void toku_log_enq_insert (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, FILENUM filenum, TXNID_PAIR xid, BYTESTRING key, BYTESTRING value) {
615 if (logger == NULL) {
616 return;
617 }
618 //txn can be NULL during tests
619 //never null when not checkpoint.
620 if (txn && !txn->begin_was_logged) {
621 invariant(!txn_declared_read_only(txn));
622 toku_maybe_log_begin_txn_for_write_operation(txn);
623 }
624 if (!logger->write_log_files) {
625 ml_lock(&logger->input_lock);
626 logger->lsn.lsn++;
627 if (lsnp) *lsnp=logger->lsn;
628 ml_unlock(&logger->input_lock);
629 return;
630 }
631 const unsigned int buflen= (+4 // len at the beginning
632 +1 // log command
633 +8 // lsn
634 +toku_logsizeof_FILENUM(filenum)
635 +toku_logsizeof_TXNID_PAIR(xid)
636 +toku_logsizeof_BYTESTRING(key)
637 +toku_logsizeof_BYTESTRING(value)
638 +8 // crc + len
639 );
640 struct wbuf wbuf;
641 ml_lock(&logger->input_lock);
642 toku_logger_make_space_in_inbuf(logger, buflen);
643 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
644 wbuf_nocrc_int(&wbuf, buflen);
645 wbuf_nocrc_char(&wbuf, 'I');
646 logger->lsn.lsn++;
647 logger->inbuf.max_lsn_in_buf = logger->lsn;
648 wbuf_nocrc_LSN(&wbuf, logger->lsn);
649 if (lsnp) *lsnp=logger->lsn;
650 wbuf_nocrc_FILENUM(&wbuf, filenum);
651 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
652 wbuf_nocrc_BYTESTRING(&wbuf, key);
653 wbuf_nocrc_BYTESTRING(&wbuf, value);
654 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
655 wbuf_nocrc_int(&wbuf, buflen);
656 assert(wbuf.ndone==buflen);
657 logger->inbuf.n_in_buf += buflen;
658 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
659}
660
661void toku_log_enq_insert_no_overwrite (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, FILENUM filenum, TXNID_PAIR xid, BYTESTRING key, BYTESTRING value) {
662 if (logger == NULL) {
663 return;
664 }
665 //txn can be NULL during tests
666 //never null when not checkpoint.
667 if (txn && !txn->begin_was_logged) {
668 invariant(!txn_declared_read_only(txn));
669 toku_maybe_log_begin_txn_for_write_operation(txn);
670 }
671 if (!logger->write_log_files) {
672 ml_lock(&logger->input_lock);
673 logger->lsn.lsn++;
674 if (lsnp) *lsnp=logger->lsn;
675 ml_unlock(&logger->input_lock);
676 return;
677 }
678 const unsigned int buflen= (+4 // len at the beginning
679 +1 // log command
680 +8 // lsn
681 +toku_logsizeof_FILENUM(filenum)
682 +toku_logsizeof_TXNID_PAIR(xid)
683 +toku_logsizeof_BYTESTRING(key)
684 +toku_logsizeof_BYTESTRING(value)
685 +8 // crc + len
686 );
687 struct wbuf wbuf;
688 ml_lock(&logger->input_lock);
689 toku_logger_make_space_in_inbuf(logger, buflen);
690 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
691 wbuf_nocrc_int(&wbuf, buflen);
692 wbuf_nocrc_char(&wbuf, 'i');
693 logger->lsn.lsn++;
694 logger->inbuf.max_lsn_in_buf = logger->lsn;
695 wbuf_nocrc_LSN(&wbuf, logger->lsn);
696 if (lsnp) *lsnp=logger->lsn;
697 wbuf_nocrc_FILENUM(&wbuf, filenum);
698 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
699 wbuf_nocrc_BYTESTRING(&wbuf, key);
700 wbuf_nocrc_BYTESTRING(&wbuf, value);
701 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
702 wbuf_nocrc_int(&wbuf, buflen);
703 assert(wbuf.ndone==buflen);
704 logger->inbuf.n_in_buf += buflen;
705 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
706}
707
708void toku_log_enq_delete_any (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, FILENUM filenum, TXNID_PAIR xid, BYTESTRING key) {
709 if (logger == NULL) {
710 return;
711 }
712 //txn can be NULL during tests
713 //never null when not checkpoint.
714 if (txn && !txn->begin_was_logged) {
715 invariant(!txn_declared_read_only(txn));
716 toku_maybe_log_begin_txn_for_write_operation(txn);
717 }
718 if (!logger->write_log_files) {
719 ml_lock(&logger->input_lock);
720 logger->lsn.lsn++;
721 if (lsnp) *lsnp=logger->lsn;
722 ml_unlock(&logger->input_lock);
723 return;
724 }
725 const unsigned int buflen= (+4 // len at the beginning
726 +1 // log command
727 +8 // lsn
728 +toku_logsizeof_FILENUM(filenum)
729 +toku_logsizeof_TXNID_PAIR(xid)
730 +toku_logsizeof_BYTESTRING(key)
731 +8 // crc + len
732 );
733 struct wbuf wbuf;
734 ml_lock(&logger->input_lock);
735 toku_logger_make_space_in_inbuf(logger, buflen);
736 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
737 wbuf_nocrc_int(&wbuf, buflen);
738 wbuf_nocrc_char(&wbuf, 'E');
739 logger->lsn.lsn++;
740 logger->inbuf.max_lsn_in_buf = logger->lsn;
741 wbuf_nocrc_LSN(&wbuf, logger->lsn);
742 if (lsnp) *lsnp=logger->lsn;
743 wbuf_nocrc_FILENUM(&wbuf, filenum);
744 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
745 wbuf_nocrc_BYTESTRING(&wbuf, key);
746 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
747 wbuf_nocrc_int(&wbuf, buflen);
748 assert(wbuf.ndone==buflen);
749 logger->inbuf.n_in_buf += buflen;
750 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
751}
752
753void toku_log_enq_insert_multiple (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, FILENUM src_filenum, FILENUMS dest_filenums, TXNID_PAIR xid, BYTESTRING src_key, BYTESTRING src_val) {
754 if (logger == NULL) {
755 return;
756 }
757 //txn can be NULL during tests
758 //never null when not checkpoint.
759 if (txn && !txn->begin_was_logged) {
760 invariant(!txn_declared_read_only(txn));
761 toku_maybe_log_begin_txn_for_write_operation(txn);
762 }
763 if (!logger->write_log_files) {
764 ml_lock(&logger->input_lock);
765 logger->lsn.lsn++;
766 if (lsnp) *lsnp=logger->lsn;
767 ml_unlock(&logger->input_lock);
768 return;
769 }
770 const unsigned int buflen= (+4 // len at the beginning
771 +1 // log command
772 +8 // lsn
773 +toku_logsizeof_FILENUM(src_filenum)
774 +toku_logsizeof_FILENUMS(dest_filenums)
775 +toku_logsizeof_TXNID_PAIR(xid)
776 +toku_logsizeof_BYTESTRING(src_key)
777 +toku_logsizeof_BYTESTRING(src_val)
778 +8 // crc + len
779 );
780 struct wbuf wbuf;
781 ml_lock(&logger->input_lock);
782 toku_logger_make_space_in_inbuf(logger, buflen);
783 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
784 wbuf_nocrc_int(&wbuf, buflen);
785 wbuf_nocrc_char(&wbuf, 'm');
786 logger->lsn.lsn++;
787 logger->inbuf.max_lsn_in_buf = logger->lsn;
788 wbuf_nocrc_LSN(&wbuf, logger->lsn);
789 if (lsnp) *lsnp=logger->lsn;
790 wbuf_nocrc_FILENUM(&wbuf, src_filenum);
791 wbuf_nocrc_FILENUMS(&wbuf, dest_filenums);
792 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
793 wbuf_nocrc_BYTESTRING(&wbuf, src_key);
794 wbuf_nocrc_BYTESTRING(&wbuf, src_val);
795 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
796 wbuf_nocrc_int(&wbuf, buflen);
797 assert(wbuf.ndone==buflen);
798 logger->inbuf.n_in_buf += buflen;
799 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
800}
801
802void toku_log_enq_delete_multiple (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, FILENUM src_filenum, FILENUMS dest_filenums, TXNID_PAIR xid, BYTESTRING src_key, BYTESTRING src_val) {
803 if (logger == NULL) {
804 return;
805 }
806 //txn can be NULL during tests
807 //never null when not checkpoint.
808 if (txn && !txn->begin_was_logged) {
809 invariant(!txn_declared_read_only(txn));
810 toku_maybe_log_begin_txn_for_write_operation(txn);
811 }
812 if (!logger->write_log_files) {
813 ml_lock(&logger->input_lock);
814 logger->lsn.lsn++;
815 if (lsnp) *lsnp=logger->lsn;
816 ml_unlock(&logger->input_lock);
817 return;
818 }
819 const unsigned int buflen= (+4 // len at the beginning
820 +1 // log command
821 +8 // lsn
822 +toku_logsizeof_FILENUM(src_filenum)
823 +toku_logsizeof_FILENUMS(dest_filenums)
824 +toku_logsizeof_TXNID_PAIR(xid)
825 +toku_logsizeof_BYTESTRING(src_key)
826 +toku_logsizeof_BYTESTRING(src_val)
827 +8 // crc + len
828 );
829 struct wbuf wbuf;
830 ml_lock(&logger->input_lock);
831 toku_logger_make_space_in_inbuf(logger, buflen);
832 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
833 wbuf_nocrc_int(&wbuf, buflen);
834 wbuf_nocrc_char(&wbuf, 'M');
835 logger->lsn.lsn++;
836 logger->inbuf.max_lsn_in_buf = logger->lsn;
837 wbuf_nocrc_LSN(&wbuf, logger->lsn);
838 if (lsnp) *lsnp=logger->lsn;
839 wbuf_nocrc_FILENUM(&wbuf, src_filenum);
840 wbuf_nocrc_FILENUMS(&wbuf, dest_filenums);
841 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
842 wbuf_nocrc_BYTESTRING(&wbuf, src_key);
843 wbuf_nocrc_BYTESTRING(&wbuf, src_val);
844 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
845 wbuf_nocrc_int(&wbuf, buflen);
846 assert(wbuf.ndone==buflen);
847 logger->inbuf.n_in_buf += buflen;
848 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
849}
850
851void toku_log_comment (TOKULOGGER logger, LSN *lsnp, int do_fsync, uint64_t timestamp, BYTESTRING comment) {
852 if (logger == NULL) {
853 return;
854 }
855 if (!logger->write_log_files) {
856 ml_lock(&logger->input_lock);
857 logger->lsn.lsn++;
858 if (lsnp) *lsnp=logger->lsn;
859 ml_unlock(&logger->input_lock);
860 return;
861 }
862 const unsigned int buflen= (+4 // len at the beginning
863 +1 // log command
864 +8 // lsn
865 +toku_logsizeof_uint64_t(timestamp)
866 +toku_logsizeof_BYTESTRING(comment)
867 +8 // crc + len
868 );
869 struct wbuf wbuf;
870 ml_lock(&logger->input_lock);
871 toku_logger_make_space_in_inbuf(logger, buflen);
872 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
873 wbuf_nocrc_int(&wbuf, buflen);
874 wbuf_nocrc_char(&wbuf, 'T');
875 logger->lsn.lsn++;
876 logger->inbuf.max_lsn_in_buf = logger->lsn;
877 wbuf_nocrc_LSN(&wbuf, logger->lsn);
878 if (lsnp) *lsnp=logger->lsn;
879 if (timestamp == 0) timestamp = toku_get_timestamp();
880 wbuf_nocrc_uint64_t(&wbuf, timestamp);
881 wbuf_nocrc_BYTESTRING(&wbuf, comment);
882 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
883 wbuf_nocrc_int(&wbuf, buflen);
884 assert(wbuf.ndone==buflen);
885 logger->inbuf.n_in_buf += buflen;
886 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
887}
888
889void toku_log_shutdown_up_to_19 (TOKULOGGER logger, LSN *lsnp, int do_fsync, uint64_t timestamp) {
890 if (logger == NULL) {
891 return;
892 }
893 if (!logger->write_log_files) {
894 ml_lock(&logger->input_lock);
895 logger->lsn.lsn++;
896 if (lsnp) *lsnp=logger->lsn;
897 ml_unlock(&logger->input_lock);
898 return;
899 }
900 const unsigned int buflen= (+4 // len at the beginning
901 +1 // log command
902 +8 // lsn
903 +toku_logsizeof_uint64_t(timestamp)
904 +8 // crc + len
905 );
906 struct wbuf wbuf;
907 ml_lock(&logger->input_lock);
908 toku_logger_make_space_in_inbuf(logger, buflen);
909 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
910 wbuf_nocrc_int(&wbuf, buflen);
911 wbuf_nocrc_char(&wbuf, 'Q');
912 logger->lsn.lsn++;
913 logger->inbuf.max_lsn_in_buf = logger->lsn;
914 wbuf_nocrc_LSN(&wbuf, logger->lsn);
915 if (lsnp) *lsnp=logger->lsn;
916 if (timestamp == 0) timestamp = toku_get_timestamp();
917 wbuf_nocrc_uint64_t(&wbuf, timestamp);
918 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
919 wbuf_nocrc_int(&wbuf, buflen);
920 assert(wbuf.ndone==buflen);
921 logger->inbuf.n_in_buf += buflen;
922 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
923}
924
925void toku_log_shutdown (TOKULOGGER logger, LSN *lsnp, int do_fsync, uint64_t timestamp, TXNID last_xid) {
926 if (logger == NULL) {
927 return;
928 }
929 if (!logger->write_log_files) {
930 ml_lock(&logger->input_lock);
931 logger->lsn.lsn++;
932 if (lsnp) *lsnp=logger->lsn;
933 ml_unlock(&logger->input_lock);
934 return;
935 }
936 const unsigned int buflen= (+4 // len at the beginning
937 +1 // log command
938 +8 // lsn
939 +toku_logsizeof_uint64_t(timestamp)
940 +toku_logsizeof_TXNID(last_xid)
941 +8 // crc + len
942 );
943 struct wbuf wbuf;
944 ml_lock(&logger->input_lock);
945 toku_logger_make_space_in_inbuf(logger, buflen);
946 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
947 wbuf_nocrc_int(&wbuf, buflen);
948 wbuf_nocrc_char(&wbuf, '0');
949 logger->lsn.lsn++;
950 logger->inbuf.max_lsn_in_buf = logger->lsn;
951 wbuf_nocrc_LSN(&wbuf, logger->lsn);
952 if (lsnp) *lsnp=logger->lsn;
953 if (timestamp == 0) timestamp = toku_get_timestamp();
954 wbuf_nocrc_uint64_t(&wbuf, timestamp);
955 wbuf_nocrc_TXNID(&wbuf, last_xid);
956 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
957 wbuf_nocrc_int(&wbuf, buflen);
958 assert(wbuf.ndone==buflen);
959 logger->inbuf.n_in_buf += buflen;
960 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
961}
962
963void toku_log_load (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, TXNID_PAIR xid, FILENUM old_filenum, BYTESTRING new_iname) {
964 if (logger == NULL) {
965 return;
966 }
967 //txn can be NULL during tests
968 //never null when not checkpoint.
969 if (txn && !txn->begin_was_logged) {
970 invariant(!txn_declared_read_only(txn));
971 toku_maybe_log_begin_txn_for_write_operation(txn);
972 }
973 if (!logger->write_log_files) {
974 ml_lock(&logger->input_lock);
975 logger->lsn.lsn++;
976 if (lsnp) *lsnp=logger->lsn;
977 ml_unlock(&logger->input_lock);
978 return;
979 }
980 const unsigned int buflen= (+4 // len at the beginning
981 +1 // log command
982 +8 // lsn
983 +toku_logsizeof_TXNID_PAIR(xid)
984 +toku_logsizeof_FILENUM(old_filenum)
985 +toku_logsizeof_BYTESTRING(new_iname)
986 +8 // crc + len
987 );
988 struct wbuf wbuf;
989 ml_lock(&logger->input_lock);
990 toku_logger_make_space_in_inbuf(logger, buflen);
991 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
992 wbuf_nocrc_int(&wbuf, buflen);
993 wbuf_nocrc_char(&wbuf, 'l');
994 logger->lsn.lsn++;
995 logger->inbuf.max_lsn_in_buf = logger->lsn;
996 wbuf_nocrc_LSN(&wbuf, logger->lsn);
997 if (lsnp) *lsnp=logger->lsn;
998 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
999 wbuf_nocrc_FILENUM(&wbuf, old_filenum);
1000 wbuf_nocrc_BYTESTRING(&wbuf, new_iname);
1001 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
1002 wbuf_nocrc_int(&wbuf, buflen);
1003 assert(wbuf.ndone==buflen);
1004 logger->inbuf.n_in_buf += buflen;
1005 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
1006}
1007
1008void toku_log_hot_index (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, TXNID_PAIR xid, FILENUMS hot_index_filenums) {
1009 if (logger == NULL) {
1010 return;
1011 }
1012 //txn can be NULL during tests
1013 //never null when not checkpoint.
1014 if (txn && !txn->begin_was_logged) {
1015 invariant(!txn_declared_read_only(txn));
1016 toku_maybe_log_begin_txn_for_write_operation(txn);
1017 }
1018 if (!logger->write_log_files) {
1019 ml_lock(&logger->input_lock);
1020 logger->lsn.lsn++;
1021 if (lsnp) *lsnp=logger->lsn;
1022 ml_unlock(&logger->input_lock);
1023 return;
1024 }
1025 const unsigned int buflen= (+4 // len at the beginning
1026 +1 // log command
1027 +8 // lsn
1028 +toku_logsizeof_TXNID_PAIR(xid)
1029 +toku_logsizeof_FILENUMS(hot_index_filenums)
1030 +8 // crc + len
1031 );
1032 struct wbuf wbuf;
1033 ml_lock(&logger->input_lock);
1034 toku_logger_make_space_in_inbuf(logger, buflen);
1035 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
1036 wbuf_nocrc_int(&wbuf, buflen);
1037 wbuf_nocrc_char(&wbuf, 'h');
1038 logger->lsn.lsn++;
1039 logger->inbuf.max_lsn_in_buf = logger->lsn;
1040 wbuf_nocrc_LSN(&wbuf, logger->lsn);
1041 if (lsnp) *lsnp=logger->lsn;
1042 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
1043 wbuf_nocrc_FILENUMS(&wbuf, hot_index_filenums);
1044 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
1045 wbuf_nocrc_int(&wbuf, buflen);
1046 assert(wbuf.ndone==buflen);
1047 logger->inbuf.n_in_buf += buflen;
1048 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
1049}
1050
1051void toku_log_enq_update (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, FILENUM filenum, TXNID_PAIR xid, BYTESTRING key, BYTESTRING extra) {
1052 if (logger == NULL) {
1053 return;
1054 }
1055 //txn can be NULL during tests
1056 //never null when not checkpoint.
1057 if (txn && !txn->begin_was_logged) {
1058 invariant(!txn_declared_read_only(txn));
1059 toku_maybe_log_begin_txn_for_write_operation(txn);
1060 }
1061 if (!logger->write_log_files) {
1062 ml_lock(&logger->input_lock);
1063 logger->lsn.lsn++;
1064 if (lsnp) *lsnp=logger->lsn;
1065 ml_unlock(&logger->input_lock);
1066 return;
1067 }
1068 const unsigned int buflen= (+4 // len at the beginning
1069 +1 // log command
1070 +8 // lsn
1071 +toku_logsizeof_FILENUM(filenum)
1072 +toku_logsizeof_TXNID_PAIR(xid)
1073 +toku_logsizeof_BYTESTRING(key)
1074 +toku_logsizeof_BYTESTRING(extra)
1075 +8 // crc + len
1076 );
1077 struct wbuf wbuf;
1078 ml_lock(&logger->input_lock);
1079 toku_logger_make_space_in_inbuf(logger, buflen);
1080 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
1081 wbuf_nocrc_int(&wbuf, buflen);
1082 wbuf_nocrc_char(&wbuf, 'u');
1083 logger->lsn.lsn++;
1084 logger->inbuf.max_lsn_in_buf = logger->lsn;
1085 wbuf_nocrc_LSN(&wbuf, logger->lsn);
1086 if (lsnp) *lsnp=logger->lsn;
1087 wbuf_nocrc_FILENUM(&wbuf, filenum);
1088 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
1089 wbuf_nocrc_BYTESTRING(&wbuf, key);
1090 wbuf_nocrc_BYTESTRING(&wbuf, extra);
1091 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
1092 wbuf_nocrc_int(&wbuf, buflen);
1093 assert(wbuf.ndone==buflen);
1094 logger->inbuf.n_in_buf += buflen;
1095 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
1096}
1097
1098void toku_log_enq_updatebroadcast (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, FILENUM filenum, TXNID_PAIR xid, BYTESTRING extra, bool is_resetting_op) {
1099 if (logger == NULL) {
1100 return;
1101 }
1102 //txn can be NULL during tests
1103 //never null when not checkpoint.
1104 if (txn && !txn->begin_was_logged) {
1105 invariant(!txn_declared_read_only(txn));
1106 toku_maybe_log_begin_txn_for_write_operation(txn);
1107 }
1108 if (!logger->write_log_files) {
1109 ml_lock(&logger->input_lock);
1110 logger->lsn.lsn++;
1111 if (lsnp) *lsnp=logger->lsn;
1112 ml_unlock(&logger->input_lock);
1113 return;
1114 }
1115 const unsigned int buflen= (+4 // len at the beginning
1116 +1 // log command
1117 +8 // lsn
1118 +toku_logsizeof_FILENUM(filenum)
1119 +toku_logsizeof_TXNID_PAIR(xid)
1120 +toku_logsizeof_BYTESTRING(extra)
1121 +toku_logsizeof_bool(is_resetting_op)
1122 +8 // crc + len
1123 );
1124 struct wbuf wbuf;
1125 ml_lock(&logger->input_lock);
1126 toku_logger_make_space_in_inbuf(logger, buflen);
1127 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
1128 wbuf_nocrc_int(&wbuf, buflen);
1129 wbuf_nocrc_char(&wbuf, 'B');
1130 logger->lsn.lsn++;
1131 logger->inbuf.max_lsn_in_buf = logger->lsn;
1132 wbuf_nocrc_LSN(&wbuf, logger->lsn);
1133 if (lsnp) *lsnp=logger->lsn;
1134 wbuf_nocrc_FILENUM(&wbuf, filenum);
1135 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
1136 wbuf_nocrc_BYTESTRING(&wbuf, extra);
1137 wbuf_nocrc_bool(&wbuf, is_resetting_op);
1138 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
1139 wbuf_nocrc_int(&wbuf, buflen);
1140 assert(wbuf.ndone==buflen);
1141 logger->inbuf.n_in_buf += buflen;
1142 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
1143}
1144
1145void toku_log_change_fdescriptor (TOKULOGGER logger, LSN *lsnp, int do_fsync, TOKUTXN txn, FILENUM filenum, TXNID_PAIR xid, BYTESTRING old_descriptor, BYTESTRING new_descriptor, bool update_cmp_descriptor) {
1146 if (logger == NULL) {
1147 return;
1148 }
1149 //txn can be NULL during tests
1150 //never null when not checkpoint.
1151 if (txn && !txn->begin_was_logged) {
1152 invariant(!txn_declared_read_only(txn));
1153 toku_maybe_log_begin_txn_for_write_operation(txn);
1154 }
1155 if (!logger->write_log_files) {
1156 ml_lock(&logger->input_lock);
1157 logger->lsn.lsn++;
1158 if (lsnp) *lsnp=logger->lsn;
1159 ml_unlock(&logger->input_lock);
1160 return;
1161 }
1162 const unsigned int buflen= (+4 // len at the beginning
1163 +1 // log command
1164 +8 // lsn
1165 +toku_logsizeof_FILENUM(filenum)
1166 +toku_logsizeof_TXNID_PAIR(xid)
1167 +toku_logsizeof_BYTESTRING(old_descriptor)
1168 +toku_logsizeof_BYTESTRING(new_descriptor)
1169 +toku_logsizeof_bool(update_cmp_descriptor)
1170 +8 // crc + len
1171 );
1172 struct wbuf wbuf;
1173 ml_lock(&logger->input_lock);
1174 toku_logger_make_space_in_inbuf(logger, buflen);
1175 wbuf_nocrc_init(&wbuf, logger->inbuf.buf+logger->inbuf.n_in_buf, buflen);
1176 wbuf_nocrc_int(&wbuf, buflen);
1177 wbuf_nocrc_char(&wbuf, 'D');
1178 logger->lsn.lsn++;
1179 logger->inbuf.max_lsn_in_buf = logger->lsn;
1180 wbuf_nocrc_LSN(&wbuf, logger->lsn);
1181 if (lsnp) *lsnp=logger->lsn;
1182 wbuf_nocrc_FILENUM(&wbuf, filenum);
1183 wbuf_nocrc_TXNID_PAIR(&wbuf, xid);
1184 wbuf_nocrc_BYTESTRING(&wbuf, old_descriptor);
1185 wbuf_nocrc_BYTESTRING(&wbuf, new_descriptor);
1186 wbuf_nocrc_bool(&wbuf, update_cmp_descriptor);
1187 wbuf_nocrc_int(&wbuf, toku_x1764_memory(wbuf.buf, wbuf.ndone));
1188 wbuf_nocrc_int(&wbuf, buflen);
1189 assert(wbuf.ndone==buflen);
1190 logger->inbuf.n_in_buf += buflen;
1191 toku_logger_maybe_fsync(logger, logger->lsn, do_fsync, true);
1192}
1193
1194static int toku_log_fread_begin_checkpoint (FILE *infile, uint32_t len1, struct logtype_begin_checkpoint *data, struct x1764 *checksum) {
1195 int r=0;
1196 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1197 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1198 r=toku_fread_uint64_t (infile, &data->timestamp , checksum, &actual_len); if (r!=0) return r;
1199 r=toku_fread_TXNID (infile, &data->last_xid , checksum, &actual_len); if (r!=0) return r;
1200 uint32_t checksum_in_file, len_in_file;
1201 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1202 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1203 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1204 return 0;
1205}
1206
1207static int toku_log_fread_end_checkpoint (FILE *infile, uint32_t len1, struct logtype_end_checkpoint *data, struct x1764 *checksum) {
1208 int r=0;
1209 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1210 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1211 r=toku_fread_LSN (infile, &data->lsn_begin_checkpoint, checksum, &actual_len); if (r!=0) return r;
1212 r=toku_fread_uint64_t (infile, &data->timestamp , checksum, &actual_len); if (r!=0) return r;
1213 r=toku_fread_uint32_t (infile, &data->num_fassociate_entries, checksum, &actual_len); if (r!=0) return r;
1214 r=toku_fread_uint32_t (infile, &data->num_xstillopen_entries, checksum, &actual_len); if (r!=0) return r;
1215 uint32_t checksum_in_file, len_in_file;
1216 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1217 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1218 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1219 return 0;
1220}
1221
1222static int toku_log_fread_fassociate (FILE *infile, uint32_t len1, struct logtype_fassociate *data, struct x1764 *checksum) {
1223 int r=0;
1224 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1225 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1226 r=toku_fread_FILENUM (infile, &data->filenum , checksum, &actual_len); if (r!=0) return r;
1227 r=toku_fread_uint32_t (infile, &data->treeflags , checksum, &actual_len); if (r!=0) return r;
1228 r=toku_fread_BYTESTRING (infile, &data->iname , checksum, &actual_len); if (r!=0) return r;
1229 r=toku_fread_uint8_t (infile, &data->unlink_on_close , checksum, &actual_len); if (r!=0) return r;
1230 uint32_t checksum_in_file, len_in_file;
1231 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1232 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1233 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1234 return 0;
1235}
1236
1237static int toku_log_fread_xstillopen (FILE *infile, uint32_t len1, struct logtype_xstillopen *data, struct x1764 *checksum) {
1238 int r=0;
1239 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1240 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1241 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1242 r=toku_fread_TXNID_PAIR (infile, &data->parentxid , checksum, &actual_len); if (r!=0) return r;
1243 r=toku_fread_uint64_t (infile, &data->rollentry_raw_count, checksum, &actual_len); if (r!=0) return r;
1244 r=toku_fread_FILENUMS (infile, &data->open_filenums , checksum, &actual_len); if (r!=0) return r;
1245 r=toku_fread_uint8_t (infile, &data->force_fsync_on_commit, checksum, &actual_len); if (r!=0) return r;
1246 r=toku_fread_uint64_t (infile, &data->num_rollback_nodes, checksum, &actual_len); if (r!=0) return r;
1247 r=toku_fread_uint64_t (infile, &data->num_rollentries , checksum, &actual_len); if (r!=0) return r;
1248 r=toku_fread_BLOCKNUM (infile, &data->spilled_rollback_head, checksum, &actual_len); if (r!=0) return r;
1249 r=toku_fread_BLOCKNUM (infile, &data->spilled_rollback_tail, checksum, &actual_len); if (r!=0) return r;
1250 r=toku_fread_BLOCKNUM (infile, &data->current_rollback, checksum, &actual_len); if (r!=0) return r;
1251 uint32_t checksum_in_file, len_in_file;
1252 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1253 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1254 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1255 return 0;
1256}
1257
1258static int toku_log_fread_xstillopenprepared (FILE *infile, uint32_t len1, struct logtype_xstillopenprepared *data, struct x1764 *checksum) {
1259 int r=0;
1260 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1261 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1262 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1263 r=toku_fread_XIDP (infile, &data->xa_xid , checksum, &actual_len); if (r!=0) return r;
1264 r=toku_fread_uint64_t (infile, &data->rollentry_raw_count, checksum, &actual_len); if (r!=0) return r;
1265 r=toku_fread_FILENUMS (infile, &data->open_filenums , checksum, &actual_len); if (r!=0) return r;
1266 r=toku_fread_uint8_t (infile, &data->force_fsync_on_commit, checksum, &actual_len); if (r!=0) return r;
1267 r=toku_fread_uint64_t (infile, &data->num_rollback_nodes, checksum, &actual_len); if (r!=0) return r;
1268 r=toku_fread_uint64_t (infile, &data->num_rollentries , checksum, &actual_len); if (r!=0) return r;
1269 r=toku_fread_BLOCKNUM (infile, &data->spilled_rollback_head, checksum, &actual_len); if (r!=0) return r;
1270 r=toku_fread_BLOCKNUM (infile, &data->spilled_rollback_tail, checksum, &actual_len); if (r!=0) return r;
1271 r=toku_fread_BLOCKNUM (infile, &data->current_rollback, checksum, &actual_len); if (r!=0) return r;
1272 uint32_t checksum_in_file, len_in_file;
1273 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1274 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1275 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1276 return 0;
1277}
1278
1279static int toku_log_fread_xbegin (FILE *infile, uint32_t len1, struct logtype_xbegin *data, struct x1764 *checksum) {
1280 int r=0;
1281 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1282 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1283 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1284 r=toku_fread_TXNID_PAIR (infile, &data->parentxid , checksum, &actual_len); if (r!=0) return r;
1285 uint32_t checksum_in_file, len_in_file;
1286 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1287 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1288 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1289 return 0;
1290}
1291
1292static int toku_log_fread_xcommit (FILE *infile, uint32_t len1, struct logtype_xcommit *data, struct x1764 *checksum) {
1293 int r=0;
1294 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1295 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1296 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1297 uint32_t checksum_in_file, len_in_file;
1298 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1299 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1300 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1301 return 0;
1302}
1303
1304static int toku_log_fread_xprepare (FILE *infile, uint32_t len1, struct logtype_xprepare *data, struct x1764 *checksum) {
1305 int r=0;
1306 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1307 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1308 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1309 r=toku_fread_XIDP (infile, &data->xa_xid , checksum, &actual_len); if (r!=0) return r;
1310 uint32_t checksum_in_file, len_in_file;
1311 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1312 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1313 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1314 return 0;
1315}
1316
1317static int toku_log_fread_xabort (FILE *infile, uint32_t len1, struct logtype_xabort *data, struct x1764 *checksum) {
1318 int r=0;
1319 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1320 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1321 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1322 uint32_t checksum_in_file, len_in_file;
1323 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1324 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1325 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1326 return 0;
1327}
1328
1329static int toku_log_fread_fcreate (FILE *infile, uint32_t len1, struct logtype_fcreate *data, struct x1764 *checksum) {
1330 int r=0;
1331 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1332 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1333 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1334 r=toku_fread_FILENUM (infile, &data->filenum , checksum, &actual_len); if (r!=0) return r;
1335 r=toku_fread_BYTESTRING (infile, &data->iname , checksum, &actual_len); if (r!=0) return r;
1336 r=toku_fread_uint32_t (infile, &data->mode , checksum, &actual_len); if (r!=0) return r;
1337 r=toku_fread_uint32_t (infile, &data->treeflags , checksum, &actual_len); if (r!=0) return r;
1338 r=toku_fread_uint32_t (infile, &data->nodesize , checksum, &actual_len); if (r!=0) return r;
1339 r=toku_fread_uint32_t (infile, &data->basementnodesize, checksum, &actual_len); if (r!=0) return r;
1340 r=toku_fread_uint32_t (infile, &data->compression_method, checksum, &actual_len); if (r!=0) return r;
1341 uint32_t checksum_in_file, len_in_file;
1342 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1343 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1344 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1345 return 0;
1346}
1347
1348static int toku_log_fread_fopen (FILE *infile, uint32_t len1, struct logtype_fopen *data, struct x1764 *checksum) {
1349 int r=0;
1350 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1351 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1352 r=toku_fread_BYTESTRING (infile, &data->iname , checksum, &actual_len); if (r!=0) return r;
1353 r=toku_fread_FILENUM (infile, &data->filenum , checksum, &actual_len); if (r!=0) return r;
1354 r=toku_fread_uint32_t (infile, &data->treeflags , checksum, &actual_len); if (r!=0) return r;
1355 uint32_t checksum_in_file, len_in_file;
1356 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1357 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1358 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1359 return 0;
1360}
1361
1362static int toku_log_fread_fclose (FILE *infile, uint32_t len1, struct logtype_fclose *data, struct x1764 *checksum) {
1363 int r=0;
1364 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1365 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1366 r=toku_fread_BYTESTRING (infile, &data->iname , checksum, &actual_len); if (r!=0) return r;
1367 r=toku_fread_FILENUM (infile, &data->filenum , checksum, &actual_len); if (r!=0) return r;
1368 uint32_t checksum_in_file, len_in_file;
1369 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1370 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1371 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1372 return 0;
1373}
1374
1375static int toku_log_fread_fdelete (FILE *infile, uint32_t len1, struct logtype_fdelete *data, struct x1764 *checksum) {
1376 int r=0;
1377 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1378 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1379 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1380 r=toku_fread_FILENUM (infile, &data->filenum , checksum, &actual_len); if (r!=0) return r;
1381 uint32_t checksum_in_file, len_in_file;
1382 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1383 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1384 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1385 return 0;
1386}
1387
1388static int toku_log_fread_frename (FILE *infile, uint32_t len1, struct logtype_frename *data, struct x1764 *checksum) {
1389 int r=0;
1390 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1391 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1392 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1393 r=toku_fread_BYTESTRING (infile, &data->old_iname , checksum, &actual_len); if (r!=0) return r;
1394 r=toku_fread_FILENUM (infile, &data->old_filenum , checksum, &actual_len); if (r!=0) return r;
1395 r=toku_fread_BYTESTRING (infile, &data->new_iname , checksum, &actual_len); if (r!=0) return r;
1396 uint32_t checksum_in_file, len_in_file;
1397 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1398 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1399 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1400 return 0;
1401}
1402
1403static int toku_log_fread_enq_insert (FILE *infile, uint32_t len1, struct logtype_enq_insert *data, struct x1764 *checksum) {
1404 int r=0;
1405 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1406 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1407 r=toku_fread_FILENUM (infile, &data->filenum , checksum, &actual_len); if (r!=0) return r;
1408 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1409 r=toku_fread_BYTESTRING (infile, &data->key , checksum, &actual_len); if (r!=0) return r;
1410 r=toku_fread_BYTESTRING (infile, &data->value , checksum, &actual_len); if (r!=0) return r;
1411 uint32_t checksum_in_file, len_in_file;
1412 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1413 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1414 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1415 return 0;
1416}
1417
1418static int toku_log_fread_enq_insert_no_overwrite (FILE *infile, uint32_t len1, struct logtype_enq_insert_no_overwrite *data, struct x1764 *checksum) {
1419 int r=0;
1420 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1421 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1422 r=toku_fread_FILENUM (infile, &data->filenum , checksum, &actual_len); if (r!=0) return r;
1423 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1424 r=toku_fread_BYTESTRING (infile, &data->key , checksum, &actual_len); if (r!=0) return r;
1425 r=toku_fread_BYTESTRING (infile, &data->value , checksum, &actual_len); if (r!=0) return r;
1426 uint32_t checksum_in_file, len_in_file;
1427 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1428 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1429 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1430 return 0;
1431}
1432
1433static int toku_log_fread_enq_delete_any (FILE *infile, uint32_t len1, struct logtype_enq_delete_any *data, struct x1764 *checksum) {
1434 int r=0;
1435 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1436 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1437 r=toku_fread_FILENUM (infile, &data->filenum , checksum, &actual_len); if (r!=0) return r;
1438 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1439 r=toku_fread_BYTESTRING (infile, &data->key , checksum, &actual_len); if (r!=0) return r;
1440 uint32_t checksum_in_file, len_in_file;
1441 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1442 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1443 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1444 return 0;
1445}
1446
1447static int toku_log_fread_enq_insert_multiple (FILE *infile, uint32_t len1, struct logtype_enq_insert_multiple *data, struct x1764 *checksum) {
1448 int r=0;
1449 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1450 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1451 r=toku_fread_FILENUM (infile, &data->src_filenum , checksum, &actual_len); if (r!=0) return r;
1452 r=toku_fread_FILENUMS (infile, &data->dest_filenums , checksum, &actual_len); if (r!=0) return r;
1453 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1454 r=toku_fread_BYTESTRING (infile, &data->src_key , checksum, &actual_len); if (r!=0) return r;
1455 r=toku_fread_BYTESTRING (infile, &data->src_val , checksum, &actual_len); if (r!=0) return r;
1456 uint32_t checksum_in_file, len_in_file;
1457 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1458 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1459 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1460 return 0;
1461}
1462
1463static int toku_log_fread_enq_delete_multiple (FILE *infile, uint32_t len1, struct logtype_enq_delete_multiple *data, struct x1764 *checksum) {
1464 int r=0;
1465 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1466 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1467 r=toku_fread_FILENUM (infile, &data->src_filenum , checksum, &actual_len); if (r!=0) return r;
1468 r=toku_fread_FILENUMS (infile, &data->dest_filenums , checksum, &actual_len); if (r!=0) return r;
1469 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1470 r=toku_fread_BYTESTRING (infile, &data->src_key , checksum, &actual_len); if (r!=0) return r;
1471 r=toku_fread_BYTESTRING (infile, &data->src_val , checksum, &actual_len); if (r!=0) return r;
1472 uint32_t checksum_in_file, len_in_file;
1473 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1474 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1475 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1476 return 0;
1477}
1478
1479static int toku_log_fread_comment (FILE *infile, uint32_t len1, struct logtype_comment *data, struct x1764 *checksum) {
1480 int r=0;
1481 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1482 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1483 r=toku_fread_uint64_t (infile, &data->timestamp , checksum, &actual_len); if (r!=0) return r;
1484 r=toku_fread_BYTESTRING (infile, &data->comment , checksum, &actual_len); if (r!=0) return r;
1485 uint32_t checksum_in_file, len_in_file;
1486 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1487 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1488 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1489 return 0;
1490}
1491
1492static int toku_log_fread_shutdown_up_to_19 (FILE *infile, uint32_t len1, struct logtype_shutdown_up_to_19 *data, struct x1764 *checksum) {
1493 int r=0;
1494 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1495 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1496 r=toku_fread_uint64_t (infile, &data->timestamp , checksum, &actual_len); if (r!=0) return r;
1497 uint32_t checksum_in_file, len_in_file;
1498 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1499 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1500 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1501 return 0;
1502}
1503
1504static int toku_log_fread_shutdown (FILE *infile, uint32_t len1, struct logtype_shutdown *data, struct x1764 *checksum) {
1505 int r=0;
1506 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1507 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1508 r=toku_fread_uint64_t (infile, &data->timestamp , checksum, &actual_len); if (r!=0) return r;
1509 r=toku_fread_TXNID (infile, &data->last_xid , checksum, &actual_len); if (r!=0) return r;
1510 uint32_t checksum_in_file, len_in_file;
1511 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1512 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1513 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1514 return 0;
1515}
1516
1517static int toku_log_fread_load (FILE *infile, uint32_t len1, struct logtype_load *data, struct x1764 *checksum) {
1518 int r=0;
1519 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1520 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1521 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1522 r=toku_fread_FILENUM (infile, &data->old_filenum , checksum, &actual_len); if (r!=0) return r;
1523 r=toku_fread_BYTESTRING (infile, &data->new_iname , checksum, &actual_len); if (r!=0) return r;
1524 uint32_t checksum_in_file, len_in_file;
1525 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1526 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1527 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1528 return 0;
1529}
1530
1531static int toku_log_fread_hot_index (FILE *infile, uint32_t len1, struct logtype_hot_index *data, struct x1764 *checksum) {
1532 int r=0;
1533 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1534 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1535 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1536 r=toku_fread_FILENUMS (infile, &data->hot_index_filenums, checksum, &actual_len); if (r!=0) return r;
1537 uint32_t checksum_in_file, len_in_file;
1538 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1539 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1540 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1541 return 0;
1542}
1543
1544static int toku_log_fread_enq_update (FILE *infile, uint32_t len1, struct logtype_enq_update *data, struct x1764 *checksum) {
1545 int r=0;
1546 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1547 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1548 r=toku_fread_FILENUM (infile, &data->filenum , checksum, &actual_len); if (r!=0) return r;
1549 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1550 r=toku_fread_BYTESTRING (infile, &data->key , checksum, &actual_len); if (r!=0) return r;
1551 r=toku_fread_BYTESTRING (infile, &data->extra , checksum, &actual_len); if (r!=0) return r;
1552 uint32_t checksum_in_file, len_in_file;
1553 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1554 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1555 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1556 return 0;
1557}
1558
1559static int toku_log_fread_enq_updatebroadcast (FILE *infile, uint32_t len1, struct logtype_enq_updatebroadcast *data, struct x1764 *checksum) {
1560 int r=0;
1561 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1562 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1563 r=toku_fread_FILENUM (infile, &data->filenum , checksum, &actual_len); if (r!=0) return r;
1564 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1565 r=toku_fread_BYTESTRING (infile, &data->extra , checksum, &actual_len); if (r!=0) return r;
1566 r=toku_fread_bool (infile, &data->is_resetting_op , checksum, &actual_len); if (r!=0) return r;
1567 uint32_t checksum_in_file, len_in_file;
1568 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1569 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1570 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1571 return 0;
1572}
1573
1574static int toku_log_fread_change_fdescriptor (FILE *infile, uint32_t len1, struct logtype_change_fdescriptor *data, struct x1764 *checksum) {
1575 int r=0;
1576 uint32_t actual_len=5; // 1 for the command, 4 for the first len.
1577 r=toku_fread_LSN (infile, &data->lsn , checksum, &actual_len); if (r!=0) return r;
1578 r=toku_fread_FILENUM (infile, &data->filenum , checksum, &actual_len); if (r!=0) return r;
1579 r=toku_fread_TXNID_PAIR (infile, &data->xid , checksum, &actual_len); if (r!=0) return r;
1580 r=toku_fread_BYTESTRING (infile, &data->old_descriptor , checksum, &actual_len); if (r!=0) return r;
1581 r=toku_fread_BYTESTRING (infile, &data->new_descriptor , checksum, &actual_len); if (r!=0) return r;
1582 r=toku_fread_bool (infile, &data->update_cmp_descriptor, checksum, &actual_len); if (r!=0) return r;
1583 uint32_t checksum_in_file, len_in_file;
1584 r=toku_fread_uint32_t_nocrclen(infile, &checksum_in_file); actual_len+=4; if (r!=0) return r;
1585 r=toku_fread_uint32_t_nocrclen(infile, &len_in_file); actual_len+=4; if (r!=0) return r;
1586 if (checksum_in_file!=toku_x1764_finish(checksum) || len_in_file!=actual_len || len1 != len_in_file) return DB_BADFORMAT;
1587 return 0;
1588}
1589
1590int toku_log_fread (FILE *infile, struct log_entry *le) {
1591 uint32_t len1; int r;
1592 uint32_t ignorelen=0;
1593 struct x1764 checksum;
1594 toku_x1764_init(&checksum);
1595 r = toku_fread_uint32_t(infile, &len1, &checksum, &ignorelen); if (r!=0) return r;
1596 int cmd=fgetc(infile);
1597 if (cmd==EOF) return EOF;
1598 char cmdchar = (char)cmd;
1599 toku_x1764_add(&checksum, &cmdchar, 1);
1600 le->cmd=(enum lt_cmd)cmd;
1601 switch ((enum lt_cmd)cmd) {
1602 case LT_begin_checkpoint:
1603 return toku_log_fread_begin_checkpoint (infile, len1, &le->u.begin_checkpoint, &checksum);
1604 case LT_end_checkpoint:
1605 return toku_log_fread_end_checkpoint (infile, len1, &le->u.end_checkpoint, &checksum);
1606 case LT_fassociate:
1607 return toku_log_fread_fassociate (infile, len1, &le->u.fassociate, &checksum);
1608 case LT_xstillopen:
1609 return toku_log_fread_xstillopen (infile, len1, &le->u.xstillopen, &checksum);
1610 case LT_xstillopenprepared:
1611 return toku_log_fread_xstillopenprepared (infile, len1, &le->u.xstillopenprepared, &checksum);
1612 case LT_xbegin:
1613 return toku_log_fread_xbegin (infile, len1, &le->u.xbegin, &checksum);
1614 case LT_xcommit:
1615 return toku_log_fread_xcommit (infile, len1, &le->u.xcommit, &checksum);
1616 case LT_xprepare:
1617 return toku_log_fread_xprepare (infile, len1, &le->u.xprepare, &checksum);
1618 case LT_xabort:
1619 return toku_log_fread_xabort (infile, len1, &le->u.xabort, &checksum);
1620 case LT_fcreate:
1621 return toku_log_fread_fcreate (infile, len1, &le->u.fcreate, &checksum);
1622 case LT_fopen:
1623 return toku_log_fread_fopen (infile, len1, &le->u.fopen, &checksum);
1624 case LT_fclose:
1625 return toku_log_fread_fclose (infile, len1, &le->u.fclose, &checksum);
1626 case LT_fdelete:
1627 return toku_log_fread_fdelete (infile, len1, &le->u.fdelete, &checksum);
1628 case LT_frename:
1629 return toku_log_fread_frename (infile, len1, &le->u.frename, &checksum);
1630 case LT_enq_insert:
1631 return toku_log_fread_enq_insert (infile, len1, &le->u.enq_insert, &checksum);
1632 case LT_enq_insert_no_overwrite:
1633 return toku_log_fread_enq_insert_no_overwrite (infile, len1, &le->u.enq_insert_no_overwrite, &checksum);
1634 case LT_enq_delete_any:
1635 return toku_log_fread_enq_delete_any (infile, len1, &le->u.enq_delete_any, &checksum);
1636 case LT_enq_insert_multiple:
1637 return toku_log_fread_enq_insert_multiple (infile, len1, &le->u.enq_insert_multiple, &checksum);
1638 case LT_enq_delete_multiple:
1639 return toku_log_fread_enq_delete_multiple (infile, len1, &le->u.enq_delete_multiple, &checksum);
1640 case LT_comment:
1641 return toku_log_fread_comment (infile, len1, &le->u.comment, &checksum);
1642 case LT_shutdown_up_to_19:
1643 return toku_log_fread_shutdown_up_to_19 (infile, len1, &le->u.shutdown_up_to_19, &checksum);
1644 case LT_shutdown:
1645 return toku_log_fread_shutdown (infile, len1, &le->u.shutdown, &checksum);
1646 case LT_load:
1647 return toku_log_fread_load (infile, len1, &le->u.load, &checksum);
1648 case LT_hot_index:
1649 return toku_log_fread_hot_index (infile, len1, &le->u.hot_index, &checksum);
1650 case LT_enq_update:
1651 return toku_log_fread_enq_update (infile, len1, &le->u.enq_update, &checksum);
1652 case LT_enq_updatebroadcast:
1653 return toku_log_fread_enq_updatebroadcast (infile, len1, &le->u.enq_updatebroadcast, &checksum);
1654 case LT_change_fdescriptor:
1655 return toku_log_fread_change_fdescriptor (infile, len1, &le->u.change_fdescriptor, &checksum);
1656 };
1657 return DB_BADFORMAT;
1658}
1659
1660// Return 0 if there is something to read, -1 if nothing to read, >0 on error
1661int toku_log_fread_backward (FILE *infile, struct log_entry *le){
1662 memset(le, 0, sizeof(*le));
1663 long pos = ftell(infile);
1664 if (pos<=12) return -1;
1665 int r = fseek(infile, -4, SEEK_CUR);
1666 if (r!=0) return get_error_errno();
1667 uint32_t len;
1668 r = toku_fread_uint32_t_nocrclen(infile, &len);
1669 if (r!=0) return 1;
1670 r = fseek(infile, -(int)len, SEEK_CUR) ;
1671 if (r!=0) return get_error_errno();
1672 r = toku_log_fread(infile, le);
1673 if (r!=0) return 1;
1674 long afterpos = ftell(infile);
1675 if (afterpos != pos) return 1;
1676 r = fseek(infile, -(int)len, SEEK_CUR);
1677 if (r!=0) return get_error_errno();
1678 return 0;
1679}
1680
1681static void toku_log_free_log_entry_begin_checkpoint_resources (struct logtype_begin_checkpoint *data) {
1682 toku_free_uint64_t(data->timestamp);
1683 toku_free_TXNID(data->last_xid);
1684}
1685
1686static void toku_log_free_log_entry_end_checkpoint_resources (struct logtype_end_checkpoint *data) {
1687 toku_free_LSN(data->lsn_begin_checkpoint);
1688 toku_free_uint64_t(data->timestamp);
1689 toku_free_uint32_t(data->num_fassociate_entries);
1690 toku_free_uint32_t(data->num_xstillopen_entries);
1691}
1692
1693static void toku_log_free_log_entry_fassociate_resources (struct logtype_fassociate *data) {
1694 toku_free_FILENUM(data->filenum);
1695 toku_free_uint32_t(data->treeflags);
1696 toku_free_BYTESTRING(data->iname);
1697 toku_free_uint8_t(data->unlink_on_close);
1698}
1699
1700static void toku_log_free_log_entry_xstillopen_resources (struct logtype_xstillopen *data) {
1701 toku_free_TXNID_PAIR(data->xid);
1702 toku_free_TXNID_PAIR(data->parentxid);
1703 toku_free_uint64_t(data->rollentry_raw_count);
1704 toku_free_FILENUMS(data->open_filenums);
1705 toku_free_uint8_t(data->force_fsync_on_commit);
1706 toku_free_uint64_t(data->num_rollback_nodes);
1707 toku_free_uint64_t(data->num_rollentries);
1708 toku_free_BLOCKNUM(data->spilled_rollback_head);
1709 toku_free_BLOCKNUM(data->spilled_rollback_tail);
1710 toku_free_BLOCKNUM(data->current_rollback);
1711}
1712
1713static void toku_log_free_log_entry_xstillopenprepared_resources (struct logtype_xstillopenprepared *data) {
1714 toku_free_TXNID_PAIR(data->xid);
1715 toku_free_XIDP(data->xa_xid);
1716 toku_free_uint64_t(data->rollentry_raw_count);
1717 toku_free_FILENUMS(data->open_filenums);
1718 toku_free_uint8_t(data->force_fsync_on_commit);
1719 toku_free_uint64_t(data->num_rollback_nodes);
1720 toku_free_uint64_t(data->num_rollentries);
1721 toku_free_BLOCKNUM(data->spilled_rollback_head);
1722 toku_free_BLOCKNUM(data->spilled_rollback_tail);
1723 toku_free_BLOCKNUM(data->current_rollback);
1724}
1725
1726static void toku_log_free_log_entry_xbegin_resources (struct logtype_xbegin *data) {
1727 toku_free_TXNID_PAIR(data->xid);
1728 toku_free_TXNID_PAIR(data->parentxid);
1729}
1730
1731static void toku_log_free_log_entry_xcommit_resources (struct logtype_xcommit *data) {
1732 toku_free_TXNID_PAIR(data->xid);
1733}
1734
1735static void toku_log_free_log_entry_xprepare_resources (struct logtype_xprepare *data) {
1736 toku_free_TXNID_PAIR(data->xid);
1737 toku_free_XIDP(data->xa_xid);
1738}
1739
1740static void toku_log_free_log_entry_xabort_resources (struct logtype_xabort *data) {
1741 toku_free_TXNID_PAIR(data->xid);
1742}
1743
1744static void toku_log_free_log_entry_fcreate_resources (struct logtype_fcreate *data) {
1745 toku_free_TXNID_PAIR(data->xid);
1746 toku_free_FILENUM(data->filenum);
1747 toku_free_BYTESTRING(data->iname);
1748 toku_free_uint32_t(data->mode);
1749 toku_free_uint32_t(data->treeflags);
1750 toku_free_uint32_t(data->nodesize);
1751 toku_free_uint32_t(data->basementnodesize);
1752 toku_free_uint32_t(data->compression_method);
1753}
1754
1755static void toku_log_free_log_entry_fopen_resources (struct logtype_fopen *data) {
1756 toku_free_BYTESTRING(data->iname);
1757 toku_free_FILENUM(data->filenum);
1758 toku_free_uint32_t(data->treeflags);
1759}
1760
1761static void toku_log_free_log_entry_fclose_resources (struct logtype_fclose *data) {
1762 toku_free_BYTESTRING(data->iname);
1763 toku_free_FILENUM(data->filenum);
1764}
1765
1766static void toku_log_free_log_entry_fdelete_resources (struct logtype_fdelete *data) {
1767 toku_free_TXNID_PAIR(data->xid);
1768 toku_free_FILENUM(data->filenum);
1769}
1770
1771static void toku_log_free_log_entry_frename_resources (struct logtype_frename *data) {
1772 toku_free_TXNID_PAIR(data->xid);
1773 toku_free_BYTESTRING(data->old_iname);
1774 toku_free_FILENUM(data->old_filenum);
1775 toku_free_BYTESTRING(data->new_iname);
1776}
1777
1778static void toku_log_free_log_entry_enq_insert_resources (struct logtype_enq_insert *data) {
1779 toku_free_FILENUM(data->filenum);
1780 toku_free_TXNID_PAIR(data->xid);
1781 toku_free_BYTESTRING(data->key);
1782 toku_free_BYTESTRING(data->value);
1783}
1784
1785static void toku_log_free_log_entry_enq_insert_no_overwrite_resources (struct logtype_enq_insert_no_overwrite *data) {
1786 toku_free_FILENUM(data->filenum);
1787 toku_free_TXNID_PAIR(data->xid);
1788 toku_free_BYTESTRING(data->key);
1789 toku_free_BYTESTRING(data->value);
1790}
1791
1792static void toku_log_free_log_entry_enq_delete_any_resources (struct logtype_enq_delete_any *data) {
1793 toku_free_FILENUM(data->filenum);
1794 toku_free_TXNID_PAIR(data->xid);
1795 toku_free_BYTESTRING(data->key);
1796}
1797
1798static void toku_log_free_log_entry_enq_insert_multiple_resources (struct logtype_enq_insert_multiple *data) {
1799 toku_free_FILENUM(data->src_filenum);
1800 toku_free_FILENUMS(data->dest_filenums);
1801 toku_free_TXNID_PAIR(data->xid);
1802 toku_free_BYTESTRING(data->src_key);
1803 toku_free_BYTESTRING(data->src_val);
1804}
1805
1806static void toku_log_free_log_entry_enq_delete_multiple_resources (struct logtype_enq_delete_multiple *data) {
1807 toku_free_FILENUM(data->src_filenum);
1808 toku_free_FILENUMS(data->dest_filenums);
1809 toku_free_TXNID_PAIR(data->xid);
1810 toku_free_BYTESTRING(data->src_key);
1811 toku_free_BYTESTRING(data->src_val);
1812}
1813
1814static void toku_log_free_log_entry_comment_resources (struct logtype_comment *data) {
1815 toku_free_uint64_t(data->timestamp);
1816 toku_free_BYTESTRING(data->comment);
1817}
1818
1819static void toku_log_free_log_entry_shutdown_up_to_19_resources (struct logtype_shutdown_up_to_19 *data) {
1820 toku_free_uint64_t(data->timestamp);
1821}
1822
1823static void toku_log_free_log_entry_shutdown_resources (struct logtype_shutdown *data) {
1824 toku_free_uint64_t(data->timestamp);
1825 toku_free_TXNID(data->last_xid);
1826}
1827
1828static void toku_log_free_log_entry_load_resources (struct logtype_load *data) {
1829 toku_free_TXNID_PAIR(data->xid);
1830 toku_free_FILENUM(data->old_filenum);
1831 toku_free_BYTESTRING(data->new_iname);
1832}
1833
1834static void toku_log_free_log_entry_hot_index_resources (struct logtype_hot_index *data) {
1835 toku_free_TXNID_PAIR(data->xid);
1836 toku_free_FILENUMS(data->hot_index_filenums);
1837}
1838
1839static void toku_log_free_log_entry_enq_update_resources (struct logtype_enq_update *data) {
1840 toku_free_FILENUM(data->filenum);
1841 toku_free_TXNID_PAIR(data->xid);
1842 toku_free_BYTESTRING(data->key);
1843 toku_free_BYTESTRING(data->extra);
1844}
1845
1846static void toku_log_free_log_entry_enq_updatebroadcast_resources (struct logtype_enq_updatebroadcast *data) {
1847 toku_free_FILENUM(data->filenum);
1848 toku_free_TXNID_PAIR(data->xid);
1849 toku_free_BYTESTRING(data->extra);
1850 toku_free_bool(data->is_resetting_op);
1851}
1852
1853static void toku_log_free_log_entry_change_fdescriptor_resources (struct logtype_change_fdescriptor *data) {
1854 toku_free_FILENUM(data->filenum);
1855 toku_free_TXNID_PAIR(data->xid);
1856 toku_free_BYTESTRING(data->old_descriptor);
1857 toku_free_BYTESTRING(data->new_descriptor);
1858 toku_free_bool(data->update_cmp_descriptor);
1859}
1860
1861void toku_log_free_log_entry_resources (struct log_entry *le) {
1862 switch ((enum lt_cmd)le->cmd) {
1863 case LT_begin_checkpoint:
1864 return toku_log_free_log_entry_begin_checkpoint_resources (&(le->u.begin_checkpoint));
1865 case LT_end_checkpoint:
1866 return toku_log_free_log_entry_end_checkpoint_resources (&(le->u.end_checkpoint));
1867 case LT_fassociate:
1868 return toku_log_free_log_entry_fassociate_resources (&(le->u.fassociate));
1869 case LT_xstillopen:
1870 return toku_log_free_log_entry_xstillopen_resources (&(le->u.xstillopen));
1871 case LT_xstillopenprepared:
1872 return toku_log_free_log_entry_xstillopenprepared_resources (&(le->u.xstillopenprepared));
1873 case LT_xbegin:
1874 return toku_log_free_log_entry_xbegin_resources (&(le->u.xbegin));
1875 case LT_xcommit:
1876 return toku_log_free_log_entry_xcommit_resources (&(le->u.xcommit));
1877 case LT_xprepare:
1878 return toku_log_free_log_entry_xprepare_resources (&(le->u.xprepare));
1879 case LT_xabort:
1880 return toku_log_free_log_entry_xabort_resources (&(le->u.xabort));
1881 case LT_fcreate:
1882 return toku_log_free_log_entry_fcreate_resources (&(le->u.fcreate));
1883 case LT_fopen:
1884 return toku_log_free_log_entry_fopen_resources (&(le->u.fopen));
1885 case LT_fclose:
1886 return toku_log_free_log_entry_fclose_resources (&(le->u.fclose));
1887 case LT_fdelete:
1888 return toku_log_free_log_entry_fdelete_resources (&(le->u.fdelete));
1889 case LT_frename:
1890 return toku_log_free_log_entry_frename_resources (&(le->u.frename));
1891 case LT_enq_insert:
1892 return toku_log_free_log_entry_enq_insert_resources (&(le->u.enq_insert));
1893 case LT_enq_insert_no_overwrite:
1894 return toku_log_free_log_entry_enq_insert_no_overwrite_resources (&(le->u.enq_insert_no_overwrite));
1895 case LT_enq_delete_any:
1896 return toku_log_free_log_entry_enq_delete_any_resources (&(le->u.enq_delete_any));
1897 case LT_enq_insert_multiple:
1898 return toku_log_free_log_entry_enq_insert_multiple_resources (&(le->u.enq_insert_multiple));
1899 case LT_enq_delete_multiple:
1900 return toku_log_free_log_entry_enq_delete_multiple_resources (&(le->u.enq_delete_multiple));
1901 case LT_comment:
1902 return toku_log_free_log_entry_comment_resources (&(le->u.comment));
1903 case LT_shutdown_up_to_19:
1904 return toku_log_free_log_entry_shutdown_up_to_19_resources (&(le->u.shutdown_up_to_19));
1905 case LT_shutdown:
1906 return toku_log_free_log_entry_shutdown_resources (&(le->u.shutdown));
1907 case LT_load:
1908 return toku_log_free_log_entry_load_resources (&(le->u.load));
1909 case LT_hot_index:
1910 return toku_log_free_log_entry_hot_index_resources (&(le->u.hot_index));
1911 case LT_enq_update:
1912 return toku_log_free_log_entry_enq_update_resources (&(le->u.enq_update));
1913 case LT_enq_updatebroadcast:
1914 return toku_log_free_log_entry_enq_updatebroadcast_resources (&(le->u.enq_updatebroadcast));
1915 case LT_change_fdescriptor:
1916 return toku_log_free_log_entry_change_fdescriptor_resources (&(le->u.change_fdescriptor));
1917 };
1918 return;
1919}
1920
1921void toku_logger_save_rollback_fdelete (TOKUTXN txn, FILENUM filenum) {
1922 toku_txn_lock(txn);
1923 ROLLBACK_LOG_NODE log;
1924 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
1925 uint32_t rollback_fsize = toku_logger_rollback_fsize_fdelete(filenum);
1926 struct roll_entry *v;
1927 size_t mem_needed = sizeof(v->u.fdelete) + __builtin_offsetof(struct roll_entry, u.fdelete);
1928 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
1929 assert(v);
1930 v->cmd = (enum rt_cmd)85;
1931 v->u.fdelete.filenum = filenum;
1932 v->prev = log->newest_logentry;
1933 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
1934 log->newest_logentry = v;
1935 log->rollentry_resident_bytecount += rollback_fsize;
1936 txn->roll_info.rollentry_raw_count += rollback_fsize;
1937 txn->roll_info.num_rollentries++;
1938 log->dirty = true;
1939 // spill and unpin assert success internally
1940 toku_maybe_spill_rollbacks(txn, log);
1941 toku_rollback_log_unpin(txn, log);
1942 toku_txn_unlock(txn);
1943}
1944void toku_logger_save_rollback_fcreate (TOKUTXN txn, FILENUM filenum, BYTESTRING *iname_ptr) {
1945 toku_txn_lock(txn);
1946 ROLLBACK_LOG_NODE log;
1947 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
1948 BYTESTRING iname = {
1949 .len = iname_ptr->len,
1950 .data = cast_to_typeof(iname.data) toku_memdup_in_rollback(log, iname_ptr->data, iname_ptr->len)
1951 };
1952 uint32_t rollback_fsize = toku_logger_rollback_fsize_fcreate(filenum, iname);
1953 struct roll_entry *v;
1954 size_t mem_needed = sizeof(v->u.fcreate) + __builtin_offsetof(struct roll_entry, u.fcreate);
1955 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
1956 assert(v);
1957 v->cmd = (enum rt_cmd)70;
1958 v->u.fcreate.filenum = filenum;
1959 v->u.fcreate.iname = iname;
1960 v->prev = log->newest_logentry;
1961 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
1962 log->newest_logentry = v;
1963 log->rollentry_resident_bytecount += rollback_fsize;
1964 txn->roll_info.rollentry_raw_count += rollback_fsize;
1965 txn->roll_info.num_rollentries++;
1966 log->dirty = true;
1967 // spill and unpin assert success internally
1968 toku_maybe_spill_rollbacks(txn, log);
1969 toku_rollback_log_unpin(txn, log);
1970 toku_txn_unlock(txn);
1971}
1972void toku_logger_save_rollback_frename (TOKUTXN txn, BYTESTRING *old_iname_ptr, BYTESTRING *new_iname_ptr) {
1973 toku_txn_lock(txn);
1974 ROLLBACK_LOG_NODE log;
1975 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
1976 BYTESTRING old_iname = {
1977 .len = old_iname_ptr->len,
1978 .data = cast_to_typeof(old_iname.data) toku_memdup_in_rollback(log, old_iname_ptr->data, old_iname_ptr->len)
1979 };
1980 BYTESTRING new_iname = {
1981 .len = new_iname_ptr->len,
1982 .data = cast_to_typeof(new_iname.data) toku_memdup_in_rollback(log, new_iname_ptr->data, new_iname_ptr->len)
1983 };
1984 uint32_t rollback_fsize = toku_logger_rollback_fsize_frename(old_iname, new_iname);
1985 struct roll_entry *v;
1986 size_t mem_needed = sizeof(v->u.frename) + __builtin_offsetof(struct roll_entry, u.frename);
1987 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
1988 assert(v);
1989 v->cmd = (enum rt_cmd)110;
1990 v->u.frename.old_iname = old_iname;
1991 v->u.frename.new_iname = new_iname;
1992 v->prev = log->newest_logentry;
1993 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
1994 log->newest_logentry = v;
1995 log->rollentry_resident_bytecount += rollback_fsize;
1996 txn->roll_info.rollentry_raw_count += rollback_fsize;
1997 txn->roll_info.num_rollentries++;
1998 log->dirty = true;
1999 // spill and unpin assert success internally
2000 toku_maybe_spill_rollbacks(txn, log);
2001 toku_rollback_log_unpin(txn, log);
2002 toku_txn_unlock(txn);
2003}
2004void toku_logger_save_rollback_cmdinsert (TOKUTXN txn, FILENUM filenum, BYTESTRING *key_ptr) {
2005 toku_txn_lock(txn);
2006 ROLLBACK_LOG_NODE log;
2007 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
2008 BYTESTRING key = {
2009 .len = key_ptr->len,
2010 .data = cast_to_typeof(key.data) toku_memdup_in_rollback(log, key_ptr->data, key_ptr->len)
2011 };
2012 uint32_t rollback_fsize = toku_logger_rollback_fsize_cmdinsert(filenum, key);
2013 struct roll_entry *v;
2014 size_t mem_needed = sizeof(v->u.cmdinsert) + __builtin_offsetof(struct roll_entry, u.cmdinsert);
2015 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
2016 assert(v);
2017 v->cmd = (enum rt_cmd)105;
2018 v->u.cmdinsert.filenum = filenum;
2019 v->u.cmdinsert.key = key;
2020 v->prev = log->newest_logentry;
2021 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
2022 log->newest_logentry = v;
2023 log->rollentry_resident_bytecount += rollback_fsize;
2024 txn->roll_info.rollentry_raw_count += rollback_fsize;
2025 txn->roll_info.num_rollentries++;
2026 log->dirty = true;
2027 // spill and unpin assert success internally
2028 toku_maybe_spill_rollbacks(txn, log);
2029 toku_rollback_log_unpin(txn, log);
2030 toku_txn_unlock(txn);
2031}
2032void toku_logger_save_rollback_cmddelete (TOKUTXN txn, FILENUM filenum, BYTESTRING *key_ptr) {
2033 toku_txn_lock(txn);
2034 ROLLBACK_LOG_NODE log;
2035 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
2036 BYTESTRING key = {
2037 .len = key_ptr->len,
2038 .data = cast_to_typeof(key.data) toku_memdup_in_rollback(log, key_ptr->data, key_ptr->len)
2039 };
2040 uint32_t rollback_fsize = toku_logger_rollback_fsize_cmddelete(filenum, key);
2041 struct roll_entry *v;
2042 size_t mem_needed = sizeof(v->u.cmddelete) + __builtin_offsetof(struct roll_entry, u.cmddelete);
2043 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
2044 assert(v);
2045 v->cmd = (enum rt_cmd)100;
2046 v->u.cmddelete.filenum = filenum;
2047 v->u.cmddelete.key = key;
2048 v->prev = log->newest_logentry;
2049 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
2050 log->newest_logentry = v;
2051 log->rollentry_resident_bytecount += rollback_fsize;
2052 txn->roll_info.rollentry_raw_count += rollback_fsize;
2053 txn->roll_info.num_rollentries++;
2054 log->dirty = true;
2055 // spill and unpin assert success internally
2056 toku_maybe_spill_rollbacks(txn, log);
2057 toku_rollback_log_unpin(txn, log);
2058 toku_txn_unlock(txn);
2059}
2060void toku_logger_save_rollback_rollinclude (TOKUTXN txn, TXNID_PAIR xid, uint64_t num_nodes, BLOCKNUM spilled_head, BLOCKNUM spilled_tail) {
2061 toku_txn_lock(txn);
2062 ROLLBACK_LOG_NODE log;
2063 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
2064 uint32_t rollback_fsize = toku_logger_rollback_fsize_rollinclude(xid, num_nodes, spilled_head, spilled_tail);
2065 struct roll_entry *v;
2066 size_t mem_needed = sizeof(v->u.rollinclude) + __builtin_offsetof(struct roll_entry, u.rollinclude);
2067 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
2068 assert(v);
2069 v->cmd = (enum rt_cmd)114;
2070 v->u.rollinclude.xid = xid;
2071 v->u.rollinclude.num_nodes = num_nodes;
2072 v->u.rollinclude.spilled_head = spilled_head;
2073 v->u.rollinclude.spilled_tail = spilled_tail;
2074 v->prev = log->newest_logentry;
2075 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
2076 log->newest_logentry = v;
2077 log->rollentry_resident_bytecount += rollback_fsize;
2078 txn->roll_info.rollentry_raw_count += rollback_fsize;
2079 txn->roll_info.num_rollentries++;
2080 log->dirty = true;
2081 // spill and unpin assert success internally
2082 toku_maybe_spill_rollbacks(txn, log);
2083 toku_rollback_log_unpin(txn, log);
2084 toku_txn_unlock(txn);
2085}
2086void toku_logger_save_rollback_load (TOKUTXN txn, FILENUM old_filenum, BYTESTRING *new_iname_ptr) {
2087 toku_txn_lock(txn);
2088 ROLLBACK_LOG_NODE log;
2089 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
2090 BYTESTRING new_iname = {
2091 .len = new_iname_ptr->len,
2092 .data = cast_to_typeof(new_iname.data) toku_memdup_in_rollback(log, new_iname_ptr->data, new_iname_ptr->len)
2093 };
2094 uint32_t rollback_fsize = toku_logger_rollback_fsize_load(old_filenum, new_iname);
2095 struct roll_entry *v;
2096 size_t mem_needed = sizeof(v->u.load) + __builtin_offsetof(struct roll_entry, u.load);
2097 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
2098 assert(v);
2099 v->cmd = (enum rt_cmd)108;
2100 v->u.load.old_filenum = old_filenum;
2101 v->u.load.new_iname = new_iname;
2102 v->prev = log->newest_logentry;
2103 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
2104 log->newest_logentry = v;
2105 log->rollentry_resident_bytecount += rollback_fsize;
2106 txn->roll_info.rollentry_raw_count += rollback_fsize;
2107 txn->roll_info.num_rollentries++;
2108 log->dirty = true;
2109 // spill and unpin assert success internally
2110 toku_maybe_spill_rollbacks(txn, log);
2111 toku_rollback_log_unpin(txn, log);
2112 toku_txn_unlock(txn);
2113}
2114void toku_logger_save_rollback_hot_index (TOKUTXN txn, FILENUMS *hot_index_filenums_ptr) {
2115 toku_txn_lock(txn);
2116 ROLLBACK_LOG_NODE log;
2117 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
2118 FILENUMS hot_index_filenums = {
2119 .num = hot_index_filenums_ptr->num,
2120 .filenums = cast_to_typeof(hot_index_filenums.filenums) toku_memdup_in_rollback(log, hot_index_filenums_ptr->filenums, hot_index_filenums_ptr->num * (sizeof (FILENUM)))
2121 };
2122 uint32_t rollback_fsize = toku_logger_rollback_fsize_hot_index(hot_index_filenums);
2123 struct roll_entry *v;
2124 size_t mem_needed = sizeof(v->u.hot_index) + __builtin_offsetof(struct roll_entry, u.hot_index);
2125 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
2126 assert(v);
2127 v->cmd = (enum rt_cmd)104;
2128 v->u.hot_index.hot_index_filenums = hot_index_filenums;
2129 v->prev = log->newest_logentry;
2130 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
2131 log->newest_logentry = v;
2132 log->rollentry_resident_bytecount += rollback_fsize;
2133 txn->roll_info.rollentry_raw_count += rollback_fsize;
2134 txn->roll_info.num_rollentries++;
2135 log->dirty = true;
2136 // spill and unpin assert success internally
2137 toku_maybe_spill_rollbacks(txn, log);
2138 toku_rollback_log_unpin(txn, log);
2139 toku_txn_unlock(txn);
2140}
2141void toku_logger_save_rollback_dictionary_redirect (TOKUTXN txn, FILENUM old_filenum, FILENUM new_filenum) {
2142 toku_txn_lock(txn);
2143 ROLLBACK_LOG_NODE log;
2144 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
2145 uint32_t rollback_fsize = toku_logger_rollback_fsize_dictionary_redirect(old_filenum, new_filenum);
2146 struct roll_entry *v;
2147 size_t mem_needed = sizeof(v->u.dictionary_redirect) + __builtin_offsetof(struct roll_entry, u.dictionary_redirect);
2148 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
2149 assert(v);
2150 v->cmd = (enum rt_cmd)82;
2151 v->u.dictionary_redirect.old_filenum = old_filenum;
2152 v->u.dictionary_redirect.new_filenum = new_filenum;
2153 v->prev = log->newest_logentry;
2154 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
2155 log->newest_logentry = v;
2156 log->rollentry_resident_bytecount += rollback_fsize;
2157 txn->roll_info.rollentry_raw_count += rollback_fsize;
2158 txn->roll_info.num_rollentries++;
2159 log->dirty = true;
2160 // spill and unpin assert success internally
2161 toku_maybe_spill_rollbacks(txn, log);
2162 toku_rollback_log_unpin(txn, log);
2163 toku_txn_unlock(txn);
2164}
2165void toku_logger_save_rollback_cmdupdate (TOKUTXN txn, FILENUM filenum, BYTESTRING *key_ptr) {
2166 toku_txn_lock(txn);
2167 ROLLBACK_LOG_NODE log;
2168 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
2169 BYTESTRING key = {
2170 .len = key_ptr->len,
2171 .data = cast_to_typeof(key.data) toku_memdup_in_rollback(log, key_ptr->data, key_ptr->len)
2172 };
2173 uint32_t rollback_fsize = toku_logger_rollback_fsize_cmdupdate(filenum, key);
2174 struct roll_entry *v;
2175 size_t mem_needed = sizeof(v->u.cmdupdate) + __builtin_offsetof(struct roll_entry, u.cmdupdate);
2176 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
2177 assert(v);
2178 v->cmd = (enum rt_cmd)117;
2179 v->u.cmdupdate.filenum = filenum;
2180 v->u.cmdupdate.key = key;
2181 v->prev = log->newest_logentry;
2182 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
2183 log->newest_logentry = v;
2184 log->rollentry_resident_bytecount += rollback_fsize;
2185 txn->roll_info.rollentry_raw_count += rollback_fsize;
2186 txn->roll_info.num_rollentries++;
2187 log->dirty = true;
2188 // spill and unpin assert success internally
2189 toku_maybe_spill_rollbacks(txn, log);
2190 toku_rollback_log_unpin(txn, log);
2191 toku_txn_unlock(txn);
2192}
2193void toku_logger_save_rollback_cmdupdatebroadcast (TOKUTXN txn, FILENUM filenum, bool is_resetting_op) {
2194 toku_txn_lock(txn);
2195 ROLLBACK_LOG_NODE log;
2196 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
2197 uint32_t rollback_fsize = toku_logger_rollback_fsize_cmdupdatebroadcast(filenum, is_resetting_op);
2198 struct roll_entry *v;
2199 size_t mem_needed = sizeof(v->u.cmdupdatebroadcast) + __builtin_offsetof(struct roll_entry, u.cmdupdatebroadcast);
2200 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
2201 assert(v);
2202 v->cmd = (enum rt_cmd)66;
2203 v->u.cmdupdatebroadcast.filenum = filenum;
2204 v->u.cmdupdatebroadcast.is_resetting_op = is_resetting_op;
2205 v->prev = log->newest_logentry;
2206 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
2207 log->newest_logentry = v;
2208 log->rollentry_resident_bytecount += rollback_fsize;
2209 txn->roll_info.rollentry_raw_count += rollback_fsize;
2210 txn->roll_info.num_rollentries++;
2211 log->dirty = true;
2212 // spill and unpin assert success internally
2213 toku_maybe_spill_rollbacks(txn, log);
2214 toku_rollback_log_unpin(txn, log);
2215 toku_txn_unlock(txn);
2216}
2217void toku_logger_save_rollback_change_fdescriptor (TOKUTXN txn, FILENUM filenum, BYTESTRING *old_descriptor_ptr) {
2218 toku_txn_lock(txn);
2219 ROLLBACK_LOG_NODE log;
2220 toku_get_and_pin_rollback_log_for_new_entry(txn, &log);
2221 BYTESTRING old_descriptor = {
2222 .len = old_descriptor_ptr->len,
2223 .data = cast_to_typeof(old_descriptor.data) toku_memdup_in_rollback(log, old_descriptor_ptr->data, old_descriptor_ptr->len)
2224 };
2225 uint32_t rollback_fsize = toku_logger_rollback_fsize_change_fdescriptor(filenum, old_descriptor);
2226 struct roll_entry *v;
2227 size_t mem_needed = sizeof(v->u.change_fdescriptor) + __builtin_offsetof(struct roll_entry, u.change_fdescriptor);
2228 CAST_FROM_VOIDP(v, toku_malloc_in_rollback(log, mem_needed));
2229 assert(v);
2230 v->cmd = (enum rt_cmd)68;
2231 v->u.change_fdescriptor.filenum = filenum;
2232 v->u.change_fdescriptor.old_descriptor = old_descriptor;
2233 v->prev = log->newest_logentry;
2234 if (log->oldest_logentry==NULL) log->oldest_logentry=v;
2235 log->newest_logentry = v;
2236 log->rollentry_resident_bytecount += rollback_fsize;
2237 txn->roll_info.rollentry_raw_count += rollback_fsize;
2238 txn->roll_info.num_rollentries++;
2239 log->dirty = true;
2240 // spill and unpin assert success internally
2241 toku_maybe_spill_rollbacks(txn, log);
2242 toku_rollback_log_unpin(txn, log);
2243 toku_txn_unlock(txn);
2244}
2245void toku_logger_rollback_wbuf_nocrc_write_fdelete (struct wbuf *wbuf, FILENUM filenum) {
2246 uint32_t rollback_fsize = toku_logger_rollback_fsize_fdelete(filenum);
2247 wbuf_nocrc_int(wbuf, rollback_fsize);
2248 wbuf_nocrc_char(wbuf, 'U');
2249 wbuf_nocrc_FILENUM(wbuf, filenum);
2250}
2251void toku_logger_rollback_wbuf_nocrc_write_fcreate (struct wbuf *wbuf, FILENUM filenum, BYTESTRING iname) {
2252 uint32_t rollback_fsize = toku_logger_rollback_fsize_fcreate(filenum, iname);
2253 wbuf_nocrc_int(wbuf, rollback_fsize);
2254 wbuf_nocrc_char(wbuf, 'F');
2255 wbuf_nocrc_FILENUM(wbuf, filenum);
2256 wbuf_nocrc_BYTESTRING(wbuf, iname);
2257}
2258void toku_logger_rollback_wbuf_nocrc_write_frename (struct wbuf *wbuf, BYTESTRING old_iname, BYTESTRING new_iname) {
2259 uint32_t rollback_fsize = toku_logger_rollback_fsize_frename(old_iname, new_iname);
2260 wbuf_nocrc_int(wbuf, rollback_fsize);
2261 wbuf_nocrc_char(wbuf, 'n');
2262 wbuf_nocrc_BYTESTRING(wbuf, old_iname);
2263 wbuf_nocrc_BYTESTRING(wbuf, new_iname);
2264}
2265void toku_logger_rollback_wbuf_nocrc_write_cmdinsert (struct wbuf *wbuf, FILENUM filenum, BYTESTRING key) {
2266 uint32_t rollback_fsize = toku_logger_rollback_fsize_cmdinsert(filenum, key);
2267 wbuf_nocrc_int(wbuf, rollback_fsize);
2268 wbuf_nocrc_char(wbuf, 'i');
2269 wbuf_nocrc_FILENUM(wbuf, filenum);
2270 wbuf_nocrc_BYTESTRING(wbuf, key);
2271}
2272void toku_logger_rollback_wbuf_nocrc_write_cmddelete (struct wbuf *wbuf, FILENUM filenum, BYTESTRING key) {
2273 uint32_t rollback_fsize = toku_logger_rollback_fsize_cmddelete(filenum, key);
2274 wbuf_nocrc_int(wbuf, rollback_fsize);
2275 wbuf_nocrc_char(wbuf, 'd');
2276 wbuf_nocrc_FILENUM(wbuf, filenum);
2277 wbuf_nocrc_BYTESTRING(wbuf, key);
2278}
2279void toku_logger_rollback_wbuf_nocrc_write_rollinclude (struct wbuf *wbuf, TXNID_PAIR xid, uint64_t num_nodes, BLOCKNUM spilled_head, BLOCKNUM spilled_tail) {
2280 uint32_t rollback_fsize = toku_logger_rollback_fsize_rollinclude(xid, num_nodes, spilled_head, spilled_tail);
2281 wbuf_nocrc_int(wbuf, rollback_fsize);
2282 wbuf_nocrc_char(wbuf, 'r');
2283 wbuf_nocrc_TXNID_PAIR(wbuf, xid);
2284 wbuf_nocrc_uint64_t(wbuf, num_nodes);
2285 wbuf_nocrc_BLOCKNUM(wbuf, spilled_head);
2286 wbuf_nocrc_BLOCKNUM(wbuf, spilled_tail);
2287}
2288void toku_logger_rollback_wbuf_nocrc_write_load (struct wbuf *wbuf, FILENUM old_filenum, BYTESTRING new_iname) {
2289 uint32_t rollback_fsize = toku_logger_rollback_fsize_load(old_filenum, new_iname);
2290 wbuf_nocrc_int(wbuf, rollback_fsize);
2291 wbuf_nocrc_char(wbuf, 'l');
2292 wbuf_nocrc_FILENUM(wbuf, old_filenum);
2293 wbuf_nocrc_BYTESTRING(wbuf, new_iname);
2294}
2295void toku_logger_rollback_wbuf_nocrc_write_hot_index (struct wbuf *wbuf, FILENUMS hot_index_filenums) {
2296 uint32_t rollback_fsize = toku_logger_rollback_fsize_hot_index(hot_index_filenums);
2297 wbuf_nocrc_int(wbuf, rollback_fsize);
2298 wbuf_nocrc_char(wbuf, 'h');
2299 wbuf_nocrc_FILENUMS(wbuf, hot_index_filenums);
2300}
2301void toku_logger_rollback_wbuf_nocrc_write_dictionary_redirect (struct wbuf *wbuf, FILENUM old_filenum, FILENUM new_filenum) {
2302 uint32_t rollback_fsize = toku_logger_rollback_fsize_dictionary_redirect(old_filenum, new_filenum);
2303 wbuf_nocrc_int(wbuf, rollback_fsize);
2304 wbuf_nocrc_char(wbuf, 'R');
2305 wbuf_nocrc_FILENUM(wbuf, old_filenum);
2306 wbuf_nocrc_FILENUM(wbuf, new_filenum);
2307}
2308void toku_logger_rollback_wbuf_nocrc_write_cmdupdate (struct wbuf *wbuf, FILENUM filenum, BYTESTRING key) {
2309 uint32_t rollback_fsize = toku_logger_rollback_fsize_cmdupdate(filenum, key);
2310 wbuf_nocrc_int(wbuf, rollback_fsize);
2311 wbuf_nocrc_char(wbuf, 'u');
2312 wbuf_nocrc_FILENUM(wbuf, filenum);
2313 wbuf_nocrc_BYTESTRING(wbuf, key);
2314}
2315void toku_logger_rollback_wbuf_nocrc_write_cmdupdatebroadcast (struct wbuf *wbuf, FILENUM filenum, bool is_resetting_op) {
2316 uint32_t rollback_fsize = toku_logger_rollback_fsize_cmdupdatebroadcast(filenum, is_resetting_op);
2317 wbuf_nocrc_int(wbuf, rollback_fsize);
2318 wbuf_nocrc_char(wbuf, 'B');
2319 wbuf_nocrc_FILENUM(wbuf, filenum);
2320 wbuf_nocrc_bool(wbuf, is_resetting_op);
2321}
2322void toku_logger_rollback_wbuf_nocrc_write_change_fdescriptor (struct wbuf *wbuf, FILENUM filenum, BYTESTRING old_descriptor) {
2323 uint32_t rollback_fsize = toku_logger_rollback_fsize_change_fdescriptor(filenum, old_descriptor);
2324 wbuf_nocrc_int(wbuf, rollback_fsize);
2325 wbuf_nocrc_char(wbuf, 'D');
2326 wbuf_nocrc_FILENUM(wbuf, filenum);
2327 wbuf_nocrc_BYTESTRING(wbuf, old_descriptor);
2328}
2329void toku_logger_rollback_wbuf_nocrc_write (struct wbuf *wbuf, struct roll_entry *r) {
2330 switch (r->cmd) {
2331 case RT_fdelete: toku_logger_rollback_wbuf_nocrc_write_fdelete(wbuf, r->u.fdelete.filenum); return;
2332 case RT_fcreate: toku_logger_rollback_wbuf_nocrc_write_fcreate(wbuf, r->u.fcreate.filenum, r->u.fcreate.iname); return;
2333 case RT_frename: toku_logger_rollback_wbuf_nocrc_write_frename(wbuf, r->u.frename.old_iname, r->u.frename.new_iname); return;
2334 case RT_cmdinsert: toku_logger_rollback_wbuf_nocrc_write_cmdinsert(wbuf, r->u.cmdinsert.filenum, r->u.cmdinsert.key); return;
2335 case RT_cmddelete: toku_logger_rollback_wbuf_nocrc_write_cmddelete(wbuf, r->u.cmddelete.filenum, r->u.cmddelete.key); return;
2336 case RT_rollinclude: toku_logger_rollback_wbuf_nocrc_write_rollinclude(wbuf, r->u.rollinclude.xid, r->u.rollinclude.num_nodes, r->u.rollinclude.spilled_head, r->u.rollinclude.spilled_tail); return;
2337 case RT_load: toku_logger_rollback_wbuf_nocrc_write_load(wbuf, r->u.load.old_filenum, r->u.load.new_iname); return;
2338 case RT_hot_index: toku_logger_rollback_wbuf_nocrc_write_hot_index(wbuf, r->u.hot_index.hot_index_filenums); return;
2339 case RT_dictionary_redirect: toku_logger_rollback_wbuf_nocrc_write_dictionary_redirect(wbuf, r->u.dictionary_redirect.old_filenum, r->u.dictionary_redirect.new_filenum); return;
2340 case RT_cmdupdate: toku_logger_rollback_wbuf_nocrc_write_cmdupdate(wbuf, r->u.cmdupdate.filenum, r->u.cmdupdate.key); return;
2341 case RT_cmdupdatebroadcast: toku_logger_rollback_wbuf_nocrc_write_cmdupdatebroadcast(wbuf, r->u.cmdupdatebroadcast.filenum, r->u.cmdupdatebroadcast.is_resetting_op); return;
2342 case RT_change_fdescriptor: toku_logger_rollback_wbuf_nocrc_write_change_fdescriptor(wbuf, r->u.change_fdescriptor.filenum, r->u.change_fdescriptor.old_descriptor); return;
2343 }
2344 assert(0);
2345}
2346uint32_t toku_logger_rollback_fsize_fdelete (FILENUM filenum) {
2347 return 1 /* the cmd*/
2348 + 4 /* the int at the end saying the size */
2349 + toku_logsizeof_FILENUM(filenum);
2350}
2351uint32_t toku_logger_rollback_fsize_fcreate (FILENUM filenum, BYTESTRING iname) {
2352 return 1 /* the cmd*/
2353 + 4 /* the int at the end saying the size */
2354 + toku_logsizeof_FILENUM(filenum)
2355 + toku_logsizeof_BYTESTRING(iname);
2356}
2357uint32_t toku_logger_rollback_fsize_frename (BYTESTRING old_iname, BYTESTRING new_iname) {
2358 return 1 /* the cmd*/
2359 + 4 /* the int at the end saying the size */
2360 + toku_logsizeof_BYTESTRING(old_iname)
2361 + toku_logsizeof_BYTESTRING(new_iname);
2362}
2363uint32_t toku_logger_rollback_fsize_cmdinsert (FILENUM filenum, BYTESTRING key) {
2364 return 1 /* the cmd*/
2365 + 4 /* the int at the end saying the size */
2366 + toku_logsizeof_FILENUM(filenum)
2367 + toku_logsizeof_BYTESTRING(key);
2368}
2369uint32_t toku_logger_rollback_fsize_cmddelete (FILENUM filenum, BYTESTRING key) {
2370 return 1 /* the cmd*/
2371 + 4 /* the int at the end saying the size */
2372 + toku_logsizeof_FILENUM(filenum)
2373 + toku_logsizeof_BYTESTRING(key);
2374}
2375uint32_t toku_logger_rollback_fsize_rollinclude (TXNID_PAIR xid, uint64_t num_nodes, BLOCKNUM spilled_head, BLOCKNUM spilled_tail) {
2376 return 1 /* the cmd*/
2377 + 4 /* the int at the end saying the size */
2378 + toku_logsizeof_TXNID_PAIR(xid)
2379 + toku_logsizeof_uint64_t(num_nodes)
2380 + toku_logsizeof_BLOCKNUM(spilled_head)
2381 + toku_logsizeof_BLOCKNUM(spilled_tail);
2382}
2383uint32_t toku_logger_rollback_fsize_load (FILENUM old_filenum, BYTESTRING new_iname) {
2384 return 1 /* the cmd*/
2385 + 4 /* the int at the end saying the size */
2386 + toku_logsizeof_FILENUM(old_filenum)
2387 + toku_logsizeof_BYTESTRING(new_iname);
2388}
2389uint32_t toku_logger_rollback_fsize_hot_index (FILENUMS hot_index_filenums) {
2390 return 1 /* the cmd*/
2391 + 4 /* the int at the end saying the size */
2392 + toku_logsizeof_FILENUMS(hot_index_filenums);
2393}
2394uint32_t toku_logger_rollback_fsize_dictionary_redirect (FILENUM old_filenum, FILENUM new_filenum) {
2395 return 1 /* the cmd*/
2396 + 4 /* the int at the end saying the size */
2397 + toku_logsizeof_FILENUM(old_filenum)
2398 + toku_logsizeof_FILENUM(new_filenum);
2399}
2400uint32_t toku_logger_rollback_fsize_cmdupdate (FILENUM filenum, BYTESTRING key) {
2401 return 1 /* the cmd*/
2402 + 4 /* the int at the end saying the size */
2403 + toku_logsizeof_FILENUM(filenum)
2404 + toku_logsizeof_BYTESTRING(key);
2405}
2406uint32_t toku_logger_rollback_fsize_cmdupdatebroadcast (FILENUM filenum, bool is_resetting_op) {
2407 return 1 /* the cmd*/
2408 + 4 /* the int at the end saying the size */
2409 + toku_logsizeof_FILENUM(filenum)
2410 + toku_logsizeof_bool(is_resetting_op);
2411}
2412uint32_t toku_logger_rollback_fsize_change_fdescriptor (FILENUM filenum, BYTESTRING old_descriptor) {
2413 return 1 /* the cmd*/
2414 + 4 /* the int at the end saying the size */
2415 + toku_logsizeof_FILENUM(filenum)
2416 + toku_logsizeof_BYTESTRING(old_descriptor);
2417}
2418uint32_t toku_logger_rollback_fsize(struct roll_entry *item){
2419 switch(item->cmd) {
2420 case RT_fdelete: return toku_logger_rollback_fsize_fdelete(item->u.fdelete.filenum);
2421 case RT_fcreate: return toku_logger_rollback_fsize_fcreate(item->u.fcreate.filenum, item->u.fcreate.iname);
2422 case RT_frename: return toku_logger_rollback_fsize_frename(item->u.frename.old_iname, item->u.frename.new_iname);
2423 case RT_cmdinsert: return toku_logger_rollback_fsize_cmdinsert(item->u.cmdinsert.filenum, item->u.cmdinsert.key);
2424 case RT_cmddelete: return toku_logger_rollback_fsize_cmddelete(item->u.cmddelete.filenum, item->u.cmddelete.key);
2425 case RT_rollinclude: return toku_logger_rollback_fsize_rollinclude(item->u.rollinclude.xid, item->u.rollinclude.num_nodes, item->u.rollinclude.spilled_head, item->u.rollinclude.spilled_tail);
2426 case RT_load: return toku_logger_rollback_fsize_load(item->u.load.old_filenum, item->u.load.new_iname);
2427 case RT_hot_index: return toku_logger_rollback_fsize_hot_index(item->u.hot_index.hot_index_filenums);
2428 case RT_dictionary_redirect: return toku_logger_rollback_fsize_dictionary_redirect(item->u.dictionary_redirect.old_filenum, item->u.dictionary_redirect.new_filenum);
2429 case RT_cmdupdate: return toku_logger_rollback_fsize_cmdupdate(item->u.cmdupdate.filenum, item->u.cmdupdate.key);
2430 case RT_cmdupdatebroadcast: return toku_logger_rollback_fsize_cmdupdatebroadcast(item->u.cmdupdatebroadcast.filenum, item->u.cmdupdatebroadcast.is_resetting_op);
2431 case RT_change_fdescriptor: return toku_logger_rollback_fsize_change_fdescriptor(item->u.change_fdescriptor.filenum, item->u.change_fdescriptor.old_descriptor);
2432 }
2433 assert(0);
2434 return 0;
2435}
2436int toku_parse_rollback(unsigned char *buf, uint32_t n_bytes, struct roll_entry **itemp, memarena *ma) {
2437 assert(n_bytes>0);
2438 struct roll_entry *item;
2439 enum rt_cmd cmd = (enum rt_cmd)(buf[0]);
2440 size_t mem_needed;
2441 struct rbuf rc = {buf, n_bytes, 1};
2442 switch(cmd) {
2443 case RT_fdelete:
2444 mem_needed = sizeof(item->u.fdelete) + __builtin_offsetof(struct roll_entry, u.fdelete);
2445 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2446 item->cmd = cmd;
2447 rbuf_ma_FILENUM(&rc, ma, &item->u.fdelete.filenum);
2448 *itemp = item;
2449 return 0;
2450 case RT_fcreate:
2451 mem_needed = sizeof(item->u.fcreate) + __builtin_offsetof(struct roll_entry, u.fcreate);
2452 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2453 item->cmd = cmd;
2454 rbuf_ma_FILENUM(&rc, ma, &item->u.fcreate.filenum);
2455 rbuf_ma_BYTESTRING(&rc, ma, &item->u.fcreate.iname);
2456 *itemp = item;
2457 return 0;
2458 case RT_frename:
2459 mem_needed = sizeof(item->u.frename) + __builtin_offsetof(struct roll_entry, u.frename);
2460 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2461 item->cmd = cmd;
2462 rbuf_ma_BYTESTRING(&rc, ma, &item->u.frename.old_iname);
2463 rbuf_ma_BYTESTRING(&rc, ma, &item->u.frename.new_iname);
2464 *itemp = item;
2465 return 0;
2466 case RT_cmdinsert:
2467 mem_needed = sizeof(item->u.cmdinsert) + __builtin_offsetof(struct roll_entry, u.cmdinsert);
2468 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2469 item->cmd = cmd;
2470 rbuf_ma_FILENUM(&rc, ma, &item->u.cmdinsert.filenum);
2471 rbuf_ma_BYTESTRING(&rc, ma, &item->u.cmdinsert.key);
2472 *itemp = item;
2473 return 0;
2474 case RT_cmddelete:
2475 mem_needed = sizeof(item->u.cmddelete) + __builtin_offsetof(struct roll_entry, u.cmddelete);
2476 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2477 item->cmd = cmd;
2478 rbuf_ma_FILENUM(&rc, ma, &item->u.cmddelete.filenum);
2479 rbuf_ma_BYTESTRING(&rc, ma, &item->u.cmddelete.key);
2480 *itemp = item;
2481 return 0;
2482 case RT_rollinclude:
2483 mem_needed = sizeof(item->u.rollinclude) + __builtin_offsetof(struct roll_entry, u.rollinclude);
2484 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2485 item->cmd = cmd;
2486 rbuf_ma_TXNID_PAIR(&rc, ma, &item->u.rollinclude.xid);
2487 rbuf_ma_uint64_t(&rc, ma, &item->u.rollinclude.num_nodes);
2488 rbuf_ma_BLOCKNUM(&rc, ma, &item->u.rollinclude.spilled_head);
2489 rbuf_ma_BLOCKNUM(&rc, ma, &item->u.rollinclude.spilled_tail);
2490 *itemp = item;
2491 return 0;
2492 case RT_load:
2493 mem_needed = sizeof(item->u.load) + __builtin_offsetof(struct roll_entry, u.load);
2494 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2495 item->cmd = cmd;
2496 rbuf_ma_FILENUM(&rc, ma, &item->u.load.old_filenum);
2497 rbuf_ma_BYTESTRING(&rc, ma, &item->u.load.new_iname);
2498 *itemp = item;
2499 return 0;
2500 case RT_hot_index:
2501 mem_needed = sizeof(item->u.hot_index) + __builtin_offsetof(struct roll_entry, u.hot_index);
2502 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2503 item->cmd = cmd;
2504 rbuf_ma_FILENUMS(&rc, ma, &item->u.hot_index.hot_index_filenums);
2505 *itemp = item;
2506 return 0;
2507 case RT_dictionary_redirect:
2508 mem_needed = sizeof(item->u.dictionary_redirect) + __builtin_offsetof(struct roll_entry, u.dictionary_redirect);
2509 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2510 item->cmd = cmd;
2511 rbuf_ma_FILENUM(&rc, ma, &item->u.dictionary_redirect.old_filenum);
2512 rbuf_ma_FILENUM(&rc, ma, &item->u.dictionary_redirect.new_filenum);
2513 *itemp = item;
2514 return 0;
2515 case RT_cmdupdate:
2516 mem_needed = sizeof(item->u.cmdupdate) + __builtin_offsetof(struct roll_entry, u.cmdupdate);
2517 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2518 item->cmd = cmd;
2519 rbuf_ma_FILENUM(&rc, ma, &item->u.cmdupdate.filenum);
2520 rbuf_ma_BYTESTRING(&rc, ma, &item->u.cmdupdate.key);
2521 *itemp = item;
2522 return 0;
2523 case RT_cmdupdatebroadcast:
2524 mem_needed = sizeof(item->u.cmdupdatebroadcast) + __builtin_offsetof(struct roll_entry, u.cmdupdatebroadcast);
2525 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2526 item->cmd = cmd;
2527 rbuf_ma_FILENUM(&rc, ma, &item->u.cmdupdatebroadcast.filenum);
2528 rbuf_ma_bool(&rc, ma, &item->u.cmdupdatebroadcast.is_resetting_op);
2529 *itemp = item;
2530 return 0;
2531 case RT_change_fdescriptor:
2532 mem_needed = sizeof(item->u.change_fdescriptor) + __builtin_offsetof(struct roll_entry, u.change_fdescriptor);
2533 CAST_FROM_VOIDP(item, ma->malloc_from_arena(mem_needed));
2534 item->cmd = cmd;
2535 rbuf_ma_FILENUM(&rc, ma, &item->u.change_fdescriptor.filenum);
2536 rbuf_ma_BYTESTRING(&rc, ma, &item->u.change_fdescriptor.old_descriptor);
2537 *itemp = item;
2538 return 0;
2539 }
2540 return EINVAL;
2541}
2542LSN toku_log_entry_get_lsn(struct log_entry *le) {
2543 return le->u.begin_checkpoint.lsn;
2544}
2545