~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Lee Bieber
  • Date: 2010-01-30 23:42:02 UTC
  • mto: This revision was merged to the branch mainline in revision 1282.
  • Revision ID: lbieber@lee-biebers-macbook-pro.local-20100130234202-sxmqfteqwiq15ptg
add target to japanese tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
4
4
Copyright (c) 2008, Google Inc.
5
 
Copyright (c) 2009, Percona Inc.
6
5
 
7
6
Portions of this file contain modifications contributed and copyrighted by
8
7
Google, Inc. Those modifications are gratefully acknowledged and are described
10
9
incorporated with their permission, and subject to the conditions contained in
11
10
the file COPYING.Google.
12
11
 
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
12
This program is free software; you can redistribute it and/or modify it under
21
13
the terms of the GNU General Public License as published by the Free Software
22
14
Foundation; version 2 of the License.
26
18
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
27
19
 
28
20
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
 
21
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
22
Place, Suite 330, Boston, MA 02111-1307 USA
31
23
 
32
24
*****************************************************************************/
 
25
/***********************************************************************
 
26
 
 
27
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 
28
Copyright (c) 2009, Percona Inc.
 
29
 
 
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
 
35
COPYING.Percona.
 
36
 
 
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.
 
40
 
 
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.
 
45
 
 
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
 
49
 
 
50
***********************************************************************/
33
51
 
34
52
/********************************************************************//**
35
53
@file srv/srv0start.c
85
103
# include "row0row.h"
86
104
# include "row0mysql.h"
87
105
# 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
106
 
92
107
#include <errno.h>
93
 
#include <unistd.h>
94
108
 
95
109
/** Log sequence number immediately after startup */
96
110
UNIV_INTERN ib_uint64_t srv_start_lsn;
129
143
static ulint            ios;
130
144
 
131
145
/** io_handler_thread parameters for thread identification */
132
 
static ulint            n[SRV_MAX_N_IO_THREADS + 6];
 
146
static ulint            n[SRV_MAX_N_IO_THREADS + 5];
133
147
/** io_handler_thread identifiers */
134
 
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 6];
 
148
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 5];
135
149
 
136
150
/** We use this mutex to test the return value of pthread_mutex_trylock
137
151
   on successful locking. HP-UX does NOT return 0, though Linux et al do. */
145
159
#define SRV_N_PENDING_IOS_PER_THREAD    OS_AIO_N_PENDING_IOS_PER_THREAD
146
160
#define SRV_MAX_N_PENDING_SYNC_IOS      100
147
161
 
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
 
162
163
/*********************************************************************//**
163
164
Convert a numeric string that optionally ends in G or M, to a number
479
480
                        the aio array */
480
481
{
481
482
        ulint   segment;
 
483
        ulint   i;
482
484
 
483
485
        segment = *((ulint*)arg);
484
486
 
486
488
        fprintf(stderr, "Io handler thread %lu starts, id %lu\n", segment,
487
489
                os_thread_pf(os_thread_get_curr_id()));
488
490
#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) {
 
491
        for (i = 0;; i++) {
495
492
                fil_aio_wait(segment);
496
493
 
497
494
                mutex_enter(&ios_mutex);
499
496
                mutex_exit(&ios_mutex);
500
497
        }
501
498
 
502
 
        thr_local_free(os_thread_get_curr_id());
503
 
 
504
499
        /* We count the number of threads in os_thread_exit(). A created
505
500
        thread should always use that to exit and not use return() to exit.
506
501
        The thread actually never comes here because it is exited in an
507
502
        os_event_wait(). */
 
503
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
508
504
        return 0;
 
505
#endif
509
506
}
510
507
#endif /* !UNIV_HOTBACKUP */
511
508
 
534
531
#endif
535
532
}
536
533
 
 
534
/*********************************************************************//**
 
535
Adds a slash or a backslash to the end of a string if it is missing
 
536
and the string is not empty.
 
537
@return string which has the separator if the string is not empty */
 
538
UNIV_INTERN
 
539
char*
 
540
srv_add_path_separator_if_needed(
 
541
/*=============================*/
 
542
        char*   str)    /*!< in: null-terminated character string */
 
543
{
 
544
        char*   out_str;
 
545
        ulint   len     = ut_strlen(str);
 
546
 
 
547
        if (len == 0 || str[len - 1] == SRV_PATH_SEPARATOR) {
 
548
 
 
549
                return(str);
 
550
        }
 
551
 
 
552
        out_str = ut_malloc(len + 2);
 
553
        memcpy(out_str, str, len);
 
554
        out_str[len] = SRV_PATH_SEPARATOR;
 
555
        out_str[len + 1] = 0;
 
556
 
 
557
        return(out_str);
 
558
}
 
559
 
537
560
#ifndef UNIV_HOTBACKUP
538
561
/*********************************************************************//**
539
562
Calculates the low 32 bits when a file size which is given as a number
582
605
        ulint   size;
583
606
        ulint   size_high;
584
607
        char    name[10000];
585
 
        ulint   dirnamelen;
586
608
 
587
609
        UT_NOT_USED(create_new_db);
588
610
 
589
611
        *log_file_created = FALSE;
590
612
 
591
613
        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,
 
614
        srv_log_group_home_dirs[k] = srv_add_path_separator_if_needed(
 
615
                srv_log_group_home_dirs[k]);
 
616
 
 
617
        ut_a(strlen(srv_log_group_home_dirs[k])
 
618
             < (sizeof name) - 10 - sizeof "ib_logfile");
 
619
        sprintf(name, "%s%s%lu", srv_log_group_home_dirs[k],
 
620
                "ib_logfile", (ulong) i);
 
621
 
 
622
        files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_NORMAL,
606
623
                                  OS_LOG_FILE, &ret);
607
624
        if (ret == FALSE) {
608
625
                if (os_file_get_last_error(FALSE) != OS_FILE_ALREADY_EXISTS
620
637
                        return(DB_ERROR);
621
638
                }
622
639
 
623
 
                files[i] = os_file_create(innodb_file_log_key, name,
624
 
                                          OS_FILE_OPEN, OS_FILE_AIO,
 
640
                files[i] = os_file_create(name, OS_FILE_OPEN, OS_FILE_AIO,
625
641
                                          OS_LOG_FILE, &ret);
626
642
                if (!ret) {
627
643
                        fprintf(stderr,
764
780
        *create_new_db = FALSE;
765
781
 
766
782
        srv_normalize_path_for_win(srv_data_home);
 
783
        srv_data_home = srv_add_path_separator_if_needed(srv_data_home);
767
784
 
768
785
        for (i = 0; i < srv_n_data_files; i++) {
769
 
                ulint   dirnamelen;
770
 
 
771
786
                srv_normalize_path_for_win(srv_data_file_names[i]);
772
 
                dirnamelen = strlen(srv_data_home);
773
787
 
774
 
                ut_a(dirnamelen + strlen(srv_data_file_names[i])
 
788
                ut_a(strlen(srv_data_home) + strlen(srv_data_file_names[i])
775
789
                     < (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]);
 
790
                sprintf(name, "%s%s", srv_data_home, srv_data_file_names[i]);
783
791
 
784
792
                if (srv_data_file_is_raw_partition[i] == 0) {
785
793
 
786
794
                        /* First we try to create the file: if it already
787
795
                        exists, ret will get value FALSE */
788
796
 
789
 
                        files[i] = os_file_create(innodb_file_data_key,
790
 
                                                  name, OS_FILE_CREATE,
 
797
                        files[i] = os_file_create(name, OS_FILE_CREATE,
791
798
                                                  OS_FILE_NORMAL,
792
799
                                                  OS_DATA_FILE, &ret);
793
800
 
814
821
                        srv_start_raw_disk_in_use = TRUE;
815
822
                        srv_created_new_raw = TRUE;
816
823
 
817
 
                        files[i] = os_file_create(innodb_file_data_key,
818
 
                                                  name, OS_FILE_OPEN_RAW,
 
824
                        files[i] = os_file_create(name, OS_FILE_OPEN_RAW,
819
825
                                                  OS_FILE_NORMAL,
820
826
                                                  OS_DATA_FILE, &ret);
821
827
                        if (!ret) {
848
854
 
849
855
                        if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
850
856
                                files[i] = os_file_create(
851
 
                                        innodb_file_data_key,
852
857
                                        name, OS_FILE_OPEN_RAW,
853
858
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
854
859
                        } else if (i == 0) {
855
860
                                files[i] = os_file_create(
856
 
                                        innodb_file_data_key,
857
861
                                        name, OS_FILE_OPEN_RETRY,
858
862
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
859
863
                        } else {
860
864
                                files[i] = os_file_create(
861
 
                                        innodb_file_data_key,
862
865
                                        name, OS_FILE_OPEN, OS_FILE_NORMAL,
863
866
                                        OS_DATA_FILE, &ret);
864
867
                        }
1001
1004
 
1002
1005
        ios = 0;
1003
1006
 
1004
 
        mutex_create(ios_mutex_key, &ios_mutex, SYNC_NO_ORDER_CHECK);
 
1007
        mutex_create(&ios_mutex, SYNC_NO_ORDER_CHECK);
1005
1008
 
1006
1009
        return(DB_SUCCESS);
1007
1010
}
1008
1011
 
1009
 
/********************************************************************
 
1012
/****************************************************************//**
1010
1013
Starts InnoDB and creates a new database if database files
1011
1014
are not found and the user wants.
1012
1015
@return DB_SUCCESS or error code */
1015
1018
innobase_start_or_create_for_mysql(void)
1016
1019
/*====================================*/
1017
1020
{
 
1021
        buf_pool_t*     ret;
1018
1022
        ibool           create_new_db;
1019
1023
        ibool           log_file_created;
1020
1024
        ibool           log_created     = FALSE;
1080
1084
#ifdef UNIV_IBUF_DEBUG
1081
1085
        fprintf(stderr,
1082
1086
                "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
 
                );
 
1087
                "InnoDB: Crash recovery will fail with UNIV_IBUF_DEBUG\n");
1088
1088
#endif
1089
1089
 
1090
1090
#ifdef UNIV_SYNC_DEBUG
1097
1097
                "InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n");
1098
1098
#endif
1099
1099
 
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
1100
#ifdef UNIV_MEM_DEBUG
1105
1101
        fprintf(stderr,
1106
1102
                "InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n");
1111
1107
                        "InnoDB: The InnoDB memory heap is disabled\n");
1112
1108
        }
1113
1109
 
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
 
 
 
1110
#ifdef HAVE_GCC_ATOMIC_BUILTINS
 
1111
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
 
1112
        fprintf(stderr,
 
1113
                "InnoDB: Mutexes and rw_locks use GCC atomic builtins.\n");
 
1114
# else /* INNODB_RW_LOCKS_USE_ATOMICS */
 
1115
        fprintf(stderr,
 
1116
                "InnoDB: Mutexes use GCC atomic builtins, rw_locks do not.\n");
 
1117
# endif /* INNODB_RW_LOCKS_USE_ATOMICS */
 
1118
#elif defined(HAVE_SOLARIS_ATOMICS)
 
1119
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
 
1120
        fprintf(stderr,
 
1121
                "InnoDB: Mutexes and rw_locks use Solaris atomic functions.\n");
 
1122
# else
 
1123
        fprintf(stderr,
 
1124
                "InnoDB: Mutexes use Solaris atomic functions.\n");
 
1125
# endif /* INNODB_RW_LOCKS_USE_ATOMICS */
 
1126
#elif defined(HAVE_WINDOWS_ATOMICS)
 
1127
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
 
1128
        fprintf(stderr,
 
1129
                "InnoDB: Mutexes and rw_locks use Windows interlocked functions.\n");
 
1130
# else
 
1131
        fprintf(stderr,
 
1132
                "InnoDB: Mutexes use Windows interlocked functions.\n");
 
1133
# endif /* INNODB_RW_LOCKS_USE_ATOMICS */
 
1134
#else /* HAVE_GCC_ATOMIC_BUILTINS */
 
1135
        fprintf(stderr,
 
1136
                "InnoDB: Neither mutexes nor rw_locks use GCC atomic builtins.\n");
 
1137
#endif /* HAVE_GCC_ATOMIC_BUILTINS */
1124
1138
 
1125
1139
        /* Since InnoDB does not currently clean up all its internal data
1126
1140
        structures in MySQL Embedded Server Library server_end(), we
1129
1143
 
1130
1144
        if (srv_start_has_been_called) {
1131
1145
                fprintf(stderr,
1132
 
                        "InnoDB: Error: startup called second time"
 
1146
                        "InnoDB: Error:startup called second time"
1133
1147
                        " during the process lifetime.\n"
1134
1148
                        "InnoDB: In the MySQL Embedded Server Library"
1135
1149
                        " you cannot call server_init()\n"
1146
1160
 
1147
1161
        srv_is_being_started = TRUE;
1148
1162
        srv_startup_is_before_trx_rollback_phase = TRUE;
 
1163
        os_aio_use_native_aio = FALSE;
1149
1164
 
1150
1165
#ifdef __WIN__
1151
1166
        switch (os_get_os_version()) {
1157
1172
                but when run in conjunction with InnoDB Hot Backup, it seemed
1158
1173
                to corrupt the data files. */
1159
1174
 
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
 
 
 
1175
                os_aio_use_native_aio = FALSE;
 
1176
                break;
1169
1177
        default:
1170
 
                /* Vista and later have both async IO and condition variables */
1171
 
                srv_use_native_aio = TRUE;
1172
 
                srv_use_native_conditions = TRUE;
 
1178
                /* On Win 2000 and XP use async i/o */
 
1179
                os_aio_use_native_aio = TRUE;
1173
1180
                break;
1174
1181
        }
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
 
 
1189
1182
#endif
1190
 
 
1191
1183
        if (srv_file_flush_method_str == NULL) {
1192
1184
                /* These are the default options */
1193
1185
 
1212
1204
#else
1213
1205
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
1214
1206
                srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
1215
 
                srv_use_native_aio = FALSE;
 
1207
                os_aio_use_native_aio = FALSE;
1216
1208
 
1217
1209
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
1218
1210
                srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1219
 
                srv_use_native_aio = FALSE;
 
1211
                os_aio_use_native_aio = FALSE;
1220
1212
 
1221
1213
        } else if (0 == ut_strcmp(srv_file_flush_method_str,
1222
1214
                                  "async_unbuffered")) {
1238
1230
        maximum number of threads that can wait in the 'srv_conc array' for
1239
1231
        their time to enter InnoDB. */
1240
1232
 
 
1233
#if defined(__NETWARE__)
 
1234
 
 
1235
        /* Create less event semaphores because Win 98/ME had
 
1236
        difficulty creating 40000 event semaphores.  Comment from
 
1237
        Novell, Inc.: also, these just take a lot of memory on
 
1238
        NetWare. */
 
1239
        srv_max_n_threads = 1000;
 
1240
#else
1241
1241
        if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
1242
1242
                /* If buffer pool is less than 1000 MB,
1243
 
                assume fewer threads. Also use only one
1244
 
                buffer pool instance */
 
1243
                assume fewer threads. */
1245
1244
                srv_max_n_threads = 50000;
1246
1245
 
1247
1246
        } else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
1248
1247
 
1249
 
                srv_buf_pool_instances = 1;
1250
1248
                srv_max_n_threads = 10000;
1251
1249
        } else {
1252
 
                srv_buf_pool_instances = 1;
1253
1250
                srv_max_n_threads = 1000;       /* saves several MB of memory,
1254
1251
                                                especially in 64-bit
1255
1252
                                                computers */
1256
1253
        }
1257
 
 
 
1254
#endif
1258
1255
        err = srv_boot();
1259
1256
 
1260
1257
        if (err != DB_SUCCESS) {
1262
1259
                return((int) err);
1263
1260
        }
1264
1261
 
1265
 
        mutex_create(srv_monitor_file_mutex_key,
1266
 
                     &srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
 
1262
        mutex_create(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
1267
1263
 
1268
1264
        if (srv_innodb_status) {
1269
1265
                srv_monitor_file_name = mem_alloc(
1285
1281
                }
1286
1282
        }
1287
1283
 
1288
 
        mutex_create(srv_dict_tmpfile_mutex_key,
1289
 
                     &srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
 
1284
        mutex_create(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
1290
1285
 
1291
1286
        srv_dict_tmpfile = os_file_create_tmpfile();
1292
1287
        if (!srv_dict_tmpfile) {
1293
1288
                return(DB_ERROR);
1294
1289
        }
1295
1290
 
1296
 
        mutex_create(srv_misc_tmpfile_mutex_key,
1297
 
                     &srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
 
1291
        mutex_create(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
1298
1292
 
1299
1293
        srv_misc_tmpfile = os_file_create_tmpfile();
1300
1294
        if (!srv_misc_tmpfile) {
1301
1295
                return(DB_ERROR);
1302
1296
        }
1303
1297
 
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. */
 
1298
        /* If user has set the value of innodb_file_io_threads then
 
1299
        we'll emit a message telling the user that this parameter
 
1300
        is now deprecated. */
 
1301
        if (srv_n_file_io_threads != 4) {
 
1302
                fprintf(stderr, "InnoDB: Warning:"
 
1303
                        " innodb_file_io_threads is deprecated."
 
1304
                        " Please use innodb_read_io_threads and"
 
1305
                        " innodb_write_io_threads instead\n");
 
1306
        }
1307
1307
 
1308
1308
        /* Now overwrite the value on srv_n_file_io_threads */
1309
1309
        srv_n_file_io_threads = 2 + srv_n_read_io_threads
1313
1313
 
1314
1314
        /* TODO: Investigate if SRV_N_PENDING_IOS_PER_THREAD (32) limit
1315
1315
        still applies to windows. */
1316
 
        if (!srv_use_native_aio) {
 
1316
        if (!os_aio_use_native_aio) {
1317
1317
                io_limit = 8 * SRV_N_PENDING_IOS_PER_THREAD;
1318
1318
        } else {
1319
1319
                io_limit = SRV_N_PENDING_IOS_PER_THREAD;
1327
1327
        fil_init(srv_file_per_table ? 50000 : 5000,
1328
1328
                 srv_max_n_open_files);
1329
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) {
 
1330
        ret = buf_pool_init();
 
1331
 
 
1332
        if (ret == NULL) {
1352
1333
                fprintf(stderr,
1353
1334
                        "InnoDB: Fatal error: cannot allocate the memory"
1354
1335
                        " for the buffer pool\n");
1418
1399
                sum_of_new_sizes += srv_data_file_sizes[i];
1419
1400
        }
1420
1401
 
1421
 
        if (sum_of_new_sizes < 10485760 / UNIV_PAGE_SIZE) {
 
1402
        if (sum_of_new_sizes < 640) {
1422
1403
                fprintf(stderr,
1423
1404
                        "InnoDB: Error: tablespace size must be"
1424
1405
                        " at least 10 MB\n");
1545
1526
 
1546
1527
        if (create_new_db) {
1547
1528
                mtr_start(&mtr);
1548
 
 
1549
1529
                fsp_header_init(0, sum_of_new_sizes, &mtr);
1550
1530
 
1551
1531
                mtr_commit(&mtr);
1552
1532
 
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
1533
                trx_sys_create();
1558
 
 
1559
1534
                dict_create();
1560
 
 
1561
1535
                srv_startup_is_before_trx_rollback_phase = FALSE;
1562
1536
 
1563
1537
#ifdef UNIV_LOG_ARCHIVE
1576
1550
                in any disk i/o, first call dict_boot */
1577
1551
 
1578
1552
                dict_boot();
1579
 
 
1580
1553
                trx_sys_init_at_db_start();
1581
 
 
1582
1554
                srv_startup_is_before_trx_rollback_phase = FALSE;
1583
1555
 
1584
1556
                /* Initialize the fsp free limit global variable in the log
1602
1574
                consistent state, this is REQUIRED for the recovery
1603
1575
                process to work. */
1604
1576
                err = trx_sys_file_format_max_check(
1605
 
                        srv_max_file_format_at_startup);
 
1577
                        srv_check_file_format_at_startup);
1606
1578
 
1607
1579
                if (err != DB_SUCCESS) {
1608
1580
                        return(err);
1636
1608
                dict_boot();
1637
1609
                trx_sys_init_at_db_start();
1638
1610
 
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
1611
                if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
1648
1612
                        /* The following call is necessary for the insert
1649
1613
                        buffer to work with multiple tablespaces. We must
1659
1623
                        every table in the InnoDB data dictionary that has
1660
1624
                        an .ibd file.
1661
1625
 
1662
 
                        We also determine the maximum tablespace id used. */
 
1626
                        We also determine the maximum tablespace id used.
 
1627
 
 
1628
                        TODO: We may have incomplete transactions in the
 
1629
                        data dictionary tables. Does that harm the scanning of
 
1630
                        the data dictionary below? */
1663
1631
 
1664
1632
                        dict_check_tablespaces_and_store_max_id(
1665
1633
                                recv_needed_recovery);
1666
1634
                }
1667
1635
 
1668
1636
                srv_startup_is_before_trx_rollback_phase = FALSE;
1669
 
                recv_recovery_rollback_active();
 
1637
 
 
1638
                /* Initialize the fsp free limit global variable in the log
 
1639
                system */
 
1640
                fsp_header_get_free_limit();
 
1641
 
 
1642
                /* recv_recovery_from_checkpoint_finish needs trx lists which
 
1643
                are initialized in trx_sys_init_at_db_start(). */
 
1644
 
 
1645
                recv_recovery_from_checkpoint_finish();
1670
1646
 
1671
1647
                /* It is possible that file_format tag has never
1672
1648
                been set. In this case we initialize it to minimum
1715
1691
        /* fprintf(stderr, "Max allowed record size %lu\n",
1716
1692
        page_get_free_space_of_empty() / 2); */
1717
1693
 
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,
 
1694
        /* Create the thread which watches the timeouts for lock waits
 
1695
        and prints InnoDB monitor info */
 
1696
 
 
1697
        os_thread_create(&srv_lock_timeout_and_monitor_thread, NULL,
1741
1698
                         thread_ids + 2 + SRV_MAX_N_IO_THREADS);
1742
1699
 
1743
1700
        /* Create the thread which warns of long semaphore waits */
1744
1701
        os_thread_create(&srv_error_monitor_thread, NULL,
1745
1702
                         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
1703
        srv_is_being_started = FALSE;
1752
1704
 
 
1705
        if (trx_doublewrite == NULL) {
 
1706
                /* Create the doublewrite buffer to a new tablespace */
 
1707
 
 
1708
                trx_sys_create_doublewrite_buf();
 
1709
        }
 
1710
 
1753
1711
        err = dict_create_or_check_foreign_constraint_tables();
1754
1712
 
1755
1713
        if (err != DB_SUCCESS) {
1761
1719
 
1762
1720
        os_thread_create(&srv_master_thread, NULL, thread_ids
1763
1721
                         + (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
1722
#ifdef UNIV_DEBUG
1775
1723
        /* buf_debug_prints = TRUE; */
1776
1724
#endif /* UNIV_DEBUG */
1864
1812
        if (srv_print_verbose_log) {
1865
1813
                ut_print_timestamp(stderr);
1866
1814
                fprintf(stderr,
1867
 
                        "  InnoDB %s started; "
 
1815
                        " InnoDB Plugin %s started; "
1868
1816
                        "log sequence number %"PRIu64"\n",
1869
1817
                        INNODB_VERSION_STR, srv_start_lsn);
1870
1818
        }
1951
1899
/*=============================*/
1952
1900
{
1953
1901
        ulint   i;
 
1902
#ifdef __NETWARE__
 
1903
        extern ibool panic_shutdown;
 
1904
#endif
1954
1905
        if (!srv_was_started) {
1955
1906
                if (srv_is_being_started) {
1956
1907
                        ut_print_timestamp(stderr);
1979
1930
                        "InnoDB will do a crash recovery!\n");
1980
1931
        }
1981
1932
 
1982
 
        logs_empty_and_mark_files_at_shutdown();
 
1933
#ifdef __NETWARE__
 
1934
        if (!panic_shutdown)
 
1935
#endif
 
1936
                logs_empty_and_mark_files_at_shutdown();
1983
1937
 
1984
1938
        if (srv_conc_n_threads != 0) {
1985
1939
                fprintf(stderr,
2018
1972
                /* c. We wake the master thread so that it exits */
2019
1973
                srv_wake_master_thread();
2020
1974
 
2021
 
                /* d. We wake the purge thread so that it exits */
2022
 
                srv_wake_purge_thread();
2023
 
 
2024
 
                /* e. Exit the i/o threads */
 
1975
                /* d. Exit the i/o threads */
2025
1976
 
2026
1977
                os_aio_wake_all_threads_at_shutdown();
2027
1978
 
2031
1982
                        /* All the threads have exited or are just exiting;
2032
1983
                        NOTE that the threads may not have completed their
2033
1984
                        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! */
 
1985
                        they have exited? Now we just sleep 0.1 seconds and
 
1986
                        hope that is enough! */
2038
1987
 
2039
1988
                        os_mutex_exit(os_sync_mutex);
2040
1989
 
2073
2022
                srv_misc_tmpfile = 0;
2074
2023
        }
2075
2024
 
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
2025
        trx_sys_file_format_close();
2085
 
        trx_sys_close();
2086
2026
 
2087
2027
        mutex_free(&srv_monitor_file_mutex);
2088
2028
        mutex_free(&srv_dict_tmpfile_mutex);
2089
2029
        mutex_free(&srv_misc_tmpfile_mutex);
2090
 
        dict_close();
2091
 
        btr_search_sys_free();
2092
2030
 
2093
2031
        /* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
2094
2032
        them */
2095
 
        os_aio_free();
2096
2033
        sync_close();
 
2034
 
 
2035
        /* 4. Free the os_conc_mutex and all os_events and os_mutexes */
 
2036
 
2097
2037
        srv_free();
2098
 
        fil_close();
2099
 
 
2100
 
        /* 4. Free the os_conc_mutex and all os_events and os_mutexes */
2101
 
 
2102
2038
        os_sync_free();
2103
2039
 
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 */
 
2040
        /* Check that all read views are closed except read view owned
 
2041
        by a purge. */
 
2042
 
 
2043
        if (UT_LIST_GET_LEN(trx_sys->view_list) > 1) {
 
2044
                fprintf(stderr,
 
2045
                        "InnoDB: Error: all read views were not closed"
 
2046
                        " before shutdown:\n"
 
2047
                        "InnoDB: %lu read views open \n",
 
2048
                        UT_LIST_GET_LEN(trx_sys->view_list) - 1);
 
2049
        }
 
2050
 
 
2051
        /* 5. Free all allocated memory and the os_fast_mutex created in
 
2052
        ut0mem.c */
 
2053
 
 
2054
        buf_pool_free();
2114
2055
        ut_free_all_mem();
2115
2056
 
2116
2057
        if (os_thread_count != 0
2142
2083
        }
2143
2084
 
2144
2085
        srv_was_started = FALSE;
2145
 
        srv_start_has_been_called = FALSE;
2146
2086
 
2147
2087
        return((int) DB_SUCCESS);
2148
2088
}
 
2089
 
 
2090
#ifdef __NETWARE__
 
2091
void set_panic_flag_for_netware()
 
2092
{
 
2093
        extern ibool panic_shutdown;
 
2094
        panic_shutdown = TRUE;
 
2095
}
 
2096
#endif /* __NETWARE__ */
2149
2097
#endif /* !UNIV_HOTBACKUP */