1
/******************************************************
2
Mini-transaction logging routines
6
Created 12/7/1995 Heikki Tuuri
7
*******************************************************/
13
/************************************************************
14
Opens a buffer to mlog. It must be closed with mlog_close. */
19
/* out: buffer, NULL if log mode MTR_LOG_NONE */
20
mtr_t* mtr, /* in: mtr */
21
ulint size) /* in: buffer size in bytes; MUST be
22
smaller than DYN_ARRAY_DATA_SIZE! */
26
mtr->modifications = TRUE;
28
if (mtr_get_log_mode(mtr) == MTR_LOG_NONE) {
35
return(dyn_array_open(mlog, size));
38
/************************************************************
39
Closes a buffer opened to mlog. */
44
mtr_t* mtr, /* in: mtr */
45
byte* ptr) /* in: buffer space from ptr up was not used */
49
ut_ad(mtr_get_log_mode(mtr) != MTR_LOG_NONE);
53
dyn_array_close(mlog, ptr);
56
/************************************************************
57
Catenates 1 - 4 bytes to the mtr log. The value is not compressed. */
62
mtr_t* mtr, /* in: mtr */
63
ulint val, /* in: value to write */
64
ulint type) /* in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
69
if (mtr_get_log_mode(mtr) == MTR_LOG_NONE) {
77
# error "MLOG_1BYTE != 1"
80
# error "MLOG_2BYTES != 2"
83
# error "MLOG_4BYTES != 4"
86
# error "MLOG_8BYTES != 8"
88
ptr = dyn_array_push(mlog, type);
90
if (type == MLOG_4BYTES) {
91
mach_write_to_4(ptr, val);
92
} else if (type == MLOG_2BYTES) {
93
mach_write_to_2(ptr, val);
95
ut_ad(type == MLOG_1BYTE);
96
mach_write_to_1(ptr, val);
100
/************************************************************
101
Catenates a compressed ulint to mlog. */
104
mlog_catenate_ulint_compressed(
105
/*===========================*/
106
mtr_t* mtr, /* in: mtr */
107
ulint val) /* in: value to write */
111
log_ptr = mlog_open(mtr, 10);
113
/* If no logging is requested, we may return now */
114
if (log_ptr == NULL) {
119
log_ptr += mach_write_compressed(log_ptr, val);
121
mlog_close(mtr, log_ptr);
124
/************************************************************
125
Catenates a compressed dulint to mlog. */
128
mlog_catenate_dulint_compressed(
129
/*============================*/
130
mtr_t* mtr, /* in: mtr */
131
dulint val) /* in: value to write */
135
log_ptr = mlog_open(mtr, 15);
137
/* If no logging is requested, we may return now */
138
if (log_ptr == NULL) {
143
log_ptr += mach_dulint_write_compressed(log_ptr, val);
145
mlog_close(mtr, log_ptr);
148
/************************************************************
149
Writes the initial part of a log record (3..11 bytes).
150
If the implementation of this function is changed, all
151
size parameters to mlog_open() should be adjusted accordingly! */
154
mlog_write_initial_log_record_fast(
155
/*===============================*/
156
/* out: new value of log_ptr */
157
byte* ptr, /* in: pointer to (inside) a buffer frame holding the
158
file page where modification is made */
159
byte type, /* in: log item type: MLOG_1BYTE, ... */
160
byte* log_ptr,/* in: pointer to mtr log which has been opened */
161
mtr_t* mtr) /* in: mtr */
167
ut_ad(mtr_memo_contains(mtr, buf_block_align(ptr),
168
MTR_MEMO_PAGE_X_FIX));
169
ut_ad(type <= MLOG_BIGGEST_TYPE);
170
ut_ad(ptr && log_ptr);
172
block = buf_block_align(ptr);
174
space = buf_block_get_space(block);
175
offset = buf_block_get_page_no(block);
177
mach_write_to_1(log_ptr, type);
179
log_ptr += mach_write_compressed(log_ptr, space);
180
log_ptr += mach_write_compressed(log_ptr, offset);
184
#ifdef UNIV_LOG_DEBUG
186
"Adding to mtr log record type %lu space %lu page no %lu\n",
187
type, space, offset); */
191
/* We now assume that all x-latched pages have been modified! */
193
if (!mtr_memo_contains(mtr, block, MTR_MEMO_MODIFY)) {
195
mtr_memo_push(mtr, block, MTR_MEMO_MODIFY);
201
/************************************************************
202
Writes a log record about an .ibd file create/delete/rename. */
205
mlog_write_initial_log_record_for_file_op(
206
/*======================================*/
207
/* out: new value of log_ptr */
208
ulint type, /* in: MLOG_FILE_CREATE, MLOG_FILE_DELETE, or
210
ulint space_id,/* in: space id, if applicable */
211
ulint page_no,/* in: page number (not relevant currently) */
212
byte* log_ptr,/* in: pointer to mtr log which has been opened */
213
mtr_t* mtr) /* in: mtr */
217
mach_write_to_1(log_ptr, type);
220
/* We write dummy space id and page number */
221
log_ptr += mach_write_compressed(log_ptr, space_id);
222
log_ptr += mach_write_compressed(log_ptr, page_no);