~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2010-12-22 03:15:22 UTC
  • mto: (2023.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2024.
  • Revision ID: mordred@inaugust.com-20101222031522-bmi73y3y00f480qs
Fixed some valgrind warning suppressions which were getting fooled by a
different stack.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
= {
488
491
#ifdef UNIV_PFS_MUTEX
489
492
/* Key to register kernel_mutex with performance schema */
490
493
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
494
/* Key to register srv_innodb_monitor_mutex with performance schema */
494
495
UNIV_INTERN mysql_pfs_key_t     srv_innodb_monitor_mutex_key;
495
496
/* Key to register srv_monitor_file_mutex with performance schema */
733
734
/* Table for MySQL threads where they will be suspended to wait for locks */
734
735
UNIV_INTERN srv_slot_t* srv_mysql_table = NULL;
735
736
 
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
737
UNIV_INTERN os_event_t  srv_lock_timeout_thread_event;
743
738
 
744
739
UNIV_INTERN srv_sys_t*  srv_sys = NULL;
748
743
UNIV_INTERN byte        srv_pad1[64];
749
744
/* mutex protecting the server, trx structs, query threads, and lock table */
750
745
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
746
/* padding to prevent other memory update hotspots from residing on
755
747
the same memory cache line */
756
748
UNIV_INTERN byte        srv_pad2[64];
912
904
 
913
905
        slot = srv_table_get_nth_slot(slot_no);
914
906
 
915
 
        type = static_cast<srv_thread_type>(slot->type);
 
907
        type = slot->type;
916
908
 
917
909
        ut_ad(type >= SRV_WORKER);
918
910
        ut_ad(type <= SRV_MASTER);
955
947
 
956
948
                slot = srv_table_get_nth_slot(i);
957
949
 
958
 
                if (slot->in_use &&
959
 
                    (static_cast<srv_thread_type>(slot->type) == type) &&
960
 
                    slot->suspended) {
 
950
                if (slot->in_use && slot->type == type && slot->suspended) {
961
951
 
962
952
                        slot->suspended = FALSE;
963
953
 
1002
992
 
1003
993
        slot = srv_table_get_nth_slot(slot_no);
1004
994
 
1005
 
        type = static_cast<srv_thread_type>(slot->type);
 
995
        type = slot->type;
1006
996
 
1007
997
        ut_ad(type >= SRV_WORKER);
1008
998
        ut_ad(type <= SRV_MASTER);
1023
1013
        srv_slot_t*             slot;
1024
1014
        ulint                   i;
1025
1015
 
1026
 
        srv_sys = static_cast<srv_sys_t *>(mem_alloc(sizeof(srv_sys_t)));
 
1016
        srv_sys = mem_alloc(sizeof(srv_sys_t));
1027
1017
 
1028
 
        kernel_mutex_temp = static_cast<ib_mutex_t *>(mem_alloc(sizeof(mutex_t)));
 
1018
        kernel_mutex_temp = mem_alloc(sizeof(mutex_t));
1029
1019
        mutex_create(kernel_mutex_key, &kernel_mutex, SYNC_KERNEL);
1030
1020
 
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
1021
        mutex_create(srv_innodb_monitor_mutex_key,
1035
1022
                     &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
1036
1023
 
1037
 
        srv_sys->threads = static_cast<srv_table_t *>(mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t)));
 
1024
        srv_sys->threads = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
1038
1025
 
1039
1026
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1040
1027
                slot = srv_table_get_nth_slot(i);
1044
1031
                ut_a(slot->event);
1045
1032
        }
1046
1033
 
1047
 
        srv_mysql_table = static_cast<srv_slot_t *>(mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t)));
 
1034
        srv_mysql_table = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_slot_t));
1048
1035
 
1049
1036
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1050
1037
                slot = srv_mysql_table + i;
1054
1041
                ut_a(slot->event);
1055
1042
        }
1056
1043
 
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
1044
        srv_lock_timeout_thread_event = os_event_create(NULL);
1064
1045
 
1065
1046
        for (i = 0; i < SRV_MASTER + 1; i++) {
1086
1067
 
1087
1068
        UT_LIST_INIT(srv_conc_queue);
1088
1069
 
1089
 
        srv_conc_slots = static_cast<srv_conc_slot_t *>(mem_alloc(OS_THREAD_MAX_N * sizeof(srv_conc_slot_t)));
 
1070
        srv_conc_slots = mem_alloc(OS_THREAD_MAX_N * sizeof(srv_conc_slot_t));
1090
1071
 
1091
1072
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1092
1073
                conc_slot = srv_conc_slots + i;
1119
1100
        mem_free(srv_mysql_table);
1120
1101
        srv_mysql_table = NULL;
1121
1102
 
1122
 
        mem_free(commit_id_mutex_temp);
1123
 
        commit_id_mutex_temp = NULL;
1124
 
 
1125
1103
        trx_i_s_cache_free(trx_i_s_cache);
1126
1104
}
1127
1105
 
1942
1920
                (ulong) srv_conc_n_waiting_threads);
1943
1921
 
1944
1922
        fprintf(file, "%lu read views open inside InnoDB\n",
1945
 
                static_cast<ulint>(UT_LIST_GET_LEN(trx_sys->view_list)));
 
1923
                UT_LIST_GET_LEN(trx_sys->view_list));
1946
1924
 
1947
1925
        n_reserved = fil_space_get_n_reserved_extents(0);
1948
1926
        if (n_reserved > 0) {
2092
2070
os_thread_ret_t
2093
2071
srv_monitor_thread(
2094
2072
/*===============*/
2095
 
        void*   /*arg __attribute__((unused))*/)
 
2073
        void*   arg __attribute__((unused)))
2096
2074
                        /*!< in: a dummy parameter required by
2097
2075
                        os_thread_create */
2098
2076
{
2099
 
        ib_int64_t      sig_count;
2100
2077
        double          time_elapsed;
2101
2078
        time_t          current_time;
2102
2079
        time_t          last_table_monitor_time;
2114
2091
        pfs_register_thread(srv_monitor_thread_key);
2115
2092
#endif
2116
2093
 
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();
 
2094
        UT_NOT_USED(arg);
 
2095
        srv_last_monitor_time = time(NULL);
 
2096
        last_table_monitor_time = time(NULL);
 
2097
        last_tablespace_monitor_time = time(NULL);
 
2098
        last_monitor_time = time(NULL);
2121
2099
        mutex_skipped = 0;
2122
2100
        last_srv_print_monitor = srv_print_innodb_monitor;
2123
2101
loop:
2124
2102
        srv_monitor_active = TRUE;
2125
2103
 
2126
2104
        /* 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();
 
2105
        monitor information. */
 
2106
 
 
2107
        os_thread_sleep(5000000);
 
2108
 
 
2109
        current_time = time(NULL);
2134
2110
 
2135
2111
        time_elapsed = difftime(current_time, last_monitor_time);
2136
2112
 
2137
2113
        if (time_elapsed > 15) {
2138
 
                last_monitor_time = ut_time();
 
2114
                last_monitor_time = time(NULL);
2139
2115
 
2140
2116
                if (srv_print_innodb_monitor) {
2141
2117
                        /* Reset mutex_skipped counter everytime
2179
2155
                if (srv_print_innodb_tablespace_monitor
2180
2156
                    && difftime(current_time,
2181
2157
                                last_tablespace_monitor_time) > 60) {
2182
 
                        last_tablespace_monitor_time = ut_time();
 
2158
                        last_tablespace_monitor_time = time(NULL);
2183
2159
 
2184
2160
                        fputs("========================"
2185
2161
                              "========================\n",
2205
2181
                if (srv_print_innodb_table_monitor
2206
2182
                    && difftime(current_time, last_table_monitor_time) > 60) {
2207
2183
 
2208
 
                        last_table_monitor_time = ut_time();
 
2184
                        last_table_monitor_time = time(NULL);
2209
2185
 
2210
2186
                        fputs("===========================================\n",
2211
2187
                              stderr);
2257
2233
os_thread_ret_t
2258
2234
srv_lock_timeout_thread(
2259
2235
/*====================*/
2260
 
        void*   /*arg __attribute__((unused))*/)
 
2236
        void*   arg __attribute__((unused)))
2261
2237
                        /* in: a dummy parameter required by
2262
2238
                        os_thread_create */
2263
2239
{
2265
2241
        ibool           some_waits;
2266
2242
        double          wait_time;
2267
2243
        ulint           i;
2268
 
        ib_int64_t      sig_count;
2269
2244
 
2270
2245
#ifdef UNIV_PFS_THREAD
2271
2246
        pfs_register_thread(srv_lock_timeout_thread_key);
2272
2247
#endif
2273
2248
 
2274
2249
loop:
2275
 
 
2276
2250
        /* When someone is waiting for a lock, we wake up every second
2277
2251
        and check if a timeout has passed for a lock wait */
2278
2252
 
2279
 
        sig_count = os_event_reset(srv_timeout_event);
2280
 
 
2281
 
        os_event_wait_time_low(srv_timeout_event, 1000000, sig_count);
 
2253
        os_thread_sleep(1000000);
2282
2254
 
2283
2255
        srv_lock_timeout_active = TRUE;
2284
2256
 
2365
2337
os_thread_ret_t
2366
2338
srv_error_monitor_thread(
2367
2339
/*=====================*/
2368
 
        void*   /*arg __attribute__((unused))*/)
 
2340
        void*   arg __attribute__((unused)))
2369
2341
                        /*!< in: a dummy parameter required by
2370
2342
                        os_thread_create */
2371
2343
{
2373
2345
        ulint           fatal_cnt       = 0;
2374
2346
        ib_uint64_t     old_lsn;
2375
2347
        ib_uint64_t     new_lsn;
2376
 
        ib_int64_t      sig_count;
2377
2348
 
2378
2349
        old_lsn = srv_start_lsn;
2379
2350
 
2449
2420
 
2450
2421
        fflush(stderr);
2451
2422
 
2452
 
        sig_count = os_event_reset(srv_error_event);
2453
 
 
2454
 
        os_event_wait_time_low(srv_error_event, 1000000, sig_count);
 
2423
        os_thread_sleep(1000000);
2455
2424
 
2456
2425
        if (srv_shutdown_state < SRV_SHUTDOWN_CLEANUP) {
2457
2426
 
2630
2599
os_thread_ret_t
2631
2600
srv_master_thread(
2632
2601
/*==============*/
2633
 
        void*   /*arg __attribute__((unused))*/)
 
2602
        void*   arg __attribute__((unused)))
2634
2603
                        /*!< in: a dummy parameter required by
2635
2604
                        os_thread_create */
2636
2605
{
2702
2671
        for (i = 0; i < 10; i++) {
2703
2672
                ulint   cur_time = ut_time_ms();
2704
2673
 
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
2674
                buf_get_total_stat(&buf_stat);
2721
2675
 
2722
2676
                n_ios_old = log_sys->n_log_ios + buf_stat.n_pages_read
2725
2679
                srv_main_thread_op_info = "sleeping";
2726
2680
                srv_main_1_second_loops++;
2727
2681
 
2728
 
                if (next_itr_time > cur_time
2729
 
                    && srv_shutdown_state == SRV_SHUTDOWN_NONE) {
 
2682
                if (next_itr_time > cur_time) {
2730
2683
 
2731
2684
                        /* Get sleep interval in micro seconds. We use
2732
2685
                        ut_min() to avoid long sleep in case of
2740
2693
                /* Each iteration should happen at 1 second interval. */
2741
2694
                next_itr_time = ut_time_ms() + 1000;
2742
2695
 
 
2696
                /* ALTER TABLE in MySQL requires on Unix that the table handler
 
2697
                can drop tables lazily after there no longer are SELECT
 
2698
                queries to them. */
 
2699
 
 
2700
                srv_main_thread_op_info = "doing background drop tables";
 
2701
 
 
2702
                row_drop_tables_for_mysql_in_background();
 
2703
 
 
2704
                srv_main_thread_op_info = "";
 
2705
 
 
2706
                if (srv_fast_shutdown && srv_shutdown_state > 0) {
 
2707
 
 
2708
                        goto background_loop;
 
2709
                }
 
2710
 
2743
2711
                /* Flush logs if needed */
2744
2712
                srv_sync_log_buffer_in_background();
2745
2713
 
2917
2885
                MySQL tries to drop a table while there are still open handles
2918
2886
                to it and we had to put it to the background drop queue.) */
2919
2887
 
2920
 
                if (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
2921
 
                        os_thread_sleep(100000);
2922
 
                }
 
2888
                os_thread_sleep(100000);
2923
2889
        }
2924
2890
 
2925
2891
        if (srv_n_purge_threads == 0) {
3078
3044
        goto loop;
3079
3045
 
3080
3046
 
3081
 
#if !defined(__SUNPRO_C)
 
3047
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
3082
3048
        OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
3083
3049
#endif
3084
3050
}
3090
3056
os_thread_ret_t
3091
3057
srv_purge_thread(
3092
3058
/*=============*/
3093
 
        void*   /*arg __attribute__((unused))*/)        /*!< in: a dummy parameter
 
3059
        void*   arg __attribute__((unused)))    /*!< in: a dummy parameter
3094
3060
                                                required by os_thread_create */
3095
3061
{
3096
3062
        srv_slot_t*     slot;