1
by brian
clean slate |
1 |
/******************************************************
|
2 |
Mini-transaction buffer
|
|
3 |
||
4 |
(c) 1995 Innobase Oy
|
|
5 |
||
6 |
Created 11/26/1995 Heikki Tuuri
|
|
7 |
*******************************************************/
|
|
8 |
||
9 |
#ifndef mtr0mtr_h
|
|
10 |
#define mtr0mtr_h
|
|
11 |
||
12 |
#include "univ.i" |
|
13 |
#include "mem0mem.h" |
|
14 |
#include "dyn0dyn.h" |
|
15 |
#include "buf0types.h" |
|
16 |
#include "sync0rw.h" |
|
17 |
#include "ut0byte.h" |
|
18 |
#include "mtr0types.h" |
|
19 |
#include "page0types.h" |
|
20 |
||
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 |
|
29 |
form */
|
|
30 |
||
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
|
|
39 |
||
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 |
|
56 |
deleted */
|
|
57 |
#define MLOG_REC_SEC_DELETE_MARK ((byte)11) /* mark secondary index record |
|
58 |
deleted */
|
|
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 |
|
62 |
page */
|
|
63 |
#define MLOG_LIST_END_DELETE ((byte)15) /* delete record list end on |
|
64 |
index page */
|
|
65 |
#define MLOG_LIST_START_DELETE ((byte)16) /* delete record list start on |
|
66 |
index page */
|
|
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 |
|
72 |
log */
|
|
73 |
#define MLOG_UNDO_ERASE_END ((byte)21) /* erase an undo log |
|
74 |
page end */
|
|
75 |
#define MLOG_UNDO_INIT ((byte)22) /* initialize a page in an |
|
76 |
undo log */
|
|
77 |
#define MLOG_UNDO_HDR_DISCARD ((byte)23) /* discard an update undo log |
|
78 |
header */
|
|
79 |
#define MLOG_UNDO_HDR_REUSE ((byte)24) /* reuse an insert undo log |
|
80 |
header */
|
|
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 |
|
85 |
page */
|
|
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
|
|
92 |
to the file page */
|
|
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 |
|
101 |
file creation */
|
|
102 |
#define MLOG_FILE_RENAME ((byte)34) /* log record about an .ibd |
|
103 |
file rename */
|
|
104 |
#define MLOG_FILE_DELETE ((byte)35) /* log record about an .ibd |
|
105 |
file deletion */
|
|
106 |
#define MLOG_COMP_REC_MIN_MARK ((byte)36) /* mark a compact index record |
|
107 |
as the predefined minimum
|
|
108 |
record */
|
|
109 |
#define MLOG_COMP_PAGE_CREATE ((byte)37) /* create a compact |
|
110 |
index page */
|
|
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
|
|
114 |
record deleted */
|
|
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
|
|
120 |
format. */
|
|
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 |
|
124 |
from a page */
|
|
125 |
#define MLOG_COMP_LIST_END_DELETE ((byte)43) /* delete compact record list |
|
126 |
end on index page */
|
|
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 */ |
|
133 |
||
134 |
#define MLOG_BIGGEST_TYPE ((byte)46) /* biggest value (used in |
|
135 |
asserts) */
|
|
136 |
||
137 |
/*******************************************************************
|
|
138 |
Starts a mini-transaction and creates a mini-transaction handle
|
|
139 |
and buffer in the memory buffer given by the caller. */
|
|
140 |
UNIV_INLINE
|
|
141 |
mtr_t* |
|
142 |
mtr_start( |
|
143 |
/*======*/
|
|
144 |
/* out: mtr buffer which also acts as
|
|
145 |
the mtr handle */
|
|
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. */
|
|
150 |
||
151 |
mtr_t* |
|
152 |
mtr_start_noninline( |
|
153 |
/*================*/
|
|
154 |
/* out: mtr buffer which also acts as
|
|
155 |
the mtr handle */
|
|
156 |
mtr_t* mtr); /* in: memory buffer for the mtr buffer */ |
|
157 |
/*******************************************************************
|
|
158 |
Commits a mini-transaction. */
|
|
159 |
||
160 |
void
|
|
161 |
mtr_commit( |
|
162 |
/*=======*/
|
|
163 |
mtr_t* mtr); /* in: mini-transaction */ |
|
164 |
/**************************************************************
|
|
165 |
Sets and returns a savepoint in mtr. */
|
|
166 |
UNIV_INLINE
|
|
167 |
ulint
|
|
168 |
mtr_set_savepoint( |
|
169 |
/*==============*/
|
|
170 |
/* out: savepoint */
|
|
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. */
|
|
176 |
||
177 |
void
|
|
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
|
|
184 |
savepoint. */
|
|
185 |
UNIV_INLINE
|
|
186 |
void
|
|
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. */
|
|
194 |
UNIV_INLINE
|
|
195 |
ulint
|
|
196 |
mtr_get_log_mode( |
|
197 |
/*=============*/
|
|
198 |
/* out: logging mode: MTR_LOG_NONE, ... */
|
|
199 |
mtr_t* mtr); /* in: mtr */ |
|
200 |
/*******************************************************************
|
|
201 |
Changes the logging mode of a mini-transaction. */
|
|
202 |
UNIV_INLINE
|
|
203 |
ulint
|
|
204 |
mtr_set_log_mode( |
|
205 |
/*=============*/
|
|
206 |
/* out: old mode */
|
|
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. */
|
|
211 |
||
212 |
ulint
|
|
213 |
mtr_read_ulint( |
|
214 |
/*===========*/
|
|
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. */
|
|
221 |
||
222 |
dulint
|
|
223 |
mtr_read_dulint( |
|
224 |
/*============*/
|
|
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__,\
|
|
231 |
(MTR))
|
|
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__,\
|
|
235 |
(MTR))
|
|
236 |
/*************************************************************************
|
|
237 |
NOTE! Use the macro above!
|
|
238 |
Locks a lock in s-mode. */
|
|
239 |
UNIV_INLINE
|
|
240 |
void
|
|
241 |
mtr_s_lock_func( |
|
242 |
/*============*/
|
|
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. */
|
|
250 |
UNIV_INLINE
|
|
251 |
void
|
|
252 |
mtr_x_lock_func( |
|
253 |
/*============*/
|
|
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 */ |
|
258 |
||
259 |
/*******************************************************
|
|
260 |
Releases an object in the memo stack. */
|
|
261 |
||
262 |
void
|
|
263 |
mtr_memo_release( |
|
264 |
/*=============*/
|
|
265 |
mtr_t* mtr, /* in: mtr */ |
|
266 |
void* object, /* in: object */ |
|
267 |
ulint type); /* in: object type: MTR_MEMO_S_LOCK, ... */ |
|
268 |
#ifdef UNIV_DEBUG
|
|
269 |
/**************************************************************
|
|
270 |
Checks if memo contains the given item. */
|
|
271 |
UNIV_INLINE
|
|
272 |
ibool
|
|
273 |
mtr_memo_contains( |
|
274 |
/*==============*/
|
|
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. */
|
|
281 |
||
282 |
void
|
|
283 |
mtr_print( |
|
284 |
/*======*/
|
|
285 |
mtr_t* mtr); /* in: mtr */ |
|
286 |
#endif /* UNIV_DEBUG */ |
|
287 |
/*######################################################################*/
|
|
288 |
||
289 |
#define MTR_BUF_MEMO_SIZE 200 /* number of slots in memo */ |
|
290 |
||
291 |
/*******************************************************************
|
|
292 |
Returns the log object of a mini-transaction buffer. */
|
|
293 |
UNIV_INLINE
|
|
294 |
dyn_array_t* |
|
295 |
mtr_get_log( |
|
296 |
/*========*/
|
|
297 |
/* out: log */
|
|
298 |
mtr_t* mtr); /* in: mini-transaction */ |
|
299 |
/*******************************************************
|
|
300 |
Pushes an object to an mtr memo stack. */
|
|
301 |
UNIV_INLINE
|
|
302 |
void
|
|
303 |
mtr_memo_push( |
|
304 |
/*==========*/
|
|
305 |
mtr_t* mtr, /* in: mtr */ |
|
306 |
void* object, /* in: object */ |
|
307 |
ulint type); /* in: object type: MTR_MEMO_S_LOCK, ... */ |
|
308 |
||
309 |
||
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 */ |
|
315 |
};
|
|
316 |
||
317 |
/* Mini-transaction handle and buffer */
|
|
318 |
struct mtr_struct{ |
|
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 */ |
|
322 |
ibool modifications; |
|
323 |
/* TRUE if the mtr made modifications to
|
|
324 |
buffer pool pages */
|
|
325 |
ulint n_log_recs; |
|
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 |
|
331 |
this mtr */
|
|
332 |
dulint end_lsn;/* end lsn of the possible log entry for |
|
333 |
this mtr */
|
|
334 |
ulint magic_n; |
|
335 |
};
|
|
336 |
||
337 |
#define MTR_MAGIC_N 54551
|
|
338 |
||
339 |
#define MTR_ACTIVE 12231
|
|
340 |
#define MTR_COMMITTING 56456
|
|
341 |
#define MTR_COMMITTED 34676
|
|
342 |
||
343 |
#ifndef UNIV_NONINL
|
|
344 |
#include "mtr0mtr.ic" |
|
345 |
#endif
|
|
346 |
||
347 |
#endif
|