1
/*****************************************************************************
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
4
Copyright (c) 2008, Google Inc.
6
Portions of this file contain modifications contributed and copyrighted by
7
Google, Inc. Those modifications are gratefully acknowledged and are described
8
briefly in the InnoDB documentation. The contributions by Google are
9
incorporated with their permission, and subject to the conditions contained in
10
the file COPYING.Google.
12
This program is free software; you can redistribute it and/or modify it under
13
the terms of the GNU General Public License as published by the Free Software
14
Foundation; version 2 of the License.
16
This program is distributed in the hope that it will be useful, but WITHOUT
17
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License along with
21
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22
Place, Suite 330, Boston, MA 02111-1307 USA
24
*****************************************************************************/
25
/***********************************************************************
27
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
28
Copyright (c) 2009, Percona Inc.
30
Portions of this file contain modifications contributed and copyrighted
31
by Percona Inc.. Those modifications are
32
gratefully acknowledged and are described briefly in the InnoDB
33
documentation. The contributions by Percona Inc. are incorporated with
34
their permission, and subject to the conditions contained in the file
37
This program is free software; you can redistribute it and/or modify it
38
under the terms of the GNU General Public License as published by the
39
Free Software Foundation; version 2 of the License.
41
This program is distributed in the hope that it will be useful, but
42
WITHOUT ANY WARRANTY; without even the implied warranty of
43
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
44
Public License for more details.
46
You should have received a copy of the GNU General Public License along
47
with this program; if not, write to the Free Software Foundation, Inc.,
48
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
50
***********************************************************************/
52
/********************************************************************//**
1
/************************************************************************
54
2
Starts the InnoDB database server
4
(c) 1996-2000 Innobase Oy
56
6
Created 2/16/1996 Heikki Tuuri
57
7
*************************************************************************/
10
#include "sync0sync.h"
59
11
#include "ut0mem.h"
60
12
#include "mem0mem.h"
61
14
#include "data0data.h"
62
15
#include "data0type.h"
63
16
#include "dict0dict.h"
64
17
#include "buf0buf.h"
65
20
#include "os0file.h"
66
21
#include "os0thread.h"
67
22
#include "fil0fil.h"
68
23
#include "fsp0fsp.h"
69
24
#include "rem0rec.h"
70
26
#include "mtr0mtr.h"
71
27
#include "log0log.h"
72
28
#include "log0recv.h"
73
29
#include "page0page.h"
74
30
#include "page0cur.h"
75
31
#include "trx0trx.h"
32
#include "dict0boot.h"
33
#include "dict0load.h"
76
34
#include "trx0sys.h"
35
#include "dict0crea.h"
77
36
#include "btr0btr.h"
78
38
#include "btr0cur.h"
79
40
#include "rem0rec.h"
44
#include "lock0lock.h"
46
#include "trx0purge.h"
51
#include "row0mysql.h"
52
#include "lock0lock.h"
80
53
#include "ibuf0ibuf.h"
54
#include "pars0pars.h"
81
56
#include "srv0start.h"
83
#ifndef UNIV_HOTBACKUP
85
# include "sync0sync.h"
88
# include "dict0boot.h"
89
# include "dict0load.h"
91
# include "usr0sess.h"
92
# include "lock0lock.h"
93
# include "trx0roll.h"
94
# include "trx0purge.h"
95
# include "lock0lock.h"
96
# include "pars0pars.h"
99
# include "dict0crea.h"
100
# include "row0ins.h"
101
# include "row0sel.h"
102
# include "row0upd.h"
103
# include "row0row.h"
104
# include "row0mysql.h"
105
# include "btr0pcur.h"
110
/** Log sequence number immediately after startup */
59
/* Log sequence number immediately after startup */
111
60
UNIV_INTERN ib_uint64_t srv_start_lsn;
112
/** Log sequence number at shutdown */
61
/* Log sequence number at shutdown */
113
62
UNIV_INTERN ib_uint64_t srv_shutdown_lsn;
115
64
#ifdef HAVE_DARWIN_THREADS
116
65
# include <sys/utsname.h>
117
/** TRUE if the F_FULLFSYNC option is available */
118
66
UNIV_INTERN ibool srv_have_fullfsync = FALSE;
121
/** TRUE if a raw partition is in use */
122
69
UNIV_INTERN ibool srv_start_raw_disk_in_use = FALSE;
124
/** TRUE if the server is being started, before rolling back any
125
incomplete transactions */
126
71
UNIV_INTERN ibool srv_startup_is_before_trx_rollback_phase = FALSE;
127
/** TRUE if the server is being started */
128
72
UNIV_INTERN ibool srv_is_being_started = FALSE;
129
/** TRUE if the server was successfully started */
130
73
UNIV_INTERN ibool srv_was_started = FALSE;
131
/** TRUE if innobase_start_or_create_for_mysql() has been called */
74
#ifndef UNIV_HOTBACKUP
132
75
static ibool srv_start_has_been_called = FALSE;
134
/** At a shutdown this value climbs from SRV_SHUTDOWN_NONE to
135
SRV_SHUTDOWN_CLEANUP and then to SRV_SHUTDOWN_LAST_PHASE, and so on */
136
UNIV_INTERN enum srv_shutdown_state srv_shutdown_state = SRV_SHUTDOWN_NONE;
138
/** Files comprising the system tablespace */
76
#endif /* !UNIV_HOTBACKUP */
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;
82
#ifndef UNIV_HOTBACKUP
139
83
static os_file_t files[1000];
141
/** Mutex protecting the ios count */
142
85
static mutex_t ios_mutex;
143
/** Count of I/O operations in io_handler_thread() */
146
/** io_handler_thread parameters for thread identification */
147
88
static ulint n[SRV_MAX_N_IO_THREADS + 5];
148
/** io_handler_thread identifiers */
149
89
static os_thread_id_t thread_ids[SRV_MAX_N_IO_THREADS + 5];
151
/** 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
152
92
on successful locking. HP-UX does NOT return 0, though Linux et al do. */
153
93
static os_fast_mutex_t srv_os_test_mutex;
155
/** Name of srv_monitor_file */
95
/* Name of srv_monitor_file */
156
96
static char* srv_monitor_file_name;
157
97
#endif /* !UNIV_HOTBACKUP */
160
99
#define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD
161
100
#define SRV_MAX_N_PENDING_SYNC_IOS 100
164
/*********************************************************************//**
165
Convert a numeric string that optionally ends in G or M, to a number
166
containing megabytes.
167
@return next character in string */
170
105
srv_parse_megabytes(
171
106
/*================*/
172
char* str, /*!< in: string containing a quantity in bytes */
173
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 */
198
/*********************************************************************//**
134
/*************************************************************************
199
135
Reads the data files and their sizes from a character string given in
201
@return TRUE if ok, FALSE on parse error */
204
139
srv_parse_data_file_paths_and_sizes(
205
140
/*================================*/
206
char* str) /*!< in/out: the data file path string */
141
/* out: TRUE if ok, FALSE if parsing
143
char* str, /* in: the data file path string */
144
char*** data_file_names, /* out, own: array of data file
146
ulint** data_file_sizes, /* out, own: array of data file sizes
148
ulint** data_file_is_raw_partition,/* out, own: array of flags
149
showing which data files are raw
151
ulint* n_data_files, /* out: number of data files */
152
ibool* is_auto_extending, /* out: TRUE if the last data file is
154
ulint* max_auto_extend_size) /* out: max auto extend size for the
155
last file if specified, 0 if not */
213
srv_auto_extend_last_data_file = FALSE;
214
srv_last_file_size_max = 0;
215
srv_data_file_names = NULL;
216
srv_data_file_sizes = NULL;
217
srv_data_file_is_raw_partition = NULL;
162
*is_auto_extending = FALSE;
163
*max_auto_extend_size = 0;
561
489
#ifndef UNIV_HOTBACKUP
562
/*********************************************************************//**
490
/*************************************************************************
563
491
Calculates the low 32 bits when a file size which is given as a number
564
database pages is converted to the number of bytes.
565
@return low 32 bytes of file size when expressed in bytes */
492
database pages is converted to the number of bytes. */
570
ulint file_size) /*!< in: file size in database pages */
497
/* out: low 32 bytes of file size when
498
expressed in bytes */
499
ulint file_size) /* in: file size in database pages */
572
501
return(0xFFFFFFFFUL & (file_size << UNIV_PAGE_SIZE_SHIFT));
575
/*********************************************************************//**
504
/*************************************************************************
576
505
Calculates the high 32 bits when a file size which is given as a number
577
database pages is converted to the number of bytes.
578
@return high 32 bytes of file size when expressed in bytes */
506
database pages is converted to the number of bytes. */
583
ulint file_size) /*!< in: file size in database pages */
511
/* out: high 32 bytes of file size when
512
expressed in bytes */
513
ulint file_size) /* in: file size in database pages */
585
515
return(file_size >> (32 - UNIV_PAGE_SIZE_SHIFT));
588
/*********************************************************************//**
589
Creates or opens the log files and closes them.
590
@return DB_SUCCESS or error code */
518
/*************************************************************************
519
Creates or opens the log files and closes them. */
593
522
open_or_create_log_file(
594
523
/*====================*/
595
ibool create_new_db, /*!< in: TRUE if we should create a
524
/* out: DB_SUCCESS or error code */
525
ibool create_new_db, /* in: TRUE if we should create a
597
ibool* log_file_created, /*!< out: TRUE if new log file
527
ibool* log_file_created, /* out: TRUE if new log file
599
ibool log_file_has_been_opened,/*!< in: TRUE if a log file has been
529
ibool log_file_has_been_opened,/* in: TRUE if a log file has been
600
530
opened before: then it is an error
601
531
to try to create another log file */
602
ulint k, /*!< in: log group number */
603
ulint i) /*!< in: log file number in group */
532
ulint k, /* in: log group number */
533
ulint i) /* in: log file number in group */
738
668
return(DB_SUCCESS);
741
/*********************************************************************//**
742
Creates or opens database data files and closes them.
743
@return DB_SUCCESS or error code */
671
/*************************************************************************
672
Creates or opens database data files and closes them. */
746
675
open_or_create_data_files(
747
676
/*======================*/
748
ibool* create_new_db, /*!< out: TRUE if new database should be
677
/* out: DB_SUCCESS or error code */
678
ibool* create_new_db, /* out: TRUE if new database should be
750
680
#ifdef UNIV_LOG_ARCHIVE
751
ulint* min_arch_log_no,/*!< out: min of archived log
681
ulint* min_arch_log_no,/* out: min of archived log
752
682
numbers in data files */
753
ulint* max_arch_log_no,/*!< out: max of archived log
683
ulint* max_arch_log_no,/* out: max of archived log
754
684
numbers in data files */
755
685
#endif /* UNIV_LOG_ARCHIVE */
756
ib_uint64_t* min_flushed_lsn,/*!< out: min of flushed lsn
757
values in data files */
758
ib_uint64_t* max_flushed_lsn,/*!< out: max of flushed lsn
759
values in data files */
760
ulint* sum_of_new_sizes)/*!< out: sum of sizes of the
686
ib_uint64_t* min_flushed_lsn,/* out: min of flushed lsn
687
values in data files */
688
ib_uint64_t* max_flushed_lsn,/* out: max of flushed lsn
689
values in data files */
690
ulint* sum_of_new_sizes)/* out: sum of sizes of the
761
691
new files added */
1103
1033
"InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n");
1106
if (UNIV_LIKELY(srv_use_sys_malloc)) {
1108
"InnoDB: The InnoDB memory heap is disabled\n");
1111
#ifdef HAVE_GCC_ATOMIC_BUILTINS
1112
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
1114
"InnoDB: Mutexes and rw_locks use GCC atomic builtins.\n");
1115
# else /* INNODB_RW_LOCKS_USE_ATOMICS */
1117
"InnoDB: Mutexes use GCC atomic builtins, rw_locks do not.\n");
1118
# endif /* INNODB_RW_LOCKS_USE_ATOMICS */
1119
#elif defined(HAVE_SOLARIS_ATOMICS)
1120
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
1122
"InnoDB: Mutexes and rw_locks use Solaris atomic functions.\n");
1125
"InnoDB: Mutexes use Solaris atomic functions.\n");
1126
# endif /* INNODB_RW_LOCKS_USE_ATOMICS */
1127
#elif defined(HAVE_WINDOWS_ATOMICS)
1128
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
1130
"InnoDB: Mutexes and rw_locks use Windows interlocked functions.\n");
1133
"InnoDB: Mutexes use Windows interlocked functions.\n");
1134
# endif /* INNODB_RW_LOCKS_USE_ATOMICS */
1135
#else /* HAVE_GCC_ATOMIC_BUILTINS */
1137
"InnoDB: Neither mutexes nor rw_locks use GCC atomic builtins.\n");
1138
#endif /* HAVE_GCC_ATOMIC_BUILTINS */
1140
1036
/* Since InnoDB does not currently clean up all its internal data
1141
1037
structures in MySQL Embedded Server Library server_end(), we
1142
1038
print an error message if someone tries to start up InnoDB a
1296
1190
return(DB_ERROR);
1299
/* If user has set the value of innodb_file_io_threads then
1300
we'll emit a message telling the user that this parameter
1301
is now deprecated. */
1302
if (srv_n_file_io_threads != 4) {
1303
fprintf(stderr, "InnoDB: Warning:"
1304
" innodb_file_io_threads is deprecated."
1305
" Please use innodb_read_io_threads and"
1306
" innodb_write_io_threads instead\n");
1193
/* Restrict the maximum number of file i/o threads */
1194
if (srv_n_file_io_threads > SRV_MAX_N_IO_THREADS) {
1196
srv_n_file_io_threads = SRV_MAX_N_IO_THREADS;
1309
/* Now overwrite the value on srv_n_file_io_threads */
1310
srv_n_file_io_threads = 2 + srv_n_read_io_threads
1311
+ srv_n_write_io_threads;
1313
ut_a(srv_n_file_io_threads <= SRV_MAX_N_IO_THREADS);
1315
/* TODO: Investigate if SRV_N_PENDING_IOS_PER_THREAD (32) limit
1316
still applies to windows. */
1317
1199
if (!os_aio_use_native_aio) {
1318
io_limit = 8 * SRV_N_PENDING_IOS_PER_THREAD;
1200
/* In simulated aio we currently have use only for 4 threads */
1201
srv_n_file_io_threads = 4;
1203
os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD
1204
* srv_n_file_io_threads,
1205
srv_n_file_io_threads,
1206
SRV_MAX_N_PENDING_SYNC_IOS);
1320
io_limit = SRV_N_PENDING_IOS_PER_THREAD;
1208
os_aio_init(SRV_N_PENDING_IOS_PER_THREAD
1209
* srv_n_file_io_threads,
1210
srv_n_file_io_threads,
1211
SRV_MAX_N_PENDING_SYNC_IOS);
1323
os_aio_init(io_limit,
1324
srv_n_read_io_threads,
1325
srv_n_write_io_threads,
1326
SRV_MAX_N_PENDING_SYNC_IOS);
1328
fil_init(srv_file_per_table ? 50000 : 5000,
1329
srv_max_n_open_files);
1214
fil_init(srv_max_n_open_files);
1331
1216
ret = buf_pool_init();