~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Patrick Crews
  • Date: 2010-12-07 20:02:50 UTC
  • Revision ID: gleebix@gmail.com-20101207200250-6a27jgqalgw5bsb5
Added disabled.def file to disable drizzleslap due to Bug#684269.  Need to skip for tarball release this round

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
 
109
112
/* Server parameters which are read from the initfile */
110
113
 
111
114
/* The following three are dir paths which are catenated before file
201
204
/** The sort order table of the MySQL latin1_swedish_ci character set
202
205
collation */
203
206
#if defined(BUILD_DRIZZLE)
204
 
const byte      srv_latin1_ordering[256]        /* The sort order table of the latin1
 
207
UNIV_INTERN const byte  srv_latin1_ordering[256]        /* The sort order table of the latin1
205
208
                                        character set. The following table is
206
209
                                        the MySQL order as of Feb 10th, 2002 */
207
210
= {
460
463
UNIV_INTERN ib_int64_t  srv_n_lock_wait_time            = 0;
461
464
UNIV_INTERN ulint               srv_n_lock_max_wait_time        = 0;
462
465
 
463
 
UNIV_INTERN ulint               srv_truncated_status_writes     = 0;
464
466
 
465
467
/*
466
468
  Set the following to 0 if you want InnoDB to write messages on
488
490
#ifdef UNIV_PFS_MUTEX
489
491
/* Key to register kernel_mutex with performance schema */
490
492
UNIV_INTERN mysql_pfs_key_t     kernel_mutex_key;
491
 
/* Key to protect writing the commit_id to the sys header */
492
 
UNIV_INTERN mysql_pfs_key_t     commit_id_mutex_key;
493
493
/* Key to register srv_innodb_monitor_mutex with performance schema */
494
494
UNIV_INTERN mysql_pfs_key_t     srv_innodb_monitor_mutex_key;
495
495
/* Key to register srv_monitor_file_mutex with performance schema */
733
733
/* Table for MySQL threads where they will be suspended to wait for locks */
734
734
UNIV_INTERN srv_slot_t* srv_mysql_table = NULL;
735
735
 
736
 
UNIV_INTERN os_event_t  srv_timeout_event;
737
 
 
738
 
UNIV_INTERN os_event_t  srv_monitor_event;
739
 
 
740
 
UNIV_INTERN os_event_t  srv_error_event;
741
 
 
742
736
UNIV_INTERN os_event_t  srv_lock_timeout_thread_event;
743
737
 
744
738
UNIV_INTERN srv_sys_t*  srv_sys = NULL;
748
742
UNIV_INTERN byte        srv_pad1[64];
749
743
/* mutex protecting the server, trx structs, query threads, and lock table */
750
744
UNIV_INTERN mutex_t*    kernel_mutex_temp;
751
 
/* mutex protecting the sys header for writing the commit id */
752
 
UNIV_INTERN mutex_t*    commit_id_mutex_temp;
753
 
 
754
745
/* padding to prevent other memory update hotspots from residing on
755
746
the same memory cache line */
756
747
UNIV_INTERN byte        srv_pad2[64];
912
903
 
913
904
        slot = srv_table_get_nth_slot(slot_no);
914
905
 
915
 
        type = static_cast<srv_thread_type>(slot->type);
 
906
        type = slot->type;
916
907
 
917
908
        ut_ad(type >= SRV_WORKER);
918
909
        ut_ad(type <= SRV_MASTER);
955
946
 
956
947
                slot = srv_table_get_nth_slot(i);
957
948
 
958
 
                if (slot->in_use &&
959
 
                    (static_cast<srv_thread_type>(slot->type) == type) &&
960
 
                    slot->suspended) {
 
949
                if (slot->in_use && slot->type == type && slot->suspended) {
961
950
 
962
951
                        slot->suspended = FALSE;
963
952
 
1002
991
 
1003
992
        slot = srv_table_get_nth_slot(slot_no);
1004
993
 
1005
 
        type = static_cast<srv_thread_type>(slot->type);
 
994
        type = slot->type;
1006
995
 
1007
996
        ut_ad(type >= SRV_WORKER);
1008
997
        ut_ad(type <= SRV_MASTER);
1023
1012
        srv_slot_t*             slot;
1024
1013
        ulint                   i;
1025
1014
 
1026
 
        srv_sys = static_cast<srv_sys_t *>(mem_alloc(sizeof(srv_sys_t)));
 
1015
        srv_sys = mem_alloc(sizeof(srv_sys_t));
1027
1016
 
1028
 
        kernel_mutex_temp = static_cast<ib_mutex_t *>(mem_alloc(sizeof(mutex_t)));
 
1017
        kernel_mutex_temp = mem_alloc(sizeof(mutex_t));
1029
1018
        mutex_create(kernel_mutex_key, &kernel_mutex, SYNC_KERNEL);
1030
1019
 
1031
 
        commit_id_mutex_temp = static_cast<ib_mutex_t *>(mem_alloc(sizeof(mutex_t)));
1032
 
        mutex_create(commit_id_mutex_key, &commit_id_mutex, SYNC_COMMIT_ID_LOCK);
1033
 
 
1034
1020
        mutex_create(srv_innodb_monitor_mutex_key,
1035
1021
                     &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
1036
1022
 
1037
 
        srv_sys->threads = static_cast<srv_table_t *>(mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t)));
 
1023
        srv_sys->threads = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
1038
1024
 
1039
1025
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1040
1026
                slot = srv_table_get_nth_slot(i);
1044
1030
                ut_a(slot->event);
1045
1031
        }
1046
1032
 
1047
 
        srv_mysql_table = static_cast<srv_slot_t *>(mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t)));
 
1033
        srv_mysql_table = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
1048
1034
 
1049
1035
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1050
1036
                slot = srv_mysql_table + i;
1054
1040
                ut_a(slot->event);
1055
1041
        }
1056
1042
 
1057
 
        srv_error_event = os_event_create(NULL);
1058
 
 
1059
 
        srv_timeout_event = os_event_create(NULL);
1060
 
 
1061
 
        srv_monitor_event = os_event_create(NULL);
1062
 
 
1063
1043
        srv_lock_timeout_thread_event = os_event_create(NULL);
1064
1044
 
1065
1045
        for (i = 0; i < SRV_MASTER + 1; i++) {
1086
1066
 
1087
1067
        UT_LIST_INIT(srv_conc_queue);
1088
1068
 
1089
 
        srv_conc_slots = static_cast<srv_conc_slot_t *>(mem_alloc(OS_THREAD_MAX_N * sizeof(srv_conc_slot_t)));
 
1069
        srv_conc_slots = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_conc_slot_t));
1090
1070
 
1091
1071
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1092
1072
                conc_slot = srv_conc_slots + i;
1119
1099
        mem_free(srv_mysql_table);
1120
1100
        srv_mysql_table = NULL;
1121
1101
 
1122
 
        mem_free(commit_id_mutex_temp);
1123
 
        commit_id_mutex_temp = NULL;
1124
 
 
1125
1102
        trx_i_s_cache_free(trx_i_s_cache);
1126
1103
}
1127
1104
 
1642
1619
                row_mysql_unfreeze_data_dictionary(trx);
1643
1620
                break;
1644
1621
        case RW_X_LATCH:
1645
 
                /* There should never be a lock wait when the
1646
 
                dictionary latch is reserved in X mode.  Dictionary
1647
 
                transactions should only acquire locks on dictionary
1648
 
                tables, not other tables. All access to dictionary
1649
 
                tables should be covered by dictionary
1650
 
                transactions. */
1651
 
                ut_print_timestamp(stderr);
1652
 
                fputs("  InnoDB: Error: dict X latch held in "
1653
 
                      "srv_suspend_mysql_thread\n", stderr);
1654
 
                /* This should never occur. This incorrect handling
1655
 
                was added in the early development of
1656
 
                ha_innobase::add_index() in InnoDB Plugin 1.0. */
1657
1622
                /* Release fast index creation latch */
1658
1623
                row_mysql_unlock_data_dictionary(trx);
1659
1624
                break;
1673
1638
                row_mysql_freeze_data_dictionary(trx);
1674
1639
                break;
1675
1640
        case RW_X_LATCH:
1676
 
                /* This should never occur. This incorrect handling
1677
 
                was added in the early development of
1678
 
                ha_innobase::add_index() in InnoDB Plugin 1.0. */
1679
1641
                row_mysql_lock_data_dictionary(trx);
1680
1642
                break;
1681
1643
        }
1942
1904
                (ulong) srv_conc_n_waiting_threads);
1943
1905
 
1944
1906
        fprintf(file, "%lu read views open inside InnoDB\n",
1945
 
                static_cast<ulint>(UT_LIST_GET_LEN(trx_sys->view_list)));
 
1907
                UT_LIST_GET_LEN(trx_sys->view_list));
1946
1908
 
1947
1909
        n_reserved = fil_space_get_n_reserved_extents(0);
1948
1910
        if (n_reserved > 0) {
2080
2042
        export_vars.innodb_rows_inserted = srv_n_rows_inserted;
2081
2043
        export_vars.innodb_rows_updated = srv_n_rows_updated;
2082
2044
        export_vars.innodb_rows_deleted = srv_n_rows_deleted;
2083
 
        export_vars.innodb_truncated_status_writes = srv_truncated_status_writes;
2084
2045
 
2085
2046
        mutex_exit(&srv_innodb_monitor_mutex);
2086
2047
}
2092
2053
os_thread_ret_t
2093
2054
srv_monitor_thread(
2094
2055
/*===============*/
2095
 
        void*   /*arg __attribute__((unused))*/)
 
2056
        void*   arg __attribute__((unused)))
2096
2057
                        /*!< in: a dummy parameter required by
2097
2058
                        os_thread_create */
2098
2059
{
2099
 
        ib_int64_t      sig_count;
2100
2060
        double          time_elapsed;
2101
2061
        time_t          current_time;
2102
2062
        time_t          last_table_monitor_time;
2114
2074
        pfs_register_thread(srv_monitor_thread_key);
2115
2075
#endif
2116
2076
 
2117
 
        srv_last_monitor_time = ut_time();
2118
 
        last_table_monitor_time = ut_time();
2119
 
        last_tablespace_monitor_time = ut_time();
2120
 
        last_monitor_time = ut_time();
 
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);
2121
2082
        mutex_skipped = 0;
2122
2083
        last_srv_print_monitor = srv_print_innodb_monitor;
2123
2084
loop:
2124
2085
        srv_monitor_active = TRUE;
2125
2086
 
2126
2087
        /* Wake up every 5 seconds to see if we need to print
2127
 
        monitor information or if signalled at shutdown. */
2128
 
 
2129
 
        sig_count = os_event_reset(srv_monitor_event);
2130
 
 
2131
 
        os_event_wait_time_low(srv_monitor_event, 5000000, sig_count);
2132
 
 
2133
 
        current_time = ut_time();
 
2088
        monitor information. */
 
2089
 
 
2090
        os_thread_sleep(5000000);
 
2091
 
 
2092
        current_time = time(NULL);
2134
2093
 
2135
2094
        time_elapsed = difftime(current_time, last_monitor_time);
2136
2095
 
2137
2096
        if (time_elapsed > 15) {
2138
 
                last_monitor_time = ut_time();
 
2097
                last_monitor_time = time(NULL);
2139
2098
 
2140
2099
                if (srv_print_innodb_monitor) {
2141
2100
                        /* Reset mutex_skipped counter everytime
2179
2138
                if (srv_print_innodb_tablespace_monitor
2180
2139
                    && difftime(current_time,
2181
2140
                                last_tablespace_monitor_time) > 60) {
2182
 
                        last_tablespace_monitor_time = ut_time();
 
2141
                        last_tablespace_monitor_time = time(NULL);
2183
2142
 
2184
2143
                        fputs("========================"
2185
2144
                              "========================\n",
2205
2164
                if (srv_print_innodb_table_monitor
2206
2165
                    && difftime(current_time, last_table_monitor_time) > 60) {
2207
2166
 
2208
 
                        last_table_monitor_time = ut_time();
 
2167
                        last_table_monitor_time = time(NULL);
2209
2168
 
2210
2169
                        fputs("===========================================\n",
2211
2170
                              stderr);
2257
2216
os_thread_ret_t
2258
2217
srv_lock_timeout_thread(
2259
2218
/*====================*/
2260
 
        void*   /*arg __attribute__((unused))*/)
 
2219
        void*   arg __attribute__((unused)))
2261
2220
                        /* in: a dummy parameter required by
2262
2221
                        os_thread_create */
2263
2222
{
2265
2224
        ibool           some_waits;
2266
2225
        double          wait_time;
2267
2226
        ulint           i;
2268
 
        ib_int64_t      sig_count;
2269
2227
 
2270
2228
#ifdef UNIV_PFS_THREAD
2271
2229
        pfs_register_thread(srv_lock_timeout_thread_key);
2272
2230
#endif
2273
2231
 
2274
2232
loop:
2275
 
 
2276
2233
        /* When someone is waiting for a lock, we wake up every second
2277
2234
        and check if a timeout has passed for a lock wait */
2278
2235
 
2279
 
        sig_count = os_event_reset(srv_timeout_event);
2280
 
 
2281
 
        os_event_wait_time_low(srv_timeout_event, 1000000, sig_count);
 
2236
        os_thread_sleep(1000000);
2282
2237
 
2283
2238
        srv_lock_timeout_active = TRUE;
2284
2239
 
2365
2320
os_thread_ret_t
2366
2321
srv_error_monitor_thread(
2367
2322
/*=====================*/
2368
 
        void*   /*arg __attribute__((unused))*/)
 
2323
        void*   arg __attribute__((unused)))
2369
2324
                        /*!< in: a dummy parameter required by
2370
2325
                        os_thread_create */
2371
2326
{
2373
2328
        ulint           fatal_cnt       = 0;
2374
2329
        ib_uint64_t     old_lsn;
2375
2330
        ib_uint64_t     new_lsn;
2376
 
        ib_int64_t      sig_count;
2377
2331
 
2378
2332
        old_lsn = srv_start_lsn;
2379
2333
 
2449
2403
 
2450
2404
        fflush(stderr);
2451
2405
 
2452
 
        sig_count = os_event_reset(srv_error_event);
2453
 
 
2454
 
        os_event_wait_time_low(srv_error_event, 1000000, sig_count);
 
2406
        os_thread_sleep(1000000);
2455
2407
 
2456
2408
        if (srv_shutdown_state < SRV_SHUTDOWN_CLEANUP) {
2457
2409
 
2630
2582
os_thread_ret_t
2631
2583
srv_master_thread(
2632
2584
/*==============*/
2633
 
        void*   /*arg __attribute__((unused))*/)
 
2585
        void*   arg __attribute__((unused)))
2634
2586
                        /*!< in: a dummy parameter required by
2635
2587
                        os_thread_create */
2636
2588
{
2695
2647
        when there is database activity */
2696
2648
 
2697
2649
        srv_last_log_flush_time = time(NULL);
2698
 
 
2699
 
        /* Sleep for 1 second on entrying the for loop below the first time. */
2700
 
        next_itr_time = ut_time_ms() + 1000;
 
2650
        next_itr_time = ut_time_ms();
2701
2651
 
2702
2652
        for (i = 0; i < 10; i++) {
2703
2653
                ulint   cur_time = ut_time_ms();
2704
2654
 
2705
 
                /* ALTER TABLE in MySQL requires on Unix that the table handler
2706
 
                can drop tables lazily after there no longer are SELECT
2707
 
                queries to them. */
2708
 
 
2709
 
                srv_main_thread_op_info = "doing background drop tables";
2710
 
 
2711
 
                row_drop_tables_for_mysql_in_background();
2712
 
 
2713
 
                srv_main_thread_op_info = "";
2714
 
 
2715
 
                if (srv_fast_shutdown && srv_shutdown_state > 0) {
2716
 
 
2717
 
                        goto background_loop;
2718
 
                }
2719
 
 
2720
2655
                buf_get_total_stat(&buf_stat);
2721
2656
 
2722
2657
                n_ios_old = log_sys->n_log_ios + buf_stat.n_pages_read
2725
2660
                srv_main_thread_op_info = "sleeping";
2726
2661
                srv_main_1_second_loops++;
2727
2662
 
2728
 
                if (next_itr_time > cur_time
2729
 
                    && srv_shutdown_state == SRV_SHUTDOWN_NONE) {
 
2663
                if (next_itr_time > cur_time) {
2730
2664
 
2731
2665
                        /* Get sleep interval in micro seconds. We use
2732
2666
                        ut_min() to avoid long sleep in case of
2740
2674
                /* Each iteration should happen at 1 second interval. */
2741
2675
                next_itr_time = ut_time_ms() + 1000;
2742
2676
 
 
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
 
2743
2692
                /* Flush logs if needed */
2744
2693
                srv_sync_log_buffer_in_background();
2745
2694
 
2917
2866
                MySQL tries to drop a table while there are still open handles
2918
2867
                to it and we had to put it to the background drop queue.) */
2919
2868
 
2920
 
                if (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
2921
 
                        os_thread_sleep(100000);
2922
 
                }
 
2869
                os_thread_sleep(100000);
2923
2870
        }
2924
2871
 
2925
2872
        if (srv_n_purge_threads == 0) {
3078
3025
        goto loop;
3079
3026
 
3080
3027
 
3081
 
#if !defined(__SUNPRO_C)
 
3028
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
3082
3029
        OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
3083
3030
#endif
3084
3031
}
3090
3037
os_thread_ret_t
3091
3038
srv_purge_thread(
3092
3039
/*=============*/
3093
 
        void*   /*arg __attribute__((unused))*/)        /*!< in: a dummy parameter
 
3040
        void*   arg __attribute__((unused)))    /*!< in: a dummy parameter
3094
3041
                                                required by os_thread_create */
3095
3042
{
3096
3043
        srv_slot_t*     slot;