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
/********************************************************************//**
54
Starts the InnoDB database server
56
Created 2/16/1996 Heikki Tuuri
57
*************************************************************************/
61
#include "data0data.h"
62
#include "data0type.h"
63
#include "dict0dict.h"
66
#include "os0thread.h"
73
#include "page0page.h"
80
#include "ibuf0ibuf.h"
81
#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 */
111
UNIV_INTERN ib_uint64_t srv_start_lsn;
112
/** Log sequence number at shutdown */
113
UNIV_INTERN ib_uint64_t srv_shutdown_lsn;
115
#ifdef HAVE_DARWIN_THREADS
116
# include <sys/utsname.h>
117
/** TRUE if the F_FULLFSYNC option is available */
118
UNIV_INTERN ibool srv_have_fullfsync = FALSE;
121
/** TRUE if a raw partition is in use */
122
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
UNIV_INTERN ibool srv_startup_is_before_trx_rollback_phase = FALSE;
127
/** TRUE if the server is being started */
128
UNIV_INTERN ibool srv_is_being_started = FALSE;
129
/** TRUE if the server was successfully started */
130
UNIV_INTERN ibool srv_was_started = FALSE;
131
/** TRUE if innobase_start_or_create_for_mysql() has been called */
132
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 */
139
static os_file_t files[1000];
141
/** Mutex protecting the ios count */
142
static mutex_t ios_mutex;
143
/** Count of I/O operations in io_handler_thread() */
146
/** io_handler_thread parameters for thread identification */
147
static ulint n[SRV_MAX_N_IO_THREADS + 5];
148
/** io_handler_thread identifiers */
149
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
152
on successful locking. HP-UX does NOT return 0, though Linux et al do. */
153
static os_fast_mutex_t srv_os_test_mutex;
155
/** Name of srv_monitor_file */
156
static char* srv_monitor_file_name;
157
#endif /* !UNIV_HOTBACKUP */
160
#define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD
161
#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 */
172
char* str, /*!< in: string containing a quantity in bytes */
173
ulint* megs) /*!< out: the number in megabytes */
178
size = strtoul(str, &endp, 10);
198
/*********************************************************************//**
199
Reads the data files and their sizes from a character string given in
201
@return TRUE if ok, FALSE on parse error */
204
srv_parse_data_file_paths_and_sizes(
205
/*================================*/
206
char* str) /*!< in/out: the data file path string */
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;
221
/* First calculate the number of data files and check syntax:
222
path:size[M | G];path:size[M | G]... . Note that a Windows path may
223
contain a drive name and a ':'. */
225
while (*str != '\0') {
228
while ((*str != ':' && *str != '\0')
230
&& (*(str + 1) == '\\' || *(str + 1) == '/'
231
|| *(str + 1) == ':'))) {
241
str = srv_parse_megabytes(str, &size);
243
if (0 == strncmp(str, ":autoextend",
244
(sizeof ":autoextend") - 1)) {
246
str += (sizeof ":autoextend") - 1;
248
if (0 == strncmp(str, ":max:",
249
(sizeof ":max:") - 1)) {
251
str += (sizeof ":max:") - 1;
253
str = srv_parse_megabytes(str, &size);
265
&& *(str + 2) == 'w') {
269
if (*str == 'r' && *(str + 1) == 'a' && *(str + 2) == 'w') {
281
} else if (*str != '\0') {
288
/* If innodb_data_file_path was defined it must contain
289
at least one data file definition */
294
srv_data_file_names = malloc(i * sizeof *srv_data_file_names);
295
srv_data_file_sizes = malloc(i * sizeof *srv_data_file_sizes);
296
srv_data_file_is_raw_partition = malloc(
297
i * sizeof *srv_data_file_is_raw_partition);
299
srv_n_data_files = i;
301
/* Then store the actual values to our arrays */
306
while (*str != '\0') {
309
/* Note that we must step over the ':' in a Windows path;
310
a Windows path normally looks like C:\ibdata\ibdata1:1G, but
311
a Windows raw partition may have a specification like
312
\\.\C::1Gnewraw or \\.\PHYSICALDRIVE2:1Gnewraw */
314
while ((*str != ':' && *str != '\0')
316
&& (*(str + 1) == '\\' || *(str + 1) == '/'
317
|| *(str + 1) == ':'))) {
322
/* Make path a null-terminated string */
327
str = srv_parse_megabytes(str, &size);
329
srv_data_file_names[i] = path;
330
srv_data_file_sizes[i] = size;
332
if (0 == strncmp(str, ":autoextend",
333
(sizeof ":autoextend") - 1)) {
335
srv_auto_extend_last_data_file = TRUE;
337
str += (sizeof ":autoextend") - 1;
339
if (0 == strncmp(str, ":max:",
340
(sizeof ":max:") - 1)) {
342
str += (sizeof ":max:") - 1;
344
str = srv_parse_megabytes(
345
str, &srv_last_file_size_max);
354
(srv_data_file_is_raw_partition)[i] = 0;
359
&& *(str + 2) == 'w') {
361
(srv_data_file_is_raw_partition)[i] = SRV_NEW_RAW;
364
if (*str == 'r' && *(str + 1) == 'a' && *(str + 2) == 'w') {
367
if ((srv_data_file_is_raw_partition)[i] == 0) {
368
(srv_data_file_is_raw_partition)[i] = SRV_OLD_RAW;
382
/*********************************************************************//**
383
Reads log group home directories from a character string given in
385
@return TRUE if ok, FALSE on parse error */
388
srv_parse_log_group_home_dirs(
389
/*==========================*/
390
char* str) /*!< in/out: character string */
396
srv_log_group_home_dirs = NULL;
400
/* First calculate the number of directories and check syntax:
403
while (*str != '\0') {
406
while (*str != ';' && *str != '\0') {
414
} else if (*str != '\0') {
421
/* If innodb_log_group_home_dir was defined it must
422
contain exactly one path definition under current MySQL */
427
srv_log_group_home_dirs = malloc(i * sizeof *srv_log_group_home_dirs);
429
/* Then store the actual values to our array */
434
while (*str != '\0') {
437
while (*str != ';' && *str != '\0') {
446
srv_log_group_home_dirs[i] = path;
454
/*********************************************************************//**
455
Frees the memory allocated by srv_parse_data_file_paths_and_sizes()
456
and srv_parse_log_group_home_dirs(). */
459
srv_free_paths_and_sizes(void)
460
/*==========================*/
462
free(srv_data_file_names);
463
srv_data_file_names = NULL;
464
free(srv_data_file_sizes);
465
srv_data_file_sizes = NULL;
466
free(srv_data_file_is_raw_partition);
467
srv_data_file_is_raw_partition = NULL;
468
free(srv_log_group_home_dirs);
469
srv_log_group_home_dirs = NULL;
472
#ifndef UNIV_HOTBACKUP
473
/********************************************************************//**
474
I/o-handler thread function.
475
@return OS_THREAD_DUMMY_RETURN */
480
void* arg) /*!< in: pointer to the number of the segment in
486
segment = *((ulint*)arg);
488
#ifdef UNIV_DEBUG_THREAD_CREATION
489
fprintf(stderr, "Io handler thread %lu starts, id %lu\n", segment,
490
os_thread_pf(os_thread_get_curr_id()));
493
fil_aio_wait(segment);
495
mutex_enter(&ios_mutex);
497
mutex_exit(&ios_mutex);
500
/* We count the number of threads in os_thread_exit(). A created
501
thread should always use that to exit and not use return() to exit.
502
The thread actually never comes here because it is exited in an
504
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
508
#endif /* !UNIV_HOTBACKUP */
511
#define SRV_PATH_SEPARATOR '\\'
513
#define SRV_PATH_SEPARATOR '/'
516
/*********************************************************************//**
517
Normalizes a directory path for Windows: converts slashes to backslashes. */
520
srv_normalize_path_for_win(
521
/*=======================*/
522
char* str __attribute__((unused))) /*!< in/out: null-terminated
526
for (; *str; str++) {
535
/*********************************************************************//**
536
Adds a slash or a backslash to the end of a string if it is missing
537
and the string is not empty.
538
@return string which has the separator if the string is not empty */
541
srv_add_path_separator_if_needed(
542
/*=============================*/
543
char* str) /*!< in: null-terminated character string */
546
ulint len = ut_strlen(str);
548
if (len == 0 || str[len - 1] == SRV_PATH_SEPARATOR) {
553
out_str = ut_malloc(len + 2);
554
memcpy(out_str, str, len);
555
out_str[len] = SRV_PATH_SEPARATOR;
556
out_str[len + 1] = 0;
561
#ifndef UNIV_HOTBACKUP
562
/*********************************************************************//**
563
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 */
570
ulint file_size) /*!< in: file size in database pages */
572
return(0xFFFFFFFFUL & (file_size << UNIV_PAGE_SIZE_SHIFT));
575
/*********************************************************************//**
576
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 */
583
ulint file_size) /*!< in: file size in database pages */
585
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 */
593
open_or_create_log_file(
594
/*====================*/
595
ibool create_new_db, /*!< in: TRUE if we should create a
597
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
600
opened before: then it is an error
601
to try to create another log file */
602
ulint k, /*!< in: log group number */
603
ulint i) /*!< in: log file number in group */
610
UT_NOT_USED(create_new_db);
612
*log_file_created = FALSE;
614
srv_normalize_path_for_win(srv_log_group_home_dirs[k]);
615
srv_log_group_home_dirs[k] = srv_add_path_separator_if_needed(
616
srv_log_group_home_dirs[k]);
618
ut_a(strlen(srv_log_group_home_dirs[k])
619
< (sizeof name) - 10 - sizeof "ib_logfile");
620
sprintf(name, "%s%s%lu", srv_log_group_home_dirs[k],
621
"ib_logfile", (ulong) i);
623
files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_NORMAL,
626
if (os_file_get_last_error(FALSE) != OS_FILE_ALREADY_EXISTS
628
/* AIX 5.1 after security patch ML7 may have errno set
629
to 0 here, which causes our function to return 100;
630
work around that AIX problem */
631
&& os_file_get_last_error(FALSE) != 100
635
"InnoDB: Error in creating"
636
" or opening %s\n", name);
641
files[i] = os_file_create(name, OS_FILE_OPEN, OS_FILE_AIO,
645
"InnoDB: Error in opening %s\n", name);
650
ret = os_file_get_size(files[i], &size, &size_high);
653
if (size != srv_calc_low32(srv_log_file_size)
654
|| size_high != srv_calc_high32(srv_log_file_size)) {
657
"InnoDB: Error: log file %s is"
658
" of different size %lu %lu bytes\n"
659
"InnoDB: than specified in the .cnf"
660
" file %lu %lu bytes!\n",
661
name, (ulong) size_high, (ulong) size,
662
(ulong) srv_calc_high32(srv_log_file_size),
663
(ulong) srv_calc_low32(srv_log_file_size));
668
*log_file_created = TRUE;
670
ut_print_timestamp(stderr);
673
" InnoDB: Log file %s did not exist:"
674
" new to be created\n",
676
if (log_file_has_been_opened) {
681
fprintf(stderr, "InnoDB: Setting log file %s size to %lu MB\n",
682
name, (ulong) srv_log_file_size
683
>> (20 - UNIV_PAGE_SIZE_SHIFT));
686
"InnoDB: Database physically writes the file"
689
ret = os_file_set_size(name, files[i],
690
srv_calc_low32(srv_log_file_size),
691
srv_calc_high32(srv_log_file_size));
694
"InnoDB: Error in creating %s:"
695
" probably out of disk space\n",
702
ret = os_file_close(files[i]);
706
/* Create in memory the file space object
707
which is for this log group */
709
fil_space_create(name,
710
2 * k + SRV_LOG_SPACE_FIRST_ID, 0, FIL_LOG);
713
ut_a(fil_validate());
715
fil_node_create(name, srv_log_file_size,
716
2 * k + SRV_LOG_SPACE_FIRST_ID, FALSE);
717
#ifdef UNIV_LOG_ARCHIVE
718
/* If this is the first log group, create the file space object
720
Under MySQL, no archiving ever done. */
722
if (k == 0 && i == 0) {
723
arch_space_id = 2 * k + 1 + SRV_LOG_SPACE_FIRST_ID;
725
fil_space_create("arch_log_space", arch_space_id, 0, FIL_LOG);
727
arch_space_id = ULINT_UNDEFINED;
729
#endif /* UNIV_LOG_ARCHIVE */
731
log_group_init(k, srv_n_log_files,
732
srv_log_file_size * UNIV_PAGE_SIZE,
733
2 * k + SRV_LOG_SPACE_FIRST_ID,
734
SRV_LOG_SPACE_FIRST_ID + 1); /* dummy arch
741
/*********************************************************************//**
742
Creates or opens database data files and closes them.
743
@return DB_SUCCESS or error code */
746
open_or_create_data_files(
747
/*======================*/
748
ibool* create_new_db, /*!< out: TRUE if new database should be
750
#ifdef UNIV_LOG_ARCHIVE
751
ulint* min_arch_log_no,/*!< out: min of archived log
752
numbers in data files */
753
ulint* max_arch_log_no,/*!< out: max of archived log
754
numbers in data files */
755
#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
765
ibool one_opened = FALSE;
766
ibool one_created = FALSE;
769
ulint rounded_size_pages;
772
if (srv_n_data_files >= 1000) {
773
fprintf(stderr, "InnoDB: can only have < 1000 data files\n"
774
"InnoDB: you have defined %lu\n",
775
(ulong) srv_n_data_files);
779
*sum_of_new_sizes = 0;
781
*create_new_db = FALSE;
783
srv_normalize_path_for_win(srv_data_home);
784
srv_data_home = srv_add_path_separator_if_needed(srv_data_home);
786
for (i = 0; i < srv_n_data_files; i++) {
787
srv_normalize_path_for_win(srv_data_file_names[i]);
789
ut_a(strlen(srv_data_home) + strlen(srv_data_file_names[i])
790
< (sizeof name) - 1);
791
sprintf(name, "%s%s", srv_data_home, srv_data_file_names[i]);
793
if (srv_data_file_is_raw_partition[i] == 0) {
795
/* First we try to create the file: if it already
796
exists, ret will get value FALSE */
798
files[i] = os_file_create(name, OS_FILE_CREATE,
802
if (ret == FALSE && os_file_get_last_error(FALSE)
803
!= OS_FILE_ALREADY_EXISTS
805
/* AIX 5.1 after security patch ML7 may have
806
errno set to 0 here, which causes our function
807
to return 100; work around that AIX problem */
808
&& os_file_get_last_error(FALSE) != 100
812
"InnoDB: Error in creating"
818
} else if (srv_data_file_is_raw_partition[i] == SRV_NEW_RAW) {
819
/* The partition is opened, not created; then it is
822
srv_start_raw_disk_in_use = TRUE;
823
srv_created_new_raw = TRUE;
825
files[i] = os_file_create(name, OS_FILE_OPEN_RAW,
830
"InnoDB: Error in opening %s\n", name);
834
} else if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
835
srv_start_raw_disk_in_use = TRUE;
843
/* We open the data file */
847
"InnoDB: Error: data files can only"
848
" be added at the end\n");
850
"InnoDB: of a tablespace, but"
851
" data file %s existed beforehand.\n",
856
if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
857
files[i] = os_file_create(
858
name, OS_FILE_OPEN_RAW,
859
OS_FILE_NORMAL, OS_DATA_FILE, &ret);
861
files[i] = os_file_create(
862
name, OS_FILE_OPEN_RETRY,
863
OS_FILE_NORMAL, OS_DATA_FILE, &ret);
865
files[i] = os_file_create(
866
name, OS_FILE_OPEN, OS_FILE_NORMAL,
872
"InnoDB: Error in opening %s\n", name);
873
os_file_get_last_error(TRUE);
878
if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
880
goto skip_size_check;
883
ret = os_file_get_size(files[i], &size, &size_high);
885
/* Round size downward to megabytes */
888
= (size / (1024 * 1024) + 4096 * size_high)
889
<< (20 - UNIV_PAGE_SIZE_SHIFT);
891
if (i == srv_n_data_files - 1
892
&& srv_auto_extend_last_data_file) {
894
if (srv_data_file_sizes[i] > rounded_size_pages
895
|| (srv_last_file_size_max > 0
896
&& srv_last_file_size_max
897
< rounded_size_pages)) {
900
"InnoDB: Error: auto-extending"
902
" of a different size\n"
903
"InnoDB: %lu pages (rounded"
904
" down to MB) than specified"
905
" in the .cnf file:\n"
906
"InnoDB: initial %lu pages,"
907
" max %lu (relevant if"
908
" non-zero) pages!\n",
910
(ulong) rounded_size_pages,
911
(ulong) srv_data_file_sizes[i],
913
srv_last_file_size_max);
918
srv_data_file_sizes[i] = rounded_size_pages;
921
if (rounded_size_pages != srv_data_file_sizes[i]) {
924
"InnoDB: Error: data file %s"
925
" is of a different size\n"
927
" (rounded down to MB)\n"
928
"InnoDB: than specified"
929
" in the .cnf file %lu pages!\n",
931
(ulong) rounded_size_pages,
932
(ulong) srv_data_file_sizes[i]);
937
fil_read_flushed_lsn_and_arch_log_no(
938
files[i], one_opened,
939
#ifdef UNIV_LOG_ARCHIVE
940
min_arch_log_no, max_arch_log_no,
941
#endif /* UNIV_LOG_ARCHIVE */
942
min_flushed_lsn, max_flushed_lsn);
945
/* We created the data file and now write it full of
951
ut_print_timestamp(stderr);
953
" InnoDB: Data file %s did not"
954
" exist: new to be created\n",
958
"InnoDB: The first specified"
959
" data file %s did not exist:\n"
960
"InnoDB: a new database"
961
" to be created!\n", name);
962
*create_new_db = TRUE;
965
ut_print_timestamp(stderr);
967
" InnoDB: Setting file %s size to %lu MB\n",
969
(ulong) (srv_data_file_sizes[i]
970
>> (20 - UNIV_PAGE_SIZE_SHIFT)));
973
"InnoDB: Database physically writes the"
974
" file full: wait...\n");
976
ret = os_file_set_size(
978
srv_calc_low32(srv_data_file_sizes[i]),
979
srv_calc_high32(srv_data_file_sizes[i]));
983
"InnoDB: Error in creating %s:"
984
" probably out of disk space\n", name);
989
*sum_of_new_sizes = *sum_of_new_sizes
990
+ srv_data_file_sizes[i];
993
ret = os_file_close(files[i]);
997
fil_space_create(name, 0, 0, FIL_TABLESPACE);
1000
ut_a(fil_validate());
1002
fil_node_create(name, srv_data_file_sizes[i], 0,
1003
srv_data_file_is_raw_partition[i] != 0);
1008
mutex_create(&ios_mutex, SYNC_NO_ORDER_CHECK);
1013
/****************************************************************//**
1014
Starts InnoDB and creates a new database if database files
1015
are not found and the user wants.
1016
@return DB_SUCCESS or error code */
1019
innobase_start_or_create_for_mysql(void)
1020
/*====================================*/
1023
ibool create_new_db;
1024
ibool log_file_created;
1025
ibool log_created = FALSE;
1026
ibool log_opened = FALSE;
1027
ib_uint64_t min_flushed_lsn;
1028
ib_uint64_t max_flushed_lsn;
1029
#ifdef UNIV_LOG_ARCHIVE
1030
ulint min_arch_log_no;
1031
ulint max_arch_log_no;
1032
#endif /* UNIV_LOG_ARCHIVE */
1033
ulint sum_of_new_sizes;
1034
ulint sum_of_data_file_sizes;
1035
ulint tablespace_size_in_header;
1039
my_bool srv_file_per_table_original_value
1040
= srv_file_per_table;
1042
#ifdef HAVE_DARWIN_THREADS
1044
/* This executable has been compiled on Mac OS X 10.3 or later.
1045
Assume that F_FULLFSYNC is available at run-time. */
1046
srv_have_fullfsync = TRUE;
1047
# else /* F_FULLFSYNC */
1048
/* This executable has been compiled on Mac OS X 10.2
1049
or earlier. Determine if the executable is running
1050
on Mac OS X 10.3 or later. */
1051
struct utsname utsname;
1052
if (uname(&utsname)) {
1053
fputs("InnoDB: cannot determine Mac OS X version!\n", stderr);
1055
srv_have_fullfsync = strcmp(utsname.release, "7.") >= 0;
1057
if (!srv_have_fullfsync) {
1058
fputs("InnoDB: On Mac OS X, fsync() may be"
1059
" broken on internal drives,\n"
1060
"InnoDB: making transactions unsafe!\n", stderr);
1062
# endif /* F_FULLFSYNC */
1063
#endif /* HAVE_DARWIN_THREADS */
1065
if (sizeof(ulint) != sizeof(void*)) {
1067
"InnoDB: Error: size of InnoDB's ulint is %lu,"
1068
" but size of void* is %lu.\n"
1069
"InnoDB: The sizes should be the same"
1070
" so that on a 64-bit platform you can\n"
1071
"InnoDB: allocate more than 4 GB of memory.",
1072
(ulong)sizeof(ulint), (ulong)sizeof(void*));
1075
/* System tables are created in tablespace 0. Thus, we must
1076
temporarily clear srv_file_per_table. This is ok, because the
1077
server will not accept connections (which could modify
1078
innodb_file_per_table) until this function has returned. */
1079
srv_file_per_table = FALSE;
1082
"InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!\n");
1085
#ifdef UNIV_IBUF_DEBUG
1087
"InnoDB: !!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!\n"
1088
"InnoDB: Crash recovery will fail with UNIV_IBUF_DEBUG\n");
1091
#ifdef UNIV_SYNC_DEBUG
1093
"InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!\n");
1096
#ifdef UNIV_SEARCH_DEBUG
1098
"InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n");
1101
#ifdef UNIV_MEM_DEBUG
1103
"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
/* Since InnoDB does not currently clean up all its internal data
1141
structures in MySQL Embedded Server Library server_end(), we
1142
print an error message if someone tries to start up InnoDB a
1143
second time during the process lifetime. */
1145
if (srv_start_has_been_called) {
1147
"InnoDB: Error:startup called second time"
1148
" during the process lifetime.\n"
1149
"InnoDB: In the MySQL Embedded Server Library"
1150
" you cannot call server_init()\n"
1151
"InnoDB: more than once during"
1152
" the process lifetime.\n");
1155
srv_start_has_been_called = TRUE;
1158
log_do_write = TRUE;
1159
#endif /* UNIV_DEBUG */
1160
/* yydebug = TRUE; */
1162
srv_is_being_started = TRUE;
1163
srv_startup_is_before_trx_rollback_phase = TRUE;
1164
os_aio_use_native_aio = FALSE;
1167
switch (os_get_os_version()) {
1171
/* On Win 95, 98, ME, Win32 subsystem for Windows 3.1,
1172
and NT use simulated aio. In NT Windows provides async i/o,
1173
but when run in conjunction with InnoDB Hot Backup, it seemed
1174
to corrupt the data files. */
1176
os_aio_use_native_aio = FALSE;
1179
/* On Win 2000 and XP use async i/o */
1180
os_aio_use_native_aio = TRUE;
1184
if (srv_file_flush_method_str == NULL) {
1185
/* These are the default options */
1187
srv_unix_file_flush_method = SRV_UNIX_FSYNC;
1189
srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1191
} else if (0 == ut_strcmp(srv_file_flush_method_str, "fsync")) {
1192
srv_unix_file_flush_method = SRV_UNIX_FSYNC;
1194
} else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) {
1195
srv_unix_file_flush_method = SRV_UNIX_O_DSYNC;
1197
} else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) {
1198
srv_unix_file_flush_method = SRV_UNIX_O_DIRECT;
1200
} else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) {
1201
srv_unix_file_flush_method = SRV_UNIX_LITTLESYNC;
1203
} else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) {
1204
srv_unix_file_flush_method = SRV_UNIX_NOSYNC;
1206
} else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
1207
srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
1208
os_aio_use_native_aio = FALSE;
1210
} else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
1211
srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1212
os_aio_use_native_aio = FALSE;
1214
} else if (0 == ut_strcmp(srv_file_flush_method_str,
1215
"async_unbuffered")) {
1216
srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1220
"InnoDB: Unrecognized value %s for"
1221
" innodb_flush_method\n",
1222
srv_file_flush_method_str);
1226
/* Note that the call srv_boot() also changes the values of
1227
some variables to the units used by InnoDB internally */
1229
/* Set the maximum number of threads which can wait for a semaphore
1230
inside InnoDB: this is the 'sync wait array' size, as well as the
1231
maximum number of threads that can wait in the 'srv_conc array' for
1232
their time to enter InnoDB. */
1234
#if defined(__NETWARE__)
1236
/* Create less event semaphores because Win 98/ME had
1237
difficulty creating 40000 event semaphores. Comment from
1238
Novell, Inc.: also, these just take a lot of memory on
1240
srv_max_n_threads = 1000;
1242
if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
1243
/* If buffer pool is less than 1000 MB,
1244
assume fewer threads. */
1245
srv_max_n_threads = 50000;
1247
} else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
1249
srv_max_n_threads = 10000;
1251
srv_max_n_threads = 1000; /* saves several MB of memory,
1252
especially in 64-bit
1258
if (err != DB_SUCCESS) {
1263
mutex_create(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
1265
if (srv_innodb_status) {
1266
srv_monitor_file_name = mem_alloc(
1267
strlen(fil_path_to_mysql_datadir)
1268
+ 20 + sizeof "/innodb_status.");
1269
sprintf(srv_monitor_file_name, "%s/innodb_status.%lu",
1270
fil_path_to_mysql_datadir, os_proc_get_number());
1271
srv_monitor_file = fopen(srv_monitor_file_name, "w+");
1272
if (!srv_monitor_file) {
1273
fprintf(stderr, "InnoDB: unable to create %s: %s\n",
1274
srv_monitor_file_name, strerror(errno));
1278
srv_monitor_file_name = NULL;
1279
srv_monitor_file = os_file_create_tmpfile();
1280
if (!srv_monitor_file) {
1285
mutex_create(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
1287
srv_dict_tmpfile = os_file_create_tmpfile();
1288
if (!srv_dict_tmpfile) {
1292
mutex_create(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
1294
srv_misc_tmpfile = os_file_create_tmpfile();
1295
if (!srv_misc_tmpfile) {
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");
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
if (!os_aio_use_native_aio) {
1318
io_limit = 8 * SRV_N_PENDING_IOS_PER_THREAD;
1320
io_limit = SRV_N_PENDING_IOS_PER_THREAD;
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);
1331
ret = buf_pool_init();
1335
"InnoDB: Fatal error: cannot allocate the memory"
1336
" for the buffer pool\n");
1342
/* We have observed deadlocks with a 5MB buffer pool but
1343
the actual lower limit could very well be a little higher. */
1345
if (srv_buf_pool_size <= 5 * 1024 * 1024) {
1347
fprintf(stderr, "InnoDB: Warning: Small buffer pool size "
1348
"(%luM), the flst_validate() debug function "
1349
"can cause a deadlock if the buffer pool fills up.\n",
1350
srv_buf_pool_size / 1024 / 1024);
1357
lock_sys_create(srv_lock_table_size);
1359
/* Create i/o-handler threads: */
1361
for (i = 0; i < srv_n_file_io_threads; i++) {
1364
os_thread_create(io_handler_thread, n + i, thread_ids + i);
1367
#ifdef UNIV_LOG_ARCHIVE
1368
if (0 != ut_strcmp(srv_log_group_home_dirs[0], srv_arch_dir)) {
1370
"InnoDB: Error: you must set the log group"
1371
" home dir in my.cnf the\n"
1372
"InnoDB: same as log arch dir.\n");
1376
#endif /* UNIV_LOG_ARCHIVE */
1378
if (srv_n_log_files * srv_log_file_size >= 262144) {
1380
"InnoDB: Error: combined size of log files"
1381
" must be < 4 GB\n");
1386
sum_of_new_sizes = 0;
1388
for (i = 0; i < srv_n_data_files; i++) {
1390
if (sizeof(off_t) < 5 && srv_data_file_sizes[i] >= 262144) {
1392
"InnoDB: Error: file size must be < 4 GB"
1393
" with this MySQL binary\n"
1394
"InnoDB: and operating system combination,"
1395
" in some OS's < 2 GB\n");
1400
sum_of_new_sizes += srv_data_file_sizes[i];
1403
if (sum_of_new_sizes < 640) {
1405
"InnoDB: Error: tablespace size must be"
1406
" at least 10 MB\n");
1411
err = open_or_create_data_files(&create_new_db,
1412
#ifdef UNIV_LOG_ARCHIVE
1413
&min_arch_log_no, &max_arch_log_no,
1414
#endif /* UNIV_LOG_ARCHIVE */
1415
&min_flushed_lsn, &max_flushed_lsn,
1417
if (err != DB_SUCCESS) {
1419
"InnoDB: Could not open or create data files.\n"
1420
"InnoDB: If you tried to add new data files,"
1421
" and it failed here,\n"
1422
"InnoDB: you should now edit innodb_data_file_path"
1424
"InnoDB: to what it was, and remove the"
1425
" new ibdata files InnoDB created\n"
1426
"InnoDB: in this failed attempt. InnoDB only wrote"
1427
" those files full of\n"
1428
"InnoDB: zeros, but did not yet use them in any way."
1429
" But be careful: do not\n"
1430
"InnoDB: remove old data files"
1431
" which contain your precious data!\n");
1436
#ifdef UNIV_LOG_ARCHIVE
1437
srv_normalize_path_for_win(srv_arch_dir);
1438
srv_arch_dir = srv_add_path_separator_if_needed(srv_arch_dir);
1439
#endif /* UNIV_LOG_ARCHIVE */
1441
for (i = 0; i < srv_n_log_files; i++) {
1442
err = open_or_create_log_file(create_new_db, &log_file_created,
1444
if (err != DB_SUCCESS) {
1449
if (log_file_created) {
1454
if ((log_opened && create_new_db)
1455
|| (log_opened && log_created)) {
1457
"InnoDB: Error: all log files must be"
1458
" created at the same time.\n"
1459
"InnoDB: All log files must be"
1460
" created also in database creation.\n"
1461
"InnoDB: If you want bigger or smaller"
1462
" log files, shut down the\n"
1463
"InnoDB: database and make sure there"
1464
" were no errors in shutdown.\n"
1465
"InnoDB: Then delete the existing log files."
1466
" Edit the .cnf file\n"
1467
"InnoDB: and start the database again.\n");
1473
/* Open all log files and data files in the system tablespace: we
1474
keep them open until database shutdown */
1476
fil_open_log_and_system_tablespace_files();
1478
if (log_created && !create_new_db
1479
#ifdef UNIV_LOG_ARCHIVE
1480
&& !srv_archive_recovery
1481
#endif /* UNIV_LOG_ARCHIVE */
1483
if (max_flushed_lsn != min_flushed_lsn
1484
#ifdef UNIV_LOG_ARCHIVE
1485
|| max_arch_log_no != min_arch_log_no
1486
#endif /* UNIV_LOG_ARCHIVE */
1489
"InnoDB: Cannot initialize created"
1490
" log files because\n"
1491
"InnoDB: data files were not in sync"
1492
" with each other\n"
1493
"InnoDB: or the data files are corrupt.\n");
1498
if (max_flushed_lsn < (ib_uint64_t) 1000) {
1500
"InnoDB: Cannot initialize created"
1501
" log files because\n"
1502
"InnoDB: data files are corrupt,"
1503
" or new data files were\n"
1504
"InnoDB: created when the database"
1505
" was started previous\n"
1506
"InnoDB: time but the database"
1507
" was not shut down\n"
1508
"InnoDB: normally after that.\n");
1513
mutex_enter(&(log_sys->mutex));
1515
#ifdef UNIV_LOG_ARCHIVE
1516
/* Do not + 1 arch_log_no because we do not use log
1518
recv_reset_logs(max_flushed_lsn, max_arch_log_no, TRUE);
1520
recv_reset_logs(max_flushed_lsn, TRUE);
1521
#endif /* UNIV_LOG_ARCHIVE */
1523
mutex_exit(&(log_sys->mutex));
1526
trx_sys_file_format_init();
1528
if (create_new_db) {
1530
fsp_header_init(0, sum_of_new_sizes, &mtr);
1536
srv_startup_is_before_trx_rollback_phase = FALSE;
1538
#ifdef UNIV_LOG_ARCHIVE
1539
} else if (srv_archive_recovery) {
1541
"InnoDB: Starting archive"
1542
" recovery from a backup...\n");
1543
err = recv_recovery_from_archive_start(
1544
min_flushed_lsn, srv_archive_recovery_limit_lsn,
1546
if (err != DB_SUCCESS) {
1550
/* Since ibuf init is in dict_boot, and ibuf is needed
1551
in any disk i/o, first call dict_boot */
1554
trx_sys_init_at_db_start();
1555
srv_startup_is_before_trx_rollback_phase = FALSE;
1557
/* Initialize the fsp free limit global variable in the log
1559
fsp_header_get_free_limit();
1561
recv_recovery_from_archive_finish();
1562
#endif /* UNIV_LOG_ARCHIVE */
1565
/* Check if we support the max format that is stamped
1566
on the system tablespace.
1567
Note: We are NOT allowed to make any modifications to
1568
the TRX_SYS_PAGE_NO page before recovery because this
1569
page also contains the max_trx_id etc. important system
1570
variables that are required for recovery. We need to
1571
ensure that we return the system to a state where normal
1572
recovery is guaranteed to work. We do this by
1573
invalidating the buffer cache, this will force the
1574
reread of the page and restoration to its last known
1575
consistent state, this is REQUIRED for the recovery
1577
err = trx_sys_file_format_max_check(
1578
srv_check_file_format_at_startup);
1580
if (err != DB_SUCCESS) {
1584
/* Invalidate the buffer pool to ensure that we reread
1585
the page that we read above, during recovery.
1586
Note that this is not as heavy weight as it seems. At
1587
this point there will be only ONE page in the buf_LRU
1588
and there must be no page in the buf_flush list. */
1589
buf_pool_invalidate();
1591
/* We always try to do a recovery, even if the database had
1592
been shut down normally: this is the normal startup path */
1594
err = recv_recovery_from_checkpoint_start(LOG_CHECKPOINT,
1598
if (err != DB_SUCCESS) {
1603
/* Since the insert buffer init is in dict_boot, and the
1604
insert buffer is needed in any disk i/o, first we call
1605
dict_boot(). Note that trx_sys_init_at_db_start() only needs
1606
to access space 0, and the insert buffer at this stage already
1607
works for space 0. */
1610
trx_sys_init_at_db_start();
1612
if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
1613
/* The following call is necessary for the insert
1614
buffer to work with multiple tablespaces. We must
1615
know the mapping between space id's and .ibd file
1618
In a crash recovery, we check that the info in data
1619
dictionary is consistent with what we already know
1620
about space id's from the call of
1621
fil_load_single_table_tablespaces().
1623
In a normal startup, we create the space objects for
1624
every table in the InnoDB data dictionary that has
1627
We also determine the maximum tablespace id used.
1629
TODO: We may have incomplete transactions in the
1630
data dictionary tables. Does that harm the scanning of
1631
the data dictionary below? */
1633
dict_check_tablespaces_and_store_max_id(
1634
recv_needed_recovery);
1637
srv_startup_is_before_trx_rollback_phase = FALSE;
1639
/* Initialize the fsp free limit global variable in the log
1641
fsp_header_get_free_limit();
1643
/* recv_recovery_from_checkpoint_finish needs trx lists which
1644
are initialized in trx_sys_init_at_db_start(). */
1646
recv_recovery_from_checkpoint_finish();
1648
/* It is possible that file_format tag has never
1649
been set. In this case we initialize it to minimum
1650
value. Important to note that we can do it ONLY after
1651
we have finished the recovery process so that the
1652
image of TRX_SYS_PAGE_NO is not stale. */
1653
trx_sys_file_format_tag_init();
1656
if (!create_new_db && sum_of_new_sizes > 0) {
1657
/* New data file(s) were added */
1660
fsp_header_inc_size(0, sum_of_new_sizes, &mtr);
1664
/* Immediately write the log record about increased tablespace
1665
size to disk, so that it is durable even if mysqld would crash
1668
log_buffer_flush_to_disk();
1671
#ifdef UNIV_LOG_ARCHIVE
1672
/* Archiving is always off under MySQL */
1673
if (!srv_log_archive_on) {
1674
ut_a(DB_SUCCESS == log_archive_noarchivelog());
1676
mutex_enter(&(log_sys->mutex));
1678
start_archive = FALSE;
1680
if (log_sys->archiving_state == LOG_ARCH_OFF) {
1681
start_archive = TRUE;
1684
mutex_exit(&(log_sys->mutex));
1686
if (start_archive) {
1687
ut_a(DB_SUCCESS == log_archive_archivelog());
1690
#endif /* UNIV_LOG_ARCHIVE */
1692
/* fprintf(stderr, "Max allowed record size %lu\n",
1693
page_get_free_space_of_empty() / 2); */
1695
/* Create the thread which watches the timeouts for lock waits
1696
and prints InnoDB monitor info */
1698
os_thread_create(&srv_lock_timeout_and_monitor_thread, NULL,
1699
thread_ids + 2 + SRV_MAX_N_IO_THREADS);
1701
/* Create the thread which warns of long semaphore waits */
1702
os_thread_create(&srv_error_monitor_thread, NULL,
1703
thread_ids + 3 + SRV_MAX_N_IO_THREADS);
1704
srv_is_being_started = FALSE;
1706
if (trx_doublewrite == NULL) {
1707
/* Create the doublewrite buffer to a new tablespace */
1709
trx_sys_create_doublewrite_buf();
1712
err = dict_create_or_check_foreign_constraint_tables();
1714
if (err != DB_SUCCESS) {
1715
return((int)DB_ERROR);
1718
/* Create the master thread which does purge and other utility
1721
os_thread_create(&srv_master_thread, NULL, thread_ids
1722
+ (1 + SRV_MAX_N_IO_THREADS));
1724
/* buf_debug_prints = TRUE; */
1725
#endif /* UNIV_DEBUG */
1726
sum_of_data_file_sizes = 0;
1728
for (i = 0; i < srv_n_data_files; i++) {
1729
sum_of_data_file_sizes += srv_data_file_sizes[i];
1732
tablespace_size_in_header = fsp_header_get_tablespace_size();
1734
if (!srv_auto_extend_last_data_file
1735
&& sum_of_data_file_sizes != tablespace_size_in_header) {
1738
"InnoDB: Error: tablespace size"
1739
" stored in header is %lu pages, but\n"
1740
"InnoDB: the sum of data file sizes is %lu pages\n",
1741
(ulong) tablespace_size_in_header,
1742
(ulong) sum_of_data_file_sizes);
1744
if (srv_force_recovery == 0
1745
&& sum_of_data_file_sizes < tablespace_size_in_header) {
1746
/* This is a fatal error, the tail of a tablespace is
1750
"InnoDB: Cannot start InnoDB."
1751
" The tail of the system tablespace is\n"
1752
"InnoDB: missing. Have you edited"
1753
" innodb_data_file_path in my.cnf in an\n"
1754
"InnoDB: inappropriate way, removing"
1755
" ibdata files from there?\n"
1756
"InnoDB: You can set innodb_force_recovery=1"
1757
" in my.cnf to force\n"
1758
"InnoDB: a startup if you are trying"
1759
" to recover a badly corrupt database.\n");
1765
if (srv_auto_extend_last_data_file
1766
&& sum_of_data_file_sizes < tablespace_size_in_header) {
1769
"InnoDB: Error: tablespace size stored in header"
1770
" is %lu pages, but\n"
1771
"InnoDB: the sum of data file sizes"
1772
" is only %lu pages\n",
1773
(ulong) tablespace_size_in_header,
1774
(ulong) sum_of_data_file_sizes);
1776
if (srv_force_recovery == 0) {
1779
"InnoDB: Cannot start InnoDB. The tail of"
1780
" the system tablespace is\n"
1781
"InnoDB: missing. Have you edited"
1782
" innodb_data_file_path in my.cnf in an\n"
1783
"InnoDB: inappropriate way, removing"
1784
" ibdata files from there?\n"
1785
"InnoDB: You can set innodb_force_recovery=1"
1786
" in my.cnf to force\n"
1787
"InnoDB: a startup if you are trying to"
1788
" recover a badly corrupt database.\n");
1794
/* Check that os_fast_mutexes work as expected */
1795
os_fast_mutex_init(&srv_os_test_mutex);
1797
if (0 != os_fast_mutex_trylock(&srv_os_test_mutex)) {
1799
"InnoDB: Error: pthread_mutex_trylock returns"
1800
" an unexpected value on\n"
1801
"InnoDB: success! Cannot continue.\n");
1805
os_fast_mutex_unlock(&srv_os_test_mutex);
1807
os_fast_mutex_lock(&srv_os_test_mutex);
1809
os_fast_mutex_unlock(&srv_os_test_mutex);
1811
os_fast_mutex_free(&srv_os_test_mutex);
1813
if (srv_print_verbose_log) {
1814
ut_print_timestamp(stderr);
1816
" InnoDB Plugin %s started; "
1817
"log sequence number %"PRIu64"\n",
1818
INNODB_VERSION_STR, srv_start_lsn);
1821
if (srv_force_recovery > 0) {
1823
"InnoDB: !!! innodb_force_recovery"
1824
" is set to %lu !!!\n",
1825
(ulong) srv_force_recovery);
1830
if (trx_doublewrite_must_reset_space_ids) {
1831
/* Actually, we did not change the undo log format between
1832
4.0 and 4.1.1, and we would not need to run purge to
1833
completion. Note also that the purge algorithm in 4.1.1
1834
can process the the history list again even after a full
1835
purge, because our algorithm does not cut the end of the
1836
history list in all cases so that it would become empty
1837
after a full purge. That mean that we may purge 4.0 type
1838
undo log even after this phase.
1840
The insert buffer record format changed between 4.0 and
1841
4.1.1. It is essential that the insert buffer is emptied
1845
"InnoDB: You are upgrading to an"
1846
" InnoDB version which allows multiple\n"
1847
"InnoDB: tablespaces. Wait that purge"
1848
" and insert buffer merge run to\n"
1849
"InnoDB: completion...\n");
1851
os_thread_sleep(1000000);
1853
if (0 == strcmp(srv_main_thread_op_info,
1854
"waiting for server activity")) {
1856
ut_a(ibuf_is_empty());
1862
"InnoDB: Full purge and insert buffer merge"
1865
trx_sys_mark_upgraded_to_multiple_tablespaces();
1868
"InnoDB: You have now successfully upgraded"
1869
" to the multiple tablespaces\n"
1870
"InnoDB: format. You should NOT DOWNGRADE"
1871
" to an earlier version of\n"
1872
"InnoDB: InnoDB! But if you absolutely need to"
1874
"InnoDB: " REFMAN "multiple-tablespaces.html\n"
1875
"InnoDB: for instructions.\n");
1878
if (srv_force_recovery == 0) {
1879
/* In the insert buffer we may have even bigger tablespace
1880
id's, because we may have dropped those tablespaces, but
1881
insert buffer merge has not had time to clean the records from
1884
ibuf_update_max_tablespace_id();
1887
srv_file_per_table = srv_file_per_table_original_value;
1889
srv_was_started = TRUE;
1891
return((int) DB_SUCCESS);
1894
/****************************************************************//**
1895
Shuts down the InnoDB database.
1896
@return DB_SUCCESS or error code */
1899
innobase_shutdown_for_mysql(void)
1900
/*=============================*/
1904
extern ibool panic_shutdown;
1906
if (!srv_was_started) {
1907
if (srv_is_being_started) {
1908
ut_print_timestamp(stderr);
1910
" InnoDB: Warning: shutting down"
1911
" a not properly started\n"
1912
"InnoDB: or created database!\n");
1918
/* 1. Flush the buffer pool to disk, write the current lsn to
1919
the tablespace header(s), and copy all log data to archive.
1920
The step 1 is the real InnoDB shutdown. The remaining steps 2 - ...
1921
just free data structures after the shutdown. */
1924
if (srv_fast_shutdown == 2) {
1925
ut_print_timestamp(stderr);
1927
" InnoDB: MySQL has requested a very fast shutdown"
1928
" without flushing "
1929
"the InnoDB buffer pool to data files."
1930
" At the next mysqld startup "
1931
"InnoDB will do a crash recovery!\n");
1935
if (!panic_shutdown)
1937
logs_empty_and_mark_files_at_shutdown();
1939
if (srv_conc_n_threads != 0) {
1941
"InnoDB: Warning: query counter shows %ld queries"
1943
"InnoDB: inside InnoDB at shutdown\n",
1944
srv_conc_n_threads);
1947
/* 2. Make all threads created by InnoDB to exit */
1949
srv_shutdown_state = SRV_SHUTDOWN_EXIT_THREADS;
1951
/* In a 'very fast' shutdown, we do not need to wait for these threads
1952
to die; all which counts is that we flushed the log; a 'very fast'
1953
shutdown is essentially a crash. */
1955
if (srv_fast_shutdown == 2) {
1959
/* All threads end up waiting for certain events. Put those events
1960
to the signaled state. Then the threads will exit themselves in
1961
os_thread_event_wait(). */
1963
for (i = 0; i < 1000; i++) {
1964
/* NOTE: IF YOU CREATE THREADS IN INNODB, YOU MUST EXIT THEM
1967
/* a. Let the lock timeout thread exit */
1968
os_event_set(srv_lock_timeout_thread_event);
1970
/* b. srv error monitor thread exits automatically, no need
1971
to do anything here */
1973
/* c. We wake the master thread so that it exits */
1974
srv_wake_master_thread();
1976
/* d. Exit the i/o threads */
1978
os_aio_wake_all_threads_at_shutdown();
1980
os_mutex_enter(os_sync_mutex);
1982
if (os_thread_count == 0) {
1983
/* All the threads have exited or are just exiting;
1984
NOTE that the threads may not have completed their
1985
exit yet. Should we use pthread_join() to make sure
1986
they have exited? Now we just sleep 0.1 seconds and
1987
hope that is enough! */
1989
os_mutex_exit(os_sync_mutex);
1991
os_thread_sleep(100000);
1996
os_mutex_exit(os_sync_mutex);
1998
os_thread_sleep(100000);
2003
"InnoDB: Warning: %lu threads created by InnoDB"
2004
" had not exited at shutdown!\n",
2005
(ulong) os_thread_count);
2008
if (srv_monitor_file) {
2009
fclose(srv_monitor_file);
2010
srv_monitor_file = 0;
2011
if (srv_monitor_file_name) {
2012
unlink(srv_monitor_file_name);
2013
mem_free(srv_monitor_file_name);
2016
if (srv_dict_tmpfile) {
2017
fclose(srv_dict_tmpfile);
2018
srv_dict_tmpfile = 0;
2021
if (srv_misc_tmpfile) {
2022
fclose(srv_misc_tmpfile);
2023
srv_misc_tmpfile = 0;
2026
trx_sys_file_format_close();
2028
mutex_free(&srv_monitor_file_mutex);
2029
mutex_free(&srv_dict_tmpfile_mutex);
2030
mutex_free(&srv_misc_tmpfile_mutex);
2032
/* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
2036
/* 4. Free the os_conc_mutex and all os_events and os_mutexes */
2041
/* Check that all read views are closed except read view owned
2044
if (UT_LIST_GET_LEN(trx_sys->view_list) > 1) {
2046
"InnoDB: Error: all read views were not closed"
2047
" before shutdown:\n"
2048
"InnoDB: %lu read views open \n",
2049
UT_LIST_GET_LEN(trx_sys->view_list) - 1);
2052
/* 5. Free all allocated memory and the os_fast_mutex created in
2058
if (os_thread_count != 0
2059
|| os_event_count != 0
2060
|| os_mutex_count != 0
2061
|| os_fast_mutex_count != 0) {
2063
"InnoDB: Warning: some resources were not"
2064
" cleaned up in shutdown:\n"
2065
"InnoDB: threads %lu, events %lu,"
2066
" os_mutexes %lu, os_fast_mutexes %lu\n",
2067
(ulong) os_thread_count, (ulong) os_event_count,
2068
(ulong) os_mutex_count, (ulong) os_fast_mutex_count);
2071
if (dict_foreign_err_file) {
2072
fclose(dict_foreign_err_file);
2074
if (lock_latest_err_file) {
2075
fclose(lock_latest_err_file);
2078
if (srv_print_verbose_log) {
2079
ut_print_timestamp(stderr);
2081
" InnoDB: Shutdown completed;"
2082
" log sequence number %"PRIu64"\n",
2086
srv_was_started = FALSE;
2088
return((int) DB_SUCCESS);
2092
void set_panic_flag_for_netware()
2094
extern ibool panic_shutdown;
2095
panic_shutdown = TRUE;
2097
#endif /* __NETWARE__ */
2098
#endif /* !UNIV_HOTBACKUP */