~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/******************************************************
2
Rollback segment
3
4
(c) 1996 Innobase Oy
5
6
Created 3/26/1996 Heikki Tuuri
7
*******************************************************/
8
9
#include "srv0srv.h"
10
11
/**********************************************************************
12
Gets a rollback segment header. */
13
UNIV_INLINE
14
trx_rsegf_t*
15
trx_rsegf_get(
16
/*==========*/
17
				/* out: rollback segment header, page
18
				x-latched */
19
	ulint	space,		/* in: space where placed */
20
	ulint	page_no,	/* in: page number of the header */
21
	mtr_t*	mtr)		/* in: mtr */
22
{
23
	trx_rsegf_t*	header;
24
25
	header = TRX_RSEG + buf_page_get(space, page_no, RW_X_LATCH, mtr);
26
27
#ifdef UNIV_SYNC_DEBUG
28
	buf_page_dbg_add_level(header, SYNC_RSEG_HEADER);
29
#endif /* UNIV_SYNC_DEBUG */
30
31
	return(header);
32
}
33
34
/**********************************************************************
35
Gets a newly created rollback segment header. */
36
UNIV_INLINE
37
trx_rsegf_t*
38
trx_rsegf_get_new(
39
/*==============*/
40
				/* out: rollback segment header, page
41
				x-latched */
42
	ulint	space,		/* in: space where placed */
43
	ulint	page_no,	/* in: page number of the header */
44
	mtr_t*	mtr)		/* in: mtr */
45
{
46
	trx_rsegf_t*	header;
47
48
	header = TRX_RSEG + buf_page_get(space, page_no, RW_X_LATCH, mtr);
49
50
#ifdef UNIV_SYNC_DEBUG
51
	buf_page_dbg_add_level(header, SYNC_RSEG_HEADER_NEW);
52
#endif /* UNIV_SYNC_DEBUG */
53
54
	return(header);
55
}
56
57
/*******************************************************************
58
Gets the file page number of the nth undo log slot. */
59
UNIV_INLINE
60
ulint
61
trx_rsegf_get_nth_undo(
62
/*===================*/
63
				/* out: page number of the undo log segment */
64
	trx_rsegf_t*	rsegf,	/* in: rollback segment header */
65
	ulint		n,	/* in: index of slot */
66
	mtr_t*		mtr)	/* in: mtr */
67
{
68
	if (UNIV_UNLIKELY(n >= TRX_RSEG_N_SLOTS)) {
69
		fprintf(stderr,
70
			"InnoDB: Error: trying to get slot %lu of rseg\n",
71
			(ulong) n);
72
		ut_error;
73
	}
74
75
	return(mtr_read_ulint(rsegf + TRX_RSEG_UNDO_SLOTS
76
			      + n * TRX_RSEG_SLOT_SIZE, MLOG_4BYTES, mtr));
77
}
78
79
/*******************************************************************
80
Sets the file page number of the nth undo log slot. */
81
UNIV_INLINE
82
void
83
trx_rsegf_set_nth_undo(
84
/*===================*/
85
	trx_rsegf_t*	rsegf,	/* in: rollback segment header */
86
	ulint		n,	/* in: index of slot */
87
	ulint		page_no,/* in: page number of the undo log segment */
88
	mtr_t*		mtr)	/* in: mtr */
89
{
90
	if (UNIV_UNLIKELY(n >= TRX_RSEG_N_SLOTS)) {
91
		fprintf(stderr,
92
			"InnoDB: Error: trying to set slot %lu of rseg\n",
93
			(ulong) n);
94
		ut_error;
95
	}
96
97
	mlog_write_ulint(rsegf + TRX_RSEG_UNDO_SLOTS + n * TRX_RSEG_SLOT_SIZE,
98
			 page_no, MLOG_4BYTES, mtr);
99
}
100
101
/********************************************************************
102
Looks for a free slot for an undo log segment. */
103
UNIV_INLINE
104
ulint
105
trx_rsegf_undo_find_free(
106
/*=====================*/
107
				/* out: slot index or ULINT_UNDEFINED if not
108
				found */
109
	trx_rsegf_t*	rsegf,	/* in: rollback segment header */
110
	mtr_t*		mtr)	/* in: mtr */
111
{
112
	ulint		i;
113
	ulint		page_no;
114
115
	for (i = 0; i < TRX_RSEG_N_SLOTS; i++) {
116
117
		page_no = trx_rsegf_get_nth_undo(rsegf, i, mtr);
118
119
		if (page_no == FIL_NULL) {
120
121
			return(i);
122
		}
123
	}
124
125
	return(ULINT_UNDEFINED);
126
}