~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Barry.Leslie at PrimeBase
  • Date: 2011-01-22 03:22:44 UTC
  • mfrom: (2101 staging)
  • mto: (2228.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2230.
  • Revision ID: barry.leslie@primebase.com-20110122032244-ukbe3mlj7fs8xph6
Merged with lp:drizzle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
4
 
Copyright (c) 2008, 2009 Google Inc.
5
 
Copyright (c) 2009, Percona Inc.
 
3
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
 
4
Copyright (C) 2008, 2009 Google Inc.
 
5
Copyright (C) 2009, Percona Inc.
6
6
 
7
7
Portions of this file contain modifications contributed and copyrighted by
8
8
Google, Inc. Those modifications are gratefully acknowledged and are described
106
106
 
107
107
UNIV_INTERN const char* srv_main_thread_op_info = "";
108
108
 
109
 
/** Prefix used by MySQL to indicate pre-5.1 table name encoding */
110
 
UNIV_INTERN const char  srv_mysql50_table_name_prefix[9] = "#mysql50#";
111
 
 
112
109
/* Server parameters which are read from the initfile */
113
110
 
114
111
/* The following three are dir paths which are catenated before file
204
201
/** The sort order table of the MySQL latin1_swedish_ci character set
205
202
collation */
206
203
#if defined(BUILD_DRIZZLE)
207
 
UNIV_INTERN const byte  srv_latin1_ordering[256]        /* The sort order table of the latin1
 
204
const byte      srv_latin1_ordering[256]        /* The sort order table of the latin1
208
205
                                        character set. The following table is
209
206
                                        the MySQL order as of Feb 10th, 2002 */
210
207
= {
463
460
UNIV_INTERN ib_int64_t  srv_n_lock_wait_time            = 0;
464
461
UNIV_INTERN ulint               srv_n_lock_max_wait_time        = 0;
465
462
 
 
463
UNIV_INTERN ulint               srv_truncated_status_writes     = 0;
466
464
 
467
465
/*
468
466
  Set the following to 0 if you want InnoDB to write messages on
733
731
/* Table for MySQL threads where they will be suspended to wait for locks */
734
732
UNIV_INTERN srv_slot_t* srv_mysql_table = NULL;
735
733
 
 
734
UNIV_INTERN os_event_t  srv_timeout_event;
 
735
 
 
736
UNIV_INTERN os_event_t  srv_monitor_event;
 
737
 
 
738
UNIV_INTERN os_event_t  srv_error_event;
 
739
 
736
740
UNIV_INTERN os_event_t  srv_lock_timeout_thread_event;
737
741
 
738
742
UNIV_INTERN srv_sys_t*  srv_sys = NULL;
903
907
 
904
908
        slot = srv_table_get_nth_slot(slot_no);
905
909
 
906
 
        type = slot->type;
 
910
        type = static_cast<srv_thread_type>(slot->type);
907
911
 
908
912
        ut_ad(type >= SRV_WORKER);
909
913
        ut_ad(type <= SRV_MASTER);
946
950
 
947
951
                slot = srv_table_get_nth_slot(i);
948
952
 
949
 
                if (slot->in_use && slot->type == type && slot->suspended) {
 
953
                if (slot->in_use &&
 
954
                    (static_cast<srv_thread_type>(slot->type) == type) &&
 
955
                    slot->suspended) {
950
956
 
951
957
                        slot->suspended = FALSE;
952
958
 
991
997
 
992
998
        slot = srv_table_get_nth_slot(slot_no);
993
999
 
994
 
        type = slot->type;
 
1000
        type = static_cast<srv_thread_type>(slot->type);
995
1001
 
996
1002
        ut_ad(type >= SRV_WORKER);
997
1003
        ut_ad(type <= SRV_MASTER);
1012
1018
        srv_slot_t*             slot;
1013
1019
        ulint                   i;
1014
1020
 
1015
 
        srv_sys = mem_alloc(sizeof(srv_sys_t));
 
1021
        srv_sys = static_cast<srv_sys_t *>(mem_alloc(sizeof(srv_sys_t)));
1016
1022
 
1017
 
        kernel_mutex_temp = mem_alloc(sizeof(mutex_t));
 
1023
        kernel_mutex_temp = static_cast<ib_mutex_t *>(mem_alloc(sizeof(mutex_t)));
1018
1024
        mutex_create(kernel_mutex_key, &kernel_mutex, SYNC_KERNEL);
1019
1025
 
1020
1026
        mutex_create(srv_innodb_monitor_mutex_key,
1021
1027
                     &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
1022
1028
 
1023
 
        srv_sys->threads = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
 
1029
        srv_sys->threads = static_cast<srv_table_t *>(mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t)));
1024
1030
 
1025
1031
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1026
1032
                slot = srv_table_get_nth_slot(i);
1030
1036
                ut_a(slot->event);
1031
1037
        }
1032
1038
 
1033
 
        srv_mysql_table = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
 
1039
        srv_mysql_table = static_cast<srv_slot_t *>(mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t)));
1034
1040
 
1035
1041
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1036
1042
                slot = srv_mysql_table + i;
1040
1046
                ut_a(slot->event);
1041
1047
        }
1042
1048
 
 
1049
        srv_error_event = os_event_create(NULL);
 
1050
 
 
1051
        srv_timeout_event = os_event_create(NULL);
 
1052
 
 
1053
        srv_monitor_event = os_event_create(NULL);
 
1054
 
1043
1055
        srv_lock_timeout_thread_event = os_event_create(NULL);
1044
1056
 
1045
1057
        for (i = 0; i < SRV_MASTER + 1; i++) {
1066
1078
 
1067
1079
        UT_LIST_INIT(srv_conc_queue);
1068
1080
 
1069
 
        srv_conc_slots = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_conc_slot_t));
 
1081
        srv_conc_slots = static_cast<srv_conc_slot_t *>(mem_alloc(OS_THREAD_MAX_N * sizeof(srv_conc_slot_t)));
1070
1082
 
1071
1083
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1072
1084
                conc_slot = srv_conc_slots + i;
1619
1631
                row_mysql_unfreeze_data_dictionary(trx);
1620
1632
                break;
1621
1633
        case RW_X_LATCH:
 
1634
                /* There should never be a lock wait when the
 
1635
                dictionary latch is reserved in X mode.  Dictionary
 
1636
                transactions should only acquire locks on dictionary
 
1637
                tables, not other tables. All access to dictionary
 
1638
                tables should be covered by dictionary
 
1639
                transactions. */
 
1640
                ut_print_timestamp(stderr);
 
1641
                fputs("  InnoDB: Error: dict X latch held in "
 
1642
                      "srv_suspend_mysql_thread\n", stderr);
 
1643
                /* This should never occur. This incorrect handling
 
1644
                was added in the early development of
 
1645
                ha_innobase::add_index() in InnoDB Plugin 1.0. */
1622
1646
                /* Release fast index creation latch */
1623
1647
                row_mysql_unlock_data_dictionary(trx);
1624
1648
                break;
1638
1662
                row_mysql_freeze_data_dictionary(trx);
1639
1663
                break;
1640
1664
        case RW_X_LATCH:
 
1665
                /* This should never occur. This incorrect handling
 
1666
                was added in the early development of
 
1667
                ha_innobase::add_index() in InnoDB Plugin 1.0. */
1641
1668
                row_mysql_lock_data_dictionary(trx);
1642
1669
                break;
1643
1670
        }
1904
1931
                (ulong) srv_conc_n_waiting_threads);
1905
1932
 
1906
1933
        fprintf(file, "%lu read views open inside InnoDB\n",
1907
 
                UT_LIST_GET_LEN(trx_sys->view_list));
 
1934
                static_cast<ulint>(UT_LIST_GET_LEN(trx_sys->view_list)));
1908
1935
 
1909
1936
        n_reserved = fil_space_get_n_reserved_extents(0);
1910
1937
        if (n_reserved > 0) {
2042
2069
        export_vars.innodb_rows_inserted = srv_n_rows_inserted;
2043
2070
        export_vars.innodb_rows_updated = srv_n_rows_updated;
2044
2071
        export_vars.innodb_rows_deleted = srv_n_rows_deleted;
 
2072
        export_vars.innodb_truncated_status_writes = srv_truncated_status_writes;
2045
2073
 
2046
2074
        mutex_exit(&srv_innodb_monitor_mutex);
2047
2075
}
2053
2081
os_thread_ret_t
2054
2082
srv_monitor_thread(
2055
2083
/*===============*/
2056
 
        void*   arg __attribute__((unused)))
 
2084
        void*   /*arg __attribute__((unused))*/)
2057
2085
                        /*!< in: a dummy parameter required by
2058
2086
                        os_thread_create */
2059
2087
{
 
2088
        ib_int64_t      sig_count;
2060
2089
        double          time_elapsed;
2061
2090
        time_t          current_time;
2062
2091
        time_t          last_table_monitor_time;
2074
2103
        pfs_register_thread(srv_monitor_thread_key);
2075
2104
#endif
2076
2105
 
2077
 
        UT_NOT_USED(arg);
2078
 
        srv_last_monitor_time = time(NULL);
2079
 
        last_table_monitor_time = time(NULL);
2080
 
        last_tablespace_monitor_time = time(NULL);
2081
 
        last_monitor_time = time(NULL);
 
2106
        srv_last_monitor_time = ut_time();
 
2107
        last_table_monitor_time = ut_time();
 
2108
        last_tablespace_monitor_time = ut_time();
 
2109
        last_monitor_time = ut_time();
2082
2110
        mutex_skipped = 0;
2083
2111
        last_srv_print_monitor = srv_print_innodb_monitor;
2084
2112
loop:
2085
2113
        srv_monitor_active = TRUE;
2086
2114
 
2087
2115
        /* Wake up every 5 seconds to see if we need to print
2088
 
        monitor information. */
2089
 
 
2090
 
        os_thread_sleep(5000000);
2091
 
 
2092
 
        current_time = time(NULL);
 
2116
        monitor information or if signalled at shutdown. */
 
2117
 
 
2118
        sig_count = os_event_reset(srv_monitor_event);
 
2119
 
 
2120
        os_event_wait_time_low(srv_monitor_event, 5000000, sig_count);
 
2121
 
 
2122
        current_time = ut_time();
2093
2123
 
2094
2124
        time_elapsed = difftime(current_time, last_monitor_time);
2095
2125
 
2096
2126
        if (time_elapsed > 15) {
2097
 
                last_monitor_time = time(NULL);
 
2127
                last_monitor_time = ut_time();
2098
2128
 
2099
2129
                if (srv_print_innodb_monitor) {
2100
2130
                        /* Reset mutex_skipped counter everytime
2138
2168
                if (srv_print_innodb_tablespace_monitor
2139
2169
                    && difftime(current_time,
2140
2170
                                last_tablespace_monitor_time) > 60) {
2141
 
                        last_tablespace_monitor_time = time(NULL);
 
2171
                        last_tablespace_monitor_time = ut_time();
2142
2172
 
2143
2173
                        fputs("========================"
2144
2174
                              "========================\n",
2164
2194
                if (srv_print_innodb_table_monitor
2165
2195
                    && difftime(current_time, last_table_monitor_time) > 60) {
2166
2196
 
2167
 
                        last_table_monitor_time = time(NULL);
 
2197
                        last_table_monitor_time = ut_time();
2168
2198
 
2169
2199
                        fputs("===========================================\n",
2170
2200
                              stderr);
2216
2246
os_thread_ret_t
2217
2247
srv_lock_timeout_thread(
2218
2248
/*====================*/
2219
 
        void*   arg __attribute__((unused)))
 
2249
        void*   /*arg __attribute__((unused))*/)
2220
2250
                        /* in: a dummy parameter required by
2221
2251
                        os_thread_create */
2222
2252
{
2224
2254
        ibool           some_waits;
2225
2255
        double          wait_time;
2226
2256
        ulint           i;
 
2257
        ib_int64_t      sig_count;
2227
2258
 
2228
2259
#ifdef UNIV_PFS_THREAD
2229
2260
        pfs_register_thread(srv_lock_timeout_thread_key);
2230
2261
#endif
2231
2262
 
2232
2263
loop:
 
2264
 
2233
2265
        /* When someone is waiting for a lock, we wake up every second
2234
2266
        and check if a timeout has passed for a lock wait */
2235
2267
 
2236
 
        os_thread_sleep(1000000);
 
2268
        sig_count = os_event_reset(srv_timeout_event);
 
2269
 
 
2270
        os_event_wait_time_low(srv_timeout_event, 1000000, sig_count);
2237
2271
 
2238
2272
        srv_lock_timeout_active = TRUE;
2239
2273
 
2320
2354
os_thread_ret_t
2321
2355
srv_error_monitor_thread(
2322
2356
/*=====================*/
2323
 
        void*   arg __attribute__((unused)))
 
2357
        void*   /*arg __attribute__((unused))*/)
2324
2358
                        /*!< in: a dummy parameter required by
2325
2359
                        os_thread_create */
2326
2360
{
2328
2362
        ulint           fatal_cnt       = 0;
2329
2363
        ib_uint64_t     old_lsn;
2330
2364
        ib_uint64_t     new_lsn;
 
2365
        ib_int64_t      sig_count;
2331
2366
 
2332
2367
        old_lsn = srv_start_lsn;
2333
2368
 
2403
2438
 
2404
2439
        fflush(stderr);
2405
2440
 
2406
 
        os_thread_sleep(1000000);
 
2441
        sig_count = os_event_reset(srv_error_event);
 
2442
 
 
2443
        os_event_wait_time_low(srv_error_event, 1000000, sig_count);
2407
2444
 
2408
2445
        if (srv_shutdown_state < SRV_SHUTDOWN_CLEANUP) {
2409
2446
 
2582
2619
os_thread_ret_t
2583
2620
srv_master_thread(
2584
2621
/*==============*/
2585
 
        void*   arg __attribute__((unused)))
 
2622
        void*   /*arg __attribute__((unused))*/)
2586
2623
                        /*!< in: a dummy parameter required by
2587
2624
                        os_thread_create */
2588
2625
{
2647
2684
        when there is database activity */
2648
2685
 
2649
2686
        srv_last_log_flush_time = time(NULL);
2650
 
        next_itr_time = ut_time_ms();
 
2687
 
 
2688
        /* Sleep for 1 second on entrying the for loop below the first time. */
 
2689
        next_itr_time = ut_time_ms() + 1000;
2651
2690
 
2652
2691
        for (i = 0; i < 10; i++) {
2653
2692
                ulint   cur_time = ut_time_ms();
2654
2693
 
 
2694
                /* ALTER TABLE in MySQL requires on Unix that the table handler
 
2695
                can drop tables lazily after there no longer are SELECT
 
2696
                queries to them. */
 
2697
 
 
2698
                srv_main_thread_op_info = "doing background drop tables";
 
2699
 
 
2700
                row_drop_tables_for_mysql_in_background();
 
2701
 
 
2702
                srv_main_thread_op_info = "";
 
2703
 
 
2704
                if (srv_fast_shutdown && srv_shutdown_state > 0) {
 
2705
 
 
2706
                        goto background_loop;
 
2707
                }
 
2708
 
2655
2709
                buf_get_total_stat(&buf_stat);
2656
2710
 
2657
2711
                n_ios_old = log_sys->n_log_ios + buf_stat.n_pages_read
2660
2714
                srv_main_thread_op_info = "sleeping";
2661
2715
                srv_main_1_second_loops++;
2662
2716
 
2663
 
                if (next_itr_time > cur_time) {
 
2717
                if (next_itr_time > cur_time
 
2718
                    && srv_shutdown_state == SRV_SHUTDOWN_NONE) {
2664
2719
 
2665
2720
                        /* Get sleep interval in micro seconds. We use
2666
2721
                        ut_min() to avoid long sleep in case of
2674
2729
                /* Each iteration should happen at 1 second interval. */
2675
2730
                next_itr_time = ut_time_ms() + 1000;
2676
2731
 
2677
 
                /* ALTER TABLE in MySQL requires on Unix that the table handler
2678
 
                can drop tables lazily after there no longer are SELECT
2679
 
                queries to them. */
2680
 
 
2681
 
                srv_main_thread_op_info = "doing background drop tables";
2682
 
 
2683
 
                row_drop_tables_for_mysql_in_background();
2684
 
 
2685
 
                srv_main_thread_op_info = "";
2686
 
 
2687
 
                if (srv_fast_shutdown && srv_shutdown_state > 0) {
2688
 
 
2689
 
                        goto background_loop;
2690
 
                }
2691
 
 
2692
2732
                /* Flush logs if needed */
2693
2733
                srv_sync_log_buffer_in_background();
2694
2734
 
2866
2906
                MySQL tries to drop a table while there are still open handles
2867
2907
                to it and we had to put it to the background drop queue.) */
2868
2908
 
2869
 
                os_thread_sleep(100000);
 
2909
                if (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
 
2910
                        os_thread_sleep(100000);
 
2911
                }
2870
2912
        }
2871
2913
 
2872
2914
        if (srv_n_purge_threads == 0) {
3025
3067
        goto loop;
3026
3068
 
3027
3069
 
3028
 
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
 
3070
#if !defined(__SUNPRO_C)
3029
3071
        OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
3030
3072
#endif
3031
3073
}
3037
3079
os_thread_ret_t
3038
3080
srv_purge_thread(
3039
3081
/*=============*/
3040
 
        void*   arg __attribute__((unused)))    /*!< in: a dummy parameter
 
3082
        void*   /*arg __attribute__((unused))*/)        /*!< in: a dummy parameter
3041
3083
                                                required by os_thread_create */
3042
3084
{
3043
3085
        srv_slot_t*     slot;