~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/******************************************************
2
Purge old versions
3
4
(c) 1996 Innobase Oy
5
6
Created 3/26/1996 Heikki Tuuri
7
*******************************************************/
8
9
#ifndef trx0purge_h
10
#define trx0purge_h
11
12
#include "univ.i"
13
#include "trx0types.h"
14
#include "mtr0mtr.h"
15
#include "trx0sys.h"
16
#include "que0types.h"
17
#include "page0page.h"
18
#include "usr0sess.h"
19
#include "fil0fil.h"
20
21
/* The global data structure coordinating a purge */
22
extern trx_purge_t*	purge_sys;
23
24
/* A dummy undo record used as a return value when we have a whole undo log
25
which needs no purge */
26
extern trx_undo_rec_t	trx_purge_dummy_rec;
27
28
/************************************************************************
29
Calculates the file address of an undo log header when we have the file
30
address of its history list node. */
31
UNIV_INLINE
32
fil_addr_t
33
trx_purge_get_log_from_hist(
34
/*========================*/
35
					/* out: file address of the log */
36
	fil_addr_t	node_addr);	/* in: file address of the history
37
					list node of the log */
38
/*********************************************************************
39
Checks if trx_id is >= purge_view: then it is guaranteed that its update
40
undo log still exists in the system. */
41
42
ibool
43
trx_purge_update_undo_must_exist(
44
/*=============================*/
45
			/* out: TRUE if is sure that it is preserved, also
46
			if the function returns FALSE, it is possible that
47
			the undo log still exists in the system */
48
	dulint	trx_id);/* in: transaction id */
49
/************************************************************************
50
Creates the global purge system control structure and inits the history
51
mutex. */
52
53
void
54
trx_purge_sys_create(void);
55
/*======================*/
56
/************************************************************************
57
Adds the update undo log as the first log in the history list. Removes the
58
update undo log segment from the rseg slot if it is too big for reuse. */
59
60
void
61
trx_purge_add_update_undo_to_history(
62
/*=================================*/
63
	trx_t*	trx,		/* in: transaction */
64
	page_t*	undo_page,	/* in: update undo log header page,
65
				x-latched */
66
	mtr_t*	mtr);		/* in: mtr */
67
/************************************************************************
68
Fetches the next undo log record from the history list to purge. It must be
69
released with the corresponding release function. */
70
71
trx_undo_rec_t*
72
trx_purge_fetch_next_rec(
73
/*=====================*/
74
				/* out: copy of an undo log record, or
75
				pointer to the dummy undo log record
76
				&trx_purge_dummy_rec if the whole undo log
77
				can skipped in purge; NULL if none left */
78
	dulint*		roll_ptr,/* out: roll pointer to undo record */
79
	trx_undo_inf_t** cell,	/* out: storage cell for the record in the
80
				purge array */
81
	mem_heap_t*	heap);	/* in: memory heap where copied */
82
/***********************************************************************
83
Releases a reserved purge undo record. */
84
85
void
86
trx_purge_rec_release(
87
/*==================*/
88
	trx_undo_inf_t*	cell);	/* in: storage cell */
89
/***********************************************************************
90
This function runs a purge batch. */
91
92
ulint
93
trx_purge(void);
94
/*===========*/
95
				/* out: number of undo log pages handled in
96
				the batch */
97
/**********************************************************************
98
Prints information of the purge system to stderr. */
99
100
void
101
trx_purge_sys_print(void);
102
/*======================*/
103
104
/* The control structure used in the purge operation */
105
struct trx_purge_struct{
106
	ulint		state;		/* Purge system state */
107
	sess_t*		sess;		/* System session running the purge
108
					query */
109
	trx_t*		trx;		/* System transaction running the purge
110
					query: this trx is not in the trx list
111
					of the trx system and it never ends */
112
	que_t*		query;		/* The query graph which will do the
113
					parallelized purge operation */
114
	rw_lock_t	latch;		/* The latch protecting the purge view.
115
					A purge operation must acquire an
116
					x-latch here for the instant at which
117
					it changes the purge view: an undo
118
					log operation can prevent this by
119
					obtaining an s-latch here. */
120
	read_view_t*	view;		/* The purge will not remove undo logs
121
					which are >= this view (purge view) */
122
	mutex_t		mutex;		/* Mutex protecting the fields below */
123
	ulint		n_pages_handled;/* Approximate number of undo log
124
					pages processed in purge */
125
	ulint		handle_limit;	/* Target of how many pages to get
126
					processed in the current purge */
127
	/*------------------------------*/
128
	/* The following two fields form the 'purge pointer' which advances
129
	during a purge, and which is used in history list truncation */
130
131
	dulint		purge_trx_no;	/* Purge has advanced past all
132
					transactions whose number is less
133
					than this */
134
	dulint		purge_undo_no;	/* Purge has advanced past all records
135
					whose undo number is less than this */
136
	/*-----------------------------*/
137
	ibool		next_stored;	/* TRUE if the info of the next record
138
					to purge is stored below: if yes, then
139
					the transaction number and the undo
140
					number of the record are stored in
141
					purge_trx_no and purge_undo_no above */
142
	trx_rseg_t*	rseg;		/* Rollback segment for the next undo
143
					record to purge */
144
	ulint		page_no;	/* Page number for the next undo
145
					record to purge, page number of the
146
					log header, if dummy record */
147
	ulint		offset;		/* Page offset for the next undo
148
					record to purge, 0 if the dummy
149
					record */
150
	ulint		hdr_page_no;	/* Header page of the undo log where
151
					the next record to purge belongs */
152
	ulint		hdr_offset;	/* Header byte offset on the page */
153
	/*-----------------------------*/
154
	trx_undo_arr_t*	arr;		/* Array of transaction numbers and
155
					undo numbers of the undo records
156
					currently under processing in purge */
157
	mem_heap_t*	heap;		/* Temporary storage used during a
158
					purge: can be emptied after purge
159
					completes */
160
};
161
162
#define TRX_PURGE_ON		1	/* purge operation is running */
163
#define TRX_STOP_PURGE		2	/* purge operation is stopped, or
164
					it should be stopped */
165
#ifndef UNIV_NONINL
166
#include "trx0purge.ic"
167
#endif
168
169
#endif