~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/******************************************************
2
Mini-transaction logging routines
3
4
(c) 1995 Innobase Oy
5
6
Created 12/7/1995 Heikki Tuuri
7
*******************************************************/
8
9
#include "mach0data.h"
10
#include "ut0lst.h"
11
#include "buf0buf.h"
12
13
/************************************************************
14
Opens a buffer to mlog. It must be closed with mlog_close. */
15
UNIV_INLINE
16
byte*
17
mlog_open(
18
/*======*/
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! */
23
{
24
	dyn_array_t*	mlog;
25
26
	mtr->modifications = TRUE;
27
28
	if (mtr_get_log_mode(mtr) == MTR_LOG_NONE) {
29
30
		return(NULL);
31
	}
32
33
	mlog = &(mtr->log);
34
35
	return(dyn_array_open(mlog, size));
36
}
37
38
/************************************************************
39
Closes a buffer opened to mlog. */
40
UNIV_INLINE
41
void
42
mlog_close(
43
/*=======*/
44
	mtr_t*	mtr,	/* in: mtr */
45
	byte*	ptr)	/* in: buffer space from ptr up was not used */
46
{
47
	dyn_array_t*	mlog;
48
49
	ut_ad(mtr_get_log_mode(mtr) != MTR_LOG_NONE);
50
51
	mlog = &(mtr->log);
52
53
	dyn_array_close(mlog, ptr);
54
}
55
56
/************************************************************
57
Catenates 1 - 4 bytes to the mtr log. The value is not compressed. */
58
UNIV_INLINE
59
void
60
mlog_catenate_ulint(
61
/*================*/
62
	mtr_t*	mtr,	/* in: mtr */
63
	ulint	val,	/* in: value to write */
64
	ulint	type)	/* in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
65
{
66
	dyn_array_t*	mlog;
67
	byte*		ptr;
68
69
	if (mtr_get_log_mode(mtr) == MTR_LOG_NONE) {
70
71
		return;
72
	}
73
74
	mlog = &(mtr->log);
75
76
#if MLOG_1BYTE != 1
77
# error "MLOG_1BYTE != 1"
78
#endif
79
#if MLOG_2BYTES != 2
80
# error "MLOG_2BYTES != 2"
81
#endif
82
#if MLOG_4BYTES != 4
83
# error "MLOG_4BYTES != 4"
84
#endif
85
#if MLOG_8BYTES != 8
86
# error "MLOG_8BYTES != 8"
87
#endif
88
	ptr = dyn_array_push(mlog, type);
89
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);
94
	} else {
95
		ut_ad(type == MLOG_1BYTE);
96
		mach_write_to_1(ptr, val);
97
	}
98
}
99
100
/************************************************************
101
Catenates a compressed ulint to mlog. */
102
UNIV_INLINE
103
void
104
mlog_catenate_ulint_compressed(
105
/*===========================*/
106
	mtr_t*	mtr,	/* in: mtr */
107
	ulint	val)	/* in: value to write */
108
{
109
	byte*	log_ptr;
110
111
	log_ptr = mlog_open(mtr, 10);
112
113
	/* If no logging is requested, we may return now */
114
	if (log_ptr == NULL) {
115
116
		return;
117
	}
118
119
	log_ptr += mach_write_compressed(log_ptr, val);
120
121
	mlog_close(mtr, log_ptr);
122
}
123
124
/************************************************************
125
Catenates a compressed dulint to mlog. */
126
UNIV_INLINE
127
void
128
mlog_catenate_dulint_compressed(
129
/*============================*/
130
	mtr_t*	mtr,	/* in: mtr */
131
	dulint	val)	/* in: value to write */
132
{
133
	byte*	log_ptr;
134
135
	log_ptr = mlog_open(mtr, 15);
136
137
	/* If no logging is requested, we may return now */
138
	if (log_ptr == NULL) {
139
140
		return;
141
	}
142
143
	log_ptr += mach_dulint_write_compressed(log_ptr, val);
144
145
	mlog_close(mtr, log_ptr);
146
}
147
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! */
152
UNIV_INLINE
153
byte*
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 */
162
{
163
	buf_block_t*	block;
164
	ulint		space;
165
	ulint		offset;
166
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);
171
172
	block = buf_block_align(ptr);
173
174
	space = buf_block_get_space(block);
175
	offset = buf_block_get_page_no(block);
176
177
	mach_write_to_1(log_ptr, type);
178
	log_ptr++;
179
	log_ptr += mach_write_compressed(log_ptr, space);
180
	log_ptr += mach_write_compressed(log_ptr, offset);
181
182
	mtr->n_log_recs++;
183
184
#ifdef UNIV_LOG_DEBUG
185
	/*	fprintf(stderr,
186
	"Adding to mtr log record type %lu space %lu page no %lu\n",
187
	type, space, offset); */
188
#endif
189
190
#ifdef UNIV_DEBUG
191
	/* We now assume that all x-latched pages have been modified! */
192
193
	if (!mtr_memo_contains(mtr, block, MTR_MEMO_MODIFY)) {
194
195
		mtr_memo_push(mtr, block, MTR_MEMO_MODIFY);
196
	}
197
#endif
198
	return(log_ptr);
199
}
200
201
/************************************************************
202
Writes a log record about an .ibd file create/delete/rename. */
203
UNIV_INLINE
204
byte*
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
209
			MLOG_FILE_RENAME */
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 */
214
{
215
	ut_ad(log_ptr);
216
217
	mach_write_to_1(log_ptr, type);
218
	log_ptr++;
219
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);
223
224
	mtr->n_log_recs++;
225
226
	return(log_ptr);
227
}