~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2011-02-05 10:53:26 UTC
  • mto: (2147.3.1 alter-table)
  • mto: This revision was merged to the branch mainline in revision 2148.
  • Revision ID: brian@tangent.org-20110205105326-hjmn5xehw5rs46tp
Fix bad error in warnings/errors.

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
127
124
/** Whether to check file format during startup.  A value of
128
125
DICT_TF_FORMAT_MAX + 1 means no checking ie. FALSE.  The default is to
129
126
set it to the highest format we support. */
130
 
UNIV_INTERN ulint       srv_check_file_format_at_startup = DICT_TF_FORMAT_MAX;
 
127
UNIV_INTERN ulint       srv_max_file_format_at_startup = DICT_TF_FORMAT_MAX;
131
128
 
132
129
#if DICT_TF_FORMAT_51
133
130
# error "DICT_TF_FORMAT_51 must be 0!"
142
139
Currently we support native aio on windows and linux */
143
140
UNIV_INTERN my_bool     srv_use_native_aio = TRUE;
144
141
 
 
142
#ifdef __WIN__
 
143
/* Windows native condition variables. We use runtime loading / function
 
144
pointers, because they are not available on Windows Server 2003 and
 
145
Windows XP/2000.
 
146
 
 
147
We use condition for events on Windows if possible, even if os_event
 
148
resembles Windows kernel event object well API-wise. The reason is
 
149
performance, kernel objects are heavyweights and WaitForSingleObject() is a
 
150
performance killer causing calling thread to context switch. Besides, Innodb
 
151
is preallocating large number (often millions) of os_events. With kernel event
 
152
objects it takes a big chunk out of non-paged pool, which is better suited
 
153
for tasks like IO than for storing idle event objects. */
 
154
UNIV_INTERN ibool       srv_use_native_conditions = FALSE;
 
155
#endif /* __WIN__ */
 
156
 
145
157
UNIV_INTERN ulint       srv_n_data_files = 0;
146
158
UNIV_INTERN char**      srv_data_file_names = NULL;
147
159
/* size in database pages */
189
201
/** The sort order table of the MySQL latin1_swedish_ci character set
190
202
collation */
191
203
#if defined(BUILD_DRIZZLE)
192
 
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
193
205
                                        character set. The following table is
194
206
                                        the MySQL order as of Feb 10th, 2002 */
195
207
= {
448
460
UNIV_INTERN ib_int64_t  srv_n_lock_wait_time            = 0;
449
461
UNIV_INTERN ulint               srv_n_lock_max_wait_time        = 0;
450
462
 
 
463
UNIV_INTERN ulint               srv_truncated_status_writes     = 0;
451
464
 
452
465
/*
453
466
  Set the following to 0 if you want InnoDB to write messages on
718
731
/* Table for MySQL threads where they will be suspended to wait for locks */
719
732
UNIV_INTERN srv_slot_t* srv_mysql_table = NULL;
720
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
 
721
740
UNIV_INTERN os_event_t  srv_lock_timeout_thread_event;
722
741
 
723
742
UNIV_INTERN srv_sys_t*  srv_sys = NULL;
888
907
 
889
908
        slot = srv_table_get_nth_slot(slot_no);
890
909
 
891
 
        type = slot->type;
 
910
        type = static_cast<srv_thread_type>(slot->type);
892
911
 
893
912
        ut_ad(type >= SRV_WORKER);
894
913
        ut_ad(type <= SRV_MASTER);
931
950
 
932
951
                slot = srv_table_get_nth_slot(i);
933
952
 
934
 
                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) {
935
956
 
936
957
                        slot->suspended = FALSE;
937
958
 
976
997
 
977
998
        slot = srv_table_get_nth_slot(slot_no);
978
999
 
979
 
        type = slot->type;
 
1000
        type = static_cast<srv_thread_type>(slot->type);
980
1001
 
981
1002
        ut_ad(type >= SRV_WORKER);
982
1003
        ut_ad(type <= SRV_MASTER);
997
1018
        srv_slot_t*             slot;
998
1019
        ulint                   i;
999
1020
 
1000
 
        srv_sys = mem_alloc(sizeof(srv_sys_t));
 
1021
        srv_sys = static_cast<srv_sys_t *>(mem_alloc(sizeof(srv_sys_t)));
1001
1022
 
1002
 
        kernel_mutex_temp = mem_alloc(sizeof(mutex_t));
 
1023
        kernel_mutex_temp = static_cast<ib_mutex_t *>(mem_alloc(sizeof(mutex_t)));
1003
1024
        mutex_create(kernel_mutex_key, &kernel_mutex, SYNC_KERNEL);
1004
1025
 
1005
1026
        mutex_create(srv_innodb_monitor_mutex_key,
1006
1027
                     &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
1007
1028
 
1008
 
        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)));
1009
1030
 
1010
1031
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1011
1032
                slot = srv_table_get_nth_slot(i);
1015
1036
                ut_a(slot->event);
1016
1037
        }
1017
1038
 
1018
 
        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)));
1019
1040
 
1020
1041
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1021
1042
                slot = srv_mysql_table + i;
1025
1046
                ut_a(slot->event);
1026
1047
        }
1027
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
 
1028
1055
        srv_lock_timeout_thread_event = os_event_create(NULL);
1029
1056
 
1030
1057
        for (i = 0; i < SRV_MASTER + 1; i++) {
1051
1078
 
1052
1079
        UT_LIST_INIT(srv_conc_queue);
1053
1080
 
1054
 
        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)));
1055
1082
 
1056
1083
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1057
1084
                conc_slot = srv_conc_slots + i;
1604
1631
                row_mysql_unfreeze_data_dictionary(trx);
1605
1632
                break;
1606
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. */
1607
1646
                /* Release fast index creation latch */
1608
1647
                row_mysql_unlock_data_dictionary(trx);
1609
1648
                break;
1623
1662
                row_mysql_freeze_data_dictionary(trx);
1624
1663
                break;
1625
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. */
1626
1668
                row_mysql_lock_data_dictionary(trx);
1627
1669
                break;
1628
1670
        }
1659
1701
                    start_time != -1 && finish_time != -1) {
1660
1702
                        srv_n_lock_max_wait_time = diff_time;
1661
1703
                }
 
1704
 
 
1705
                /* Record the lock wait time for this thread */
 
1706
                thd_set_lock_wait_time(trx->mysql_thd, diff_time);
1662
1707
        }
1663
1708
 
1664
1709
        if (trx->was_chosen_as_deadlock_victim) {
1886
1931
                (ulong) srv_conc_n_waiting_threads);
1887
1932
 
1888
1933
        fprintf(file, "%lu read views open inside InnoDB\n",
1889
 
                UT_LIST_GET_LEN(trx_sys->view_list));
 
1934
                static_cast<ulint>(UT_LIST_GET_LEN(trx_sys->view_list)));
1890
1935
 
1891
1936
        n_reserved = fil_space_get_n_reserved_extents(0);
1892
1937
        if (n_reserved > 0) {
2024
2069
        export_vars.innodb_rows_inserted = srv_n_rows_inserted;
2025
2070
        export_vars.innodb_rows_updated = srv_n_rows_updated;
2026
2071
        export_vars.innodb_rows_deleted = srv_n_rows_deleted;
 
2072
        export_vars.innodb_truncated_status_writes = srv_truncated_status_writes;
2027
2073
 
2028
2074
        mutex_exit(&srv_innodb_monitor_mutex);
2029
2075
}
2035
2081
os_thread_ret_t
2036
2082
srv_monitor_thread(
2037
2083
/*===============*/
2038
 
        void*   arg __attribute__((unused)))
 
2084
        void*   /*arg __attribute__((unused))*/)
2039
2085
                        /*!< in: a dummy parameter required by
2040
2086
                        os_thread_create */
2041
2087
{
 
2088
        ib_int64_t      sig_count;
2042
2089
        double          time_elapsed;
2043
2090
        time_t          current_time;
2044
2091
        time_t          last_table_monitor_time;
2056
2103
        pfs_register_thread(srv_monitor_thread_key);
2057
2104
#endif
2058
2105
 
2059
 
        UT_NOT_USED(arg);
2060
 
        srv_last_monitor_time = time(NULL);
2061
 
        last_table_monitor_time = time(NULL);
2062
 
        last_tablespace_monitor_time = time(NULL);
2063
 
        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();
2064
2110
        mutex_skipped = 0;
2065
2111
        last_srv_print_monitor = srv_print_innodb_monitor;
2066
2112
loop:
2067
2113
        srv_monitor_active = TRUE;
2068
2114
 
2069
2115
        /* Wake up every 5 seconds to see if we need to print
2070
 
        monitor information. */
2071
 
 
2072
 
        os_thread_sleep(5000000);
2073
 
 
2074
 
        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();
2075
2123
 
2076
2124
        time_elapsed = difftime(current_time, last_monitor_time);
2077
2125
 
2078
2126
        if (time_elapsed > 15) {
2079
 
                last_monitor_time = time(NULL);
 
2127
                last_monitor_time = ut_time();
2080
2128
 
2081
2129
                if (srv_print_innodb_monitor) {
2082
2130
                        /* Reset mutex_skipped counter everytime
2120
2168
                if (srv_print_innodb_tablespace_monitor
2121
2169
                    && difftime(current_time,
2122
2170
                                last_tablespace_monitor_time) > 60) {
2123
 
                        last_tablespace_monitor_time = time(NULL);
 
2171
                        last_tablespace_monitor_time = ut_time();
2124
2172
 
2125
2173
                        fputs("========================"
2126
2174
                              "========================\n",
2146
2194
                if (srv_print_innodb_table_monitor
2147
2195
                    && difftime(current_time, last_table_monitor_time) > 60) {
2148
2196
 
2149
 
                        last_table_monitor_time = time(NULL);
 
2197
                        last_table_monitor_time = ut_time();
2150
2198
 
2151
2199
                        fputs("===========================================\n",
2152
2200
                              stderr);
2198
2246
os_thread_ret_t
2199
2247
srv_lock_timeout_thread(
2200
2248
/*====================*/
2201
 
        void*   arg __attribute__((unused)))
 
2249
        void*   /*arg __attribute__((unused))*/)
2202
2250
                        /* in: a dummy parameter required by
2203
2251
                        os_thread_create */
2204
2252
{
2206
2254
        ibool           some_waits;
2207
2255
        double          wait_time;
2208
2256
        ulint           i;
 
2257
        ib_int64_t      sig_count;
2209
2258
 
2210
2259
#ifdef UNIV_PFS_THREAD
2211
2260
        pfs_register_thread(srv_lock_timeout_thread_key);
2212
2261
#endif
2213
2262
 
2214
2263
loop:
 
2264
 
2215
2265
        /* When someone is waiting for a lock, we wake up every second
2216
2266
        and check if a timeout has passed for a lock wait */
2217
2267
 
2218
 
        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);
2219
2271
 
2220
2272
        srv_lock_timeout_active = TRUE;
2221
2273
 
2302
2354
os_thread_ret_t
2303
2355
srv_error_monitor_thread(
2304
2356
/*=====================*/
2305
 
        void*   arg __attribute__((unused)))
 
2357
        void*   /*arg __attribute__((unused))*/)
2306
2358
                        /*!< in: a dummy parameter required by
2307
2359
                        os_thread_create */
2308
2360
{
2310
2362
        ulint           fatal_cnt       = 0;
2311
2363
        ib_uint64_t     old_lsn;
2312
2364
        ib_uint64_t     new_lsn;
 
2365
        ib_int64_t      sig_count;
2313
2366
 
2314
2367
        old_lsn = srv_start_lsn;
2315
2368
 
2385
2438
 
2386
2439
        fflush(stderr);
2387
2440
 
2388
 
        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);
2389
2444
 
2390
2445
        if (srv_shutdown_state < SRV_SHUTDOWN_CLEANUP) {
2391
2446
 
2402
2457
        OS_THREAD_DUMMY_RETURN;
2403
2458
}
2404
2459
 
2405
 
/******************************************************************//**
2406
 
Increment the server activity count. */
2407
 
UNIV_INLINE
2408
 
void
2409
 
srv_inc_activity_count_low(void)
2410
 
/*============================*/
2411
 
{
2412
 
        mutex_enter(&kernel_mutex);
2413
 
 
2414
 
        ++srv_activity_count;
2415
 
 
2416
 
        mutex_exit(&kernel_mutex);
2417
 
}
2418
 
 
2419
 
/******************************************************************//**
2420
 
Increment the server activity count. */
2421
 
UNIV_INTERN
2422
 
void
2423
 
srv_inc_activity_count(void)
2424
 
/*========================*/
2425
 
{
2426
 
        srv_inc_activity_count_low();
2427
 
}
2428
 
 
2429
2460
/**********************************************************************//**
2430
2461
Check whether any background thread is active.
2431
2462
@return FALSE if all are are suspended or have exited. */
2462
2493
srv_active_wake_master_thread(void)
2463
2494
/*===============================*/
2464
2495
{
2465
 
        ut_ad(!mutex_own(&kernel_mutex));
2466
 
 
2467
 
        srv_inc_activity_count_low();
 
2496
        srv_activity_count++;
2468
2497
 
2469
2498
        if (srv_n_threads_active[SRV_MASTER] == 0) {
2470
2499
 
2590
2619
os_thread_ret_t
2591
2620
srv_master_thread(
2592
2621
/*==============*/
2593
 
        void*   arg __attribute__((unused)))
 
2622
        void*   /*arg __attribute__((unused))*/)
2594
2623
                        /*!< in: a dummy parameter required by
2595
2624
                        os_thread_create */
2596
2625
{
2655
2684
        when there is database activity */
2656
2685
 
2657
2686
        srv_last_log_flush_time = time(NULL);
2658
 
        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;
2659
2690
 
2660
2691
        for (i = 0; i < 10; i++) {
2661
2692
                ulint   cur_time = ut_time_ms();
2662
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
 
2663
2709
                buf_get_total_stat(&buf_stat);
2664
2710
 
2665
2711
                n_ios_old = log_sys->n_log_ios + buf_stat.n_pages_read
2668
2714
                srv_main_thread_op_info = "sleeping";
2669
2715
                srv_main_1_second_loops++;
2670
2716
 
2671
 
                if (next_itr_time > cur_time) {
 
2717
                if (next_itr_time > cur_time
 
2718
                    && srv_shutdown_state == SRV_SHUTDOWN_NONE) {
2672
2719
 
2673
2720
                        /* Get sleep interval in micro seconds. We use
2674
2721
                        ut_min() to avoid long sleep in case of
2682
2729
                /* Each iteration should happen at 1 second interval. */
2683
2730
                next_itr_time = ut_time_ms() + 1000;
2684
2731
 
2685
 
                /* ALTER TABLE in MySQL requires on Unix that the table handler
2686
 
                can drop tables lazily after there no longer are SELECT
2687
 
                queries to them. */
2688
 
 
2689
 
                srv_main_thread_op_info = "doing background drop tables";
2690
 
 
2691
 
                row_drop_tables_for_mysql_in_background();
2692
 
 
2693
 
                srv_main_thread_op_info = "";
2694
 
 
2695
 
                if (srv_fast_shutdown && srv_shutdown_state > 0) {
2696
 
 
2697
 
                        goto background_loop;
2698
 
                }
2699
 
 
2700
2732
                /* Flush logs if needed */
2701
2733
                srv_sync_log_buffer_in_background();
2702
2734
 
2874
2906
                MySQL tries to drop a table while there are still open handles
2875
2907
                to it and we had to put it to the background drop queue.) */
2876
2908
 
2877
 
                os_thread_sleep(100000);
 
2909
                if (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
 
2910
                        os_thread_sleep(100000);
 
2911
                }
2878
2912
        }
2879
2913
 
2880
2914
        if (srv_n_purge_threads == 0) {
3033
3067
        goto loop;
3034
3068
 
3035
3069
 
3036
 
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
 
3070
#if !defined(__SUNPRO_C)
3037
3071
        OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
3038
3072
#endif
3039
3073
}
3045
3079
os_thread_ret_t
3046
3080
srv_purge_thread(
3047
3081
/*=============*/
3048
 
        void*   arg __attribute__((unused)))    /*!< in: a dummy parameter
 
3082
        void*   /*arg __attribute__((unused))*/)        /*!< in: a dummy parameter
3049
3083
                                                required by os_thread_create */
3050
3084
{
3051
3085
        srv_slot_t*     slot;
3063
3097
 
3064
3098
        slot_no = srv_table_reserve_slot(SRV_WORKER);
3065
3099
 
 
3100
        slot = srv_table_get_nth_slot(slot_no);
 
3101
 
3066
3102
        ++srv_n_threads_active[SRV_WORKER];
3067
3103
 
3068
3104
        mutex_exit(&kernel_mutex);
3114
3150
 
3115
3151
        mutex_enter(&kernel_mutex);
3116
3152
 
 
3153
        ut_ad(srv_table_get_nth_slot(slot_no) == slot);
 
3154
 
3117
3155
        /* Decrement the active count. */
3118
3156
        srv_suspend_thread();
3119
3157
 
3120
 
        mutex_exit(&kernel_mutex);
 
3158
        slot->in_use = FALSE;
3121
3159
 
3122
3160
        /* Free the thread local memory. */
3123
3161
        thr_local_free(os_thread_get_curr_id());
3124
3162
 
3125
 
        mutex_enter(&kernel_mutex);
3126
 
 
3127
 
        /* Free the slot for reuse. */
3128
 
        slot = srv_table_get_nth_slot(slot_no);
3129
 
        slot->in_use = FALSE;
3130
 
 
3131
3163
        mutex_exit(&kernel_mutex);
3132
3164
 
3133
3165
#ifdef UNIV_DEBUG_THREAD_CREATION