~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

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