1
/******************************************************
2
Mini-transaction buffer
6
Created 11/26/1995 Heikki Tuuri
7
*******************************************************/
15
#include "buf0types.h"
18
#include "mtr0types.h"
19
#include "page0types.h"
21
/* Logging modes for a mini-transaction */
22
#define MTR_LOG_ALL 21 /* default mode: log all operations
23
modifying disk-based data */
24
#define MTR_LOG_NONE 22 /* log no operations */
25
/*#define MTR_LOG_SPACE 23 */ /* log only operations modifying
26
file space page allocation data
27
(operations in fsp0fsp.* ) */
28
#define MTR_LOG_SHORT_INSERTS 24 /* inserts are logged in a shorter
31
/* Types for the mlock objects to store in the mtr memo; NOTE that the
32
first 3 values must be RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
33
#define MTR_MEMO_PAGE_S_FIX RW_S_LATCH
34
#define MTR_MEMO_PAGE_X_FIX RW_X_LATCH
35
#define MTR_MEMO_BUF_FIX RW_NO_LATCH
36
#define MTR_MEMO_MODIFY 54
37
#define MTR_MEMO_S_LOCK 55
38
#define MTR_MEMO_X_LOCK 56
40
/* Log item types: we have made them to be of the type 'byte'
41
for the compiler to warn if val and type parameters are switched
42
in a call to mlog_write_ulint. NOTE! For 1 - 8 bytes, the
43
flag value must give the length also! */
44
#define MLOG_SINGLE_REC_FLAG 128 /* if the mtr contains only
45
one log record for one page,
46
i.e., write_initial_log_record
47
has been called only once,
48
this flag is ORed to the type
49
of that first log record */
50
#define MLOG_1BYTE (1) /* one byte is written */
51
#define MLOG_2BYTES (2) /* 2 bytes ... */
52
#define MLOG_4BYTES (4) /* 4 bytes ... */
53
#define MLOG_8BYTES (8) /* 8 bytes ... */
54
#define MLOG_REC_INSERT ((byte)9) /* record insert */
55
#define MLOG_REC_CLUST_DELETE_MARK ((byte)10) /* mark clustered index record
57
#define MLOG_REC_SEC_DELETE_MARK ((byte)11) /* mark secondary index record
59
#define MLOG_REC_UPDATE_IN_PLACE ((byte)13) /* update of a record,
60
preserves record field sizes */
61
#define MLOG_REC_DELETE ((byte)14) /* delete a record from a
63
#define MLOG_LIST_END_DELETE ((byte)15) /* delete record list end on
65
#define MLOG_LIST_START_DELETE ((byte)16) /* delete record list start on
67
#define MLOG_LIST_END_COPY_CREATED ((byte)17) /* copy record list end to a
68
new created index page */
69
#define MLOG_PAGE_REORGANIZE ((byte)18) /* reorganize an index page */
70
#define MLOG_PAGE_CREATE ((byte)19) /* create an index page */
71
#define MLOG_UNDO_INSERT ((byte)20) /* insert entry in an undo
73
#define MLOG_UNDO_ERASE_END ((byte)21) /* erase an undo log
75
#define MLOG_UNDO_INIT ((byte)22) /* initialize a page in an
77
#define MLOG_UNDO_HDR_DISCARD ((byte)23) /* discard an update undo log
79
#define MLOG_UNDO_HDR_REUSE ((byte)24) /* reuse an insert undo log
81
#define MLOG_UNDO_HDR_CREATE ((byte)25) /* create an undo log header */
82
#define MLOG_REC_MIN_MARK ((byte)26) /* mark an index record as the
83
predefined minimum record */
84
#define MLOG_IBUF_BITMAP_INIT ((byte)27) /* initialize an ibuf bitmap
86
/*#define MLOG_FULL_PAGE ((byte)28) full contents of a page */
87
#define MLOG_INIT_FILE_PAGE ((byte)29) /* this means that a file page
88
is taken into use and the prior
89
contents of the page should be
90
ignored: in recovery we must
91
not trust the lsn values stored
93
#define MLOG_WRITE_STRING ((byte)30) /* write a string to a page */
94
#define MLOG_MULTI_REC_END ((byte)31) /* if a single mtr writes
95
log records for several pages,
96
this log record ends the
97
sequence of these records */
98
#define MLOG_DUMMY_RECORD ((byte)32) /* dummy log record used to
99
pad a log block full */
100
#define MLOG_FILE_CREATE ((byte)33) /* log record about an .ibd
102
#define MLOG_FILE_RENAME ((byte)34) /* log record about an .ibd
104
#define MLOG_FILE_DELETE ((byte)35) /* log record about an .ibd
106
#define MLOG_COMP_REC_MIN_MARK ((byte)36) /* mark a compact index record
107
as the predefined minimum
109
#define MLOG_COMP_PAGE_CREATE ((byte)37) /* create a compact
111
#define MLOG_COMP_REC_INSERT ((byte)38) /* compact record insert */
112
#define MLOG_COMP_REC_CLUST_DELETE_MARK ((byte)39)
113
/* mark compact clustered index
115
#define MLOG_COMP_REC_SEC_DELETE_MARK ((byte)40)/* mark compact secondary index
116
record deleted; this log
117
record type is redundant, as
118
MLOG_REC_SEC_DELETE_MARK is
119
independent of the record
121
#define MLOG_COMP_REC_UPDATE_IN_PLACE ((byte)41)/* update of a compact record,
122
preserves record field sizes */
123
#define MLOG_COMP_REC_DELETE ((byte)42) /* delete a compact record
125
#define MLOG_COMP_LIST_END_DELETE ((byte)43) /* delete compact record list
127
#define MLOG_COMP_LIST_START_DELETE ((byte)44) /* delete compact record list
128
start on index page */
129
#define MLOG_COMP_LIST_END_COPY_CREATED ((byte)45)
130
/* copy compact record list end
131
to a new created index page */
132
#define MLOG_COMP_PAGE_REORGANIZE ((byte)46) /* reorganize an index page */
134
#define MLOG_BIGGEST_TYPE ((byte)46) /* biggest value (used in
137
/*******************************************************************
138
Starts a mini-transaction and creates a mini-transaction handle
139
and buffer in the memory buffer given by the caller. */
144
/* out: mtr buffer which also acts as
146
mtr_t* mtr); /* in: memory buffer for the mtr buffer */
147
/*******************************************************************
148
Starts a mini-transaction and creates a mini-transaction handle
149
and buffer in the memory buffer given by the caller. */
154
/* out: mtr buffer which also acts as
156
mtr_t* mtr); /* in: memory buffer for the mtr buffer */
157
/*******************************************************************
158
Commits a mini-transaction. */
163
mtr_t* mtr); /* in: mini-transaction */
164
/**************************************************************
165
Sets and returns a savepoint in mtr. */
171
mtr_t* mtr); /* in: mtr */
172
/**************************************************************
173
Releases the latches stored in an mtr memo down to a savepoint.
174
NOTE! The mtr must not have made changes to buffer pages after the
175
savepoint, as these can be handled only by mtr_commit. */
178
mtr_rollback_to_savepoint(
179
/*======================*/
180
mtr_t* mtr, /* in: mtr */
181
ulint savepoint); /* in: savepoint */
182
/**************************************************************
183
Releases the (index tree) s-latch stored in an mtr memo after a
187
mtr_release_s_latch_at_savepoint(
188
/*=============================*/
189
mtr_t* mtr, /* in: mtr */
190
ulint savepoint, /* in: savepoint */
191
rw_lock_t* lock); /* in: latch to release */
192
/*******************************************************************
193
Gets the logging mode of a mini-transaction. */
198
/* out: logging mode: MTR_LOG_NONE, ... */
199
mtr_t* mtr); /* in: mtr */
200
/*******************************************************************
201
Changes the logging mode of a mini-transaction. */
207
mtr_t* mtr, /* in: mtr */
208
ulint mode); /* in: logging mode: MTR_LOG_NONE, ... */
209
/************************************************************
210
Reads 1 - 4 bytes from a file page buffered in the buffer pool. */
215
/* out: value read */
216
byte* ptr, /* in: pointer from where to read */
217
ulint type, /* in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
218
mtr_t* mtr); /* in: mini-transaction handle */
219
/************************************************************
220
Reads 8 bytes from a file page buffered in the buffer pool. */
225
/* out: value read */
226
byte* ptr, /* in: pointer from where to read */
227
mtr_t* mtr); /* in: mini-transaction handle */
228
/*************************************************************************
229
This macro locks an rw-lock in s-mode. */
230
#define mtr_s_lock(B, MTR) mtr_s_lock_func((B), __FILE__, __LINE__,\
232
/*************************************************************************
233
This macro locks an rw-lock in x-mode. */
234
#define mtr_x_lock(B, MTR) mtr_x_lock_func((B), __FILE__, __LINE__,\
236
/*************************************************************************
237
NOTE! Use the macro above!
238
Locks a lock in s-mode. */
243
rw_lock_t* lock, /* in: rw-lock */
244
const char* file, /* in: file name */
245
ulint line, /* in: line number */
246
mtr_t* mtr); /* in: mtr */
247
/*************************************************************************
248
NOTE! Use the macro above!
249
Locks a lock in x-mode. */
254
rw_lock_t* lock, /* in: rw-lock */
255
const char* file, /* in: file name */
256
ulint line, /* in: line number */
257
mtr_t* mtr); /* in: mtr */
259
/*******************************************************
260
Releases an object in the memo stack. */
265
mtr_t* mtr, /* in: mtr */
266
void* object, /* in: object */
267
ulint type); /* in: object type: MTR_MEMO_S_LOCK, ... */
269
/**************************************************************
270
Checks if memo contains the given item. */
275
/* out: TRUE if contains */
276
mtr_t* mtr, /* in: mtr */
277
void* object, /* in: object to search */
278
ulint type); /* in: type of object */
279
/*************************************************************
280
Prints info of an mtr handle. */
285
mtr_t* mtr); /* in: mtr */
286
#endif /* UNIV_DEBUG */
287
/*######################################################################*/
289
#define MTR_BUF_MEMO_SIZE 200 /* number of slots in memo */
291
/*******************************************************************
292
Returns the log object of a mini-transaction buffer. */
298
mtr_t* mtr); /* in: mini-transaction */
299
/*******************************************************
300
Pushes an object to an mtr memo stack. */
305
mtr_t* mtr, /* in: mtr */
306
void* object, /* in: object */
307
ulint type); /* in: object type: MTR_MEMO_S_LOCK, ... */
310
/* Type definition of a mini-transaction memo stack slot. */
311
typedef struct mtr_memo_slot_struct mtr_memo_slot_t;
312
struct mtr_memo_slot_struct{
313
ulint type; /* type of the stored object (MTR_MEMO_S_LOCK, ...) */
314
void* object; /* pointer to the object */
317
/* Mini-transaction handle and buffer */
319
ulint state; /* MTR_ACTIVE, MTR_COMMITTING, MTR_COMMITTED */
320
dyn_array_t memo; /* memo stack for locks etc. */
321
dyn_array_t log; /* mini-transaction log */
323
/* TRUE if the mtr made modifications to
326
/* count of how many page initial log records
327
have been written to the mtr log */
328
ulint log_mode; /* specifies which operations should be
329
logged; default value MTR_LOG_ALL */
330
dulint start_lsn;/* start lsn of the possible log entry for
332
dulint end_lsn;/* end lsn of the possible log entry for
337
#define MTR_MAGIC_N 54551
339
#define MTR_ACTIVE 12231
340
#define MTR_COMMITTING 56456
341
#define MTR_COMMITTED 34676
344
#include "mtr0mtr.ic"