~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Patrick Crews
  • Date: 2011-01-29 14:17:35 UTC
  • mto: (2126.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2127.
  • Revision ID: gleebix@gmail.com-20110129141735-3y2658vt5ur0a33o
Fixes to make test-dbqp

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
4
 
Copyright (c) 2008, Google Inc.
 
3
Copyright (C) 1996, 2010, Innobase Oy. All Rights Reserved.
 
4
Copyright (C) 2008, Google Inc.
 
5
Copyright (C) 2009, Percona Inc.
5
6
 
6
7
Portions of this file contain modifications contributed and copyrighted by
7
8
Google, Inc. Those modifications are gratefully acknowledged and are described
9
10
incorporated with their permission, and subject to the conditions contained in
10
11
the file COPYING.Google.
11
12
 
 
13
Portions of this file contain modifications contributed and copyrighted
 
14
by Percona Inc.. Those modifications are
 
15
gratefully acknowledged and are described briefly in the InnoDB
 
16
documentation. The contributions by Percona Inc. are incorporated with
 
17
their permission, and subject to the conditions contained in the file
 
18
COPYING.Percona.
 
19
 
12
20
This program is free software; you can redistribute it and/or modify it under
13
21
the terms of the GNU General Public License as published by the Free Software
14
22
Foundation; version 2 of the License.
18
26
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
27
 
20
28
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
 
29
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
30
St, Fifth Floor, Boston, MA 02110-1301 USA
23
31
 
24
32
*****************************************************************************/
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
 
***********************************************************************/
51
33
 
52
34
/********************************************************************//**
53
35
@file srv/srv0start.c
103
85
# include "row0row.h"
104
86
# include "row0mysql.h"
105
87
# include "btr0pcur.h"
 
88
# include "thr0loc.h"
 
89
# include "os0sync.h" /* for INNODB_RW_LOCKS_USE_ATOMICS */
 
90
# include "zlib.h" /* for ZLIB_VERSION */
106
91
 
107
92
#include <errno.h>
108
93
#include <unistd.h>
109
94
 
 
95
#include <drizzled/gettext.h> 
 
96
 
110
97
/** Log sequence number immediately after startup */
111
98
UNIV_INTERN ib_uint64_t srv_start_lsn;
112
99
/** Log sequence number at shutdown */
138
125
/** Files comprising the system tablespace */
139
126
static os_file_t        files[1000];
140
127
 
141
 
/** Mutex protecting the ios count */
142
 
static mutex_t          ios_mutex;
143
 
/** Count of I/O operations in io_handler_thread() */
144
 
static ulint            ios;
145
 
 
146
128
/** io_handler_thread parameters for thread identification */
147
 
static ulint            n[SRV_MAX_N_IO_THREADS + 5];
 
129
static ulint            n[SRV_MAX_N_IO_THREADS + 6];
148
130
/** io_handler_thread identifiers */
149
 
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 5];
 
131
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 6];
150
132
 
151
133
/** We use this mutex to test the return value of pthread_mutex_trylock
152
134
   on successful locking. HP-UX does NOT return 0, though Linux et al do. */
160
142
#define SRV_N_PENDING_IOS_PER_THREAD    OS_AIO_N_PENDING_IOS_PER_THREAD
161
143
#define SRV_MAX_N_PENDING_SYNC_IOS      100
162
144
 
 
145
#ifdef UNIV_PFS_THREAD
 
146
/* Keys to register InnoDB threads with performance schema */
 
147
UNIV_INTERN mysql_pfs_key_t     io_handler_thread_key;
 
148
UNIV_INTERN mysql_pfs_key_t     srv_lock_timeout_thread_key;
 
149
UNIV_INTERN mysql_pfs_key_t     srv_error_monitor_thread_key;
 
150
UNIV_INTERN mysql_pfs_key_t     srv_monitor_thread_key;
 
151
UNIV_INTERN mysql_pfs_key_t     srv_master_thread_key;
 
152
#endif /* UNIV_PFS_THREAD */
163
153
 
164
154
/*********************************************************************//**
165
155
Convert a numeric string that optionally ends in G or M, to a number
291
281
                return(FALSE);
292
282
        }
293
283
 
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);
 
284
        srv_data_file_names = static_cast<char **>(malloc(i * sizeof *srv_data_file_names));
 
285
        srv_data_file_sizes = static_cast<ulint *>(malloc(i * sizeof *srv_data_file_sizes));
 
286
        srv_data_file_is_raw_partition = static_cast<ulint *>(malloc(
 
287
                                                                     i * sizeof *srv_data_file_is_raw_partition));
298
288
 
299
289
        srv_n_data_files = i;
300
290
 
424
414
                return(FALSE);
425
415
        }
426
416
 
427
 
        srv_log_group_home_dirs = malloc(i * sizeof *srv_log_group_home_dirs);
 
417
        srv_log_group_home_dirs = static_cast<char **>(malloc(i * sizeof *srv_log_group_home_dirs));
428
418
 
429
419
        /* Then store the actual values to our array */
430
420
 
473
463
/********************************************************************//**
474
464
I/o-handler thread function.
475
465
@return OS_THREAD_DUMMY_RETURN */
476
 
static
 
466
extern "C"
 
467
os_thread_ret_t
 
468
io_handler_thread(void* arg);
 
469
 
 
470
extern "C"
477
471
os_thread_ret_t
478
472
io_handler_thread(
479
473
/*==============*/
481
475
                        the aio array */
482
476
{
483
477
        ulint   segment;
484
 
        ulint   i;
485
478
 
486
479
        segment = *((ulint*)arg);
487
480
 
489
482
        fprintf(stderr, "Io handler thread %lu starts, id %lu\n", segment,
490
483
                os_thread_pf(os_thread_get_curr_id()));
491
484
#endif
492
 
        for (i = 0;; i++) {
 
485
 
 
486
#ifdef UNIV_PFS_THREAD
 
487
        pfs_register_thread(io_handler_thread_key);
 
488
#endif /* UNIV_PFS_THREAD */
 
489
 
 
490
        while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS) {
493
491
                fil_aio_wait(segment);
494
 
 
495
 
                mutex_enter(&ios_mutex);
496
 
                ios++;
497
 
                mutex_exit(&ios_mutex);
498
492
        }
499
493
 
500
494
        /* We count the number of threads in os_thread_exit(). A created
501
495
        thread should always use that to exit and not use return() to exit.
502
496
        The thread actually never comes here because it is exited in an
503
497
        os_event_wait(). */
504
 
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
505
498
        return 0;
506
 
#endif
507
499
}
508
500
#endif /* !UNIV_HOTBACKUP */
509
501
 
519
511
void
520
512
srv_normalize_path_for_win(
521
513
/*=======================*/
522
 
        char*   str __attribute__((unused)))    /*!< in/out: null-terminated
 
514
        char*   /*str __attribute__((unused))*/)        /*!< in/out: null-terminated
523
515
                                                character string */
524
516
{
525
517
#ifdef __WIN__
532
524
#endif
533
525
}
534
526
 
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 */
539
 
UNIV_INTERN
540
 
char*
541
 
srv_add_path_separator_if_needed(
542
 
/*=============================*/
543
 
        char*   str)    /*!< in: null-terminated character string */
544
 
{
545
 
        char*   out_str;
546
 
        ulint   len     = ut_strlen(str);
547
 
 
548
 
        if (len == 0 || str[len - 1] == SRV_PATH_SEPARATOR) {
549
 
 
550
 
                return(str);
551
 
        }
552
 
 
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;
557
 
 
558
 
        return(out_str);
559
 
}
560
 
 
561
527
#ifndef UNIV_HOTBACKUP
562
528
/*********************************************************************//**
563
529
Calculates the low 32 bits when a file size which is given as a number
606
572
        ulint   size;
607
573
        ulint   size_high;
608
574
        char    name[10000];
 
575
        ulint   dirnamelen;
609
576
 
610
577
        UT_NOT_USED(create_new_db);
611
578
 
612
579
        *log_file_created = FALSE;
613
580
 
614
581
        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]);
617
 
 
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);
622
 
 
623
 
        files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_NORMAL,
 
582
 
 
583
        dirnamelen = strlen(srv_log_group_home_dirs[k]);
 
584
        ut_a(dirnamelen < (sizeof name) - 10 - sizeof "ib_logfile");
 
585
        memcpy(name, srv_log_group_home_dirs[k], dirnamelen);
 
586
 
 
587
        /* Add a path separator if needed. */
 
588
        if (dirnamelen && name[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
 
589
                name[dirnamelen++] = SRV_PATH_SEPARATOR;
 
590
        }
 
591
 
 
592
        sprintf(name + dirnamelen, "%s%lu", "ib_logfile", (ulong) i);
 
593
 
 
594
        files[i] = os_file_create(innodb_file_log_key, name,
 
595
                                  OS_FILE_CREATE, OS_FILE_NORMAL,
624
596
                                  OS_LOG_FILE, &ret);
625
597
        if (ret == FALSE) {
626
598
                if (os_file_get_last_error(FALSE) != OS_FILE_ALREADY_EXISTS
638
610
                        return(DB_ERROR);
639
611
                }
640
612
 
641
 
                files[i] = os_file_create(name, OS_FILE_OPEN, OS_FILE_AIO,
 
613
                files[i] = os_file_create(innodb_file_log_key, name,
 
614
                                          OS_FILE_OPEN, OS_FILE_AIO,
642
615
                                          OS_LOG_FILE, &ret);
643
616
                if (!ret) {
644
617
                        fprintf(stderr,
781
754
        *create_new_db = FALSE;
782
755
 
783
756
        srv_normalize_path_for_win(srv_data_home);
784
 
        srv_data_home = srv_add_path_separator_if_needed(srv_data_home);
785
757
 
786
758
        for (i = 0; i < srv_n_data_files; i++) {
 
759
                ulint   dirnamelen;
 
760
 
787
761
                srv_normalize_path_for_win(srv_data_file_names[i]);
 
762
                dirnamelen = strlen(srv_data_home);
788
763
 
789
 
                ut_a(strlen(srv_data_home) + strlen(srv_data_file_names[i])
 
764
                ut_a(dirnamelen + strlen(srv_data_file_names[i])
790
765
                     < (sizeof name) - 1);
791
 
                sprintf(name, "%s%s", srv_data_home, srv_data_file_names[i]);
 
766
                memcpy(name, srv_data_home, dirnamelen);
 
767
                /* Add a path separator if needed. */
 
768
                if (dirnamelen && name[dirnamelen - 1] != SRV_PATH_SEPARATOR) {
 
769
                        name[dirnamelen++] = SRV_PATH_SEPARATOR;
 
770
                }
 
771
 
 
772
                strcpy(name + dirnamelen, srv_data_file_names[i]);
792
773
 
793
774
                if (srv_data_file_is_raw_partition[i] == 0) {
794
775
 
795
776
                        /* First we try to create the file: if it already
796
777
                        exists, ret will get value FALSE */
797
778
 
798
 
                        files[i] = os_file_create(name, OS_FILE_CREATE,
 
779
                        files[i] = os_file_create(innodb_file_data_key,
 
780
                                                  name, OS_FILE_CREATE,
799
781
                                                  OS_FILE_NORMAL,
800
782
                                                  OS_DATA_FILE, &ret);
801
783
 
822
804
                        srv_start_raw_disk_in_use = TRUE;
823
805
                        srv_created_new_raw = TRUE;
824
806
 
825
 
                        files[i] = os_file_create(name, OS_FILE_OPEN_RAW,
 
807
                        files[i] = os_file_create(innodb_file_data_key,
 
808
                                                  name, OS_FILE_OPEN_RAW,
826
809
                                                  OS_FILE_NORMAL,
827
810
                                                  OS_DATA_FILE, &ret);
828
811
                        if (!ret) {
855
838
 
856
839
                        if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
857
840
                                files[i] = os_file_create(
 
841
                                        innodb_file_data_key,
858
842
                                        name, OS_FILE_OPEN_RAW,
859
843
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
860
844
                        } else if (i == 0) {
861
845
                                files[i] = os_file_create(
 
846
                                        innodb_file_data_key,
862
847
                                        name, OS_FILE_OPEN_RETRY,
863
848
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
864
849
                        } else {
865
850
                                files[i] = os_file_create(
 
851
                                        innodb_file_data_key,
866
852
                                        name, OS_FILE_OPEN, OS_FILE_NORMAL,
867
853
                                        OS_DATA_FILE, &ret);
868
854
                        }
1003
989
                                srv_data_file_is_raw_partition[i] != 0);
1004
990
        }
1005
991
 
1006
 
        ios = 0;
1007
 
 
1008
 
        mutex_create(&ios_mutex, SYNC_NO_ORDER_CHECK);
1009
 
 
1010
992
        return(DB_SUCCESS);
1011
993
}
1012
994
 
1013
 
/****************************************************************//**
 
995
/********************************************************************
1014
996
Starts InnoDB and creates a new database if database files
1015
997
are not found and the user wants.
1016
998
@return DB_SUCCESS or error code */
1019
1001
innobase_start_or_create_for_mysql(void)
1020
1002
/*====================================*/
1021
1003
{
1022
 
        buf_pool_t*     ret;
1023
1004
        ibool           create_new_db;
1024
1005
        ibool           log_file_created;
1025
1006
        ibool           log_created     = FALSE;
1050
1031
        on Mac OS X 10.3 or later. */
1051
1032
        struct utsname utsname;
1052
1033
        if (uname(&utsname)) {
1053
 
                fputs("InnoDB: cannot determine Mac OS X version!\n", stderr);
 
1034
                fputs(_("InnoDB: cannot determine Mac OS X version!\n"), stderr);
1054
1035
        } else {
1055
1036
                srv_have_fullfsync = strcmp(utsname.release, "7.") >= 0;
1056
1037
        }
1057
1038
        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);
 
1039
                fputs(_("InnoDB: On Mac OS X, fsync() may be"
 
1040
                        " broken on internal drives,\n"
 
1041
                        "InnoDB: making transactions unsafe!\n"), stderr);
1061
1042
        }
1062
1043
# endif /* F_FULLFSYNC */
1063
1044
#endif /* HAVE_DARWIN_THREADS */
1064
1045
 
1065
1046
        if (sizeof(ulint) != sizeof(void*)) {
1066
1047
                fprintf(stderr,
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.",
 
1048
                        _("InnoDB: Error: size of InnoDB's ulint is %lu,"
 
1049
                          " but size of void* is %lu.\n"
 
1050
                          "InnoDB: The sizes should be the same"
 
1051
                          " so that on a 64-bit platform you can\n"
 
1052
                          "InnoDB: allocate more than 4 GB of memory."),
1072
1053
                        (ulong)sizeof(ulint), (ulong)sizeof(void*));
1073
1054
        }
1074
1055
 
1079
1060
        srv_file_per_table = FALSE;
1080
1061
#ifdef UNIV_DEBUG
1081
1062
        fprintf(stderr,
1082
 
                "InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!\n");
 
1063
                _("InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!\n"));
1083
1064
#endif
1084
1065
 
1085
1066
#ifdef UNIV_IBUF_DEBUG
1086
1067
        fprintf(stderr,
1087
 
                "InnoDB: !!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!\n"
1088
 
                "InnoDB: Crash recovery will fail with UNIV_IBUF_DEBUG\n");
 
1068
                _("InnoDB: !!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!\n"
 
1069
# ifdef UNIV_IBUF_COUNT_DEBUG
 
1070
                  "InnoDB: !!!!!!!! UNIV_IBUF_COUNT_DEBUG switched on !!!!!!!!!\n"
 
1071
                  "InnoDB: Crash recovery will fail with UNIV_IBUF_COUNT_DEBUG\n"
 
1072
# endif
 
1073
                ));
1089
1074
#endif
1090
1075
 
1091
1076
#ifdef UNIV_SYNC_DEBUG
1092
1077
        fprintf(stderr,
1093
 
                "InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!\n");
 
1078
                _("InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!\n"));
1094
1079
#endif
1095
1080
 
1096
1081
#ifdef UNIV_SEARCH_DEBUG
1097
1082
        fprintf(stderr,
1098
 
                "InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n");
 
1083
                _("InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n"));
1099
1084
#endif
1100
1085
 
 
1086
#ifdef UNIV_LOG_LSN_DEBUG
 
1087
        fprintf(stderr,
 
1088
                _("InnoDB: !!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!\n"));
 
1089
#endif /* UNIV_LOG_LSN_DEBUG */
1101
1090
#ifdef UNIV_MEM_DEBUG
1102
1091
        fprintf(stderr,
1103
 
                "InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n");
 
1092
                _("InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n"));
1104
1093
#endif
1105
1094
 
1106
1095
        if (UNIV_LIKELY(srv_use_sys_malloc)) {
1107
1096
                fprintf(stderr,
1108
 
                        "InnoDB: The InnoDB memory heap is disabled\n");
 
1097
                        _("InnoDB: The InnoDB memory heap is disabled\n"));
1109
1098
        }
1110
1099
 
1111
 
#ifdef HAVE_GCC_ATOMIC_BUILTINS
1112
 
# ifdef INNODB_RW_LOCKS_USE_ATOMICS
1113
 
        fprintf(stderr,
1114
 
                "InnoDB: Mutexes and rw_locks use GCC atomic builtins.\n");
1115
 
# else /* INNODB_RW_LOCKS_USE_ATOMICS */
1116
 
        fprintf(stderr,
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
1121
 
        fprintf(stderr,
1122
 
                "InnoDB: Mutexes and rw_locks use Solaris atomic functions.\n");
1123
 
# else
1124
 
        fprintf(stderr,
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
1129
 
        fprintf(stderr,
1130
 
                "InnoDB: Mutexes and rw_locks use Windows interlocked functions.\n");
1131
 
# else
1132
 
        fprintf(stderr,
1133
 
                "InnoDB: Mutexes use Windows interlocked functions.\n");
1134
 
# endif /* INNODB_RW_LOCKS_USE_ATOMICS */
1135
 
#else /* HAVE_GCC_ATOMIC_BUILTINS */
1136
 
        fprintf(stderr,
1137
 
                "InnoDB: Neither mutexes nor rw_locks use GCC atomic builtins.\n");
1138
 
#endif /* HAVE_GCC_ATOMIC_BUILTINS */
 
1100
        fputs("InnoDB: " IB_ATOMICS_STARTUP_MSG
 
1101
                "\nInnoDB: Compressed tables use zlib " ZLIB_VERSION
 
1102
#ifdef UNIV_ZIP_DEBUG
 
1103
              " with validation"
 
1104
#endif /* UNIV_ZIP_DEBUG */
 
1105
#ifdef UNIV_ZIP_COPY
 
1106
              " and extra copying"
 
1107
#endif /* UNIV_ZIP_COPY */
 
1108
              "\n" , stderr);
 
1109
 
1139
1110
 
1140
1111
        /* Since InnoDB does not currently clean up all its internal data
1141
1112
        structures in MySQL Embedded Server Library server_end(), we
1144
1115
 
1145
1116
        if (srv_start_has_been_called) {
1146
1117
                fprintf(stderr,
1147
 
                        "InnoDB: Error:startup called second time"
 
1118
                        "InnoDB: Error: startup called second time"
1148
1119
                        " during the process lifetime.\n"
1149
1120
                        "InnoDB: In the MySQL Embedded Server Library"
1150
1121
                        " you cannot call server_init()\n"
1161
1132
 
1162
1133
        srv_is_being_started = TRUE;
1163
1134
        srv_startup_is_before_trx_rollback_phase = TRUE;
1164
 
        os_aio_use_native_aio = FALSE;
1165
1135
 
1166
1136
#ifdef __WIN__
1167
1137
        switch (os_get_os_version()) {
1173
1143
                but when run in conjunction with InnoDB Hot Backup, it seemed
1174
1144
                to corrupt the data files. */
1175
1145
 
1176
 
                os_aio_use_native_aio = FALSE;
1177
 
                break;
 
1146
                srv_use_native_aio = FALSE;
 
1147
                break;
 
1148
 
 
1149
        case OS_WIN2000:
 
1150
        case OS_WINXP:
 
1151
                /* On 2000 and XP, async IO is available. */
 
1152
                srv_use_native_aio = TRUE;
 
1153
                break;
 
1154
 
1178
1155
        default:
1179
 
                /* On Win 2000 and XP use async i/o */
1180
 
                os_aio_use_native_aio = TRUE;
 
1156
                /* Vista and later have both async IO and condition variables */
 
1157
                srv_use_native_aio = TRUE;
 
1158
                srv_use_native_conditions = TRUE;
1181
1159
                break;
1182
1160
        }
 
1161
 
 
1162
#elif defined(LINUX_NATIVE_AIO)
 
1163
 
 
1164
        if (srv_use_native_aio) {
 
1165
                ut_print_timestamp(stderr);
 
1166
                fprintf(stderr,
 
1167
                        _("  InnoDB: Using Linux native AIO\n"));
 
1168
        }
 
1169
#else
 
1170
        /* Currently native AIO is supported only on windows and linux
 
1171
        and that also when the support is compiled in. In all other
 
1172
        cases, we ignore the setting of innodb_use_native_aio. */
 
1173
        srv_use_native_aio = FALSE;
 
1174
 
1183
1175
#endif
 
1176
 
1184
1177
        if (srv_file_flush_method_str == NULL) {
1185
1178
                /* These are the default options */
1186
1179
 
1205
1198
#else
1206
1199
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
1207
1200
                srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
1208
 
                os_aio_use_native_aio = FALSE;
 
1201
                srv_use_native_aio = FALSE;
1209
1202
 
1210
1203
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
1211
1204
                srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1212
 
                os_aio_use_native_aio = FALSE;
 
1205
                srv_use_native_aio = FALSE;
1213
1206
 
1214
1207
        } else if (0 == ut_strcmp(srv_file_flush_method_str,
1215
1208
                                  "async_unbuffered")) {
1231
1224
        maximum number of threads that can wait in the 'srv_conc array' for
1232
1225
        their time to enter InnoDB. */
1233
1226
 
1234
 
#if defined(__NETWARE__)
1235
 
 
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
1239
 
        NetWare. */
1240
 
        srv_max_n_threads = 1000;
1241
 
#else
1242
1227
        if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
1243
1228
                /* If buffer pool is less than 1000 MB,
1244
 
                assume fewer threads. */
 
1229
                assume fewer threads. Also use only one
 
1230
                buffer pool instance */
1245
1231
                srv_max_n_threads = 50000;
1246
1232
 
1247
1233
        } else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
1248
1234
 
 
1235
                srv_buf_pool_instances = 1;
1249
1236
                srv_max_n_threads = 10000;
1250
1237
        } else {
 
1238
                srv_buf_pool_instances = 1;
1251
1239
                srv_max_n_threads = 1000;       /* saves several MB of memory,
1252
1240
                                                especially in 64-bit
1253
1241
                                                computers */
1254
1242
        }
1255
 
#endif
 
1243
 
1256
1244
        err = srv_boot();
1257
1245
 
1258
1246
        if (err != DB_SUCCESS) {
1260
1248
                return((int) err);
1261
1249
        }
1262
1250
 
1263
 
        mutex_create(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
 
1251
        mutex_create(srv_monitor_file_mutex_key,
 
1252
                     &srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
1264
1253
 
1265
1254
        if (srv_innodb_status) {
1266
 
                srv_monitor_file_name = mem_alloc(
 
1255
          srv_monitor_file_name = static_cast<char *>(mem_alloc(
1267
1256
                        strlen(fil_path_to_mysql_datadir)
1268
 
                        + 20 + sizeof "/innodb_status.");
 
1257
                        + 20 + sizeof "/innodb_status."));
1269
1258
                sprintf(srv_monitor_file_name, "%s/innodb_status.%lu",
1270
1259
                        fil_path_to_mysql_datadir, os_proc_get_number());
1271
1260
                srv_monitor_file = fopen(srv_monitor_file_name, "w+");
1282
1271
                }
1283
1272
        }
1284
1273
 
1285
 
        mutex_create(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
 
1274
        mutex_create(srv_dict_tmpfile_mutex_key,
 
1275
                     &srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
1286
1276
 
1287
1277
        srv_dict_tmpfile = os_file_create_tmpfile();
1288
1278
        if (!srv_dict_tmpfile) {
1289
1279
                return(DB_ERROR);
1290
1280
        }
1291
1281
 
1292
 
        mutex_create(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
 
1282
        mutex_create(srv_misc_tmpfile_mutex_key,
 
1283
                     &srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
1293
1284
 
1294
1285
        srv_misc_tmpfile = os_file_create_tmpfile();
1295
1286
        if (!srv_misc_tmpfile) {
1296
1287
                return(DB_ERROR);
1297
1288
        }
1298
1289
 
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");
1307
 
        }
 
1290
        /* innodb_file_io_threads used to be user settable.
 
1291
           It is now just a combination of read_io_threads and
 
1292
           write_io_threads that is set by innodb internally. */
1308
1293
 
1309
1294
        /* Now overwrite the value on srv_n_file_io_threads */
1310
1295
        srv_n_file_io_threads = 2 + srv_n_read_io_threads
1314
1299
 
1315
1300
        /* TODO: Investigate if SRV_N_PENDING_IOS_PER_THREAD (32) limit
1316
1301
        still applies to windows. */
1317
 
        if (!os_aio_use_native_aio) {
 
1302
        if (!srv_use_native_aio) {
1318
1303
                io_limit = 8 * SRV_N_PENDING_IOS_PER_THREAD;
1319
1304
        } else {
1320
1305
                io_limit = SRV_N_PENDING_IOS_PER_THREAD;
1328
1313
        fil_init(srv_file_per_table ? 50000 : 5000,
1329
1314
                 srv_max_n_open_files);
1330
1315
 
1331
 
        ret = buf_pool_init();
1332
 
 
1333
 
        if (ret == NULL) {
 
1316
        /* Print time to initialize the buffer pool */
 
1317
        ut_print_timestamp(stderr);
 
1318
        fprintf(stderr,
 
1319
                "  InnoDB: Initializing buffer pool, size =");
 
1320
 
 
1321
        if (srv_buf_pool_size >= 1024 * 1024 * 1024) {
 
1322
                fprintf(stderr,
 
1323
                        " %.1fG\n",
 
1324
                        ((double) srv_buf_pool_size) / (1024 * 1024 * 1024));
 
1325
        } else {
 
1326
                fprintf(stderr,
 
1327
                        " %.1fM\n",
 
1328
                        ((double) srv_buf_pool_size) / (1024 * 1024));
 
1329
        }
 
1330
 
 
1331
        err = buf_pool_init(srv_buf_pool_size, srv_buf_pool_instances);
 
1332
 
 
1333
        ut_print_timestamp(stderr);
 
1334
        fprintf(stderr,
 
1335
                "  InnoDB: Completed initialization of buffer pool\n");
 
1336
 
 
1337
        if (err != DB_SUCCESS) {
1334
1338
                fprintf(stderr,
1335
1339
                        "InnoDB: Fatal error: cannot allocate the memory"
1336
1340
                        " for the buffer pool\n");
1400
1404
                sum_of_new_sizes += srv_data_file_sizes[i];
1401
1405
        }
1402
1406
 
1403
 
        if (sum_of_new_sizes < 640) {
 
1407
        if (sum_of_new_sizes < 10485760 / UNIV_PAGE_SIZE) {
1404
1408
                fprintf(stderr,
1405
1409
                        "InnoDB: Error: tablespace size must be"
1406
1410
                        " at least 10 MB\n");
1527
1531
 
1528
1532
        if (create_new_db) {
1529
1533
                mtr_start(&mtr);
 
1534
 
1530
1535
                fsp_header_init(0, sum_of_new_sizes, &mtr);
1531
1536
 
1532
1537
                mtr_commit(&mtr);
1533
1538
 
 
1539
                /* To maintain backward compatibility we create only
 
1540
                the first rollback segment before the double write buffer.
 
1541
                All the remaining rollback segments will be created later,
 
1542
                after the double write buffer has been created. */
1534
1543
                trx_sys_create();
 
1544
 
1535
1545
                dict_create();
 
1546
 
1536
1547
                srv_startup_is_before_trx_rollback_phase = FALSE;
1537
1548
 
1538
1549
#ifdef UNIV_LOG_ARCHIVE
1551
1562
                in any disk i/o, first call dict_boot */
1552
1563
 
1553
1564
                dict_boot();
 
1565
 
1554
1566
                trx_sys_init_at_db_start();
 
1567
 
1555
1568
                srv_startup_is_before_trx_rollback_phase = FALSE;
1556
1569
 
1557
1570
                /* Initialize the fsp free limit global variable in the log
1575
1588
                consistent state, this is REQUIRED for the recovery
1576
1589
                process to work. */
1577
1590
                err = trx_sys_file_format_max_check(
1578
 
                        srv_check_file_format_at_startup);
 
1591
                        srv_max_file_format_at_startup);
1579
1592
 
1580
1593
                if (err != DB_SUCCESS) {
1581
1594
                        return(err);
1609
1622
                dict_boot();
1610
1623
                trx_sys_init_at_db_start();
1611
1624
 
 
1625
                /* Initialize the fsp free limit global variable in the log
 
1626
                system */
 
1627
                fsp_header_get_free_limit();
 
1628
 
 
1629
                /* recv_recovery_from_checkpoint_finish needs trx lists which
 
1630
                are initialized in trx_sys_init_at_db_start(). */
 
1631
 
 
1632
                recv_recovery_from_checkpoint_finish();
1612
1633
                if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
1613
1634
                        /* The following call is necessary for the insert
1614
1635
                        buffer to work with multiple tablespaces. We must
1624
1645
                        every table in the InnoDB data dictionary that has
1625
1646
                        an .ibd file.
1626
1647
 
1627
 
                        We also determine the maximum tablespace id used.
1628
 
 
1629
 
                        TODO: We may have incomplete transactions in the
1630
 
                        data dictionary tables. Does that harm the scanning of
1631
 
                        the data dictionary below? */
 
1648
                        We also determine the maximum tablespace id used. */
1632
1649
 
1633
1650
                        dict_check_tablespaces_and_store_max_id(
1634
1651
                                recv_needed_recovery);
1635
1652
                }
1636
1653
 
1637
1654
                srv_startup_is_before_trx_rollback_phase = FALSE;
1638
 
 
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();
 
1655
                recv_recovery_rollback_active();
1647
1656
 
1648
1657
                /* It is possible that file_format tag has never
1649
1658
                been set. In this case we initialize it to minimum
1692
1701
        /* fprintf(stderr, "Max allowed record size %lu\n",
1693
1702
        page_get_free_space_of_empty() / 2); */
1694
1703
 
1695
 
        /* Create the thread which watches the timeouts for lock waits
1696
 
        and prints InnoDB monitor info */
1697
 
 
1698
 
        os_thread_create(&srv_lock_timeout_and_monitor_thread, NULL,
 
1704
        if (trx_doublewrite == NULL) {
 
1705
                /* Create the doublewrite buffer to a new tablespace */
 
1706
 
 
1707
                trx_sys_create_doublewrite_buf();
 
1708
        }
 
1709
 
 
1710
        /* Here the double write buffer has already been created and so
 
1711
        any new rollback segments will be allocated after the double
 
1712
        write buffer. The default segment should already exist.
 
1713
        We create the new segments only if it's a new database or
 
1714
        the database was shutdown cleanly. */
 
1715
 
 
1716
        /* Note: When creating the extra rollback segments during an upgrade
 
1717
        we violate the latching order, even if the change buffer is empty.
 
1718
        We make an exception in sync0sync.c and check srv_is_being_started
 
1719
        for that violation. It cannot create a deadlock because we are still
 
1720
        running in single threaded mode essentially. Only the IO threads
 
1721
        should be running at this stage. */
 
1722
 
 
1723
        trx_sys_create_rsegs(TRX_SYS_N_RSEGS - 1);
 
1724
 
 
1725
        /* Create the thread which watches the timeouts for lock waits */
 
1726
        os_thread_create(&srv_lock_timeout_thread, NULL,
1699
1727
                         thread_ids + 2 + SRV_MAX_N_IO_THREADS);
1700
1728
 
1701
1729
        /* Create the thread which warns of long semaphore waits */
1702
1730
        os_thread_create(&srv_error_monitor_thread, NULL,
1703
1731
                         thread_ids + 3 + SRV_MAX_N_IO_THREADS);
 
1732
 
 
1733
        /* Create the thread which prints InnoDB monitor info */
 
1734
        os_thread_create(&srv_monitor_thread, NULL,
 
1735
                         thread_ids + 4 + SRV_MAX_N_IO_THREADS);
 
1736
 
1704
1737
        srv_is_being_started = FALSE;
1705
1738
 
1706
 
        if (trx_doublewrite == NULL) {
1707
 
                /* Create the doublewrite buffer to a new tablespace */
1708
 
 
1709
 
                trx_sys_create_doublewrite_buf();
1710
 
        }
1711
 
 
1712
1739
        err = dict_create_or_check_foreign_constraint_tables();
1713
1740
 
1714
1741
        if (err != DB_SUCCESS) {
1720
1747
 
1721
1748
        os_thread_create(&srv_master_thread, NULL, thread_ids
1722
1749
                         + (1 + SRV_MAX_N_IO_THREADS));
 
1750
 
 
1751
        /* Currently we allow only a single purge thread. */
 
1752
        ut_a(srv_n_purge_threads == 0 || srv_n_purge_threads == 1);
 
1753
 
 
1754
        /* If the user has requested a separate purge thread then
 
1755
        start the purge thread. */
 
1756
        if (srv_n_purge_threads == 1) {
 
1757
                os_thread_create(&srv_purge_thread, NULL, NULL);
 
1758
        }
 
1759
 
1723
1760
#ifdef UNIV_DEBUG
1724
1761
        /* buf_debug_prints = TRUE; */
1725
1762
#endif /* UNIV_DEBUG */
1813
1850
        if (srv_print_verbose_log) {
1814
1851
                ut_print_timestamp(stderr);
1815
1852
                fprintf(stderr,
1816
 
                        " InnoDB Plugin %s started; "
 
1853
                        "  InnoDB %s started; "
1817
1854
                        "log sequence number %"PRIu64"\n",
1818
1855
                        INNODB_VERSION_STR, srv_start_lsn);
1819
1856
        }
1900
1937
/*=============================*/
1901
1938
{
1902
1939
        ulint   i;
1903
 
#ifdef __NETWARE__
1904
 
        extern ibool panic_shutdown;
1905
 
#endif
1906
1940
        if (!srv_was_started) {
1907
1941
                if (srv_is_being_started) {
1908
1942
                        ut_print_timestamp(stderr);
1931
1965
                        "InnoDB will do a crash recovery!\n");
1932
1966
        }
1933
1967
 
1934
 
#ifdef __NETWARE__
1935
 
        if (!panic_shutdown)
1936
 
#endif
1937
 
                logs_empty_and_mark_files_at_shutdown();
 
1968
        logs_empty_and_mark_files_at_shutdown();
1938
1969
 
1939
1970
        if (srv_conc_n_threads != 0) {
1940
1971
                fprintf(stderr,
1973
2004
                /* c. We wake the master thread so that it exits */
1974
2005
                srv_wake_master_thread();
1975
2006
 
1976
 
                /* d. Exit the i/o threads */
 
2007
                /* d. We wake the purge thread so that it exits */
 
2008
                srv_wake_purge_thread();
 
2009
 
 
2010
                /* e. Exit the i/o threads */
1977
2011
 
1978
2012
                os_aio_wake_all_threads_at_shutdown();
1979
2013
 
1983
2017
                        /* All the threads have exited or are just exiting;
1984
2018
                        NOTE that the threads may not have completed their
1985
2019
                        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! */
 
2020
                        they have exited? If we did, we would have to
 
2021
                        remove the pthread_detach() from
 
2022
                        os_thread_exit().  Now we just sleep 0.1
 
2023
                        seconds and hope that is enough! */
1988
2024
 
1989
2025
                        os_mutex_exit(os_sync_mutex);
1990
2026
 
2023
2059
                srv_misc_tmpfile = 0;
2024
2060
        }
2025
2061
 
 
2062
        /* This must be disabled before closing the buffer pool
 
2063
        and closing the data dictionary.  */
 
2064
        btr_search_disable();
 
2065
 
 
2066
        ibuf_close();
 
2067
        log_shutdown();
 
2068
        lock_sys_close();
 
2069
        thr_local_close();
2026
2070
        trx_sys_file_format_close();
 
2071
        trx_sys_close();
2027
2072
 
2028
2073
        mutex_free(&srv_monitor_file_mutex);
2029
2074
        mutex_free(&srv_dict_tmpfile_mutex);
2030
2075
        mutex_free(&srv_misc_tmpfile_mutex);
 
2076
        dict_close();
 
2077
        btr_search_sys_free();
2031
2078
 
2032
2079
        /* 3. Free all InnoDB's own mutexes and the os_fast_mutexes inside
2033
2080
        them */
 
2081
        os_aio_free();
2034
2082
        sync_close();
 
2083
        srv_free();
 
2084
        fil_close();
2035
2085
 
2036
2086
        /* 4. Free the os_conc_mutex and all os_events and os_mutexes */
2037
2087
 
2038
 
        srv_free();
2039
2088
        os_sync_free();
2040
2089
 
2041
 
        /* Check that all read views are closed except read view owned
2042
 
        by a purge. */
2043
 
 
2044
 
        if (UT_LIST_GET_LEN(trx_sys->view_list) > 1) {
2045
 
                fprintf(stderr,
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);
2050
 
        }
2051
 
 
2052
 
        /* 5. Free all allocated memory and the os_fast_mutex created in
2053
 
        ut0mem.c */
2054
 
 
2055
 
        buf_pool_free();
 
2090
        /* 5. Free all allocated memory */
 
2091
 
 
2092
        pars_lexer_close();
 
2093
        log_mem_free();
 
2094
        buf_pool_free(srv_buf_pool_instances);
 
2095
        mem_close();
 
2096
 
 
2097
        /* ut_free_all_mem() frees all allocated memory not freed yet
 
2098
        in shutdown, and it will also free the ut_list_mutex, so it
 
2099
        should be the last one for all operation */
2056
2100
        ut_free_all_mem();
2057
2101
 
2058
2102
        if (os_thread_count != 0
2084
2128
        }
2085
2129
 
2086
2130
        srv_was_started = FALSE;
 
2131
        srv_start_has_been_called = FALSE;
2087
2132
 
2088
2133
        return((int) DB_SUCCESS);
2089
2134
}
2090
 
 
2091
 
#ifdef __NETWARE__
2092
 
void set_panic_flag_for_netware()
2093
 
{
2094
 
        extern ibool panic_shutdown;
2095
 
        panic_shutdown = TRUE;
2096
 
}
2097
 
#endif /* __NETWARE__ */
2098
2135
#endif /* !UNIV_HOTBACKUP */