~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

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.
4
 
Copyright (C) 2008, Google Inc.
5
 
Copyright (C) 2009, Percona Inc.
 
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
 
4
Copyright (c) 2008, Google 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.
30
22
St, Fifth Floor, Boston, MA 02110-1301 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
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
49
 
 
50
***********************************************************************/
33
51
 
34
52
/********************************************************************//**
35
53
@file srv/srv0start.c
87
105
# include "btr0pcur.h"
88
106
# include "thr0loc.h"
89
107
# include "os0sync.h" /* for INNODB_RW_LOCKS_USE_ATOMICS */
90
 
# include "zlib.h" /* for ZLIB_VERSION */
91
108
 
92
109
#include <errno.h>
93
110
#include <unistd.h>
94
111
 
95
 
#include <drizzled/gettext.h> 
96
 
#include <drizzled/errmsg_print.h>
97
 
 
98
112
/** Log sequence number immediately after startup */
99
113
UNIV_INTERN ib_uint64_t srv_start_lsn;
100
114
/** Log sequence number at shutdown */
126
140
/** Files comprising the system tablespace */
127
141
static os_file_t        files[1000];
128
142
 
 
143
/** Mutex protecting the ios count */
 
144
static mutex_t          ios_mutex;
 
145
/** Count of I/O operations in io_handler_thread() */
 
146
static ulint            ios;
 
147
 
129
148
/** io_handler_thread parameters for thread identification */
130
 
static ulint            n[SRV_MAX_N_IO_THREADS + 6];
 
149
static ulint            n[SRV_MAX_N_IO_THREADS + 5];
131
150
/** io_handler_thread identifiers */
132
 
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 6];
 
151
static os_thread_id_t   thread_ids[SRV_MAX_N_IO_THREADS + 5];
133
152
 
134
153
/** We use this mutex to test the return value of pthread_mutex_trylock
135
154
   on successful locking. HP-UX does NOT return 0, though Linux et al do. */
143
162
#define SRV_N_PENDING_IOS_PER_THREAD    OS_AIO_N_PENDING_IOS_PER_THREAD
144
163
#define SRV_MAX_N_PENDING_SYNC_IOS      100
145
164
 
146
 
#ifdef UNIV_PFS_THREAD
147
 
/* Keys to register InnoDB threads with performance schema */
148
 
UNIV_INTERN mysql_pfs_key_t     io_handler_thread_key;
149
 
UNIV_INTERN mysql_pfs_key_t     srv_lock_timeout_thread_key;
150
 
UNIV_INTERN mysql_pfs_key_t     srv_error_monitor_thread_key;
151
 
UNIV_INTERN mysql_pfs_key_t     srv_monitor_thread_key;
152
 
UNIV_INTERN mysql_pfs_key_t     srv_master_thread_key;
153
 
#endif /* UNIV_PFS_THREAD */
154
165
 
155
166
/*********************************************************************//**
156
167
Convert a numeric string that optionally ends in G or M, to a number
282
293
                return(FALSE);
283
294
        }
284
295
 
285
 
        srv_data_file_names = static_cast<char **>(malloc(i * sizeof *srv_data_file_names));
286
 
        srv_data_file_sizes = static_cast<ulint *>(malloc(i * sizeof *srv_data_file_sizes));
287
 
        srv_data_file_is_raw_partition = static_cast<ulint *>(malloc(
288
 
                                                                     i * sizeof *srv_data_file_is_raw_partition));
 
296
        srv_data_file_names = malloc(i * sizeof *srv_data_file_names);
 
297
        srv_data_file_sizes = malloc(i * sizeof *srv_data_file_sizes);
 
298
        srv_data_file_is_raw_partition = malloc(
 
299
                i * sizeof *srv_data_file_is_raw_partition);
289
300
 
290
301
        srv_n_data_files = i;
291
302
 
415
426
                return(FALSE);
416
427
        }
417
428
 
418
 
        srv_log_group_home_dirs = static_cast<char **>(malloc(i * sizeof *srv_log_group_home_dirs));
 
429
        srv_log_group_home_dirs = malloc(i * sizeof *srv_log_group_home_dirs);
419
430
 
420
431
        /* Then store the actual values to our array */
421
432
 
464
475
/********************************************************************//**
465
476
I/o-handler thread function.
466
477
@return OS_THREAD_DUMMY_RETURN */
467
 
extern "C"
468
 
os_thread_ret_t
469
 
io_handler_thread(void* arg);
470
 
 
471
 
extern "C"
 
478
static
472
479
os_thread_ret_t
473
480
io_handler_thread(
474
481
/*==============*/
476
483
                        the aio array */
477
484
{
478
485
        ulint   segment;
 
486
        ulint   i;
479
487
 
480
488
        segment = *((ulint*)arg);
481
489
 
483
491
        fprintf(stderr, "Io handler thread %lu starts, id %lu\n", segment,
484
492
                os_thread_pf(os_thread_get_curr_id()));
485
493
#endif
486
 
 
487
 
#ifdef UNIV_PFS_THREAD
488
 
        pfs_register_thread(io_handler_thread_key);
489
 
#endif /* UNIV_PFS_THREAD */
490
 
 
491
 
        while (srv_shutdown_state != SRV_SHUTDOWN_EXIT_THREADS) {
 
494
        for (i = 0;; i++) {
492
495
                fil_aio_wait(segment);
 
496
 
 
497
                mutex_enter(&ios_mutex);
 
498
                ios++;
 
499
                mutex_exit(&ios_mutex);
493
500
        }
494
 
 
495
501
        /* We count the number of threads in os_thread_exit(). A created
496
502
        thread should always use that to exit and not use return() to exit.
497
503
        The thread actually never comes here because it is exited in an
498
504
        os_event_wait(). */
 
505
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
 
506
        /* This is disabled on SunStudio as it (rightly) gives a warning
 
507
           about this code never being reached. See the loop above? No exit
 
508
           condition. */
 
509
        thr_local_free(os_thread_get_curr_id());
 
510
 
499
511
        return 0;
 
512
#endif
500
513
}
501
514
#endif /* !UNIV_HOTBACKUP */
502
515
 
512
525
void
513
526
srv_normalize_path_for_win(
514
527
/*=======================*/
515
 
        char*   /*str __attribute__((unused))*/)        /*!< in/out: null-terminated
 
528
        char*   str __attribute__((unused)))    /*!< in/out: null-terminated
516
529
                                                character string */
517
530
{
518
531
#ifdef __WIN__
592
605
 
593
606
        sprintf(name + dirnamelen, "%s%lu", "ib_logfile", (ulong) i);
594
607
 
595
 
        files[i] = os_file_create(innodb_file_log_key, name,
596
 
                                  OS_FILE_CREATE, OS_FILE_NORMAL,
 
608
        files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_NORMAL,
597
609
                                  OS_LOG_FILE, &ret);
598
610
        if (ret == FALSE) {
599
611
                if (os_file_get_last_error(FALSE) != OS_FILE_ALREADY_EXISTS
604
616
                    && os_file_get_last_error(FALSE) != 100
605
617
#endif
606
618
                    ) {
607
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
608
 
                                          "InnoDB: Error in creating or opening %s", name);
 
619
                        fprintf(stderr,
 
620
                                "InnoDB: Error in creating"
 
621
                                " or opening %s\n", name);
609
622
 
610
 
                  return(DB_ERROR);
 
623
                        return(DB_ERROR);
611
624
                }
612
625
 
613
 
                files[i] = os_file_create(innodb_file_log_key, name,
614
 
                                          OS_FILE_OPEN, OS_FILE_AIO,
 
626
                files[i] = os_file_create(name, OS_FILE_OPEN, OS_FILE_AIO,
615
627
                                          OS_LOG_FILE, &ret);
616
628
                if (!ret) {
617
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
618
 
                                          "InnoDB: Error in opening %s.", name);
 
629
                        fprintf(stderr,
 
630
                                "InnoDB: Error in opening %s\n", name);
619
631
 
620
632
                        return(DB_ERROR);
621
633
                }
626
638
                if (size != srv_calc_low32(srv_log_file_size)
627
639
                    || size_high != srv_calc_high32(srv_log_file_size)) {
628
640
 
629
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
630
 
                                          "InnoDB: Error: log file %s is of different size %lu %lu bytes than specified in the .cnf"
631
 
                                          " file %lu %lu bytes!",
632
 
                                          name, (ulong) size_high, (ulong) size,
633
 
                                          (ulong) srv_calc_high32(srv_log_file_size),
634
 
                                          (ulong) srv_calc_low32(srv_log_file_size));
 
641
                        fprintf(stderr,
 
642
                                "InnoDB: Error: log file %s is"
 
643
                                " of different size %lu %lu bytes\n"
 
644
                                "InnoDB: than specified in the .cnf"
 
645
                                " file %lu %lu bytes!\n",
 
646
                                name, (ulong) size_high, (ulong) size,
 
647
                                (ulong) srv_calc_high32(srv_log_file_size),
 
648
                                (ulong) srv_calc_low32(srv_log_file_size));
635
649
 
636
650
                        return(DB_ERROR);
637
651
                }
638
652
        } else {
639
653
                *log_file_created = TRUE;
640
654
 
641
 
                drizzled::errmsg_printf(drizzled::error::INFO,
642
 
                                        "InnoDB: Log file %s did not exist: new to be created",
643
 
                                        name);
 
655
                ut_print_timestamp(stderr);
 
656
 
 
657
                fprintf(stderr,
 
658
                        "  InnoDB: Log file %s did not exist:"
 
659
                        " new to be created\n",
 
660
                        name);
644
661
                if (log_file_has_been_opened) {
645
662
 
646
663
                        return(DB_ERROR);
647
664
                }
648
665
 
649
 
                drizzled::errmsg_printf(drizzled::error::INFO,
650
 
                                        "InnoDB: Setting log file %s size to %lu MB",
651
 
                                        name, (ulong) srv_log_file_size
652
 
                                        >> (20 - UNIV_PAGE_SIZE_SHIFT));
 
666
                fprintf(stderr, "InnoDB: Setting log file %s size to %lu MB\n",
 
667
                        name, (ulong) srv_log_file_size
 
668
                        >> (20 - UNIV_PAGE_SIZE_SHIFT));
653
669
 
654
 
                drizzled::errmsg_printf(drizzled::error::INFO,
655
 
                                        "InnoDB: Database physically writes the file full: wait...\n");
 
670
                fprintf(stderr,
 
671
                        "InnoDB: Database physically writes the file"
 
672
                        " full: wait...\n");
656
673
 
657
674
                ret = os_file_set_size(name, files[i],
658
675
                                       srv_calc_low32(srv_log_file_size),
659
676
                                       srv_calc_high32(srv_log_file_size));
660
677
                if (!ret) {
661
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
662
 
                                          "InnoDB: Error in creating %s: probably out of disk space",
663
 
                                          name);
 
678
                        fprintf(stderr,
 
679
                                "InnoDB: Error in creating %s:"
 
680
                                " probably out of disk space\n",
 
681
                                name);
664
682
 
665
683
                        return(DB_ERROR);
666
684
                }
737
755
        char    name[10000];
738
756
 
739
757
        if (srv_n_data_files >= 1000) {
740
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
741
 
                                  "InnoDB: can only have < 1000 data files you have defined %lu",
742
 
                                  (ulong) srv_n_data_files);
 
758
                fprintf(stderr, "InnoDB: can only have < 1000 data files\n"
 
759
                        "InnoDB: you have defined %lu\n",
 
760
                        (ulong) srv_n_data_files);
743
761
                return(DB_ERROR);
744
762
        }
745
763
 
770
788
                        /* First we try to create the file: if it already
771
789
                        exists, ret will get value FALSE */
772
790
 
773
 
                        files[i] = os_file_create(innodb_file_data_key,
774
 
                                                  name, OS_FILE_CREATE,
 
791
                        files[i] = os_file_create(name, OS_FILE_CREATE,
775
792
                                                  OS_FILE_NORMAL,
776
793
                                                  OS_DATA_FILE, &ret);
777
794
 
784
801
                            && os_file_get_last_error(FALSE) != 100
785
802
#endif
786
803
                            ) {
787
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
788
 
                                                  "InnoDB: Error in creating or opening %s",
789
 
                                                  name);
 
804
                                fprintf(stderr,
 
805
                                        "InnoDB: Error in creating"
 
806
                                        " or opening %s\n",
 
807
                                        name);
790
808
 
791
809
                                return(DB_ERROR);
792
810
                        }
797
815
                        srv_start_raw_disk_in_use = TRUE;
798
816
                        srv_created_new_raw = TRUE;
799
817
 
800
 
                        files[i] = os_file_create(innodb_file_data_key,
801
 
                                                  name, OS_FILE_OPEN_RAW,
 
818
                        files[i] = os_file_create(name, OS_FILE_OPEN_RAW,
802
819
                                                  OS_FILE_NORMAL,
803
820
                                                  OS_DATA_FILE, &ret);
804
821
                        if (!ret) {
805
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
806
 
                                                  "InnoDB: Error in opening %s", name);
 
822
                                fprintf(stderr,
 
823
                                        "InnoDB: Error in opening %s\n", name);
807
824
 
808
825
                                return(DB_ERROR);
809
826
                        }
819
836
                        /* We open the data file */
820
837
 
821
838
                        if (one_created) {
822
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
823
 
                                        "InnoDB: Error: data files can only be added at the end of a tablespace, but"
824
 
                                        " data file %s existed beforehand.",
825
 
                                        name);
 
839
                                fprintf(stderr,
 
840
                                        "InnoDB: Error: data files can only"
 
841
                                        " be added at the end\n");
 
842
                                fprintf(stderr,
 
843
                                        "InnoDB: of a tablespace, but"
 
844
                                        " data file %s existed beforehand.\n",
 
845
                                        name);
826
846
                                return(DB_ERROR);
827
847
                        }
828
848
 
829
849
                        if (srv_data_file_is_raw_partition[i] == SRV_OLD_RAW) {
830
850
                                files[i] = os_file_create(
831
 
                                        innodb_file_data_key,
832
851
                                        name, OS_FILE_OPEN_RAW,
833
852
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
834
853
                        } else if (i == 0) {
835
854
                                files[i] = os_file_create(
836
 
                                        innodb_file_data_key,
837
855
                                        name, OS_FILE_OPEN_RETRY,
838
856
                                        OS_FILE_NORMAL, OS_DATA_FILE, &ret);
839
857
                        } else {
840
858
                                files[i] = os_file_create(
841
 
                                        innodb_file_data_key,
842
859
                                        name, OS_FILE_OPEN, OS_FILE_NORMAL,
843
860
                                        OS_DATA_FILE, &ret);
844
861
                        }
845
862
 
846
863
                        if (!ret) {
847
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
848
 
                                                  "InnoDB: Error in opening %s", name);
 
864
                                fprintf(stderr,
 
865
                                        "InnoDB: Error in opening %s\n", name);
849
866
                                os_file_get_last_error(TRUE);
850
867
 
851
868
                                return(DB_ERROR);
872
889
                                        && srv_last_file_size_max
873
890
                                        < rounded_size_pages)) {
874
891
 
875
 
                                  drizzled::errmsg_printf(drizzled::error::ERROR,
876
 
                                                          "InnoDB: Error: auto-extending data file %s is of a different size. "
877
 
                                                          "%lu pages (rounded down to MB) than specified in the .cnf file: "
878
 
                                                          "initial %lu pages, max %lu (relevant if non-zero) pages!",
879
 
                                                          name,
880
 
                                                          (ulong) rounded_size_pages,
881
 
                                                          (ulong) srv_data_file_sizes[i],
882
 
                                                          (ulong)
883
 
                                                          srv_last_file_size_max);
 
892
                                        fprintf(stderr,
 
893
                                                "InnoDB: Error: auto-extending"
 
894
                                                " data file %s is"
 
895
                                                " of a different size\n"
 
896
                                                "InnoDB: %lu pages (rounded"
 
897
                                                " down to MB) than specified"
 
898
                                                " in the .cnf file:\n"
 
899
                                                "InnoDB: initial %lu pages,"
 
900
                                                " max %lu (relevant if"
 
901
                                                " non-zero) pages!\n",
 
902
                                                name,
 
903
                                                (ulong) rounded_size_pages,
 
904
                                                (ulong) srv_data_file_sizes[i],
 
905
                                                (ulong)
 
906
                                                srv_last_file_size_max);
884
907
 
885
908
                                        return(DB_ERROR);
886
909
                                }
890
913
 
891
914
                        if (rounded_size_pages != srv_data_file_sizes[i]) {
892
915
 
893
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
894
 
                                        "InnoDB: Error: data file %s is of a different size. "
895
 
                                        "%lu pages (rounded down to MB). "
896
 
                                        "Than specified in the .cnf file %lu pages!",
 
916
                                fprintf(stderr,
 
917
                                        "InnoDB: Error: data file %s"
 
918
                                        " is of a different size\n"
 
919
                                        "InnoDB: %lu pages"
 
920
                                        " (rounded down to MB)\n"
 
921
                                        "InnoDB: than specified"
 
922
                                        " in the .cnf file %lu pages!\n",
897
923
                                        name,
898
924
                                        (ulong) rounded_size_pages,
899
925
                                        (ulong) srv_data_file_sizes[i]);
915
941
                        one_created = TRUE;
916
942
 
917
943
                        if (i > 0) {
918
 
                                drizzled::errmsg_printf(drizzled::error::INFO,
919
 
                                        "  InnoDB: Data file %s did not exist: new to be created",
 
944
                                ut_print_timestamp(stderr);
 
945
                                fprintf(stderr,
 
946
                                        "  InnoDB: Data file %s did not"
 
947
                                        " exist: new to be created\n",
920
948
                                        name);
921
949
                        } else {
922
 
                          drizzled::errmsg_printf(drizzled::error::INFO,
923
 
                                        "InnoDB: The first specified data file %s did not exist. A new database to be created!", name);
 
950
                                fprintf(stderr,
 
951
                                        "InnoDB: The first specified"
 
952
                                        " data file %s did not exist:\n"
 
953
                                        "InnoDB: a new database"
 
954
                                        " to be created!\n", name);
924
955
                                *create_new_db = TRUE;
925
956
                        }
926
957
 
927
 
                        drizzled::errmsg_printf(drizzled::error::INFO,
928
 
                                                "  InnoDB: Setting file %s size to %lu MB",
929
 
                                                name, (ulong) (srv_data_file_sizes[i]
930
 
                                                         >> (20 - UNIV_PAGE_SIZE_SHIFT)));
 
958
                        ut_print_timestamp(stderr);
 
959
                        fprintf(stderr,
 
960
                                "  InnoDB: Setting file %s size to %lu MB\n",
 
961
                                name,
 
962
                                (ulong) (srv_data_file_sizes[i]
 
963
                                         >> (20 - UNIV_PAGE_SIZE_SHIFT)));
931
964
 
932
 
                        drizzled::errmsg_printf(drizzled::error::INFO,
933
 
                                "InnoDB: Database physically writes the file full: wait...");
 
965
                        fprintf(stderr,
 
966
                                "InnoDB: Database physically writes the"
 
967
                                " file full: wait...\n");
934
968
 
935
969
                        ret = os_file_set_size(
936
970
                                name, files[i],
938
972
                                srv_calc_high32(srv_data_file_sizes[i]));
939
973
 
940
974
                        if (!ret) {
941
 
                          drizzled::errmsg_printf(drizzled::error::ERROR,
942
 
                                                  "InnoDB: Error in creating %s: probably out of disk space", name);
 
975
                                fprintf(stderr,
 
976
                                        "InnoDB: Error in creating %s:"
 
977
                                        " probably out of disk space\n", name);
943
978
 
944
979
                                return(DB_ERROR);
945
980
                        }
961
996
                                srv_data_file_is_raw_partition[i] != 0);
962
997
        }
963
998
 
 
999
        ios = 0;
 
1000
 
 
1001
        mutex_create(&ios_mutex, SYNC_NO_ORDER_CHECK);
 
1002
 
964
1003
        return(DB_SUCCESS);
965
1004
}
966
1005
 
973
1012
innobase_start_or_create_for_mysql(void)
974
1013
/*====================================*/
975
1014
{
 
1015
        buf_pool_t*     ret;
976
1016
        ibool           create_new_db;
977
1017
        ibool           log_file_created;
978
1018
        ibool           log_created     = FALSE;
1003
1043
        on Mac OS X 10.3 or later. */
1004
1044
        struct utsname utsname;
1005
1045
        if (uname(&utsname)) {
1006
 
                fputs(_("InnoDB: cannot determine Mac OS X version!\n"), stderr);
 
1046
                fputs("InnoDB: cannot determine Mac OS X version!\n", stderr);
1007
1047
        } else {
1008
1048
                srv_have_fullfsync = strcmp(utsname.release, "7.") >= 0;
1009
1049
        }
1010
1050
        if (!srv_have_fullfsync) {
1011
 
                fputs(_("InnoDB: On Mac OS X, fsync() may be"
1012
 
                        " broken on internal drives,\n"
1013
 
                        "InnoDB: making transactions unsafe!\n"), stderr);
 
1051
                fputs("InnoDB: On Mac OS X, fsync() may be"
 
1052
                      " broken on internal drives,\n"
 
1053
                      "InnoDB: making transactions unsafe!\n", stderr);
1014
1054
        }
1015
1055
# endif /* F_FULLFSYNC */
1016
1056
#endif /* HAVE_DARWIN_THREADS */
1017
1057
 
1018
1058
        if (sizeof(ulint) != sizeof(void*)) {
1019
 
          drizzled::errmsg_printf(drizzled::error::WARN,
1020
 
                        _("InnoDB: Error: size of InnoDB's ulint is %lu, but size of void* is %lu. "
1021
 
                          "The sizes should be the same so that on a 64-bit platform you can. Allocate more than 4 GB of memory."),
 
1059
                fprintf(stderr,
 
1060
                        "InnoDB: Error: size of InnoDB's ulint is %lu,"
 
1061
                        " but size of void* is %lu.\n"
 
1062
                        "InnoDB: The sizes should be the same"
 
1063
                        " so that on a 64-bit platform you can\n"
 
1064
                        "InnoDB: allocate more than 4 GB of memory.",
1022
1065
                        (ulong)sizeof(ulint), (ulong)sizeof(void*));
1023
1066
        }
1024
1067
 
1028
1071
        innodb_file_per_table) until this function has returned. */
1029
1072
        srv_file_per_table = FALSE;
1030
1073
#ifdef UNIV_DEBUG
1031
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1032
 
                                _("InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!\n"));
 
1074
        fprintf(stderr,
 
1075
                "InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!\n");
1033
1076
#endif
1034
1077
 
1035
1078
#ifdef UNIV_IBUF_DEBUG
1036
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1037
 
                _("InnoDB: !!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!\n"
1038
 
# ifdef UNIV_IBUF_COUNT_DEBUG
1039
 
                  "InnoDB: !!!!!!!! UNIV_IBUF_COUNT_DEBUG switched on !!!!!!!!!\n"
1040
 
                  "InnoDB: Crash recovery will fail with UNIV_IBUF_COUNT_DEBUG\n"
1041
 
# endif
1042
 
                ));
 
1079
        fprintf(stderr,
 
1080
                "InnoDB: !!!!!!!! UNIV_IBUF_DEBUG switched on !!!!!!!!!\n"
 
1081
                "InnoDB: Crash recovery will fail with UNIV_IBUF_DEBUG\n");
1043
1082
#endif
1044
1083
 
1045
1084
#ifdef UNIV_SYNC_DEBUG
1046
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1047
 
                                _("InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!\n"));
 
1085
        fprintf(stderr,
 
1086
                "InnoDB: !!!!!!!! UNIV_SYNC_DEBUG switched on !!!!!!!!!\n");
1048
1087
#endif
1049
1088
 
1050
1089
#ifdef UNIV_SEARCH_DEBUG
1051
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1052
 
                                _("InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n"));
 
1090
        fprintf(stderr,
 
1091
                "InnoDB: !!!!!!!! UNIV_SEARCH_DEBUG switched on !!!!!!!!!\n");
1053
1092
#endif
1054
1093
 
1055
1094
#ifdef UNIV_LOG_LSN_DEBUG
1056
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1057
 
                                _("InnoDB: !!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!\n"));
 
1095
        fprintf(stderr,
 
1096
                "InnoDB: !!!!!!!! UNIV_LOG_LSN_DEBUG switched on !!!!!!!!!\n");
1058
1097
#endif /* UNIV_LOG_LSN_DEBUG */
1059
1098
#ifdef UNIV_MEM_DEBUG
1060
 
        drizzled::errmsg_printf(drizzled::error::INFO,
1061
 
                                _("InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n"));
 
1099
        fprintf(stderr,
 
1100
                "InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n");
1062
1101
#endif
1063
1102
 
1064
 
        if (UNIV_LIKELY(srv_use_sys_malloc))
1065
 
        {
1066
 
          drizzled::errmsg_printf(drizzled::error::ERROR, _("InnoDB: The InnoDB memory heap is disabled\n"));
 
1103
        if (UNIV_LIKELY(srv_use_sys_malloc)) {
 
1104
                fprintf(stderr,
 
1105
                        "InnoDB: The InnoDB memory heap is disabled\n");
1067
1106
        }
1068
1107
 
1069
 
        fputs("InnoDB: " IB_ATOMICS_STARTUP_MSG
1070
 
                "\nInnoDB: Compressed tables use zlib " ZLIB_VERSION
1071
 
#ifdef UNIV_ZIP_DEBUG
1072
 
              " with validation"
1073
 
#endif /* UNIV_ZIP_DEBUG */
1074
 
#ifdef UNIV_ZIP_COPY
1075
 
              " and extra copying"
1076
 
#endif /* UNIV_ZIP_COPY */
1077
 
              "\n" , stderr);
1078
 
 
 
1108
        fprintf(stderr, "InnoDB: %s\n", IB_ATOMICS_STARTUP_MSG);
1079
1109
 
1080
1110
        /* Since InnoDB does not currently clean up all its internal data
1081
1111
        structures in MySQL Embedded Server Library server_end(), we
1083
1113
        second time during the process lifetime. */
1084
1114
 
1085
1115
        if (srv_start_has_been_called) {
1086
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1087
 
                        "InnoDB: Error: startup called second time during the process lifetime.\n");
 
1116
                fprintf(stderr,
 
1117
                        "InnoDB: Error: startup called second time"
 
1118
                        " during the process lifetime.\n"
 
1119
                        "InnoDB: In the MySQL Embedded Server Library"
 
1120
                        " you cannot call server_init()\n"
 
1121
                        "InnoDB: more than once during"
 
1122
                        " the process lifetime.\n");
1088
1123
        }
1089
1124
 
1090
1125
        srv_start_has_been_called = TRUE;
1096
1131
 
1097
1132
        srv_is_being_started = TRUE;
1098
1133
        srv_startup_is_before_trx_rollback_phase = TRUE;
 
1134
        os_aio_use_native_aio = FALSE;
1099
1135
 
1100
1136
#ifdef __WIN__
1101
1137
        switch (os_get_os_version()) {
1107
1143
                but when run in conjunction with InnoDB Hot Backup, it seemed
1108
1144
                to corrupt the data files. */
1109
1145
 
1110
 
                srv_use_native_aio = FALSE;
1111
 
                break;
1112
 
 
1113
 
        case OS_WIN2000:
1114
 
        case OS_WINXP:
1115
 
                /* On 2000 and XP, async IO is available. */
1116
 
                srv_use_native_aio = TRUE;
1117
 
                break;
1118
 
 
 
1146
                os_aio_use_native_aio = FALSE;
 
1147
                break;
1119
1148
        default:
1120
 
                /* Vista and later have both async IO and condition variables */
1121
 
                srv_use_native_aio = TRUE;
1122
 
                srv_use_native_conditions = TRUE;
 
1149
                /* On Win 2000 and XP use async i/o */
 
1150
                os_aio_use_native_aio = TRUE;
1123
1151
                break;
1124
1152
        }
1125
 
 
1126
 
#elif defined(LINUX_NATIVE_AIO)
1127
 
 
1128
 
        if (srv_use_native_aio) {
1129
 
                drizzled::errmsg_printf(drizzled::error::INFO,
1130
 
                                        _("InnoDB: Using Linux native AIO"));
1131
 
        }
1132
 
#else
1133
 
        /* Currently native AIO is supported only on windows and linux
1134
 
        and that also when the support is compiled in. In all other
1135
 
        cases, we ignore the setting of innodb_use_native_aio. */
1136
 
        srv_use_native_aio = FALSE;
1137
 
 
1138
1153
#endif
1139
 
 
1140
1154
        if (srv_file_flush_method_str == NULL) {
1141
1155
                /* These are the default options */
1142
1156
 
1161
1175
#else
1162
1176
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
1163
1177
                srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
1164
 
                srv_use_native_aio = FALSE;
 
1178
                os_aio_use_native_aio = FALSE;
1165
1179
 
1166
1180
        } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
1167
1181
                srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1168
 
                srv_use_native_aio = FALSE;
 
1182
                os_aio_use_native_aio = FALSE;
1169
1183
 
1170
1184
        } else if (0 == ut_strcmp(srv_file_flush_method_str,
1171
1185
                                  "async_unbuffered")) {
1172
1186
                srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
1173
1187
#endif
1174
1188
        } else {
1175
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1176
 
                                  "InnoDB: Unrecognized value %s for innodb_flush_method",
1177
 
                                  srv_file_flush_method_str);
 
1189
                fprintf(stderr,
 
1190
                        "InnoDB: Unrecognized value %s for"
 
1191
                        " innodb_flush_method\n",
 
1192
                        srv_file_flush_method_str);
1178
1193
                return(DB_ERROR);
1179
1194
        }
1180
1195
 
1186
1201
        maximum number of threads that can wait in the 'srv_conc array' for
1187
1202
        their time to enter InnoDB. */
1188
1203
 
 
1204
#if defined(__NETWARE__)
 
1205
 
 
1206
        /* Create less event semaphores because Win 98/ME had
 
1207
        difficulty creating 40000 event semaphores.  Comment from
 
1208
        Novell, Inc.: also, these just take a lot of memory on
 
1209
        NetWare. */
 
1210
        srv_max_n_threads = 1000;
 
1211
#else
1189
1212
        if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
1190
1213
                /* If buffer pool is less than 1000 MB,
1191
 
                assume fewer threads. Also use only one
1192
 
                buffer pool instance */
 
1214
                assume fewer threads. */
1193
1215
                srv_max_n_threads = 50000;
1194
1216
 
1195
1217
        } else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
1196
1218
 
1197
 
                srv_buf_pool_instances = 1;
1198
1219
                srv_max_n_threads = 10000;
1199
1220
        } else {
1200
 
                srv_buf_pool_instances = 1;
1201
1221
                srv_max_n_threads = 1000;       /* saves several MB of memory,
1202
1222
                                                especially in 64-bit
1203
1223
                                                computers */
1204
1224
        }
1205
 
 
 
1225
#endif
1206
1226
        err = srv_boot();
1207
1227
 
1208
1228
        if (err != DB_SUCCESS) {
1210
1230
                return((int) err);
1211
1231
        }
1212
1232
 
1213
 
        mutex_create(srv_monitor_file_mutex_key,
1214
 
                     &srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
 
1233
        mutex_create(&srv_monitor_file_mutex, SYNC_NO_ORDER_CHECK);
1215
1234
 
1216
1235
        if (srv_innodb_status) {
1217
 
          srv_monitor_file_name = static_cast<char *>(mem_alloc(
 
1236
                srv_monitor_file_name = mem_alloc(
1218
1237
                        strlen(fil_path_to_mysql_datadir)
1219
 
                        + 20 + sizeof "/innodb_status."));
 
1238
                        + 20 + sizeof "/innodb_status.");
1220
1239
                sprintf(srv_monitor_file_name, "%s/innodb_status.%lu",
1221
1240
                        fil_path_to_mysql_datadir, os_proc_get_number());
1222
1241
                srv_monitor_file = fopen(srv_monitor_file_name, "w+");
1223
1242
                if (!srv_monitor_file) {
1224
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1225
 
                                          "InnoDB: unable to create %s: %s\n", srv_monitor_file_name, strerror(errno));
 
1243
                        fprintf(stderr, "InnoDB: unable to create %s: %s\n",
 
1244
                                srv_monitor_file_name, strerror(errno));
1226
1245
                        return(DB_ERROR);
1227
1246
                }
1228
1247
        } else {
1233
1252
                }
1234
1253
        }
1235
1254
 
1236
 
        mutex_create(srv_dict_tmpfile_mutex_key,
1237
 
                     &srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
 
1255
        mutex_create(&srv_dict_tmpfile_mutex, SYNC_DICT_OPERATION);
1238
1256
 
1239
1257
        srv_dict_tmpfile = os_file_create_tmpfile();
1240
1258
        if (!srv_dict_tmpfile) {
1241
1259
                return(DB_ERROR);
1242
1260
        }
1243
1261
 
1244
 
        mutex_create(srv_misc_tmpfile_mutex_key,
1245
 
                     &srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
 
1262
        mutex_create(&srv_misc_tmpfile_mutex, SYNC_ANY_LATCH);
1246
1263
 
1247
1264
        srv_misc_tmpfile = os_file_create_tmpfile();
1248
1265
        if (!srv_misc_tmpfile) {
1261
1278
 
1262
1279
        /* TODO: Investigate if SRV_N_PENDING_IOS_PER_THREAD (32) limit
1263
1280
        still applies to windows. */
1264
 
        if (!srv_use_native_aio) {
 
1281
        if (!os_aio_use_native_aio) {
1265
1282
                io_limit = 8 * SRV_N_PENDING_IOS_PER_THREAD;
1266
1283
        } else {
1267
1284
                io_limit = SRV_N_PENDING_IOS_PER_THREAD;
1275
1292
        fil_init(srv_file_per_table ? 50000 : 5000,
1276
1293
                 srv_max_n_open_files);
1277
1294
 
1278
 
        /* Print time to initialize the buffer pool */
1279
 
 
1280
 
        if (srv_buf_pool_size >= 1024 * 1024 * 1024) {
1281
 
          drizzled::errmsg_printf(drizzled::error::INFO, "InnoDB: Initializing buffer pool, size = %.1fG",
1282
 
                                  ((double) srv_buf_pool_size) / (1024 * 1024 * 1024));
1283
 
        } else {
1284
 
          drizzled::errmsg_printf(drizzled::error::INFO, "InnoDB: Initializing buffer pool, size = %.1fM",
1285
 
                                  ((double) srv_buf_pool_size) / (1024 * 1024));
1286
 
        }
1287
 
 
1288
 
        err = buf_pool_init(srv_buf_pool_size, srv_buf_pool_instances);
1289
 
 
1290
 
        drizzled::errmsg_printf(drizzled::error::INFO, "InnoDB: Completed initialization of buffer pool");
1291
 
 
1292
 
        if (err != DB_SUCCESS) {
1293
 
          drizzled::errmsg_printf(drizzled::error::ERROR, "InnoDB: Fatal error: cannot allocate the memory for the buffer pool");
1294
 
 
1295
 
          return(DB_ERROR);
 
1295
        ret = buf_pool_init();
 
1296
 
 
1297
        if (ret == NULL) {
 
1298
                fprintf(stderr,
 
1299
                        "InnoDB: Fatal error: cannot allocate the memory"
 
1300
                        " for the buffer pool\n");
 
1301
 
 
1302
                return(DB_ERROR);
1296
1303
        }
1297
1304
 
1298
1305
#ifdef UNIV_DEBUG
1301
1308
 
1302
1309
        if (srv_buf_pool_size <= 5 * 1024 * 1024) {
1303
1310
 
1304
 
          drizzled::errmsg_printf(drizzled::error::WARN, "InnoDB: Warning: Small buffer pool size "
1305
 
                                  "(%luM), the flst_validate() debug function "
1306
 
                                  "can cause a deadlock if the buffer pool fills up.\n",
1307
 
                                  srv_buf_pool_size / 1024 / 1024);
 
1311
                fprintf(stderr, "InnoDB: Warning: Small buffer pool size "
 
1312
                        "(%luM), the flst_validate() debug function "
 
1313
                        "can cause a deadlock if the buffer pool fills up.\n",
 
1314
                        srv_buf_pool_size / 1024 / 1024);
1308
1315
        }
1309
1316
#endif
1310
1317
 
1323
1330
 
1324
1331
#ifdef UNIV_LOG_ARCHIVE
1325
1332
        if (0 != ut_strcmp(srv_log_group_home_dirs[0], srv_arch_dir)) {
1326
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1327
 
                                  "InnoDB: Error: you must set the log group home dir in my.cnf the same as log arch dir.");
 
1333
                fprintf(stderr,
 
1334
                        "InnoDB: Error: you must set the log group"
 
1335
                        " home dir in my.cnf the\n"
 
1336
                        "InnoDB: same as log arch dir.\n");
1328
1337
 
1329
1338
                return(DB_ERROR);
1330
1339
        }
1331
1340
#endif /* UNIV_LOG_ARCHIVE */
1332
1341
 
1333
1342
        if (srv_n_log_files * srv_log_file_size >= 262144) {
1334
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1335
 
                                  "InnoDB: Error: combined size of log files must be < 4 GB");
 
1343
                fprintf(stderr,
 
1344
                        "InnoDB: Error: combined size of log files"
 
1345
                        " must be < 4 GB\n");
1336
1346
 
1337
1347
                return(DB_ERROR);
1338
1348
        }
1342
1352
        for (i = 0; i < srv_n_data_files; i++) {
1343
1353
#ifndef __WIN__
1344
1354
                if (sizeof(off_t) < 5 && srv_data_file_sizes[i] >= 262144) {
1345
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1346
 
                                          "InnoDB: Error: file size must be < 4 GB with this MySQL binary and operating system combination,"
1347
 
                                          " in some OS's < 2 GB\n");
 
1355
                        fprintf(stderr,
 
1356
                                "InnoDB: Error: file size must be < 4 GB"
 
1357
                                " with this MySQL binary\n"
 
1358
                                "InnoDB: and operating system combination,"
 
1359
                                " in some OS's < 2 GB\n");
1348
1360
 
1349
1361
                        return(DB_ERROR);
1350
1362
                }
1353
1365
        }
1354
1366
 
1355
1367
        if (sum_of_new_sizes < 10485760 / UNIV_PAGE_SIZE) {
1356
 
          drizzled::errmsg_printf(drizzled::error::ERROR, "InnoDB: Error: tablespace size must be at least 10 MB");
 
1368
                fprintf(stderr,
 
1369
                        "InnoDB: Error: tablespace size must be"
 
1370
                        " at least 10 MB\n");
1357
1371
 
1358
1372
                return(DB_ERROR);
1359
1373
        }
1365
1379
                                        &min_flushed_lsn, &max_flushed_lsn,
1366
1380
                                        &sum_of_new_sizes);
1367
1381
        if (err != DB_SUCCESS) {
1368
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1369
 
                                  "InnoDB: Could not open or create data files.\n"
1370
 
                                  "InnoDB: If you tried to add new data files, and it failed here,\n"
1371
 
                                  "InnoDB: you should now edit innodb_data_file_path in my.cnf back\n"
1372
 
                                  "InnoDB: to what it was, and remove the new ibdata files InnoDB created\n"
1373
 
                                  "InnoDB: in this failed attempt. InnoDB only wrote those files full of\n"
1374
 
                                  "InnoDB: zeros, but did not yet use them in any way. But be careful: do not\n"
1375
 
                                  "InnoDB: remove old data files which contain your precious data!\n");
 
1382
                fprintf(stderr,
 
1383
                        "InnoDB: Could not open or create data files.\n"
 
1384
                        "InnoDB: If you tried to add new data files,"
 
1385
                        " and it failed here,\n"
 
1386
                        "InnoDB: you should now edit innodb_data_file_path"
 
1387
                        " in my.cnf back\n"
 
1388
                        "InnoDB: to what it was, and remove the"
 
1389
                        " new ibdata files InnoDB created\n"
 
1390
                        "InnoDB: in this failed attempt. InnoDB only wrote"
 
1391
                        " those files full of\n"
 
1392
                        "InnoDB: zeros, but did not yet use them in any way."
 
1393
                        " But be careful: do not\n"
 
1394
                        "InnoDB: remove old data files"
 
1395
                        " which contain your precious data!\n");
1376
1396
 
1377
1397
                return((int) err);
1378
1398
        }
1397
1417
                }
1398
1418
                if ((log_opened && create_new_db)
1399
1419
                    || (log_opened && log_created)) {
1400
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1401
 
                                "InnoDB: Error: all log files must be created at the same time.\n"
1402
 
                                "InnoDB: All log files must be created also in database creation.\n"
1403
 
                                "InnoDB: If you want bigger or smaller log files, shut down the\n"
1404
 
                                "InnoDB: database and make sure there were no errors in shutdown.\n"
1405
 
                                "InnoDB: Then delete the existing log files. Edit the .cnf file\n"
 
1420
                        fprintf(stderr,
 
1421
                                "InnoDB: Error: all log files must be"
 
1422
                                " created at the same time.\n"
 
1423
                                "InnoDB: All log files must be"
 
1424
                                " created also in database creation.\n"
 
1425
                                "InnoDB: If you want bigger or smaller"
 
1426
                                " log files, shut down the\n"
 
1427
                                "InnoDB: database and make sure there"
 
1428
                                " were no errors in shutdown.\n"
 
1429
                                "InnoDB: Then delete the existing log files."
 
1430
                                " Edit the .cnf file\n"
1406
1431
                                "InnoDB: and start the database again.\n");
1407
1432
 
1408
1433
                        return(DB_ERROR);
1424
1449
                    || max_arch_log_no != min_arch_log_no
1425
1450
#endif /* UNIV_LOG_ARCHIVE */
1426
1451
                    ) {
1427
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1428
 
                                "InnoDB: Cannot initialize created log files because\n"
1429
 
                                "InnoDB: data files were not in sync with each other\n"
 
1452
                        fprintf(stderr,
 
1453
                                "InnoDB: Cannot initialize created"
 
1454
                                " log files because\n"
 
1455
                                "InnoDB: data files were not in sync"
 
1456
                                " with each other\n"
1430
1457
                                "InnoDB: or the data files are corrupt.\n");
1431
1458
 
1432
1459
                        return(DB_ERROR);
1433
1460
                }
1434
1461
 
1435
1462
                if (max_flushed_lsn < (ib_uint64_t) 1000) {
1436
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1437
 
                                "InnoDB: Cannot initialize created log files because\n"
1438
 
                                "InnoDB: data files are corrupt, or new data files were\n"
1439
 
                                "InnoDB: created when the database was started previous\n"
1440
 
                                "InnoDB: time but the database was not shut down\n"
1441
 
                                "InnoDB: normally after that.\n");
 
1463
                        fprintf(stderr,
 
1464
                                "InnoDB: Cannot initialize created"
 
1465
                                " log files because\n"
 
1466
                                "InnoDB: data files are corrupt,"
 
1467
                                " or new data files were\n"
 
1468
                                "InnoDB: created when the database"
 
1469
                                " was started previous\n"
 
1470
                                "InnoDB: time but the database"
 
1471
                                " was not shut down\n"
 
1472
                                "InnoDB: normally after that.\n");
1442
1473
 
1443
1474
                        return(DB_ERROR);
1444
1475
                }
1460
1491
 
1461
1492
        if (create_new_db) {
1462
1493
                mtr_start(&mtr);
1463
 
 
1464
1494
                fsp_header_init(0, sum_of_new_sizes, &mtr);
1465
1495
 
1466
1496
                mtr_commit(&mtr);
1467
1497
 
1468
 
                /* To maintain backward compatibility we create only
1469
 
                the first rollback segment before the double write buffer.
1470
 
                All the remaining rollback segments will be created later,
1471
 
                after the double write buffer has been created. */
1472
1498
                trx_sys_create();
1473
 
 
1474
1499
                dict_create();
1475
 
 
1476
1500
                srv_startup_is_before_trx_rollback_phase = FALSE;
1477
1501
 
1478
1502
#ifdef UNIV_LOG_ARCHIVE
1479
1503
        } else if (srv_archive_recovery) {
1480
 
          drizzled::errmsg_printf(drizzled::error::INFO,
1481
 
                                  "InnoDB: Starting archive recovery from a backup...");
 
1504
                fprintf(stderr,
 
1505
                        "InnoDB: Starting archive"
 
1506
                        " recovery from a backup...\n");
1482
1507
                err = recv_recovery_from_archive_start(
1483
1508
                        min_flushed_lsn, srv_archive_recovery_limit_lsn,
1484
1509
                        min_arch_log_no);
1490
1515
                in any disk i/o, first call dict_boot */
1491
1516
 
1492
1517
                dict_boot();
1493
 
 
1494
1518
                trx_sys_init_at_db_start();
1495
 
 
1496
1519
                srv_startup_is_before_trx_rollback_phase = FALSE;
1497
1520
 
1498
1521
                /* Initialize the fsp free limit global variable in the log
1516
1539
                consistent state, this is REQUIRED for the recovery
1517
1540
                process to work. */
1518
1541
                err = trx_sys_file_format_max_check(
1519
 
                        srv_max_file_format_at_startup);
 
1542
                        srv_check_file_format_at_startup);
1520
1543
 
1521
1544
                if (err != DB_SUCCESS) {
1522
1545
                        return(err);
1550
1573
                dict_boot();
1551
1574
                trx_sys_init_at_db_start();
1552
1575
 
1553
 
                /* Initialize the fsp free limit global variable in the log
1554
 
                system */
1555
 
                fsp_header_get_free_limit();
1556
 
 
1557
 
                /* recv_recovery_from_checkpoint_finish needs trx lists which
1558
 
                are initialized in trx_sys_init_at_db_start(). */
1559
 
 
1560
 
                recv_recovery_from_checkpoint_finish();
1561
1576
                if (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE) {
1562
1577
                        /* The following call is necessary for the insert
1563
1578
                        buffer to work with multiple tablespaces. We must
1573
1588
                        every table in the InnoDB data dictionary that has
1574
1589
                        an .ibd file.
1575
1590
 
1576
 
                        We also determine the maximum tablespace id used. */
 
1591
                        We also determine the maximum tablespace id used.
 
1592
 
 
1593
                        TODO: We may have incomplete transactions in the
 
1594
                        data dictionary tables. Does that harm the scanning of
 
1595
                        the data dictionary below? */
1577
1596
 
1578
1597
                        dict_check_tablespaces_and_store_max_id(
1579
1598
                                recv_needed_recovery);
1580
1599
                }
1581
1600
 
1582
1601
                srv_startup_is_before_trx_rollback_phase = FALSE;
1583
 
                recv_recovery_rollback_active();
 
1602
 
 
1603
                /* Initialize the fsp free limit global variable in the log
 
1604
                system */
 
1605
                fsp_header_get_free_limit();
 
1606
 
 
1607
                /* recv_recovery_from_checkpoint_finish needs trx lists which
 
1608
                are initialized in trx_sys_init_at_db_start(). */
 
1609
 
 
1610
                recv_recovery_from_checkpoint_finish();
1584
1611
 
1585
1612
                /* It is possible that file_format tag has never
1586
1613
                been set. In this case we initialize it to minimum
1629
1656
        /* fprintf(stderr, "Max allowed record size %lu\n",
1630
1657
        page_get_free_space_of_empty() / 2); */
1631
1658
 
1632
 
        if (trx_doublewrite == NULL) {
1633
 
                /* Create the doublewrite buffer to a new tablespace */
1634
 
 
1635
 
                trx_sys_create_doublewrite_buf();
1636
 
        }
1637
 
 
1638
 
        /* Here the double write buffer has already been created and so
1639
 
        any new rollback segments will be allocated after the double
1640
 
        write buffer. The default segment should already exist.
1641
 
        We create the new segments only if it's a new database or
1642
 
        the database was shutdown cleanly. */
1643
 
 
1644
 
        /* Note: When creating the extra rollback segments during an upgrade
1645
 
        we violate the latching order, even if the change buffer is empty.
1646
 
        We make an exception in sync0sync.c and check srv_is_being_started
1647
 
        for that violation. It cannot create a deadlock because we are still
1648
 
        running in single threaded mode essentially. Only the IO threads
1649
 
        should be running at this stage. */
1650
 
 
1651
 
        trx_sys_create_rsegs(TRX_SYS_N_RSEGS - 1);
1652
 
 
1653
 
        /* Create the thread which watches the timeouts for lock waits */
1654
 
        os_thread_create(&srv_lock_timeout_thread, NULL,
 
1659
        /* Create the thread which watches the timeouts for lock waits
 
1660
        and prints InnoDB monitor info */
 
1661
 
 
1662
        os_thread_create(&srv_lock_timeout_and_monitor_thread, NULL,
1655
1663
                         thread_ids + 2 + SRV_MAX_N_IO_THREADS);
1656
1664
 
1657
1665
        /* Create the thread which warns of long semaphore waits */
1658
1666
        os_thread_create(&srv_error_monitor_thread, NULL,
1659
1667
                         thread_ids + 3 + SRV_MAX_N_IO_THREADS);
1660
 
 
1661
 
        /* Create the thread which prints InnoDB monitor info */
1662
 
        os_thread_create(&srv_monitor_thread, NULL,
1663
 
                         thread_ids + 4 + SRV_MAX_N_IO_THREADS);
1664
 
 
1665
1668
        srv_is_being_started = FALSE;
1666
1669
 
 
1670
        if (trx_doublewrite == NULL) {
 
1671
                /* Create the doublewrite buffer to a new tablespace */
 
1672
 
 
1673
                trx_sys_create_doublewrite_buf();
 
1674
        }
 
1675
 
1667
1676
        err = dict_create_or_check_foreign_constraint_tables();
1668
1677
 
1669
1678
        if (err != DB_SUCCESS) {
1675
1684
 
1676
1685
        os_thread_create(&srv_master_thread, NULL, thread_ids
1677
1686
                         + (1 + SRV_MAX_N_IO_THREADS));
1678
 
 
1679
 
        /* Currently we allow only a single purge thread. */
1680
 
        ut_a(srv_n_purge_threads == 0 || srv_n_purge_threads == 1);
1681
 
 
1682
 
        /* If the user has requested a separate purge thread then
1683
 
        start the purge thread. */
1684
 
        if (srv_n_purge_threads == 1) {
1685
 
                os_thread_create(&srv_purge_thread, NULL, NULL);
1686
 
        }
1687
 
 
1688
1687
#ifdef UNIV_DEBUG
1689
1688
        /* buf_debug_prints = TRUE; */
1690
1689
#endif /* UNIV_DEBUG */
1699
1698
        if (!srv_auto_extend_last_data_file
1700
1699
            && sum_of_data_file_sizes != tablespace_size_in_header) {
1701
1700
 
1702
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1703
 
                                  "InnoDB: Error: tablespace size stored in header is %lu pages, but the sum of data file sizes is %lu pages.",
1704
 
                                  (ulong) tablespace_size_in_header,
1705
 
                                  (ulong) sum_of_data_file_sizes);
 
1701
                fprintf(stderr,
 
1702
                        "InnoDB: Error: tablespace size"
 
1703
                        " stored in header is %lu pages, but\n"
 
1704
                        "InnoDB: the sum of data file sizes is %lu pages\n",
 
1705
                        (ulong) tablespace_size_in_header,
 
1706
                        (ulong) sum_of_data_file_sizes);
1706
1707
 
1707
1708
                if (srv_force_recovery == 0
1708
1709
                    && sum_of_data_file_sizes < tablespace_size_in_header) {
1709
1710
                        /* This is a fatal error, the tail of a tablespace is
1710
1711
                        missing */
1711
1712
 
1712
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1713
 
                                          "InnoDB: Cannot start InnoDB. The tail of the system tablespace is "
1714
 
                                          "missing. Have you edited innodb_data_file_path in my.cnf in an "
1715
 
                                          "inappropriate way, removing ibdata files from there? "
1716
 
                                          "You can set innodb_force_recovery=1 in my.cnf to force "
1717
 
                                          "a startup if you are trying to recover a badly corrupt database.");
 
1713
                        fprintf(stderr,
 
1714
                                "InnoDB: Cannot start InnoDB."
 
1715
                                " The tail of the system tablespace is\n"
 
1716
                                "InnoDB: missing. Have you edited"
 
1717
                                " innodb_data_file_path in my.cnf in an\n"
 
1718
                                "InnoDB: inappropriate way, removing"
 
1719
                                " ibdata files from there?\n"
 
1720
                                "InnoDB: You can set innodb_force_recovery=1"
 
1721
                                " in my.cnf to force\n"
 
1722
                                "InnoDB: a startup if you are trying"
 
1723
                                " to recover a badly corrupt database.\n");
1718
1724
 
1719
1725
                        return(DB_ERROR);
1720
1726
                }
1723
1729
        if (srv_auto_extend_last_data_file
1724
1730
            && sum_of_data_file_sizes < tablespace_size_in_header) {
1725
1731
 
1726
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1727
 
                                  "InnoDB: Error: tablespace size stored in header is %lu pages, but the sum of data file sizes"
1728
 
                                  " is only %lu pages\n",
1729
 
                                  (ulong) tablespace_size_in_header,
1730
 
                                  (ulong) sum_of_data_file_sizes);
 
1732
                fprintf(stderr,
 
1733
                        "InnoDB: Error: tablespace size stored in header"
 
1734
                        " is %lu pages, but\n"
 
1735
                        "InnoDB: the sum of data file sizes"
 
1736
                        " is only %lu pages\n",
 
1737
                        (ulong) tablespace_size_in_header,
 
1738
                        (ulong) sum_of_data_file_sizes);
1731
1739
 
1732
1740
                if (srv_force_recovery == 0) {
1733
1741
 
1734
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1735
 
                                "InnoDB: Cannot start InnoDB. The tail of the system tablespace is "
1736
 
                                "missing. Have you edited innodb_data_file_path in my.cnf in an "
1737
 
                                "inappropriate way, removing ibdata files from there? "
1738
 
                                "You can set innodb_force_recovery=1 in my.cnf to force "
1739
 
                                "a startup if you are trying to recover a badly corrupt database.\n");
 
1742
                        fprintf(stderr,
 
1743
                                "InnoDB: Cannot start InnoDB. The tail of"
 
1744
                                " the system tablespace is\n"
 
1745
                                "InnoDB: missing. Have you edited"
 
1746
                                " innodb_data_file_path in my.cnf in an\n"
 
1747
                                "InnoDB: inappropriate way, removing"
 
1748
                                " ibdata files from there?\n"
 
1749
                                "InnoDB: You can set innodb_force_recovery=1"
 
1750
                                " in my.cnf to force\n"
 
1751
                                "InnoDB: a startup if you are trying to"
 
1752
                                " recover a badly corrupt database.\n");
1740
1753
 
1741
1754
                        return(DB_ERROR);
1742
1755
                }
1746
1759
        os_fast_mutex_init(&srv_os_test_mutex);
1747
1760
 
1748
1761
        if (0 != os_fast_mutex_trylock(&srv_os_test_mutex)) {
1749
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1750
 
                        "InnoDB: Error: pthread_mutex_trylock returns an unexpected value on success! Cannot continue.\n");
 
1762
                fprintf(stderr,
 
1763
                        "InnoDB: Error: pthread_mutex_trylock returns"
 
1764
                        " an unexpected value on\n"
 
1765
                        "InnoDB: success! Cannot continue.\n");
1751
1766
                exit(1);
1752
1767
        }
1753
1768
 
1760
1775
        os_fast_mutex_free(&srv_os_test_mutex);
1761
1776
 
1762
1777
        if (srv_print_verbose_log) {
1763
 
                drizzled::errmsg_printf(drizzled::error::ERROR,
1764
 
                                        "InnoDB %s started; log sequence number %"PRIu64"\n",
1765
 
                                        INNODB_VERSION_STR, srv_start_lsn);
 
1778
                ut_print_timestamp(stderr);
 
1779
                fprintf(stderr,
 
1780
                        " InnoDB Plugin %s started; "
 
1781
                        "log sequence number %"PRIu64"\n",
 
1782
                        INNODB_VERSION_STR, srv_start_lsn);
1766
1783
        }
1767
1784
 
1768
1785
        if (srv_force_recovery > 0) {
1769
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
1770
 
                                  "InnoDB: !!! innodb_force_recovery is set to %lu !!!\n",
1771
 
                                  (ulong) srv_force_recovery);
 
1786
                fprintf(stderr,
 
1787
                        "InnoDB: !!! innodb_force_recovery"
 
1788
                        " is set to %lu !!!\n",
 
1789
                        (ulong) srv_force_recovery);
1772
1790
        }
1773
1791
 
 
1792
        fflush(stderr);
 
1793
 
1774
1794
        if (trx_doublewrite_must_reset_space_ids) {
1775
1795
                /* Actually, we did not change the undo log format between
1776
1796
                4.0 and 4.1.1, and we would not need to run purge to
1785
1805
                4.1.1. It is essential that the insert buffer is emptied
1786
1806
                here! */
1787
1807
 
1788
 
          drizzled::errmsg_printf(drizzled::error::INFO,
1789
 
                                  "InnoDB: You are upgrading to an InnoDB version which allows multiple. "
1790
 
                                  "tablespaces. Wait that purge and insert buffer merge run to completion...");
 
1808
                fprintf(stderr,
 
1809
                        "InnoDB: You are upgrading to an"
 
1810
                        " InnoDB version which allows multiple\n"
 
1811
                        "InnoDB: tablespaces. Wait that purge"
 
1812
                        " and insert buffer merge run to\n"
 
1813
                        "InnoDB: completion...\n");
1791
1814
                for (;;) {
1792
1815
                        os_thread_sleep(1000000);
1793
1816
 
1799
1822
                                break;
1800
1823
                        }
1801
1824
                }
1802
 
                drizzled::errmsg_printf(drizzled::error::INFO,
1803
 
                                        "InnoDB: Full purge and insert buffer merge completed.");
 
1825
                fprintf(stderr,
 
1826
                        "InnoDB: Full purge and insert buffer merge"
 
1827
                        " completed.\n");
1804
1828
 
1805
1829
                trx_sys_mark_upgraded_to_multiple_tablespaces();
1806
1830
 
1807
 
                drizzled::errmsg_printf(drizzled::error::INFO,
1808
 
                                        "InnoDB: You have now successfully upgraded"
1809
 
                                        " to the multiple tablespaces\n"
1810
 
                                        "InnoDB: format. You should NOT DOWNGRADE"
1811
 
                                        " to an earlier version of\n"
1812
 
                                        "InnoDB: InnoDB! But if you absolutely need to"
1813
 
                                        " downgrade, see\n"
1814
 
                                        "InnoDB: " REFMAN "multiple-tablespaces.html\n"
1815
 
                                        "InnoDB: for instructions.\n");
 
1831
                fprintf(stderr,
 
1832
                        "InnoDB: You have now successfully upgraded"
 
1833
                        " to the multiple tablespaces\n"
 
1834
                        "InnoDB: format. You should NOT DOWNGRADE"
 
1835
                        " to an earlier version of\n"
 
1836
                        "InnoDB: InnoDB! But if you absolutely need to"
 
1837
                        " downgrade, see\n"
 
1838
                        "InnoDB: " REFMAN "multiple-tablespaces.html\n"
 
1839
                        "InnoDB: for instructions.\n");
1816
1840
        }
1817
1841
 
1818
1842
        if (srv_force_recovery == 0) {
1840
1864
/*=============================*/
1841
1865
{
1842
1866
        ulint   i;
 
1867
#ifdef __NETWARE__
 
1868
        extern ibool panic_shutdown;
 
1869
#endif
1843
1870
        if (!srv_was_started) {
1844
1871
                if (srv_is_being_started) {
1845
 
                  drizzled::errmsg_printf(drizzled::error::ERROR,
1846
 
                                "InnoDB: Warning: shutting down a not properly started or created database!");
 
1872
                        ut_print_timestamp(stderr);
 
1873
                        fprintf(stderr,
 
1874
                                "  InnoDB: Warning: shutting down"
 
1875
                                " a not properly started\n"
 
1876
                                "InnoDB: or created database!\n");
1847
1877
                }
1848
1878
 
1849
1879
                return(DB_SUCCESS);
1856
1886
 
1857
1887
 
1858
1888
        if (srv_fast_shutdown == 2) {
1859
 
                drizzled::errmsg_printf(drizzled::error::INFO,
1860
 
                                        "InnoDB: MySQL has requested a very fast shutdown without flushing "
1861
 
                                        "the InnoDB buffer pool to data files. At the next mysqld startup "
1862
 
                                        "InnoDB will do a crash recovery!");
 
1889
                ut_print_timestamp(stderr);
 
1890
                fprintf(stderr,
 
1891
                        "  InnoDB: MySQL has requested a very fast shutdown"
 
1892
                        " without flushing "
 
1893
                        "the InnoDB buffer pool to data files."
 
1894
                        " At the next mysqld startup "
 
1895
                        "InnoDB will do a crash recovery!\n");
1863
1896
        }
1864
1897
 
1865
 
        logs_empty_and_mark_files_at_shutdown();
 
1898
#ifdef __NETWARE__
 
1899
        if (!panic_shutdown)
 
1900
#endif
 
1901
                logs_empty_and_mark_files_at_shutdown();
1866
1902
 
1867
1903
        if (srv_conc_n_threads != 0) {
1868
 
          drizzled::errmsg_printf(drizzled::error::WARN,
1869
 
                                  "InnoDB: Warning: query counter shows %ld queries still InnoDB: inside InnoDB at shutdown.",
1870
 
                                  srv_conc_n_threads);
 
1904
                fprintf(stderr,
 
1905
                        "InnoDB: Warning: query counter shows %ld queries"
 
1906
                        " still\n"
 
1907
                        "InnoDB: inside InnoDB at shutdown\n",
 
1908
                        srv_conc_n_threads);
1871
1909
        }
1872
1910
 
1873
1911
        /* 2. Make all threads created by InnoDB to exit */
1899
1937
                /* c. We wake the master thread so that it exits */
1900
1938
                srv_wake_master_thread();
1901
1939
 
1902
 
                /* d. We wake the purge thread so that it exits */
1903
 
                srv_wake_purge_thread();
1904
 
 
1905
 
                /* e. Exit the i/o threads */
 
1940
                /* d. Exit the i/o threads */
1906
1941
 
1907
1942
                os_aio_wake_all_threads_at_shutdown();
1908
1943
 
1930
1965
        }
1931
1966
 
1932
1967
        if (i == 1000) {
1933
 
          drizzled::errmsg_printf(drizzled::error::WARN,
1934
 
                        "InnoDB: Warning: %lu threads created by InnoDB had not exited at shutdown!",
 
1968
                fprintf(stderr,
 
1969
                        "InnoDB: Warning: %lu threads created by InnoDB"
 
1970
                        " had not exited at shutdown!\n",
1935
1971
                        (ulong) os_thread_count);
1936
1972
        }
1937
1973
 
1985
2021
 
1986
2022
        pars_lexer_close();
1987
2023
        log_mem_free();
1988
 
        buf_pool_free(srv_buf_pool_instances);
 
2024
        buf_pool_free();
 
2025
        ut_free_all_mem();
1989
2026
        mem_close();
1990
2027
 
1991
 
        /* ut_free_all_mem() frees all allocated memory not freed yet
1992
 
        in shutdown, and it will also free the ut_list_mutex, so it
1993
 
        should be the last one for all operation */
1994
 
        ut_free_all_mem();
1995
 
 
1996
2028
        if (os_thread_count != 0
1997
2029
            || os_event_count != 0
1998
2030
            || os_mutex_count != 0
1999
2031
            || os_fast_mutex_count != 0) {
2000
 
          drizzled::errmsg_printf(drizzled::error::WARN,
2001
 
                                  "InnoDB: Warning: some resources were not cleaned up in shutdown:\n"
2002
 
                                  "InnoDB: threads %lu, events %lu, os_mutexes %lu, os_fast_mutexes %lu\n",
2003
 
                                  (ulong) os_thread_count, (ulong) os_event_count,
2004
 
                                  (ulong) os_mutex_count, (ulong) os_fast_mutex_count);
 
2032
                fprintf(stderr,
 
2033
                        "InnoDB: Warning: some resources were not"
 
2034
                        " cleaned up in shutdown:\n"
 
2035
                        "InnoDB: threads %lu, events %lu,"
 
2036
                        " os_mutexes %lu, os_fast_mutexes %lu\n",
 
2037
                        (ulong) os_thread_count, (ulong) os_event_count,
 
2038
                        (ulong) os_mutex_count, (ulong) os_fast_mutex_count);
2005
2039
        }
2006
2040
 
2007
2041
        if (dict_foreign_err_file) {
2012
2046
        }
2013
2047
 
2014
2048
        if (srv_print_verbose_log) {
2015
 
                drizzled::errmsg_printf(drizzled::error::INFO,
2016
 
                                        "InnoDB: Shutdown completed log sequence number %"PRIu64,
2017
 
                                        srv_shutdown_lsn);
 
2049
                ut_print_timestamp(stderr);
 
2050
                fprintf(stderr,
 
2051
                        "  InnoDB: Shutdown completed;"
 
2052
                        " log sequence number %"PRIu64"\n",
 
2053
                        srv_shutdown_lsn);
2018
2054
        }
2019
2055
 
2020
2056
        srv_was_started = FALSE;
2022
2058
 
2023
2059
        return((int) DB_SUCCESS);
2024
2060
}
 
2061
 
 
2062
#ifdef __NETWARE__
 
2063
void set_panic_flag_for_netware()
 
2064
{
 
2065
        extern ibool panic_shutdown;
 
2066
        panic_shutdown = TRUE;
 
2067
}
 
2068
#endif /* __NETWARE__ */
2025
2069
#endif /* !UNIV_HOTBACKUP */