1
by brian
clean slate |
1 |
/******************************************************
|
2 |
Database log
|
|
3 |
||
4 |
(c) 1995 Innobase Oy
|
|
5 |
||
6 |
Created 12/9/1995 Heikki Tuuri
|
|
7 |
*******************************************************/
|
|
8 |
||
9 |
#ifndef log0log_h
|
|
10 |
#define log0log_h
|
|
11 |
||
12 |
#include "univ.i" |
|
13 |
#include "ut0byte.h" |
|
14 |
#include "sync0sync.h" |
|
15 |
#include "sync0rw.h" |
|
16 |
||
17 |
typedef struct log_struct log_t; |
|
18 |
typedef struct log_group_struct log_group_t; |
|
19 |
||
20 |
#ifdef UNIV_DEBUG
|
|
21 |
extern ibool log_do_write; |
|
22 |
extern ibool log_debug_writes; |
|
23 |
#else /* UNIV_DEBUG */ |
|
24 |
# define log_do_write TRUE
|
|
25 |
#endif /* UNIV_DEBUG */ |
|
26 |
||
27 |
/* Wait modes for log_write_up_to */
|
|
28 |
#define LOG_NO_WAIT 91
|
|
29 |
#define LOG_WAIT_ONE_GROUP 92
|
|
30 |
#define LOG_WAIT_ALL_GROUPS 93
|
|
31 |
#define LOG_MAX_N_GROUPS 32
|
|
32 |
||
33 |
/********************************************************************
|
|
34 |
Sets the global variable log_fsp_current_free_limit. Also makes a checkpoint,
|
|
35 |
so that we know that the limit has been written to a log checkpoint field
|
|
36 |
on disk. */
|
|
37 |
||
38 |
void
|
|
39 |
log_fsp_current_free_limit_set_and_checkpoint( |
|
40 |
/*==========================================*/
|
|
41 |
ulint limit); /* in: limit to set */ |
|
42 |
/***********************************************************************
|
|
43 |
Calculates where in log files we find a specified lsn. */
|
|
44 |
||
45 |
ulint
|
|
46 |
log_calc_where_lsn_is( |
|
47 |
/*==================*/
|
|
48 |
/* out: log file number */
|
|
49 |
ib_longlong* log_file_offset, /* out: offset in that file |
|
50 |
(including the header) */ |
|
51 |
dulint first_header_lsn, /* in: first log file start |
|
52 |
lsn */
|
|
53 |
dulint lsn, /* in: lsn whose position to |
|
54 |
determine */
|
|
55 |
ulint n_log_files, /* in: total number of log |
|
56 |
files */
|
|
57 |
ib_longlong log_file_size); /* in: log file size |
|
58 |
(including the header) */
|
|
59 |
/****************************************************************
|
|
60 |
Writes to the log the string given. The log must be released with
|
|
61 |
log_release. */
|
|
62 |
UNIV_INLINE
|
|
63 |
dulint
|
|
64 |
log_reserve_and_write_fast( |
|
65 |
/*=======================*/
|
|
66 |
/* out: end lsn of the log record, ut_dulint_zero if
|
|
67 |
did not succeed */
|
|
68 |
byte* str, /* in: string */ |
|
69 |
ulint len, /* in: string length */ |
|
70 |
dulint* start_lsn,/* out: start lsn of the log record */ |
|
71 |
ibool* success);/* out: TRUE if success */ |
|
72 |
/***************************************************************************
|
|
73 |
Releases the log mutex. */
|
|
74 |
UNIV_INLINE
|
|
75 |
void
|
|
76 |
log_release(void); |
|
77 |
/*=============*/
|
|
78 |
/***************************************************************************
|
|
79 |
Checks if there is need for a log buffer flush or a new checkpoint, and does
|
|
80 |
this if yes. Any database operation should call this when it has modified
|
|
81 |
more than about 4 pages. NOTE that this function may only be called when the
|
|
82 |
OS thread owns no synchronization objects except the dictionary mutex. */
|
|
83 |
UNIV_INLINE
|
|
84 |
void
|
|
85 |
log_free_check(void); |
|
86 |
/*================*/
|
|
87 |
/****************************************************************
|
|
88 |
Opens the log for log_write_low. The log must be closed with log_close and
|
|
89 |
released with log_release. */
|
|
90 |
||
91 |
dulint
|
|
92 |
log_reserve_and_open( |
|
93 |
/*=================*/
|
|
94 |
/* out: start lsn of the log record */
|
|
95 |
ulint len); /* in: length of data to be catenated */ |
|
96 |
/****************************************************************
|
|
97 |
Writes to the log the string given. It is assumed that the caller holds the
|
|
98 |
log mutex. */
|
|
99 |
||
100 |
void
|
|
101 |
log_write_low( |
|
102 |
/*==========*/
|
|
103 |
byte* str, /* in: string */ |
|
104 |
ulint str_len); /* in: string length */ |
|
105 |
/****************************************************************
|
|
106 |
Closes the log. */
|
|
107 |
||
108 |
dulint
|
|
109 |
log_close(void); |
|
110 |
/*===========*/
|
|
111 |
/* out: lsn */
|
|
112 |
/****************************************************************
|
|
113 |
Gets the current lsn. */
|
|
114 |
UNIV_INLINE
|
|
115 |
dulint
|
|
116 |
log_get_lsn(void); |
|
117 |
/*=============*/
|
|
118 |
/* out: current lsn */
|
|
119 |
/**********************************************************
|
|
120 |
Initializes the log. */
|
|
121 |
||
122 |
void
|
|
123 |
log_init(void); |
|
124 |
/*==========*/
|
|
125 |
/**********************************************************************
|
|
126 |
Inits a log group to the log system. */
|
|
127 |
||
128 |
void
|
|
129 |
log_group_init( |
|
130 |
/*===========*/
|
|
131 |
ulint id, /* in: group id */ |
|
132 |
ulint n_files, /* in: number of log files */ |
|
133 |
ulint file_size, /* in: log file size in bytes */ |
|
134 |
ulint space_id, /* in: space id of the file space |
|
135 |
which contains the log files of this
|
|
136 |
group */
|
|
137 |
ulint archive_space_id); /* in: space id of the file space |
|
138 |
which contains some archived log
|
|
139 |
files for this group; currently, only
|
|
140 |
for the first log group this is
|
|
141 |
used */
|
|
142 |
/**********************************************************
|
|
143 |
Completes an i/o to a log file. */
|
|
144 |
||
145 |
void
|
|
146 |
log_io_complete( |
|
147 |
/*============*/
|
|
148 |
log_group_t* group); /* in: log group */ |
|
149 |
/**********************************************************
|
|
150 |
This function is called, e.g., when a transaction wants to commit. It checks
|
|
151 |
that the log has been written to the log file up to the last log entry written
|
|
152 |
by the transaction. If there is a flush running, it waits and checks if the
|
|
153 |
flush flushed enough. If not, starts a new flush. */
|
|
154 |
||
155 |
void
|
|
156 |
log_write_up_to( |
|
157 |
/*============*/
|
|
158 |
dulint lsn, /* in: log sequence number up to which the log should |
|
159 |
be written, ut_dulint_max if not specified */
|
|
160 |
ulint wait, /* in: LOG_NO_WAIT, LOG_WAIT_ONE_GROUP, |
|
161 |
or LOG_WAIT_ALL_GROUPS */
|
|
162 |
ibool flush_to_disk); |
|
163 |
/* in: TRUE if we want the written log also to be
|
|
164 |
flushed to disk */
|
|
165 |
/********************************************************************
|
|
166 |
Does a syncronous flush of the log buffer to disk. */
|
|
167 |
||
168 |
void
|
|
169 |
log_buffer_flush_to_disk(void); |
|
170 |
/*==========================*/
|
|
171 |
/********************************************************************
|
|
172 |
Advances the smallest lsn for which there are unflushed dirty blocks in the
|
|
173 |
buffer pool and also may make a new checkpoint. NOTE: this function may only
|
|
174 |
be called if the calling thread owns no synchronization objects! */
|
|
175 |
||
176 |
ibool
|
|
177 |
log_preflush_pool_modified_pages( |
|
178 |
/*=============================*/
|
|
179 |
/* out: FALSE if there was a flush batch of
|
|
180 |
the same type running, which means that we
|
|
181 |
could not start this flush batch */
|
|
182 |
dulint new_oldest, /* in: try to advance oldest_modified_lsn |
|
183 |
at least to this lsn */
|
|
184 |
ibool sync); /* in: TRUE if synchronous operation is |
|
185 |
desired */
|
|
186 |
/**********************************************************
|
|
187 |
Makes a checkpoint. Note that this function does not flush dirty
|
|
188 |
blocks from the buffer pool: it only checks what is lsn of the oldest
|
|
189 |
modification in the pool, and writes information about the lsn in
|
|
190 |
log files. Use log_make_checkpoint_at to flush also the pool. */
|
|
191 |
||
192 |
ibool
|
|
193 |
log_checkpoint( |
|
194 |
/*===========*/
|
|
195 |
/* out: TRUE if success, FALSE if a checkpoint
|
|
196 |
write was already running */
|
|
197 |
ibool sync, /* in: TRUE if synchronous operation is |
|
198 |
desired */
|
|
199 |
ibool write_always); /* in: the function normally checks if the |
|
200 |
the new checkpoint would have a greater
|
|
201 |
lsn than the previous one: if not, then no
|
|
202 |
physical write is done; by setting this
|
|
203 |
parameter TRUE, a physical write will always be
|
|
204 |
made to log files */
|
|
205 |
/********************************************************************
|
|
206 |
Makes a checkpoint at a given lsn or later. */
|
|
207 |
||
208 |
void
|
|
209 |
log_make_checkpoint_at( |
|
210 |
/*===================*/
|
|
211 |
dulint lsn, /* in: make a checkpoint at this or a later |
|
212 |
lsn, if ut_dulint_max, makes a checkpoint at
|
|
213 |
the latest lsn */
|
|
214 |
ibool write_always); /* in: the function normally checks if the |
|
215 |
the new checkpoint would have a greater
|
|
216 |
lsn than the previous one: if not, then no
|
|
217 |
physical write is done; by setting this
|
|
218 |
parameter TRUE, a physical write will always be
|
|
219 |
made to log files */
|
|
220 |
/********************************************************************
|
|
221 |
Makes a checkpoint at the latest lsn and writes it to first page of each
|
|
222 |
data file in the database, so that we know that the file spaces contain
|
|
223 |
all modifications up to that lsn. This can only be called at database
|
|
224 |
shutdown. This function also writes all log in log files to the log archive. */
|
|
225 |
||
226 |
void
|
|
227 |
logs_empty_and_mark_files_at_shutdown(void); |
|
228 |
/*=======================================*/
|
|
229 |
/**********************************************************
|
|
230 |
Reads a checkpoint info from a log group header to log_sys->checkpoint_buf. */
|
|
231 |
||
232 |
void
|
|
233 |
log_group_read_checkpoint_info( |
|
234 |
/*===========================*/
|
|
235 |
log_group_t* group, /* in: log group */ |
|
236 |
ulint field); /* in: LOG_CHECKPOINT_1 or LOG_CHECKPOINT_2 */ |
|
237 |
/***********************************************************************
|
|
238 |
Gets info from a checkpoint about a log group. */
|
|
239 |
||
240 |
void
|
|
241 |
log_checkpoint_get_nth_group_info( |
|
242 |
/*==============================*/
|
|
243 |
byte* buf, /* in: buffer containing checkpoint info */ |
|
244 |
ulint n, /* in: nth slot */ |
|
245 |
ulint* file_no,/* out: archived file number */ |
|
246 |
ulint* offset);/* out: archived file offset */ |
|
247 |
/**********************************************************
|
|
248 |
Writes checkpoint info to groups. */
|
|
249 |
||
250 |
void
|
|
251 |
log_groups_write_checkpoint_info(void); |
|
252 |
/*==================================*/
|
|
253 |
/**********************************************************
|
|
254 |
Writes info to a buffer of a log group when log files are created in
|
|
255 |
backup restoration. */
|
|
256 |
||
257 |
void
|
|
258 |
log_reset_first_header_and_checkpoint( |
|
259 |
/*==================================*/
|
|
260 |
byte* hdr_buf,/* in: buffer which will be written to the start |
|
261 |
of the first log file */
|
|
262 |
dulint start); /* in: lsn of the start of the first log file; |
|
263 |
we pretend that there is a checkpoint at
|
|
264 |
start + LOG_BLOCK_HDR_SIZE */
|
|
265 |
/************************************************************************
|
|
266 |
Starts an archiving operation. */
|
|
267 |
||
268 |
ibool
|
|
269 |
log_archive_do( |
|
270 |
/*===========*/
|
|
271 |
/* out: TRUE if succeed, FALSE if an archiving
|
|
272 |
operation was already running */
|
|
273 |
ibool sync, /* in: TRUE if synchronous operation is desired */ |
|
274 |
ulint* n_bytes);/* out: archive log buffer size, 0 if nothing to |
|
275 |
archive */
|
|
276 |
/********************************************************************
|
|
277 |
Writes the log contents to the archive up to the lsn when this function was
|
|
278 |
called, and stops the archiving. When archiving is started again, the archived
|
|
279 |
log file numbers start from a number one higher, so that the archiving will
|
|
280 |
not write again to the archived log files which exist when this function
|
|
281 |
returns. */
|
|
282 |
||
283 |
ulint
|
|
284 |
log_archive_stop(void); |
|
285 |
/*==================*/
|
|
286 |
/* out: DB_SUCCESS or DB_ERROR */
|
|
287 |
/********************************************************************
|
|
288 |
Starts again archiving which has been stopped. */
|
|
289 |
||
290 |
ulint
|
|
291 |
log_archive_start(void); |
|
292 |
/*===================*/
|
|
293 |
/* out: DB_SUCCESS or DB_ERROR */
|
|
294 |
/********************************************************************
|
|
295 |
Stop archiving the log so that a gap may occur in the archived log files. */
|
|
296 |
||
297 |
ulint
|
|
298 |
log_archive_noarchivelog(void); |
|
299 |
/*==========================*/
|
|
300 |
/* out: DB_SUCCESS or DB_ERROR */
|
|
301 |
/********************************************************************
|
|
302 |
Start archiving the log so that a gap may occur in the archived log files. */
|
|
303 |
||
304 |
ulint
|
|
305 |
log_archive_archivelog(void); |
|
306 |
/*========================*/
|
|
307 |
/* out: DB_SUCCESS or DB_ERROR */
|
|
308 |
/**********************************************************
|
|
309 |
Generates an archived log file name. */
|
|
310 |
||
311 |
void
|
|
312 |
log_archived_file_name_gen( |
|
313 |
/*=======================*/
|
|
314 |
char* buf, /* in: buffer where to write */ |
|
315 |
ulint id, /* in: group id */ |
|
316 |
ulint file_no);/* in: file number */ |
|
317 |
/************************************************************************
|
|
318 |
Checks that there is enough free space in the log to start a new query step.
|
|
319 |
Flushes the log buffer or makes a new checkpoint if necessary. NOTE: this
|
|
320 |
function may only be called if the calling thread owns no synchronization
|
|
321 |
objects! */
|
|
322 |
||
323 |
void
|
|
324 |
log_check_margins(void); |
|
325 |
/*===================*/
|
|
326 |
/**********************************************************
|
|
327 |
Reads a specified log segment to a buffer. */
|
|
328 |
||
329 |
void
|
|
330 |
log_group_read_log_seg( |
|
331 |
/*===================*/
|
|
332 |
ulint type, /* in: LOG_ARCHIVE or LOG_RECOVER */ |
|
333 |
byte* buf, /* in: buffer where to read */ |
|
334 |
log_group_t* group, /* in: log group */ |
|
335 |
dulint start_lsn, /* in: read area start */ |
|
336 |
dulint end_lsn); /* in: read area end */ |
|
337 |
/**********************************************************
|
|
338 |
Writes a buffer to a log file group. */
|
|
339 |
||
340 |
void
|
|
341 |
log_group_write_buf( |
|
342 |
/*================*/
|
|
343 |
log_group_t* group, /* in: log group */ |
|
344 |
byte* buf, /* in: buffer */ |
|
345 |
ulint len, /* in: buffer len; must be divisible |
|
346 |
by OS_FILE_LOG_BLOCK_SIZE */
|
|
347 |
dulint start_lsn, /* in: start lsn of the buffer; must |
|
348 |
be divisible by
|
|
349 |
OS_FILE_LOG_BLOCK_SIZE */
|
|
350 |
ulint new_data_offset);/* in: start offset of new data in |
|
351 |
buf: this parameter is used to decide
|
|
352 |
if we have to write a new log file
|
|
353 |
header */
|
|
354 |
/************************************************************
|
|
355 |
Sets the field values in group to correspond to a given lsn. For this function
|
|
356 |
to work, the values must already be correctly initialized to correspond to
|
|
357 |
some lsn, for instance, a checkpoint lsn. */
|
|
358 |
||
359 |
void
|
|
360 |
log_group_set_fields( |
|
361 |
/*=================*/
|
|
362 |
log_group_t* group, /* in: group */ |
|
363 |
dulint lsn); /* in: lsn for which the values should be |
|
364 |
set */
|
|
365 |
/**********************************************************
|
|
366 |
Calculates the data capacity of a log group, when the log file headers are not
|
|
367 |
included. */
|
|
368 |
||
369 |
ulint
|
|
370 |
log_group_get_capacity( |
|
371 |
/*===================*/
|
|
372 |
/* out: capacity in bytes */
|
|
373 |
log_group_t* group); /* in: log group */ |
|
374 |
/****************************************************************
|
|
375 |
Gets a log block flush bit. */
|
|
376 |
UNIV_INLINE
|
|
377 |
ibool
|
|
378 |
log_block_get_flush_bit( |
|
379 |
/*====================*/
|
|
380 |
/* out: TRUE if this block was the first
|
|
381 |
to be written in a log flush */
|
|
382 |
byte* log_block); /* in: log block */ |
|
383 |
/****************************************************************
|
|
384 |
Gets a log block number stored in the header. */
|
|
385 |
UNIV_INLINE
|
|
386 |
ulint
|
|
387 |
log_block_get_hdr_no( |
|
388 |
/*=================*/
|
|
389 |
/* out: log block number stored in the block
|
|
390 |
header */
|
|
391 |
byte* log_block); /* in: log block */ |
|
392 |
/****************************************************************
|
|
393 |
Gets a log block data length. */
|
|
394 |
UNIV_INLINE
|
|
395 |
ulint
|
|
396 |
log_block_get_data_len( |
|
397 |
/*===================*/
|
|
398 |
/* out: log block data length measured as a
|
|
399 |
byte offset from the block start */
|
|
400 |
byte* log_block); /* in: log block */ |
|
401 |
/****************************************************************
|
|
402 |
Sets the log block data length. */
|
|
403 |
UNIV_INLINE
|
|
404 |
void
|
|
405 |
log_block_set_data_len( |
|
406 |
/*===================*/
|
|
407 |
byte* log_block, /* in: log block */ |
|
408 |
ulint len); /* in: data length */ |
|
409 |
/****************************************************************
|
|
410 |
Calculates the checksum for a log block. */
|
|
411 |
UNIV_INLINE
|
|
412 |
ulint
|
|
413 |
log_block_calc_checksum( |
|
414 |
/*====================*/
|
|
415 |
/* out: checksum */
|
|
416 |
byte* block); /* in: log block */ |
|
417 |
/****************************************************************
|
|
418 |
Gets a log block checksum field value. */
|
|
419 |
UNIV_INLINE
|
|
420 |
ulint
|
|
421 |
log_block_get_checksum( |
|
422 |
/*===================*/
|
|
423 |
/* out: checksum */
|
|
424 |
byte* log_block); /* in: log block */ |
|
425 |
/****************************************************************
|
|
426 |
Sets a log block checksum field value. */
|
|
427 |
UNIV_INLINE
|
|
428 |
void
|
|
429 |
log_block_set_checksum( |
|
430 |
/*===================*/
|
|
431 |
byte* log_block, /* in: log block */ |
|
432 |
ulint checksum); /* in: checksum */ |
|
433 |
/****************************************************************
|
|
434 |
Gets a log block first mtr log record group offset. */
|
|
435 |
UNIV_INLINE
|
|
436 |
ulint
|
|
437 |
log_block_get_first_rec_group( |
|
438 |
/*==========================*/
|
|
439 |
/* out: first mtr log record group byte offset
|
|
440 |
from the block start, 0 if none */
|
|
441 |
byte* log_block); /* in: log block */ |
|
442 |
/****************************************************************
|
|
443 |
Sets the log block first mtr log record group offset. */
|
|
444 |
UNIV_INLINE
|
|
445 |
void
|
|
446 |
log_block_set_first_rec_group( |
|
447 |
/*==========================*/
|
|
448 |
byte* log_block, /* in: log block */ |
|
449 |
ulint offset); /* in: offset, 0 if none */ |
|
450 |
/****************************************************************
|
|
451 |
Gets a log block checkpoint number field (4 lowest bytes). */
|
|
452 |
UNIV_INLINE
|
|
453 |
ulint
|
|
454 |
log_block_get_checkpoint_no( |
|
455 |
/*========================*/
|
|
456 |
/* out: checkpoint no (4 lowest bytes) */
|
|
457 |
byte* log_block); /* in: log block */ |
|
458 |
/****************************************************************
|
|
459 |
Initializes a log block in the log buffer. */
|
|
460 |
UNIV_INLINE
|
|
461 |
void
|
|
462 |
log_block_init( |
|
463 |
/*===========*/
|
|
464 |
byte* log_block, /* in: pointer to the log buffer */ |
|
465 |
dulint lsn); /* in: lsn within the log block */ |
|
466 |
/****************************************************************
|
|
467 |
Initializes a log block in the log buffer in the old, < 3.23.52 format, where
|
|
468 |
there was no checksum yet. */
|
|
469 |
UNIV_INLINE
|
|
470 |
void
|
|
471 |
log_block_init_in_old_format( |
|
472 |
/*=========================*/
|
|
473 |
byte* log_block, /* in: pointer to the log buffer */ |
|
474 |
dulint lsn); /* in: lsn within the log block */ |
|
475 |
/****************************************************************
|
|
476 |
Converts a lsn to a log block number. */
|
|
477 |
UNIV_INLINE
|
|
478 |
ulint
|
|
479 |
log_block_convert_lsn_to_no( |
|
480 |
/*========================*/
|
|
481 |
/* out: log block number, it is > 0 and <= 1G */
|
|
482 |
dulint lsn); /* in: lsn of a byte within the block */ |
|
483 |
/**********************************************************
|
|
484 |
Prints info of the log. */
|
|
485 |
||
486 |
void
|
|
487 |
log_print( |
|
488 |
/*======*/
|
|
489 |
FILE* file); /* in: file where to print */ |
|
490 |
/**********************************************************
|
|
491 |
Peeks the current lsn. */
|
|
492 |
||
493 |
ibool
|
|
494 |
log_peek_lsn( |
|
495 |
/*=========*/
|
|
496 |
/* out: TRUE if success, FALSE if could not get the
|
|
497 |
log system mutex */
|
|
498 |
dulint* lsn); /* out: if returns TRUE, current lsn is here */ |
|
499 |
/**************************************************************************
|
|
500 |
Refreshes the statistics used to print per-second averages. */
|
|
501 |
||
502 |
void
|
|
503 |
log_refresh_stats(void); |
|
504 |
/*===================*/
|
|
505 |
||
506 |
extern log_t* log_sys; |
|
507 |
||
508 |
/* Values used as flags */
|
|
509 |
#define LOG_FLUSH 7652559
|
|
510 |
#define LOG_CHECKPOINT 78656949
|
|
511 |
#define LOG_ARCHIVE 11122331
|
|
512 |
#define LOG_RECOVER 98887331
|
|
513 |
||
514 |
/* The counting of lsn's starts from this value: this must be non-zero */
|
|
515 |
#define LOG_START_LSN ut_dulint_create(0, 16 * OS_FILE_LOG_BLOCK_SIZE)
|
|
516 |
||
517 |
#define LOG_BUFFER_SIZE (srv_log_buffer_size * UNIV_PAGE_SIZE)
|
|
518 |
#define LOG_ARCHIVE_BUF_SIZE (srv_log_buffer_size * UNIV_PAGE_SIZE / 4)
|
|
519 |
||
520 |
/* Offsets of a log block header */
|
|
521 |
#define LOG_BLOCK_HDR_NO 0 /* block number which must be > 0 and |
|
522 |
is allowed to wrap around at 2G; the
|
|
523 |
highest bit is set to 1 if this is the
|
|
524 |
first log block in a log flush write
|
|
525 |
segment */
|
|
526 |
#define LOG_BLOCK_FLUSH_BIT_MASK 0x80000000UL
|
|
527 |
/* mask used to get the highest bit in
|
|
528 |
the preceding field */
|
|
529 |
#define LOG_BLOCK_HDR_DATA_LEN 4 /* number of bytes of log written to |
|
530 |
this block */
|
|
531 |
#define LOG_BLOCK_FIRST_REC_GROUP 6 /* offset of the first start of an |
|
532 |
mtr log record group in this log block,
|
|
533 |
0 if none; if the value is the same
|
|
534 |
as LOG_BLOCK_HDR_DATA_LEN, it means
|
|
535 |
that the first rec group has not yet
|
|
536 |
been catenated to this log block, but
|
|
537 |
if it will, it will start at this
|
|
538 |
offset; an archive recovery can
|
|
539 |
start parsing the log records starting
|
|
540 |
from this offset in this log block,
|
|
541 |
if value not 0 */
|
|
542 |
#define LOG_BLOCK_CHECKPOINT_NO 8 /* 4 lower bytes of the value of |
|
543 |
log_sys->next_checkpoint_no when the
|
|
544 |
log block was last written to: if the
|
|
545 |
block has not yet been written full,
|
|
546 |
this value is only updated before a
|
|
547 |
log buffer flush */
|
|
548 |
#define LOG_BLOCK_HDR_SIZE 12 /* size of the log block header in |
|
549 |
bytes */
|
|
550 |
||
551 |
/* Offsets of a log block trailer from the end of the block */
|
|
552 |
#define LOG_BLOCK_CHECKSUM 4 /* 4 byte checksum of the log block |
|
553 |
contents; in InnoDB versions
|
|
554 |
< 3.23.52 this did not contain the
|
|
555 |
checksum but the same value as
|
|
556 |
.._HDR_NO */
|
|
557 |
#define LOG_BLOCK_TRL_SIZE 4 /* trailer size in bytes */ |
|
558 |
||
559 |
/* Offsets for a checkpoint field */
|
|
560 |
#define LOG_CHECKPOINT_NO 0
|
|
561 |
#define LOG_CHECKPOINT_LSN 8
|
|
562 |
#define LOG_CHECKPOINT_OFFSET 16
|
|
563 |
#define LOG_CHECKPOINT_LOG_BUF_SIZE 20
|
|
564 |
#define LOG_CHECKPOINT_ARCHIVED_LSN 24
|
|
565 |
#define LOG_CHECKPOINT_GROUP_ARRAY 32
|
|
566 |
||
567 |
/* For each value < LOG_MAX_N_GROUPS the following 8 bytes: */
|
|
568 |
||
569 |
#define LOG_CHECKPOINT_ARCHIVED_FILE_NO 0
|
|
570 |
#define LOG_CHECKPOINT_ARCHIVED_OFFSET 4
|
|
571 |
||
572 |
#define LOG_CHECKPOINT_ARRAY_END (LOG_CHECKPOINT_GROUP_ARRAY\
|
|
573 |
+ LOG_MAX_N_GROUPS * 8)
|
|
574 |
#define LOG_CHECKPOINT_CHECKSUM_1 LOG_CHECKPOINT_ARRAY_END
|
|
575 |
#define LOG_CHECKPOINT_CHECKSUM_2 (4 + LOG_CHECKPOINT_ARRAY_END)
|
|
576 |
#define LOG_CHECKPOINT_FSP_FREE_LIMIT (8 + LOG_CHECKPOINT_ARRAY_END)
|
|
577 |
/* current fsp free limit in
|
|
578 |
tablespace 0, in units of one
|
|
579 |
megabyte; this information is only used
|
|
580 |
by ibbackup to decide if it can
|
|
581 |
truncate unused ends of
|
|
582 |
non-auto-extending data files in space
|
|
583 |
0 */
|
|
584 |
#define LOG_CHECKPOINT_FSP_MAGIC_N (12 + LOG_CHECKPOINT_ARRAY_END)
|
|
585 |
/* this magic number tells if the
|
|
586 |
checkpoint contains the above field:
|
|
587 |
the field was added to
|
|
588 |
InnoDB-3.23.50 */
|
|
589 |
#define LOG_CHECKPOINT_SIZE (16 + LOG_CHECKPOINT_ARRAY_END)
|
|
590 |
||
591 |
#define LOG_CHECKPOINT_FSP_MAGIC_N_VAL 1441231243
|
|
592 |
||
593 |
/* Offsets of a log file header */
|
|
594 |
#define LOG_GROUP_ID 0 /* log group number */ |
|
595 |
#define LOG_FILE_START_LSN 4 /* lsn of the start of data in this |
|
596 |
log file */
|
|
597 |
#define LOG_FILE_NO 12 /* 4-byte archived log file number; |
|
598 |
this field is only defined in an
|
|
599 |
archived log file */
|
|
600 |
#define LOG_FILE_WAS_CREATED_BY_HOT_BACKUP 16
|
|
601 |
/* a 32-byte field which contains
|
|
602 |
the string 'ibbackup' and the
|
|
603 |
creation time if the log file was
|
|
604 |
created by ibbackup --restore;
|
|
605 |
when mysqld is first time started
|
|
606 |
on the restored database, it can
|
|
607 |
print helpful info for the user */
|
|
608 |
#define LOG_FILE_ARCH_COMPLETED OS_FILE_LOG_BLOCK_SIZE
|
|
609 |
/* this 4-byte field is TRUE when
|
|
610 |
the writing of an archived log file
|
|
611 |
has been completed; this field is
|
|
612 |
only defined in an archived log file */
|
|
613 |
#define LOG_FILE_END_LSN (OS_FILE_LOG_BLOCK_SIZE + 4)
|
|
614 |
/* lsn where the archived log file
|
|
615 |
at least extends: actually the
|
|
616 |
archived log file may extend to a
|
|
617 |
later lsn, as long as it is within the
|
|
618 |
same log block as this lsn; this field
|
|
619 |
is defined only when an archived log
|
|
620 |
file has been completely written */
|
|
621 |
#define LOG_CHECKPOINT_1 OS_FILE_LOG_BLOCK_SIZE
|
|
622 |
/* first checkpoint field in the log
|
|
623 |
header; we write alternately to the
|
|
624 |
checkpoint fields when we make new
|
|
625 |
checkpoints; this field is only defined
|
|
626 |
in the first log file of a log group */
|
|
627 |
#define LOG_CHECKPOINT_2 (3 * OS_FILE_LOG_BLOCK_SIZE)
|
|
628 |
/* second checkpoint field in the log
|
|
629 |
header */
|
|
630 |
#define LOG_FILE_HDR_SIZE (4 * OS_FILE_LOG_BLOCK_SIZE)
|
|
631 |
||
632 |
#define LOG_GROUP_OK 301
|
|
633 |
#define LOG_GROUP_CORRUPTED 302
|
|
634 |
||
635 |
/* Log group consists of a number of log files, each of the same size; a log
|
|
636 |
group is implemented as a space in the sense of the module fil0fil. */
|
|
637 |
||
638 |
struct log_group_struct{ |
|
639 |
/* The following fields are protected by log_sys->mutex */
|
|
640 |
ulint id; /* log group id */ |
|
641 |
ulint n_files; /* number of files in the group */ |
|
642 |
ulint file_size; /* individual log file size in bytes, |
|
643 |
including the log file header */
|
|
644 |
ulint space_id; /* file space which implements the log |
|
645 |
group */
|
|
646 |
ulint state; /* LOG_GROUP_OK or |
|
647 |
LOG_GROUP_CORRUPTED */
|
|
648 |
dulint lsn; /* lsn used to fix coordinates within |
|
649 |
the log group */
|
|
650 |
ulint lsn_offset; /* the offset of the above lsn */ |
|
651 |
ulint n_pending_writes;/* number of currently pending flush |
|
652 |
writes for this log group */
|
|
653 |
byte** file_header_bufs;/* buffers for each file header in the |
|
654 |
group */
|
|
655 |
/*-----------------------------*/
|
|
656 |
byte** archive_file_header_bufs;/* buffers for each file |
|
657 |
header in the group */
|
|
658 |
ulint archive_space_id;/* file space which implements the log |
|
659 |
group archive */
|
|
660 |
ulint archived_file_no;/* file number corresponding to |
|
661 |
log_sys->archived_lsn */
|
|
662 |
ulint archived_offset;/* file offset corresponding to |
|
663 |
log_sys->archived_lsn, 0 if we have
|
|
664 |
not yet written to the archive file
|
|
665 |
number archived_file_no */
|
|
666 |
ulint next_archived_file_no;/* during an archive write, |
|
667 |
until the write is completed, we
|
|
668 |
store the next value for
|
|
669 |
archived_file_no here: the write
|
|
670 |
completion function then sets the new
|
|
671 |
value to ..._file_no */
|
|
672 |
ulint next_archived_offset; /* like the preceding field */ |
|
673 |
/*-----------------------------*/
|
|
674 |
dulint scanned_lsn; /* used only in recovery: recovery scan |
|
675 |
succeeded up to this lsn in this log
|
|
676 |
group */
|
|
677 |
byte* checkpoint_buf; /* checkpoint header is written from |
|
678 |
this buffer to the group */
|
|
679 |
UT_LIST_NODE_T(log_group_t) |
|
680 |
log_groups; /* list of log groups */ |
|
681 |
};
|
|
682 |
||
683 |
struct log_struct{ |
|
684 |
byte pad[64]; /* padding to prevent other memory |
|
685 |
update hotspots from residing on the
|
|
686 |
same memory cache line */
|
|
687 |
dulint lsn; /* log sequence number */ |
|
688 |
ulint buf_free; /* first free offset within the log |
|
689 |
buffer */
|
|
690 |
mutex_t mutex; /* mutex protecting the log */ |
|
691 |
byte* buf; /* log buffer */ |
|
692 |
ulint buf_size; /* log buffer size in bytes */ |
|
693 |
ulint max_buf_free; /* recommended maximum value of |
|
694 |
buf_free, after which the buffer is
|
|
695 |
flushed */
|
|
696 |
ulint old_buf_free; /* value of buf free when log was |
|
697 |
last time opened; only in the debug
|
|
698 |
version */
|
|
699 |
dulint old_lsn; /* value of lsn when log was last time |
|
700 |
opened; only in the debug version */
|
|
701 |
ibool check_flush_or_checkpoint; |
|
702 |
/* this is set to TRUE when there may
|
|
703 |
be need to flush the log buffer, or
|
|
704 |
preflush buffer pool pages, or make
|
|
705 |
a checkpoint; this MUST be TRUE when
|
|
706 |
lsn - last_checkpoint_lsn >
|
|
707 |
max_checkpoint_age; this flag is
|
|
708 |
peeked at by log_free_check(), which
|
|
709 |
does not reserve the log mutex */
|
|
710 |
UT_LIST_BASE_NODE_T(log_group_t) |
|
711 |
log_groups; /* log groups */ |
|
712 |
||
713 |
/* The fields involved in the log buffer flush */
|
|
714 |
||
715 |
ulint buf_next_to_write;/* first offset in the log buffer |
|
716 |
where the byte content may not exist
|
|
717 |
written to file, e.g., the start
|
|
718 |
offset of a log record catenated
|
|
719 |
later; this is advanced when a flush
|
|
720 |
operation is completed to all the log
|
|
721 |
groups */
|
|
722 |
dulint written_to_some_lsn; |
|
723 |
/* first log sequence number not yet
|
|
724 |
written to any log group; for this to
|
|
725 |
be advanced, it is enough that the
|
|
726 |
write i/o has been completed for any
|
|
727 |
one log group */
|
|
728 |
dulint written_to_all_lsn; |
|
729 |
/* first log sequence number not yet
|
|
730 |
written to some log group; for this to
|
|
731 |
be advanced, it is enough that the
|
|
732 |
write i/o has been completed for all
|
|
733 |
log groups */
|
|
734 |
dulint write_lsn; /* end lsn for the current running |
|
735 |
write */
|
|
736 |
ulint write_end_offset;/* the data in buffer has been written |
|
737 |
up to this offset when the current
|
|
738 |
write ends: this field will then
|
|
739 |
be copied to buf_next_to_write */
|
|
740 |
dulint current_flush_lsn;/* end lsn for the current running |
|
741 |
write + flush operation */
|
|
742 |
dulint flushed_to_disk_lsn; |
|
743 |
/* how far we have written the log
|
|
744 |
AND flushed to disk */
|
|
745 |
ulint n_pending_writes;/* number of currently pending flushes |
|
746 |
or writes */
|
|
747 |
/* NOTE on the 'flush' in names of the fields below: starting from
|
|
748 |
4.0.14, we separate the write of the log file and the actual fsync()
|
|
749 |
or other method to flush it to disk. The names below shhould really
|
|
750 |
be 'flush_or_write'! */
|
|
751 |
os_event_t no_flush_event; /* this event is in the reset state |
|
752 |
when a flush or a write is running;
|
|
753 |
a thread should wait for this without
|
|
754 |
owning the log mutex, but NOTE that
|
|
755 |
to set or reset this event, the
|
|
756 |
thread MUST own the log mutex! */
|
|
757 |
ibool one_flushed; /* during a flush, this is first FALSE |
|
758 |
and becomes TRUE when one log group
|
|
759 |
has been written or flushed */
|
|
760 |
os_event_t one_flushed_event;/* this event is reset when the |
|
761 |
flush or write has not yet completed
|
|
762 |
for any log group; e.g., this means
|
|
763 |
that a transaction has been committed
|
|
764 |
when this is set; a thread should wait
|
|
765 |
for this without owning the log mutex,
|
|
766 |
but NOTE that to set or reset this
|
|
767 |
event, the thread MUST own the log
|
|
768 |
mutex! */
|
|
769 |
ulint n_log_ios; /* number of log i/os initiated thus |
|
770 |
far */
|
|
771 |
ulint n_log_ios_old; /* number of log i/o's at the |
|
772 |
previous printout */
|
|
773 |
time_t last_printout_time;/* when log_print was last time |
|
774 |
called */
|
|
775 |
||
776 |
/* Fields involved in checkpoints */
|
|
777 |
ulint log_group_capacity; /* capacity of the log group; if |
|
778 |
the checkpoint age exceeds this, it is
|
|
779 |
a serious error because it is possible
|
|
780 |
we will then overwrite log and spoil
|
|
781 |
crash recovery */
|
|
782 |
ulint max_modified_age_async; |
|
783 |
/* when this recommended value for lsn
|
|
784 |
- buf_pool_get_oldest_modification()
|
|
785 |
is exceeded, we start an asynchronous
|
|
786 |
preflush of pool pages */
|
|
787 |
ulint max_modified_age_sync; |
|
788 |
/* when this recommended value for lsn
|
|
789 |
- buf_pool_get_oldest_modification()
|
|
790 |
is exceeded, we start a synchronous
|
|
791 |
preflush of pool pages */
|
|
792 |
ulint adm_checkpoint_interval; |
|
793 |
/* administrator-specified checkpoint
|
|
794 |
interval in terms of log growth in
|
|
795 |
bytes; the interval actually used by
|
|
796 |
the database can be smaller */
|
|
797 |
ulint max_checkpoint_age_async; |
|
798 |
/* when this checkpoint age is exceeded
|
|
799 |
we start an asynchronous writing of a
|
|
800 |
new checkpoint */
|
|
801 |
ulint max_checkpoint_age; |
|
802 |
/* this is the maximum allowed value
|
|
803 |
for lsn - last_checkpoint_lsn when a
|
|
804 |
new query step is started */
|
|
805 |
dulint next_checkpoint_no; |
|
806 |
/* next checkpoint number */
|
|
807 |
dulint last_checkpoint_lsn; |
|
808 |
/* latest checkpoint lsn */
|
|
809 |
dulint next_checkpoint_lsn; |
|
810 |
/* next checkpoint lsn */
|
|
811 |
ulint n_pending_checkpoint_writes; |
|
812 |
/* number of currently pending
|
|
813 |
checkpoint writes */
|
|
814 |
rw_lock_t checkpoint_lock;/* this latch is x-locked when a |
|
815 |
checkpoint write is running; a thread
|
|
816 |
should wait for this without owning
|
|
817 |
the log mutex */
|
|
818 |
byte* checkpoint_buf; /* checkpoint header is read to this |
|
819 |
buffer */
|
|
820 |
/* Fields involved in archiving */
|
|
821 |
ulint archiving_state;/* LOG_ARCH_ON, LOG_ARCH_STOPPING |
|
822 |
LOG_ARCH_STOPPED, LOG_ARCH_OFF */
|
|
823 |
dulint archived_lsn; /* archiving has advanced to this |
|
824 |
lsn */
|
|
825 |
ulint max_archived_lsn_age_async; |
|
826 |
/* recommended maximum age of
|
|
827 |
archived_lsn, before we start
|
|
828 |
asynchronous copying to the archive */
|
|
829 |
ulint max_archived_lsn_age; |
|
830 |
/* maximum allowed age for
|
|
831 |
archived_lsn */
|
|
832 |
dulint next_archived_lsn;/* during an archive write, |
|
833 |
until the write is completed, we
|
|
834 |
store the next value for
|
|
835 |
archived_lsn here: the write
|
|
836 |
completion function then sets the new
|
|
837 |
value to archived_lsn */
|
|
838 |
ulint archiving_phase;/* LOG_ARCHIVE_READ or |
|
839 |
LOG_ARCHIVE_WRITE */
|
|
840 |
ulint n_pending_archive_ios; |
|
841 |
/* number of currently pending reads
|
|
842 |
or writes in archiving */
|
|
843 |
rw_lock_t archive_lock; /* this latch is x-locked when an |
|
844 |
archive write is running; a thread
|
|
845 |
should wait for this without owning
|
|
846 |
the log mutex */
|
|
847 |
ulint archive_buf_size;/* size of archive_buf */ |
|
848 |
byte* archive_buf; /* log segment is written to the |
|
849 |
archive from this buffer */
|
|
850 |
os_event_t archiving_on; /* if archiving has been stopped, |
|
851 |
a thread can wait for this event to
|
|
852 |
become signaled */
|
|
853 |
};
|
|
854 |
||
855 |
#define LOG_ARCH_ON 71
|
|
856 |
#define LOG_ARCH_STOPPING 72
|
|
857 |
#define LOG_ARCH_STOPPING2 73
|
|
858 |
#define LOG_ARCH_STOPPED 74
|
|
859 |
#define LOG_ARCH_OFF 75
|
|
860 |
||
861 |
#ifndef UNIV_NONINL
|
|
862 |
#include "log0log.ic" |
|
863 |
#endif
|
|
864 |
||
865 |
#endif
|