00001 /****************************************************** 00002 Mini-transaction buffer 00003 00004 (c) 1995 Innobase Oy 00005 00006 Created 11/26/1995 Heikki Tuuri 00007 *******************************************************/ 00008 00009 #ifndef mtr0mtr_h 00010 #define mtr0mtr_h 00011 00012 #include "univ.i" 00013 #include "mem0mem.h" 00014 #include "dyn0dyn.h" 00015 #include "buf0types.h" 00016 #include "sync0rw.h" 00017 #include "ut0byte.h" 00018 #include "mtr0types.h" 00019 #include "page0types.h" 00020 00021 /* Logging modes for a mini-transaction */ 00022 #define MTR_LOG_ALL 21 /* default mode: log all operations 00023 modifying disk-based data */ 00024 #define MTR_LOG_NONE 22 /* log no operations */ 00025 /*#define MTR_LOG_SPACE 23 */ /* log only operations modifying 00026 file space page allocation data 00027 (operations in fsp0fsp.* ) */ 00028 #define MTR_LOG_SHORT_INSERTS 24 /* inserts are logged in a shorter 00029 form */ 00030 00031 /* Types for the mlock objects to store in the mtr memo; NOTE that the 00032 first 3 values must be RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */ 00033 #define MTR_MEMO_PAGE_S_FIX RW_S_LATCH 00034 #define MTR_MEMO_PAGE_X_FIX RW_X_LATCH 00035 #define MTR_MEMO_BUF_FIX RW_NO_LATCH 00036 #define MTR_MEMO_MODIFY 54 00037 #define MTR_MEMO_S_LOCK 55 00038 #define MTR_MEMO_X_LOCK 56 00039 00040 /* Log item types: we have made them to be of the type 'byte' 00041 for the compiler to warn if val and type parameters are switched 00042 in a call to mlog_write_ulint. NOTE! For 1 - 8 bytes, the 00043 flag value must give the length also! */ 00044 #define MLOG_SINGLE_REC_FLAG 128 /* if the mtr contains only 00045 one log record for one page, 00046 i.e., write_initial_log_record 00047 has been called only once, 00048 this flag is ORed to the type 00049 of that first log record */ 00050 #define MLOG_1BYTE (1) /* one byte is written */ 00051 #define MLOG_2BYTES (2) /* 2 bytes ... */ 00052 #define MLOG_4BYTES (4) /* 4 bytes ... */ 00053 #define MLOG_8BYTES (8) /* 8 bytes ... */ 00054 #define MLOG_REC_INSERT ((byte)9) /* record insert */ 00055 #define MLOG_REC_CLUST_DELETE_MARK ((byte)10) /* mark clustered index record 00056 deleted */ 00057 #define MLOG_REC_SEC_DELETE_MARK ((byte)11) /* mark secondary index record 00058 deleted */ 00059 #define MLOG_REC_UPDATE_IN_PLACE ((byte)13) /* update of a record, 00060 preserves record field sizes */ 00061 #define MLOG_REC_DELETE ((byte)14) /* delete a record from a 00062 page */ 00063 #define MLOG_LIST_END_DELETE ((byte)15) /* delete record list end on 00064 index page */ 00065 #define MLOG_LIST_START_DELETE ((byte)16) /* delete record list start on 00066 index page */ 00067 #define MLOG_LIST_END_COPY_CREATED ((byte)17) /* copy record list end to a 00068 new created index page */ 00069 #define MLOG_PAGE_REORGANIZE ((byte)18) /* reorganize an index page */ 00070 #define MLOG_PAGE_CREATE ((byte)19) /* create an index page */ 00071 #define MLOG_UNDO_INSERT ((byte)20) /* insert entry in an undo 00072 log */ 00073 #define MLOG_UNDO_ERASE_END ((byte)21) /* erase an undo log page end */ 00074 #define MLOG_UNDO_INIT ((byte)22) /* initialize a page in an 00075 undo log */ 00076 #define MLOG_UNDO_HDR_DISCARD ((byte)23) /* discard an update undo log 00077 header */ 00078 #define MLOG_UNDO_HDR_REUSE ((byte)24) /* reuse an insert undo log 00079 header */ 00080 #define MLOG_UNDO_HDR_CREATE ((byte)25) /* create an undo log header */ 00081 #define MLOG_REC_MIN_MARK ((byte)26) /* mark an index record as the 00082 predefined minimum record */ 00083 #define MLOG_IBUF_BITMAP_INIT ((byte)27) /* initialize an ibuf bitmap 00084 page */ 00085 /*#define MLOG_FULL_PAGE ((byte)28) full contents of a page */ 00086 #define MLOG_INIT_FILE_PAGE ((byte)29) /* this means that a file page 00087 is taken into use and the prior 00088 contents of the page should be 00089 ignored: in recovery we must 00090 not trust the lsn values stored 00091 to the file page */ 00092 #define MLOG_WRITE_STRING ((byte)30) /* write a string to a page */ 00093 #define MLOG_MULTI_REC_END ((byte)31) /* if a single mtr writes 00094 log records for several pages, 00095 this log record ends the 00096 sequence of these records */ 00097 #define MLOG_DUMMY_RECORD ((byte)32) /* dummy log record used to 00098 pad a log block full */ 00099 #define MLOG_FILE_CREATE ((byte)33) /* log record about an .ibd 00100 file creation */ 00101 #define MLOG_FILE_RENAME ((byte)34) /* log record about an .ibd 00102 file rename */ 00103 #define MLOG_FILE_DELETE ((byte)35) /* log record about an .ibd 00104 file deletion */ 00105 #define MLOG_COMP_REC_MIN_MARK ((byte)36) /* mark a compact index record 00106 as the predefined minimum 00107 record */ 00108 #define MLOG_COMP_PAGE_CREATE ((byte)37) /* create a compact 00109 index page */ 00110 #define MLOG_COMP_REC_INSERT ((byte)38) /* compact record insert */ 00111 #define MLOG_COMP_REC_CLUST_DELETE_MARK ((byte)39) 00112 /* mark compact clustered index 00113 record deleted */ 00114 #define MLOG_COMP_REC_SEC_DELETE_MARK ((byte)40)/* mark compact secondary index 00115 record deleted; this log 00116 record type is redundant, as 00117 MLOG_REC_SEC_DELETE_MARK is 00118 independent of the record 00119 format. */ 00120 #define MLOG_COMP_REC_UPDATE_IN_PLACE ((byte)41)/* update of a compact record, 00121 preserves record field sizes */ 00122 #define MLOG_COMP_REC_DELETE ((byte)42) /* delete a compact record 00123 from a page */ 00124 #define MLOG_COMP_LIST_END_DELETE ((byte)43) /* delete compact record list 00125 end on index page */ 00126 #define MLOG_COMP_LIST_START_DELETE ((byte)44) /* delete compact record list 00127 start on index page */ 00128 #define MLOG_COMP_LIST_END_COPY_CREATED ((byte)45) 00129 /* copy compact record list end 00130 to a new created index page */ 00131 #define MLOG_COMP_PAGE_REORGANIZE ((byte)46) /* reorganize an index page */ 00132 00133 #define MLOG_BIGGEST_TYPE ((byte)46) /* biggest value (used in 00134 asserts) */ 00135 00136 /******************************************************************* 00137 Starts a mini-transaction and creates a mini-transaction handle 00138 and buffer in the memory buffer given by the caller. */ 00139 UNIV_INLINE 00140 mtr_t* 00141 mtr_start( 00142 /*======*/ 00143 /* out: mtr buffer which also acts as 00144 the mtr handle */ 00145 mtr_t* mtr); /* in: memory buffer for the mtr buffer */ 00146 /******************************************************************* 00147 Starts a mini-transaction and creates a mini-transaction handle 00148 and buffer in the memory buffer given by the caller. */ 00149 00150 mtr_t* 00151 mtr_start_noninline( 00152 /*================*/ 00153 /* out: mtr buffer which also acts as 00154 the mtr handle */ 00155 mtr_t* mtr); /* in: memory buffer for the mtr buffer */ 00156 /******************************************************************* 00157 Commits a mini-transaction. */ 00158 00159 void 00160 mtr_commit( 00161 /*=======*/ 00162 mtr_t* mtr); /* in: mini-transaction */ 00163 /************************************************************** 00164 Sets and returns a savepoint in mtr. */ 00165 UNIV_INLINE 00166 ulint 00167 mtr_set_savepoint( 00168 /*==============*/ 00169 /* out: savepoint */ 00170 mtr_t* mtr); /* in: mtr */ 00171 /************************************************************** 00172 Releases the latches stored in an mtr memo down to a savepoint. 00173 NOTE! The mtr must not have made changes to buffer pages after the 00174 savepoint, as these can be handled only by mtr_commit. */ 00175 00176 void 00177 mtr_rollback_to_savepoint( 00178 /*======================*/ 00179 mtr_t* mtr, /* in: mtr */ 00180 ulint savepoint); /* in: savepoint */ 00181 /************************************************************** 00182 Releases the (index tree) s-latch stored in an mtr memo after a 00183 savepoint. */ 00184 UNIV_INLINE 00185 void 00186 mtr_release_s_latch_at_savepoint( 00187 /*=============================*/ 00188 mtr_t* mtr, /* in: mtr */ 00189 ulint savepoint, /* in: savepoint */ 00190 rw_lock_t* lock); /* in: latch to release */ 00191 /******************************************************************* 00192 Gets the logging mode of a mini-transaction. */ 00193 UNIV_INLINE 00194 ulint 00195 mtr_get_log_mode( 00196 /*=============*/ 00197 /* out: logging mode: MTR_LOG_NONE, ... */ 00198 mtr_t* mtr); /* in: mtr */ 00199 /******************************************************************* 00200 Changes the logging mode of a mini-transaction. */ 00201 UNIV_INLINE 00202 ulint 00203 mtr_set_log_mode( 00204 /*=============*/ 00205 /* out: old mode */ 00206 mtr_t* mtr, /* in: mtr */ 00207 ulint mode); /* in: logging mode: MTR_LOG_NONE, ... */ 00208 /************************************************************ 00209 Reads 1 - 4 bytes from a file page buffered in the buffer pool. */ 00210 00211 ulint 00212 mtr_read_ulint( 00213 /*===========*/ 00214 /* out: value read */ 00215 byte* ptr, /* in: pointer from where to read */ 00216 ulint type, /* in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */ 00217 mtr_t* mtr); /* in: mini-transaction handle */ 00218 /************************************************************ 00219 Reads 8 bytes from a file page buffered in the buffer pool. */ 00220 00221 dulint 00222 mtr_read_dulint( 00223 /*============*/ 00224 /* out: value read */ 00225 byte* ptr, /* in: pointer from where to read */ 00226 mtr_t* mtr); /* in: mini-transaction handle */ 00227 /************************************************************************* 00228 This macro locks an rw-lock in s-mode. */ 00229 #define mtr_s_lock(B, MTR) mtr_s_lock_func((B), __FILE__, __LINE__,\ 00230 (MTR)) 00231 /************************************************************************* 00232 This macro locks an rw-lock in x-mode. */ 00233 #define mtr_x_lock(B, MTR) mtr_x_lock_func((B), __FILE__, __LINE__,\ 00234 (MTR)) 00235 /************************************************************************* 00236 NOTE! Use the macro above! 00237 Locks a lock in s-mode. */ 00238 UNIV_INLINE 00239 void 00240 mtr_s_lock_func( 00241 /*============*/ 00242 rw_lock_t* lock, /* in: rw-lock */ 00243 const char* file, /* in: file name */ 00244 ulint line, /* in: line number */ 00245 mtr_t* mtr); /* in: mtr */ 00246 /************************************************************************* 00247 NOTE! Use the macro above! 00248 Locks a lock in x-mode. */ 00249 UNIV_INLINE 00250 void 00251 mtr_x_lock_func( 00252 /*============*/ 00253 rw_lock_t* lock, /* in: rw-lock */ 00254 const char* file, /* in: file name */ 00255 ulint line, /* in: line number */ 00256 mtr_t* mtr); /* in: mtr */ 00257 00258 /******************************************************* 00259 Releases an object in the memo stack. */ 00260 00261 void 00262 mtr_memo_release( 00263 /*=============*/ 00264 mtr_t* mtr, /* in: mtr */ 00265 void* object, /* in: object */ 00266 ulint type); /* in: object type: MTR_MEMO_S_LOCK, ... */ 00267 /************************************************************** 00268 Checks if memo contains the given item. */ 00269 UNIV_INLINE 00270 ibool 00271 mtr_memo_contains( 00272 /*==============*/ 00273 /* out: TRUE if contains */ 00274 mtr_t* mtr, /* in: mtr */ 00275 void* object, /* in: object to search */ 00276 ulint type); /* in: type of object */ 00277 /************************************************************* 00278 Prints info of an mtr handle. */ 00279 00280 void 00281 mtr_print( 00282 /*======*/ 00283 mtr_t* mtr); /* in: mtr */ 00284 /*######################################################################*/ 00285 00286 #define MTR_BUF_MEMO_SIZE 200 /* number of slots in memo */ 00287 00288 /******************************************************************* 00289 Returns the log object of a mini-transaction buffer. */ 00290 UNIV_INLINE 00291 dyn_array_t* 00292 mtr_get_log( 00293 /*========*/ 00294 /* out: log */ 00295 mtr_t* mtr); /* in: mini-transaction */ 00296 /******************************************************* 00297 Pushes an object to an mtr memo stack. */ 00298 UNIV_INLINE 00299 void 00300 mtr_memo_push( 00301 /*==========*/ 00302 mtr_t* mtr, /* in: mtr */ 00303 void* object, /* in: object */ 00304 ulint type); /* in: object type: MTR_MEMO_S_LOCK, ... */ 00305 00306 00307 /* Type definition of a mini-transaction memo stack slot. */ 00308 typedef struct mtr_memo_slot_struct mtr_memo_slot_t; 00309 struct mtr_memo_slot_struct{ 00310 ulint type; /* type of the stored object (MTR_MEMO_S_LOCK, ...) */ 00311 void* object; /* pointer to the object */ 00312 }; 00313 00314 /* Mini-transaction handle and buffer */ 00315 struct mtr_struct{ 00316 ulint state; /* MTR_ACTIVE, MTR_COMMITTING, MTR_COMMITTED */ 00317 dyn_array_t memo; /* memo stack for locks etc. */ 00318 dyn_array_t log; /* mini-transaction log */ 00319 ibool modifications; 00320 /* TRUE if the mtr made modifications to 00321 buffer pool pages */ 00322 ulint n_log_recs; 00323 /* count of how many page initial log records 00324 have been written to the mtr log */ 00325 ulint log_mode; /* specifies which operations should be 00326 logged; default value MTR_LOG_ALL */ 00327 dulint start_lsn;/* start lsn of the possible log entry for 00328 this mtr */ 00329 dulint end_lsn;/* end lsn of the possible log entry for 00330 this mtr */ 00331 ulint magic_n; 00332 }; 00333 00334 #define MTR_MAGIC_N 54551 00335 00336 #define MTR_ACTIVE 12231 00337 #define MTR_COMMITTING 56456 00338 #define MTR_COMMITTED 34676 00339 00340 #ifndef UNIV_NONINL 00341 #include "mtr0mtr.ic" 00342 #endif 00343 00344 #endif
1.4.7

