53
54
#define MTR_MEMO_S_LOCK 55
54
55
#define MTR_MEMO_X_LOCK 56
56
/* Log item types: we have made them to be of the type 'byte'
57
for the compiler to warn if val and type parameters are switched
58
in a call to mlog_write_ulint. NOTE! For 1 - 8 bytes, the
59
flag value must give the length also! */
60
#define MLOG_SINGLE_REC_FLAG 128 /* if the mtr contains only
57
/** @name Log item types
58
The log items are declared 'byte' so that the compiler can warn if val
59
and type parameters are switched in a call to mlog_write_ulint. NOTE!
60
For 1 - 8 bytes, the flag value must give the length also! @{ */
61
#define MLOG_SINGLE_REC_FLAG 128 /*!< if the mtr contains only
61
62
one log record for one page,
62
63
i.e., write_initial_log_record
63
64
has been called only once,
64
65
this flag is ORed to the type
65
66
of that first log record */
66
#define MLOG_1BYTE (1) /* one byte is written */
67
#define MLOG_2BYTES (2) /* 2 bytes ... */
68
#define MLOG_4BYTES (4) /* 4 bytes ... */
69
#define MLOG_8BYTES (8) /* 8 bytes ... */
70
#define MLOG_REC_INSERT ((byte)9) /* record insert */
71
#define MLOG_REC_CLUST_DELETE_MARK ((byte)10) /* mark clustered index record
73
#define MLOG_REC_SEC_DELETE_MARK ((byte)11) /* mark secondary index record
75
#define MLOG_REC_UPDATE_IN_PLACE ((byte)13) /* update of a record,
67
#define MLOG_1BYTE (1) /*!< one byte is written */
68
#define MLOG_2BYTES (2) /*!< 2 bytes ... */
69
#define MLOG_4BYTES (4) /*!< 4 bytes ... */
70
#define MLOG_8BYTES (8) /*!< 8 bytes ... */
71
#define MLOG_REC_INSERT ((byte)9) /*!< record insert */
72
#define MLOG_REC_CLUST_DELETE_MARK ((byte)10) /*!< mark clustered index record
74
#define MLOG_REC_SEC_DELETE_MARK ((byte)11) /*!< mark secondary index record
76
#define MLOG_REC_UPDATE_IN_PLACE ((byte)13) /*!< update of a record,
76
77
preserves record field sizes */
77
#define MLOG_REC_DELETE ((byte)14) /* delete a record from a
78
#define MLOG_REC_DELETE ((byte)14) /*!< delete a record from a
79
#define MLOG_LIST_END_DELETE ((byte)15) /* delete record list end on
81
#define MLOG_LIST_START_DELETE ((byte)16) /* delete record list start on
83
#define MLOG_LIST_END_COPY_CREATED ((byte)17) /* copy record list end to a
80
#define MLOG_LIST_END_DELETE ((byte)15) /*!< delete record list end on
82
#define MLOG_LIST_START_DELETE ((byte)16) /*!< delete record list start on
84
#define MLOG_LIST_END_COPY_CREATED ((byte)17) /*!< copy record list end to a
84
85
new created index page */
85
#define MLOG_PAGE_REORGANIZE ((byte)18) /* reorganize an index page */
86
#define MLOG_PAGE_CREATE ((byte)19) /* create an index page */
87
#define MLOG_UNDO_INSERT ((byte)20) /* insert entry in an undo
86
#define MLOG_PAGE_REORGANIZE ((byte)18) /*!< reorganize an
88
ROW_FORMAT=REDUNDANT */
89
#define MLOG_PAGE_CREATE ((byte)19) /*!< create an index page */
90
#define MLOG_UNDO_INSERT ((byte)20) /*!< insert entry in an undo
89
#define MLOG_UNDO_ERASE_END ((byte)21) /* erase an undo log
92
#define MLOG_UNDO_ERASE_END ((byte)21) /*!< erase an undo log
91
#define MLOG_UNDO_INIT ((byte)22) /* initialize a page in an
94
#define MLOG_UNDO_INIT ((byte)22) /*!< initialize a page in an
93
#define MLOG_UNDO_HDR_DISCARD ((byte)23) /* discard an update undo log
95
#define MLOG_UNDO_HDR_REUSE ((byte)24) /* reuse an insert undo log
97
#define MLOG_UNDO_HDR_CREATE ((byte)25) /* create an undo log header */
98
#define MLOG_REC_MIN_MARK ((byte)26) /* mark an index record as the
99
predefined minimum record */
100
#define MLOG_IBUF_BITMAP_INIT ((byte)27) /* initialize an ibuf bitmap
96
#define MLOG_UNDO_HDR_DISCARD ((byte)23) /*!< discard an update undo log
98
#define MLOG_UNDO_HDR_REUSE ((byte)24) /*!< reuse an insert undo log
100
#define MLOG_UNDO_HDR_CREATE ((byte)25) /*!< create an undo
102
#define MLOG_REC_MIN_MARK ((byte)26) /*!< mark an index
106
#define MLOG_IBUF_BITMAP_INIT ((byte)27) /*!< initialize an
102
108
/*#define MLOG_FULL_PAGE ((byte)28) full contents of a page */
103
#define MLOG_INIT_FILE_PAGE ((byte)29) /* this means that a file page
104
is taken into use and the prior
105
contents of the page should be
106
ignored: in recovery we must
107
not trust the lsn values stored
109
#define MLOG_WRITE_STRING ((byte)30) /* write a string to a page */
110
#define MLOG_MULTI_REC_END ((byte)31) /* if a single mtr writes
111
log records for several pages,
109
#ifdef UNIV_LOG_LSN_DEBUG
110
# define MLOG_LSN ((byte)28) /* current LSN */
112
#define MLOG_INIT_FILE_PAGE ((byte)29) /*!< this means that a
114
into use and the prior
116
should be ignored: in
121
#define MLOG_WRITE_STRING ((byte)30) /*!< write a string to
123
#define MLOG_MULTI_REC_END ((byte)31) /*!< if a single mtr writes
112
125
this log record ends the
113
126
sequence of these records */
114
#define MLOG_DUMMY_RECORD ((byte)32) /* dummy log record used to
127
#define MLOG_DUMMY_RECORD ((byte)32) /*!< dummy log record used to
115
128
pad a log block full */
116
#define MLOG_FILE_CREATE ((byte)33) /* log record about an .ibd
129
#define MLOG_FILE_CREATE ((byte)33) /*!< log record about an .ibd
118
#define MLOG_FILE_RENAME ((byte)34) /* log record about an .ibd
131
#define MLOG_FILE_RENAME ((byte)34) /*!< log record about an .ibd
120
#define MLOG_FILE_DELETE ((byte)35) /* log record about an .ibd
133
#define MLOG_FILE_DELETE ((byte)35) /*!< log record about an .ibd
122
#define MLOG_COMP_REC_MIN_MARK ((byte)36) /* mark a compact index record
123
as the predefined minimum
135
#define MLOG_COMP_REC_MIN_MARK ((byte)36) /*!< mark a compact
125
#define MLOG_COMP_PAGE_CREATE ((byte)37) /* create a compact
139
#define MLOG_COMP_PAGE_CREATE ((byte)37) /*!< create a compact
127
#define MLOG_COMP_REC_INSERT ((byte)38) /* compact record insert */
141
#define MLOG_COMP_REC_INSERT ((byte)38) /*!< compact record insert */
128
142
#define MLOG_COMP_REC_CLUST_DELETE_MARK ((byte)39)
129
/* mark compact clustered index
131
#define MLOG_COMP_REC_SEC_DELETE_MARK ((byte)40)/* mark compact secondary index
132
record deleted; this log
133
record type is redundant, as
134
MLOG_REC_SEC_DELETE_MARK is
135
independent of the record
137
#define MLOG_COMP_REC_UPDATE_IN_PLACE ((byte)41)/* update of a compact record,
138
preserves record field sizes */
139
#define MLOG_COMP_REC_DELETE ((byte)42) /* delete a compact record
144
clustered index record
146
#define MLOG_COMP_REC_SEC_DELETE_MARK ((byte)40)/*!< mark compact
147
secondary index record
151
MLOG_REC_SEC_DELETE_MARK
152
is independent of the
154
#define MLOG_COMP_REC_UPDATE_IN_PLACE ((byte)41)/*!< update of a
156
preserves record field
158
#define MLOG_COMP_REC_DELETE ((byte)42) /*!< delete a compact record
141
#define MLOG_COMP_LIST_END_DELETE ((byte)43) /* delete compact record list
160
#define MLOG_COMP_LIST_END_DELETE ((byte)43) /*!< delete compact record list
142
161
end on index page */
143
#define MLOG_COMP_LIST_START_DELETE ((byte)44) /* delete compact record list
162
#define MLOG_COMP_LIST_START_DELETE ((byte)44) /*!< delete compact record list
144
163
start on index page */
145
164
#define MLOG_COMP_LIST_END_COPY_CREATED ((byte)45)
146
/* copy compact record list end
147
to a new created index page */
148
#define MLOG_COMP_PAGE_REORGANIZE ((byte)46) /* reorganize an index page */
149
#define MLOG_FILE_CREATE2 ((byte)47) /* log record about creating
169
#define MLOG_COMP_PAGE_REORGANIZE ((byte)46) /*!< reorganize an index page */
170
#define MLOG_FILE_CREATE2 ((byte)47) /*!< log record about creating
150
171
an .ibd file, with format */
151
#define MLOG_ZIP_WRITE_NODE_PTR ((byte)48) /* write the node pointer of
172
#define MLOG_ZIP_WRITE_NODE_PTR ((byte)48) /*!< write the node pointer of
152
173
a record on a compressed
153
174
non-leaf B-tree page */
154
#define MLOG_ZIP_WRITE_BLOB_PTR ((byte)49) /* write the BLOB pointer
175
#define MLOG_ZIP_WRITE_BLOB_PTR ((byte)49) /*!< write the BLOB pointer
155
176
of an externally stored column
156
177
on a compressed page */
157
#define MLOG_ZIP_WRITE_HEADER ((byte)50) /* write to compressed page
178
#define MLOG_ZIP_WRITE_HEADER ((byte)50) /*!< write to compressed page
159
#define MLOG_ZIP_PAGE_COMPRESS ((byte)51) /* compress an index page */
160
#define MLOG_BIGGEST_TYPE ((byte)51) /* biggest value (used in
163
/*******************************************************************
180
#define MLOG_ZIP_PAGE_COMPRESS ((byte)51) /*!< compress an index page */
181
#define MLOG_BIGGEST_TYPE ((byte)51) /*!< biggest value (used in
185
/** @name Flags for MLOG_FILE operations
186
(stored in the page number parameter, called log_flags in the
187
functions). The page number parameter was originally written as 0. @{ */
188
#define MLOG_FILE_FLAG_TEMP 1 /*!< identifies TEMPORARY TABLE in
189
MLOG_FILE_CREATE, MLOG_FILE_CREATE2 */
192
/***************************************************************//**
164
193
Starts a mini-transaction and creates a mini-transaction handle
165
and buffer in the memory buffer given by the caller. */
194
and buffer in the memory buffer given by the caller.
195
@return mtr buffer which also acts as the mtr handle */
170
/* out: mtr buffer which also acts as
172
mtr_t* mtr); /* in: memory buffer for the mtr buffer */
173
/*******************************************************************
200
mtr_t* mtr); /*!< in: memory buffer for the mtr buffer */
201
/***************************************************************//**
174
202
Commits a mini-transaction. */
179
mtr_t* mtr); /* in: mini-transaction */
180
/**************************************************************
181
Sets and returns a savepoint in mtr. */
207
mtr_t* mtr); /*!< in: mini-transaction */
208
/**********************************************************//**
209
Sets and returns a savepoint in mtr.
184
213
mtr_set_savepoint(
185
214
/*==============*/
187
mtr_t* mtr); /* in: mtr */
188
/**************************************************************
215
mtr_t* mtr); /*!< in: mtr */
216
/**********************************************************//**
189
217
Releases the latches stored in an mtr memo down to a savepoint.
190
218
NOTE! The mtr must not have made changes to buffer pages after the
191
219
savepoint, as these can be handled only by mtr_commit. */
194
222
mtr_rollback_to_savepoint(
195
223
/*======================*/
196
mtr_t* mtr, /* in: mtr */
197
ulint savepoint); /* in: savepoint */
198
/**************************************************************
224
mtr_t* mtr, /*!< in: mtr */
225
ulint savepoint); /*!< in: savepoint */
226
#ifndef UNIV_HOTBACKUP
227
/**********************************************************//**
199
228
Releases the (index tree) s-latch stored in an mtr memo after a
203
232
mtr_release_s_latch_at_savepoint(
204
233
/*=============================*/
205
mtr_t* mtr, /* in: mtr */
206
ulint savepoint, /* in: savepoint */
207
rw_lock_t* lock); /* in: latch to release */
208
/*******************************************************************
209
Gets the logging mode of a mini-transaction. */
234
mtr_t* mtr, /*!< in: mtr */
235
ulint savepoint, /*!< in: savepoint */
236
rw_lock_t* lock); /*!< in: latch to release */
237
#else /* !UNIV_HOTBACKUP */
238
# define mtr_release_s_latch_at_savepoint(mtr,savepoint,lock) ((void) 0)
239
#endif /* !UNIV_HOTBACKUP */
240
/***************************************************************//**
241
Gets the logging mode of a mini-transaction.
242
@return logging mode: MTR_LOG_NONE, ... */
212
245
mtr_get_log_mode(
213
246
/*=============*/
214
/* out: logging mode: MTR_LOG_NONE, ... */
215
mtr_t* mtr); /* in: mtr */
216
/*******************************************************************
217
Changes the logging mode of a mini-transaction. */
247
mtr_t* mtr); /*!< in: mtr */
248
/***************************************************************//**
249
Changes the logging mode of a mini-transaction.
220
253
mtr_set_log_mode(
221
254
/*=============*/
223
mtr_t* mtr, /* in: mtr */
224
ulint mode); /* in: logging mode: MTR_LOG_NONE, ... */
225
/************************************************************
226
Reads 1 - 4 bytes from a file page buffered in the buffer pool. */
255
mtr_t* mtr, /*!< in: mtr */
256
ulint mode); /*!< in: logging mode: MTR_LOG_NONE, ... */
257
/********************************************************//**
258
Reads 1 - 4 bytes from a file page buffered in the buffer pool.
259
@return value read */
231
/* out: value read */
232
const byte* ptr, /* in: pointer from where to read */
233
ulint type, /* in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
234
mtr_t* mtr); /* in: mini-transaction handle */
235
/************************************************************
236
Reads 8 bytes from a file page buffered in the buffer pool. */
241
/* out: value read */
242
const byte* ptr, /* in: pointer from where to read */
243
mtr_t* mtr); /* in: mini-transaction handle */
244
/*************************************************************************
264
const byte* ptr, /*!< in: pointer from where to read */
265
ulint type, /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
266
mtr_t* mtr); /*!< in: mini-transaction handle */
267
#ifndef UNIV_HOTBACKUP
268
/*********************************************************************//**
245
269
This macro locks an rw-lock in s-mode. */
246
270
#define mtr_s_lock(B, MTR) mtr_s_lock_func((B), __FILE__, __LINE__,\
248
/*************************************************************************
272
/*********************************************************************//**
249
273
This macro locks an rw-lock in x-mode. */
250
274
#define mtr_x_lock(B, MTR) mtr_x_lock_func((B), __FILE__, __LINE__,\
252
/*************************************************************************
276
/*********************************************************************//**
253
277
NOTE! Use the macro above!
254
278
Locks a lock in s-mode. */
259
rw_lock_t* lock, /* in: rw-lock */
260
const char* file, /* in: file name */
261
ulint line, /* in: line number */
262
mtr_t* mtr); /* in: mtr */
263
/*************************************************************************
283
rw_lock_t* lock, /*!< in: rw-lock */
284
const char* file, /*!< in: file name */
285
ulint line, /*!< in: line number */
286
mtr_t* mtr); /*!< in: mtr */
287
/*********************************************************************//**
264
288
NOTE! Use the macro above!
265
289
Locks a lock in x-mode. */
270
rw_lock_t* lock, /* in: rw-lock */
271
const char* file, /* in: file name */
272
ulint line, /* in: line number */
273
mtr_t* mtr); /* in: mtr */
294
rw_lock_t* lock, /*!< in: rw-lock */
295
const char* file, /*!< in: file name */
296
ulint line, /*!< in: line number */
297
mtr_t* mtr); /*!< in: mtr */
298
#endif /* !UNIV_HOTBACKUP */
275
/*******************************************************
300
/***************************************************//**
276
301
Releases an object in the memo stack. */
279
304
mtr_memo_release(
280
305
/*=============*/
281
mtr_t* mtr, /* in: mtr */
282
void* object, /* in: object */
283
ulint type); /* in: object type: MTR_MEMO_S_LOCK, ... */
306
mtr_t* mtr, /*!< in: mtr */
307
void* object, /*!< in: object */
308
ulint type); /*!< in: object type: MTR_MEMO_S_LOCK, ... */
284
309
#ifdef UNIV_DEBUG
285
/**************************************************************
286
Checks if memo contains the given item. */
310
# ifndef UNIV_HOTBACKUP
311
/**********************************************************//**
312
Checks if memo contains the given item.
313
@return TRUE if contains */
289
316
mtr_memo_contains(
290
317
/*==============*/
291
/* out: TRUE if contains */
292
mtr_t* mtr, /* in: mtr */
293
const void* object, /* in: object to search */
294
ulint type); /* in: type of object */
318
mtr_t* mtr, /*!< in: mtr */
319
const void* object, /*!< in: object to search */
320
ulint type); /*!< in: type of object */
296
/**************************************************************
297
Checks if memo contains the given page. */
322
/**********************************************************//**
323
Checks if memo contains the given page.
324
@return TRUE if contains */
300
327
mtr_memo_contains_page(
301
328
/*===================*/
302
/* out: TRUE if contains */
303
mtr_t* mtr, /* in: mtr */
304
const byte* ptr, /* in: pointer to buffer frame */
305
ulint type); /* in: type of object */
306
/*************************************************************
329
mtr_t* mtr, /*!< in: mtr */
330
const byte* ptr, /*!< in: pointer to buffer frame */
331
ulint type); /*!< in: type of object */
332
/*********************************************************//**
307
333
Prints info of an mtr handle. */
312
mtr_t* mtr); /* in: mtr */
338
mtr_t* mtr); /*!< in: mtr */
339
# else /* !UNIV_HOTBACKUP */
340
# define mtr_memo_contains(mtr, object, type) TRUE
341
# define mtr_memo_contains_page(mtr, ptr, type) TRUE
342
# endif /* !UNIV_HOTBACKUP */
313
343
#endif /* UNIV_DEBUG */
314
344
/*######################################################################*/
316
346
#define MTR_BUF_MEMO_SIZE 200 /* number of slots in memo */
318
/*******************************************************************
319
Returns the log object of a mini-transaction buffer. */
348
/***************************************************************//**
349
Returns the log object of a mini-transaction buffer.
325
mtr_t* mtr); /* in: mini-transaction */
326
/*******************************************************
355
mtr_t* mtr); /*!< in: mini-transaction */
356
/***************************************************//**
327
357
Pushes an object to an mtr memo stack. */
332
mtr_t* mtr, /* in: mtr */
333
void* object, /* in: object */
334
ulint type); /* in: object type: MTR_MEMO_S_LOCK, ... */
362
mtr_t* mtr, /*!< in: mtr */
363
void* object, /*!< in: object */
364
ulint type); /*!< in: object type: MTR_MEMO_S_LOCK, ... */
337
367
/* Type definition of a mini-transaction memo stack slot. */
338
368
typedef struct mtr_memo_slot_struct mtr_memo_slot_t;
339
369
struct mtr_memo_slot_struct{
340
ulint type; /* type of the stored object (MTR_MEMO_S_LOCK, ...) */
341
void* object; /* pointer to the object */
370
ulint type; /*!< type of the stored object (MTR_MEMO_S_LOCK, ...) */
371
void* object; /*!< pointer to the object */
344
374
/* Mini-transaction handle and buffer */
345
375
struct mtr_struct{
346
376
#ifdef UNIV_DEBUG
347
ulint state; /* MTR_ACTIVE, MTR_COMMITTING, MTR_COMMITTED */
377
ulint state; /*!< MTR_ACTIVE, MTR_COMMITTING, MTR_COMMITTED */
349
dyn_array_t memo; /* memo stack for locks etc. */
350
dyn_array_t log; /* mini-transaction log */
379
dyn_array_t memo; /*!< memo stack for locks etc. */
380
dyn_array_t log; /*!< mini-transaction log */
351
381
ibool modifications;
352
382
/* TRUE if the mtr made modifications to
353
383
buffer pool pages */