22
22
Place, Suite 330, Boston, MA 02111-1307 USA
24
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
/********************************************************************//**
26
/************************************************************************
54
27
Starts the InnoDB database server
56
29
Created 2/16/1996 Heikki Tuuri
57
30
*************************************************************************/
33
#include "sync0sync.h"
59
34
#include "ut0mem.h"
60
35
#include "mem0mem.h"
61
36
#include "data0data.h"
62
37
#include "data0type.h"
63
38
#include "dict0dict.h"
64
39
#include "buf0buf.h"
65
42
#include "os0file.h"
66
43
#include "os0thread.h"
67
44
#include "fil0fil.h"
68
45
#include "fsp0fsp.h"
69
46
#include "rem0rec.h"
70
48
#include "mtr0mtr.h"
71
49
#include "log0log.h"
72
50
#include "log0recv.h"
73
51
#include "page0page.h"
74
52
#include "page0cur.h"
75
53
#include "trx0trx.h"
54
#include "dict0boot.h"
55
#include "dict0load.h"
76
56
#include "trx0sys.h"
57
#include "dict0crea.h"
77
58
#include "btr0btr.h"
78
60
#include "btr0cur.h"
79
62
#include "rem0rec.h"
66
#include "lock0lock.h"
68
#include "trx0purge.h"
73
#include "row0mysql.h"
74
#include "lock0lock.h"
80
75
#include "ibuf0ibuf.h"
76
#include "pars0pars.h"
81
78
#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 */
81
/* Log sequence number immediately after startup */
111
82
UNIV_INTERN ib_uint64_t srv_start_lsn;
112
/** Log sequence number at shutdown */
83
/* Log sequence number at shutdown */
113
84
UNIV_INTERN ib_uint64_t srv_shutdown_lsn;
115
86
#ifdef HAVE_DARWIN_THREADS
116
87
# include <sys/utsname.h>
117
/** TRUE if the F_FULLFSYNC option is available */
118
88
UNIV_INTERN ibool srv_have_fullfsync = FALSE;
121
/** TRUE if a raw partition is in use */
122
91
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
93
UNIV_INTERN ibool srv_startup_is_before_trx_rollback_phase = FALSE;
127
/** TRUE if the server is being started */
128
94
UNIV_INTERN ibool srv_is_being_started = FALSE;
129
/** TRUE if the server was successfully started */
130
95
UNIV_INTERN ibool srv_was_started = FALSE;
131
/** TRUE if innobase_start_or_create_for_mysql() has been called */
96
#ifndef UNIV_HOTBACKUP
132
97
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 */
98
#endif /* !UNIV_HOTBACKUP */
100
/* At a shutdown the value first climbs to SRV_SHUTDOWN_CLEANUP
101
and then to SRV_SHUTDOWN_LAST_PHASE */
102
UNIV_INTERN ulint srv_shutdown_state = 0;
104
#ifndef UNIV_HOTBACKUP
139
105
static os_file_t files[1000];
141
/** Mutex protecting the ios count */
142
107
static mutex_t ios_mutex;
143
/** Count of I/O operations in io_handler_thread() */
144
108
static ulint ios;
146
/** io_handler_thread parameters for thread identification */
147
110
static ulint n[SRV_MAX_N_IO_THREADS + 5];
148
/** io_handler_thread identifiers */
149
111
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
113
/* We use this mutex to test the return value of pthread_mutex_trylock
152
114
on successful locking. HP-UX does NOT return 0, though Linux et al do. */
153
115
static os_fast_mutex_t srv_os_test_mutex;
155
/** Name of srv_monitor_file */
117
/* Name of srv_monitor_file */
156
118
static char* srv_monitor_file_name;
157
119
#endif /* !UNIV_HOTBACKUP */
160
121
#define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD
161
122
#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
127
srv_parse_megabytes(
171
128
/*================*/
172
char* str, /*!< in: string containing a quantity in bytes */
173
ulint* megs) /*!< out: the number in megabytes */
129
/* out: next character in string */
130
char* str, /* in: string containing a quantity in bytes */
131
ulint* megs) /* out: the number in megabytes */
561
519
#ifndef UNIV_HOTBACKUP
562
/*********************************************************************//**
520
/*************************************************************************
563
521
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 */
522
database pages is converted to the number of bytes. */
570
ulint file_size) /*!< in: file size in database pages */
527
/* out: low 32 bytes of file size when
528
expressed in bytes */
529
ulint file_size) /* in: file size in database pages */
572
531
return(0xFFFFFFFFUL & (file_size << UNIV_PAGE_SIZE_SHIFT));
575
/*********************************************************************//**
534
/*************************************************************************
576
535
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 */
536
database pages is converted to the number of bytes. */
583
ulint file_size) /*!< in: file size in database pages */
541
/* out: high 32 bytes of file size when
542
expressed in bytes */
543
ulint file_size) /* in: file size in database pages */
585
545
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 */
548
/*************************************************************************
549
Creates or opens the log files and closes them. */
593
552
open_or_create_log_file(
594
553
/*====================*/
595
ibool create_new_db, /*!< in: TRUE if we should create a
554
/* out: DB_SUCCESS or error code */
555
ibool create_new_db, /* in: TRUE if we should create a
597
ibool* log_file_created, /*!< out: TRUE if new log file
557
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
559
ibool log_file_has_been_opened,/* in: TRUE if a log file has been
600
560
opened before: then it is an error
601
561
to try to create another log file */
602
ulint k, /*!< in: log group number */
603
ulint i) /*!< in: log file number in group */
562
ulint k, /* in: log group number */
563
ulint i) /* in: log file number in group */
738
698
return(DB_SUCCESS);
741
/*********************************************************************//**
742
Creates or opens database data files and closes them.
743
@return DB_SUCCESS or error code */
701
/*************************************************************************
702
Creates or opens database data files and closes them. */
746
705
open_or_create_data_files(
747
706
/*======================*/
748
ibool* create_new_db, /*!< out: TRUE if new database should be
707
/* out: DB_SUCCESS or error code */
708
ibool* create_new_db, /* out: TRUE if new database should be
750
710
#ifdef UNIV_LOG_ARCHIVE
751
ulint* min_arch_log_no,/*!< out: min of archived log
711
ulint* min_arch_log_no,/* out: min of archived log
752
712
numbers in data files */
753
ulint* max_arch_log_no,/*!< out: max of archived log
713
ulint* max_arch_log_no,/* out: max of archived log
754
714
numbers in data files */
755
715
#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
716
ib_uint64_t* min_flushed_lsn,/* out: min of flushed lsn
717
values in data files */
718
ib_uint64_t* max_flushed_lsn,/* out: max of flushed lsn
719
values in data files */
720
ulint* sum_of_new_sizes)/* out: sum of sizes of the
761
721
new files added */
1111
1070
#ifdef HAVE_GCC_ATOMIC_BUILTINS
1112
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
1071
#ifdef INNODB_RW_LOCKS_USE_ATOMICS
1113
1072
fprintf(stderr,
1114
1073
"InnoDB: Mutexes and rw_locks use GCC atomic builtins.\n");
1115
# else /* INNODB_RW_LOCKS_USE_ATOMICS */
1074
#else /* INNODB_RW_LOCKS_USE_ATOMICS */
1116
1075
fprintf(stderr,
1117
1076
"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 */
1077
#endif /* INNODB_RW_LOCKS_USE_ATOMICS */
1135
1078
#else /* HAVE_GCC_ATOMIC_BUILTINS */
1136
1079
fprintf(stderr,
1137
1080
"InnoDB: Neither mutexes nor rw_locks use GCC atomic builtins.\n");
1164
1107
os_aio_use_native_aio = FALSE;
1167
switch (os_get_os_version()) {
1110
if (os_get_os_version() == OS_WIN95
1111
|| os_get_os_version() == OS_WIN31
1112
|| os_get_os_version() == OS_WINNT) {
1171
1114
/* On Win 95, 98, ME, Win32 subsystem for Windows 3.1,
1172
1115
and NT use simulated aio. In NT Windows provides async i/o,
1173
1116
but when run in conjunction with InnoDB Hot Backup, it seemed
1174
1117
to corrupt the data files. */
1176
1119
os_aio_use_native_aio = FALSE;
1179
1121
/* On Win 2000 and XP use async i/o */
1180
1122
os_aio_use_native_aio = TRUE;
1184
1125
if (srv_file_flush_method_str == NULL) {
1296
1237
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");
1240
/* Restrict the maximum number of file i/o threads */
1241
if (srv_n_file_io_threads > SRV_MAX_N_IO_THREADS) {
1243
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
1246
if (!os_aio_use_native_aio) {
1318
io_limit = 8 * SRV_N_PENDING_IOS_PER_THREAD;
1247
/* In simulated aio we currently have use only for 4 threads */
1248
srv_n_file_io_threads = 4;
1250
os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD
1251
* srv_n_file_io_threads,
1252
srv_n_file_io_threads,
1253
SRV_MAX_N_PENDING_SYNC_IOS);
1320
io_limit = SRV_N_PENDING_IOS_PER_THREAD;
1255
os_aio_init(SRV_N_PENDING_IOS_PER_THREAD
1256
* srv_n_file_io_threads,
1257
srv_n_file_io_threads,
1258
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);
1261
fil_init(srv_max_n_open_files);
1331
1263
ret = buf_pool_init();