~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/fil/fil0fil.c

  • Committer: Monty Taylor
  • Date: 2009-08-12 06:25:19 UTC
  • mto: (1114.1.1 innodb-plugin-merge)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: mordred@inaugust.com-20090812062519-cij02mrrunvnxblt
Tags: innodb-plugin-1.0.4
InnoDB Plugin 1.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
*****************************************************************************/
18
18
 
19
 
/******************************************************
 
19
/**************************************************//**
 
20
@file fil/fil0fil.c
20
21
The tablespace memory cache
21
22
 
22
23
Created 10/25/1995 Heikki Tuuri
25
26
#include "fil0fil.h"
26
27
 
27
28
#include "mem0mem.h"
28
 
#include "sync0sync.h"
29
29
#include "hash0hash.h"
30
30
#include "os0file.h"
31
 
#include "os0sync.h"
32
31
#include "mach0data.h"
33
 
#include "ibuf0ibuf.h"
34
32
#include "buf0buf.h"
35
33
#include "buf0flu.h"
36
 
#include "buf0lru.h"
37
34
#include "log0recv.h"
38
35
#include "fsp0fsp.h"
39
36
#include "srv0srv.h"
42
39
#include "mtr0log.h"
43
40
#include "dict0dict.h"
44
41
#include "page0zip.h"
45
 
 
 
42
#ifndef UNIV_HOTBACKUP
 
43
# include "buf0lru.h"
 
44
# include "ibuf0ibuf.h"
 
45
# include "sync0sync.h"
 
46
# include "os0sync.h"
 
47
#else /* !UNIV_HOTBACKUP */
 
48
static ulint srv_data_read, srv_data_written;
 
49
#endif /* !UNIV_HOTBACKUP */
46
50
 
47
51
/*
48
52
                IMPLEMENTATION OF THE TABLESPACE MEMORY CACHE
100
104
completes, we decrement the count and return the file node to the LRU-list if
101
105
the count drops to zero. */
102
106
 
103
 
/* When mysqld is run, the default directory "." is the mysqld datadir,
 
107
/** When mysqld is run, the default directory "." is the mysqld datadir,
104
108
but in the MySQL Embedded Server Library and ibbackup it is not the default
105
109
directory, and we must set the base file path explicitly */
106
110
UNIV_INTERN const char* fil_path_to_mysql_datadir       = ".";
107
111
 
108
 
/* The number of fsyncs done to the log */
 
112
/** The number of fsyncs done to the log */
109
113
UNIV_INTERN ulint       fil_n_log_flushes                       = 0;
110
114
 
 
115
/** Number of pending redo log flushes */
111
116
UNIV_INTERN ulint       fil_n_pending_log_flushes               = 0;
 
117
/** Number of pending tablespace flushes */
112
118
UNIV_INTERN ulint       fil_n_pending_tablespace_flushes        = 0;
113
119
 
114
 
/* Null file address */
 
120
/** The null file address */
115
121
UNIV_INTERN fil_addr_t  fil_addr_null = {FIL_NULL, 0};
116
122
 
117
 
/* File node of a tablespace or the log data space */
 
123
/** File node of a tablespace or the log data space */
118
124
struct fil_node_struct {
119
 
        fil_space_t*    space;  /* backpointer to the space where this node
 
125
        fil_space_t*    space;  /*!< backpointer to the space where this node
120
126
                                belongs */
121
 
        char*           name;   /* path to the file */
122
 
        ibool           open;   /* TRUE if file open */
123
 
        os_file_t       handle; /* OS handle to the file, if file open */
124
 
        ibool           is_raw_disk;/* TRUE if the 'file' is actually a raw
 
127
        char*           name;   /*!< path to the file */
 
128
        ibool           open;   /*!< TRUE if file open */
 
129
        os_file_t       handle; /*!< OS handle to the file, if file open */
 
130
        ibool           is_raw_disk;/*!< TRUE if the 'file' is actually a raw
125
131
                                device or a raw disk partition */
126
 
        ulint           size;   /* size of the file in database pages, 0 if
 
132
        ulint           size;   /*!< size of the file in database pages, 0 if
127
133
                                not known yet; the possible last incomplete
128
134
                                megabyte may be ignored if space == 0 */
129
135
        ulint           n_pending;
130
 
                                /* count of pending i/o's on this file;
 
136
                                /*!< count of pending i/o's on this file;
131
137
                                closing of the file is not allowed if
132
138
                                this is > 0 */
133
139
        ulint           n_pending_flushes;
134
 
                                /* count of pending flushes on this file;
 
140
                                /*!< count of pending flushes on this file;
135
141
                                closing of the file is not allowed if
136
142
                                this is > 0 */
137
 
        ib_int64_t      modification_counter;/* when we write to the file we
 
143
        ib_int64_t      modification_counter;/*!< when we write to the file we
138
144
                                increment this by one */
139
 
        ib_int64_t      flush_counter;/* up to what modification_counter value
140
 
                                we have flushed the modifications to disk */
 
145
        ib_int64_t      flush_counter;/*!< up to what
 
146
                                modification_counter value we have
 
147
                                flushed the modifications to disk */
141
148
        UT_LIST_NODE_T(fil_node_t) chain;
142
 
                                /* link field for the file chain */
 
149
                                /*!< link field for the file chain */
143
150
        UT_LIST_NODE_T(fil_node_t) LRU;
144
 
                                /* link field for the LRU list */
145
 
        ulint           magic_n;
 
151
                                /*!< link field for the LRU list */
 
152
        ulint           magic_n;/*!< FIL_NODE_MAGIC_N */
146
153
};
147
154
 
 
155
/** Value of fil_node_struct::magic_n */
148
156
#define FIL_NODE_MAGIC_N        89389
149
157
 
150
 
/* Tablespace or log data space: let us call them by a common name space */
 
158
/** Tablespace or log data space: let us call them by a common name space */
151
159
struct fil_space_struct {
152
 
        char*           name;   /* space name = the path to the first file in
 
160
        char*           name;   /*!< space name = the path to the first file in
153
161
                                it */
154
 
        ulint           id;     /* space id */
 
162
        ulint           id;     /*!< space id */
155
163
        ib_int64_t      tablespace_version;
156
 
                                /* in DISCARD/IMPORT this timestamp is used to
157
 
                                check if we should ignore an insert buffer
158
 
                                merge request for a page because it actually
159
 
                                was for the previous incarnation of the
160
 
                                space */
161
 
        ibool           mark;   /* this is set to TRUE at database startup if
 
164
                                /*!< in DISCARD/IMPORT this timestamp
 
165
                                is used to check if we should ignore
 
166
                                an insert buffer merge request for a
 
167
                                page because it actually was for the
 
168
                                previous incarnation of the space */
 
169
        ibool           mark;   /*!< this is set to TRUE at database startup if
162
170
                                the space corresponds to a table in the InnoDB
163
171
                                data dictionary; so we can print a warning of
164
172
                                orphaned tablespaces */
165
 
        ibool           stop_ios;/* TRUE if we want to rename the .ibd file of
166
 
                                tablespace and want to stop temporarily
167
 
                                posting of new i/o requests on the file */
 
173
        ibool           stop_ios;/*!< TRUE if we want to rename the
 
174
                                .ibd file of tablespace and want to
 
175
                                stop temporarily posting of new i/o
 
176
                                requests on the file */
168
177
        ibool           stop_ibuf_merges;
169
 
                                /* we set this TRUE when we start deleting a
170
 
                                single-table tablespace */
 
178
                                /*!< we set this TRUE when we start
 
179
                                deleting a single-table tablespace */
171
180
        ibool           is_being_deleted;
172
 
                                /* this is set to TRUE when we start
 
181
                                /*!< this is set to TRUE when we start
173
182
                                deleting a single-table tablespace and its
174
183
                                file; when this flag is set no further i/o
175
184
                                or flush requests can be placed on this space,
176
185
                                though there may be such requests still being
177
186
                                processed on this space */
178
 
        ulint           purpose;/* FIL_TABLESPACE, FIL_LOG, or FIL_ARCH_LOG */
 
187
        ulint           purpose;/*!< FIL_TABLESPACE, FIL_LOG, or
 
188
                                FIL_ARCH_LOG */
179
189
        UT_LIST_BASE_NODE_T(fil_node_t) chain;
180
 
                                /* base node for the file chain */
181
 
        ulint           size;   /* space size in pages; 0 if a single-table
 
190
                                /*!< base node for the file chain */
 
191
        ulint           size;   /*!< space size in pages; 0 if a single-table
182
192
                                tablespace whose size we do not know yet;
183
193
                                last incomplete megabytes in data files may be
184
194
                                ignored if space == 0 */
185
 
        ulint           flags;  /* in: compressed page size
186
 
                                and file format, or 0 */
 
195
        ulint           flags;  /*!< compressed page size and file format, or 0 */
187
196
        ulint           n_reserved_extents;
188
 
                                /* number of reserved free extents for
 
197
                                /*!< number of reserved free extents for
189
198
                                ongoing operations like B-tree page split */
190
 
        ulint           n_pending_flushes; /* this is > 0 when flushing
 
199
        ulint           n_pending_flushes; /*!< this is positive when flushing
191
200
                                the tablespace to disk; dropping of the
192
 
                                tablespace is forbidden if this is > 0 */
193
 
        ulint           n_pending_ibuf_merges;/* this is > 0 when merging
194
 
                                insert buffer entries to a page so that we
195
 
                                may need to access the ibuf bitmap page in the
196
 
                                tablespade: dropping of the tablespace is
197
 
                                forbidden if this is > 0 */
198
 
        hash_node_t     hash;   /* hash chain node */
199
 
        hash_node_t     name_hash;/* hash chain the name_hash table */
200
 
        rw_lock_t       latch;  /* latch protecting the file space storage
 
201
                                tablespace is forbidden if this is positive */
 
202
        ulint           n_pending_ibuf_merges;/*!< this is positive
 
203
                                when merging insert buffer entries to
 
204
                                a page so that we may need to access
 
205
                                the ibuf bitmap page in the
 
206
                                tablespade: dropping of the tablespace
 
207
                                is forbidden if this is positive */
 
208
        hash_node_t     hash;   /*!< hash chain node */
 
209
        hash_node_t     name_hash;/*!< hash chain the name_hash table */
 
210
#ifndef UNIV_HOTBACKUP
 
211
        rw_lock_t       latch;  /*!< latch protecting the file space storage
201
212
                                allocation */
 
213
#endif /* !UNIV_HOTBACKUP */
202
214
        UT_LIST_NODE_T(fil_space_t) unflushed_spaces;
203
 
                                /* list of spaces with at least one unflushed
 
215
                                /*!< list of spaces with at least one unflushed
204
216
                                file we have written to */
205
 
        ibool           is_in_unflushed_spaces; /* TRUE if this space is
206
 
                                currently in the list above */
 
217
        ibool           is_in_unflushed_spaces; /*!< TRUE if this space is
 
218
                                currently in unflushed_spaces */
207
219
        UT_LIST_NODE_T(fil_space_t) space_list;
208
 
                                /* list of all spaces */
209
 
        ulint           magic_n;
 
220
                                /*!< list of all spaces */
 
221
        ulint           magic_n;/*!< FIL_SPACE_MAGIC_N */
210
222
};
211
223
 
 
224
/** Value of fil_space_struct::magic_n */
212
225
#define FIL_SPACE_MAGIC_N       89472
213
226
 
214
 
/* The tablespace memory cache; also the totality of logs = the log data space,
215
 
is stored here; below we talk about tablespaces, but also the ib_logfiles
216
 
form a 'space' and it is handled here */
217
 
 
 
227
/** The tablespace memory cache */
218
228
typedef struct fil_system_struct        fil_system_t;
 
229
 
 
230
/** The tablespace memory cache; also the totality of logs (the log
 
231
data space) is stored here; below we talk about tablespaces, but also
 
232
the ib_logfiles form a 'space' and it is handled here */
 
233
 
219
234
struct fil_system_struct {
220
 
        mutex_t         mutex;          /* The mutex protecting the cache */
221
 
        hash_table_t*   spaces;         /* The hash table of spaces in the
 
235
#ifndef UNIV_HOTBACKUP
 
236
        mutex_t         mutex;          /*!< The mutex protecting the cache */
 
237
#endif /* !UNIV_HOTBACKUP */
 
238
        hash_table_t*   spaces;         /*!< The hash table of spaces in the
222
239
                                        system; they are hashed on the space
223
240
                                        id */
224
 
        hash_table_t*   name_hash;      /* hash table based on the space
 
241
        hash_table_t*   name_hash;      /*!< hash table based on the space
225
242
                                        name */
226
243
        UT_LIST_BASE_NODE_T(fil_node_t) LRU;
227
 
                                        /* base node for the LRU list of the
 
244
                                        /*!< base node for the LRU list of the
228
245
                                        most recently used open files with no
229
246
                                        pending i/o's; if we start an i/o on
230
247
                                        the file, we first remove it from this
235
252
                                        after the startup, and kept open until
236
253
                                        shutdown */
237
254
        UT_LIST_BASE_NODE_T(fil_space_t) unflushed_spaces;
238
 
                                        /* base node for the list of those
 
255
                                        /*!< base node for the list of those
239
256
                                        tablespaces whose files contain
240
257
                                        unflushed writes; those spaces have
241
258
                                        at least one file node where
242
259
                                        modification_counter > flush_counter */
243
 
        ulint           n_open;         /* number of files currently open */
244
 
        ulint           max_n_open;     /* n_open is not allowed to exceed
 
260
        ulint           n_open;         /*!< number of files currently open */
 
261
        ulint           max_n_open;     /*!< n_open is not allowed to exceed
245
262
                                        this */
246
 
        ib_int64_t      modification_counter;/* when we write to a file we
 
263
        ib_int64_t      modification_counter;/*!< when we write to a file we
247
264
                                        increment this by one */
248
 
        ulint           max_assigned_id;/* maximum space id in the existing
 
265
        ulint           max_assigned_id;/*!< maximum space id in the existing
249
266
                                        tables, or assigned during the time
250
267
                                        mysqld has been up; at an InnoDB
251
268
                                        startup we scan the data dictionary
252
269
                                        and set here the maximum of the
253
270
                                        space id's of the tables there */
254
271
        ib_int64_t      tablespace_version;
255
 
                                        /* a counter which is incremented for
 
272
                                        /*!< a counter which is incremented for
256
273
                                        every space object memory creation;
257
274
                                        every space mem object gets a
258
275
                                        'timestamp' from this; in DISCARD/
260
277
                                        should ignore an insert buffer merge
261
278
                                        request */
262
279
        UT_LIST_BASE_NODE_T(fil_space_t) space_list;
263
 
                                        /* list of all file spaces */
 
280
                                        /*!< list of all file spaces */
264
281
};
265
282
 
266
 
/* The tablespace memory cache. This variable is NULL before the module is
 
283
/** The tablespace memory cache. This variable is NULL before the module is
267
284
initialized. */
268
 
UNIV_INTERN fil_system_t*       fil_system      = NULL;
269
 
 
270
 
 
271
 
/************************************************************************
 
285
static fil_system_t*    fil_system      = NULL;
 
286
 
 
287
 
 
288
/********************************************************************//**
272
289
NOTE: you must call fil_mutex_enter_and_prepare_for_io() first!
273
290
 
274
291
Prepares a file node for i/o. Opens the file if it is closed. Updates the
279
296
void
280
297
fil_node_prepare_for_io(
281
298
/*====================*/
282
 
        fil_node_t*     node,   /* in: file node */
283
 
        fil_system_t*   system, /* in: tablespace memory cache */
284
 
        fil_space_t*    space); /* in: space */
285
 
/************************************************************************
 
299
        fil_node_t*     node,   /*!< in: file node */
 
300
        fil_system_t*   system, /*!< in: tablespace memory cache */
 
301
        fil_space_t*    space); /*!< in: space */
 
302
/********************************************************************//**
286
303
Updates the data structures when an i/o operation finishes. Updates the
287
304
pending i/o's field in the node appropriately. */
288
305
static
289
306
void
290
307
fil_node_complete_io(
291
308
/*=================*/
292
 
        fil_node_t*     node,   /* in: file node */
293
 
        fil_system_t*   system, /* in: tablespace memory cache */
294
 
        ulint           type);  /* in: OS_FILE_WRITE or OS_FILE_READ; marks
 
309
        fil_node_t*     node,   /*!< in: file node */
 
310
        fil_system_t*   system, /*!< in: tablespace memory cache */
 
311
        ulint           type);  /*!< in: OS_FILE_WRITE or OS_FILE_READ; marks
295
312
                                the node as modified if
296
313
                                type == OS_FILE_WRITE */
297
 
/***********************************************************************
 
314
/*******************************************************************//**
298
315
Checks if a single-table tablespace for a given table name exists in the
299
 
tablespace memory cache. */
 
316
tablespace memory cache.
 
317
@return space id, ULINT_UNDEFINED if not found */
300
318
static
301
319
ulint
302
320
fil_get_space_id_for_table(
303
321
/*=======================*/
304
 
                                /* out: space id, ULINT_UNDEFINED if not
305
 
                                found */
306
 
        const char*     name);  /* in: table name in the standard
 
322
        const char*     name);  /*!< in: table name in the standard
307
323
                                'databasename/tablename' format */
308
 
/************************************************************************
 
324
/********************************************************************//**
309
325
Reads data from a space to a buffer. Remember that the possible incomplete
310
326
blocks at the end of file are ignored: they are not taken into account when
311
 
calculating the byte offset within a space. */
 
327
calculating the byte offset within a space.
 
328
@return DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do
 
329
i/o on a tablespace which does not exist */
312
330
UNIV_INLINE
313
331
ulint
314
332
fil_read(
315
333
/*=====*/
316
 
                                /* out: DB_SUCCESS, or DB_TABLESPACE_DELETED
317
 
                                if we are trying to do i/o on a tablespace
318
 
                                which does not exist */
319
 
        ibool   sync,           /* in: TRUE if synchronous aio is desired */
320
 
        ulint   space_id,       /* in: space id */
321
 
        ulint   zip_size,       /* in: compressed page size in bytes;
 
334
        ibool   sync,           /*!< in: TRUE if synchronous aio is desired */
 
335
        ulint   space_id,       /*!< in: space id */
 
336
        ulint   zip_size,       /*!< in: compressed page size in bytes;
322
337
                                0 for uncompressed pages */
323
 
        ulint   block_offset,   /* in: offset in number of blocks */
324
 
        ulint   byte_offset,    /* in: remainder of offset in bytes; in aio
 
338
        ulint   block_offset,   /*!< in: offset in number of blocks */
 
339
        ulint   byte_offset,    /*!< in: remainder of offset in bytes; in aio
325
340
                                this must be divisible by the OS block size */
326
 
        ulint   len,            /* in: how many bytes to read; this must not
 
341
        ulint   len,            /*!< in: how many bytes to read; this must not
327
342
                                cross a file boundary; in aio this must be a
328
343
                                block size multiple */
329
 
        void*   buf,            /* in/out: buffer where to store data read;
 
344
        void*   buf,            /*!< in/out: buffer where to store data read;
330
345
                                in aio this must be appropriately aligned */
331
 
        void*   message)        /* in: message for aio handler if non-sync
 
346
        void*   message)        /*!< in: message for aio handler if non-sync
332
347
                                aio used, else ignored */
333
348
{
334
349
        return(fil_io(OS_FILE_READ, sync, space_id, zip_size, block_offset,
335
350
                                          byte_offset, len, buf, message));
336
351
}
337
352
 
338
 
/************************************************************************
 
353
/********************************************************************//**
339
354
Writes data to a space from a buffer. Remember that the possible incomplete
340
355
blocks at the end of file are ignored: they are not taken into account when
341
 
calculating the byte offset within a space. */
 
356
calculating the byte offset within a space.
 
357
@return DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do
 
358
i/o on a tablespace which does not exist */
342
359
UNIV_INLINE
343
360
ulint
344
361
fil_write(
345
362
/*======*/
346
 
                                /* out: DB_SUCCESS, or DB_TABLESPACE_DELETED
347
 
                                if we are trying to do i/o on a tablespace
348
 
                                which does not exist */
349
 
        ibool   sync,           /* in: TRUE if synchronous aio is desired */
350
 
        ulint   space_id,       /* in: space id */
351
 
        ulint   zip_size,       /* in: compressed page size in bytes;
 
363
        ibool   sync,           /*!< in: TRUE if synchronous aio is desired */
 
364
        ulint   space_id,       /*!< in: space id */
 
365
        ulint   zip_size,       /*!< in: compressed page size in bytes;
352
366
                                0 for uncompressed pages */
353
 
        ulint   block_offset,   /* in: offset in number of blocks */
354
 
        ulint   byte_offset,    /* in: remainder of offset in bytes; in aio
 
367
        ulint   block_offset,   /*!< in: offset in number of blocks */
 
368
        ulint   byte_offset,    /*!< in: remainder of offset in bytes; in aio
355
369
                                this must be divisible by the OS block size */
356
 
        ulint   len,            /* in: how many bytes to write; this must
 
370
        ulint   len,            /*!< in: how many bytes to write; this must
357
371
                                not cross a file boundary; in aio this must
358
372
                                be a block size multiple */
359
 
        void*   buf,            /* in: buffer from which to write; in aio
 
373
        void*   buf,            /*!< in: buffer from which to write; in aio
360
374
                                this must be appropriately aligned */
361
 
        void*   message)        /* in: message for aio handler if non-sync
 
375
        void*   message)        /*!< in: message for aio handler if non-sync
362
376
                                aio used, else ignored */
363
377
{
364
378
        return(fil_io(OS_FILE_WRITE, sync, space_id, zip_size, block_offset,
365
379
                                           byte_offset, len, buf, message));
366
380
}
367
381
 
368
 
/***********************************************************************
 
382
/*******************************************************************//**
369
383
Returns the table space by a given id, NULL if not found. */
370
384
UNIV_INLINE
371
385
fil_space_t*
372
386
fil_space_get_by_id(
373
387
/*================*/
374
 
        ulint   id)     /* in: space id */
 
388
        ulint   id)     /*!< in: space id */
375
389
{
376
390
        fil_space_t*    space;
377
391
 
385
399
        return(space);
386
400
}
387
401
 
388
 
/***********************************************************************
 
402
/*******************************************************************//**
389
403
Returns the table space by a given name, NULL if not found. */
390
404
UNIV_INLINE
391
405
fil_space_t*
392
406
fil_space_get_by_name(
393
407
/*==================*/
394
 
        const char*     name)   /* in: space name */
 
408
        const char*     name)   /*!< in: space name */
395
409
{
396
410
        fil_space_t*    space;
397
411
        ulint           fold;
408
422
        return(space);
409
423
}
410
424
 
411
 
/***********************************************************************
412
 
Returns the version number of a tablespace, -1 if not found. */
 
425
#ifndef UNIV_HOTBACKUP
 
426
/*******************************************************************//**
 
427
Returns the version number of a tablespace, -1 if not found.
 
428
@return version number, -1 if the tablespace does not exist in the
 
429
memory cache */
413
430
UNIV_INTERN
414
431
ib_int64_t
415
432
fil_space_get_version(
416
433
/*==================*/
417
 
                        /* out: version number, -1 if the tablespace does not
418
 
                        exist in the memory cache */
419
 
        ulint   id)     /* in: space id */
 
434
        ulint   id)     /*!< in: space id */
420
435
{
421
 
        fil_system_t*   system          = fil_system;
422
436
        fil_space_t*    space;
423
437
        ib_int64_t      version         = -1;
424
438
 
425
 
        ut_ad(system);
 
439
        ut_ad(fil_system);
426
440
 
427
 
        mutex_enter(&(system->mutex));
 
441
        mutex_enter(&fil_system->mutex);
428
442
 
429
443
        space = fil_space_get_by_id(id);
430
444
 
432
446
                version = space->tablespace_version;
433
447
        }
434
448
 
435
 
        mutex_exit(&(system->mutex));
 
449
        mutex_exit(&fil_system->mutex);
436
450
 
437
451
        return(version);
438
452
}
439
453
 
440
 
/***********************************************************************
441
 
Returns the latch of a file space. */
 
454
/*******************************************************************//**
 
455
Returns the latch of a file space.
 
456
@return latch protecting storage allocation */
442
457
UNIV_INTERN
443
458
rw_lock_t*
444
459
fil_space_get_latch(
445
460
/*================*/
446
 
                        /* out: latch protecting storage allocation */
447
 
        ulint   id,     /* in: space id */
448
 
        ulint*  flags)  /* out: tablespace flags */
 
461
        ulint   id,     /*!< in: space id */
 
462
        ulint*  flags)  /*!< out: tablespace flags */
449
463
{
450
 
        fil_system_t*   system          = fil_system;
451
464
        fil_space_t*    space;
452
465
 
453
 
        ut_ad(system);
 
466
        ut_ad(fil_system);
454
467
 
455
 
        mutex_enter(&(system->mutex));
 
468
        mutex_enter(&fil_system->mutex);
456
469
 
457
470
        space = fil_space_get_by_id(id);
458
471
 
462
475
                *flags = space->flags;
463
476
        }
464
477
 
465
 
        mutex_exit(&(system->mutex));
 
478
        mutex_exit(&fil_system->mutex);
466
479
 
467
480
        return(&(space->latch));
468
481
}
469
482
 
470
 
/***********************************************************************
471
 
Returns the type of a file space. */
 
483
/*******************************************************************//**
 
484
Returns the type of a file space.
 
485
@return FIL_TABLESPACE or FIL_LOG */
472
486
UNIV_INTERN
473
487
ulint
474
488
fil_space_get_type(
475
489
/*===============*/
476
 
                        /* out: FIL_TABLESPACE or FIL_LOG */
477
 
        ulint   id)     /* in: space id */
 
490
        ulint   id)     /*!< in: space id */
478
491
{
479
 
        fil_system_t*   system          = fil_system;
480
492
        fil_space_t*    space;
481
493
 
482
 
        ut_ad(system);
 
494
        ut_ad(fil_system);
483
495
 
484
 
        mutex_enter(&(system->mutex));
 
496
        mutex_enter(&fil_system->mutex);
485
497
 
486
498
        space = fil_space_get_by_id(id);
487
499
 
488
500
        ut_a(space);
489
501
 
490
 
        mutex_exit(&(system->mutex));
 
502
        mutex_exit(&fil_system->mutex);
491
503
 
492
504
        return(space->purpose);
493
505
}
 
506
#endif /* !UNIV_HOTBACKUP */
494
507
 
495
 
/**************************************************************************
 
508
/**********************************************************************//**
496
509
Checks if all the file nodes in a space are flushed. The caller must hold
497
 
the fil_system mutex. */
 
510
the fil_system mutex.
 
511
@return TRUE if all are flushed */
498
512
static
499
513
ibool
500
514
fil_space_is_flushed(
501
515
/*=================*/
502
 
                                /* out: TRUE if all are flushed */
503
 
        fil_space_t*    space)  /* in: space */
 
516
        fil_space_t*    space)  /*!< in: space */
504
517
{
505
518
        fil_node_t*     node;
506
519
 
507
 
        ut_ad(mutex_own(&(fil_system->mutex)));
 
520
        ut_ad(mutex_own(&fil_system->mutex));
508
521
 
509
522
        node = UT_LIST_GET_FIRST(space->chain);
510
523
 
520
533
        return(TRUE);
521
534
}
522
535
 
523
 
/***********************************************************************
 
536
/*******************************************************************//**
524
537
Appends a new file to the chain of files of a space. File must be closed. */
525
538
UNIV_INTERN
526
539
void
527
540
fil_node_create(
528
541
/*============*/
529
 
        const char*     name,   /* in: file name (file must be closed) */
530
 
        ulint           size,   /* in: file size in database blocks, rounded
 
542
        const char*     name,   /*!< in: file name (file must be closed) */
 
543
        ulint           size,   /*!< in: file size in database blocks, rounded
531
544
                                downwards to an integer */
532
 
        ulint           id,     /* in: space id where to append */
533
 
        ibool           is_raw) /* in: TRUE if a raw device or
 
545
        ulint           id,     /*!< in: space id where to append */
 
546
        ibool           is_raw) /*!< in: TRUE if a raw device or
534
547
                                a raw disk partition */
535
548
{
536
 
        fil_system_t*   system  = fil_system;
537
549
        fil_node_t*     node;
538
550
        fil_space_t*    space;
539
551
 
540
 
        ut_a(system);
 
552
        ut_a(fil_system);
541
553
        ut_a(name);
542
554
 
543
 
        mutex_enter(&(system->mutex));
 
555
        mutex_enter(&fil_system->mutex);
544
556
 
545
557
        node = mem_alloc(sizeof(fil_node_t));
546
558
 
571
583
 
572
584
                mem_free(node);
573
585
 
574
 
                mutex_exit(&(system->mutex));
 
586
                mutex_exit(&fil_system->mutex);
575
587
 
576
588
                return;
577
589
        }
582
594
 
583
595
        UT_LIST_ADD_LAST(chain, space->chain, node);
584
596
 
585
 
        mutex_exit(&(system->mutex));
 
597
        mutex_exit(&fil_system->mutex);
586
598
}
587
599
 
588
 
/************************************************************************
 
600
/********************************************************************//**
589
601
Opens a the file of a node of a tablespace. The caller must own the fil_system
590
602
mutex. */
591
603
static
592
604
void
593
605
fil_node_open_file(
594
606
/*===============*/
595
 
        fil_node_t*     node,   /* in: file node */
596
 
        fil_system_t*   system, /* in: tablespace memory cache */
597
 
        fil_space_t*    space)  /* in: space */
 
607
        fil_node_t*     node,   /*!< in: file node */
 
608
        fil_system_t*   system, /*!< in: tablespace memory cache */
 
609
        fil_space_t*    space)  /*!< in: space */
598
610
{
599
611
        ib_int64_t      size_bytes;
600
612
        ulint           size_low;
757
769
        }
758
770
}
759
771
 
760
 
/**************************************************************************
 
772
/**********************************************************************//**
761
773
Closes a file. */
762
774
static
763
775
void
764
776
fil_node_close_file(
765
777
/*================*/
766
 
        fil_node_t*     node,   /* in: file node */
767
 
        fil_system_t*   system) /* in: tablespace memory cache */
 
778
        fil_node_t*     node,   /*!< in: file node */
 
779
        fil_system_t*   system) /*!< in: tablespace memory cache */
768
780
{
769
781
        ibool   ret;
770
782
 
792
804
        }
793
805
}
794
806
 
795
 
/************************************************************************
 
807
/********************************************************************//**
796
808
Tries to close a file in the LRU list. The caller must hold the fil_sys
797
 
mutex. */
 
809
mutex.
 
810
@return TRUE if success, FALSE if should retry later; since i/o's
 
811
generally complete in < 100 ms, and as InnoDB writes at most 128 pages
 
812
from the buffer pool in a batch, and then immediately flushes the
 
813
files, there is a good chance that the next time we find a suitable
 
814
node from the LRU list */
798
815
static
799
816
ibool
800
817
fil_try_to_close_file_in_LRU(
801
818
/*=========================*/
802
 
                                /* out: TRUE if success, FALSE if should retry
803
 
                                later; since i/o's generally complete in <
804
 
                                100 ms, and as InnoDB writes at most 128 pages
805
 
                                from the buffer pool in a batch, and then
806
 
                                immediately flushes the files, there is a good
807
 
                                chance that the next time we find a suitable
808
 
                                node from the LRU list */
809
 
        ibool   print_info)     /* in: if TRUE, prints information why it
 
819
        ibool   print_info)     /*!< in: if TRUE, prints information why it
810
820
                                cannot close a file */
811
821
{
812
 
        fil_system_t*   system          = fil_system;
813
822
        fil_node_t*     node;
814
823
 
815
 
        ut_ad(mutex_own(&(system->mutex)));
 
824
        ut_ad(mutex_own(&fil_system->mutex));
816
825
 
817
 
        node = UT_LIST_GET_LAST(system->LRU);
 
826
        node = UT_LIST_GET_LAST(fil_system->LRU);
818
827
 
819
828
        if (print_info) {
820
829
                fprintf(stderr,
821
830
                        "InnoDB: fil_sys open file LRU len %lu\n",
822
 
                        (ulong) UT_LIST_GET_LEN(system->LRU));
 
831
                        (ulong) UT_LIST_GET_LEN(fil_system->LRU));
823
832
        }
824
833
 
825
834
        while (node != NULL) {
826
835
                if (node->modification_counter == node->flush_counter
827
836
                    && node->n_pending_flushes == 0) {
828
837
 
829
 
                        fil_node_close_file(node, system);
 
838
                        fil_node_close_file(node, fil_system);
830
839
 
831
840
                        return(TRUE);
832
841
                }
854
863
        return(FALSE);
855
864
}
856
865
 
857
 
/***********************************************************************
 
866
/*******************************************************************//**
858
867
Reserves the fil_system mutex and tries to make sure we can open at least one
859
868
file while holding it. This should be called before calling
860
869
fil_node_prepare_for_io(), because that function may need to open a file. */
862
871
void
863
872
fil_mutex_enter_and_prepare_for_io(
864
873
/*===============================*/
865
 
        ulint   space_id)       /* in: space id */
 
874
        ulint   space_id)       /*!< in: space id */
866
875
{
867
 
        fil_system_t*   system          = fil_system;
868
876
        fil_space_t*    space;
869
877
        ibool           success;
870
878
        ibool           print_info      = FALSE;
871
879
        ulint           count           = 0;
872
880
        ulint           count2          = 0;
873
881
 
874
 
        ut_ad(!mutex_own(&(system->mutex)));
875
882
retry:
876
 
        mutex_enter(&(system->mutex));
 
883
        mutex_enter(&fil_system->mutex);
877
884
 
878
885
        if (space_id == 0 || space_id >= SRV_LOG_SPACE_FIRST_ID) {
879
886
                /* We keep log files and system tablespace files always open;
885
892
                return;
886
893
        }
887
894
 
888
 
        if (system->n_open < system->max_n_open) {
 
895
        if (fil_system->n_open < fil_system->max_n_open) {
889
896
 
890
897
                return;
891
898
        }
904
911
                                (ulong) count2);
905
912
                }
906
913
 
907
 
                mutex_exit(&(system->mutex));
 
914
                mutex_exit(&fil_system->mutex);
908
915
 
909
916
                os_thread_sleep(20000);
910
917
 
930
937
close_more:
931
938
        success = fil_try_to_close_file_in_LRU(print_info);
932
939
 
933
 
        if (success && system->n_open >= system->max_n_open) {
 
940
        if (success && fil_system->n_open >= fil_system->max_n_open) {
934
941
 
935
942
                goto close_more;
936
943
        }
937
944
 
938
 
        if (system->n_open < system->max_n_open) {
 
945
        if (fil_system->n_open < fil_system->max_n_open) {
939
946
                /* Ok */
940
947
 
941
948
                return;
950
957
                        "InnoDB: You may need to raise the value of"
951
958
                        " innodb_max_files_open in\n"
952
959
                        "InnoDB: my.cnf.\n",
953
 
                        (ulong) system->n_open, (ulong) system->max_n_open);
 
960
                        (ulong) fil_system->n_open,
 
961
                        (ulong) fil_system->max_n_open);
954
962
 
955
963
                return;
956
964
        }
957
965
 
958
 
        mutex_exit(&(system->mutex));
 
966
        mutex_exit(&fil_system->mutex);
959
967
 
960
968
#ifndef UNIV_HOTBACKUP
961
969
        /* Wake the i/o-handler threads to make sure pending i/o's are
974
982
        goto retry;
975
983
}
976
984
 
977
 
/***********************************************************************
 
985
/*******************************************************************//**
978
986
Frees a file node object from a tablespace memory cache. */
979
987
static
980
988
void
981
989
fil_node_free(
982
990
/*==========*/
983
 
        fil_node_t*     node,   /* in, own: file node */
984
 
        fil_system_t*   system, /* in: tablespace memory cache */
985
 
        fil_space_t*    space)  /* in: space where the file node is chained */
 
991
        fil_node_t*     node,   /*!< in, own: file node */
 
992
        fil_system_t*   system, /*!< in: tablespace memory cache */
 
993
        fil_space_t*    space)  /*!< in: space where the file node is chained */
986
994
{
987
995
        ut_ad(node && system && space);
988
996
        ut_ad(mutex_own(&(system->mutex)));
1017
1025
}
1018
1026
 
1019
1027
#ifdef UNIV_LOG_ARCHIVE
1020
 
/********************************************************************
 
1028
/****************************************************************//**
1021
1029
Drops files from the start of a file space, so that its size is cut by
1022
1030
the amount given. */
1023
1031
UNIV_INTERN
1024
1032
void
1025
1033
fil_space_truncate_start(
1026
1034
/*=====================*/
1027
 
        ulint   id,             /* in: space id */
1028
 
        ulint   trunc_len)      /* in: truncate by this much; it is an error
 
1035
        ulint   id,             /*!< in: space id */
 
1036
        ulint   trunc_len)      /*!< in: truncate by this much; it is an error
1029
1037
                                if this does not equal to the combined size of
1030
1038
                                some initial files in the space */
1031
1039
{
1032
 
        fil_system_t*   system          = fil_system;
1033
1040
        fil_node_t*     node;
1034
1041
        fil_space_t*    space;
1035
1042
 
1036
 
        mutex_enter(&(system->mutex));
 
1043
        mutex_enter(&fil_system->mutex);
1037
1044
 
1038
1045
        space = fil_space_get_by_id(id);
1039
1046
 
1046
1053
 
1047
1054
                trunc_len -= node->size * UNIV_PAGE_SIZE;
1048
1055
 
1049
 
                fil_node_free(node, system, space);
 
1056
                fil_node_free(node, fil_system, space);
1050
1057
        }
1051
1058
 
1052
 
        mutex_exit(&(system->mutex));
 
1059
        mutex_exit(&fil_system->mutex);
1053
1060
}
1054
1061
#endif /* UNIV_LOG_ARCHIVE */
1055
1062
 
1056
 
/***********************************************************************
 
1063
/*******************************************************************//**
1057
1064
Creates a space memory object and puts it to the tablespace memory cache. If
1058
 
there is an error, prints an error message to the .err log. */
 
1065
there is an error, prints an error message to the .err log.
 
1066
@return TRUE if success */
1059
1067
UNIV_INTERN
1060
1068
ibool
1061
1069
fil_space_create(
1062
1070
/*=============*/
1063
 
                                /* out: TRUE if success */
1064
 
        const char*     name,   /* in: space name */
1065
 
        ulint           id,     /* in: space id */
1066
 
        ulint           flags,  /* in: compressed page size
 
1071
        const char*     name,   /*!< in: space name */
 
1072
        ulint           id,     /*!< in: space id */
 
1073
        ulint           flags,  /*!< in: compressed page size
1067
1074
                                and file format, or 0 */
1068
 
        ulint           purpose)/* in: FIL_TABLESPACE, or FIL_LOG if log */
 
1075
        ulint           purpose)/*!< in: FIL_TABLESPACE, or FIL_LOG if log */
1069
1076
{
1070
 
        fil_system_t*   system          = fil_system;
1071
1077
        fil_space_t*    space;
1072
1078
 
1073
1079
        /* The tablespace flags (FSP_SPACE_FLAGS) should be 0 for
1081
1087
        "InnoDB: Adding tablespace %lu of name %s, purpose %lu\n", id, name,
1082
1088
        purpose);*/
1083
1089
 
1084
 
        ut_a(system);
 
1090
        ut_a(fil_system);
1085
1091
        ut_a(name);
1086
1092
 
1087
 
        mutex_enter(&(system->mutex));
 
1093
        mutex_enter(&fil_system->mutex);
1088
1094
 
1089
1095
        space = fil_space_get_by_name(name);
1090
1096
 
1105
1111
 
1106
1112
                if (id == 0 || purpose != FIL_TABLESPACE) {
1107
1113
 
1108
 
                        mutex_exit(&(system->mutex));
 
1114
                        mutex_exit(&fil_system->mutex);
1109
1115
 
1110
1116
                        return(FALSE);
1111
1117
                }
1127
1133
 
1128
1134
                namesake_id = space->id;
1129
1135
 
1130
 
                mutex_exit(&(system->mutex));
 
1136
                mutex_exit(&fil_system->mutex);
1131
1137
 
1132
1138
                fil_space_free(namesake_id);
1133
1139
 
1149
1155
                fputs(" already exists in the tablespace\n"
1150
1156
                      "InnoDB: memory cache!\n", stderr);
1151
1157
 
1152
 
                mutex_exit(&(system->mutex));
 
1158
                mutex_exit(&fil_system->mutex);
1153
1159
 
1154
1160
                return(FALSE);
1155
1161
        }
1159
1165
        space->name = mem_strdup(name);
1160
1166
        space->id = id;
1161
1167
 
1162
 
        system->tablespace_version++;
1163
 
        space->tablespace_version = system->tablespace_version;
 
1168
        fil_system->tablespace_version++;
 
1169
        space->tablespace_version = fil_system->tablespace_version;
1164
1170
        space->mark = FALSE;
1165
1171
 
1166
 
        if (purpose == FIL_TABLESPACE && id > system->max_assigned_id) {
1167
 
                system->max_assigned_id = id;
 
1172
        if (purpose == FIL_TABLESPACE && id > fil_system->max_assigned_id) {
 
1173
                fil_system->max_assigned_id = id;
1168
1174
        }
1169
1175
 
1170
1176
        space->stop_ios = FALSE;
1184
1190
 
1185
1191
        rw_lock_create(&space->latch, SYNC_FSP);
1186
1192
 
1187
 
        HASH_INSERT(fil_space_t, hash, system->spaces, id, space);
 
1193
        HASH_INSERT(fil_space_t, hash, fil_system->spaces, id, space);
1188
1194
 
1189
 
        HASH_INSERT(fil_space_t, name_hash, system->name_hash,
 
1195
        HASH_INSERT(fil_space_t, name_hash, fil_system->name_hash,
1190
1196
                    ut_fold_string(name), space);
1191
1197
        space->is_in_unflushed_spaces = FALSE;
1192
1198
 
1193
 
        UT_LIST_ADD_LAST(space_list, system->space_list, space);
 
1199
        UT_LIST_ADD_LAST(space_list, fil_system->space_list, space);
1194
1200
 
1195
 
        mutex_exit(&(system->mutex));
 
1201
        mutex_exit(&fil_system->mutex);
1196
1202
 
1197
1203
        return(TRUE);
1198
1204
}
1199
1205
 
1200
 
/***********************************************************************
 
1206
/*******************************************************************//**
1201
1207
Assigns a new space id for a new single-table tablespace. This works simply by
1202
1208
incrementing the global counter. If 4 billion id's is not enough, we may need
1203
 
to recycle id's. */
 
1209
to recycle id's.
 
1210
@return new tablespace id; ULINT_UNDEFINED if could not assign an id */
1204
1211
static
1205
1212
ulint
1206
1213
fil_assign_new_space_id(void)
1207
1214
/*=========================*/
1208
 
                        /* out: new tablespace id; ULINT_UNDEFINED if could
1209
 
                        not assign an id */
1210
1215
{
1211
 
        fil_system_t*   system = fil_system;
1212
1216
        ulint           id;
1213
1217
 
1214
 
        mutex_enter(&(system->mutex));
1215
 
 
1216
 
        system->max_assigned_id++;
1217
 
 
1218
 
        id = system->max_assigned_id;
 
1218
        mutex_enter(&fil_system->mutex);
 
1219
 
 
1220
        fil_system->max_assigned_id++;
 
1221
 
 
1222
        id = fil_system->max_assigned_id;
1219
1223
 
1220
1224
        if (id > (SRV_LOG_SPACE_FIRST_ID / 2) && (id % 1000000UL == 0)) {
1221
1225
                ut_print_timestamp(stderr);
1241
1245
                        " have to dump all your tables and\n"
1242
1246
                        "InnoDB: recreate the whole InnoDB installation.\n",
1243
1247
                        (ulong) id);
1244
 
                system->max_assigned_id--;
 
1248
                fil_system->max_assigned_id--;
1245
1249
 
1246
1250
                id = ULINT_UNDEFINED;
1247
1251
        }
1248
1252
 
1249
 
        mutex_exit(&(system->mutex));
 
1253
        mutex_exit(&fil_system->mutex);
1250
1254
 
1251
1255
        return(id);
1252
1256
}
1253
1257
 
1254
 
/***********************************************************************
 
1258
/*******************************************************************//**
1255
1259
Frees a space object from the tablespace memory cache. Closes the files in
1256
1260
the chain but does not delete them. There must not be any pending i/o's or
1257
 
flushes on the files. */
 
1261
flushes on the files.
 
1262
@return TRUE if success */
1258
1263
UNIV_INTERN
1259
1264
ibool
1260
1265
fil_space_free(
1261
1266
/*===========*/
1262
 
                        /* out: TRUE if success */
1263
 
        ulint   id)     /* in: space id */
 
1267
        ulint   id)     /*!< in: space id */
1264
1268
{
1265
 
        fil_system_t*   system = fil_system;
1266
1269
        fil_space_t*    space;
1267
1270
        fil_space_t*    namespace;
1268
1271
        fil_node_t*     fil_node;
1269
1272
 
1270
 
        mutex_enter(&(system->mutex));
 
1273
        mutex_enter(&fil_system->mutex);
1271
1274
 
1272
1275
        space = fil_space_get_by_id(id);
1273
1276
 
1278
1281
                        " from the cache but\n"
1279
1282
                        "InnoDB: it is not there.\n", (ulong) id);
1280
1283
 
1281
 
                mutex_exit(&(system->mutex));
 
1284
                mutex_exit(&fil_system->mutex);
1282
1285
 
1283
1286
                return(FALSE);
1284
1287
        }
1285
1288
 
1286
 
        HASH_DELETE(fil_space_t, hash, system->spaces, id, space);
 
1289
        HASH_DELETE(fil_space_t, hash, fil_system->spaces, id, space);
1287
1290
 
1288
1291
        namespace = fil_space_get_by_name(space->name);
1289
1292
        ut_a(namespace);
1290
1293
        ut_a(space == namespace);
1291
1294
 
1292
 
        HASH_DELETE(fil_space_t, name_hash, system->name_hash,
 
1295
        HASH_DELETE(fil_space_t, name_hash, fil_system->name_hash,
1293
1296
                    ut_fold_string(space->name), space);
1294
1297
 
1295
1298
        if (space->is_in_unflushed_spaces) {
1296
1299
                space->is_in_unflushed_spaces = FALSE;
1297
1300
 
1298
 
                UT_LIST_REMOVE(unflushed_spaces, system->unflushed_spaces,
 
1301
                UT_LIST_REMOVE(unflushed_spaces, fil_system->unflushed_spaces,
1299
1302
                               space);
1300
1303
        }
1301
1304
 
1302
 
        UT_LIST_REMOVE(space_list, system->space_list, space);
 
1305
        UT_LIST_REMOVE(space_list, fil_system->space_list, space);
1303
1306
 
1304
1307
        ut_a(space->magic_n == FIL_SPACE_MAGIC_N);
1305
1308
        ut_a(0 == space->n_pending_flushes);
1307
1310
        fil_node = UT_LIST_GET_FIRST(space->chain);
1308
1311
 
1309
1312
        while (fil_node != NULL) {
1310
 
                fil_node_free(fil_node, system, space);
 
1313
                fil_node_free(fil_node, fil_system, space);
1311
1314
 
1312
1315
                fil_node = UT_LIST_GET_FIRST(space->chain);
1313
1316
        }
1314
1317
 
1315
1318
        ut_a(0 == UT_LIST_GET_LEN(space->chain));
1316
1319
 
1317
 
        mutex_exit(&(system->mutex));
 
1320
        mutex_exit(&fil_system->mutex);
1318
1321
 
1319
1322
        rw_lock_free(&(space->latch));
1320
1323
 
1324
1327
        return(TRUE);
1325
1328
}
1326
1329
 
1327
 
#ifdef UNIV_HOTBACKUP
1328
 
/***********************************************************************
1329
 
Returns the tablespace object for a given id, or NULL if not found from the
1330
 
tablespace memory cache. */
1331
 
static
1332
 
fil_space_t*
1333
 
fil_get_space_for_id_low(
1334
 
/*=====================*/
1335
 
                        /* out: tablespace object or NULL; NOTE that you must
1336
 
                        own &(fil_system->mutex) to call this function! */
1337
 
        ulint   id)     /* in: space id */
1338
 
{
1339
 
        fil_system_t*   system          = fil_system;
1340
 
        fil_space_t*    space;
1341
 
 
1342
 
        ut_ad(system);
1343
 
 
1344
 
        space = fil_space_get_by_id(id);
1345
 
 
1346
 
        return(space);
1347
 
}
1348
 
#endif
1349
 
 
1350
 
/***********************************************************************
 
1330
/*******************************************************************//**
1351
1331
Returns the size of the space in pages. The tablespace must be cached in the
1352
 
memory cache. */
 
1332
memory cache.
 
1333
@return space size, 0 if space not found */
1353
1334
UNIV_INTERN
1354
1335
ulint
1355
1336
fil_space_get_size(
1356
1337
/*===============*/
1357
 
                        /* out: space size, 0 if space not found */
1358
 
        ulint   id)     /* in: space id */
 
1338
        ulint   id)     /*!< in: space id */
1359
1339
{
1360
 
        fil_system_t*   system          = fil_system;
1361
1340
        fil_node_t*     node;
1362
1341
        fil_space_t*    space;
1363
1342
        ulint           size;
1364
1343
 
1365
 
        ut_ad(system);
 
1344
        ut_ad(fil_system);
1366
1345
 
1367
1346
        fil_mutex_enter_and_prepare_for_io(id);
1368
1347
 
1369
1348
        space = fil_space_get_by_id(id);
1370
1349
 
1371
1350
        if (space == NULL) {
1372
 
                mutex_exit(&(system->mutex));
 
1351
                mutex_exit(&fil_system->mutex);
1373
1352
 
1374
1353
                return(0);
1375
1354
        }
1385
1364
                the file yet; the following calls will open it and update the
1386
1365
                size fields */
1387
1366
 
1388
 
                fil_node_prepare_for_io(node, system, space);
1389
 
                fil_node_complete_io(node, system, OS_FILE_READ);
 
1367
                fil_node_prepare_for_io(node, fil_system, space);
 
1368
                fil_node_complete_io(node, fil_system, OS_FILE_READ);
1390
1369
        }
1391
1370
 
1392
1371
        size = space->size;
1393
1372
 
1394
 
        mutex_exit(&(system->mutex));
 
1373
        mutex_exit(&fil_system->mutex);
1395
1374
 
1396
1375
        return(size);
1397
1376
}
1398
1377
 
1399
 
/***********************************************************************
 
1378
/*******************************************************************//**
1400
1379
Returns the flags of the space. The tablespace must be cached
1401
 
in the memory cache. */
 
1380
in the memory cache.
 
1381
@return flags, ULINT_UNDEFINED if space not found */
1402
1382
UNIV_INTERN
1403
1383
ulint
1404
1384
fil_space_get_flags(
1405
1385
/*================*/
1406
 
                        /* out: flags, ULINT_UNDEFINED if space not found */
1407
 
        ulint   id)     /* in: space id */
 
1386
        ulint   id)     /*!< in: space id */
1408
1387
{
1409
 
        fil_system_t*   system          = fil_system;
1410
1388
        fil_node_t*     node;
1411
1389
        fil_space_t*    space;
1412
1390
        ulint           flags;
1413
1391
 
1414
 
        ut_ad(system);
 
1392
        ut_ad(fil_system);
1415
1393
 
1416
1394
        if (UNIV_UNLIKELY(!id)) {
1417
1395
                return(0);
1422
1400
        space = fil_space_get_by_id(id);
1423
1401
 
1424
1402
        if (space == NULL) {
1425
 
                mutex_exit(&(system->mutex));
 
1403
                mutex_exit(&fil_system->mutex);
1426
1404
 
1427
1405
                return(ULINT_UNDEFINED);
1428
1406
        }
1438
1416
                the file yet; the following calls will open it and update the
1439
1417
                size fields */
1440
1418
 
1441
 
                fil_node_prepare_for_io(node, system, space);
1442
 
                fil_node_complete_io(node, system, OS_FILE_READ);
 
1419
                fil_node_prepare_for_io(node, fil_system, space);
 
1420
                fil_node_complete_io(node, fil_system, OS_FILE_READ);
1443
1421
        }
1444
1422
 
1445
1423
        flags = space->flags;
1446
1424
 
1447
 
        mutex_exit(&(system->mutex));
 
1425
        mutex_exit(&fil_system->mutex);
1448
1426
 
1449
1427
        return(flags);
1450
1428
}
1451
1429
 
1452
 
/***********************************************************************
 
1430
/*******************************************************************//**
1453
1431
Returns the compressed page size of the space, or 0 if the space
1454
 
is not compressed. The tablespace must be cached in the memory cache. */
 
1432
is not compressed. The tablespace must be cached in the memory cache.
 
1433
@return compressed page size, ULINT_UNDEFINED if space not found */
1455
1434
UNIV_INTERN
1456
1435
ulint
1457
1436
fil_space_get_zip_size(
1458
1437
/*===================*/
1459
 
                        /* out: compressed page size, ULINT_UNDEFINED
1460
 
                        if space not found */
1461
 
        ulint   id)     /* in: space id */
 
1438
        ulint   id)     /*!< in: space id */
1462
1439
{
1463
1440
        ulint   flags;
1464
1441
 
1472
1449
        return(flags);
1473
1450
}
1474
1451
 
1475
 
/***********************************************************************
 
1452
/*******************************************************************//**
1476
1453
Checks if the pair space, page_no refers to an existing page in a tablespace
1477
 
file space. The tablespace must be cached in the memory cache. */
 
1454
file space. The tablespace must be cached in the memory cache.
 
1455
@return TRUE if the address is meaningful */
1478
1456
UNIV_INTERN
1479
1457
ibool
1480
1458
fil_check_adress_in_tablespace(
1481
1459
/*===========================*/
1482
 
                        /* out: TRUE if the address is meaningful */
1483
 
        ulint   id,     /* in: space id */
1484
 
        ulint   page_no)/* in: page number */
 
1460
        ulint   id,     /*!< in: space id */
 
1461
        ulint   page_no)/*!< in: page number */
1485
1462
{
1486
1463
        if (fil_space_get_size(id) > page_no) {
1487
1464
 
1491
1468
        return(FALSE);
1492
1469
}
1493
1470
 
1494
 
/********************************************************************
1495
 
Creates a the tablespace memory cache. */
1496
 
static
1497
 
fil_system_t*
1498
 
fil_system_create(
1499
 
/*==============*/
1500
 
                                /* out, own: tablespace memory cache */
1501
 
        ulint   hash_size,      /* in: hash table size */
1502
 
        ulint   max_n_open)     /* in: maximum number of open files; must be
1503
 
                                > 10 */
1504
 
{
1505
 
        fil_system_t*   system;
1506
 
 
1507
 
        ut_a(hash_size > 0);
1508
 
        ut_a(max_n_open > 0);
1509
 
 
1510
 
        system = mem_alloc(sizeof(fil_system_t));
1511
 
 
1512
 
        mutex_create(&system->mutex, SYNC_ANY_LATCH);
1513
 
 
1514
 
        system->spaces = hash_create(hash_size);
1515
 
        system->name_hash = hash_create(hash_size);
1516
 
 
1517
 
        UT_LIST_INIT(system->LRU);
1518
 
 
1519
 
        system->n_open = 0;
1520
 
        system->max_n_open = max_n_open;
1521
 
 
1522
 
        system->modification_counter = 0;
1523
 
        system->max_assigned_id = 0;
1524
 
 
1525
 
        system->tablespace_version = 0;
1526
 
 
1527
 
        UT_LIST_INIT(system->unflushed_spaces);
1528
 
        UT_LIST_INIT(system->space_list);
1529
 
 
1530
 
        return(system);
1531
 
}
1532
 
 
1533
 
/********************************************************************
 
1471
/****************************************************************//**
1534
1472
Initializes the tablespace memory cache. */
1535
1473
UNIV_INTERN
1536
1474
void
1537
1475
fil_init(
1538
1476
/*=====*/
1539
 
        ulint   max_n_open)     /* in: max number of open files */
 
1477
        ulint   hash_size,      /*!< in: hash table size */
 
1478
        ulint   max_n_open)     /*!< in: max number of open files */
1540
1479
{
1541
 
        ulint   hash_size;
1542
 
 
1543
1480
        ut_a(fil_system == NULL);
1544
1481
 
1545
 
        if (srv_file_per_table) {
1546
 
                hash_size = 50000;
1547
 
        } else {
1548
 
                hash_size = 5000;
1549
 
        }
1550
 
 
1551
 
        fil_system = fil_system_create(hash_size, max_n_open);
 
1482
        ut_a(hash_size > 0);
 
1483
        ut_a(max_n_open > 0);
 
1484
 
 
1485
        fil_system = mem_alloc(sizeof(fil_system_t));
 
1486
 
 
1487
        mutex_create(&fil_system->mutex, SYNC_ANY_LATCH);
 
1488
 
 
1489
        fil_system->spaces = hash_create(hash_size);
 
1490
        fil_system->name_hash = hash_create(hash_size);
 
1491
 
 
1492
        UT_LIST_INIT(fil_system->LRU);
 
1493
 
 
1494
        fil_system->n_open = 0;
 
1495
        fil_system->max_n_open = max_n_open;
 
1496
 
 
1497
        fil_system->modification_counter = 0;
 
1498
        fil_system->max_assigned_id = 0;
 
1499
 
 
1500
        fil_system->tablespace_version = 0;
 
1501
 
 
1502
        UT_LIST_INIT(fil_system->unflushed_spaces);
 
1503
        UT_LIST_INIT(fil_system->space_list);
1552
1504
}
1553
1505
 
1554
 
/***********************************************************************
 
1506
/*******************************************************************//**
1555
1507
Opens all log files and system tablespace data files. They stay open until the
1556
1508
database server shutdown. This should be called at a server startup after the
1557
1509
space objects for the log and the system tablespace have been created. The
1562
1514
fil_open_log_and_system_tablespace_files(void)
1563
1515
/*==========================================*/
1564
1516
{
1565
 
        fil_system_t*   system = fil_system;
1566
1517
        fil_space_t*    space;
1567
1518
        fil_node_t*     node;
1568
1519
 
1569
 
        mutex_enter(&(system->mutex));
 
1520
        mutex_enter(&fil_system->mutex);
1570
1521
 
1571
 
        space = UT_LIST_GET_FIRST(system->space_list);
 
1522
        space = UT_LIST_GET_FIRST(fil_system->space_list);
1572
1523
 
1573
1524
        while (space != NULL) {
1574
1525
                if (space->purpose != FIL_TABLESPACE || space->id == 0) {
1576
1527
 
1577
1528
                        while (node != NULL) {
1578
1529
                                if (!node->open) {
1579
 
                                        fil_node_open_file(node, system,
 
1530
                                        fil_node_open_file(node, fil_system,
1580
1531
                                                           space);
1581
1532
                                }
1582
 
                                if (system->max_n_open < 10 + system->n_open) {
 
1533
                                if (fil_system->max_n_open
 
1534
                                    < 10 + fil_system->n_open) {
1583
1535
                                        fprintf(stderr,
1584
1536
                                                "InnoDB: Warning: you must"
1585
1537
                                                " raise the value of"
1597
1549
                                                " Current open files %lu,"
1598
1550
                                                " max allowed"
1599
1551
                                                " open files %lu.\n",
1600
 
                                                (ulong) system->n_open,
1601
 
                                                (ulong) system->max_n_open);
 
1552
                                                (ulong) fil_system->n_open,
 
1553
                                                (ulong) fil_system->max_n_open);
1602
1554
                                }
1603
1555
                                node = UT_LIST_GET_NEXT(chain, node);
1604
1556
                        }
1606
1558
                space = UT_LIST_GET_NEXT(space_list, space);
1607
1559
        }
1608
1560
 
1609
 
        mutex_exit(&(system->mutex));
 
1561
        mutex_exit(&fil_system->mutex);
1610
1562
}
1611
1563
 
1612
 
/***********************************************************************
 
1564
/*******************************************************************//**
1613
1565
Closes all open files. There must not be any pending i/o's or not flushed
1614
1566
modifications in the files. */
1615
1567
UNIV_INTERN
1617
1569
fil_close_all_files(void)
1618
1570
/*=====================*/
1619
1571
{
1620
 
        fil_system_t*   system = fil_system;
1621
1572
        fil_space_t*    space;
1622
1573
        fil_node_t*     node;
1623
1574
 
1624
 
        mutex_enter(&(system->mutex));
 
1575
        mutex_enter(&fil_system->mutex);
1625
1576
 
1626
 
        space = UT_LIST_GET_FIRST(system->space_list);
 
1577
        space = UT_LIST_GET_FIRST(fil_system->space_list);
1627
1578
 
1628
1579
        while (space != NULL) {
1629
1580
                node = UT_LIST_GET_FIRST(space->chain);
1630
1581
 
1631
1582
                while (node != NULL) {
1632
1583
                        if (node->open) {
1633
 
                                fil_node_close_file(node, system);
 
1584
                                fil_node_close_file(node, fil_system);
1634
1585
                        }
1635
1586
                        node = UT_LIST_GET_NEXT(chain, node);
1636
1587
                }
1637
1588
                space = UT_LIST_GET_NEXT(space_list, space);
1638
1589
        }
1639
1590
 
1640
 
        mutex_exit(&(system->mutex));
 
1591
        mutex_exit(&fil_system->mutex);
1641
1592
}
1642
1593
 
1643
 
/***********************************************************************
 
1594
/*******************************************************************//**
1644
1595
Sets the max tablespace id counter if the given number is bigger than the
1645
1596
previous value. */
1646
1597
UNIV_INTERN
1647
1598
void
1648
1599
fil_set_max_space_id_if_bigger(
1649
1600
/*===========================*/
1650
 
        ulint   max_id) /* in: maximum known id */
 
1601
        ulint   max_id) /*!< in: maximum known id */
1651
1602
{
1652
 
        fil_system_t*   system = fil_system;
1653
 
 
1654
1603
        if (max_id >= SRV_LOG_SPACE_FIRST_ID) {
1655
1604
                fprintf(stderr,
1656
1605
                        "InnoDB: Fatal error: max tablespace id"
1657
1606
                        " is too high, %lu\n", (ulong) max_id);
1658
 
                ut_a(0);
1659
 
        }
1660
 
 
1661
 
        mutex_enter(&(system->mutex));
1662
 
 
1663
 
        if (system->max_assigned_id < max_id) {
1664
 
 
1665
 
                system->max_assigned_id = max_id;
1666
 
        }
1667
 
 
1668
 
        mutex_exit(&(system->mutex));
 
1607
                ut_error;
 
1608
        }
 
1609
 
 
1610
        mutex_enter(&fil_system->mutex);
 
1611
 
 
1612
        if (fil_system->max_assigned_id < max_id) {
 
1613
 
 
1614
                fil_system->max_assigned_id = max_id;
 
1615
        }
 
1616
 
 
1617
        mutex_exit(&fil_system->mutex);
1669
1618
}
1670
1619
 
1671
 
/********************************************************************
 
1620
/****************************************************************//**
1672
1621
Writes the flushed lsn and the latest archived log number to the page header
1673
1622
of the first page of a data file of the system tablespace (space 0),
1674
1623
which is uncompressed. */
1676
1625
ulint
1677
1626
fil_write_lsn_and_arch_no_to_file(
1678
1627
/*==============================*/
1679
 
        ulint           sum_of_sizes,   /* in: combined size of previous files
 
1628
        ulint           sum_of_sizes,   /*!< in: combined size of previous files
1680
1629
                                        in space, in database pages */
1681
 
        ib_uint64_t     lsn,            /* in: lsn to write */
1682
 
        ulint           arch_log_no     /* in: archived log number to write */
1683
 
        __attribute__((unused)))
 
1630
        ib_uint64_t     lsn,            /*!< in: lsn to write */
 
1631
        ulint           arch_log_no __attribute__((unused)))
 
1632
                                        /*!< in: archived log number to write */
1684
1633
{
1685
1634
        byte*   buf1;
1686
1635
        byte*   buf;
1699
1648
        return(DB_SUCCESS);
1700
1649
}
1701
1650
 
1702
 
/********************************************************************
 
1651
/****************************************************************//**
1703
1652
Writes the flushed lsn and the latest archived log number to the page
1704
 
header of the first page of each data file in the system tablespace. */
 
1653
header of the first page of each data file in the system tablespace.
 
1654
@return DB_SUCCESS or error number */
1705
1655
UNIV_INTERN
1706
1656
ulint
1707
1657
fil_write_flushed_lsn_to_data_files(
1708
1658
/*================================*/
1709
 
                                        /* out: DB_SUCCESS or error number */
1710
 
        ib_uint64_t     lsn,            /* in: lsn to write */
1711
 
        ulint           arch_log_no)    /* in: latest archived log
 
1659
        ib_uint64_t     lsn,            /*!< in: lsn to write */
 
1660
        ulint           arch_log_no)    /*!< in: latest archived log
1712
1661
                                        file number */
1713
1662
{
1714
1663
        fil_space_t*    space;
1716
1665
        ulint           sum_of_sizes;
1717
1666
        ulint           err;
1718
1667
 
1719
 
        mutex_enter(&(fil_system->mutex));
 
1668
        mutex_enter(&fil_system->mutex);
1720
1669
 
1721
1670
        space = UT_LIST_GET_FIRST(fil_system->space_list);
1722
1671
 
1733
1682
 
1734
1683
                        node = UT_LIST_GET_FIRST(space->chain);
1735
1684
                        while (node) {
1736
 
                                mutex_exit(&(fil_system->mutex));
 
1685
                                mutex_exit(&fil_system->mutex);
1737
1686
 
1738
1687
                                err = fil_write_lsn_and_arch_no_to_file(
1739
1688
                                        sum_of_sizes, lsn, arch_log_no);
1742
1691
                                        return(err);
1743
1692
                                }
1744
1693
 
1745
 
                                mutex_enter(&(fil_system->mutex));
 
1694
                                mutex_enter(&fil_system->mutex);
1746
1695
 
1747
1696
                                sum_of_sizes += node->size;
1748
1697
                                node = UT_LIST_GET_NEXT(chain, node);
1751
1700
                space = UT_LIST_GET_NEXT(space_list, space);
1752
1701
        }
1753
1702
 
1754
 
        mutex_exit(&(fil_system->mutex));
 
1703
        mutex_exit(&fil_system->mutex);
1755
1704
 
1756
1705
        return(DB_SUCCESS);
1757
1706
}
1758
1707
 
1759
 
/***********************************************************************
 
1708
/*******************************************************************//**
1760
1709
Reads the flushed lsn and arch no fields from a data file at database
1761
1710
startup. */
1762
1711
UNIV_INTERN
1763
1712
void
1764
1713
fil_read_flushed_lsn_and_arch_log_no(
1765
1714
/*=================================*/
1766
 
        os_file_t       data_file,              /* in: open data file */
1767
 
        ibool           one_read_already,       /* in: TRUE if min and max
 
1715
        os_file_t       data_file,              /*!< in: open data file */
 
1716
        ibool           one_read_already,       /*!< in: TRUE if min and max
1768
1717
                                                parameters below already
1769
1718
                                                contain sensible data */
1770
1719
#ifdef UNIV_LOG_ARCHIVE
1771
 
        ulint*          min_arch_log_no,        /* in/out: */
1772
 
        ulint*          max_arch_log_no,        /* in/out: */
 
1720
        ulint*          min_arch_log_no,        /*!< in/out: */
 
1721
        ulint*          max_arch_log_no,        /*!< in/out: */
1773
1722
#endif /* UNIV_LOG_ARCHIVE */
1774
 
        ib_uint64_t*    min_flushed_lsn,        /* in/out: */
1775
 
        ib_uint64_t*    max_flushed_lsn)        /* in/out: */
 
1723
        ib_uint64_t*    min_flushed_lsn,        /*!< in/out: */
 
1724
        ib_uint64_t*    max_flushed_lsn)        /*!< in/out: */
1776
1725
{
1777
1726
        byte*           buf;
1778
1727
        byte*           buf2;
1816
1765
 
1817
1766
/*================ SINGLE-TABLE TABLESPACES ==========================*/
1818
1767
 
1819
 
/***********************************************************************
 
1768
#ifndef UNIV_HOTBACKUP
 
1769
/*******************************************************************//**
1820
1770
Increments the count of pending insert buffer page merges, if space is not
1821
 
being deleted. */
 
1771
being deleted.
 
1772
@return TRUE if being deleted, and ibuf merges should be skipped */
1822
1773
UNIV_INTERN
1823
1774
ibool
1824
1775
fil_inc_pending_ibuf_merges(
1825
1776
/*========================*/
1826
 
                        /* out: TRUE if being deleted, and ibuf merges should
1827
 
                        be skipped */
1828
 
        ulint   id)     /* in: space id */
 
1777
        ulint   id)     /*!< in: space id */
1829
1778
{
1830
 
        fil_system_t*   system          = fil_system;
1831
1779
        fil_space_t*    space;
1832
1780
 
1833
 
        mutex_enter(&(system->mutex));
 
1781
        mutex_enter(&fil_system->mutex);
1834
1782
 
1835
1783
        space = fil_space_get_by_id(id);
1836
1784
 
1842
1790
        }
1843
1791
 
1844
1792
        if (space == NULL || space->stop_ibuf_merges) {
1845
 
                mutex_exit(&(system->mutex));
 
1793
                mutex_exit(&fil_system->mutex);
1846
1794
 
1847
1795
                return(TRUE);
1848
1796
        }
1849
1797
 
1850
1798
        space->n_pending_ibuf_merges++;
1851
1799
 
1852
 
        mutex_exit(&(system->mutex));
 
1800
        mutex_exit(&fil_system->mutex);
1853
1801
 
1854
1802
        return(FALSE);
1855
1803
}
1856
1804
 
1857
 
/***********************************************************************
 
1805
/*******************************************************************//**
1858
1806
Decrements the count of pending insert buffer page merges. */
1859
1807
UNIV_INTERN
1860
1808
void
1861
1809
fil_decr_pending_ibuf_merges(
1862
1810
/*=========================*/
1863
 
        ulint   id)     /* in: space id */
 
1811
        ulint   id)     /*!< in: space id */
1864
1812
{
1865
 
        fil_system_t*   system          = fil_system;
1866
1813
        fil_space_t*    space;
1867
1814
 
1868
 
        mutex_enter(&(system->mutex));
 
1815
        mutex_enter(&fil_system->mutex);
1869
1816
 
1870
1817
        space = fil_space_get_by_id(id);
1871
1818
 
1880
1827
                space->n_pending_ibuf_merges--;
1881
1828
        }
1882
1829
 
1883
 
        mutex_exit(&(system->mutex));
 
1830
        mutex_exit(&fil_system->mutex);
1884
1831
}
 
1832
#endif /* !UNIV_HOTBACKUP */
1885
1833
 
1886
 
/************************************************************
 
1834
/********************************************************//**
1887
1835
Creates the database directory for a table if it does not exist yet. */
1888
1836
static
1889
1837
void
1890
1838
fil_create_directory_for_tablename(
1891
1839
/*===============================*/
1892
 
        const char*     name)   /* in: name in the standard
 
1840
        const char*     name)   /*!< in: name in the standard
1893
1841
                                'databasename/tablename' format */
1894
1842
{
1895
1843
        const char*     namend;
1913
1861
}
1914
1862
 
1915
1863
#ifndef UNIV_HOTBACKUP
1916
 
/************************************************************
 
1864
/********************************************************//**
1917
1865
Writes a log record about an .ibd file create/rename/delete. */
1918
1866
static
1919
1867
void
1920
1868
fil_op_write_log(
1921
1869
/*=============*/
1922
 
        ulint           type,           /* in: MLOG_FILE_CREATE,
 
1870
        ulint           type,           /*!< in: MLOG_FILE_CREATE,
1923
1871
                                        MLOG_FILE_CREATE2,
1924
1872
                                        MLOG_FILE_DELETE, or
1925
1873
                                        MLOG_FILE_RENAME */
1926
 
        ulint           space_id,       /* in: space id */
1927
 
        ulint           flags,          /* in: compressed page size
 
1874
        ulint           space_id,       /*!< in: space id */
 
1875
        ulint           log_flags,      /*!< in: redo log flags (stored
 
1876
                                        in the page number field) */
 
1877
        ulint           flags,          /*!< in: compressed page size
1928
1878
                                        and file format
1929
1879
                                        if type==MLOG_FILE_CREATE2, or 0 */
1930
 
        const char*     name,           /* in: table name in the familiar
 
1880
        const char*     name,           /*!< in: table name in the familiar
1931
1881
                                        'databasename/tablename' format, or
1932
1882
                                        the file path in the case of
1933
1883
                                        MLOG_FILE_DELETE */
1934
 
        const char*     new_name,       /* in: if type is MLOG_FILE_RENAME,
 
1884
        const char*     new_name,       /*!< in: if type is MLOG_FILE_RENAME,
1935
1885
                                        the new table name in the
1936
1886
                                        'databasename/tablename' format */
1937
 
        mtr_t*          mtr)            /* in: mini-transaction handle */
 
1887
        mtr_t*          mtr)            /*!< in: mini-transaction handle */
1938
1888
{
1939
1889
        byte*   log_ptr;
1940
1890
        ulint   len;
1947
1897
                return;
1948
1898
        }
1949
1899
 
1950
 
        log_ptr = mlog_write_initial_log_record_for_file_op(type, space_id, 0,
1951
 
                                                            log_ptr, mtr);
 
1900
        log_ptr = mlog_write_initial_log_record_for_file_op(
 
1901
                type, space_id, log_flags, log_ptr, mtr);
1952
1902
        if (type == MLOG_FILE_CREATE2) {
1953
1903
                mach_write_to_4(log_ptr, flags);
1954
1904
                log_ptr += 4;
1977
1927
}
1978
1928
#endif
1979
1929
 
1980
 
/***********************************************************************
 
1930
/*******************************************************************//**
1981
1931
Parses the body of a log record written about an .ibd file operation. That is,
1982
1932
the log record part after the standard (type, space id, page no) header of the
1983
1933
log record.
1988
1938
created does not exist, then we create the directory, too.
1989
1939
 
1990
1940
Note that ibbackup --apply-log sets fil_path_to_mysql_datadir to point to the
1991
 
datadir that we should use in replaying the file operations. */
 
1941
datadir that we should use in replaying the file operations.
 
1942
@return end of log record, or NULL if the record was not completely
 
1943
contained between ptr and end_ptr */
1992
1944
UNIV_INTERN
1993
1945
byte*
1994
1946
fil_op_log_parse_or_replay(
1995
1947
/*=======================*/
1996
 
                                /* out: end of log record, or NULL if the
1997
 
                                record was not completely contained between
1998
 
                                ptr and end_ptr */
1999
 
        byte*   ptr,            /* in: buffer containing the log record body,
 
1948
        byte*   ptr,            /*!< in: buffer containing the log record body,
2000
1949
                                or an initial segment of it, if the record does
2001
1950
                                not fir completely between ptr and end_ptr */
2002
 
        byte*   end_ptr,        /* in: buffer end */
2003
 
        ulint   type,           /* in: the type of this log record */
2004
 
        ulint   space_id)       /* in: the space id of the tablespace in
 
1951
        byte*   end_ptr,        /*!< in: buffer end */
 
1952
        ulint   type,           /*!< in: the type of this log record */
 
1953
        ulint   space_id,       /*!< in: the space id of the tablespace in
2005
1954
                                question, or 0 if the log record should
2006
1955
                                only be parsed but not replayed */
 
1956
        ulint   log_flags)      /*!< in: redo log flags
 
1957
                                (stored in the page number parameter) */
2007
1958
{
2008
1959
        ulint           name_len;
2009
1960
        ulint           new_name_len;
2123
2074
                } else if (fil_get_space_id_for_table(name)
2124
2075
                           != ULINT_UNDEFINED) {
2125
2076
                        /* Do nothing */
 
2077
                } else if (log_flags & MLOG_FILE_FLAG_TEMP) {
 
2078
                        /* Temporary table, do nothing */
2126
2079
                } else {
2127
2080
                        /* Create the database directory for name, if it does
2128
2081
                        not exist yet */
2144
2097
        return(ptr);
2145
2098
}
2146
2099
 
2147
 
/***********************************************************************
 
2100
/*******************************************************************//**
2148
2101
Deletes a single-table tablespace. The tablespace must be cached in the
2149
 
memory cache. */
 
2102
memory cache.
 
2103
@return TRUE if success */
2150
2104
UNIV_INTERN
2151
2105
ibool
2152
2106
fil_delete_tablespace(
2153
2107
/*==================*/
2154
 
                        /* out: TRUE if success */
2155
 
        ulint   id)     /* in: space id */
 
2108
        ulint   id)     /*!< in: space id */
2156
2109
{
2157
 
        fil_system_t*   system          = fil_system;
2158
2110
        ibool           success;
2159
2111
        fil_space_t*    space;
2160
2112
        fil_node_t*     node;
2163
2115
 
2164
2116
        ut_a(id != 0);
2165
2117
stop_ibuf_merges:
2166
 
        mutex_enter(&(system->mutex));
 
2118
        mutex_enter(&fil_system->mutex);
2167
2119
 
2168
2120
        space = fil_space_get_by_id(id);
2169
2121
 
2171
2123
                space->stop_ibuf_merges = TRUE;
2172
2124
 
2173
2125
                if (space->n_pending_ibuf_merges == 0) {
2174
 
                        mutex_exit(&(system->mutex));
 
2126
                        mutex_exit(&fil_system->mutex);
2175
2127
 
2176
2128
                        count = 0;
2177
2129
 
2190
2142
                                        (ulong) count);
2191
2143
                        }
2192
2144
 
2193
 
                        mutex_exit(&(system->mutex));
 
2145
                        mutex_exit(&fil_system->mutex);
2194
2146
 
2195
2147
                        os_thread_sleep(20000);
2196
2148
                        count++;
2199
2151
                }
2200
2152
        }
2201
2153
 
2202
 
        mutex_exit(&(system->mutex));
 
2154
        mutex_exit(&fil_system->mutex);
2203
2155
        count = 0;
2204
2156
 
2205
2157
try_again:
2206
 
        mutex_enter(&(system->mutex));
 
2158
        mutex_enter(&fil_system->mutex);
2207
2159
 
2208
2160
        space = fil_space_get_by_id(id);
2209
2161
 
2215
2167
                        " tablespace memory cache.\n",
2216
2168
                        (ulong) id);
2217
2169
 
2218
 
                mutex_exit(&(system->mutex));
 
2170
                mutex_exit(&fil_system->mutex);
2219
2171
 
2220
2172
                return(FALSE);
2221
2173
        }
2242
2194
                                (ulong) node->n_pending,
2243
2195
                                (ulong) count);
2244
2196
                }
2245
 
                mutex_exit(&(system->mutex));
 
2197
                mutex_exit(&fil_system->mutex);
2246
2198
                os_thread_sleep(20000);
2247
2199
 
2248
2200
                count++;
2252
2204
 
2253
2205
        path = mem_strdup(space->name);
2254
2206
 
2255
 
        mutex_exit(&(system->mutex));
 
2207
        mutex_exit(&fil_system->mutex);
2256
2208
#ifndef UNIV_HOTBACKUP
2257
2209
        /* Invalidate in the buffer pool all pages belonging to the
2258
2210
        tablespace. Since we have set space->is_being_deleted = TRUE, readahead
2287
2239
                to write any log record */
2288
2240
                mtr_start(&mtr);
2289
2241
 
2290
 
                fil_op_write_log(MLOG_FILE_DELETE, id, 0, path, NULL, &mtr);
 
2242
                fil_op_write_log(MLOG_FILE_DELETE, id, 0, 0, path, NULL, &mtr);
2291
2243
                mtr_commit(&mtr);
2292
2244
#endif
2293
2245
                mem_free(path);
2300
2252
        return(FALSE);
2301
2253
}
2302
2254
 
2303
 
/***********************************************************************
 
2255
#ifndef UNIV_HOTBACKUP
 
2256
/*******************************************************************//**
2304
2257
Discards a single-table tablespace. The tablespace must be cached in the
2305
2258
memory cache. Discarding is like deleting a tablespace, but
2306
2259
1) we do not drop the table from the data dictionary;
2307
2260
2) we remove all insert buffer entries for the tablespace immediately; in DROP
2308
2261
TABLE they are only removed gradually in the background;
2309
2262
3) when the user does IMPORT TABLESPACE, the tablespace will have the same id
2310
 
as it originally had. */
 
2263
as it originally had.
 
2264
@return TRUE if success */
2311
2265
UNIV_INTERN
2312
2266
ibool
2313
2267
fil_discard_tablespace(
2314
2268
/*===================*/
2315
 
                        /* out: TRUE if success */
2316
 
        ulint   id)     /* in: space id */
 
2269
        ulint   id)     /*!< in: space id */
2317
2270
{
2318
2271
        ibool   success;
2319
2272
 
2334
2287
 
2335
2288
        return(success);
2336
2289
}
 
2290
#endif /* !UNIV_HOTBACKUP */
2337
2291
 
2338
 
/***********************************************************************
2339
 
Renames the memory cache structures of a single-table tablespace. */
 
2292
/*******************************************************************//**
 
2293
Renames the memory cache structures of a single-table tablespace.
 
2294
@return TRUE if success */
2340
2295
static
2341
2296
ibool
2342
2297
fil_rename_tablespace_in_mem(
2343
2298
/*=========================*/
2344
 
                                /* out: TRUE if success */
2345
 
        fil_space_t*    space,  /* in: tablespace memory object */
2346
 
        fil_node_t*     node,   /* in: file node of that tablespace */
2347
 
        const char*     path)   /* in: new name */
 
2299
        fil_space_t*    space,  /*!< in: tablespace memory object */
 
2300
        fil_node_t*     node,   /*!< in: file node of that tablespace */
 
2301
        const char*     path)   /*!< in: new name */
2348
2302
{
2349
 
        fil_system_t*   system          = fil_system;
2350
2303
        fil_space_t*    space2;
2351
2304
        const char*     old_name        = space->name;
2352
2305
 
 
2306
        ut_ad(mutex_own(&fil_system->mutex));
 
2307
 
2353
2308
        space2 = fil_space_get_by_name(old_name);
2354
2309
        if (space != space2) {
2355
2310
                fputs("InnoDB: Error: cannot find ", stderr);
2368
2323
                return(FALSE);
2369
2324
        }
2370
2325
 
2371
 
        HASH_DELETE(fil_space_t, name_hash, system->name_hash,
 
2326
        HASH_DELETE(fil_space_t, name_hash, fil_system->name_hash,
2372
2327
                    ut_fold_string(space->name), space);
2373
2328
        mem_free(space->name);
2374
2329
        mem_free(node->name);
2376
2331
        space->name = mem_strdup(path);
2377
2332
        node->name = mem_strdup(path);
2378
2333
 
2379
 
        HASH_INSERT(fil_space_t, name_hash, system->name_hash,
 
2334
        HASH_INSERT(fil_space_t, name_hash, fil_system->name_hash,
2380
2335
                    ut_fold_string(path), space);
2381
2336
        return(TRUE);
2382
2337
}
2383
2338
 
2384
 
/***********************************************************************
 
2339
/*******************************************************************//**
2385
2340
Allocates a file name for a single-table tablespace. The string must be freed
2386
 
by caller with mem_free(). */
 
2341
by caller with mem_free().
 
2342
@return own: file name */
2387
2343
static
2388
2344
char*
2389
2345
fil_make_ibd_name(
2390
2346
/*==============*/
2391
 
                                        /* out, own: file name */
2392
 
        const char*     name,           /* in: table name or a dir path of a
 
2347
        const char*     name,           /*!< in: table name or a dir path of a
2393
2348
                                        TEMPORARY table */
2394
 
        ibool           is_temp)        /* in: TRUE if it is a dir path */
 
2349
        ibool           is_temp)        /*!< in: TRUE if it is a dir path */
2395
2350
{
2396
2351
        ulint   namelen         = strlen(name);
2397
2352
        ulint   dirlen          = strlen(fil_path_to_mysql_datadir);
2413
2368
        return(filename);
2414
2369
}
2415
2370
 
2416
 
/***********************************************************************
 
2371
/*******************************************************************//**
2417
2372
Renames a single-table tablespace. The tablespace must be cached in the
2418
 
tablespace memory cache. */
 
2373
tablespace memory cache.
 
2374
@return TRUE if success */
2419
2375
UNIV_INTERN
2420
2376
ibool
2421
2377
fil_rename_tablespace(
2422
2378
/*==================*/
2423
 
                                        /* out: TRUE if success */
2424
 
        const char*     old_name,       /* in: old table name in the standard
 
2379
        const char*     old_name,       /*!< in: old table name in the standard
2425
2380
                                        databasename/tablename format of
2426
2381
                                        InnoDB, or NULL if we do the rename
2427
2382
                                        based on the space id only */
2428
 
        ulint           id,             /* in: space id */
2429
 
        const char*     new_name)       /* in: new table name in the standard
 
2383
        ulint           id,             /*!< in: space id */
 
2384
        const char*     new_name)       /*!< in: new table name in the standard
2430
2385
                                        databasename/tablename format
2431
2386
                                        of InnoDB */
2432
2387
{
2433
 
        fil_system_t*   system          = fil_system;
2434
2388
        ibool           success;
2435
2389
        fil_space_t*    space;
2436
2390
        fil_node_t*     node;
2457
2411
                fprintf(stderr, ", %lu iterations\n", (ulong) count);
2458
2412
        }
2459
2413
 
2460
 
        mutex_enter(&(system->mutex));
 
2414
        mutex_enter(&fil_system->mutex);
2461
2415
 
2462
2416
        space = fil_space_get_by_id(id);
2463
2417
 
2468
2422
                        "InnoDB: though the table ", (ulong) id);
2469
2423
                ut_print_filename(stderr, old_name);
2470
2424
                fputs(" in a rename operation should have that id\n", stderr);
2471
 
                mutex_exit(&(system->mutex));
 
2425
                mutex_exit(&fil_system->mutex);
2472
2426
 
2473
2427
                return(FALSE);
2474
2428
        }
2475
2429
 
2476
2430
        if (count > 25000) {
2477
2431
                space->stop_ios = FALSE;
2478
 
                mutex_exit(&(system->mutex));
 
2432
                mutex_exit(&fil_system->mutex);
2479
2433
 
2480
2434
                return(FALSE);
2481
2435
        }
2493
2447
                /* There are pending i/o's or flushes, sleep for a while and
2494
2448
                retry */
2495
2449
 
2496
 
                mutex_exit(&(system->mutex));
 
2450
                mutex_exit(&fil_system->mutex);
2497
2451
 
2498
2452
                os_thread_sleep(20000);
2499
2453
 
2502
2456
        } else if (node->modification_counter > node->flush_counter) {
2503
2457
                /* Flush the space */
2504
2458
 
2505
 
                mutex_exit(&(system->mutex));
 
2459
                mutex_exit(&fil_system->mutex);
2506
2460
 
2507
2461
                os_thread_sleep(20000);
2508
2462
 
2513
2467
        } else if (node->open) {
2514
2468
                /* Close the file */
2515
2469
 
2516
 
                fil_node_close_file(node, system);
 
2470
                fil_node_close_file(node, fil_system);
2517
2471
        }
2518
2472
 
2519
2473
        /* Check that the old name in the space is right */
2548
2502
 
2549
2503
        space->stop_ios = FALSE;
2550
2504
 
2551
 
        mutex_exit(&(system->mutex));
 
2505
        mutex_exit(&fil_system->mutex);
2552
2506
 
2553
2507
#ifndef UNIV_HOTBACKUP
2554
2508
        if (success) {
2556
2510
 
2557
2511
                mtr_start(&mtr);
2558
2512
 
2559
 
                fil_op_write_log(MLOG_FILE_RENAME, id, 0, old_name, new_name,
 
2513
                fil_op_write_log(MLOG_FILE_RENAME, id, 0, 0, old_name, new_name,
2560
2514
                                 &mtr);
2561
2515
                mtr_commit(&mtr);
2562
2516
        }
2564
2518
        return(success);
2565
2519
}
2566
2520
 
2567
 
/***********************************************************************
 
2521
/*******************************************************************//**
2568
2522
Creates a new single-table tablespace to a database directory of MySQL.
2569
2523
Database directories are under the 'datadir' of MySQL. The datadir is the
2570
2524
directory of a running mysqld program. We can refer to it by simply the
2571
2525
path '.'. Tables created with CREATE TEMPORARY TABLE we place in the temp
2572
 
dir of the mysqld server. */
 
2526
dir of the mysqld server.
 
2527
@return DB_SUCCESS or error code */
2573
2528
UNIV_INTERN
2574
2529
ulint
2575
2530
fil_create_new_single_table_tablespace(
2576
2531
/*===================================*/
2577
 
                                        /* out: DB_SUCCESS or error code */
2578
 
        ulint*          space_id,       /* in/out: space id; if this is != 0,
 
2532
        ulint*          space_id,       /*!< in/out: space id; if this is != 0,
2579
2533
                                        then this is an input parameter,
2580
2534
                                        otherwise output */
2581
 
        const char*     tablename,      /* in: the table name in the usual
 
2535
        const char*     tablename,      /*!< in: the table name in the usual
2582
2536
                                        databasename/tablename format
2583
2537
                                        of InnoDB, or a dir path to a temp
2584
2538
                                        table */
2585
 
        ibool           is_temp,        /* in: TRUE if a table created with
 
2539
        ibool           is_temp,        /*!< in: TRUE if a table created with
2586
2540
                                        CREATE TEMPORARY TABLE */
2587
 
        ulint           flags,          /* in: tablespace flags */
2588
 
        ulint           size)           /* in: the initial size of the
 
2541
        ulint           flags,          /*!< in: tablespace flags */
 
2542
        ulint           size)           /*!< in: the initial size of the
2589
2543
                                        tablespace file in pages,
2590
2544
                                        must be >= FIL_IBD_FILE_INITIAL_SIZE */
2591
2545
{
2760
2714
                fil_op_write_log(flags
2761
2715
                                 ? MLOG_FILE_CREATE2
2762
2716
                                 : MLOG_FILE_CREATE,
2763
 
                                 *space_id, flags,
 
2717
                                 *space_id,
 
2718
                                 is_temp ? MLOG_FILE_FLAG_TEMP : 0,
 
2719
                                 flags,
2764
2720
                                 tablename, NULL, &mtr);
2765
2721
 
2766
2722
                mtr_commit(&mtr);
2770
2726
        return(DB_SUCCESS);
2771
2727
}
2772
2728
 
2773
 
/************************************************************************
 
2729
#ifndef UNIV_HOTBACKUP
 
2730
/********************************************************************//**
2774
2731
It is possible, though very improbable, that the lsn's in the tablespace to be
2775
2732
imported have risen above the current system lsn, if a lengthy purge, ibuf
2776
2733
merge, or rollback was performed on a backup taken with ibbackup. If that is
2778
2735
after it performed these cleanup operations on the .ibd file, so that it at
2779
2736
the shutdown stamped the latest lsn to the FIL_PAGE_FILE_FLUSH_LSN in the
2780
2737
first page of the .ibd file, and we can determine whether we need to reset the
2781
 
lsn's just by looking at that flush lsn. */
 
2738
lsn's just by looking at that flush lsn.
 
2739
@return TRUE if success */
2782
2740
UNIV_INTERN
2783
2741
ibool
2784
2742
fil_reset_too_high_lsns(
2785
2743
/*====================*/
2786
 
                                        /* out: TRUE if success */
2787
 
        const char*     name,           /* in: table name in the
 
2744
        const char*     name,           /*!< in: table name in the
2788
2745
                                        databasename/tablename format */
2789
 
        ib_uint64_t     current_lsn)    /* in: reset lsn's if the lsn stamped
 
2746
        ib_uint64_t     current_lsn)    /*!< in: reset lsn's if the lsn stamped
2790
2747
                                        to FIL_PAGE_FILE_FLUSH_LSN in the
2791
2748
                                        first page is too high */
2792
2749
{
2933
2890
        return(success);
2934
2891
}
2935
2892
 
2936
 
/************************************************************************
 
2893
/********************************************************************//**
2937
2894
Tries to open a single-table tablespace and optionally checks the space id is
2938
2895
right in it. If does not succeed, prints an error message to the .err log. This
2939
2896
function is used to open a tablespace when we start up mysqld, and also in
2941
2898
NOTE that we assume this operation is used either at the database startup
2942
2899
or under the protection of the dictionary mutex, so that two users cannot
2943
2900
race here. This operation does not leave the file associated with the
2944
 
tablespace open, but closes it after we have looked at the space id in it. */
 
2901
tablespace open, but closes it after we have looked at the space id in it.
 
2902
@return TRUE if success */
2945
2903
UNIV_INTERN
2946
2904
ibool
2947
2905
fil_open_single_table_tablespace(
2948
2906
/*=============================*/
2949
 
                                        /* out: TRUE if success */
2950
 
        ibool           check_space_id, /* in: should we check that the space
 
2907
        ibool           check_space_id, /*!< in: should we check that the space
2951
2908
                                        id in the file is right; we assume
2952
2909
                                        that this function runs much faster
2953
2910
                                        if no check is made, since accessing
2954
2911
                                        the file inode probably is much
2955
2912
                                        faster (the OS caches them) than
2956
2913
                                        accessing the first page of the file */
2957
 
        ulint           id,             /* in: space id */
2958
 
        ulint           flags,          /* in: tablespace flags */
2959
 
        const char*     name)           /* in: table name in the
 
2914
        ulint           id,             /*!< in: space id */
 
2915
        ulint           flags,          /*!< in: tablespace flags */
 
2916
        const char*     name)           /*!< in: table name in the
2960
2917
                                        databasename/tablename format */
2961
2918
{
2962
2919
        os_file_t       file;
2997
2954
                      " a temporary table #sql...,\n"
2998
2955
                      "InnoDB: and MySQL removed the .ibd file for this.\n"
2999
2956
                      "InnoDB: Please refer to\n"
3000
 
                      "InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
3001
 
                      "innodb-troubleshooting.html\n"
 
2957
                      "InnoDB: " REFMAN "innodb-troubleshooting-datadict.html\n"
3002
2958
                      "InnoDB: for how to resolve the issue.\n", stderr);
3003
2959
 
3004
2960
                mem_free(filepath);
3040
2996
                        "InnoDB: commands DISCARD TABLESPACE and"
3041
2997
                        " IMPORT TABLESPACE?\n"
3042
2998
                        "InnoDB: Please refer to\n"
3043
 
                        "InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
3044
 
                        "innodb-troubleshooting.html\n"
 
2999
                        "InnoDB: " REFMAN "innodb-troubleshooting-datadict.html\n"
3045
3000
                        "InnoDB: for how to resolve the issue.\n",
3046
3001
                        (ulong) space_id, (ulong) space_flags,
3047
3002
                        (ulong) id, (ulong) flags);
3068
3023
 
3069
3024
        return(ret);
3070
3025
}
 
3026
#endif /* !UNIV_HOTBACKUP */
3071
3027
 
3072
3028
#ifdef UNIV_HOTBACKUP
3073
 
/***********************************************************************
 
3029
/*******************************************************************//**
3074
3030
Allocates a file name for an old version of a single-table tablespace.
3075
 
The string must be freed by caller with mem_free()! */
 
3031
The string must be freed by caller with mem_free()!
 
3032
@return own: file name */
3076
3033
static
3077
3034
char*
3078
3035
fil_make_ibbackup_old_name(
3079
3036
/*=======================*/
3080
 
                                        /* out, own: file name */
3081
 
        const char*     name)           /* in: original file name */
 
3037
        const char*     name)           /*!< in: original file name */
3082
3038
{
3083
3039
        static const char suffix[] = "_ibbackup_old_vers_";
3084
3040
        ulint   len     = strlen(name);
3091
3047
}
3092
3048
#endif /* UNIV_HOTBACKUP */
3093
3049
 
3094
 
/************************************************************************
 
3050
/********************************************************************//**
3095
3051
Opens an .ibd file and adds the associated single-table tablespace to the
3096
3052
InnoDB fil0fil.c data structures. */
3097
3053
static
3098
3054
void
3099
3055
fil_load_single_table_tablespace(
3100
3056
/*=============================*/
3101
 
        const char*     dbname,         /* in: database name */
3102
 
        const char*     filename)       /* in: file name (not a path),
 
3057
        const char*     dbname,         /*!< in: database name */
 
3058
        const char*     filename)       /*!< in: file name (not a path),
3103
3059
                                        including the .ibd extension */
3104
3060
{
3105
3061
        os_file_t       file;
3307
3263
        file than delete it, because if there is a bug, we do not want to
3308
3264
        destroy valuable data. */
3309
3265
 
3310
 
        mutex_enter(&(fil_system->mutex));
 
3266
        mutex_enter(&fil_system->mutex);
3311
3267
 
3312
 
        space = fil_get_space_for_id_low(space_id);
 
3268
        space = fil_space_get_by_id(space_id);
3313
3269
 
3314
3270
        if (space) {
3315
3271
                char*   new_path;
3327
3283
 
3328
3284
                new_path = fil_make_ibbackup_old_name(filepath);
3329
3285
 
3330
 
                mutex_exit(&(fil_system->mutex));
 
3286
                mutex_exit(&fil_system->mutex);
3331
3287
 
3332
3288
                ut_a(os_file_rename(filepath, new_path));
3333
3289
 
3337
3293
 
3338
3294
                return;
3339
3295
        }
3340
 
        mutex_exit(&(fil_system->mutex));
 
3296
        mutex_exit(&fil_system->mutex);
3341
3297
#endif
3342
3298
        success = fil_space_create(filepath, space_id, flags, FIL_TABLESPACE);
3343
3299
 
3357
3313
        mem_free(filepath);
3358
3314
}
3359
3315
 
3360
 
/***************************************************************************
 
3316
/***********************************************************************//**
3361
3317
A fault-tolerant function that tries to read the next file name in the
3362
3318
directory. We retry 100 times if os_file_readdir_next_file() returns -1. The
3363
 
idea is to read as much good data as we can and jump over bad data. */
 
3319
idea is to read as much good data as we can and jump over bad data.
 
3320
@return 0 if ok, -1 if error even after the retries, 1 if at the end
 
3321
of the directory */
3364
3322
static
3365
3323
int
3366
3324
fil_file_readdir_next_file(
3367
3325
/*=======================*/
3368
 
                                /* out: 0 if ok, -1 if error even after the
3369
 
                                retries, 1 if at the end of the directory */
3370
 
        ulint*          err,    /* out: this is set to DB_ERROR if an error
 
3326
        ulint*          err,    /*!< out: this is set to DB_ERROR if an error
3371
3327
                                was encountered, otherwise not changed */
3372
 
        const char*     dirname,/* in: directory name or path */
3373
 
        os_file_dir_t   dir,    /* in: directory stream */
3374
 
        os_file_stat_t* info)   /* in/out: buffer where the info is returned */
 
3328
        const char*     dirname,/*!< in: directory name or path */
 
3329
        os_file_dir_t   dir,    /*!< in: directory stream */
 
3330
        os_file_stat_t* info)   /*!< in/out: buffer where the info is returned */
3375
3331
{
3376
3332
        ulint   i;
3377
3333
        int     ret;
3397
3353
        return(-1);
3398
3354
}
3399
3355
 
3400
 
/************************************************************************
 
3356
/********************************************************************//**
3401
3357
At the server startup, if we need crash recovery, scans the database
3402
3358
directories under the MySQL datadir, looking for .ibd files. Those files are
3403
3359
single-table tablespaces. We need to know the space id in each of them so that
3404
3360
we know into which file we should look to check the contents of a page stored
3405
3361
in the doublewrite buffer, also to know where to apply log records where the
3406
 
space id is != 0. */
 
3362
space id is != 0.
 
3363
@return DB_SUCCESS or error number */
3407
3364
UNIV_INTERN
3408
3365
ulint
3409
3366
fil_load_single_table_tablespaces(void)
3410
3367
/*===================================*/
3411
 
                        /* out: DB_SUCCESS or error number */
3412
3368
{
3413
3369
        int             ret;
3414
3370
        char*           dbpath          = NULL;
3526
3482
        return(err);
3527
3483
}
3528
3484
 
3529
 
/************************************************************************
 
3485
/********************************************************************//**
3530
3486
If we need crash recovery, and we have called
3531
3487
fil_load_single_table_tablespaces() and dict_load_single_table_tablespaces(),
3532
3488
we can call this function to print an error message of orphaned .ibd files
3537
3493
fil_print_orphaned_tablespaces(void)
3538
3494
/*================================*/
3539
3495
{
3540
 
        fil_system_t*   system          = fil_system;
3541
3496
        fil_space_t*    space;
3542
3497
 
3543
 
        mutex_enter(&(system->mutex));
 
3498
        mutex_enter(&fil_system->mutex);
3544
3499
 
3545
 
        space = UT_LIST_GET_FIRST(system->space_list);
 
3500
        space = UT_LIST_GET_FIRST(fil_system->space_list);
3546
3501
 
3547
3502
        while (space) {
3548
3503
                if (space->purpose == FIL_TABLESPACE && space->id != 0
3557
3512
                space = UT_LIST_GET_NEXT(space_list, space);
3558
3513
        }
3559
3514
 
3560
 
        mutex_exit(&(system->mutex));
 
3515
        mutex_exit(&fil_system->mutex);
3561
3516
}
3562
3517
 
3563
 
/***********************************************************************
 
3518
/*******************************************************************//**
3564
3519
Returns TRUE if a single-table tablespace does not exist in the memory cache,
3565
 
or is being deleted there. */
 
3520
or is being deleted there.
 
3521
@return TRUE if does not exist or is being\ deleted */
3566
3522
UNIV_INTERN
3567
3523
ibool
3568
3524
fil_tablespace_deleted_or_being_deleted_in_mem(
3569
3525
/*===========================================*/
3570
 
                                /* out: TRUE if does not exist or is being\
3571
 
                                deleted */
3572
 
        ulint           id,     /* in: space id */
3573
 
        ib_int64_t      version)/* in: tablespace_version should be this; if
 
3526
        ulint           id,     /*!< in: space id */
 
3527
        ib_int64_t      version)/*!< in: tablespace_version should be this; if
3574
3528
                                you pass -1 as the value of this, then this
3575
3529
                                parameter is ignored */
3576
3530
{
3577
 
        fil_system_t*   system  = fil_system;
3578
3531
        fil_space_t*    space;
3579
3532
 
3580
 
        ut_ad(system);
 
3533
        ut_ad(fil_system);
3581
3534
 
3582
 
        mutex_enter(&(system->mutex));
 
3535
        mutex_enter(&fil_system->mutex);
3583
3536
 
3584
3537
        space = fil_space_get_by_id(id);
3585
3538
 
3586
3539
        if (space == NULL || space->is_being_deleted) {
3587
 
                mutex_exit(&(system->mutex));
 
3540
                mutex_exit(&fil_system->mutex);
3588
3541
 
3589
3542
                return(TRUE);
3590
3543
        }
3591
3544
 
3592
3545
        if (version != ((ib_int64_t)-1)
3593
3546
            && space->tablespace_version != version) {
3594
 
                mutex_exit(&(system->mutex));
 
3547
                mutex_exit(&fil_system->mutex);
3595
3548
 
3596
3549
                return(TRUE);
3597
3550
        }
3598
3551
 
3599
 
        mutex_exit(&(system->mutex));
 
3552
        mutex_exit(&fil_system->mutex);
3600
3553
 
3601
3554
        return(FALSE);
3602
3555
}
3603
3556
 
3604
 
/***********************************************************************
3605
 
Returns TRUE if a single-table tablespace exists in the memory cache. */
 
3557
/*******************************************************************//**
 
3558
Returns TRUE if a single-table tablespace exists in the memory cache.
 
3559
@return TRUE if exists */
3606
3560
UNIV_INTERN
3607
3561
ibool
3608
3562
fil_tablespace_exists_in_mem(
3609
3563
/*=========================*/
3610
 
                        /* out: TRUE if exists */
3611
 
        ulint   id)     /* in: space id */
 
3564
        ulint   id)     /*!< in: space id */
3612
3565
{
3613
 
        fil_system_t*   system          = fil_system;
3614
3566
        fil_space_t*    space;
3615
3567
 
3616
 
        ut_ad(system);
 
3568
        ut_ad(fil_system);
3617
3569
 
3618
 
        mutex_enter(&(system->mutex));
 
3570
        mutex_enter(&fil_system->mutex);
3619
3571
 
3620
3572
        space = fil_space_get_by_id(id);
3621
3573
 
3622
 
        if (space == NULL) {
3623
 
                mutex_exit(&(system->mutex));
3624
 
 
3625
 
                return(FALSE);
3626
 
        }
3627
 
 
3628
 
        mutex_exit(&(system->mutex));
3629
 
 
3630
 
        return(TRUE);
 
3574
        mutex_exit(&fil_system->mutex);
 
3575
 
 
3576
        return(space != NULL);
3631
3577
}
3632
3578
 
3633
 
/***********************************************************************
 
3579
/*******************************************************************//**
3634
3580
Returns TRUE if a matching tablespace exists in the InnoDB tablespace memory
3635
3581
cache. Note that if we have not done a crash recovery at the database startup,
3636
 
there may be many tablespaces which are not yet in the memory cache. */
 
3582
there may be many tablespaces which are not yet in the memory cache.
 
3583
@return TRUE if a matching tablespace exists in the memory cache */
3637
3584
UNIV_INTERN
3638
3585
ibool
3639
3586
fil_space_for_table_exists_in_mem(
3640
3587
/*==============================*/
3641
 
                                        /* out: TRUE if a matching tablespace
3642
 
                                        exists in the memory cache */
3643
 
        ulint           id,             /* in: space id */
3644
 
        const char*     name,           /* in: table name in the standard
 
3588
        ulint           id,             /*!< in: space id */
 
3589
        const char*     name,           /*!< in: table name in the standard
3645
3590
                                        'databasename/tablename' format or
3646
3591
                                        the dir path to a temp table */
3647
 
        ibool           is_temp,        /* in: TRUE if created with CREATE
 
3592
        ibool           is_temp,        /*!< in: TRUE if created with CREATE
3648
3593
                                        TEMPORARY TABLE */
3649
 
        ibool           mark_space,     /* in: in crash recovery, at database
 
3594
        ibool           mark_space,     /*!< in: in crash recovery, at database
3650
3595
                                        startup we mark all spaces which have
3651
3596
                                        an associated table in the InnoDB
3652
3597
                                        data dictionary, so that
3653
3598
                                        we can print a warning about orphaned
3654
3599
                                        tablespaces */
3655
3600
        ibool           print_error_if_does_not_exist)
3656
 
                                        /* in: print detailed error
 
3601
                                        /*!< in: print detailed error
3657
3602
                                        information to the .err log if a
3658
3603
                                        matching tablespace is not found from
3659
3604
                                        memory */
3660
3605
{
3661
 
        fil_system_t*   system          = fil_system;
3662
3606
        fil_space_t*    namespace;
3663
3607
        fil_space_t*    space;
3664
3608
        char*           path;
3665
3609
 
3666
 
        ut_ad(system);
 
3610
        ut_ad(fil_system);
3667
3611
 
3668
 
        mutex_enter(&(system->mutex));
 
3612
        mutex_enter(&fil_system->mutex);
3669
3613
 
3670
3614
        path = fil_make_ibd_name(name, is_temp);
3671
3615
 
3685
3629
                }
3686
3630
 
3687
3631
                mem_free(path);
3688
 
                mutex_exit(&(system->mutex));
 
3632
                mutex_exit(&fil_system->mutex);
3689
3633
 
3690
3634
                return(TRUE);
3691
3635
        }
3693
3637
        if (!print_error_if_does_not_exist) {
3694
3638
 
3695
3639
                mem_free(path);
3696
 
                mutex_exit(&(system->mutex));
 
3640
                mutex_exit(&fil_system->mutex);
3697
3641
 
3698
3642
                return(FALSE);
3699
3643
        }
3733
3677
                }
3734
3678
error_exit:
3735
3679
                fputs("InnoDB: Please refer to\n"
3736
 
                      "InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
3737
 
                      "innodb-troubleshooting.html\n"
 
3680
                      "InnoDB: " REFMAN "innodb-troubleshooting-datadict.html\n"
3738
3681
                      "InnoDB: for how to resolve the issue.\n", stderr);
3739
3682
 
3740
3683
                mem_free(path);
3741
 
                mutex_exit(&(system->mutex));
 
3684
                mutex_exit(&fil_system->mutex);
3742
3685
 
3743
3686
                return(FALSE);
3744
3687
        }
3768
3711
        }
3769
3712
 
3770
3713
        mem_free(path);
3771
 
        mutex_exit(&(system->mutex));
 
3714
        mutex_exit(&fil_system->mutex);
3772
3715
 
3773
3716
        return(FALSE);
3774
3717
}
3775
3718
 
3776
 
/***********************************************************************
 
3719
/*******************************************************************//**
3777
3720
Checks if a single-table tablespace for a given table name exists in the
3778
 
tablespace memory cache. */
 
3721
tablespace memory cache.
 
3722
@return space id, ULINT_UNDEFINED if not found */
3779
3723
static
3780
3724
ulint
3781
3725
fil_get_space_id_for_table(
3782
3726
/*=======================*/
3783
 
                                /* out: space id, ULINT_UNDEFINED if not
3784
 
                                found */
3785
 
        const char*     name)   /* in: table name in the standard
 
3727
        const char*     name)   /*!< in: table name in the standard
3786
3728
                                'databasename/tablename' format */
3787
3729
{
3788
 
        fil_system_t*   system          = fil_system;
3789
3730
        fil_space_t*    namespace;
3790
3731
        ulint           id              = ULINT_UNDEFINED;
3791
3732
        char*           path;
3792
3733
 
3793
 
        ut_ad(system);
 
3734
        ut_ad(fil_system);
3794
3735
 
3795
 
        mutex_enter(&(system->mutex));
 
3736
        mutex_enter(&fil_system->mutex);
3796
3737
 
3797
3738
        path = fil_make_ibd_name(name, FALSE);
3798
3739
 
3807
3748
 
3808
3749
        mem_free(path);
3809
3750
 
3810
 
        mutex_exit(&(system->mutex));
 
3751
        mutex_exit(&fil_system->mutex);
3811
3752
 
3812
3753
        return(id);
3813
3754
}
3814
3755
 
3815
 
/**************************************************************************
 
3756
/**********************************************************************//**
3816
3757
Tries to extend a data file so that it would accommodate the number of pages
3817
3758
given. The tablespace must be cached in the memory cache. If the space is big
3818
 
enough already, does nothing. */
 
3759
enough already, does nothing.
 
3760
@return TRUE if success */
3819
3761
UNIV_INTERN
3820
3762
ibool
3821
3763
fil_extend_space_to_desired_size(
3822
3764
/*=============================*/
3823
 
                                /* out: TRUE if success */
3824
 
        ulint*  actual_size,    /* out: size of the space after extension;
 
3765
        ulint*  actual_size,    /*!< out: size of the space after extension;
3825
3766
                                if we ran out of disk space this may be lower
3826
3767
                                than the desired size */
3827
 
        ulint   space_id,       /* in: space id */
3828
 
        ulint   size_after_extend)/* in: desired size in pages after the
 
3768
        ulint   space_id,       /*!< in: space id */
 
3769
        ulint   size_after_extend)/*!< in: desired size in pages after the
3829
3770
                                extension; if the current space size is bigger
3830
3771
                                than this already, the function does nothing */
3831
3772
{
3832
 
        fil_system_t*   system          = fil_system;
3833
3773
        fil_node_t*     node;
3834
3774
        fil_space_t*    space;
3835
3775
        byte*           buf2;
3852
3792
 
3853
3793
                *actual_size = space->size;
3854
3794
 
3855
 
                mutex_exit(&(system->mutex));
 
3795
                mutex_exit(&fil_system->mutex);
3856
3796
 
3857
3797
                return(TRUE);
3858
3798
        }
3864
3804
 
3865
3805
        node = UT_LIST_GET_LAST(space->chain);
3866
3806
 
3867
 
        fil_node_prepare_for_io(node, system, space);
 
3807
        fil_node_prepare_for_io(node, fil_system, space);
3868
3808
 
3869
3809
        start_page_no = space->size;
3870
3810
        file_start_page_no = space->size - node->size;
3921
3861
 
3922
3862
        mem_free(buf2);
3923
3863
 
3924
 
        fil_node_complete_io(node, system, OS_FILE_WRITE);
 
3864
        fil_node_complete_io(node, fil_system, OS_FILE_WRITE);
3925
3865
 
3926
3866
        *actual_size = space->size;
3927
3867
 
3940
3880
        /*
3941
3881
        printf("Extended %s to %lu, actual size %lu pages\n", space->name,
3942
3882
        size_after_extend, *actual_size); */
3943
 
        mutex_exit(&(system->mutex));
 
3883
        mutex_exit(&fil_system->mutex);
3944
3884
 
3945
3885
        fil_flush(space_id);
3946
3886
 
3948
3888
}
3949
3889
 
3950
3890
#ifdef UNIV_HOTBACKUP
3951
 
/************************************************************************
 
3891
/********************************************************************//**
3952
3892
Extends all tablespaces to the size stored in the space header. During the
3953
3893
ibbackup --apply-log phase we extended the spaces on-demand so that log records
3954
3894
could be applied, but that may have left spaces still too small compared to
3958
3898
fil_extend_tablespaces_to_stored_len(void)
3959
3899
/*======================================*/
3960
3900
{
3961
 
        fil_system_t*   system          = fil_system;
3962
3901
        fil_space_t*    space;
3963
3902
        byte*           buf;
3964
3903
        ulint           actual_size;
3968
3907
 
3969
3908
        buf = mem_alloc(UNIV_PAGE_SIZE);
3970
3909
 
3971
 
        mutex_enter(&(system->mutex));
 
3910
        mutex_enter(&fil_system->mutex);
3972
3911
 
3973
 
        space = UT_LIST_GET_FIRST(system->space_list);
 
3912
        space = UT_LIST_GET_FIRST(fil_system->space_list);
3974
3913
 
3975
3914
        while (space) {
3976
3915
                ut_a(space->purpose == FIL_TABLESPACE);
3977
3916
 
3978
 
                mutex_exit(&(system->mutex)); /* no need to protect with a
 
3917
                mutex_exit(&fil_system->mutex); /* no need to protect with a
3979
3918
                                              mutex, because this is a
3980
3919
                                              single-threaded operation */
3981
 
                error = fil_read(TRUE, space->id, space->zip_size,
 
3920
                error = fil_read(TRUE, space->id,
 
3921
                                 dict_table_flags_to_zip_size(space->flags),
3982
3922
                                 0, 0, UNIV_PAGE_SIZE, buf, NULL);
3983
3923
                ut_a(error == DB_SUCCESS);
3984
3924
 
3999
3939
                        exit(1);
4000
3940
                }
4001
3941
 
4002
 
                mutex_enter(&(system->mutex));
 
3942
                mutex_enter(&fil_system->mutex);
4003
3943
 
4004
3944
                space = UT_LIST_GET_NEXT(space_list, space);
4005
3945
        }
4006
3946
 
4007
 
        mutex_exit(&(system->mutex));
 
3947
        mutex_exit(&fil_system->mutex);
4008
3948
 
4009
3949
        mem_free(buf);
4010
3950
}
4012
3952
 
4013
3953
/*========== RESERVE FREE EXTENTS (for a B-tree split, for example) ===*/
4014
3954
 
4015
 
/***********************************************************************
4016
 
Tries to reserve free extents in a file space. */
 
3955
/*******************************************************************//**
 
3956
Tries to reserve free extents in a file space.
 
3957
@return TRUE if succeed */
4017
3958
UNIV_INTERN
4018
3959
ibool
4019
3960
fil_space_reserve_free_extents(
4020
3961
/*===========================*/
4021
 
                                /* out: TRUE if succeed */
4022
 
        ulint   id,             /* in: space id */
4023
 
        ulint   n_free_now,     /* in: number of free extents now */
4024
 
        ulint   n_to_reserve)   /* in: how many one wants to reserve */
 
3962
        ulint   id,             /*!< in: space id */
 
3963
        ulint   n_free_now,     /*!< in: number of free extents now */
 
3964
        ulint   n_to_reserve)   /*!< in: how many one wants to reserve */
4025
3965
{
4026
 
        fil_system_t*   system          = fil_system;
4027
3966
        fil_space_t*    space;
4028
3967
        ibool           success;
4029
3968
 
4030
 
        ut_ad(system);
 
3969
        ut_ad(fil_system);
4031
3970
 
4032
 
        mutex_enter(&(system->mutex));
 
3971
        mutex_enter(&fil_system->mutex);
4033
3972
 
4034
3973
        space = fil_space_get_by_id(id);
4035
3974
 
4042
3981
                success = TRUE;
4043
3982
        }
4044
3983
 
4045
 
        mutex_exit(&(system->mutex));
 
3984
        mutex_exit(&fil_system->mutex);
4046
3985
 
4047
3986
        return(success);
4048
3987
}
4049
3988
 
4050
 
/***********************************************************************
 
3989
/*******************************************************************//**
4051
3990
Releases free extents in a file space. */
4052
3991
UNIV_INTERN
4053
3992
void
4054
3993
fil_space_release_free_extents(
4055
3994
/*===========================*/
4056
 
        ulint   id,             /* in: space id */
4057
 
        ulint   n_reserved)     /* in: how many one reserved */
 
3995
        ulint   id,             /*!< in: space id */
 
3996
        ulint   n_reserved)     /*!< in: how many one reserved */
4058
3997
{
4059
 
        fil_system_t*   system          = fil_system;
4060
3998
        fil_space_t*    space;
4061
3999
 
4062
 
        ut_ad(system);
 
4000
        ut_ad(fil_system);
4063
4001
 
4064
 
        mutex_enter(&(system->mutex));
 
4002
        mutex_enter(&fil_system->mutex);
4065
4003
 
4066
4004
        space = fil_space_get_by_id(id);
4067
4005
 
4070
4008
 
4071
4009
        space->n_reserved_extents -= n_reserved;
4072
4010
 
4073
 
        mutex_exit(&(system->mutex));
 
4011
        mutex_exit(&fil_system->mutex);
4074
4012
}
4075
4013
 
4076
 
/***********************************************************************
 
4014
/*******************************************************************//**
4077
4015
Gets the number of reserved extents. If the database is silent, this number
4078
4016
should be zero. */
4079
4017
UNIV_INTERN
4080
4018
ulint
4081
4019
fil_space_get_n_reserved_extents(
4082
4020
/*=============================*/
4083
 
        ulint   id)             /* in: space id */
 
4021
        ulint   id)             /*!< in: space id */
4084
4022
{
4085
 
        fil_system_t*   system          = fil_system;
4086
4023
        fil_space_t*    space;
4087
4024
        ulint           n;
4088
4025
 
4089
 
        ut_ad(system);
 
4026
        ut_ad(fil_system);
4090
4027
 
4091
 
        mutex_enter(&(system->mutex));
 
4028
        mutex_enter(&fil_system->mutex);
4092
4029
 
4093
4030
        space = fil_space_get_by_id(id);
4094
4031
 
4096
4033
 
4097
4034
        n = space->n_reserved_extents;
4098
4035
 
4099
 
        mutex_exit(&(system->mutex));
 
4036
        mutex_exit(&fil_system->mutex);
4100
4037
 
4101
4038
        return(n);
4102
4039
}
4103
4040
 
4104
4041
/*============================ FILE I/O ================================*/
4105
4042
 
4106
 
/************************************************************************
 
4043
/********************************************************************//**
4107
4044
NOTE: you must call fil_mutex_enter_and_prepare_for_io() first!
4108
4045
 
4109
4046
Prepares a file node for i/o. Opens the file if it is closed. Updates the
4114
4051
void
4115
4052
fil_node_prepare_for_io(
4116
4053
/*====================*/
4117
 
        fil_node_t*     node,   /* in: file node */
4118
 
        fil_system_t*   system, /* in: tablespace memory cache */
4119
 
        fil_space_t*    space)  /* in: space */
 
4054
        fil_node_t*     node,   /*!< in: file node */
 
4055
        fil_system_t*   system, /*!< in: tablespace memory cache */
 
4056
        fil_space_t*    space)  /*!< in: space */
4120
4057
{
4121
4058
        ut_ad(node && system && space);
4122
4059
        ut_ad(mutex_own(&(system->mutex)));
4149
4086
        node->n_pending++;
4150
4087
}
4151
4088
 
4152
 
/************************************************************************
 
4089
/********************************************************************//**
4153
4090
Updates the data structures when an i/o operation finishes. Updates the
4154
4091
pending i/o's field in the node appropriately. */
4155
4092
static
4156
4093
void
4157
4094
fil_node_complete_io(
4158
4095
/*=================*/
4159
 
        fil_node_t*     node,   /* in: file node */
4160
 
        fil_system_t*   system, /* in: tablespace memory cache */
4161
 
        ulint           type)   /* in: OS_FILE_WRITE or OS_FILE_READ; marks
 
4096
        fil_node_t*     node,   /*!< in: file node */
 
4097
        fil_system_t*   system, /*!< in: tablespace memory cache */
 
4098
        ulint           type)   /*!< in: OS_FILE_WRITE or OS_FILE_READ; marks
4162
4099
                                the node as modified if
4163
4100
                                type == OS_FILE_WRITE */
4164
4101
{
4190
4127
        }
4191
4128
}
4192
4129
 
4193
 
/************************************************************************
 
4130
/********************************************************************//**
4194
4131
Report information about an invalid page access. */
4195
4132
static
4196
4133
void
4197
4134
fil_report_invalid_page_access(
4198
4135
/*===========================*/
4199
 
        ulint           block_offset,   /* in: block offset */
4200
 
        ulint           space_id,       /* in: space id */
4201
 
        const char*     space_name,     /* in: space name */
4202
 
        ulint           byte_offset,    /* in: byte offset */
4203
 
        ulint           len,            /* in: I/O length */
4204
 
        ulint           type)           /* in: I/O type */
 
4136
        ulint           block_offset,   /*!< in: block offset */
 
4137
        ulint           space_id,       /*!< in: space id */
 
4138
        const char*     space_name,     /*!< in: space name */
 
4139
        ulint           byte_offset,    /*!< in: byte offset */
 
4140
        ulint           len,            /*!< in: I/O length */
 
4141
        ulint           type)           /*!< in: I/O type */
4205
4142
{
4206
4143
        fprintf(stderr,
4207
4144
                "InnoDB: Error: trying to access page number %lu"
4218
4155
                (ulong) byte_offset, (ulong) len, (ulong) type);
4219
4156
}
4220
4157
 
4221
 
/************************************************************************
4222
 
Reads or writes data. This operation is asynchronous (aio). */
 
4158
/********************************************************************//**
 
4159
Reads or writes data. This operation is asynchronous (aio).
 
4160
@return DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do
 
4161
i/o on a tablespace which does not exist */
4223
4162
UNIV_INTERN
4224
4163
ulint
4225
4164
fil_io(
4226
4165
/*===*/
4227
 
                                /* out: DB_SUCCESS, or DB_TABLESPACE_DELETED
4228
 
                                if we are trying to do i/o on a tablespace
4229
 
                                which does not exist */
4230
 
        ulint   type,           /* in: OS_FILE_READ or OS_FILE_WRITE,
 
4166
        ulint   type,           /*!< in: OS_FILE_READ or OS_FILE_WRITE,
4231
4167
                                ORed to OS_FILE_LOG, if a log i/o
4232
4168
                                and ORed to OS_AIO_SIMULATED_WAKE_LATER
4233
4169
                                if simulated aio and we want to post a
4236
4172
                                because i/os are not actually handled until
4237
4173
                                all have been posted: use with great
4238
4174
                                caution! */
4239
 
        ibool   sync,           /* in: TRUE if synchronous aio is desired */
4240
 
        ulint   space_id,       /* in: space id */
4241
 
        ulint   zip_size,       /* in: compressed page size in bytes;
 
4175
        ibool   sync,           /*!< in: TRUE if synchronous aio is desired */
 
4176
        ulint   space_id,       /*!< in: space id */
 
4177
        ulint   zip_size,       /*!< in: compressed page size in bytes;
4242
4178
                                0 for uncompressed pages */
4243
 
        ulint   block_offset,   /* in: offset in number of blocks */
4244
 
        ulint   byte_offset,    /* in: remainder of offset in bytes; in
 
4179
        ulint   block_offset,   /*!< in: offset in number of blocks */
 
4180
        ulint   byte_offset,    /*!< in: remainder of offset in bytes; in
4245
4181
                                aio this must be divisible by the OS block
4246
4182
                                size */
4247
 
        ulint   len,            /* in: how many bytes to read or write; this
 
4183
        ulint   len,            /*!< in: how many bytes to read or write; this
4248
4184
                                must not cross a file boundary; in aio this
4249
4185
                                must be a block size multiple */
4250
 
        void*   buf,            /* in/out: buffer where to store read data
 
4186
        void*   buf,            /*!< in/out: buffer where to store read data
4251
4187
                                or from where to write; in aio this must be
4252
4188
                                appropriately aligned */
4253
 
        void*   message)        /* in: message for aio handler if non-sync
 
4189
        void*   message)        /*!< in: message for aio handler if non-sync
4254
4190
                                aio used, else ignored */
4255
4191
{
4256
 
        fil_system_t*   system          = fil_system;
4257
4192
        ulint           mode;
4258
4193
        fil_space_t*    space;
4259
4194
        fil_node_t*     node;
4278
4213
# error "(1 << UNIV_PAGE_SIZE_SHIFT) != UNIV_PAGE_SIZE"
4279
4214
#endif
4280
4215
        ut_ad(fil_validate());
4281
 
#ifndef UNIV_LOG_DEBUG
 
4216
#ifndef UNIV_HOTBACKUP
 
4217
# ifndef UNIV_LOG_DEBUG
4282
4218
        /* ibuf bitmap pages must be read in the sync aio mode: */
4283
4219
        ut_ad(recv_no_ibuf_operations || (type == OS_FILE_WRITE)
4284
4220
              || !ibuf_bitmap_page(zip_size, block_offset)
4285
4221
              || sync || is_log);
4286
4222
        ut_ad(!ibuf_inside() || is_log || (type == OS_FILE_WRITE)
4287
4223
              || ibuf_page(space_id, zip_size, block_offset, NULL));
4288
 
#endif
 
4224
# endif /* UNIV_LOG_DEBUG */
4289
4225
        if (sync) {
4290
4226
                mode = OS_AIO_SYNC;
4291
4227
        } else if (is_log) {
4297
4233
        } else {
4298
4234
                mode = OS_AIO_NORMAL;
4299
4235
        }
 
4236
#else /* !UNIV_HOTBACKUP */
 
4237
        ut_a(sync);
 
4238
        mode = OS_AIO_SYNC;
 
4239
#endif /* !UNIV_HOTBACKUP */
4300
4240
 
4301
4241
        if (type == OS_FILE_READ) {
4302
4242
                srv_data_read+= len;
4312
4252
        space = fil_space_get_by_id(space_id);
4313
4253
 
4314
4254
        if (!space) {
4315
 
                mutex_exit(&(system->mutex));
 
4255
                mutex_exit(&fil_system->mutex);
4316
4256
 
4317
4257
                ut_print_timestamp(stderr);
4318
4258
                fprintf(stderr,
4356
4296
        }
4357
4297
 
4358
4298
        /* Open file if closed */
4359
 
        fil_node_prepare_for_io(node, system, space);
 
4299
        fil_node_prepare_for_io(node, fil_system, space);
4360
4300
 
4361
4301
        /* Check that at least the start offset is within the bounds of a
4362
4302
        single-table tablespace */
4370
4310
                ut_error;
4371
4311
        }
4372
4312
 
4373
 
        /* Now we have made the changes in the data structures of system */
4374
 
        mutex_exit(&(system->mutex));
 
4313
        /* Now we have made the changes in the data structures of fil_system */
 
4314
        mutex_exit(&fil_system->mutex);
4375
4315
 
4376
4316
        /* Calculate the low 32 bits and the high 32 bits of the file offset */
4377
4317
 
4425
4365
                /* The i/o operation is already completed when we return from
4426
4366
                os_aio: */
4427
4367
 
4428
 
                mutex_enter(&(system->mutex));
4429
 
 
4430
 
                fil_node_complete_io(node, system, type);
4431
 
 
4432
 
                mutex_exit(&(system->mutex));
 
4368
                mutex_enter(&fil_system->mutex);
 
4369
 
 
4370
                fil_node_complete_io(node, fil_system, type);
 
4371
 
 
4372
                mutex_exit(&fil_system->mutex);
4433
4373
 
4434
4374
                ut_ad(fil_validate());
4435
4375
        }
4437
4377
        return(DB_SUCCESS);
4438
4378
}
4439
4379
 
4440
 
/**************************************************************************
 
4380
#ifndef UNIV_HOTBACKUP
 
4381
/**********************************************************************//**
4441
4382
Waits for an aio operation to complete. This function is used to write the
4442
4383
handler for completed requests. The aio array of pending requests is divided
4443
4384
into segments (see os0file.c for more info). The thread specifies which
4446
4387
void
4447
4388
fil_aio_wait(
4448
4389
/*=========*/
4449
 
        ulint   segment)        /* in: the number of the segment in the aio
 
4390
        ulint   segment)        /*!< in: the number of the segment in the aio
4450
4391
                                array to wait for */
4451
4392
{
4452
 
        fil_system_t*   system          = fil_system;
4453
4393
        ibool           ret;
4454
4394
        fil_node_t*     fil_node;
4455
4395
        void*           message;
4477
4417
 
4478
4418
        srv_set_io_thread_op_info(segment, "complete io for fil node");
4479
4419
 
4480
 
        mutex_enter(&(system->mutex));
 
4420
        mutex_enter(&fil_system->mutex);
4481
4421
 
4482
4422
        fil_node_complete_io(fil_node, fil_system, type);
4483
4423
 
4484
 
        mutex_exit(&(system->mutex));
 
4424
        mutex_exit(&fil_system->mutex);
4485
4425
 
4486
4426
        ut_ad(fil_validate());
4487
4427
 
4499
4439
                log_io_complete(message);
4500
4440
        }
4501
4441
}
 
4442
#endif /* UNIV_HOTBACKUP */
4502
4443
 
4503
 
/**************************************************************************
 
4444
/**********************************************************************//**
4504
4445
Flushes to disk possible writes cached by the OS. If the space does not exist
4505
4446
or is being dropped, does not do anything. */
4506
4447
UNIV_INTERN
4507
4448
void
4508
4449
fil_flush(
4509
4450
/*======*/
4510
 
        ulint   space_id)       /* in: file space id (this can be a group of
 
4451
        ulint   space_id)       /*!< in: file space id (this can be a group of
4511
4452
                                log files or a tablespace of the database) */
4512
4453
{
4513
 
        fil_system_t*   system  = fil_system;
4514
4454
        fil_space_t*    space;
4515
4455
        fil_node_t*     node;
4516
4456
        os_file_t       file;
4517
4457
        ib_int64_t      old_mod_counter;
4518
4458
 
4519
 
        mutex_enter(&(system->mutex));
 
4459
        mutex_enter(&fil_system->mutex);
4520
4460
 
4521
4461
        space = fil_space_get_by_id(space_id);
4522
4462
 
4523
4463
        if (!space || space->is_being_deleted) {
4524
 
                mutex_exit(&(system->mutex));
 
4464
                mutex_exit(&fil_system->mutex);
4525
4465
 
4526
4466
                return;
4527
4467
        }
4528
4468
 
4529
 
        space->n_pending_flushes++;     /* prevent dropping of the space while
 
4469
        space->n_pending_flushes++;     /*!< prevent dropping of the space while
4530
4470
                                        we are flushing */
4531
4471
        node = UT_LIST_GET_FIRST(space->chain);
4532
4472
 
4557
4497
                                not know what bugs OS's may contain in file
4558
4498
                                i/o; sleep for a while */
4559
4499
 
4560
 
                                mutex_exit(&(system->mutex));
 
4500
                                mutex_exit(&fil_system->mutex);
4561
4501
 
4562
4502
                                os_thread_sleep(20000);
4563
4503
 
4564
 
                                mutex_enter(&(system->mutex));
 
4504
                                mutex_enter(&fil_system->mutex);
4565
4505
 
4566
4506
                                if (node->flush_counter >= old_mod_counter) {
4567
4507
 
4575
4515
                        file = node->handle;
4576
4516
                        node->n_pending_flushes++;
4577
4517
 
4578
 
                        mutex_exit(&(system->mutex));
 
4518
                        mutex_exit(&fil_system->mutex);
4579
4519
 
4580
4520
                        /* fprintf(stderr, "Flushing to file %s\n",
4581
4521
                        node->name); */
4582
4522
 
4583
4523
                        os_file_flush(file);
4584
4524
 
4585
 
                        mutex_enter(&(system->mutex));
 
4525
                        mutex_enter(&fil_system->mutex);
4586
4526
 
4587
4527
                        node->n_pending_flushes--;
4588
4528
skip_flush:
4596
4536
 
4597
4537
                                        UT_LIST_REMOVE(
4598
4538
                                                unflushed_spaces,
4599
 
                                                system->unflushed_spaces,
 
4539
                                                fil_system->unflushed_spaces,
4600
4540
                                                space);
4601
4541
                                }
4602
4542
                        }
4613
4553
 
4614
4554
        space->n_pending_flushes--;
4615
4555
 
4616
 
        mutex_exit(&(system->mutex));
 
4556
        mutex_exit(&fil_system->mutex);
4617
4557
}
4618
4558
 
4619
 
/**************************************************************************
 
4559
/**********************************************************************//**
4620
4560
Flushes to disk the writes in file spaces of the given type possibly cached by
4621
4561
the OS. */
4622
4562
UNIV_INTERN
4623
4563
void
4624
4564
fil_flush_file_spaces(
4625
4565
/*==================*/
4626
 
        ulint   purpose)        /* in: FIL_TABLESPACE, FIL_LOG */
 
4566
        ulint   purpose)        /*!< in: FIL_TABLESPACE, FIL_LOG */
4627
4567
{
4628
 
        fil_system_t*   system  = fil_system;
4629
4568
        fil_space_t*    space;
4630
4569
        ulint*          space_ids;
4631
4570
        ulint           n_space_ids;
4632
4571
        ulint           i;
4633
4572
 
4634
 
        mutex_enter(&(system->mutex));
 
4573
        mutex_enter(&fil_system->mutex);
4635
4574
 
4636
 
        n_space_ids = UT_LIST_GET_LEN(system->unflushed_spaces);
 
4575
        n_space_ids = UT_LIST_GET_LEN(fil_system->unflushed_spaces);
4637
4576
        if (n_space_ids == 0) {
4638
4577
 
4639
 
                mutex_exit(&system->mutex);
 
4578
                mutex_exit(&fil_system->mutex);
4640
4579
                return;
4641
4580
        }
4642
4581
 
4643
4582
        /* Assemble a list of space ids to flush.  Previously, we
4644
 
        traversed system->unflushed_spaces and called UT_LIST_GET_NEXT()
 
4583
        traversed fil_system->unflushed_spaces and called UT_LIST_GET_NEXT()
4645
4584
        on a space that was just removed from the list by fil_flush().
4646
4585
        Thus, the space could be dropped and the memory overwritten. */
4647
4586
        space_ids = mem_alloc(n_space_ids * sizeof *space_ids);
4648
4587
 
4649
4588
        n_space_ids = 0;
4650
4589
 
4651
 
        for (space = UT_LIST_GET_FIRST(system->unflushed_spaces);
 
4590
        for (space = UT_LIST_GET_FIRST(fil_system->unflushed_spaces);
4652
4591
             space;
4653
4592
             space = UT_LIST_GET_NEXT(unflushed_spaces, space)) {
4654
4593
 
4658
4597
                }
4659
4598
        }
4660
4599
 
4661
 
        mutex_exit(&system->mutex);
 
4600
        mutex_exit(&fil_system->mutex);
4662
4601
 
4663
4602
        /* Flush the spaces.  It will not hurt to call fil_flush() on
4664
4603
        a non-existing space id. */
4670
4609
        mem_free(space_ids);
4671
4610
}
4672
4611
 
4673
 
/**********************************************************************
4674
 
Checks the consistency of the tablespace cache. */
 
4612
/******************************************************************//**
 
4613
Checks the consistency of the tablespace cache.
 
4614
@return TRUE if ok */
4675
4615
UNIV_INTERN
4676
4616
ibool
4677
4617
fil_validate(void)
4678
4618
/*==============*/
4679
 
                        /* out: TRUE if ok */
4680
4619
{
4681
 
        fil_system_t*   system          = fil_system;
4682
4620
        fil_space_t*    space;
4683
4621
        fil_node_t*     fil_node;
4684
4622
        ulint           n_open          = 0;
4685
4623
        ulint           i;
4686
4624
 
4687
 
        mutex_enter(&(system->mutex));
 
4625
        mutex_enter(&fil_system->mutex);
4688
4626
 
4689
4627
        /* Look for spaces in the hash table */
4690
4628
 
4691
 
        for (i = 0; i < hash_get_n_cells(system->spaces); i++) {
 
4629
        for (i = 0; i < hash_get_n_cells(fil_system->spaces); i++) {
4692
4630
 
4693
 
                space = HASH_GET_FIRST(system->spaces, i);
 
4631
                space = HASH_GET_FIRST(fil_system->spaces, i);
4694
4632
 
4695
4633
                while (space != NULL) {
4696
 
                        UT_LIST_VALIDATE(chain, fil_node_t, space->chain);
 
4634
                        UT_LIST_VALIDATE(chain, fil_node_t, space->chain,
 
4635
                                         ut_a(ut_list_node_313->open
 
4636
                                              || !ut_list_node_313->n_pending));
4697
4637
 
4698
4638
                        fil_node = UT_LIST_GET_FIRST(space->chain);
4699
4639
 
4711
4651
                }
4712
4652
        }
4713
4653
 
4714
 
        ut_a(system->n_open == n_open);
4715
 
 
4716
 
        UT_LIST_VALIDATE(LRU, fil_node_t, system->LRU);
4717
 
 
4718
 
        fil_node = UT_LIST_GET_FIRST(system->LRU);
 
4654
        ut_a(fil_system->n_open == n_open);
 
4655
 
 
4656
        UT_LIST_VALIDATE(LRU, fil_node_t, fil_system->LRU, (void) 0);
 
4657
 
 
4658
        fil_node = UT_LIST_GET_FIRST(fil_system->LRU);
4719
4659
 
4720
4660
        while (fil_node != NULL) {
4721
4661
                ut_a(fil_node->n_pending == 0);
4726
4666
                fil_node = UT_LIST_GET_NEXT(LRU, fil_node);
4727
4667
        }
4728
4668
 
4729
 
        mutex_exit(&(system->mutex));
 
4669
        mutex_exit(&fil_system->mutex);
4730
4670
 
4731
4671
        return(TRUE);
4732
4672
}
4733
4673
 
4734
 
/************************************************************************
4735
 
Returns TRUE if file address is undefined. */
 
4674
/********************************************************************//**
 
4675
Returns TRUE if file address is undefined.
 
4676
@return TRUE if undefined */
4736
4677
UNIV_INTERN
4737
4678
ibool
4738
4679
fil_addr_is_null(
4739
4680
/*=============*/
4740
 
                                /* out: TRUE if undefined */
4741
 
        fil_addr_t      addr)   /* in: address */
 
4681
        fil_addr_t      addr)   /*!< in: address */
4742
4682
{
4743
4683
        return(addr.page == FIL_NULL);
4744
4684
}
4745
4685
 
4746
 
/************************************************************************
4747
 
Accessor functions for a file page */
 
4686
/********************************************************************//**
 
4687
Get the predecessor of a file page.
 
4688
@return FIL_PAGE_PREV */
4748
4689
UNIV_INTERN
4749
4690
ulint
4750
 
fil_page_get_prev(const byte*   page)
 
4691
fil_page_get_prev(
 
4692
/*==============*/
 
4693
        const byte*     page)   /*!< in: file page */
4751
4694
{
4752
4695
        return(mach_read_from_4(page + FIL_PAGE_PREV));
4753
4696
}
4754
4697
 
 
4698
/********************************************************************//**
 
4699
Get the successor of a file page.
 
4700
@return FIL_PAGE_NEXT */
4755
4701
UNIV_INTERN
4756
4702
ulint
4757
 
fil_page_get_next(const byte*   page)
 
4703
fil_page_get_next(
 
4704
/*==============*/
 
4705
        const byte*     page)   /*!< in: file page */
4758
4706
{
4759
4707
        return(mach_read_from_4(page + FIL_PAGE_NEXT));
4760
4708
}
4761
4709
 
4762
 
/*************************************************************************
 
4710
/*********************************************************************//**
4763
4711
Sets the file page type. */
4764
4712
UNIV_INTERN
4765
4713
void
4766
4714
fil_page_set_type(
4767
4715
/*==============*/
4768
 
        byte*   page,   /* in: file page */
4769
 
        ulint   type)   /* in: type */
 
4716
        byte*   page,   /*!< in/out: file page */
 
4717
        ulint   type)   /*!< in: type */
4770
4718
{
4771
4719
        ut_ad(page);
4772
4720
 
4773
4721
        mach_write_to_2(page + FIL_PAGE_TYPE, type);
4774
4722
}
4775
4723
 
4776
 
/*************************************************************************
4777
 
Gets the file page type. */
 
4724
/*********************************************************************//**
 
4725
Gets the file page type.
 
4726
@return type; NOTE that if the type has not been written to page, the
 
4727
return value not defined */
4778
4728
UNIV_INTERN
4779
4729
ulint
4780
4730
fil_page_get_type(
4781
4731
/*==============*/
4782
 
                                /* out: type; NOTE that if the type
4783
 
                                has not been written to page, the return value
4784
 
                                not defined */
4785
 
        const byte*     page)   /* in: file page */
 
4732
        const byte*     page)   /*!< in: file page */
4786
4733
{
4787
4734
        ut_ad(page);
4788
4735