1 /*****************************************************************************
2 
3 Copyright (c) 2011-2012, Percona Inc. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15 Street, Fifth Floor, Boston, MA 02110-1301, USA
16 
17 *****************************************************************************/
18 
19 /**************************************************//**
20 @file include/log0online.h
21 Online database log parsing for changed page tracking
22 *******************************************************/
23 
24 #ifndef log0online_h
25 #define log0online_h
26 
27 #include "univ.i"
28 #include "os0file.h"
29 #include "log0log.h"
30 
31 /** Single bitmap file information */
32 typedef struct log_online_bitmap_file_struct log_online_bitmap_file_t;
33 
34 /** A set of bitmap files containing some LSN range */
35 typedef struct log_online_bitmap_file_range_struct
36 log_online_bitmap_file_range_t;
37 
38 /** An iterator over changed page info */
39 typedef struct log_bitmap_iterator_struct log_bitmap_iterator_t;
40 
41 /** Initialize the constant part of the log tracking subsystem */
42 UNIV_INTERN
43 void
44 log_online_init(void);
45 
46 /** Initialize the dynamic part of the log tracking subsystem */
47 UNIV_INTERN
48 void
49 log_online_read_init(void);
50 
51 /** Shut down the dynamic part of the log tracking subsystem */
52 UNIV_INTERN
53 void
54 log_online_read_shutdown(void);
55 
56 /** Shut down the constant part of the log tracking subsystem */
57 UNIV_INTERN
58 void
59 log_online_shutdown(void);
60 
61 /*********************************************************************//**
62 Reads and parses the redo log up to last checkpoint LSN to build the changed
63 page bitmap which is then written to disk.
64 
65 @return TRUE if log tracking succeeded, FALSE if bitmap write I/O error */
66 UNIV_INTERN
67 ibool
68 log_online_follow_redo_log(void);
69 /*=============================*/
70 
71 /************************************************************//**
72 Delete all the bitmap files for data less than the specified LSN.
73 If called with lsn == 0 (i.e. set by RESET request) or
74 IB_ULONGLONG_MAX, restart the bitmap file sequence, otherwise
75 continue it.
76 
77 @return FALSE to indicate success, TRUE for failure. */
78 UNIV_INTERN
79 ibool
80 log_online_purge_changed_page_bitmaps(
81 /*==================================*/
82 	lsn_t lsn);	/*!<in: LSN to purge files up to */
83 
84 #define LOG_BITMAP_ITERATOR_START_LSN(i) \
85 	((i).start_lsn)
86 #define LOG_BITMAP_ITERATOR_END_LSN(i) \
87 	((i).end_lsn)
88 #define LOG_BITMAP_ITERATOR_SPACE_ID(i) \
89 	((i).space_id)
90 #define LOG_BITMAP_ITERATOR_PAGE_NUM(i) \
91 	((i).first_page_id + (i).bit_offset)
92 #define LOG_BITMAP_ITERATOR_PAGE_CHANGED(i) \
93 	((i).changed)
94 
95 /*********************************************************************//**
96 Initializes log bitmap iterator.  The minimum LSN is used for finding the
97 correct starting file with records and it there may be records returned by
98 the iterator that have LSN less than start_lsn.
99 
100 @return TRUE if the iterator is initialized OK, FALSE otherwise. */
101 UNIV_INTERN
102 ibool
103 log_online_bitmap_iterator_init(
104 /*============================*/
105 	log_bitmap_iterator_t	*i,		/*!<in/out:  iterator */
106 	lsn_t			min_lsn,	/*!<in: start LSN for the
107 						iterator */
108 	lsn_t			max_lsn);	/*!<in: end LSN for the
109 						iterator */
110 
111 /*********************************************************************//**
112 Releases log bitmap iterator. */
113 UNIV_INTERN
114 void
115 log_online_bitmap_iterator_release(
116 /*===============================*/
117 	log_bitmap_iterator_t *i); /*!<in/out:  iterator */
118 
119 /*********************************************************************//**
120 Iterates through bits of saved bitmap blocks.
121 Sequentially reads blocks from bitmap file(s) and interates through
122 their bits. Ignores blocks with wrong checksum.
123 @return TRUE if iteration is successful, FALSE if all bits are iterated. */
124 UNIV_INTERN
125 ibool
126 log_online_bitmap_iterator_next(
127 /*============================*/
128 	log_bitmap_iterator_t *i); /*!<in/out: iterator */
129 
130 /** Struct for single bitmap file information */
131 struct log_online_bitmap_file_struct {
132 	/** Name with full path
133 	    61 is a nice magic constant for the extra space needed for the sprintf
134 	    template in the cc file
135 	*/
136 	char		name[FN_REFLEN+61];
137 	pfs_os_file_t	file;			/*!< Handle to opened file */
138 	ib_uint64_t	size;			/*!< Size of the file */
139 	os_offset_t	offset;			/*!< Offset of the next read,
140 						or count of already-read bytes
141 						*/
142 };
143 
144 /** Struct for a set of bitmap files containing some LSN range */
145 struct log_online_bitmap_file_range_struct {
146 	size_t	count;					/*!< Number of files */
147 	/*!< Dynamically-allocated array of info about individual files */
148 	struct files_t {
149 		char	name[FN_REFLEN];	/*!< Name of a file */
150 		lsn_t	start_lsn;		/*!< Starting LSN of data in
151 						this file */
152 		ulong	seq_num;		/*!< Sequence number of	this
153 						file */
154 	}	*files;
155 };
156 
157 /** Struct for an iterator through all bits of changed pages bitmap blocks */
158 struct log_bitmap_iterator_struct
159 {
160 	lsn_t				max_lsn;	/*!< End LSN of the
161 							range */
162 	ibool				failed;		/*!< Has the iteration
163 							stopped prematurely */
164 	log_online_bitmap_file_range_t	in_files;	/*!< The bitmap files
165 							for this iterator */
166 	size_t				in_i;		/*!< Currently read
167 							file index in in_files
168 							*/
169 	log_online_bitmap_file_t	in;		/*!< Currently read
170 							file */
171 	ib_uint32_t			bit_offset;	/*!< bit offset inside
172 							the current bitmap
173 							block */
174 	lsn_t				start_lsn;	/*!< Start LSN of the
175 							current bitmap block */
176 	lsn_t				end_lsn;	/*!< End LSN of the
177 							current bitmap block */
178 	ib_uint32_t			space_id;	/*!< Current block
179 							space id */
180 	ib_uint32_t			first_page_id;	/*!< Id of the first
181 							page in the current
182 							block */
183 	ibool				last_page_in_run;/*!< "Last page in
184 							run" flag value for the
185 							current block */
186 	ibool				changed;	/*!< true if current
187 							page was changed */
188 	byte*				page;		/*!< Bitmap block */
189 };
190 
191 #endif
192