~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Stewart Smith
  • Date: 2008-11-07 22:58:15 UTC
  • mto: This revision was merged to the branch mainline in revision 587.
  • Revision ID: stewart@flamingspork.com-20081107225815-ie2kwpxnytpstovl
remove trailing whitespace in serialize/table

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
 
dulint          srv_start_lsn;
 
60
UNIV_INTERN ib_uint64_t srv_start_lsn;
61
61
/* Log sequence number at shutdown */
62
 
dulint          srv_shutdown_lsn;
 
62
UNIV_INTERN ib_uint64_t srv_shutdown_lsn;
63
63
 
64
64
#ifdef HAVE_DARWIN_THREADS
65
65
# include <sys/utsname.h>
66
 
ibool           srv_have_fullfsync = FALSE;
 
66
UNIV_INTERN ibool       srv_have_fullfsync = FALSE;
67
67
#endif
68
68
 
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;
 
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;
75
74
#ifndef UNIV_HOTBACKUP
76
75
static ibool    srv_start_has_been_called = FALSE;
77
 
static ibool    srv_was_started = FALSE;
78
76
#endif /* !UNIV_HOTBACKUP */
79
77
 
80
78
/* At a shutdown the value first climbs to SRV_SHUTDOWN_CLEANUP
81
79
and then to SRV_SHUTDOWN_LAST_PHASE */
82
 
ulint           srv_shutdown_state = 0;
 
80
UNIV_INTERN ulint               srv_shutdown_state = 0;
83
81
 
84
82
#ifndef UNIV_HOTBACKUP
85
83
static os_file_t        files[1000];
150
148
/*************************************************************************
151
149
Reads the data files and their sizes from a character string given in
152
150
the .cnf file. */
153
 
 
 
151
UNIV_INTERN
154
152
ibool
155
153
srv_parse_data_file_paths_and_sizes(
156
154
/*================================*/
342
340
/*************************************************************************
343
341
Reads log group home directories from a character string given in
344
342
the .cnf file. */
345
 
 
 
343
UNIV_INTERN
346
344
ibool
347
345
srv_parse_log_group_home_dirs(
348
346
/*==========================*/
457
455
 
458
456
/*************************************************************************
459
457
Normalizes a directory path for Windows: converts slashes to backslashes. */
460
 
 
 
458
UNIV_INTERN
461
459
void
462
460
srv_normalize_path_for_win(
463
461
/*=======================*/
477
475
/*************************************************************************
478
476
Adds a slash or a backslash to the end of a string if it is missing
479
477
and the string is not empty. */
480
 
 
 
478
UNIV_INTERN
481
479
char*
482
480
srv_add_path_separator_if_needed(
483
481
/*=============================*/
652
650
                which is for this log group */
653
651
 
654
652
                fil_space_create(name,
655
 
                                 2 * k + SRV_LOG_SPACE_FIRST_ID, FIL_LOG);
 
653
                                 2 * k + SRV_LOG_SPACE_FIRST_ID, 0, FIL_LOG);
656
654
        }
657
655
 
658
656
        ut_a(fil_validate());
667
665
        if (k == 0 && i == 0) {
668
666
                arch_space_id = 2 * k + 1 + SRV_LOG_SPACE_FIRST_ID;
669
667
 
670
 
                fil_space_create("arch_log_space", arch_space_id, FIL_LOG);
 
668
                fil_space_create("arch_log_space", arch_space_id, 0, FIL_LOG);
671
669
        } else {
672
670
                arch_space_id = ULINT_UNDEFINED;
673
671
        }
689
687
ulint
690
688
open_or_create_data_files(
691
689
/*======================*/
692
 
                                /* out: DB_SUCCESS or error code */
693
 
        ibool*  create_new_db,  /* out: TRUE if new database should be
694
 
                                                                created */
 
690
                                        /* out: DB_SUCCESS or error code */
 
691
        ibool*          create_new_db,  /* out: TRUE if new database should be
 
692
                                        created */
695
693
#ifdef UNIV_LOG_ARCHIVE
696
 
        ulint*  min_arch_log_no,/* out: min of archived log numbers in data
697
 
                                files */
698
 
        ulint*  max_arch_log_no,/* out: */
 
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 */
699
698
#endif /* UNIV_LOG_ARCHIVE */
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 */
 
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 */
704
705
{
705
706
        ibool   ret;
706
707
        ulint   i;
936
937
                ut_a(ret);
937
938
 
938
939
                if (i == 0) {
939
 
                        fil_space_create(name, 0, FIL_TABLESPACE);
 
940
                        fil_space_create(name, 0, 0, FIL_TABLESPACE);
940
941
                }
941
942
 
942
943
                ut_a(fil_validate());
943
944
 
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
 
                }
 
945
                fil_node_create(name, srv_data_file_sizes[i], 0,
 
946
                                srv_data_file_is_raw_partition[i] != 0);
951
947
        }
952
948
 
953
949
        ios = 0;
961
957
Starts InnoDB and creates a new database if database files
962
958
are not found and the user wants. Server parameters are
963
959
read from a file of name "srv_init" in the ib_home directory. */
964
 
 
 
960
UNIV_INTERN
965
961
int
966
962
innobase_start_or_create_for_mysql(void)
967
963
/*====================================*/
968
964
                                /* out: DB_SUCCESS or error code */
969
965
{
970
966
        buf_pool_t*     ret;
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;
 
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;
977
973
#ifdef UNIV_LOG_ARCHIVE
978
 
        ulint   min_arch_log_no;
979
 
        ulint   max_arch_log_no;
 
974
        ulint           min_arch_log_no;
 
975
        ulint           max_arch_log_no;
980
976
#endif /* UNIV_LOG_ARCHIVE */
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;
 
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;
988
985
#ifdef HAVE_DARWIN_THREADS
989
986
# ifdef F_FULLFSYNC
990
987
        /* This executable has been compiled on Mac OS X 10.3 or later.
1018
1015
                        (ulong)sizeof(ulint), (ulong)sizeof(void*));
1019
1016
        }
1020
1017
 
1021
 
        srv_file_per_table = FALSE; /* system tables are created in tablespace
1022
 
                                    0 */
 
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;
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
 
 
1065
1049
        /* Since InnoDB does not currently clean up all its internal data
1066
1050
        structures in MySQL Embedded Server Library server_end(), we
1067
1051
        print an error message if someone tries to start up InnoDB a
1088
1072
        srv_startup_is_before_trx_rollback_phase = TRUE;
1089
1073
        os_aio_use_native_aio = FALSE;
1090
1074
 
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
 
 
1106
1075
#ifdef __WIN__
1107
1076
        if (os_get_os_version() == OS_WIN95
1108
1077
            || os_get_os_version() == OS_WIN31
1162
1131
        }
1163
1132
 
1164
1133
        /* Note that the call srv_boot() also changes the values of
1165
 
        srv_pool_size etc. to the units used by InnoDB internally */
 
1134
        some variables to the units used by InnoDB internally */
1166
1135
 
1167
1136
        /* Set the maximum number of threads which can wait for a semaphore
1168
1137
        inside InnoDB: this is the 'sync wait array' size, as well as the
1169
1138
        maximum number of threads that can wait in the 'srv_conc array' for
1170
1139
        their time to enter InnoDB. */
1171
1140
 
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,
 
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,
1177
1151
                assume fewer threads. */
1178
1152
                srv_max_n_threads = 50000;
1179
1153
 
1180
 
        } else if (srv_pool_size >= 8 * 1024) {
 
1154
        } else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
1181
1155
 
1182
1156
                srv_max_n_threads = 10000;
1183
1157
        } else {
1185
1159
                                                especially in 64-bit
1186
1160
                                                computers */
1187
1161
        }
1188
 
        err = srv_boot(); /* This changes srv_pool_size to units of a page */
 
1162
#endif
 
1163
        err = srv_boot();
1189
1164
 
1190
1165
        if (err != DB_SUCCESS) {
1191
1166
 
1251
1226
 
1252
1227
        fil_init(srv_max_n_open_files);
1253
1228
 
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
 
        }
 
1229
        ret = buf_pool_init();
1273
1230
 
1274
1231
        if (ret == NULL) {
1275
1232
                fprintf(stderr,
1408
1365
            && !srv_archive_recovery
1409
1366
#endif /* UNIV_LOG_ARCHIVE */
1410
1367
            ) {
1411
 
                if (ut_dulint_cmp(max_flushed_lsn, min_flushed_lsn) != 0
 
1368
                if (max_flushed_lsn != min_flushed_lsn
1412
1369
#ifdef UNIV_LOG_ARCHIVE
1413
1370
                    || max_arch_log_no != min_arch_log_no
1414
1371
#endif /* UNIV_LOG_ARCHIVE */
1423
1380
                        return(DB_ERROR);
1424
1381
                }
1425
1382
 
1426
 
                if (ut_dulint_cmp(max_flushed_lsn, ut_dulint_create(0, 1000))
1427
 
                    < 0) {
 
1383
                if (max_flushed_lsn < (ib_uint64_t) 1000) {
1428
1384
                        fprintf(stderr,
1429
1385
                                "InnoDB: Cannot initialize created"
1430
1386
                                " log files because\n"
1452
1408
                mutex_exit(&(log_sys->mutex));
1453
1409
        }
1454
1410
 
 
1411
        trx_sys_file_format_init();
 
1412
 
1455
1413
        if (create_new_db) {
1456
1414
                mtr_start(&mtr);
1457
 
 
1458
1415
                fsp_header_init(0, sum_of_new_sizes, &mtr);
1459
1416
 
1460
1417
                mtr_commit(&mtr);
1484
1441
 
1485
1442
                /* Initialize the fsp free limit global variable in the log
1486
1443
                system */
1487
 
                fsp_header_get_free_limit(0);
 
1444
                fsp_header_get_free_limit();
1488
1445
 
1489
1446
                recv_recovery_from_archive_finish();
1490
1447
#endif /* UNIV_LOG_ARCHIVE */
1491
1448
        } 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
 
1492
1459
                /* We always try to do a recovery, even if the database had
1493
1460
                been shut down normally: this is the normal startup path */
1494
1461
 
1495
1462
                err = recv_recovery_from_checkpoint_start(LOG_CHECKPOINT,
1496
 
                                                          ut_dulint_max,
 
1463
                                                          IB_ULONGLONG_MAX,
1497
1464
                                                          min_flushed_lsn,
1498
1465
                                                          max_flushed_lsn);
1499
1466
                if (err != DB_SUCCESS) {
1539
1506
 
1540
1507
                /* Initialize the fsp free limit global variable in the log
1541
1508
                system */
1542
 
                fsp_header_get_free_limit(0);
 
1509
                fsp_header_get_free_limit();
1543
1510
 
1544
1511
                /* recv_recovery_from_checkpoint_finish needs trx lists which
1545
1512
                are initialized in trx_sys_init_at_db_start(). */
1595
1562
        /* Create the thread which warns of long semaphore waits */
1596
1563
        os_thread_create(&srv_error_monitor_thread, NULL,
1597
1564
                         thread_ids + 3 + SRV_MAX_N_IO_THREADS);
1598
 
        srv_was_started = TRUE;
1599
1565
        srv_is_being_started = FALSE;
1600
1566
 
1601
1567
        if (trx_doublewrite == NULL) {
1624
1590
                sum_of_data_file_sizes += srv_data_file_sizes[i];
1625
1591
        }
1626
1592
 
1627
 
        tablespace_size_in_header = fsp_header_get_tablespace_size(0);
 
1593
        tablespace_size_in_header = fsp_header_get_tablespace_size();
1628
1594
 
1629
1595
        if (!srv_auto_extend_last_data_file
1630
1596
            && sum_of_data_file_sizes != tablespace_size_in_header) {
1708
1674
        if (srv_print_verbose_log) {
1709
1675
                ut_print_timestamp(stderr);
1710
1676
                fprintf(stderr,
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));
 
1677
                        " InnoDB Plugin %s started; "
 
1678
                        "log sequence number %"PRIu64"\n",
 
1679
                        INNODB_VERSION_STR, srv_start_lsn);
1714
1680
        }
1715
1681
 
1716
1682
        if (srv_force_recovery > 0) {
1782
1748
 
1783
1749
        srv_file_per_table = srv_file_per_table_original_value;
1784
1750
 
 
1751
        srv_was_started = TRUE;
 
1752
 
1785
1753
        return((int) DB_SUCCESS);
1786
1754
}
1787
1755
 
1788
1756
/********************************************************************
1789
1757
Shuts down the InnoDB database. */
1790
 
 
 
1758
UNIV_INTERN
1791
1759
int
1792
1760
innobase_shutdown_for_mysql(void)
1793
1761
/*=============================*/
1794
1762
                                /* out: DB_SUCCESS or error code */
1795
1763
{
1796
1764
        ulint   i;
 
1765
#ifdef __NETWARE__
 
1766
        extern ibool panic_shutdown;
 
1767
#endif
1797
1768
        if (!srv_was_started) {
1798
1769
                if (srv_is_being_started) {
1799
1770
                        ut_print_timestamp(stderr);
1822
1793
                        "InnoDB will do a crash recovery!\n");
1823
1794
        }
1824
1795
 
1825
 
        logs_empty_and_mark_files_at_shutdown();
 
1796
#ifdef __NETWARE__
 
1797
        if(!panic_shutdown)
 
1798
#endif
 
1799
                logs_empty_and_mark_files_at_shutdown();
1826
1800
 
1827
1801
        if (srv_conc_n_threads != 0) {
1828
1802
                fprintf(stderr,
1911
1885
                srv_misc_tmpfile = 0;
1912
1886
        }
1913
1887
 
 
1888
        trx_sys_file_format_close();
 
1889
 
1914
1890
        mutex_free(&srv_monitor_file_mutex);
1915
1891
        mutex_free(&srv_dict_tmpfile_mutex);
1916
1892
        mutex_free(&srv_misc_tmpfile_mutex);
1938
1914
        /* 5. Free all allocated memory and the os_fast_mutex created in
1939
1915
        ut0mem.c */
1940
1916
 
 
1917
        buf_pool_free();
1941
1918
        ut_free_all_mem();
1942
1919
 
1943
1920
        if (os_thread_count != 0
1964
1941
                ut_print_timestamp(stderr);
1965
1942
                fprintf(stderr,
1966
1943
                        "  InnoDB: Shutdown completed;"
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));
 
1944
                        " log sequence number %"PRIu64"\n",
 
1945
                        srv_shutdown_lsn);
1970
1946
        }
1971
1947
 
 
1948
        srv_was_started = FALSE;
 
1949
 
1972
1950
        return((int) DB_SUCCESS);
1973
1951
}
1974
1952
 
 
1953
#ifdef __NETWARE__
 
1954
void set_panic_flag_for_netware()
 
1955
{
 
1956
        extern ibool panic_shutdown;
 
1957
        panic_shutdown = TRUE;
 
1958
}
 
1959
#endif /* __NETWARE__ */
1975
1960
#endif /* !UNIV_HOTBACKUP */