~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
#include "que0que.h"
58
58
 
59
59
/* Log sequence number immediately after startup */
60
 
UNIV_INTERN ib_uint64_t srv_start_lsn;
 
60
dulint          srv_start_lsn;
61
61
/* Log sequence number at shutdown */
62
 
UNIV_INTERN ib_uint64_t srv_shutdown_lsn;
 
62
dulint          srv_shutdown_lsn;
63
63
 
64
64
#ifdef HAVE_DARWIN_THREADS
65
65
# include <sys/utsname.h>
66
 
UNIV_INTERN ibool       srv_have_fullfsync = FALSE;
 
66
ibool           srv_have_fullfsync = FALSE;
67
67
#endif
68
68
 
69
 
UNIV_INTERN ibool       srv_start_raw_disk_in_use = FALSE;
70
 
 
71
 
UNIV_INTERN ibool       srv_startup_is_before_trx_rollback_phase = FALSE;
72
 
UNIV_INTERN ibool       srv_is_being_started = FALSE;
73
 
UNIV_INTERN ibool       srv_was_started = FALSE;
 
69
ibool           srv_start_raw_disk_in_use = FALSE;
 
70
 
 
71
ulint           srv_sizeof_trx_t_in_ha_innodb_cc;
 
72
 
 
73
ibool           srv_startup_is_before_trx_rollback_phase = FALSE;
 
74
ibool           srv_is_being_started = FALSE;
74
75
#ifndef UNIV_HOTBACKUP
75
76
static ibool    srv_start_has_been_called = FALSE;
 
77
static ibool    srv_was_started = FALSE;
76
78
#endif /* !UNIV_HOTBACKUP */
77
79
 
78
80
/* At a shutdown the value first climbs to SRV_SHUTDOWN_CLEANUP
79
81
and then to SRV_SHUTDOWN_LAST_PHASE */
80
 
UNIV_INTERN ulint               srv_shutdown_state = 0;
 
82
ulint           srv_shutdown_state = 0;
81
83
 
82
84
#ifndef UNIV_HOTBACKUP
83
85
static os_file_t        files[1000];
148
150
/*************************************************************************
149
151
Reads the data files and their sizes from a character string given in
150
152
the .cnf file. */
151
 
UNIV_INTERN
 
153
 
152
154
ibool
153
155
srv_parse_data_file_paths_and_sizes(
154
156
/*================================*/
340
342
/*************************************************************************
341
343
Reads log group home directories from a character string given in
342
344
the .cnf file. */
343
 
UNIV_INTERN
 
345
 
344
346
ibool
345
347
srv_parse_log_group_home_dirs(
346
348
/*==========================*/
455
457
 
456
458
/*************************************************************************
457
459
Normalizes a directory path for Windows: converts slashes to backslashes. */
458
 
UNIV_INTERN
 
460
 
459
461
void
460
462
srv_normalize_path_for_win(
461
463
/*=======================*/
475
477
/*************************************************************************
476
478
Adds a slash or a backslash to the end of a string if it is missing
477
479
and the string is not empty. */
478
 
UNIV_INTERN
 
480
 
479
481
char*
480
482
srv_add_path_separator_if_needed(
481
483
/*=============================*/
650
652
                which is for this log group */
651
653
 
652
654
                fil_space_create(name,
653
 
                                 2 * k + SRV_LOG_SPACE_FIRST_ID, 0, FIL_LOG);
 
655
                                 2 * k + SRV_LOG_SPACE_FIRST_ID, FIL_LOG);
654
656
        }
655
657
 
656
658
        ut_a(fil_validate());
665
667
        if (k == 0 && i == 0) {
666
668
                arch_space_id = 2 * k + 1 + SRV_LOG_SPACE_FIRST_ID;
667
669
 
668
 
                fil_space_create("arch_log_space", arch_space_id, 0, FIL_LOG);
 
670
                fil_space_create("arch_log_space", arch_space_id, FIL_LOG);
669
671
        } else {
670
672
                arch_space_id = ULINT_UNDEFINED;
671
673
        }
687
689
ulint
688
690
open_or_create_data_files(
689
691
/*======================*/
690
 
                                        /* out: DB_SUCCESS or error code */
691
 
        ibool*          create_new_db,  /* out: TRUE if new database should be
692
 
                                        created */
 
692
                                /* out: DB_SUCCESS or error code */
 
693
        ibool*  create_new_db,  /* out: TRUE if new database should be
 
694
                                                                created */
693
695
#ifdef UNIV_LOG_ARCHIVE
694
 
        ulint*          min_arch_log_no,/* out: min of archived log
695
 
                                        numbers in data files */
696
 
        ulint*          max_arch_log_no,/* out: max of archived log
697
 
                                        numbers in data files */
 
696
        ulint*  min_arch_log_no,/* out: min of archived log numbers in data
 
697
                                files */
 
698
        ulint*  max_arch_log_no,/* out: */
698
699
#endif /* UNIV_LOG_ARCHIVE */
699
 
        ib_uint64_t*    min_flushed_lsn,/* out: min of flushed lsn
700
 
                                        values in data files */
701
 
        ib_uint64_t*    max_flushed_lsn,/* out: max of flushed lsn
702
 
                                        values in data files */
703
 
        ulint*          sum_of_new_sizes)/* out: sum of sizes of the
704
 
                                        new files added */
 
700
        dulint* min_flushed_lsn,/* out: min of flushed lsn values in data
 
701
                                files */
 
702
        dulint* max_flushed_lsn,/* out: */
 
703
        ulint*  sum_of_new_sizes)/* out: sum of sizes of the new files added */
705
704
{
706
705
        ibool   ret;
707
706
        ulint   i;
937
936
                ut_a(ret);
938
937
 
939
938
                if (i == 0) {
940
 
                        fil_space_create(name, 0, 0, FIL_TABLESPACE);
 
939
                        fil_space_create(name, 0, FIL_TABLESPACE);
941
940
                }
942
941
 
943
942
                ut_a(fil_validate());
944
943
 
945
 
                fil_node_create(name, srv_data_file_sizes[i], 0,
946
 
                                srv_data_file_is_raw_partition[i] != 0);
 
944
                if (srv_data_file_is_raw_partition[i]) {
 
945
 
 
946
                        fil_node_create(name, srv_data_file_sizes[i], 0, TRUE);
 
947
                } else {
 
948
                        fil_node_create(name, srv_data_file_sizes[i], 0,
 
949
                                        FALSE);
 
950
                }
947
951
        }
948
952
 
949
953
        ios = 0;
957
961
Starts InnoDB and creates a new database if database files
958
962
are not found and the user wants. Server parameters are
959
963
read from a file of name "srv_init" in the ib_home directory. */
960
 
UNIV_INTERN
 
964
 
961
965
int
962
966
innobase_start_or_create_for_mysql(void)
963
967
/*====================================*/
964
968
                                /* out: DB_SUCCESS or error code */
965
969
{
966
970
        buf_pool_t*     ret;
967
 
        ibool           create_new_db;
968
 
        ibool           log_file_created;
969
 
        ibool           log_created     = FALSE;
970
 
        ibool           log_opened      = FALSE;
971
 
        ib_uint64_t     min_flushed_lsn;
972
 
        ib_uint64_t     max_flushed_lsn;
 
971
        ibool   create_new_db;
 
972
        ibool   log_file_created;
 
973
        ibool   log_created     = FALSE;
 
974
        ibool   log_opened      = FALSE;
 
975
        dulint  min_flushed_lsn;
 
976
        dulint  max_flushed_lsn;
973
977
#ifdef UNIV_LOG_ARCHIVE
974
 
        ulint           min_arch_log_no;
975
 
        ulint           max_arch_log_no;
 
978
        ulint   min_arch_log_no;
 
979
        ulint   max_arch_log_no;
976
980
#endif /* UNIV_LOG_ARCHIVE */
977
 
        ulint           sum_of_new_sizes;
978
 
        ulint           sum_of_data_file_sizes;
979
 
        ulint           tablespace_size_in_header;
980
 
        ulint           err;
981
 
        ulint           i;
982
 
        my_bool         srv_file_per_table_original_value
983
 
                = srv_file_per_table;
984
 
        mtr_t           mtr;
 
981
        ulint   sum_of_new_sizes;
 
982
        ulint   sum_of_data_file_sizes;
 
983
        ulint   tablespace_size_in_header;
 
984
        ulint   err;
 
985
        ulint   i;
 
986
        ibool   srv_file_per_table_original_value  = srv_file_per_table;
 
987
        mtr_t   mtr;
985
988
#ifdef HAVE_DARWIN_THREADS
986
989
# ifdef F_FULLFSYNC
987
990
        /* This executable has been compiled on Mac OS X 10.3 or later.
1015
1018
                        (ulong)sizeof(ulint), (ulong)sizeof(void*));
1016
1019
        }
1017
1020
 
1018
 
        /* System tables are created in tablespace 0.  Thus, we must
1019
 
        temporarily clear srv_file_per_table.  This is ok, because the
1020
 
        server will not accept connections (which could modify
1021
 
        innodb_file_per_table) until this function has returned. */
1022
 
        srv_file_per_table = FALSE;
 
1021
        srv_file_per_table = FALSE; /* system tables are created in tablespace
 
1022
                                    0 */
1023
1023
#ifdef UNIV_DEBUG
1024
1024
        fprintf(stderr,
1025
1025
                "InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!\n");
1046
1046
                "InnoDB: !!!!!!!! UNIV_MEM_DEBUG switched on !!!!!!!!!\n");
1047
1047
#endif
1048
1048
 
 
1049
#ifdef UNIV_SIMULATE_AWE
 
1050
        fprintf(stderr,
 
1051
                "InnoDB: !!!!!!!! UNIV_SIMULATE_AWE switched on !!!!!!!!!\n");
 
1052
#endif
 
1053
        if (srv_sizeof_trx_t_in_ha_innodb_cc != (ulint)sizeof(trx_t)) {
 
1054
                fprintf(stderr,
 
1055
                        "InnoDB: Error: trx_t size is %lu in ha_innodb.cc"
 
1056
                        " but %lu in srv0start.c\n"
 
1057
                        "InnoDB: Check that pthread_mutex_t is defined"
 
1058
                        " in the same way in these\n"
 
1059
                        "InnoDB: compilation modules. Cannot continue.\n",
 
1060
                        (ulong)  srv_sizeof_trx_t_in_ha_innodb_cc,
 
1061
                        (ulong) sizeof(trx_t));
 
1062
                return(DB_ERROR);
 
1063
        }
 
1064
 
1049
1065
        /* Since InnoDB does not currently clean up all its internal data
1050
1066
        structures in MySQL Embedded Server Library server_end(), we
1051
1067
        print an error message if someone tries to start up InnoDB a
1072
1088
        srv_startup_is_before_trx_rollback_phase = TRUE;
1073
1089
        os_aio_use_native_aio = FALSE;
1074
1090
 
 
1091
#if !defined(__WIN2000__) && !defined(UNIV_SIMULATE_AWE)
 
1092
        if (srv_use_awe) {
 
1093
 
 
1094
                fprintf(stderr,
 
1095
                        "InnoDB: Error: You have specified"
 
1096
                        " innodb_buffer_pool_awe_mem_mb\n"
 
1097
                        "InnoDB: in my.cnf, but AWE can only"
 
1098
                        " be used in Windows 2000 and later.\n"
 
1099
                        "InnoDB: To use AWE, InnoDB must"
 
1100
                        " be compiled with __WIN2000__ defined.\n");
 
1101
 
 
1102
                return(DB_ERROR);
 
1103
        }
 
1104
#endif
 
1105
 
1075
1106
#ifdef __WIN__
1076
1107
        if (os_get_os_version() == OS_WIN95
1077
1108
            || os_get_os_version() == OS_WIN31
1131
1162
        }
1132
1163
 
1133
1164
        /* Note that the call srv_boot() also changes the values of
1134
 
        some variables to the units used by InnoDB internally */
 
1165
        srv_pool_size etc. to the units used by InnoDB internally */
1135
1166
 
1136
1167
        /* Set the maximum number of threads which can wait for a semaphore
1137
1168
        inside InnoDB: this is the 'sync wait array' size, as well as the
1138
1169
        maximum number of threads that can wait in the 'srv_conc array' for
1139
1170
        their time to enter InnoDB. */
1140
1171
 
1141
 
#if defined(__NETWARE__)
1142
 
 
1143
 
        /* Create less event semaphores because Win 98/ME had
1144
 
        difficulty creating 40000 event semaphores.  Comment from
1145
 
        Novell, Inc.: also, these just take a lot of memory on
1146
 
        NetWare. */
1147
 
        srv_max_n_threads = 1000;
1148
 
#else
1149
 
        if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
1150
 
                /* If buffer pool is less than 1000 MB,
 
1172
        if (srv_pool_size >= 1000 * 1024) {
 
1173
                /* Here we still have srv_pool_size counted
 
1174
                in kilobytes (in 4.0 this was in bytes)
 
1175
                srv_boot() converts the value to
 
1176
                pages; if buffer pool is less than 1000 MB,
1151
1177
                assume fewer threads. */
1152
1178
                srv_max_n_threads = 50000;
1153
1179
 
1154
 
        } else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
 
1180
        } else if (srv_pool_size >= 8 * 1024) {
1155
1181
 
1156
1182
                srv_max_n_threads = 10000;
1157
1183
        } else {
1159
1185
                                                especially in 64-bit
1160
1186
                                                computers */
1161
1187
        }
1162
 
#endif
1163
 
        err = srv_boot();
 
1188
        err = srv_boot(); /* This changes srv_pool_size to units of a page */
1164
1189
 
1165
1190
        if (err != DB_SUCCESS) {
1166
1191
 
1226
1251
 
1227
1252
        fil_init(srv_max_n_open_files);
1228
1253
 
1229
 
        ret = buf_pool_init();
 
1254
        if (srv_use_awe) {
 
1255
                fprintf(stderr,
 
1256
                        "InnoDB: Using AWE: Memory window is %lu MB"
 
1257
                        " and AWE memory is %lu MB\n",
 
1258
                        (ulong) (srv_awe_window_size / ((1024 * 1024)
 
1259
                                                        / UNIV_PAGE_SIZE)),
 
1260
                        (ulong) (srv_pool_size / ((1024 * 1024)
 
1261
                                                  / UNIV_PAGE_SIZE)));
 
1262
 
 
1263
                /* We must disable adaptive hash indexes because they do not
 
1264
                tolerate remapping of pages in AWE */
 
1265
 
 
1266
                srv_use_adaptive_hash_indexes = FALSE;
 
1267
                ret = buf_pool_init(srv_pool_size, srv_pool_size,
 
1268
                                    srv_awe_window_size);
 
1269
        } else {
 
1270
                ret = buf_pool_init(srv_pool_size, srv_pool_size,
 
1271
                                    srv_pool_size);
 
1272
        }
1230
1273
 
1231
1274
        if (ret == NULL) {
1232
1275
                fprintf(stderr,
1365
1408
            && !srv_archive_recovery
1366
1409
#endif /* UNIV_LOG_ARCHIVE */
1367
1410
            ) {
1368
 
                if (max_flushed_lsn != min_flushed_lsn
 
1411
                if (ut_dulint_cmp(max_flushed_lsn, min_flushed_lsn) != 0
1369
1412
#ifdef UNIV_LOG_ARCHIVE
1370
1413
                    || max_arch_log_no != min_arch_log_no
1371
1414
#endif /* UNIV_LOG_ARCHIVE */
1380
1423
                        return(DB_ERROR);
1381
1424
                }
1382
1425
 
1383
 
                if (max_flushed_lsn < (ib_uint64_t) 1000) {
 
1426
                if (ut_dulint_cmp(max_flushed_lsn, ut_dulint_create(0, 1000))
 
1427
                    < 0) {
1384
1428
                        fprintf(stderr,
1385
1429
                                "InnoDB: Cannot initialize created"
1386
1430
                                " log files because\n"
1408
1452
                mutex_exit(&(log_sys->mutex));
1409
1453
        }
1410
1454
 
1411
 
        trx_sys_file_format_init();
1412
 
 
1413
1455
        if (create_new_db) {
1414
1456
                mtr_start(&mtr);
 
1457
 
1415
1458
                fsp_header_init(0, sum_of_new_sizes, &mtr);
1416
1459
 
1417
1460
                mtr_commit(&mtr);
1441
1484
 
1442
1485
                /* Initialize the fsp free limit global variable in the log
1443
1486
                system */
1444
 
                fsp_header_get_free_limit();
 
1487
                fsp_header_get_free_limit(0);
1445
1488
 
1446
1489
                recv_recovery_from_archive_finish();
1447
1490
#endif /* UNIV_LOG_ARCHIVE */
1448
1491
        } else {
1449
 
 
1450
 
                /* Check if we support the max format that is stamped
1451
 
                on the system tablespace. */
1452
 
                err = trx_sys_file_format_max_check(
1453
 
                        srv_check_file_format_at_startup);
1454
 
 
1455
 
                if (err != DB_SUCCESS) {
1456
 
                        return(err);
1457
 
                }
1458
 
 
1459
1492
                /* We always try to do a recovery, even if the database had
1460
1493
                been shut down normally: this is the normal startup path */
1461
1494
 
1462
1495
                err = recv_recovery_from_checkpoint_start(LOG_CHECKPOINT,
1463
 
                                                          IB_ULONGLONG_MAX,
 
1496
                                                          ut_dulint_max,
1464
1497
                                                          min_flushed_lsn,
1465
1498
                                                          max_flushed_lsn);
1466
1499
                if (err != DB_SUCCESS) {
1506
1539
 
1507
1540
                /* Initialize the fsp free limit global variable in the log
1508
1541
                system */
1509
 
                fsp_header_get_free_limit();
 
1542
                fsp_header_get_free_limit(0);
1510
1543
 
1511
1544
                /* recv_recovery_from_checkpoint_finish needs trx lists which
1512
1545
                are initialized in trx_sys_init_at_db_start(). */
1562
1595
        /* Create the thread which warns of long semaphore waits */
1563
1596
        os_thread_create(&srv_error_monitor_thread, NULL,
1564
1597
                         thread_ids + 3 + SRV_MAX_N_IO_THREADS);
 
1598
        srv_was_started = TRUE;
1565
1599
        srv_is_being_started = FALSE;
1566
1600
 
1567
1601
        if (trx_doublewrite == NULL) {
1590
1624
                sum_of_data_file_sizes += srv_data_file_sizes[i];
1591
1625
        }
1592
1626
 
1593
 
        tablespace_size_in_header = fsp_header_get_tablespace_size();
 
1627
        tablespace_size_in_header = fsp_header_get_tablespace_size(0);
1594
1628
 
1595
1629
        if (!srv_auto_extend_last_data_file
1596
1630
            && sum_of_data_file_sizes != tablespace_size_in_header) {
1674
1708
        if (srv_print_verbose_log) {
1675
1709
                ut_print_timestamp(stderr);
1676
1710
                fprintf(stderr,
1677
 
                        " InnoDB Plugin %s started; "
1678
 
                        "log sequence number %"PRIu64"\n",
1679
 
                        INNODB_VERSION_STR, srv_start_lsn);
 
1711
                        "  InnoDB: Started; log sequence number %lu %lu\n",
 
1712
                        (ulong) ut_dulint_get_high(srv_start_lsn),
 
1713
                        (ulong) ut_dulint_get_low(srv_start_lsn));
1680
1714
        }
1681
1715
 
1682
1716
        if (srv_force_recovery > 0) {
1748
1782
 
1749
1783
        srv_file_per_table = srv_file_per_table_original_value;
1750
1784
 
1751
 
        srv_was_started = TRUE;
1752
 
 
1753
1785
        return((int) DB_SUCCESS);
1754
1786
}
1755
1787
 
1756
1788
/********************************************************************
1757
1789
Shuts down the InnoDB database. */
1758
 
UNIV_INTERN
 
1790
 
1759
1791
int
1760
1792
innobase_shutdown_for_mysql(void)
1761
1793
/*=============================*/
1762
1794
                                /* out: DB_SUCCESS or error code */
1763
1795
{
1764
1796
        ulint   i;
1765
 
#ifdef __NETWARE__
1766
 
        extern ibool panic_shutdown;
1767
 
#endif
1768
1797
        if (!srv_was_started) {
1769
1798
                if (srv_is_being_started) {
1770
1799
                        ut_print_timestamp(stderr);
1793
1822
                        "InnoDB will do a crash recovery!\n");
1794
1823
        }
1795
1824
 
1796
 
#ifdef __NETWARE__
1797
 
        if(!panic_shutdown)
1798
 
#endif
1799
 
                logs_empty_and_mark_files_at_shutdown();
 
1825
        logs_empty_and_mark_files_at_shutdown();
1800
1826
 
1801
1827
        if (srv_conc_n_threads != 0) {
1802
1828
                fprintf(stderr,
1885
1911
                srv_misc_tmpfile = 0;
1886
1912
        }
1887
1913
 
1888
 
        trx_sys_file_format_close();
1889
 
 
1890
1914
        mutex_free(&srv_monitor_file_mutex);
1891
1915
        mutex_free(&srv_dict_tmpfile_mutex);
1892
1916
        mutex_free(&srv_misc_tmpfile_mutex);
1914
1938
        /* 5. Free all allocated memory and the os_fast_mutex created in
1915
1939
        ut0mem.c */
1916
1940
 
1917
 
        buf_pool_free();
1918
1941
        ut_free_all_mem();
1919
1942
 
1920
1943
        if (os_thread_count != 0
1941
1964
                ut_print_timestamp(stderr);
1942
1965
                fprintf(stderr,
1943
1966
                        "  InnoDB: Shutdown completed;"
1944
 
                        " log sequence number %"PRIu64"\n",
1945
 
                        srv_shutdown_lsn);
 
1967
                        " log sequence number %lu %lu\n",
 
1968
                        (ulong) ut_dulint_get_high(srv_shutdown_lsn),
 
1969
                        (ulong) ut_dulint_get_low(srv_shutdown_lsn));
1946
1970
        }
1947
1971
 
1948
 
        srv_was_started = FALSE;
1949
 
 
1950
1972
        return((int) DB_SUCCESS);
1951
1973
}
1952
1974
 
1953
 
#ifdef __NETWARE__
1954
 
void set_panic_flag_for_netware()
1955
 
{
1956
 
        extern ibool panic_shutdown;
1957
 
        panic_shutdown = TRUE;
1958
 
}
1959
 
#endif /* __NETWARE__ */
1960
1975
#endif /* !UNIV_HOTBACKUP */