~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-12-16 20:06:09 UTC
  • Revision ID: brian@tangent.org-20101216200609-xigmi0vbldradofi
I've mentioned this to Paul. Once we have the bits in for session around
thread he will go in and fix what he needs to fix. 

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
60
60
/* Dummy comment */
61
61
#include "srv0srv.h"
62
62
 
63
 
#include <drizzled/error.h>
64
 
#include <drizzled/errmsg_print.h>
65
 
 
66
63
#include "ut0mem.h"
67
64
#include "ut0ut.h"
68
65
#include "os0proc.h"
109
106
 
110
107
UNIV_INTERN const char* srv_main_thread_op_info = "";
111
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
112
/* Server parameters which are read from the initfile */
113
113
 
114
114
/* The following three are dir paths which are catenated before file
204
204
/** The sort order table of the MySQL latin1_swedish_ci character set
205
205
collation */
206
206
#if defined(BUILD_DRIZZLE)
207
 
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
208
208
                                        character set. The following table is
209
209
                                        the MySQL order as of Feb 10th, 2002 */
210
210
= {
491
491
#ifdef UNIV_PFS_MUTEX
492
492
/* Key to register kernel_mutex with performance schema */
493
493
UNIV_INTERN mysql_pfs_key_t     kernel_mutex_key;
494
 
/* Key to protect writing the commit_id to the sys header */
495
 
UNIV_INTERN mysql_pfs_key_t     commit_id_mutex_key;
496
494
/* Key to register srv_innodb_monitor_mutex with performance schema */
497
495
UNIV_INTERN mysql_pfs_key_t     srv_innodb_monitor_mutex_key;
498
496
/* Key to register srv_monitor_file_mutex with performance schema */
736
734
/* Table for MySQL threads where they will be suspended to wait for locks */
737
735
UNIV_INTERN srv_slot_t* srv_mysql_table = NULL;
738
736
 
739
 
UNIV_INTERN os_event_t  srv_timeout_event;
740
 
 
741
 
UNIV_INTERN os_event_t  srv_monitor_event;
742
 
 
743
 
UNIV_INTERN os_event_t  srv_error_event;
744
 
 
745
737
UNIV_INTERN os_event_t  srv_lock_timeout_thread_event;
746
738
 
747
739
UNIV_INTERN srv_sys_t*  srv_sys = NULL;
751
743
UNIV_INTERN byte        srv_pad1[64];
752
744
/* mutex protecting the server, trx structs, query threads, and lock table */
753
745
UNIV_INTERN mutex_t*    kernel_mutex_temp;
754
 
/* mutex protecting the sys header for writing the commit id */
755
 
UNIV_INTERN mutex_t*    commit_id_mutex_temp;
756
 
 
757
746
/* padding to prevent other memory update hotspots from residing on
758
747
the same memory cache line */
759
748
UNIV_INTERN byte        srv_pad2[64];
915
904
 
916
905
        slot = srv_table_get_nth_slot(slot_no);
917
906
 
918
 
        type = static_cast<srv_thread_type>(slot->type);
 
907
        type = slot->type;
919
908
 
920
909
        ut_ad(type >= SRV_WORKER);
921
910
        ut_ad(type <= SRV_MASTER);
958
947
 
959
948
                slot = srv_table_get_nth_slot(i);
960
949
 
961
 
                if (slot->in_use &&
962
 
                    (static_cast<srv_thread_type>(slot->type) == type) &&
963
 
                    slot->suspended) {
 
950
                if (slot->in_use && slot->type == type && slot->suspended) {
964
951
 
965
952
                        slot->suspended = FALSE;
966
953
 
1005
992
 
1006
993
        slot = srv_table_get_nth_slot(slot_no);
1007
994
 
1008
 
        type = static_cast<srv_thread_type>(slot->type);
 
995
        type = slot->type;
1009
996
 
1010
997
        ut_ad(type >= SRV_WORKER);
1011
998
        ut_ad(type <= SRV_MASTER);
1026
1013
        srv_slot_t*             slot;
1027
1014
        ulint                   i;
1028
1015
 
1029
 
        srv_sys = static_cast<srv_sys_t *>(mem_alloc(sizeof(srv_sys_t)));
 
1016
        srv_sys = mem_alloc(sizeof(srv_sys_t));
1030
1017
 
1031
 
        kernel_mutex_temp = static_cast<ib_mutex_t *>(mem_alloc(sizeof(mutex_t)));
 
1018
        kernel_mutex_temp = mem_alloc(sizeof(mutex_t));
1032
1019
        mutex_create(kernel_mutex_key, &kernel_mutex, SYNC_KERNEL);
1033
1020
 
1034
 
        commit_id_mutex_temp = static_cast<ib_mutex_t *>(mem_alloc(sizeof(mutex_t)));
1035
 
        mutex_create(commit_id_mutex_key, &commit_id_mutex, SYNC_COMMIT_ID_LOCK);
1036
 
 
1037
1021
        mutex_create(srv_innodb_monitor_mutex_key,
1038
1022
                     &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
1039
1023
 
1040
 
        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));
1041
1025
 
1042
1026
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1043
1027
                slot = srv_table_get_nth_slot(i);
1047
1031
                ut_a(slot->event);
1048
1032
        }
1049
1033
 
1050
 
        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));
1051
1035
 
1052
1036
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1053
1037
                slot = srv_mysql_table + i;
1057
1041
                ut_a(slot->event);
1058
1042
        }
1059
1043
 
1060
 
        srv_error_event = os_event_create(NULL);
1061
 
 
1062
 
        srv_timeout_event = os_event_create(NULL);
1063
 
 
1064
 
        srv_monitor_event = os_event_create(NULL);
1065
 
 
1066
1044
        srv_lock_timeout_thread_event = os_event_create(NULL);
1067
1045
 
1068
1046
        for (i = 0; i < SRV_MASTER + 1; i++) {
1089
1067
 
1090
1068
        UT_LIST_INIT(srv_conc_queue);
1091
1069
 
1092
 
        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));
1093
1071
 
1094
1072
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1095
1073
                conc_slot = srv_conc_slots + i;
1122
1100
        mem_free(srv_mysql_table);
1123
1101
        srv_mysql_table = NULL;
1124
1102
 
1125
 
        mem_free(commit_id_mutex_temp);
1126
 
        commit_id_mutex_temp = NULL;
1127
 
 
1128
1103
        trx_i_s_cache_free(trx_i_s_cache);
1129
1104
}
1130
1105
 
1945
1920
                (ulong) srv_conc_n_waiting_threads);
1946
1921
 
1947
1922
        fprintf(file, "%lu read views open inside InnoDB\n",
1948
 
                static_cast<ulint>(UT_LIST_GET_LEN(trx_sys->view_list)));
 
1923
                UT_LIST_GET_LEN(trx_sys->view_list));
1949
1924
 
1950
1925
        n_reserved = fil_space_get_n_reserved_extents(0);
1951
1926
        if (n_reserved > 0) {
2095
2070
os_thread_ret_t
2096
2071
srv_monitor_thread(
2097
2072
/*===============*/
2098
 
        void*   /*arg __attribute__((unused))*/)
 
2073
        void*   arg __attribute__((unused)))
2099
2074
                        /*!< in: a dummy parameter required by
2100
2075
                        os_thread_create */
2101
2076
{
2102
 
        ib_int64_t      sig_count;
2103
2077
        double          time_elapsed;
2104
2078
        time_t          current_time;
2105
2079
        time_t          last_table_monitor_time;
2117
2091
        pfs_register_thread(srv_monitor_thread_key);
2118
2092
#endif
2119
2093
 
2120
 
        srv_last_monitor_time = ut_time();
2121
 
        last_table_monitor_time = ut_time();
2122
 
        last_tablespace_monitor_time = ut_time();
2123
 
        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);
2124
2099
        mutex_skipped = 0;
2125
2100
        last_srv_print_monitor = srv_print_innodb_monitor;
2126
2101
loop:
2127
2102
        srv_monitor_active = TRUE;
2128
2103
 
2129
2104
        /* Wake up every 5 seconds to see if we need to print
2130
 
        monitor information or if signalled at shutdown. */
2131
 
 
2132
 
        sig_count = os_event_reset(srv_monitor_event);
2133
 
 
2134
 
        os_event_wait_time_low(srv_monitor_event, 5000000, sig_count);
2135
 
 
2136
 
        current_time = ut_time();
 
2105
        monitor information. */
 
2106
 
 
2107
        os_thread_sleep(5000000);
 
2108
 
 
2109
        current_time = time(NULL);
2137
2110
 
2138
2111
        time_elapsed = difftime(current_time, last_monitor_time);
2139
2112
 
2140
2113
        if (time_elapsed > 15) {
2141
 
                last_monitor_time = ut_time();
 
2114
                last_monitor_time = time(NULL);
2142
2115
 
2143
2116
                if (srv_print_innodb_monitor) {
2144
2117
                        /* Reset mutex_skipped counter everytime
2182
2155
                if (srv_print_innodb_tablespace_monitor
2183
2156
                    && difftime(current_time,
2184
2157
                                last_tablespace_monitor_time) > 60) {
2185
 
                        last_tablespace_monitor_time = ut_time();
 
2158
                        last_tablespace_monitor_time = time(NULL);
2186
2159
 
2187
2160
                        fputs("========================"
2188
2161
                              "========================\n",
2208
2181
                if (srv_print_innodb_table_monitor
2209
2182
                    && difftime(current_time, last_table_monitor_time) > 60) {
2210
2183
 
2211
 
                        last_table_monitor_time = ut_time();
 
2184
                        last_table_monitor_time = time(NULL);
2212
2185
 
2213
2186
                        fputs("===========================================\n",
2214
2187
                              stderr);
2260
2233
os_thread_ret_t
2261
2234
srv_lock_timeout_thread(
2262
2235
/*====================*/
2263
 
        void*   /*arg __attribute__((unused))*/)
 
2236
        void*   arg __attribute__((unused)))
2264
2237
                        /* in: a dummy parameter required by
2265
2238
                        os_thread_create */
2266
2239
{
2268
2241
        ibool           some_waits;
2269
2242
        double          wait_time;
2270
2243
        ulint           i;
2271
 
        ib_int64_t      sig_count;
2272
2244
 
2273
2245
#ifdef UNIV_PFS_THREAD
2274
2246
        pfs_register_thread(srv_lock_timeout_thread_key);
2275
2247
#endif
2276
2248
 
2277
2249
loop:
2278
 
 
2279
2250
        /* When someone is waiting for a lock, we wake up every second
2280
2251
        and check if a timeout has passed for a lock wait */
2281
2252
 
2282
 
        sig_count = os_event_reset(srv_timeout_event);
2283
 
 
2284
 
        os_event_wait_time_low(srv_timeout_event, 1000000, sig_count);
 
2253
        os_thread_sleep(1000000);
2285
2254
 
2286
2255
        srv_lock_timeout_active = TRUE;
2287
2256
 
2368
2337
os_thread_ret_t
2369
2338
srv_error_monitor_thread(
2370
2339
/*=====================*/
2371
 
        void*   /*arg __attribute__((unused))*/)
 
2340
        void*   arg __attribute__((unused)))
2372
2341
                        /*!< in: a dummy parameter required by
2373
2342
                        os_thread_create */
2374
2343
{
2376
2345
        ulint           fatal_cnt       = 0;
2377
2346
        ib_uint64_t     old_lsn;
2378
2347
        ib_uint64_t     new_lsn;
2379
 
        ib_int64_t      sig_count;
2380
2348
 
2381
2349
        old_lsn = srv_start_lsn;
2382
2350
 
2398
2366
        new_lsn = log_get_lsn();
2399
2367
 
2400
2368
        if (new_lsn < old_lsn) {
2401
 
          drizzled::errmsg_printf(drizzled::error::INFO,
2402
 
                                  "InnoDB: Error: old log sequence number %"PRIu64" was greater than the new log sequence number %"PRIu64"!"
2403
 
                                  "InnoDB: Please submit a bug report to http://bugs.launchpad.net/drizzle",
2404
 
                                  old_lsn, new_lsn);
 
2369
                ut_print_timestamp(stderr);
 
2370
                fprintf(stderr,
 
2371
                        "  InnoDB: Error: old log sequence number %"PRIu64""
 
2372
                        " was greater\n"
 
2373
                        "InnoDB: than the new log sequence number %"PRIu64"!\n"
 
2374
                        "InnoDB: Please submit a bug report"
 
2375
                        " to http://bugs.mysql.com\n",
 
2376
                        old_lsn, new_lsn);
2405
2377
        }
2406
2378
 
2407
2379
        old_lsn = new_lsn;
2448
2420
 
2449
2421
        fflush(stderr);
2450
2422
 
2451
 
        sig_count = os_event_reset(srv_error_event);
2452
 
 
2453
 
        os_event_wait_time_low(srv_error_event, 1000000, sig_count);
 
2423
        os_thread_sleep(1000000);
2454
2424
 
2455
2425
        if (srv_shutdown_state < SRV_SHUTDOWN_CLEANUP) {
2456
2426
 
2629
2599
os_thread_ret_t
2630
2600
srv_master_thread(
2631
2601
/*==============*/
2632
 
        void*   /*arg __attribute__((unused))*/)
 
2602
        void*   arg __attribute__((unused)))
2633
2603
                        /*!< in: a dummy parameter required by
2634
2604
                        os_thread_create */
2635
2605
{
2701
2671
        for (i = 0; i < 10; i++) {
2702
2672
                ulint   cur_time = ut_time_ms();
2703
2673
 
2704
 
                /* ALTER TABLE in MySQL requires on Unix that the table handler
2705
 
                can drop tables lazily after there no longer are SELECT
2706
 
                queries to them. */
2707
 
 
2708
 
                srv_main_thread_op_info = "doing background drop tables";
2709
 
 
2710
 
                row_drop_tables_for_mysql_in_background();
2711
 
 
2712
 
                srv_main_thread_op_info = "";
2713
 
 
2714
 
                if (srv_fast_shutdown && srv_shutdown_state > 0) {
2715
 
 
2716
 
                        goto background_loop;
2717
 
                }
2718
 
 
2719
2674
                buf_get_total_stat(&buf_stat);
2720
2675
 
2721
2676
                n_ios_old = log_sys->n_log_ios + buf_stat.n_pages_read
2724
2679
                srv_main_thread_op_info = "sleeping";
2725
2680
                srv_main_1_second_loops++;
2726
2681
 
2727
 
                if (next_itr_time > cur_time
2728
 
                    && srv_shutdown_state == SRV_SHUTDOWN_NONE) {
 
2682
                if (next_itr_time > cur_time) {
2729
2683
 
2730
2684
                        /* Get sleep interval in micro seconds. We use
2731
2685
                        ut_min() to avoid long sleep in case of
2739
2693
                /* Each iteration should happen at 1 second interval. */
2740
2694
                next_itr_time = ut_time_ms() + 1000;
2741
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
 
2742
2711
                /* Flush logs if needed */
2743
2712
                srv_sync_log_buffer_in_background();
2744
2713
 
2916
2885
                MySQL tries to drop a table while there are still open handles
2917
2886
                to it and we had to put it to the background drop queue.) */
2918
2887
 
2919
 
                if (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
2920
 
                        os_thread_sleep(100000);
2921
 
                }
 
2888
                os_thread_sleep(100000);
2922
2889
        }
2923
2890
 
2924
2891
        if (srv_n_purge_threads == 0) {
3077
3044
        goto loop;
3078
3045
 
3079
3046
 
3080
 
#if !defined(__SUNPRO_C)
 
3047
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
3081
3048
        OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
3082
3049
#endif
3083
3050
}
3089
3056
os_thread_ret_t
3090
3057
srv_purge_thread(
3091
3058
/*=============*/
3092
 
        void*   /*arg __attribute__((unused))*/)        /*!< in: a dummy parameter
 
3059
        void*   arg __attribute__((unused)))    /*!< in: a dummy parameter
3093
3060
                                                required by os_thread_create */
3094
3061
{
3095
3062
        srv_slot_t*     slot;