~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-12 06:56:00 UTC
  • mto: This revision was merged to the branch mainline in revision 2161.
  • Revision ID: brian@tangent.org-20110212065600-m6c68fybw51rflhj
Further strip out includes.

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
 
 
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
= {
734
731
/* Table for MySQL threads where they will be suspended to wait for locks */
735
732
UNIV_INTERN srv_slot_t* srv_mysql_table = NULL;
736
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
 
737
740
UNIV_INTERN os_event_t  srv_lock_timeout_thread_event;
738
741
 
739
742
UNIV_INTERN srv_sys_t*  srv_sys = NULL;
904
907
 
905
908
        slot = srv_table_get_nth_slot(slot_no);
906
909
 
907
 
        type = slot->type;
 
910
        type = static_cast<srv_thread_type>(slot->type);
908
911
 
909
912
        ut_ad(type >= SRV_WORKER);
910
913
        ut_ad(type <= SRV_MASTER);
947
950
 
948
951
                slot = srv_table_get_nth_slot(i);
949
952
 
950
 
                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) {
951
956
 
952
957
                        slot->suspended = FALSE;
953
958
 
992
997
 
993
998
        slot = srv_table_get_nth_slot(slot_no);
994
999
 
995
 
        type = slot->type;
 
1000
        type = static_cast<srv_thread_type>(slot->type);
996
1001
 
997
1002
        ut_ad(type >= SRV_WORKER);
998
1003
        ut_ad(type <= SRV_MASTER);
1013
1018
        srv_slot_t*             slot;
1014
1019
        ulint                   i;
1015
1020
 
1016
 
        srv_sys = mem_alloc(sizeof(srv_sys_t));
 
1021
        srv_sys = static_cast<srv_sys_t *>(mem_alloc(sizeof(srv_sys_t)));
1017
1022
 
1018
 
        kernel_mutex_temp = mem_alloc(sizeof(mutex_t));
 
1023
        kernel_mutex_temp = static_cast<ib_mutex_t *>(mem_alloc(sizeof(mutex_t)));
1019
1024
        mutex_create(kernel_mutex_key, &kernel_mutex, SYNC_KERNEL);
1020
1025
 
1021
1026
        mutex_create(srv_innodb_monitor_mutex_key,
1022
1027
                     &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
1023
1028
 
1024
 
        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)));
1025
1030
 
1026
1031
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1027
1032
                slot = srv_table_get_nth_slot(i);
1031
1036
                ut_a(slot->event);
1032
1037
        }
1033
1038
 
1034
 
        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)));
1035
1040
 
1036
1041
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1037
1042
                slot = srv_mysql_table + i;
1041
1046
                ut_a(slot->event);
1042
1047
        }
1043
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
 
1044
1055
        srv_lock_timeout_thread_event = os_event_create(NULL);
1045
1056
 
1046
1057
        for (i = 0; i < SRV_MASTER + 1; i++) {
1067
1078
 
1068
1079
        UT_LIST_INIT(srv_conc_queue);
1069
1080
 
1070
 
        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)));
1071
1082
 
1072
1083
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1073
1084
                conc_slot = srv_conc_slots + i;
1920
1931
                (ulong) srv_conc_n_waiting_threads);
1921
1932
 
1922
1933
        fprintf(file, "%lu read views open inside InnoDB\n",
1923
 
                UT_LIST_GET_LEN(trx_sys->view_list));
 
1934
                static_cast<ulint>(UT_LIST_GET_LEN(trx_sys->view_list)));
1924
1935
 
1925
1936
        n_reserved = fil_space_get_n_reserved_extents(0);
1926
1937
        if (n_reserved > 0) {
2070
2081
os_thread_ret_t
2071
2082
srv_monitor_thread(
2072
2083
/*===============*/
2073
 
        void*   arg __attribute__((unused)))
 
2084
        void*   /*arg __attribute__((unused))*/)
2074
2085
                        /*!< in: a dummy parameter required by
2075
2086
                        os_thread_create */
2076
2087
{
 
2088
        ib_int64_t      sig_count;
2077
2089
        double          time_elapsed;
2078
2090
        time_t          current_time;
2079
2091
        time_t          last_table_monitor_time;
2091
2103
        pfs_register_thread(srv_monitor_thread_key);
2092
2104
#endif
2093
2105
 
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);
 
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();
2099
2110
        mutex_skipped = 0;
2100
2111
        last_srv_print_monitor = srv_print_innodb_monitor;
2101
2112
loop:
2102
2113
        srv_monitor_active = TRUE;
2103
2114
 
2104
2115
        /* Wake up every 5 seconds to see if we need to print
2105
 
        monitor information. */
2106
 
 
2107
 
        os_thread_sleep(5000000);
2108
 
 
2109
 
        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();
2110
2123
 
2111
2124
        time_elapsed = difftime(current_time, last_monitor_time);
2112
2125
 
2113
2126
        if (time_elapsed > 15) {
2114
 
                last_monitor_time = time(NULL);
 
2127
                last_monitor_time = ut_time();
2115
2128
 
2116
2129
                if (srv_print_innodb_monitor) {
2117
2130
                        /* Reset mutex_skipped counter everytime
2155
2168
                if (srv_print_innodb_tablespace_monitor
2156
2169
                    && difftime(current_time,
2157
2170
                                last_tablespace_monitor_time) > 60) {
2158
 
                        last_tablespace_monitor_time = time(NULL);
 
2171
                        last_tablespace_monitor_time = ut_time();
2159
2172
 
2160
2173
                        fputs("========================"
2161
2174
                              "========================\n",
2181
2194
                if (srv_print_innodb_table_monitor
2182
2195
                    && difftime(current_time, last_table_monitor_time) > 60) {
2183
2196
 
2184
 
                        last_table_monitor_time = time(NULL);
 
2197
                        last_table_monitor_time = ut_time();
2185
2198
 
2186
2199
                        fputs("===========================================\n",
2187
2200
                              stderr);
2233
2246
os_thread_ret_t
2234
2247
srv_lock_timeout_thread(
2235
2248
/*====================*/
2236
 
        void*   arg __attribute__((unused)))
 
2249
        void*   /*arg __attribute__((unused))*/)
2237
2250
                        /* in: a dummy parameter required by
2238
2251
                        os_thread_create */
2239
2252
{
2241
2254
        ibool           some_waits;
2242
2255
        double          wait_time;
2243
2256
        ulint           i;
 
2257
        ib_int64_t      sig_count;
2244
2258
 
2245
2259
#ifdef UNIV_PFS_THREAD
2246
2260
        pfs_register_thread(srv_lock_timeout_thread_key);
2247
2261
#endif
2248
2262
 
2249
2263
loop:
 
2264
 
2250
2265
        /* When someone is waiting for a lock, we wake up every second
2251
2266
        and check if a timeout has passed for a lock wait */
2252
2267
 
2253
 
        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);
2254
2271
 
2255
2272
        srv_lock_timeout_active = TRUE;
2256
2273
 
2337
2354
os_thread_ret_t
2338
2355
srv_error_monitor_thread(
2339
2356
/*=====================*/
2340
 
        void*   arg __attribute__((unused)))
 
2357
        void*   /*arg __attribute__((unused))*/)
2341
2358
                        /*!< in: a dummy parameter required by
2342
2359
                        os_thread_create */
2343
2360
{
2345
2362
        ulint           fatal_cnt       = 0;
2346
2363
        ib_uint64_t     old_lsn;
2347
2364
        ib_uint64_t     new_lsn;
 
2365
        ib_int64_t      sig_count;
2348
2366
 
2349
2367
        old_lsn = srv_start_lsn;
2350
2368
 
2420
2438
 
2421
2439
        fflush(stderr);
2422
2440
 
2423
 
        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);
2424
2444
 
2425
2445
        if (srv_shutdown_state < SRV_SHUTDOWN_CLEANUP) {
2426
2446
 
2599
2619
os_thread_ret_t
2600
2620
srv_master_thread(
2601
2621
/*==============*/
2602
 
        void*   arg __attribute__((unused)))
 
2622
        void*   /*arg __attribute__((unused))*/)
2603
2623
                        /*!< in: a dummy parameter required by
2604
2624
                        os_thread_create */
2605
2625
{
2671
2691
        for (i = 0; i < 10; i++) {
2672
2692
                ulint   cur_time = ut_time_ms();
2673
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
 
2674
2709
                buf_get_total_stat(&buf_stat);
2675
2710
 
2676
2711
                n_ios_old = log_sys->n_log_ios + buf_stat.n_pages_read
2679
2714
                srv_main_thread_op_info = "sleeping";
2680
2715
                srv_main_1_second_loops++;
2681
2716
 
2682
 
                if (next_itr_time > cur_time) {
 
2717
                if (next_itr_time > cur_time
 
2718
                    && srv_shutdown_state == SRV_SHUTDOWN_NONE) {
2683
2719
 
2684
2720
                        /* Get sleep interval in micro seconds. We use
2685
2721
                        ut_min() to avoid long sleep in case of
2693
2729
                /* Each iteration should happen at 1 second interval. */
2694
2730
                next_itr_time = ut_time_ms() + 1000;
2695
2731
 
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
 
 
2711
2732
                /* Flush logs if needed */
2712
2733
                srv_sync_log_buffer_in_background();
2713
2734
 
2885
2906
                MySQL tries to drop a table while there are still open handles
2886
2907
                to it and we had to put it to the background drop queue.) */
2887
2908
 
2888
 
                os_thread_sleep(100000);
 
2909
                if (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
 
2910
                        os_thread_sleep(100000);
 
2911
                }
2889
2912
        }
2890
2913
 
2891
2914
        if (srv_n_purge_threads == 0) {
3044
3067
        goto loop;
3045
3068
 
3046
3069
 
3047
 
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
 
3070
#if !defined(__SUNPRO_C)
3048
3071
        OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
3049
3072
#endif
3050
3073
}
3056
3079
os_thread_ret_t
3057
3080
srv_purge_thread(
3058
3081
/*=============*/
3059
 
        void*   arg __attribute__((unused)))    /*!< in: a dummy parameter
 
3082
        void*   /*arg __attribute__((unused))*/)        /*!< in: a dummy parameter
3060
3083
                                                required by os_thread_create */
3061
3084
{
3062
3085
        srv_slot_t*     slot;