~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/srv/srv0start.c

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
4
 
Copyright (c) 2008, Google Inc.
5
 
Copyright (c) 2009, Percona Inc.
6
 
 
7
 
Portions of this file contain modifications contributed and copyrighted by
8
 
Google, Inc. Those modifications are gratefully acknowledged and are described
9
 
briefly in the InnoDB documentation. The contributions by Google are
10
 
incorporated with their permission, and subject to the conditions contained in
11
 
the file COPYING.Google.
12
 
 
13
 
Portions of this file contain modifications contributed and copyrighted
14
 
by Percona Inc.. Those modifications are
15
 
gratefully acknowledged and are described briefly in the InnoDB
16
 
documentation. The contributions by Percona Inc. are incorporated with
17
 
their permission, and subject to the conditions contained in the file
18
 
COPYING.Percona.
19
 
 
20
 
This program is free software; you can redistribute it and/or modify it under
21
 
the terms of the GNU General Public License as published by the Free Software
22
 
Foundation; version 2 of the License.
23
 
 
24
 
This program is distributed in the hope that it will be useful, but WITHOUT
25
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
26
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
27
 
 
28
 
You should have received a copy of the GNU General Public License along with
29
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
30
 
St, Fifth Floor, Boston, MA 02110-1301 USA
31
 
 
32
 
*****************************************************************************/
33
 
 
34
 
/********************************************************************//**
35
 
@file srv/srv0start.c
 
1
/************************************************************************
36
2
Starts the InnoDB database server
37
3
 
 
4
(c) 1996-2000 Innobase Oy
 
5
 
38
6
Created 2/16/1996 Heikki Tuuri
39
7
*************************************************************************/
40
8
 
 
9
#include "os0proc.h"
 
10
#include "sync0sync.h"
41
11
#include "ut0mem.h"
42
12
#include "mem0mem.h"
 
13
#include "mem0pool.h"
43
14
#include "data0data.h"
44
15
#include "data0type.h"
45
16
#include "dict0dict.h"
46
17
#include "buf0buf.h"
 
18
#include "buf0flu.h"
 
19
#include "buf0rea.h"
47
20
#include "os0file.h"
48
21
#include "os0thread.h"
49
22
#include "fil0fil.h"
50
23
#include "fsp0fsp.h"
51
24
#include "rem0rec.h"
 
25
#include "rem0cmp.h"
52
26
#include "mtr0mtr.h"
53
27
#include "log0log.h"
54
28
#include "log0recv.h"
55
29
#include "page0page.h"
56
30
#include "page0cur.h"
57
31
#include "trx0trx.h"
 
32
#include "dict0boot.h"
 
33
#include "dict0load.h"
58
34
#include "trx0sys.h"
 
35
#include "dict0crea.h"
59
36
#include "btr0btr.h"
 
37
#include "btr0pcur.h"
60
38
#include "btr0cur.h"
 
39
#include "btr0sea.h"
61
40
#include "rem0rec.h"
 
41
#include "srv0srv.h"
 
42
#include "que0que.h"
 
43
#include "usr0sess.h"
 
44
#include "lock0lock.h"
 
45
#include "trx0roll.h"
 
46
#include "trx0purge.h"
 
47
#include "row0ins.h"
 
48
#include "row0sel.h"
 
49
#include "row0upd.h"
 
50
#include "row0row.h"
 
51
#include "row0mysql.h"
 
52
#include "lock0lock.h"
62
53
#include "ibuf0ibuf.h"
 
54
#include "pars0pars.h"
 
55
#include "btr0sea.h"
63
56
#include "srv0start.h"
64
 
#include "srv0srv.h"
65
 
#ifndef UNIV_HOTBACKUP
66
 
# include "os0proc.h"
67
 
# include "sync0sync.h"
68
 
# include "buf0flu.h"
69
 
# include "buf0rea.h"
70
 
# include "dict0boot.h"
71
 
# include "dict0load.h"
72
 
# include "que0que.h"
73
 
# include "usr0sess.h"
74
 
# include "lock0lock.h"
75
 
# include "trx0roll.h"
76
 
# include "trx0purge.h"
77
 
# include "lock0lock.h"
78
 
# include "pars0pars.h"
79
 
# include "btr0sea.h"
80
 
# include "rem0cmp.h"
81
 
# include "dict0crea.h"
82
 
# include "row0ins.h"
83
 
# include "row0sel.h"
84
 
# include "row0upd.h"
85
 
# include "row0row.h"
86
 
# include "row0mysql.h"
87
 
# include "btr0pcur.h"
88
 
# include "thr0loc.h"
89
 
# include "os0sync.h" /* for INNODB_RW_LOCKS_USE_ATOMICS */
90
 
# include "zlib.h" /* for ZLIB_VERSION */
91
 
 
92
 
#include <errno.h>
93
 
#include <unistd.h>
94
 
 
95
 
/** Log sequence number immediately after startup */
 
57
#include "que0que.h"
 
58
 
 
59
/* Log sequence number immediately after startup */
96
60
UNIV_INTERN ib_uint64_t srv_start_lsn;
97
 
/** Log sequence number at shutdown */
 
61
/* Log sequence number at shutdown */
98
62
UNIV_INTERN ib_uint64_t srv_shutdown_lsn;
99
63
 
100
64
#ifdef HAVE_DARWIN_THREADS
101
65
# include <sys/utsname.h>
102
 
/** TRUE if the F_FULLFSYNC option is available */
103
66
UNIV_INTERN ibool       srv_have_fullfsync = FALSE;
104
67
#endif
105
68
 
106
 
/** TRUE if a raw partition is in use */
107
69
UNIV_INTERN ibool       srv_start_raw_disk_in_use = FALSE;
108
70
 
109
 
/** TRUE if the server is being started, before rolling back any
110
 
incomplete transactions */
111
71
UNIV_INTERN ibool       srv_startup_is_before_trx_rollback_phase = FALSE;
112
 
/** TRUE if the server is being started */
113
72
UNIV_INTERN ibool       srv_is_being_started = FALSE;
114
 
/** TRUE if the server was successfully started */
115
73
UNIV_INTERN ibool       srv_was_started = FALSE;
116
 
/** TRUE if innobase_start_or_create_for_mysql() has been called */
 
74
#ifndef UNIV_HOTBACKUP
117
75
static ibool    srv_start_has_been_called = FALSE;
118
 
 
119
 
/** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
120
 
SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
121
 
UNIV_INTERN enum srv_shutdown_state     srv_shutdown_state = SRV_SHUTDOWN_NONE;
122
 
 
123
 
/** Files comprising the system tablespace */
 
76
#endif /* !UNIV_HOTBACKUP */
 
77
 
 
78
/* At a shutdown the value first climbs to SRV_SHUTDOWN_CLEANUP
 
79
and then to SRV_SHUTDOWN_LAST_PHASE */
 
80
UNIV_INTERN ulint               srv_shutdown_state = 0;
 
81
 
 
82
#ifndef UNIV_HOTBACKUP
124
83
static os_file_t        files[1000];
125
84
 
126
 
/** Mutex protecting the ios count */
127
85
static mutex_t          ios_mutex;
128
 
/** Count of I/O operations in io_handler_thread() */
129
86
static ulint            ios;
130
87
 
131
 
/** io_handler_thread parameters for thread identification */
132
 
static ulint            n[SRV_MAX_N_IO_THREADS + 6];
133
 
/** io_handler_thread identifiers */
134
 
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 6];
 
88
static ulint            n[SRV_MAX_N_IO_THREADS + 5];
 
89
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 5];
135
90
 
136
 
/** We use this mutex to test the return value of pthread_mutex_trylock
 
91
/* We use this mutex to test the return value of pthread_mutex_trylock
137
92
   on successful locking. HP-UX does NOT return 0, though Linux et al do. */
138
93
static os_fast_mutex_t  srv_os_test_mutex;
139
94
 
140
 
/** Name of srv_monitor_file */
 
95
/* Name of srv_monitor_file */
141
96
static char*    srv_monitor_file_name;
142
97
#endif /* !UNIV_HOTBACKUP */
143
98
 
144
 
/** */
145
99
#define SRV_N_PENDING_IOS_PER_THREAD    OS_AIO_N_PENDING_IOS_PER_THREAD
146
100
#define SRV_MAX_N_PENDING_SYNC_IOS      100
147
101
 
148
 
#ifdef UNIV_PFS_THREAD
149
 
/* Keys to register InnoDB threads with performance schema */
150
 
UNIV_INTERN mysql_pfs_key_t     io_handler_thread_key;
151
 
UNIV_INTERN mysql_pfs_key_t     srv_lock_timeout_thread_key;
152
 
UNIV_INTERN mysql_pfs_key_t     srv_error_monitor_thread_key;
153
 
UNIV_INTERN mysql_pfs_key_t     srv_monitor_thread_key;
154
 
UNIV_INTERN mysql_pfs_key_t     srv_master_thread_key;
155
 
#endif /* UNIV_PFS_THREAD */
156
 
 
157
 
#ifdef UNIV_PFS_MUTEX
158
 
/* Key to register ios_mutex_key with performance schema */
159
 
UNIV_INTERN mysql_pfs_key_t     ios_mutex_key;
160
 
#endif /* UNIV_PFS_MUTEX */
161
 
 
162
 
/*********************************************************************//**
163
 
Convert a numeric string that optionally ends in G or M, to a number
164
 
containing megabytes.
165
 
@return next character in string */
 
102
 
166
103
static
167
104
char*
168
105
srv_parse_megabytes(
169
106
/*================*/
170
 
        char*   str,    /*!< in: string containing a quantity in bytes */
171
 
        ulint*  megs)   /*!< out: the number in megabytes */
 
107
                        /* out: next character in string */
 
108
        char*   str,    /* in: string containing a quantity in bytes */
 
109
        ulint*  megs)   /* out: the number in megabytes */
172
110
{
173
111
        char*   endp;
174
112
        ulint   size;
193
131
        return(str);
194
132
}
195
133
 
196
 
/*********************************************************************//**
 
134
/*************************************************************************
197
135
Reads the data files and their sizes from a character string given in
198
 
the .cnf file.
199
 
@return TRUE if ok, FALSE on parse error */
 
136
the .cnf file. */
200
137
UNIV_INTERN
201
138
ibool
202
139
srv_parse_data_file_paths_and_sizes(
203
140
/*================================*/
204
 
        char*   str)    /*!< in/out: the data file path string */
 
141
                                        /* out: TRUE if ok, FALSE if parsing
 
142
                                        error */
 
143
        char*   str,                    /* in: the data file path string */
 
144
        char*** data_file_names,        /* out, own: array of data file
 
145
                                        names */
 
146
        ulint** data_file_sizes,        /* out, own: array of data file sizes
 
147
                                        in megabytes */
 
148
        ulint** data_file_is_raw_partition,/* out, own: array of flags
 
149
                                        showing which data files are raw
 
150
                                        partitions */
 
151
        ulint*  n_data_files,           /* out: number of data files */
 
152
        ibool*  is_auto_extending,      /* out: TRUE if the last data file is
 
153
                                        auto-extending */
 
154
        ulint*  max_auto_extend_size)   /* out: max auto extend size for the
 
155
                                        last file if specified, 0 if not */
205
156
{
206
157
        char*   input_str;
207
158
        char*   path;
208
159
        ulint   size;
209
160
        ulint   i       = 0;
210
161
 
211
 
        srv_auto_extend_last_data_file = FALSE;
212
 
        srv_last_file_size_max = 0;
213
 
        srv_data_file_names = NULL;
214
 
        srv_data_file_sizes = NULL;
215
 
        srv_data_file_is_raw_partition = NULL;
 
162
        *is_auto_extending = FALSE;
 
163
        *max_auto_extend_size = 0;
216
164
 
217
165
        input_str = str;
218
166
 
289
237
                return(FALSE);
290
238
        }
291
239
 
292
 
        srv_data_file_names = malloc(i * sizeof *srv_data_file_names);
293
 
        srv_data_file_sizes = malloc(i * sizeof *srv_data_file_sizes);
294
 
        srv_data_file_is_raw_partition = malloc(
295
 
                i * sizeof *srv_data_file_is_raw_partition);
 
240
        *data_file_names = (char**)ut_malloc(i * sizeof(void*));
 
241
        *data_file_sizes = (ulint*)ut_malloc(i * sizeof(ulint));
 
242
        *data_file_is_raw_partition = (ulint*)ut_malloc(i * sizeof(ulint));
296
243
 
297
 
        srv_n_data_files = i;
 
244
        *n_data_files = i;
298
245
 
299
246
        /* Then store the actual values to our arrays */
300
247
 
324
271
 
325
272
                str = srv_parse_megabytes(str, &size);
326
273
 
327
 
                srv_data_file_names[i] = path;
328
 
                srv_data_file_sizes[i] = size;
 
274
                (*data_file_names)[i] = path;
 
275
                (*data_file_sizes)[i] = size;
329
276
 
330
277
                if (0 == strncmp(str, ":autoextend",
331
278
                                 (sizeof ":autoextend") - 1)) {
332
279
 
333
 
                        srv_auto_extend_last_data_file = TRUE;
 
280
                        *is_auto_extending = TRUE;
334
281
 
335
282
                        str += (sizeof ":autoextend") - 1;
336
283
 
340
287
                                str += (sizeof ":max:") - 1;
341
288
 
342
289
                                str = srv_parse_megabytes(
343
 
                                        str, &srv_last_file_size_max);
 
290
                                        str, max_auto_extend_size);
344
291
                        }
345
292
 
346
293
                        if (*str != '\0') {
349
296
                        }
350
297
                }
351
298
 
352
 
                (srv_data_file_is_raw_partition)[i] = 0;
 
299
                (*data_file_is_raw_partition)[i] = 0;
353
300
 
354
301
                if (strlen(str) >= 6
355
302
                    && *str == 'n'
356
303
                    && *(str + 1) == 'e'
357
304
                    && *(str + 2) == 'w') {
358
305
                        str += 3;
359
 
                        (srv_data_file_is_raw_partition)[i] = SRV_NEW_RAW;
 
306
                        (*data_file_is_raw_partition)[i] = SRV_NEW_RAW;
360
307
                }
361
308
 
362
309
                if (*str == 'r' && *(str + 1) == 'a' && *(str + 2) == 'w') {
363
310
                        str += 3;
364
311
 
365
 
                        if ((srv_data_file_is_raw_partition)[i] == 0) {
366
 
                                (srv_data_file_is_raw_partition)[i] = SRV_OLD_RAW;
 
312
                        if ((*data_file_is_raw_partition)[i] == 0) {
 
313
                                (*data_file_is_raw_partition)[i] = SRV_OLD_RAW;
367
314
                        }
368
315
                }
369
316
 
377
324
        return(TRUE);
378
325
}
379
326
 
380
 
/*********************************************************************//**
 
327
/*************************************************************************
381
328
Reads log group home directories from a character string given in
382
 
the .cnf file.
383
 
@return TRUE if ok, FALSE on parse error */
 
329
the .cnf file. */
384
330
UNIV_INTERN
385
331
ibool
386
332
srv_parse_log_group_home_dirs(
387
333
/*==========================*/
388
 
        char*   str)    /*!< in/out: character string */
 
334
                                        /* out: TRUE if ok, FALSE if parsing
 
335
                                        error */
 
336
        char*   str,                    /* in: character string */
 
337
        char*** log_group_home_dirs)    /* out, own: log group home dirs */
389
338
{
390
339
        char*   input_str;
391
340
        char*   path;
392
341
        ulint   i       = 0;
393
342
 
394
 
        srv_log_group_home_dirs = NULL;
395
 
 
396
343
        input_str = str;
397
344
 
398
345
        /* First calculate the number of directories and check syntax:
422
369
                return(FALSE);
423
370
        }
424
371
 
425
 
        srv_log_group_home_dirs = malloc(i * sizeof *srv_log_group_home_dirs);
 
372
        *log_group_home_dirs = (char**) ut_malloc(i * sizeof(void*));
426
373
 
427
374
        /* Then store the actual values to our array */
428
375
 
441
388
                        str++;
442
389
                }
443
390
 
444
 
                srv_log_group_home_dirs[i] = path;
 
391
                (*log_group_home_dirs)[i] = path;
445
392
 
446
393
                i++;
447
394
        }
449
396
        return(TRUE);
450
397
}
451
398
 
452
 
/*********************************************************************//**
453
 
Frees the memory allocated by srv_parse_data_file_paths_and_sizes()
454
 
and srv_parse_log_group_home_dirs(). */
455
 
UNIV_INTERN
456
 
void
457
 
srv_free_paths_and_sizes(void)
458
 
/*==========================*/
459
 
{
460
 
        free(srv_data_file_names);
461
 
        srv_data_file_names = NULL;
462
 
        free(srv_data_file_sizes);
463
 
        srv_data_file_sizes = NULL;
464
 
        free(srv_data_file_is_raw_partition);
465
 
        srv_data_file_is_raw_partition = NULL;
466
 
        free(srv_log_group_home_dirs);
467
 
        srv_log_group_home_dirs = NULL;
468
 
}
469
 
 
470
399
#ifndef UNIV_HOTBACKUP
471
 
/********************************************************************//**
472
 
I/o-handler thread function.
473
 
@return OS_THREAD_DUMMY_RETURN */
 
400
/************************************************************************
 
401
I/o-handler thread function. */
474
402
static
 
403
 
475
404
os_thread_ret_t
476
405
io_handler_thread(
477
406
/*==============*/
478
 
        void*   arg)    /*!< in: pointer to the number of the segment in
479
 
                        the aio array */
 
407
        void*   arg)
480
408
{
481
409
        ulint   segment;
 
410
        ulint   i;
482
411
 
483
412
        segment = *((ulint*)arg);
484
413
 
486
415
        fprintf(stderr, "Io handler thread %lu starts, id %lu\n", segment,
487
416
                os_thread_pf(os_thread_get_curr_id()));
488
417
#endif
489
 
 
490
 
#ifdef UNIV_PFS_THREAD
491
 
        pfs_register_thread(io_handler_thread_key);
492
 
#endif /* UNIV_PFS_THREAD */
493
 
 
494
 
        while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS) {
 
418
        for (i = 0;; i++) {
495
419
                fil_aio_wait(segment);
496
420
 
497
421
                mutex_enter(&ios_mutex);
499
423
                mutex_exit(&ios_mutex);
500
424
        }
501
425
 
502
 
        thr_local_free(os_thread_get_curr_id());
503
 
 
504
426
        /* We count the number of threads in os_thread_exit(). A created
505
427
        thread should always use that to exit and not use return() to exit.
506
428
        The thread actually never comes here because it is exited in an
507
429
        os_event_wait(). */
 
430
#ifndef UNIV_SOLARIS
508
431
        return 0;
 
432
#endif
509
433
}
510
434
#endif /* !UNIV_HOTBACKUP */
511
435
 
515
439
#define SRV_PATH_SEPARATOR      '/'
516
440
#endif
517
441
 
518
 
/*********************************************************************//**
 
442
/*************************************************************************
519
443
Normalizes a directory path for Windows: converts slashes to backslashes. */
520
444
UNIV_INTERN
521
445
void
522
446
srv_normalize_path_for_win(
523
447
/*=======================*/
524
 
        char*   str __attribute__((unused)))    /*!< in/out: null-terminated
 
448
        char*   str __attribute__((unused)))    /* in/out: null-terminated
525
449
                                                character string */
526
450
{
527
451
#ifdef __WIN__
534
458
#endif
535
459
}
536
460
 
 
461
/*************************************************************************
 
462
Adds a slash or a backslash to the end of a string if it is missing
 
463
and the string is not empty. */
 
464
UNIV_INTERN
 
465
char*
 
466
srv_add_path_separator_if_needed(
 
467
/*=============================*/
 
468
                        /* out: string which has the separator if the
 
469
                        string is not empty */
 
470
        char*   str)    /* in: null-terminated character string */
 
471
{
 
472
        char*   out_str;
 
473
        ulint   len     = ut_strlen(str);
 
474
 
 
475
        if (len == 0 || str[len - 1] == SRV_PATH_SEPARATOR) {
 
476
 
 
477
                return(str);
 
478
        }
 
479
 
 
480
        out_str = ut_malloc(len + 2);
 
481
        memcpy(out_str, str, len);
 
482
        out_str[len] = SRV_PATH_SEPARATOR;
 
483
        out_str[len + 1] = 0;
 
484
 
 
485
        return(out_str);
 
486
}
 
487
 
537
488
#ifndef UNIV_HOTBACKUP
538
 
/*********************************************************************//**
 
489
/*************************************************************************
539
490
Calculates the low 32 bits when a file size which is given as a number
540
 
database pages is converted to the number of bytes.
541
 
@return low 32 bytes of file size when expressed in bytes */
 
491
database pages is converted to the number of bytes. */
542
492
static
543
493
ulint
544
494
srv_calc_low32(
545
495
/*===========*/
546
 
        ulint   file_size)      /*!< in: file size in database pages */
 
496
                                /* out: low 32 bytes of file size when
 
497
                                expressed in bytes */
 
498
        ulint   file_size)      /* in: file size in database pages */
547
499
{
548
500
        return(0xFFFFFFFFUL & (file_size << UNIV_PAGE_SIZE_SHIFT));
549
501
}
550
502
 
551
 
/*********************************************************************//**
 
503
/*************************************************************************
552
504
Calculates the high 32 bits when a file size which is given as a number
553
 
database pages is converted to the number of bytes.
554
 
@return high 32 bytes of file size when expressed in bytes */
 
505
database pages is converted to the number of bytes. */
555
506
static
556
507
ulint
557
508
srv_calc_high32(
558
509
/*============*/
559
 
        ulint   file_size)      /*!< in: file size in database pages */
 
510
                                /* out: high 32 bytes of file size when
 
511
                                expressed in bytes */
 
512
        ulint   file_size)      /* in: file size in database pages */
560
513
{
561
514
        return(file_size >> (32 - UNIV_PAGE_SIZE_SHIFT));
562
515
}
563
516
 
564
 
/*********************************************************************//**
565
 
Creates or opens the log files and closes them.
566
 
@return DB_SUCCESS or error code */
 
517
/*************************************************************************
 
518
Creates or opens the log files and closes them. */
567
519
static
568
520
ulint
569
521
open_or_create_log_file(
570
522
/*====================*/
571
 
        ibool   create_new_db,          /*!< in: TRUE if we should create a
 
523
                                        /* out: DB_SUCCESS or error code */
 
524
        ibool   create_new_db,          /* in: TRUE if we should create a
572
525
                                        new database */
573
 
        ibool*  log_file_created,       /*!< out: TRUE if new log file
 
526
        ibool*  log_file_created,       /* out: TRUE if new log file
574
527
                                        created */
575
 
        ibool   log_file_has_been_opened,/*!< in: TRUE if a log file has been
 
528
        ibool   log_file_has_been_opened,/* in: TRUE if a log file has been
576
529
                                        opened before: then it is an error
577
530
                                        to try to create another log file */
578
 
        ulint   k,                      /*!< in: log group number */
579
 
        ulint   i)                      /*!< in: log file number in group */
 
531
        ulint   k,                      /* in: log group number */
 
532
        ulint   i)                      /* in: log file number in group */
580
533
{
581
534
        ibool   ret;
582
535
        ulint   size;
583
536
        ulint   size_high;
584
537
        char    name[10000];
585
 
        ulint   dirnamelen;
586
538
 
587
539
        UT_NOT_USED(create_new_db);
588
540
 
589
541
        *log_file_created = FALSE;
590
542
 
591
543
        srv_normalize_path_for_win(srv_log_group_home_dirs[k]);
592
 
 
593
 
        dirnamelen = strlen(srv_log_group_home_dirs[k]);
594
 
        ut_a(dirnamelen < (sizeof name) - 10 - sizeof "ib_logfile");
595
 
        memcpy(name, srv_log_group_home_dirs[k], dirnamelen);
596
 
 
597
 
        /* Add a path separator if needed. */
598
 
        if (dirnamelen && name[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
599
 
                name[dirnamelen++] = SRV_PATH_SEPARATOR;
600
 
        }
601
 
 
602
 
        sprintf(name + dirnamelen, "%s%lu", "ib_logfile", (ulong) i);
603
 
 
604
 
        files[i] = os_file_create(innodb_file_log_key, name,
605
 
                                  OS_FILE_CREATE, OS_FILE_NORMAL,
 
544
        srv_log_group_home_dirs[k] = srv_add_path_separator_if_needed(
 
545
                srv_log_group_home_dirs[k]);
 
546
 
 
547
        ut_a(strlen(srv_log_group_home_dirs[k])
 
548
             < (sizeof name) - 10 - sizeof "ib_logfile");
 
549
        sprintf(name, "%s%s%lu", srv_log_group_home_dirs[k],
 
550
                "ib_logfile", (ulong) i);
 
551
 
 
552
        files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_NORMAL,
606
553
                                  OS_LOG_FILE, &ret);
607
554
        if (ret == FALSE) {
608
555
                if (os_file_get_last_error(FALSE) != OS_FILE_ALREADY_EXISTS
620
567
                        return(DB_ERROR);
621
568
                }
622
569
 
623
 
                files[i] = os_file_create(innodb_file_log_key, name,
624
 
                                          OS_FILE_OPEN, OS_FILE_AIO,
 
570
                files[i] = os_file_create(name, OS_FILE_OPEN, OS_FILE_AIO,
625
571
                                          OS_LOG_FILE, &ret);
626
572
                if (!ret) {
627
573
                        fprintf(stderr,
721
667
        return(DB_SUCCESS);
722
668
}
723
669
 
724
 
/*********************************************************************//**
725
 
Creates or opens database data files and closes them.
726
 
@return DB_SUCCESS or error code */
 
670
/*************************************************************************
 
671
Creates or opens database data files and closes them. */
727
672
static
728
673
ulint
729
674
open_or_create_data_files(
730
675
/*======================*/
731
 
        ibool*          create_new_db,  /*!< out: TRUE if new database should be
 
676
                                        /* out: DB_SUCCESS or error code */
 
677
        ibool*          create_new_db,  /* out: TRUE if new database should be
732
678
                                        created */
733
679
#ifdef UNIV_LOG_ARCHIVE
734
 
        ulint*          min_arch_log_no,/*!< out: min of archived log
 
680
        ulint*          min_arch_log_no,/* out: min of archived log
735
681
                                        numbers in data files */
736
 
        ulint*          max_arch_log_no,/*!< out: max of archived log
 
682
        ulint*          max_arch_log_no,/* out: max of archived log
737
683
                                        numbers in data files */
738
684
#endif /* UNIV_LOG_ARCHIVE */
739
 
        ib_uint64_t*    min_flushed_lsn,/*!< out: min of flushed lsn
740
 
                                        values in data files */
741
 
        ib_uint64_t*    max_flushed_lsn,/*!< out: max of flushed lsn
742
 
                                        values in data files */
743
 
        ulint*          sum_of_new_sizes)/*!< out: sum of sizes of the
 
685
        ib_uint64_t*    min_flushed_lsn,/* out: min of flushed lsn
 
686
                                        values in data files */
 
687
        ib_uint64_t*    max_flushed_lsn,/* out: max of flushed lsn
 
688
                                        values in data files */
 
689
        ulint*          sum_of_new_sizes)/* out: sum of sizes of the
744
690
                                        new files added */
745
691
{
746
692
        ibool   ret;
764
710
        *create_new_db = FALSE;
765
711
 
766
712
        srv_normalize_path_for_win(srv_data_home);
 
713
        srv_data_home = srv_add_path_separator_if_needed(srv_data_home);
767
714
 
768
715
        for (i = 0; i < srv_n_data_files; i++) {
769
 
                ulint   dirnamelen;
770
 
 
771
716
                srv_normalize_path_for_win(srv_data_file_names[i]);
772
 
                dirnamelen = strlen(srv_data_home);
773
717
 
774
 
                ut_a(dirnamelen + strlen(srv_data_file_names[i])
 
718
                ut_a(strlen(srv_data_home) + strlen(srv_data_file_names[i])
775
719
                     < (sizeof name) - 1);
776
 
                memcpy(name, srv_data_home, dirnamelen);
777
 
                /* Add a path separator if needed. */
778
 
                if (dirnamelen && name[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
779
 
                        name[dirnamelen++] = SRV_PATH_SEPARATOR;
780
 
                }
781
 
 
782
 
                strcpy(name + dirnamelen, srv_data_file_names[i]);
 
720
                sprintf(name, "%s%s", srv_data_home, srv_data_file_names[i]);
783
721
 
784
722
                if (srv_data_file_is_raw_partition[i] == 0) {
785
723
 
786
724
                        /* First we try to create the file: if it already
787
725
                        exists, ret will get value FALSE */
788
726
 
789
 
                        files[i] = os_file_create(innodb_file_data_key,
790
 
                                                  name, OS_FILE_CREATE,
 
727
                        files[i] = os_file_create(name, OS_FILE_CREATE,
791
728
                                                  OS_FILE_NORMAL,
792
729
                                                  OS_DATA_FILE, &ret);
793
730
 
814
751
                        srv_start_raw_disk_in_use = TRUE;
815
752
                        srv_created_new_raw = TRUE;
816
753
 
817
 
                        files[i] = os_file_create(innodb_file_data_key,
818
 
                                                  name, OS_FILE_OPEN_RAW,
 
754
                        files[i] = os_file_create(name, OS_FILE_OPEN_RAW,
819
755
                                                  OS_FILE_NORMAL,
820
756
                                                  OS_DATA_FILE, &ret);
821
757
                        if (!ret) {
848
784
 
849
785
                        if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
850
786
                                files[i] = os_file_create(
851
 
                                        innodb_file_data_key,
852
787
                                        name, OS_FILE_OPEN_RAW,
853
788
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
854
789
                        } else if (i == 0) {
855
790
                                files[i] = os_file_create(
856
 
                                        innodb_file_data_key,
857
791
                                        name, OS_FILE_OPEN_RETRY,
858
792
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
859
793
                        } else {
860
794
                                files[i] = os_file_create(
861
 
                                        innodb_file_data_key,
862
795
                                        name, OS_FILE_OPEN, OS_FILE_NORMAL,
863
796
                                        OS_DATA_FILE, &ret);
864
797
                        }
1001
934
 
1002
935
        ios = 0;
1003
936
 
1004
 
        mutex_create(ios_mutex_key, &ios_mutex, SYNC_NO_ORDER_CHECK);
 
937
        mutex_create(&ios_mutex, SYNC_NO_ORDER_CHECK);
1005
938
 
1006
939
        return(DB_SUCCESS);
1007
940
}
1008
941
 
1009
942
/********************************************************************
1010
943
Starts InnoDB and creates a new database if database files
1011
 
are not found and the user wants.
1012
 
@return DB_SUCCESS or error code */
 
944
are not found and the user wants. Server parameters are
 
945
read from a file of name "srv_init" in the ib_home directory. */
1013
946
UNIV_INTERN
1014
947
int
1015
948
innobase_start_or_create_for_mysql(void)
1016
949
/*====================================*/
 
950
                                /* out: DB_SUCCESS or error code */
1017
951
{
 
952
        buf_pool_t*     ret;
1018
953
        ibool           create_new_db;
1019
954
        ibool           log_file_created;
1020
955
        ibool           log_created     = FALSE;
1030
965
        ulint           tablespace_size_in_header;
1031
966
        ulint           err;
1032
967
        ulint           i;
1033
 
        ulint           io_limit;
1034
968
        my_bool         srv_file_per_table_original_value
1035
969
                = srv_file_per_table;
1036
970
        mtr_t           mtr;
1080
1014
#ifdef UNIV_IBUF_DEBUG
1081
1015
        fprintf(stderr,
1082
1016
                "InnoDB: !!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!\n"
1083
 
# ifdef UNIV_IBUF_COUNT_DEBUG
1084
 
                "InnoDB: !!!!!!!! UNIV_IBUF_COUNT_DEBUG switched on !!!!!!!!!\n"
1085
 
                "InnoDB: Crash recovery will fail with UNIV_IBUF_COUNT_DEBUG\n"
1086
 
# endif
1087
 
                );
 
1017
                "InnoDB: Crash recovery will fail with UNIV_IBUF_DEBUG\n");
1088
1018
#endif
1089
1019
 
1090
1020
#ifdef UNIV_SYNC_DEBUG
1097
1027
                "InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n");
1098
1028
#endif
1099
1029
 
1100
 
#ifdef UNIV_LOG_LSN_DEBUG
1101
 
        fprintf(stderr,
1102
 
                "InnoDB: !!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!\n");
1103
 
#endif /* UNIV_LOG_LSN_DEBUG */
1104
1030
#ifdef UNIV_MEM_DEBUG
1105
1031
        fprintf(stderr,
1106
1032
                "InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n");
1107
1033
#endif
1108
1034
 
1109
 
        if (UNIV_LIKELY(srv_use_sys_malloc)) {
1110
 
                fprintf(stderr,
1111
 
                        "InnoDB: The InnoDB memory heap is disabled\n");
1112
 
        }
1113
 
 
1114
 
        fputs("InnoDB: " IB_ATOMICS_STARTUP_MSG
1115
 
              "\nInnoDB: Compressed tables use zlib " ZLIB_VERSION
1116
 
#ifdef UNIV_ZIP_DEBUG
1117
 
              " with validation"
1118
 
#endif /* UNIV_ZIP_DEBUG */
1119
 
#ifdef UNIV_ZIP_COPY
1120
 
              " and extra copying"
1121
 
#endif /* UNIV_ZIP_COPY */
1122
 
              "\n" , stderr);
1123
 
 
1124
 
 
1125
1035
        /* Since InnoDB does not currently clean up all its internal data
1126
1036
        structures in MySQL Embedded Server Library server_end(), we
1127
1037
        print an error message if someone tries to start up InnoDB a
1129
1039
 
1130
1040
        if (srv_start_has_been_called) {
1131
1041
                fprintf(stderr,
1132
 
                        "InnoDB: Error: startup called second time"
 
1042
                        "InnoDB: Error:startup called second time"
1133
1043
                        " during the process lifetime.\n"
1134
1044
                        "InnoDB: In the MySQL Embedded Server Library"
1135
1045
                        " you cannot call server_init()\n"
1146
1056
 
1147
1057
        srv_is_being_started = TRUE;
1148
1058
        srv_startup_is_before_trx_rollback_phase = TRUE;
 
1059
        os_aio_use_native_aio = FALSE;
1149
1060
 
1150
1061
#ifdef __WIN__
1151
 
        switch (os_get_os_version()) {
1152
 
        case OS_WIN95:
1153
 
        case OS_WIN31:
1154
 
        case OS_WINNT:
 
1062
        if (os_get_os_version() == OS_WIN95
 
1063
            || os_get_os_version() == OS_WIN31
 
1064
            || os_get_os_version() == OS_WINNT) {
 
1065
 
1155
1066
                /* On Win 95, 98, ME, Win32 subsystem for Windows 3.1,
1156
1067
                and NT use simulated aio. In NT Windows provides async i/o,
1157
1068
                but when run in conjunction with InnoDB Hot Backup, it seemed
1158
1069
                to corrupt the data files. */
1159
1070
 
1160
 
                srv_use_native_aio = FALSE;
1161
 
                break;
1162
 
 
1163
 
        case OS_WIN2000:
1164
 
        case OS_WINXP:
1165
 
                /* On 2000 and XP, async IO is available. */
1166
 
                srv_use_native_aio = TRUE;
1167
 
                break;
1168
 
 
1169
 
        default:
1170
 
                /* Vista and later have both async IO and condition variables */
1171
 
                srv_use_native_aio = TRUE;
1172
 
                srv_use_native_conditions = TRUE;
1173
 
                break;
1174
 
        }
1175
 
 
1176
 
#elif defined(LINUX_NATIVE_AIO)
1177
 
 
1178
 
        if (srv_use_native_aio) {
1179
 
                ut_print_timestamp(stderr);
1180
 
                fprintf(stderr,
1181
 
                        "  InnoDB: Using Linux native AIO\n");
1182
 
        }
1183
 
#else
1184
 
        /* Currently native AIO is supported only on windows and linux
1185
 
        and that also when the support is compiled in. In all other
1186
 
        cases, we ignore the setting of innodb_use_native_aio. */
1187
 
        srv_use_native_aio = FALSE;
1188
 
 
 
1071
                os_aio_use_native_aio = FALSE;
 
1072
        } else {
 
1073
                /* On Win 2000 and XP use async i/o */
 
1074
                os_aio_use_native_aio = TRUE;
 
1075
        }
1189
1076
#endif
1190
 
 
1191
1077
        if (srv_file_flush_method_str == NULL) {
1192
1078
                /* These are the default options */
1193
1079
 
1212
1098
#else
1213
1099
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
1214
1100
                srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
1215
 
                srv_use_native_aio = FALSE;
 
1101
                os_aio_use_native_aio = FALSE;
1216
1102
 
1217
1103
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
1218
1104
                srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1219
 
                srv_use_native_aio = FALSE;
 
1105
                os_aio_use_native_aio = FALSE;
1220
1106
 
1221
1107
        } else if (0 == ut_strcmp(srv_file_flush_method_str,
1222
1108
                                  "async_unbuffered")) {
1238
1124
        maximum number of threads that can wait in the 'srv_conc array' for
1239
1125
        their time to enter InnoDB. */
1240
1126
 
 
1127
#if defined(__NETWARE__)
 
1128
 
 
1129
        /* Create less event semaphores because Win 98/ME had
 
1130
        difficulty creating 40000 event semaphores.  Comment from
 
1131
        Novell, Inc.: also, these just take a lot of memory on
 
1132
        NetWare. */
 
1133
        srv_max_n_threads = 1000;
 
1134
#else
1241
1135
        if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
1242
1136
                /* If buffer pool is less than 1000 MB,
1243
 
                assume fewer threads. Also use only one
1244
 
                buffer pool instance */
 
1137
                assume fewer threads. */
1245
1138
                srv_max_n_threads = 50000;
1246
1139
 
1247
1140
        } else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
1248
1141
 
1249
 
                srv_buf_pool_instances = 1;
1250
1142
                srv_max_n_threads = 10000;
1251
1143
        } else {
1252
 
                srv_buf_pool_instances = 1;
1253
1144
                srv_max_n_threads = 1000;       /* saves several MB of memory,
1254
1145
                                                especially in 64-bit
1255
1146
                                                computers */
1256
1147
        }
1257
 
 
 
1148
#endif
1258
1149
        err = srv_boot();
1259
1150
 
1260
1151
        if (err != DB_SUCCESS) {
1262
1153
                return((int) err);
1263
1154
        }
1264
1155
 
1265
 
        mutex_create(srv_monitor_file_mutex_key,
1266
 
                     &srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
 
1156
        mutex_create(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
1267
1157
 
1268
1158
        if (srv_innodb_status) {
1269
1159
                srv_monitor_file_name = mem_alloc(
1285
1175
                }
1286
1176
        }
1287
1177
 
1288
 
        mutex_create(srv_dict_tmpfile_mutex_key,
1289
 
                     &srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
 
1178
        mutex_create(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
1290
1179
 
1291
1180
        srv_dict_tmpfile = os_file_create_tmpfile();
1292
1181
        if (!srv_dict_tmpfile) {
1293
1182
                return(DB_ERROR);
1294
1183
        }
1295
1184
 
1296
 
        mutex_create(srv_misc_tmpfile_mutex_key,
1297
 
                     &srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
 
1185
        mutex_create(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
1298
1186
 
1299
1187
        srv_misc_tmpfile = os_file_create_tmpfile();
1300
1188
        if (!srv_misc_tmpfile) {
1301
1189
                return(DB_ERROR);
1302
1190
        }
1303
1191
 
1304
 
        /* innodb_file_io_threads used to be user settable.
1305
 
           It is now just a combination of read_io_threads and
1306
 
           write_io_threads that is set by innodb internally. */
1307
 
 
1308
 
        /* Now overwrite the value on srv_n_file_io_threads */
1309
 
        srv_n_file_io_threads = 2 + srv_n_read_io_threads
1310
 
                                + srv_n_write_io_threads;
1311
 
 
1312
 
        ut_a(srv_n_file_io_threads <= SRV_MAX_N_IO_THREADS);
1313
 
 
1314
 
        /* TODO: Investigate if SRV_N_PENDING_IOS_PER_THREAD (32) limit
1315
 
        still applies to windows. */
1316
 
        if (!srv_use_native_aio) {
1317
 
                io_limit = 8 * SRV_N_PENDING_IOS_PER_THREAD;
1318
 
        } else {
1319
 
                io_limit = SRV_N_PENDING_IOS_PER_THREAD;
1320
 
        }
1321
 
 
1322
 
        os_aio_init(io_limit,
1323
 
                    srv_n_read_io_threads,
1324
 
                    srv_n_write_io_threads,
1325
 
                    SRV_MAX_N_PENDING_SYNC_IOS);
1326
 
 
1327
 
        fil_init(srv_file_per_table ? 50000 : 5000,
1328
 
                 srv_max_n_open_files);
1329
 
 
1330
 
        /* Print time to initialize the buffer pool */
1331
 
        ut_print_timestamp(stderr);
1332
 
        fprintf(stderr,
1333
 
                "  InnoDB: Initializing buffer pool, size =");
1334
 
 
1335
 
        if (srv_buf_pool_size >= 1024 * 1024 * 1024) {
1336
 
                fprintf(stderr,
1337
 
                        " %.1fG\n",
1338
 
                        ((double) srv_buf_pool_size) / (1024 * 1024 * 1024));
1339
 
        } else {
1340
 
                fprintf(stderr,
1341
 
                        " %.1fM\n",
1342
 
                        ((double) srv_buf_pool_size) / (1024 * 1024));
1343
 
        }
1344
 
 
1345
 
        err = buf_pool_init(srv_buf_pool_size, srv_buf_pool_instances);
1346
 
 
1347
 
        ut_print_timestamp(stderr);
1348
 
        fprintf(stderr,
1349
 
                "  InnoDB: Completed initialization of buffer pool\n");
1350
 
 
1351
 
        if (err != DB_SUCCESS) {
 
1192
        /* Restrict the maximum number of file i/o threads */
 
1193
        if (srv_n_file_io_threads > SRV_MAX_N_IO_THREADS) {
 
1194
 
 
1195
                srv_n_file_io_threads = SRV_MAX_N_IO_THREADS;
 
1196
        }
 
1197
 
 
1198
        if (!os_aio_use_native_aio) {
 
1199
                /* In simulated aio we currently have use only for 4 threads */
 
1200
                srv_n_file_io_threads = 4;
 
1201
 
 
1202
                os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD
 
1203
                            * srv_n_file_io_threads,
 
1204
                            srv_n_file_io_threads,
 
1205
                            SRV_MAX_N_PENDING_SYNC_IOS);
 
1206
        } else {
 
1207
                os_aio_init(SRV_N_PENDING_IOS_PER_THREAD
 
1208
                            * srv_n_file_io_threads,
 
1209
                            srv_n_file_io_threads,
 
1210
                            SRV_MAX_N_PENDING_SYNC_IOS);
 
1211
        }
 
1212
 
 
1213
        fil_init(srv_max_n_open_files);
 
1214
 
 
1215
        ret = buf_pool_init();
 
1216
 
 
1217
        if (ret == NULL) {
1352
1218
                fprintf(stderr,
1353
1219
                        "InnoDB: Fatal error: cannot allocate the memory"
1354
1220
                        " for the buffer pool\n");
1418
1284
                sum_of_new_sizes += srv_data_file_sizes[i];
1419
1285
        }
1420
1286
 
1421
 
        if (sum_of_new_sizes < 10485760 / UNIV_PAGE_SIZE) {
 
1287
        if (sum_of_new_sizes < 640) {
1422
1288
                fprintf(stderr,
1423
1289
                        "InnoDB: Error: tablespace size must be"
1424
1290
                        " at least 10 MB\n");
1545
1411
 
1546
1412
        if (create_new_db) {
1547
1413
                mtr_start(&mtr);
1548
 
 
1549
1414
                fsp_header_init(0, sum_of_new_sizes, &mtr);
1550
1415
 
1551
1416
                mtr_commit(&mtr);
1552
1417
 
1553
 
                /* To maintain backward compatibility we create only
1554
 
                the first rollback segment before the double write buffer.
1555
 
                All the remaining rollback segments will be created later,
1556
 
                after the double write buffer has been created. */
1557
1418
                trx_sys_create();
1558
 
 
1559
1419
                dict_create();
1560
 
 
1561
1420
                srv_startup_is_before_trx_rollback_phase = FALSE;
1562
1421
 
1563
1422
#ifdef UNIV_LOG_ARCHIVE
1576
1435
                in any disk i/o, first call dict_boot */
1577
1436
 
1578
1437
                dict_boot();
1579
 
 
1580
1438
                trx_sys_init_at_db_start();
1581
 
 
1582
1439
                srv_startup_is_before_trx_rollback_phase = FALSE;
1583
1440
 
1584
1441
                /* Initialize the fsp free limit global variable in the log
1602
1459
                consistent state, this is REQUIRED for the recovery
1603
1460
                process to work. */
1604
1461
                err = trx_sys_file_format_max_check(
1605
 
                        srv_max_file_format_at_startup);
 
1462
                        srv_check_file_format_at_startup);
1606
1463
 
1607
1464
                if (err != DB_SUCCESS) {
1608
1465
                        return(err);
1636
1493
                dict_boot();
1637
1494
                trx_sys_init_at_db_start();
1638
1495
 
1639
 
                /* Initialize the fsp free limit global variable in the log
1640
 
                system */
1641
 
                fsp_header_get_free_limit();
1642
 
 
1643
 
                /* recv_recovery_from_checkpoint_finish needs trx lists which
1644
 
                are initialized in trx_sys_init_at_db_start(). */
1645
 
 
1646
 
                recv_recovery_from_checkpoint_finish();
1647
1496
                if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
1648
1497
                        /* The following call is necessary for the insert
1649
1498
                        buffer to work with multiple tablespaces. We must
1659
1508
                        every table in the InnoDB data dictionary that has
1660
1509
                        an .ibd file.
1661
1510
 
1662
 
                        We also determine the maximum tablespace id used. */
 
1511
                        We also determine the maximum tablespace id used.
 
1512
 
 
1513
                        TODO: We may have incomplete transactions in the
 
1514
                        data dictionary tables. Does that harm the scanning of
 
1515
                        the data dictionary below? */
1663
1516
 
1664
1517
                        dict_check_tablespaces_and_store_max_id(
1665
1518
                                recv_needed_recovery);
1666
1519
                }
1667
1520
 
1668
1521
                srv_startup_is_before_trx_rollback_phase = FALSE;
1669
 
                recv_recovery_rollback_active();
 
1522
 
 
1523
                /* Initialize the fsp free limit global variable in the log
 
1524
                system */
 
1525
                fsp_header_get_free_limit();
 
1526
 
 
1527
                /* recv_recovery_from_checkpoint_finish needs trx lists which
 
1528
                are initialized in trx_sys_init_at_db_start(). */
 
1529
 
 
1530
                recv_recovery_from_checkpoint_finish();
1670
1531
 
1671
1532
                /* It is possible that file_format tag has never
1672
1533
                been set. In this case we initialize it to minimum
1715
1576
        /* fprintf(stderr, "Max allowed record size %lu\n",
1716
1577
        page_get_free_space_of_empty() / 2); */
1717
1578
 
1718
 
        if (trx_doublewrite == NULL) {
1719
 
                /* Create the doublewrite buffer to a new tablespace */
1720
 
 
1721
 
                trx_sys_create_doublewrite_buf();
1722
 
        }
1723
 
 
1724
 
        /* Here the double write buffer has already been created and so
1725
 
        any new rollback segments will be allocated after the double
1726
 
        write buffer. The default segment should already exist.
1727
 
        We create the new segments only if it's a new database or
1728
 
        the database was shutdown cleanly. */
1729
 
 
1730
 
        /* Note: When creating the extra rollback segments during an upgrade
1731
 
        we violate the latching order, even if the change buffer is empty.
1732
 
        We make an exception in sync0sync.c and check srv_is_being_started
1733
 
        for that violation. It cannot create a deadlock because we are still
1734
 
        running in single threaded mode essentially. Only the IO threads
1735
 
        should be running at this stage. */
1736
 
 
1737
 
        trx_sys_create_rsegs(TRX_SYS_N_RSEGS - 1);
1738
 
 
1739
 
        /* Create the thread which watches the timeouts for lock waits */
1740
 
        os_thread_create(&srv_lock_timeout_thread, NULL,
 
1579
        /* Create the thread which watches the timeouts for lock waits
 
1580
        and prints InnoDB monitor info */
 
1581
 
 
1582
        os_thread_create(&srv_lock_timeout_and_monitor_thread, NULL,
1741
1583
                         thread_ids + 2 + SRV_MAX_N_IO_THREADS);
1742
1584
 
1743
1585
        /* Create the thread which warns of long semaphore waits */
1744
1586
        os_thread_create(&srv_error_monitor_thread, NULL,
1745
1587
                         thread_ids + 3 + SRV_MAX_N_IO_THREADS);
1746
 
 
1747
 
        /* Create the thread which prints InnoDB monitor info */
1748
 
        os_thread_create(&srv_monitor_thread, NULL,
1749
 
                         thread_ids + 4 + SRV_MAX_N_IO_THREADS);
1750
 
 
1751
1588
        srv_is_being_started = FALSE;
1752
1589
 
 
1590
        if (trx_doublewrite == NULL) {
 
1591
                /* Create the doublewrite buffer to a new tablespace */
 
1592
 
 
1593
                trx_sys_create_doublewrite_buf();
 
1594
        }
 
1595
 
1753
1596
        err = dict_create_or_check_foreign_constraint_tables();
1754
1597
 
1755
1598
        if (err != DB_SUCCESS) {
1761
1604
 
1762
1605
        os_thread_create(&srv_master_thread, NULL, thread_ids
1763
1606
                         + (1 + SRV_MAX_N_IO_THREADS));
1764
 
 
1765
 
        /* Currently we allow only a single purge thread. */
1766
 
        ut_a(srv_n_purge_threads == 0 || srv_n_purge_threads == 1);
1767
 
 
1768
 
        /* If the user has requested a separate purge thread then
1769
 
        start the purge thread. */
1770
 
        if (srv_n_purge_threads == 1) {
1771
 
                os_thread_create(&srv_purge_thread, NULL, NULL);
1772
 
        }
1773
 
 
1774
1607
#ifdef UNIV_DEBUG
1775
1608
        /* buf_debug_prints = TRUE; */
1776
1609
#endif /* UNIV_DEBUG */
1864
1697
        if (srv_print_verbose_log) {
1865
1698
                ut_print_timestamp(stderr);
1866
1699
                fprintf(stderr,
1867
 
                        "  InnoDB %s started; "
 
1700
                        " InnoDB Plugin %s started; "
1868
1701
                        "log sequence number %"PRIu64"\n",
1869
1702
                        INNODB_VERSION_STR, srv_start_lsn);
1870
1703
        }
1922
1755
                        " to an earlier version of\n"
1923
1756
                        "InnoDB: InnoDB! But if you absolutely need to"
1924
1757
                        " downgrade, see\n"
1925
 
                        "InnoDB: " REFMAN "multiple-tablespaces.html\n"
 
1758
                        "InnoDB: http://dev.mysql.com/doc/refman/5.1/en/"
 
1759
                        "multiple-tablespaces.html\n"
1926
1760
                        "InnoDB: for instructions.\n");
1927
1761
        }
1928
1762
 
1942
1776
        return((int) DB_SUCCESS);
1943
1777
}
1944
1778
 
1945
 
/****************************************************************//**
1946
 
Shuts down the InnoDB database.
1947
 
@return DB_SUCCESS or error code */
 
1779
/********************************************************************
 
1780
Shuts down the InnoDB database. */
1948
1781
UNIV_INTERN
1949
1782
int
1950
1783
innobase_shutdown_for_mysql(void)
1951
1784
/*=============================*/
 
1785
                                /* out: DB_SUCCESS or error code */
1952
1786
{
1953
1787
        ulint   i;
 
1788
#ifdef __NETWARE__
 
1789
        extern ibool panic_shutdown;
 
1790
#endif
1954
1791
        if (!srv_was_started) {
1955
1792
                if (srv_is_being_started) {
1956
1793
                        ut_print_timestamp(stderr);
1979
1816
                        "InnoDB will do a crash recovery!\n");
1980
1817
        }
1981
1818
 
1982
 
        logs_empty_and_mark_files_at_shutdown();
 
1819
#ifdef __NETWARE__
 
1820
        if(!panic_shutdown)
 
1821
#endif
 
1822
                logs_empty_and_mark_files_at_shutdown();
1983
1823
 
1984
1824
        if (srv_conc_n_threads != 0) {
1985
1825
                fprintf(stderr,
2018
1858
                /* c. We wake the master thread so that it exits */
2019
1859
                srv_wake_master_thread();
2020
1860
 
2021
 
                /* d. We wake the purge thread so that it exits */
2022
 
                srv_wake_purge_thread();
2023
 
 
2024
 
                /* e. Exit the i/o threads */
 
1861
                /* d. Exit the i/o threads */
2025
1862
 
2026
1863
                os_aio_wake_all_threads_at_shutdown();
2027
1864
 
2031
1868
                        /* All the threads have exited or are just exiting;
2032
1869
                        NOTE that the threads may not have completed their
2033
1870
                        exit yet. Should we use pthread_join() to make sure
2034
 
                        they have exited? If we did, we would have to
2035
 
                        remove the pthread_detach() from
2036
 
                        os_thread_exit().  Now we just sleep 0.1
2037
 
                        seconds and hope that is enough! */
 
1871
                        they have exited? Now we just sleep 0.1 seconds and
 
1872
                        hope that is enough! */
2038
1873
 
2039
1874
                        os_mutex_exit(os_sync_mutex);
2040
1875
 
2073
1908
                srv_misc_tmpfile = 0;
2074
1909
        }
2075
1910
 
2076
 
        /* This must be disabled before closing the buffer pool
2077
 
        and closing the data dictionary.  */
2078
 
        btr_search_disable();
2079
 
 
2080
 
        ibuf_close();
2081
 
        log_shutdown();
2082
 
        lock_sys_close();
2083
 
        thr_local_close();
2084
1911
        trx_sys_file_format_close();
2085
 
        trx_sys_close();
2086
1912
 
2087
1913
        mutex_free(&srv_monitor_file_mutex);
2088
1914
        mutex_free(&srv_dict_tmpfile_mutex);
2089
1915
        mutex_free(&srv_misc_tmpfile_mutex);
2090
 
        dict_close();
2091
 
        btr_search_sys_free();
2092
1916
 
2093
1917
        /* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
2094
1918
        them */
2095
 
        os_aio_free();
2096
1919
        sync_close();
 
1920
 
 
1921
        /* 4. Free the os_conc_mutex and all os_events and os_mutexes */
 
1922
 
2097
1923
        srv_free();
2098
 
        fil_close();
2099
 
 
2100
 
        /* 4. Free the os_conc_mutex and all os_events and os_mutexes */
2101
 
 
2102
1924
        os_sync_free();
2103
1925
 
2104
 
        /* 5. Free all allocated memory */
2105
 
 
2106
 
        pars_lexer_close();
2107
 
        log_mem_free();
2108
 
        buf_pool_free(srv_buf_pool_instances);
2109
 
        mem_close();
2110
 
 
2111
 
        /* ut_free_all_mem() frees all allocated memory not freed yet
2112
 
        in shutdown, and it will also free the ut_list_mutex, so it
2113
 
        should be the last one for all operation */
 
1926
        /* Check that all read views are closed except read view owned
 
1927
        by a purge. */
 
1928
 
 
1929
        if (UT_LIST_GET_LEN(trx_sys->view_list) > 1) {
 
1930
                fprintf(stderr,
 
1931
                        "InnoDB: Error: all read views were not closed"
 
1932
                        " before shutdown:\n"
 
1933
                        "InnoDB: %lu read views open \n",
 
1934
                        UT_LIST_GET_LEN(trx_sys->view_list) - 1);
 
1935
        }
 
1936
 
 
1937
        /* 5. Free all allocated memory and the os_fast_mutex created in
 
1938
        ut0mem.c */
 
1939
 
 
1940
        buf_pool_free();
2114
1941
        ut_free_all_mem();
2115
1942
 
2116
1943
        if (os_thread_count != 0
2142
1969
        }
2143
1970
 
2144
1971
        srv_was_started = FALSE;
2145
 
        srv_start_has_been_called = FALSE;
2146
1972
 
2147
1973
        return((int) DB_SUCCESS);
2148
1974
}
 
1975
 
 
1976
#ifdef __NETWARE__
 
1977
void set_panic_flag_for_netware()
 
1978
{
 
1979
        extern ibool panic_shutdown;
 
1980
        panic_shutdown = TRUE;
 
1981
}
 
1982
#endif /* __NETWARE__ */
2149
1983
#endif /* !UNIV_HOTBACKUP */