~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/fil0fil.h

  • Committer: Monty Taylor
  • Date: 2009-03-08 23:45:12 UTC
  • mto: (923.2.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 921.
  • Revision ID: mordred@inaugust.com-20090308234512-tqkygxtu1iaig23s
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1995, 2010, 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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/fil0fil.h
 
1
/******************************************************
21
2
The low-level file system
22
3
 
 
4
(c) 1995 Innobase Oy
 
5
 
23
6
Created 10/25/1995 Heikki Tuuri
24
7
*******************************************************/
25
8
 
27
10
#define fil0fil_h
28
11
 
29
12
#include "univ.i"
 
13
#include "sync0rw.h"
30
14
#include "dict0types.h"
 
15
#include "ibuf0types.h"
31
16
#include "ut0byte.h"
32
17
#include "os0file.h"
33
 
#ifndef UNIV_HOTBACKUP
34
 
#include "sync0rw.h"
35
 
#include "ibuf0types.h"
36
 
#endif /* !UNIV_HOTBACKUP */
37
18
 
38
 
/** When mysqld is run, the default directory "." is the mysqld datadir,
39
 
but in the MySQL Embedded Server Library and ibbackup it is not the default
40
 
directory, and we must set the base file path explicitly */
 
19
/* When mysqld is run, the default directory "." is the mysqld datadir, but in
 
20
ibbackup we must set it explicitly; the patgh must NOT contain the trailing
 
21
'/' or '\' */
41
22
extern const char*      fil_path_to_mysql_datadir;
42
23
 
43
 
/** Initial size of a single-table tablespace in pages */
 
24
/* Initial size of a single-table tablespace in pages */
44
25
#define FIL_IBD_FILE_INITIAL_SIZE       4
45
26
 
46
 
/** 'null' (undefined) page offset in the context of file spaces */
 
27
/* 'null' (undefined) page offset in the context of file spaces */
47
28
#define FIL_NULL        ULINT32_UNDEFINED
48
29
 
49
30
/* Space address data type; this is intended to be used when
50
31
addresses accurate to a byte are stored in file pages. If the page part
51
32
of the address is FIL_NULL, the address is considered undefined. */
52
33
 
53
 
typedef byte    fil_faddr_t;    /*!< 'type' definition in C: an address
 
34
typedef byte    fil_faddr_t;    /* 'type' definition in C: an address
54
35
                                stored in a file page is a string of bytes */
55
36
#define FIL_ADDR_PAGE   0       /* first in address is the page offset */
56
37
#define FIL_ADDR_BYTE   4       /* then comes 2-byte byte offset within page*/
57
38
 
58
39
#define FIL_ADDR_SIZE   6       /* address size is 6 bytes */
59
40
 
60
 
/** A struct for storing a space address FIL_ADDR, when it is used
 
41
/* A struct for storing a space address FIL_ADDR, when it is used
61
42
in C program data structures. */
62
43
 
63
44
typedef struct fil_addr_struct  fil_addr_t;
64
 
/** File space address */
65
45
struct fil_addr_struct{
66
 
        ulint   page;           /*!< page number within a space */
67
 
        ulint   boffset;        /*!< byte offset within the page */
 
46
        ulint   page;           /* page number within a space */
 
47
        ulint   boffset;        /* byte offset within the page */
68
48
};
69
49
 
70
 
/** The null file address */
 
50
/* Null file address */
71
51
extern fil_addr_t       fil_addr_null;
72
52
 
73
 
/** The byte offsets on a file page for various variables @{ */
74
 
#define FIL_PAGE_SPACE_OR_CHKSUM 0      /*!< in < MySQL-4.0.14 space id the
 
53
/* The byte offsets on a file page for various variables */
 
54
#define FIL_PAGE_SPACE_OR_CHKSUM 0      /* in < MySQL-4.0.14 space id the
75
55
                                        page belongs to (== 0) but in later
76
56
                                        versions the 'new' checksum of the
77
57
                                        page */
78
 
#define FIL_PAGE_OFFSET         4       /*!< page offset inside space */
79
 
#define FIL_PAGE_PREV           8       /*!< if there is a 'natural'
80
 
                                        predecessor of the page, its
81
 
                                        offset.  Otherwise FIL_NULL.
82
 
                                        This field is not set on BLOB
83
 
                                        pages, which are stored as a
84
 
                                        singly-linked list.  See also
85
 
                                        FIL_PAGE_NEXT. */
86
 
#define FIL_PAGE_NEXT           12      /*!< if there is a 'natural' successor
 
58
#define FIL_PAGE_OFFSET         4       /* page offset inside space */
 
59
#define FIL_PAGE_PREV           8       /* if there is a 'natural' predecessor
 
60
                                        of the page, its offset.
 
61
                                        Otherwise FIL_NULL.
 
62
                                        This field is not set on BLOB pages,
 
63
                                        which are stored as a singly-linked
 
64
                                        list.  See also FIL_PAGE_NEXT. */
 
65
#define FIL_PAGE_NEXT           12      /* if there is a 'natural' successor
87
66
                                        of the page, its offset.
88
67
                                        Otherwise FIL_NULL.
89
68
                                        B-tree index pages
93
72
                                        FIL_PAGE_PREV and FIL_PAGE_NEXT
94
73
                                        in the collation order of the
95
74
                                        smallest user record on each page. */
96
 
#define FIL_PAGE_LSN            16      /*!< lsn of the end of the newest
 
75
#define FIL_PAGE_LSN            16      /* lsn of the end of the newest
97
76
                                        modification log record to the page */
98
 
#define FIL_PAGE_TYPE           24      /*!< file page type: FIL_PAGE_INDEX,...,
 
77
#define FIL_PAGE_TYPE           24      /* file page type: FIL_PAGE_INDEX,...,
99
78
                                        2 bytes.
100
79
 
101
80
                                        The contents of this field can only
110
89
                                        MySQL/InnoDB 5.1.7 or later, the
111
90
                                        contents of this field is valid
112
91
                                        for all uncompressed pages. */
113
 
#define FIL_PAGE_FILE_FLUSH_LSN 26      /*!< this is only defined for the
114
 
                                        first page in a system tablespace
115
 
                                        data file (ibdata*, not *.ibd):
116
 
                                        the file has been flushed to disk
117
 
                                        at least up to this lsn */
118
 
#define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID  34 /*!< starting from 4.1.x this
 
92
#define FIL_PAGE_FILE_FLUSH_LSN 26      /* this is only defined for the
 
93
                                        first page in a data file: the file
 
94
                                        has been flushed to disk at least up
 
95
                                        to this lsn */
 
96
#define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID  34 /* starting from 4.1.x this
119
97
                                        contains the space id of the page */
120
 
#define FIL_PAGE_DATA           38      /*!< start of the data on the page */
121
 
/* @} */
122
 
/** File page trailer @{ */
123
 
#define FIL_PAGE_END_LSN_OLD_CHKSUM 8   /*!< the low 4 bytes of this are used
 
98
#define FIL_PAGE_DATA           38      /* start of the data on the page */
 
99
 
 
100
/* File page trailer */
 
101
#define FIL_PAGE_END_LSN_OLD_CHKSUM 8   /* the low 4 bytes of this are used
124
102
                                        to store the page checksum, the
125
103
                                        last 4 bytes should be identical
126
104
                                        to the last 4 bytes of FIL_PAGE_LSN */
127
 
#define FIL_PAGE_DATA_END       8       /*!< size of the page trailer */
128
 
/* @} */
 
105
#define FIL_PAGE_DATA_END       8
129
106
 
130
 
/** File page types (values of FIL_PAGE_TYPE) @{ */
131
 
#define FIL_PAGE_INDEX          17855   /*!< B-tree node */
132
 
#define FIL_PAGE_UNDO_LOG       2       /*!< Undo log page */
133
 
#define FIL_PAGE_INODE          3       /*!< Index node */
134
 
#define FIL_PAGE_IBUF_FREE_LIST 4       /*!< Insert buffer free list */
 
107
/* File page types (values of FIL_PAGE_TYPE) */
 
108
#define FIL_PAGE_INDEX          17855   /* B-tree node */
 
109
#define FIL_PAGE_UNDO_LOG       2       /* Undo log page */
 
110
#define FIL_PAGE_INODE          3       /* Index node */
 
111
#define FIL_PAGE_IBUF_FREE_LIST 4       /* Insert buffer free list */
135
112
/* File page types introduced in MySQL/InnoDB 5.1.7 */
136
 
#define FIL_PAGE_TYPE_ALLOCATED 0       /*!< Freshly allocated page */
137
 
#define FIL_PAGE_IBUF_BITMAP    5       /*!< Insert buffer bitmap */
138
 
#define FIL_PAGE_TYPE_SYS       6       /*!< System page */
139
 
#define FIL_PAGE_TYPE_TRX_SYS   7       /*!< Transaction system data */
140
 
#define FIL_PAGE_TYPE_FSP_HDR   8       /*!< File space header */
141
 
#define FIL_PAGE_TYPE_XDES      9       /*!< Extent descriptor page */
142
 
#define FIL_PAGE_TYPE_BLOB      10      /*!< Uncompressed BLOB page */
143
 
#define FIL_PAGE_TYPE_ZBLOB     11      /*!< First compressed BLOB page */
144
 
#define FIL_PAGE_TYPE_ZBLOB2    12      /*!< Subsequent compressed BLOB page */
145
 
/* @} */
146
 
 
147
 
/** Space types @{ */
148
 
#define FIL_TABLESPACE          501     /*!< tablespace */
149
 
#define FIL_LOG                 502     /*!< redo log */
150
 
/* @} */
151
 
 
152
 
/** The number of fsyncs done to the log */
 
113
#define FIL_PAGE_TYPE_ALLOCATED 0       /* Freshly allocated page */
 
114
#define FIL_PAGE_IBUF_BITMAP    5       /* Insert buffer bitmap */
 
115
#define FIL_PAGE_TYPE_SYS       6       /* System page */
 
116
#define FIL_PAGE_TYPE_TRX_SYS   7       /* Transaction system data */
 
117
#define FIL_PAGE_TYPE_FSP_HDR   8       /* File space header */
 
118
#define FIL_PAGE_TYPE_XDES      9       /* Extent descriptor page */
 
119
#define FIL_PAGE_TYPE_BLOB      10      /* Uncompressed BLOB page */
 
120
#define FIL_PAGE_TYPE_ZBLOB     11      /* First compressed BLOB page */
 
121
#define FIL_PAGE_TYPE_ZBLOB2    12      /* Subsequent compressed BLOB page */
 
122
 
 
123
/* Space types */
 
124
#define FIL_TABLESPACE          501
 
125
#define FIL_LOG                 502
 
126
 
153
127
extern ulint    fil_n_log_flushes;
154
128
 
155
 
/** Number of pending redo log flushes */
156
129
extern ulint    fil_n_pending_log_flushes;
157
 
/** Number of pending tablespace flushes */
158
130
extern ulint    fil_n_pending_tablespace_flushes;
159
131
 
160
132
 
161
 
#ifndef UNIV_HOTBACKUP
162
 
/*******************************************************************//**
163
 
Returns the version number of a tablespace, -1 if not found.
164
 
@return version number, -1 if the tablespace does not exist in the
165
 
memory cache */
 
133
/***********************************************************************
 
134
Returns the version number of a tablespace, -1 if not found. */
166
135
UNIV_INTERN
167
136
ib_int64_t
168
137
fil_space_get_version(
169
138
/*==================*/
170
 
        ulint   id);    /*!< in: space id */
171
 
/*******************************************************************//**
172
 
Returns the latch of a file space.
173
 
@return latch protecting storage allocation */
 
139
                        /* out: version number, -1 if the tablespace does not
 
140
                        exist in the memory cache */
 
141
        ulint   id);    /* in: space id */
 
142
/***********************************************************************
 
143
Returns the latch of a file space. */
174
144
UNIV_INTERN
175
145
rw_lock_t*
176
146
fil_space_get_latch(
177
147
/*================*/
178
 
        ulint   id,     /*!< in: space id */
179
 
        ulint*  zip_size);/*!< out: compressed page size, or
 
148
                        /* out: latch protecting storage allocation */
 
149
        ulint   id,     /* in: space id */
 
150
        ulint*  zip_size);/* out: compressed page size, or
180
151
                        0 for uncompressed tablespaces */
181
 
/*******************************************************************//**
182
 
Returns the type of a file space.
183
 
@return FIL_TABLESPACE or FIL_LOG */
 
152
/***********************************************************************
 
153
Returns the type of a file space. */
184
154
UNIV_INTERN
185
155
ulint
186
156
fil_space_get_type(
187
157
/*===============*/
188
 
        ulint   id);    /*!< in: space id */
189
 
#endif /* !UNIV_HOTBACKUP */
190
 
/*******************************************************************//**
 
158
                        /* out: FIL_TABLESPACE or FIL_LOG */
 
159
        ulint   id);    /* in: space id */
 
160
/***********************************************************************
 
161
Returns the ibuf data of a file space. */
 
162
UNIV_INTERN
 
163
ibuf_data_t*
 
164
fil_space_get_ibuf_data(
 
165
/*====================*/
 
166
                        /* out: ibuf data for this space */
 
167
        ulint   id);    /* in: space id */
 
168
/***********************************************************************
191
169
Appends a new file to the chain of files of a space. File must be closed. */
192
170
UNIV_INTERN
193
171
void
194
172
fil_node_create(
195
173
/*============*/
196
 
        const char*     name,   /*!< in: file name (file must be closed) */
197
 
        ulint           size,   /*!< in: file size in database blocks, rounded
 
174
        const char*     name,   /* in: file name (file must be closed) */
 
175
        ulint           size,   /* in: file size in database blocks, rounded
198
176
                                downwards to an integer */
199
 
        ulint           id,     /*!< in: space id where to append */
200
 
        ibool           is_raw);/*!< in: TRUE if a raw device or
 
177
        ulint           id,     /* in: space id where to append */
 
178
        ibool           is_raw);/* in: TRUE if a raw device or
201
179
                                a raw disk partition */
202
180
#ifdef UNIV_LOG_ARCHIVE
203
 
/****************************************************************//**
 
181
/********************************************************************
204
182
Drops files from the start of a file space, so that its size is cut by
205
183
the amount given. */
206
184
UNIV_INTERN
207
185
void
208
186
fil_space_truncate_start(
209
187
/*=====================*/
210
 
        ulint   id,             /*!< in: space id */
211
 
        ulint   trunc_len);     /*!< in: truncate by this much; it is an error
 
188
        ulint   id,             /* in: space id */
 
189
        ulint   trunc_len);     /* in: truncate by this much; it is an error
212
190
                                if this does not equal to the combined size of
213
191
                                some initial files in the space */
214
192
#endif /* UNIV_LOG_ARCHIVE */
215
 
/*******************************************************************//**
 
193
/***********************************************************************
216
194
Creates a space memory object and puts it to the 'fil system' hash table. If
217
 
there is an error, prints an error message to the .err log.
218
 
@return TRUE if success */
 
195
there is an error, prints an error message to the .err log. */
219
196
UNIV_INTERN
220
197
ibool
221
198
fil_space_create(
222
199
/*=============*/
223
 
        const char*     name,   /*!< in: space name */
224
 
        ulint           id,     /*!< in: space id */
225
 
        ulint           zip_size,/*!< in: compressed page size, or
 
200
                                /* out: TRUE if success */
 
201
        const char*     name,   /* in: space name */
 
202
        ulint           id,     /* in: space id */
 
203
        ulint           zip_size,/* in: compressed page size, or
226
204
                                0 for uncompressed tablespaces */
227
 
        ulint           purpose);/*!< in: FIL_TABLESPACE, or FIL_LOG if log */
228
 
/*******************************************************************//**
229
 
Assigns a new space id for a new single-table tablespace. This works simply by
230
 
incrementing the global counter. If 4 billion id's is not enough, we may need
231
 
to recycle id's.
232
 
@return TRUE if assigned, FALSE if not */
 
205
        ulint           purpose);/* in: FIL_TABLESPACE, or FIL_LOG if log */
 
206
/***********************************************************************
 
207
Frees a space object from a the tablespace memory cache. Closes the files in
 
208
the chain but does not delete them. */
233
209
UNIV_INTERN
234
210
ibool
235
 
fil_assign_new_space_id(
236
 
/*====================*/
237
 
        ulint*  space_id);      /*!< in/out: space id */
238
 
/*******************************************************************//**
 
211
fil_space_free(
 
212
/*===========*/
 
213
                        /* out: TRUE if success */
 
214
        ulint   id);    /* in: space id */
 
215
/***********************************************************************
239
216
Returns the size of the space in pages. The tablespace must be cached in the
240
 
memory cache.
241
 
@return space size, 0 if space not found */
 
217
memory cache. */
242
218
UNIV_INTERN
243
219
ulint
244
220
fil_space_get_size(
245
221
/*===============*/
246
 
        ulint   id);    /*!< in: space id */
247
 
/*******************************************************************//**
 
222
                        /* out: space size, 0 if space not found */
 
223
        ulint   id);    /* in: space id */
 
224
/***********************************************************************
248
225
Returns the flags of the space. The tablespace must be cached
249
 
in the memory cache.
250
 
@return flags, ULINT_UNDEFINED if space not found */
 
226
in the memory cache. */
251
227
UNIV_INTERN
252
228
ulint
253
229
fil_space_get_flags(
254
230
/*================*/
255
 
        ulint   id);    /*!< in: space id */
256
 
/*******************************************************************//**
 
231
                        /* out: flags, ULINT_UNDEFINED if space not found */
 
232
        ulint   id);    /* in: space id */
 
233
/***********************************************************************
257
234
Returns the compressed page size of the space, or 0 if the space
258
 
is not compressed. The tablespace must be cached in the memory cache.
259
 
@return compressed page size, ULINT_UNDEFINED if space not found */
 
235
is not compressed. The tablespace must be cached in the memory cache. */
260
236
UNIV_INTERN
261
237
ulint
262
238
fil_space_get_zip_size(
263
239
/*===================*/
264
 
        ulint   id);    /*!< in: space id */
265
 
/*******************************************************************//**
 
240
                        /* out: compressed page size, ULINT_UNDEFINED
 
241
                        if space not found */
 
242
        ulint   id);    /* in: space id */
 
243
/***********************************************************************
266
244
Checks if the pair space, page_no refers to an existing page in a tablespace
267
 
file space. The tablespace must be cached in the memory cache.
268
 
@return TRUE if the address is meaningful */
 
245
file space. The tablespace must be cached in the memory cache. */
269
246
UNIV_INTERN
270
247
ibool
271
248
fil_check_adress_in_tablespace(
272
249
/*===========================*/
273
 
        ulint   id,     /*!< in: space id */
274
 
        ulint   page_no);/*!< in: page number */
275
 
/****************************************************************//**
 
250
                        /* out: TRUE if the address is meaningful */
 
251
        ulint   id,     /* in: space id */
 
252
        ulint   page_no);/* in: page number */
 
253
/********************************************************************
276
254
Initializes the tablespace memory cache. */
277
255
UNIV_INTERN
278
256
void
279
257
fil_init(
280
258
/*=====*/
281
 
        ulint   hash_size,      /*!< in: hash table size */
282
 
        ulint   max_n_open);    /*!< in: max number of open files */
283
 
/*******************************************************************//**
284
 
Initializes the tablespace memory cache. */
285
 
UNIV_INTERN
286
 
void
287
 
fil_close(void);
288
 
/*===========*/
289
 
/*******************************************************************//**
 
259
        ulint   max_n_open);    /* in: max number of open files */
 
260
/***********************************************************************
290
261
Opens all log files and system tablespace data files. They stay open until the
291
262
database server shutdown. This should be called at a server startup after the
292
263
space objects for the log and the system tablespace have been created. The
296
267
void
297
268
fil_open_log_and_system_tablespace_files(void);
298
269
/*==========================================*/
299
 
/*******************************************************************//**
 
270
/***********************************************************************
300
271
Closes all open files. There must not be any pending i/o's or not flushed
301
272
modifications in the files. */
302
273
UNIV_INTERN
303
274
void
304
275
fil_close_all_files(void);
305
276
/*=====================*/
306
 
/*******************************************************************//**
 
277
/***********************************************************************
307
278
Sets the max tablespace id counter if the given number is bigger than the
308
279
previous value. */
309
280
UNIV_INTERN
310
281
void
311
282
fil_set_max_space_id_if_bigger(
312
283
/*===========================*/
313
 
        ulint   max_id);/*!< in: maximum known id */
314
 
#ifndef UNIV_HOTBACKUP
315
 
/****************************************************************//**
 
284
        ulint   max_id);/* in: maximum known id */
 
285
/********************************************************************
 
286
Initializes the ibuf data structure for space 0 == the system tablespace.
 
287
This can be called after the file space headers have been created and the
 
288
dictionary system has been initialized. */
 
289
UNIV_INTERN
 
290
void
 
291
fil_ibuf_init_at_db_start(void);
 
292
/*===========================*/
 
293
/********************************************************************
316
294
Writes the flushed lsn and the latest archived log number to the page
317
 
header of the first page of each data file in the system tablespace.
318
 
@return DB_SUCCESS or error number */
 
295
header of the first page of each data file in the system tablespace. */
319
296
UNIV_INTERN
320
297
ulint
321
298
fil_write_flushed_lsn_to_data_files(
322
299
/*================================*/
323
 
        ib_uint64_t     lsn,            /*!< in: lsn to write */
324
 
        ulint           arch_log_no);   /*!< in: latest archived log
 
300
                                        /* out: DB_SUCCESS or error number */
 
301
        ib_uint64_t     lsn,            /* in: lsn to write */
 
302
        ulint           arch_log_no);   /* in: latest archived log
325
303
                                        file number */
326
 
/*******************************************************************//**
 
304
/***********************************************************************
327
305
Reads the flushed lsn and arch no fields from a data file at database
328
306
startup. */
329
307
UNIV_INTERN
330
308
void
331
309
fil_read_flushed_lsn_and_arch_log_no(
332
310
/*=================================*/
333
 
        os_file_t       data_file,              /*!< in: open data file */
334
 
        ibool           one_read_already,       /*!< in: TRUE if min and max
 
311
        os_file_t       data_file,              /* in: open data file */
 
312
        ibool           one_read_already,       /* in: TRUE if min and max
335
313
                                                parameters below already
336
314
                                                contain sensible data */
337
315
#ifdef UNIV_LOG_ARCHIVE
338
 
        ulint*          min_arch_log_no,        /*!< in/out: */
339
 
        ulint*          max_arch_log_no,        /*!< in/out: */
 
316
        ulint*          min_arch_log_no,        /* in/out: */
 
317
        ulint*          max_arch_log_no,        /* in/out: */
340
318
#endif /* UNIV_LOG_ARCHIVE */
341
 
        ib_uint64_t*    min_flushed_lsn,        /*!< in/out: */
342
 
        ib_uint64_t*    max_flushed_lsn);       /*!< in/out: */
343
 
/*******************************************************************//**
 
319
        ib_uint64_t*    min_flushed_lsn,        /* in/out: */
 
320
        ib_uint64_t*    max_flushed_lsn);       /* in/out: */
 
321
/***********************************************************************
344
322
Increments the count of pending insert buffer page merges, if space is not
345
 
being deleted.
346
 
@return TRUE if being deleted, and ibuf merges should be skipped */
 
323
being deleted. */
347
324
UNIV_INTERN
348
325
ibool
349
326
fil_inc_pending_ibuf_merges(
350
327
/*========================*/
351
 
        ulint   id);    /*!< in: space id */
352
 
/*******************************************************************//**
 
328
                        /* out: TRUE if being deleted, and ibuf merges should
 
329
                        be skipped */
 
330
        ulint   id);    /* in: space id */
 
331
/***********************************************************************
353
332
Decrements the count of pending insert buffer page merges. */
354
333
UNIV_INTERN
355
334
void
356
335
fil_decr_pending_ibuf_merges(
357
336
/*=========================*/
358
 
        ulint   id);    /*!< in: space id */
359
 
#endif /* !UNIV_HOTBACKUP */
360
 
/*******************************************************************//**
 
337
        ulint   id);    /* in: space id */
 
338
/***********************************************************************
361
339
Parses the body of a log record written about an .ibd file operation. That is,
362
340
the log record part after the standard (type, space id, page no) header of the
363
341
log record.
368
346
created does not exist, then we create the directory, too.
369
347
 
370
348
Note that ibbackup --apply-log sets fil_path_to_mysql_datadir to point to the
371
 
datadir that we should use in replaying the file operations.
372
 
@return end of log record, or NULL if the record was not completely
373
 
contained between ptr and end_ptr */
 
349
datadir that we should use in replaying the file operations. */
374
350
UNIV_INTERN
375
351
byte*
376
352
fil_op_log_parse_or_replay(
377
353
/*=======================*/
378
 
        byte*   ptr,            /*!< in: buffer containing the log record body,
 
354
                                /* out: end of log record, or NULL if the
 
355
                                record was not completely contained between
 
356
                                ptr and end_ptr */
 
357
        byte*   ptr,            /* in: buffer containing the log record body,
379
358
                                or an initial segment of it, if the record does
380
359
                                not fir completely between ptr and end_ptr */
381
 
        byte*   end_ptr,        /*!< in: buffer end */
382
 
        ulint   type,           /*!< in: the type of this log record */
383
 
        ulint   space_id,       /*!< in: the space id of the tablespace in
 
360
        byte*   end_ptr,        /* in: buffer end */
 
361
        ulint   type,           /* in: the type of this log record */
 
362
        ulint   space_id);      /* in: the space id of the tablespace in
384
363
                                question, or 0 if the log record should
385
364
                                only be parsed but not replayed */
386
 
        ulint   log_flags);     /*!< in: redo log flags
387
 
                                (stored in the page number parameter) */
388
 
/*******************************************************************//**
 
365
/***********************************************************************
389
366
Deletes a single-table tablespace. The tablespace must be cached in the
390
 
memory cache.
391
 
@return TRUE if success */
 
367
memory cache. */
392
368
UNIV_INTERN
393
369
ibool
394
370
fil_delete_tablespace(
395
371
/*==================*/
396
 
        ulint   id);    /*!< in: space id */
397
 
#ifndef UNIV_HOTBACKUP
398
 
/*******************************************************************//**
 
372
                        /* out: TRUE if success */
 
373
        ulint   id);    /* in: space id */
 
374
/***********************************************************************
399
375
Discards a single-table tablespace. The tablespace must be cached in the
400
376
memory cache. Discarding is like deleting a tablespace, but
401
377
1) we do not drop the table from the data dictionary;
402
378
2) we remove all insert buffer entries for the tablespace immediately; in DROP
403
379
TABLE they are only removed gradually in the background;
404
380
3) when the user does IMPORT TABLESPACE, the tablespace will have the same id
405
 
as it originally had.
406
 
@return TRUE if success */
 
381
as it originally had. */
407
382
UNIV_INTERN
408
383
ibool
409
384
fil_discard_tablespace(
410
385
/*===================*/
411
 
        ulint   id);    /*!< in: space id */
412
 
#endif /* !UNIV_HOTBACKUP */
413
 
/*******************************************************************//**
 
386
                        /* out: TRUE if success */
 
387
        ulint   id);    /* in: space id */
 
388
/***********************************************************************
414
389
Renames a single-table tablespace. The tablespace must be cached in the
415
 
tablespace memory cache.
416
 
@return TRUE if success */
 
390
tablespace memory cache. */
417
391
UNIV_INTERN
418
392
ibool
419
393
fil_rename_tablespace(
420
394
/*==================*/
421
 
        const char*     old_name,       /*!< in: old table name in the standard
 
395
                                        /* out: TRUE if success */
 
396
        const char*     old_name,       /* in: old table name in the standard
422
397
                                        databasename/tablename format of
423
398
                                        InnoDB, or NULL if we do the rename
424
399
                                        based on the space id only */
425
 
        ulint           id,             /*!< in: space id */
426
 
        const char*     new_name);      /*!< in: new table name in the standard
 
400
        ulint           id,             /* in: space id */
 
401
        const char*     new_name);      /* in: new table name in the standard
427
402
                                        databasename/tablename format
428
403
                                        of InnoDB */
429
404
 
430
 
/*******************************************************************//**
 
405
/***********************************************************************
431
406
Creates a new single-table tablespace to a database directory of MySQL.
432
407
Database directories are under the 'datadir' of MySQL. The datadir is the
433
408
directory of a running mysqld program. We can refer to it by simply the
434
409
path '.'. Tables created with CREATE TEMPORARY TABLE we place in the temp
435
 
dir of the mysqld server.
436
 
@return DB_SUCCESS or error code */
 
410
dir of the mysqld server. */
437
411
UNIV_INTERN
438
412
ulint
439
413
fil_create_new_single_table_tablespace(
440
414
/*===================================*/
441
 
        ulint           space_id,       /*!< in: space id */
442
 
        const char*     tablename,      /*!< in: the table name in the usual
 
415
                                        /* out: DB_SUCCESS or error code */
 
416
        ulint*          space_id,       /* in/out: space id; if this is != 0,
 
417
                                        then this is an input parameter,
 
418
                                        otherwise output */
 
419
        const char*     tablename,      /* in: the table name in the usual
443
420
                                        databasename/tablename format
444
421
                                        of InnoDB, or a dir path to a temp
445
422
                                        table */
446
 
        ibool           is_temp,        /*!< in: TRUE if a table created with
 
423
        ibool           is_temp,        /* in: TRUE if a table created with
447
424
                                        CREATE TEMPORARY TABLE */
448
 
        ulint           flags,          /*!< in: tablespace flags */
449
 
        ulint           size);          /*!< in: the initial size of the
 
425
        ulint           flags,          /* in: tablespace flags */
 
426
        ulint           size);          /* in: the initial size of the
450
427
                                        tablespace file in pages,
451
428
                                        must be >= FIL_IBD_FILE_INITIAL_SIZE */
452
 
#ifndef UNIV_HOTBACKUP
453
 
/********************************************************************//**
 
429
/************************************************************************
454
430
Tries to open a single-table tablespace and optionally checks the space id is
455
431
right in it. If does not succeed, prints an error message to the .err log. This
456
432
function is used to open a tablespace when we start up mysqld, and also in
458
434
NOTE that we assume this operation is used either at the database startup
459
435
or under the protection of the dictionary mutex, so that two users cannot
460
436
race here. This operation does not leave the file associated with the
461
 
tablespace open, but closes it after we have looked at the space id in it.
462
 
@return TRUE if success */
 
437
tablespace open, but closes it after we have looked at the space id in it. */
463
438
UNIV_INTERN
464
439
ibool
465
440
fil_open_single_table_tablespace(
466
441
/*=============================*/
467
 
        ibool           check_space_id, /*!< in: should we check that the space
 
442
                                        /* out: TRUE if success */
 
443
        ibool           check_space_id, /* in: should we check that the space
468
444
                                        id in the file is right; we assume
469
445
                                        that this function runs much faster
470
446
                                        if no check is made, since accessing
471
447
                                        the file inode probably is much
472
448
                                        faster (the OS caches them) than
473
449
                                        accessing the first page of the file */
474
 
        ulint           id,             /*!< in: space id */
475
 
        ulint           flags,          /*!< in: tablespace flags */
476
 
        const char*     name);          /*!< in: table name in the
 
450
        ulint           id,             /* in: space id */
 
451
        ulint           flags,          /* in: tablespace flags */
 
452
        const char*     name);          /* in: table name in the
477
453
                                        databasename/tablename format */
478
 
/********************************************************************//**
 
454
/************************************************************************
479
455
It is possible, though very improbable, that the lsn's in the tablespace to be
480
456
imported have risen above the current system lsn, if a lengthy purge, ibuf
481
457
merge, or rollback was performed on a backup taken with ibbackup. If that is
483
459
after it performed these cleanup operations on the .ibd file, so that it at
484
460
the shutdown stamped the latest lsn to the FIL_PAGE_FILE_FLUSH_LSN in the
485
461
first page of the .ibd file, and we can determine whether we need to reset the
486
 
lsn's just by looking at that flush lsn.
487
 
@return TRUE if success */
 
462
lsn's just by looking at that flush lsn. */
488
463
UNIV_INTERN
489
464
ibool
490
465
fil_reset_too_high_lsns(
491
466
/*====================*/
492
 
        const char*     name,           /*!< in: table name in the
 
467
                                        /* out: TRUE if success */
 
468
        const char*     name,           /* in: table name in the
493
469
                                        databasename/tablename format */
494
 
        ib_uint64_t     current_lsn);   /*!< in: reset lsn's if the lsn stamped
 
470
        ib_uint64_t     current_lsn);   /* in: reset lsn's if the lsn stamped
495
471
                                        to FIL_PAGE_FILE_FLUSH_LSN in the
496
472
                                        first page is too high */
497
 
#endif /* !UNIV_HOTBACKUP */
498
 
/********************************************************************//**
 
473
/************************************************************************
499
474
At the server startup, if we need crash recovery, scans the database
500
475
directories under the MySQL datadir, looking for .ibd files. Those files are
501
476
single-table tablespaces. We need to know the space id in each of them so that
502
477
we know into which file we should look to check the contents of a page stored
503
478
in the doublewrite buffer, also to know where to apply log records where the
504
 
space id is != 0.
505
 
@return DB_SUCCESS or error number */
 
479
space id is != 0. */
506
480
UNIV_INTERN
507
481
ulint
508
482
fil_load_single_table_tablespaces(void);
509
483
/*===================================*/
510
 
/*******************************************************************//**
 
484
                        /* out: DB_SUCCESS or error number */
 
485
/************************************************************************
 
486
If we need crash recovery, and we have called
 
487
fil_load_single_table_tablespaces() and dict_load_single_table_tablespaces(),
 
488
we can call this function to print an error message of orphaned .ibd files
 
489
for which there is not a data dictionary entry with a matching table name
 
490
and space id. */
 
491
UNIV_INTERN
 
492
void
 
493
fil_print_orphaned_tablespaces(void);
 
494
/*================================*/
 
495
/***********************************************************************
511
496
Returns TRUE if a single-table tablespace does not exist in the memory cache,
512
 
or is being deleted there.
513
 
@return TRUE if does not exist or is being\ deleted */
 
497
or is being deleted there. */
514
498
UNIV_INTERN
515
499
ibool
516
500
fil_tablespace_deleted_or_being_deleted_in_mem(
517
501
/*===========================================*/
518
 
        ulint           id,     /*!< in: space id */
519
 
        ib_int64_t      version);/*!< in: tablespace_version should be this; if
 
502
                                /* out: TRUE if does not exist or is being\
 
503
                                deleted */
 
504
        ulint           id,     /* in: space id */
 
505
        ib_int64_t      version);/* in: tablespace_version should be this; if
520
506
                                you pass -1 as the value of this, then this
521
507
                                parameter is ignored */
522
 
/*******************************************************************//**
523
 
Returns TRUE if a single-table tablespace exists in the memory cache.
524
 
@return TRUE if exists */
 
508
/***********************************************************************
 
509
Returns TRUE if a single-table tablespace exists in the memory cache. */
525
510
UNIV_INTERN
526
511
ibool
527
512
fil_tablespace_exists_in_mem(
528
513
/*=========================*/
529
 
        ulint   id);    /*!< in: space id */
530
 
#ifndef UNIV_HOTBACKUP
531
 
/*******************************************************************//**
 
514
                        /* out: TRUE if exists */
 
515
        ulint   id);    /* in: space id */
 
516
/***********************************************************************
532
517
Returns TRUE if a matching tablespace exists in the InnoDB tablespace memory
533
518
cache. Note that if we have not done a crash recovery at the database startup,
534
 
there may be many tablespaces which are not yet in the memory cache.
535
 
@return TRUE if a matching tablespace exists in the memory cache */
 
519
there may be many tablespaces which are not yet in the memory cache. */
536
520
UNIV_INTERN
537
521
ibool
538
522
fil_space_for_table_exists_in_mem(
539
523
/*==============================*/
540
 
        ulint           id,             /*!< in: space id */
541
 
        const char*     name,           /*!< in: table name in the standard
 
524
                                        /* out: TRUE if a matching tablespace
 
525
                                        exists in the memory cache */
 
526
        ulint           id,             /* in: space id */
 
527
        const char*     name,           /* in: table name in the standard
542
528
                                        'databasename/tablename' format or
543
529
                                        the dir path to a temp table */
544
 
        ibool           is_temp,        /*!< in: TRUE if created with CREATE
 
530
        ibool           is_temp,        /* in: TRUE if created with CREATE
545
531
                                        TEMPORARY TABLE */
546
 
        ibool           mark_space,     /*!< in: in crash recovery, at database
 
532
        ibool           mark_space,     /* in: in crash recovery, at database
547
533
                                        startup we mark all spaces which have
548
534
                                        an associated table in the InnoDB
549
535
                                        data dictionary, so that
550
536
                                        we can print a warning about orphaned
551
537
                                        tablespaces */
552
538
        ibool           print_error_if_does_not_exist);
553
 
                                        /*!< in: print detailed error
 
539
                                        /* in: print detailed error
554
540
                                        information to the .err log if a
555
541
                                        matching tablespace is not found from
556
542
                                        memory */
557
 
#else /* !UNIV_HOTBACKUP */
558
 
/********************************************************************//**
559
 
Extends all tablespaces to the size stored in the space header. During the
560
 
ibbackup --apply-log phase we extended the spaces on-demand so that log records
561
 
could be appllied, but that may have left spaces still too small compared to
562
 
the size stored in the space header. */
563
 
UNIV_INTERN
564
 
void
565
 
fil_extend_tablespaces_to_stored_len(void);
566
 
/*======================================*/
567
 
#endif /* !UNIV_HOTBACKUP */
568
 
/**********************************************************************//**
 
543
/**************************************************************************
569
544
Tries to extend a data file so that it would accommodate the number of pages
570
545
given. The tablespace must be cached in the memory cache. If the space is big
571
 
enough already, does nothing.
572
 
@return TRUE if success */
 
546
enough already, does nothing. */
573
547
UNIV_INTERN
574
548
ibool
575
549
fil_extend_space_to_desired_size(
576
550
/*=============================*/
577
 
        ulint*  actual_size,    /*!< out: size of the space after extension;
 
551
                                /* out: TRUE if success */
 
552
        ulint*  actual_size,    /* out: size of the space after extension;
578
553
                                if we ran out of disk space this may be lower
579
554
                                than the desired size */
580
 
        ulint   space_id,       /*!< in: space id */
581
 
        ulint   size_after_extend);/*!< in: desired size in pages after the
 
555
        ulint   space_id,       /* in: space id */
 
556
        ulint   size_after_extend);/* in: desired size in pages after the
582
557
                                extension; if the current space size is bigger
583
558
                                than this already, the function does nothing */
584
 
/*******************************************************************//**
585
 
Tries to reserve free extents in a file space.
586
 
@return TRUE if succeed */
 
559
#ifdef UNIV_HOTBACKUP
 
560
/************************************************************************
 
561
Extends all tablespaces to the size stored in the space header. During the
 
562
ibbackup --apply-log phase we extended the spaces on-demand so that log records
 
563
could be appllied, but that may have left spaces still too small compared to
 
564
the size stored in the space header. */
 
565
UNIV_INTERN
 
566
void
 
567
fil_extend_tablespaces_to_stored_len(void);
 
568
/*======================================*/
 
569
#endif
 
570
/***********************************************************************
 
571
Tries to reserve free extents in a file space. */
587
572
UNIV_INTERN
588
573
ibool
589
574
fil_space_reserve_free_extents(
590
575
/*===========================*/
591
 
        ulint   id,             /*!< in: space id */
592
 
        ulint   n_free_now,     /*!< in: number of free extents now */
593
 
        ulint   n_to_reserve);  /*!< in: how many one wants to reserve */
594
 
/*******************************************************************//**
 
576
                                /* out: TRUE if succeed */
 
577
        ulint   id,             /* in: space id */
 
578
        ulint   n_free_now,     /* in: number of free extents now */
 
579
        ulint   n_to_reserve);  /* in: how many one wants to reserve */
 
580
/***********************************************************************
595
581
Releases free extents in a file space. */
596
582
UNIV_INTERN
597
583
void
598
584
fil_space_release_free_extents(
599
585
/*===========================*/
600
 
        ulint   id,             /*!< in: space id */
601
 
        ulint   n_reserved);    /*!< in: how many one reserved */
602
 
/*******************************************************************//**
 
586
        ulint   id,             /* in: space id */
 
587
        ulint   n_reserved);    /* in: how many one reserved */
 
588
/***********************************************************************
603
589
Gets the number of reserved extents. If the database is silent, this number
604
590
should be zero. */
605
591
UNIV_INTERN
606
592
ulint
607
593
fil_space_get_n_reserved_extents(
608
594
/*=============================*/
609
 
        ulint   id);            /*!< in: space id */
610
 
/********************************************************************//**
611
 
Reads or writes data. This operation is asynchronous (aio).
612
 
@return DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do
613
 
i/o on a tablespace which does not exist */
 
595
        ulint   id);            /* in: space id */
 
596
/************************************************************************
 
597
Reads or writes data. This operation is asynchronous (aio). */
614
598
UNIV_INTERN
615
599
ulint
616
600
fil_io(
617
601
/*===*/
618
 
        ulint   type,           /*!< in: OS_FILE_READ or OS_FILE_WRITE,
 
602
                                /* out: DB_SUCCESS, or DB_TABLESPACE_DELETED
 
603
                                if we are trying to do i/o on a tablespace
 
604
                                which does not exist */
 
605
        ulint   type,           /* in: OS_FILE_READ or OS_FILE_WRITE,
619
606
                                ORed to OS_FILE_LOG, if a log i/o
620
607
                                and ORed to OS_AIO_SIMULATED_WAKE_LATER
621
608
                                if simulated aio and we want to post a
624
611
                                because i/os are not actually handled until
625
612
                                all have been posted: use with great
626
613
                                caution! */
627
 
        ibool   sync,           /*!< in: TRUE if synchronous aio is desired */
628
 
        ulint   space_id,       /*!< in: space id */
629
 
        ulint   zip_size,       /*!< in: compressed page size in bytes;
 
614
        ibool   sync,           /* in: TRUE if synchronous aio is desired */
 
615
        ulint   space_id,       /* in: space id */
 
616
        ulint   zip_size,       /* in: compressed page size in bytes;
630
617
                                0 for uncompressed pages */
631
 
        ulint   block_offset,   /*!< in: offset in number of blocks */
632
 
        ulint   byte_offset,    /*!< in: remainder of offset in bytes; in
 
618
        ulint   block_offset,   /* in: offset in number of blocks */
 
619
        ulint   byte_offset,    /* in: remainder of offset in bytes; in
633
620
                                aio this must be divisible by the OS block
634
621
                                size */
635
 
        ulint   len,            /*!< in: how many bytes to read or write; this
 
622
        ulint   len,            /* in: how many bytes to read or write; this
636
623
                                must not cross a file boundary; in aio this
637
624
                                must be a block size multiple */
638
 
        void*   buf,            /*!< in/out: buffer where to store read data
 
625
        void*   buf,            /* in/out: buffer where to store read data
639
626
                                or from where to write; in aio this must be
640
627
                                appropriately aligned */
641
 
        void*   message);       /*!< in: message for aio handler if non-sync
 
628
        void*   message);       /* in: message for aio handler if non-sync
642
629
                                aio used, else ignored */
643
 
/**********************************************************************//**
 
630
/**************************************************************************
644
631
Waits for an aio operation to complete. This function is used to write the
645
632
handler for completed requests. The aio array of pending requests is divided
646
633
into segments (see os0file.c for more info). The thread specifies which
649
636
void
650
637
fil_aio_wait(
651
638
/*=========*/
652
 
        ulint   segment);       /*!< in: the number of the segment in the aio
 
639
        ulint   segment);       /* in: the number of the segment in the aio
653
640
                                array to wait for */
654
 
/**********************************************************************//**
 
641
/**************************************************************************
655
642
Flushes to disk possible writes cached by the OS. If the space does not exist
656
643
or is being dropped, does not do anything. */
657
644
UNIV_INTERN
658
645
void
659
646
fil_flush(
660
647
/*======*/
661
 
        ulint   space_id);      /*!< in: file space id (this can be a group of
 
648
        ulint   space_id);      /* in: file space id (this can be a group of
662
649
                                log files or a tablespace of the database) */
663
 
/**********************************************************************//**
 
650
/**************************************************************************
664
651
Flushes to disk writes in file spaces of the given type possibly cached by
665
652
the OS. */
666
653
UNIV_INTERN
667
654
void
668
655
fil_flush_file_spaces(
669
656
/*==================*/
670
 
        ulint   purpose);       /*!< in: FIL_TABLESPACE, FIL_LOG */
671
 
/******************************************************************//**
672
 
Checks the consistency of the tablespace cache.
673
 
@return TRUE if ok */
 
657
        ulint   purpose);       /* in: FIL_TABLESPACE, FIL_LOG */
 
658
/**********************************************************************
 
659
Checks the consistency of the tablespace cache. */
674
660
UNIV_INTERN
675
661
ibool
676
662
fil_validate(void);
677
663
/*==============*/
678
 
/********************************************************************//**
679
 
Returns TRUE if file address is undefined.
680
 
@return TRUE if undefined */
 
664
                        /* out: TRUE if ok */
 
665
/************************************************************************
 
666
Returns TRUE if file address is undefined. */
681
667
UNIV_INTERN
682
668
ibool
683
669
fil_addr_is_null(
684
670
/*=============*/
685
 
        fil_addr_t      addr);  /*!< in: address */
686
 
/********************************************************************//**
687
 
Get the predecessor of a file page.
688
 
@return FIL_PAGE_PREV */
689
 
UNIV_INTERN
690
 
ulint
691
 
fil_page_get_prev(
692
 
/*==============*/
693
 
        const byte*     page);  /*!< in: file page */
694
 
/********************************************************************//**
695
 
Get the successor of a file page.
696
 
@return FIL_PAGE_NEXT */
697
 
UNIV_INTERN
698
 
ulint
699
 
fil_page_get_next(
700
 
/*==============*/
701
 
        const byte*     page);  /*!< in: file page */
702
 
/*********************************************************************//**
 
671
                                /* out: TRUE if undefined */
 
672
        fil_addr_t      addr);  /* in: address */
 
673
/************************************************************************
 
674
Accessor functions for a file page */
 
675
UNIV_INTERN
 
676
ulint
 
677
fil_page_get_prev(const byte*   page);
 
678
ulint
 
679
fil_page_get_next(const byte*   page);
 
680
/*************************************************************************
703
681
Sets the file page type. */
704
682
UNIV_INTERN
705
683
void
706
684
fil_page_set_type(
707
685
/*==============*/
708
 
        byte*   page,   /*!< in/out: file page */
709
 
        ulint   type);  /*!< in: type */
710
 
/*********************************************************************//**
711
 
Gets the file page type.
712
 
@return type; NOTE that if the type has not been written to page, the
713
 
return value not defined */
 
686
        byte*   page,   /* in: file page */
 
687
        ulint   type);  /* in: type */
 
688
/*************************************************************************
 
689
Gets the file page type. */
714
690
UNIV_INTERN
715
691
ulint
716
692
fil_page_get_type(
717
693
/*==============*/
718
 
        const byte*     page);  /*!< in: file page */
 
694
                                /* out: type; NOTE that if the type
 
695
                                has not been written to page, the
 
696
                                return value not defined */
 
697
        const byte*     page);  /* in: file page */
719
698
 
720
 
/*******************************************************************//**
721
 
Returns TRUE if a single-table tablespace is being deleted.
722
 
@return TRUE if being deleted */
723
 
UNIV_INTERN
724
 
ibool
725
 
fil_tablespace_is_being_deleted(
726
 
/*============================*/
727
 
        ulint           id);    /*!< in: space id */
728
699
 
729
700
typedef struct fil_space_struct fil_space_t;
730
701