~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
4
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
8
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
17
*****************************************************************************/
18
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
19
/**************************************************//**
20
@file include/trx0rseg.ic
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
21
Rollback segment
22
23
Created 3/26/1996 Heikki Tuuri
24
*******************************************************/
25
26
#include "srv0srv.h"
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
27
#include "mtr0log.h"
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
28
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
29
/******************************************************************//**
30
Gets a rollback segment header.
31
@return	rollback segment header, page x-latched */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
32
UNIV_INLINE
33
trx_rsegf_t*
34
trx_rsegf_get(
35
/*==========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
36
	ulint	space,		/*!< in: space where placed */
37
	ulint	zip_size,	/*!< in: compressed page size in bytes
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
38
				or 0 for uncompressed pages */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
39
	ulint	page_no,	/*!< in: page number of the header */
40
	mtr_t*	mtr)		/*!< in: mtr */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
41
{
42
	buf_block_t*	block;
43
	trx_rsegf_t*	header;
44
45
	block = buf_page_get(space, zip_size, page_no, RW_X_LATCH, mtr);
46
	buf_block_dbg_add_level(block, SYNC_RSEG_HEADER);
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
47
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
48
	header = TRX_RSEG + buf_block_get_frame(block);
49
50
	return(header);
51
}
52
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
53
/******************************************************************//**
54
Gets a newly created rollback segment header.
55
@return	rollback segment header, page x-latched */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
56
UNIV_INLINE
57
trx_rsegf_t*
58
trx_rsegf_get_new(
59
/*==============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
60
	ulint	space,		/*!< in: space where placed */
61
	ulint	zip_size,	/*!< in: compressed page size in bytes
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
62
				or 0 for uncompressed pages */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
63
	ulint	page_no,	/*!< in: page number of the header */
64
	mtr_t*	mtr)		/*!< in: mtr */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
65
{
66
	buf_block_t*	block;
67
	trx_rsegf_t*	header;
68
69
	block = buf_page_get(space, zip_size, page_no, RW_X_LATCH, mtr);
70
	buf_block_dbg_add_level(block, SYNC_RSEG_HEADER_NEW);
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
71
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
72
	header = TRX_RSEG + buf_block_get_frame(block);
73
74
	return(header);
75
}
76
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
77
/***************************************************************//**
78
Gets the file page number of the nth undo log slot.
79
@return	page number of the undo log segment */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
80
UNIV_INLINE
81
ulint
82
trx_rsegf_get_nth_undo(
83
/*===================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
84
	trx_rsegf_t*	rsegf,	/*!< in: rollback segment header */
85
	ulint		n,	/*!< in: index of slot */
86
	mtr_t*		mtr)	/*!< in: mtr */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
87
{
88
	if (UNIV_UNLIKELY(n >= TRX_RSEG_N_SLOTS)) {
89
		fprintf(stderr,
90
			"InnoDB: Error: trying to get slot %lu of rseg\n",
91
			(ulong) n);
92
		ut_error;
93
	}
94
95
	return(mtr_read_ulint(rsegf + TRX_RSEG_UNDO_SLOTS
96
			      + n * TRX_RSEG_SLOT_SIZE, MLOG_4BYTES, mtr));
97
}
98
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
99
/***************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
100
Sets the file page number of the nth undo log slot. */
101
UNIV_INLINE
102
void
103
trx_rsegf_set_nth_undo(
104
/*===================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
105
	trx_rsegf_t*	rsegf,	/*!< in: rollback segment header */
106
	ulint		n,	/*!< in: index of slot */
107
	ulint		page_no,/*!< in: page number of the undo log segment */
108
	mtr_t*		mtr)	/*!< in: mtr */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
109
{
110
	if (UNIV_UNLIKELY(n >= TRX_RSEG_N_SLOTS)) {
111
		fprintf(stderr,
112
			"InnoDB: Error: trying to set slot %lu of rseg\n",
113
			(ulong) n);
114
		ut_error;
115
	}
116
117
	mlog_write_ulint(rsegf + TRX_RSEG_UNDO_SLOTS + n * TRX_RSEG_SLOT_SIZE,
118
			 page_no, MLOG_4BYTES, mtr);
119
}
120
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
121
/****************************************************************//**
122
Looks for a free slot for an undo log segment.
123
@return	slot index or ULINT_UNDEFINED if not found */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
124
UNIV_INLINE
125
ulint
126
trx_rsegf_undo_find_free(
127
/*=====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
128
	trx_rsegf_t*	rsegf,	/*!< in: rollback segment header */
129
	mtr_t*		mtr)	/*!< in: mtr */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
130
{
131
	ulint		i;
132
	ulint		page_no;
133
134
	for (i = 0; i < TRX_RSEG_N_SLOTS; i++) {
135
136
		page_no = trx_rsegf_get_nth_undo(rsegf, i, mtr);
137
138
		if (page_no == FIL_NULL) {
139
140
			return(i);
141
		}
142
	}
143
144
	return(ULINT_UNDEFINED);
145
}