Drizzled Public API Documentation

log0log.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4 Copyright (C) 2009 Google Inc.
5 
6 Portions of this file contain modifications contributed and copyrighted by
7 Google, Inc. Those modifications are gratefully acknowledged and are described
8 briefly in the InnoDB documentation. The contributions by Google are
9 incorporated with their permission, and subject to the conditions contained in
10 the file COPYING.Google.
11 
12 This program is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free Software
14 Foundation; version 2 of the License.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22 St, Fifth Floor, Boston, MA 02110-1301 USA
23 
24 *****************************************************************************/
25 
26 /**************************************************/
33 #pragma once
34 #ifndef log0log_h
35 #define log0log_h
36 
37 #include "univ.i"
38 #include "ut0byte.h"
39 #include "ut0lst.h"
40 #ifndef UNIV_HOTBACKUP
41 #include "sync0sync.h"
42 #include "sync0rw.h"
43 #endif /* !UNIV_HOTBACKUP */
44 
46 typedef struct log_struct log_t;
49 
50 #ifdef UNIV_DEBUG
51 
52 extern ibool log_do_write;
54 extern ibool log_debug_writes;
55 #else /* UNIV_DEBUG */
56 
57 # define log_do_write TRUE
58 #endif /* UNIV_DEBUG */
59 
61 #define LOG_NO_WAIT 91
62 #define LOG_WAIT_ONE_GROUP 92
63 #define LOG_WAIT_ALL_GROUPS 93
64 /* @} */
66 #define LOG_MAX_N_GROUPS 32
67 
68 #ifndef UNIV_HOTBACKUP
69 /****************************************************************/
73 UNIV_INTERN
74 void
76 /*==========================================*/
77  ulint limit);
78 #endif /* !UNIV_HOTBACKUP */
79 /*******************************************************************/
82 UNIV_INTERN
83 ulint
85 /*==================*/
86  ib_int64_t* log_file_offset,
88  ib_uint64_t first_header_lsn,
90  ib_uint64_t lsn,
92  ulint n_log_files,
94  ib_int64_t log_file_size);
96 #ifndef UNIV_HOTBACKUP
97 /************************************************************/
101 UNIV_INLINE
102 ib_uint64_t
104 /*=======================*/
105  const void* str,
106  ulint len,
107  ib_uint64_t* start_lsn);
108 /***********************************************************************/
110 UNIV_INLINE
111 void
112 log_release(void);
113 /*=============*/
114 /***********************************************************************/
119 UNIV_INLINE
120 void
121 log_free_check(void);
122 /*================*/
123 /************************************************************/
127 UNIV_INTERN
128 ib_uint64_t
130 /*=================*/
131  ulint len);
132 /************************************************************/
135 UNIV_INTERN
136 void
138 /*==========*/
139  byte* str,
140  ulint str_len);
141 /************************************************************/
144 UNIV_INTERN
145 ib_uint64_t
146 log_close(void);
147 /*===========*/
148 /************************************************************/
151 UNIV_INLINE
152 ib_uint64_t
153 log_get_lsn(void);
154 /*=============*/
155 /****************************************************************
156 Gets the log group capacity. It is OK to read the value without
157 holding log_sys->mutex because it is constant.
158 @return log group capacity */
159 UNIV_INLINE
160 ulint
161 log_get_capacity(void);
162 /*==================*/
163 /******************************************************/
165 UNIV_INTERN
166 void
167 log_init(void);
168 /*==========*/
169 /******************************************************************/
171 UNIV_INTERN
172 void
174 /*===========*/
175  ulint id,
176  ulint n_files,
177  ulint file_size,
178  ulint space_id,
181  ulint archive_space_id);
186 /******************************************************/
188 UNIV_INTERN
189 void
191 /*============*/
192  log_group_t* group);
193 /******************************************************/
198 UNIV_INTERN
199 void
201 /*============*/
202  ib_uint64_t lsn,
205  ulint wait,
207  ibool flush_to_disk);
210 /****************************************************************/
212 UNIV_INTERN
213 void
215 /*==========================*/
216 /****************************************************************/
221 UNIV_INTERN
222 void
224 /*==========================*/
225  ibool flush); /*<! in: flush the logs to disk */
226 /****************************************************************/
232 UNIV_INTERN
233 ibool
235 /*=============================*/
236  ib_uint64_t new_oldest,
239  ibool sync);
241 /******************************************************/
247 UNIV_INTERN
248 ibool
250 /*===========*/
251  ibool sync,
253  ibool write_always);
259 /****************************************************************/
261 UNIV_INTERN
262 void
264 /*===================*/
265  ib_uint64_t lsn,
268  ibool write_always);
275 /****************************************************************/
280 UNIV_INTERN
281 void
283 /*=======================================*/
284 /******************************************************/
286 UNIV_INTERN
287 void
289 /*===========================*/
290  log_group_t* group,
291  ulint field);
292 /*******************************************************************/
294 UNIV_INTERN
295 void
297 /*==============================*/
298  const byte* buf,
299  ulint n,
300  ulint* file_no,
301  ulint* offset);
302 /******************************************************/
304 UNIV_INTERN
305 void
307 /*==================================*/
308 /********************************************************************/
311 UNIV_INTERN
312 ibool
314 /*===========*/
315  ibool sync,
316  ulint* n_bytes);
318 /****************************************************************/
325 UNIV_INTERN
326 ulint
327 log_archive_stop(void);
328 /*==================*/
329 /****************************************************************/
332 UNIV_INTERN
333 ulint
334 log_archive_start(void);
335 /*===================*/
336 /****************************************************************/
339 UNIV_INTERN
340 ulint
342 /*==========================*/
343 /****************************************************************/
346 UNIV_INTERN
347 ulint
349 /*========================*/
350 /******************************************************/
352 UNIV_INTERN
353 void
355 /*=======================*/
356  char* buf,
357  ulint id,
358  ulint file_no);
359 #else /* !UNIV_HOTBACKUP */
360 /******************************************************/
363 UNIV_INTERN
364 void
365 log_reset_first_header_and_checkpoint(
366 /*==================================*/
367  byte* hdr_buf,
369  ib_uint64_t start);
372 #endif /* !UNIV_HOTBACKUP */
373 /********************************************************************/
378 UNIV_INTERN
379 void
380 log_check_margins(void);
381 /*===================*/
382 #ifndef UNIV_HOTBACKUP
383 /******************************************************/
385 UNIV_INTERN
386 void
388 /*===================*/
389  ulint type,
390  byte* buf,
391  log_group_t* group,
392  ib_uint64_t start_lsn,
393  ib_uint64_t end_lsn);
394 /******************************************************/
396 UNIV_INTERN
397 void
399 /*================*/
400  log_group_t* group,
401  byte* buf,
402  ulint len,
404  ib_uint64_t start_lsn,
407  ulint new_data_offset);
411 /********************************************************/
415 UNIV_INTERN
416 void
418 /*=================*/
419  log_group_t* group,
420  ib_uint64_t lsn);
422 /******************************************************/
426 UNIV_INTERN
427 ulint
429 /*===================*/
430  const log_group_t* group);
431 #endif /* !UNIV_HOTBACKUP */
432 /************************************************************/
435 UNIV_INLINE
436 ibool
438 /*====================*/
439  const byte* log_block);
440 /************************************************************/
443 UNIV_INLINE
444 ulint
446 /*=================*/
447  const byte* log_block);
448 /************************************************************/
451 UNIV_INLINE
452 ulint
454 /*===================*/
455  const byte* log_block);
456 /************************************************************/
458 UNIV_INLINE
459 void
461 /*===================*/
462  byte* log_block,
463  ulint len);
464 /************************************************************/
467 UNIV_INLINE
468 ulint
470 /*====================*/
471  const byte* block);
472 /************************************************************/
475 UNIV_INLINE
476 ulint
478 /*===================*/
479  const byte* log_block);
480 /************************************************************/
482 UNIV_INLINE
483 void
485 /*===================*/
486  byte* log_block,
487  ulint checksum);
488 /************************************************************/
492 UNIV_INLINE
493 ulint
495 /*==========================*/
496  const byte* log_block);
497 /************************************************************/
499 UNIV_INLINE
500 void
502 /*==========================*/
503  byte* log_block,
504  ulint offset);
505 /************************************************************/
508 UNIV_INLINE
509 ulint
511 /*========================*/
512  const byte* log_block);
513 /************************************************************/
515 UNIV_INLINE
516 void
518 /*===========*/
519  byte* log_block,
520  ib_uint64_t lsn);
521 /************************************************************/
524 UNIV_INLINE
525 void
527 /*=========================*/
528  byte* log_block,
529  ib_uint64_t lsn);
530 /************************************************************/
533 UNIV_INLINE
534 ulint
536 /*========================*/
537  ib_uint64_t lsn);
538 /******************************************************/
540 UNIV_INTERN
541 void
542 log_print(
543 /*======*/
544  FILE* file);
545 /******************************************************/
548 UNIV_INTERN
549 ibool
551 /*=========*/
552  ib_uint64_t* lsn);
553 /**********************************************************************/
555 UNIV_INTERN
556 void
557 log_refresh_stats(void);
558 /*===================*/
559 /**********************************************************
560 Shutdown the log system but do not release all the memory. */
561 UNIV_INTERN
562 void
563 log_shutdown(void);
564 /*==============*/
565 /**********************************************************
566 Free the log system data structures. */
567 UNIV_INTERN
568 void
569 log_mem_free(void);
570 /*==============*/
571 
572 extern log_t* log_sys;
573 
574 /* Values used as flags */
575 #define LOG_FLUSH 7652559
576 #define LOG_CHECKPOINT 78656949
577 #ifdef UNIV_LOG_ARCHIVE
578 # define LOG_ARCHIVE 11122331
579 #endif /* UNIV_LOG_ARCHIVE */
580 #define LOG_RECOVER 98887331
581 
582 /* The counting of lsn's starts from this value: this must be non-zero */
583 #define LOG_START_LSN ((ib_uint64_t) (16 * OS_FILE_LOG_BLOCK_SIZE))
584 
585 #define LOG_BUFFER_SIZE (srv_log_buffer_size * UNIV_PAGE_SIZE)
586 #define LOG_ARCHIVE_BUF_SIZE (srv_log_buffer_size * UNIV_PAGE_SIZE / 4)
587 
588 /* Offsets of a log block header */
589 #define LOG_BLOCK_HDR_NO 0 /* block number which must be > 0 and
590  is allowed to wrap around at 2G; the
591  highest bit is set to 1 if this is the
592  first log block in a log flush write
593  segment */
594 #define LOG_BLOCK_FLUSH_BIT_MASK 0x80000000UL
595  /* mask used to get the highest bit in
596  the preceding field */
597 #define LOG_BLOCK_HDR_DATA_LEN 4 /* number of bytes of log written to
598  this block */
599 #define LOG_BLOCK_FIRST_REC_GROUP 6 /* offset of the first start of an
600  mtr log record group in this log block,
601  0 if none; if the value is the same
602  as LOG_BLOCK_HDR_DATA_LEN, it means
603  that the first rec group has not yet
604  been catenated to this log block, but
605  if it will, it will start at this
606  offset; an archive recovery can
607  start parsing the log records starting
608  from this offset in this log block,
609  if value not 0 */
610 #define LOG_BLOCK_CHECKPOINT_NO 8 /* 4 lower bytes of the value of
611  log_sys->next_checkpoint_no when the
612  log block was last written to: if the
613  block has not yet been written full,
614  this value is only updated before a
615  log buffer flush */
616 #define LOG_BLOCK_HDR_SIZE 12 /* size of the log block header in
617  bytes */
618 
619 /* Offsets of a log block trailer from the end of the block */
620 #define LOG_BLOCK_CHECKSUM 4 /* 4 byte checksum of the log block
621  contents; in InnoDB versions
622  < 3.23.52 this did not contain the
623  checksum but the same value as
624  .._HDR_NO */
625 #define LOG_BLOCK_TRL_SIZE 4 /* trailer size in bytes */
626 
627 /* Offsets for a checkpoint field */
628 #define LOG_CHECKPOINT_NO 0
629 #define LOG_CHECKPOINT_LSN 8
630 #define LOG_CHECKPOINT_OFFSET 16
631 #define LOG_CHECKPOINT_LOG_BUF_SIZE 20
632 #define LOG_CHECKPOINT_ARCHIVED_LSN 24
633 #define LOG_CHECKPOINT_GROUP_ARRAY 32
634 
635 /* For each value smaller than LOG_MAX_N_GROUPS the following 8 bytes: */
636 
637 #define LOG_CHECKPOINT_ARCHIVED_FILE_NO 0
638 #define LOG_CHECKPOINT_ARCHIVED_OFFSET 4
639 
640 #define LOG_CHECKPOINT_ARRAY_END (LOG_CHECKPOINT_GROUP_ARRAY\
641  + LOG_MAX_N_GROUPS * 8)
642 #define LOG_CHECKPOINT_CHECKSUM_1 LOG_CHECKPOINT_ARRAY_END
643 #define LOG_CHECKPOINT_CHECKSUM_2 (4 + LOG_CHECKPOINT_ARRAY_END)
644 #define LOG_CHECKPOINT_FSP_FREE_LIMIT (8 + LOG_CHECKPOINT_ARRAY_END)
645  /* current fsp free limit in
646  tablespace 0, in units of one
647  megabyte; this information is only used
648  by ibbackup to decide if it can
649  truncate unused ends of
650  non-auto-extending data files in space
651  0 */
652 #define LOG_CHECKPOINT_FSP_MAGIC_N (12 + LOG_CHECKPOINT_ARRAY_END)
653  /* this magic number tells if the
654  checkpoint contains the above field:
655  the field was added to
656  InnoDB-3.23.50 */
657 #define LOG_CHECKPOINT_SIZE (16 + LOG_CHECKPOINT_ARRAY_END)
658 
659 #define LOG_CHECKPOINT_FSP_MAGIC_N_VAL 1441231243
660 
661 /* Offsets of a log file header */
662 #define LOG_GROUP_ID 0 /* log group number */
663 #define LOG_FILE_START_LSN 4 /* lsn of the start of data in this
664  log file */
665 #define LOG_FILE_NO 12 /* 4-byte archived log file number;
666  this field is only defined in an
667  archived log file */
668 #define LOG_FILE_WAS_CREATED_BY_HOT_BACKUP 16
669  /* a 32-byte field which contains
670  the string 'ibbackup' and the
671  creation time if the log file was
672  created by ibbackup --restore;
673  when mysqld is first time started
674  on the restored database, it can
675  print helpful info for the user */
676 #define LOG_FILE_OS_FILE_LOG_BLOCK_SIZE 64
677  /* The log_block_size of XtraDB.
678  0 means default 512. */
679 #define LOG_FILE_ARCH_COMPLETED OS_FILE_LOG_BLOCK_SIZE
680  /* this 4-byte field is TRUE when
681  the writing of an archived log file
682  has been completed; this field is
683  only defined in an archived log file */
684 #define LOG_FILE_END_LSN (OS_FILE_LOG_BLOCK_SIZE + 4)
685  /* lsn where the archived log file
686  at least extends: actually the
687  archived log file may extend to a
688  later lsn, as long as it is within the
689  same log block as this lsn; this field
690  is defined only when an archived log
691  file has been completely written */
692 #define LOG_CHECKPOINT_1 OS_FILE_LOG_BLOCK_SIZE
693  /* first checkpoint field in the log
694  header; we write alternately to the
695  checkpoint fields when we make new
696  checkpoints; this field is only defined
697  in the first log file of a log group */
698 #define LOG_CHECKPOINT_2 (3 * OS_FILE_LOG_BLOCK_SIZE)
699  /* second checkpoint field in the log
700  header */
701 #define LOG_FILE_HDR_SIZE (4 * OS_FILE_LOG_BLOCK_SIZE)
702 
703 #define LOG_GROUP_OK 301
704 #define LOG_GROUP_CORRUPTED 302
705 
709  /* The following fields are protected by log_sys->mutex */
710  ulint id;
711  ulint n_files;
712  ulint file_size;
714  ulint space_id;
716  ulint state;
718  ib_uint64_t lsn;
720  ulint lsn_offset;
726 #ifdef UNIV_LOG_ARCHIVE
727  /*-----------------------------*/
728  byte** archive_file_header_bufs_ptr;
729  byte** archive_file_header_bufs;
731  ulint archive_space_id;
734  ulint archived_file_no;
736  ulint archived_offset;
740  ulint next_archived_file_no;
746  ulint next_archived_offset;
747 #endif /* UNIV_LOG_ARCHIVE */
748  /*-----------------------------*/
749  ib_uint64_t scanned_lsn;
757 };
758 
760 struct log_struct{
761  byte pad[64];
764  ib_uint64_t lsn;
765  ulint buf_free;
767 #ifndef UNIV_HOTBACKUP
769 #endif /* !UNIV_HOTBACKUP */
770 
779  byte* buf_ptr; /* unaligned log buffer */
780  byte* buf;
781  ulint buf_size;
782  ulint max_buf_free;
785  ulint old_buf_free;
788  ib_uint64_t old_lsn;
803 #ifndef UNIV_HOTBACKUP
804 
813  ib_uint64_t written_to_some_lsn;
819  ib_uint64_t written_to_all_lsn;
835  ib_uint64_t write_lsn;
842  ib_uint64_t current_flush_lsn;
844  ib_uint64_t flushed_to_disk_lsn;
849  /* NOTE on the 'flush' in names of the fields below: starting from
850  4.0.14, we separate the write of the log file and the actual fsync()
851  or other method to flush it to disk. The names below shhould really
852  be 'flush_or_write'! */
859  ibool one_flushed;
872  ulint n_log_ios;
878  /* @} */
879 
912  ib_uint64_t next_checkpoint_no;
914  ib_uint64_t last_checkpoint_lsn;
916  ib_uint64_t next_checkpoint_lsn;
925 #endif /* !UNIV_HOTBACKUP */
926  byte* checkpoint_buf_ptr;/* unaligned checkpoint header */
929  /* @} */
930 #ifdef UNIV_LOG_ARCHIVE
931 
932  ulint archiving_state;
934  ib_uint64_t archived_lsn;
936  ulint max_archived_lsn_age_async;
940  ulint max_archived_lsn_age;
943  ib_uint64_t next_archived_lsn;
949  ulint archiving_phase;
951  ulint n_pending_archive_ios;
954  rw_lock_t archive_lock;
958  ulint archive_buf_size;
959  byte* archive_buf;
961  os_event_t archiving_on;
964  /* @} */
965 #endif /* UNIV_LOG_ARCHIVE */
966 };
967 
969 #define log_flush_order_mutex_own() \
970  mutex_own(&log_sys->log_flush_order_mutex)
971 
973 #define log_flush_order_mutex_enter() do { \
974  mutex_enter(&log_sys->log_flush_order_mutex); \
975 } while (0)
976 
977 # define log_flush_order_mutex_exit() do { \
978  mutex_exit(&log_sys->log_flush_order_mutex); \
979 } while (0)
980 
981 #ifdef UNIV_LOG_ARCHIVE
982 
983 #define LOG_ARCH_ON 71
984 #define LOG_ARCH_STOPPING 72
985 #define LOG_ARCH_STOPPING2 73
986 #define LOG_ARCH_STOPPED 74
987 #define LOG_ARCH_OFF 75
988 /* @} */
989 #endif /* UNIV_LOG_ARCHIVE */
990 
991 #ifndef UNIV_NONINL
992 #include "log0log.ic"
993 #endif
994 
995 #endif