summaryrefslogtreecommitdiff
path: root/storage/xtradb/include/log0online.h
blob: 2d1febe9b9fc81b8bc9430c45d78dc699b20594b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*****************************************************************************

Copyright (c) 2011-2012, Percona Inc. All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA

*****************************************************************************/

/**************************************************//**
@file include/log0online.h
Online database log parsing for changed page tracking
*******************************************************/

#ifndef log0online_h
#define log0online_h

#include "univ.i"
#include "os0file.h"
#include "log0log.h"

/** Single bitmap file information */
typedef struct log_online_bitmap_file_struct log_online_bitmap_file_t;

/** A set of bitmap files containing some LSN range */
typedef struct log_online_bitmap_file_range_struct
log_online_bitmap_file_range_t;

/** An iterator over changed page info */
typedef struct log_bitmap_iterator_struct log_bitmap_iterator_t;

/** Initialize the constant part of the log tracking subsystem */
UNIV_INTERN
void
log_online_init(void);

/** Initialize the dynamic part of the log tracking subsystem */
UNIV_INTERN
void
log_online_read_init(void);

/** Shut down the dynamic part of the log tracking subsystem */
UNIV_INTERN
void
log_online_read_shutdown(void);

/** Shut down the constant part of the log tracking subsystem */
UNIV_INTERN
void
log_online_shutdown(void);

/*********************************************************************//**
Reads and parses the redo log up to last checkpoint LSN to build the changed
page bitmap which is then written to disk.

@return TRUE if log tracking succeeded, FALSE if bitmap write I/O error */
UNIV_INTERN
ibool
log_online_follow_redo_log(void);
/*=============================*/

/************************************************************//**
Delete all the bitmap files for data less than the specified LSN.
If called with lsn == 0 (i.e. set by RESET request) or
IB_ULONGLONG_MAX, restart the bitmap file sequence, otherwise
continue it.

@return FALSE to indicate success, TRUE for failure. */
UNIV_INTERN
ibool
log_online_purge_changed_page_bitmaps(
/*==================================*/
	lsn_t lsn);	/*!<in: LSN to purge files up to */

#define LOG_BITMAP_ITERATOR_START_LSN(i) \
	((i).start_lsn)
#define LOG_BITMAP_ITERATOR_END_LSN(i) \
	((i).end_lsn)
#define LOG_BITMAP_ITERATOR_SPACE_ID(i) \
	((i).space_id)
#define LOG_BITMAP_ITERATOR_PAGE_NUM(i) \
	((i).first_page_id + (i).bit_offset)
#define LOG_BITMAP_ITERATOR_PAGE_CHANGED(i) \
	((i).changed)

/*********************************************************************//**
Initializes log bitmap iterator.  The minimum LSN is used for finding the
correct starting file with records and it there may be records returned by
the iterator that have LSN less than start_lsn.

@return TRUE if the iterator is initialized OK, FALSE otherwise. */
UNIV_INTERN
ibool
log_online_bitmap_iterator_init(
/*============================*/
	log_bitmap_iterator_t	*i,		/*!<in/out:  iterator */
	lsn_t			min_lsn,	/*!<in: start LSN for the
						iterator */
	lsn_t			max_lsn);	/*!<in: end LSN for the
						iterator */

/*********************************************************************//**
Releases log bitmap iterator. */
UNIV_INTERN
void
log_online_bitmap_iterator_release(
/*===============================*/
	log_bitmap_iterator_t *i); /*!<in/out:  iterator */

/*********************************************************************//**
Iterates through bits of saved bitmap blocks.
Sequentially reads blocks from bitmap file(s) and interates through
their bits. Ignores blocks with wrong checksum.
@return TRUE if iteration is successful, FALSE if all bits are iterated. */
UNIV_INTERN
ibool
log_online_bitmap_iterator_next(
/*============================*/
	log_bitmap_iterator_t *i); /*!<in/out: iterator */

/** Struct for single bitmap file information */
struct log_online_bitmap_file_struct {
	/** Name with full path
	    61 is a nice magic constant for the extra space needed for the sprintf
	    template in the cc file
	*/
	char		name[FN_REFLEN+61];	/*!< Name with full path */
	pfs_os_file_t	file;			/*!< Handle to opened file */
	ib_uint64_t	size;			/*!< Size of the file */
	os_offset_t	offset;			/*!< Offset of the next read,
						or count of already-read bytes
						*/
};

/** Struct for a set of bitmap files containing some LSN range */
struct log_online_bitmap_file_range_struct {
	size_t	count;					/*!< Number of files */
	/*!< Dynamically-allocated array of info about individual files */
	struct files_t {
		char	name[FN_REFLEN];	/*!< Name of a file */
		lsn_t	start_lsn;		/*!< Starting LSN of data in
						this file */
		ulong	seq_num;		/*!< Sequence number of	this
						file */
	}	*files;
};

/** Struct for an iterator through all bits of changed pages bitmap blocks */
struct log_bitmap_iterator_struct
{
	lsn_t				max_lsn;	/*!< End LSN of the
							range */
	ibool				failed;		/*!< Has the iteration
							stopped prematurely */
	log_online_bitmap_file_range_t	in_files;	/*!< The bitmap files
							for this iterator */
	size_t				in_i;		/*!< Currently read
							file index in in_files
							*/
	log_online_bitmap_file_t	in;		/*!< Currently read
							file */
	ib_uint32_t			bit_offset;	/*!< bit offset inside
							the current bitmap
							block */
	lsn_t				start_lsn;	/*!< Start LSN of the
							current bitmap block */
	lsn_t				end_lsn;	/*!< End LSN of the
							current bitmap block */
	ib_uint32_t			space_id;	/*!< Current block
							space id */
	ib_uint32_t			first_page_id;	/*!< Id of the first
							page in the current
							block */
	ibool				last_page_in_run;/*!< "Last page in
							run" flag value for the
							current block */
	ibool				changed;	/*!< true if current
							page was changed */
	byte*				page;		/*!< Bitmap block */
};

#endif