~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-08 18:53:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1983.
  • Revision ID: brian@tangent.org-20101208185346-89uak2ofyivk1yss
Update schema, make sure that it always ruturns a valid string (it just
makes the entire interface simpler to use).

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
= {
463
463
UNIV_INTERN ib_int64_t  srv_n_lock_wait_time            = 0;
464
464
UNIV_INTERN ulint               srv_n_lock_max_wait_time        = 0;
465
465
 
466
 
UNIV_INTERN ulint               srv_truncated_status_writes     = 0;
467
466
 
468
467
/*
469
468
  Set the following to 0 if you want InnoDB to write messages on
491
490
#ifdef UNIV_PFS_MUTEX
492
491
/* Key to register kernel_mutex with performance schema */
493
492
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
493
/* Key to register srv_innodb_monitor_mutex with performance schema */
497
494
UNIV_INTERN mysql_pfs_key_t     srv_innodb_monitor_mutex_key;
498
495
/* Key to register srv_monitor_file_mutex with performance schema */
736
733
/* Table for MySQL threads where they will be suspended to wait for locks */
737
734
UNIV_INTERN srv_slot_t* srv_mysql_table = NULL;
738
735
 
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
736
UNIV_INTERN os_event_t  srv_lock_timeout_thread_event;
746
737
 
747
738
UNIV_INTERN srv_sys_t*  srv_sys = NULL;
751
742
UNIV_INTERN byte        srv_pad1[64];
752
743
/* mutex protecting the server, trx structs, query threads, and lock table */
753
744
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
745
/* padding to prevent other memory update hotspots from residing on
758
746
the same memory cache line */
759
747
UNIV_INTERN byte        srv_pad2[64];
915
903
 
916
904
        slot = srv_table_get_nth_slot(slot_no);
917
905
 
918
 
        type = static_cast<srv_thread_type>(slot->type);
 
906
        type = slot->type;
919
907
 
920
908
        ut_ad(type >= SRV_WORKER);
921
909
        ut_ad(type <= SRV_MASTER);
958
946
 
959
947
                slot = srv_table_get_nth_slot(i);
960
948
 
961
 
                if (slot->in_use &&
962
 
                    (static_cast<srv_thread_type>(slot->type) == type) &&
963
 
                    slot->suspended) {
 
949
                if (slot->in_use && slot->type == type && slot->suspended) {
964
950
 
965
951
                        slot->suspended = FALSE;
966
952
 
1005
991
 
1006
992
        slot = srv_table_get_nth_slot(slot_no);
1007
993
 
1008
 
        type = static_cast<srv_thread_type>(slot->type);
 
994
        type = slot->type;
1009
995
 
1010
996
        ut_ad(type >= SRV_WORKER);
1011
997
        ut_ad(type <= SRV_MASTER);
1026
1012
        srv_slot_t*             slot;
1027
1013
        ulint                   i;
1028
1014
 
1029
 
        srv_sys = static_cast<srv_sys_t *>(mem_alloc(sizeof(srv_sys_t)));
 
1015
        srv_sys = mem_alloc(sizeof(srv_sys_t));
1030
1016
 
1031
 
        kernel_mutex_temp = static_cast<ib_mutex_t *>(mem_alloc(sizeof(mutex_t)));
 
1017
        kernel_mutex_temp = mem_alloc(sizeof(mutex_t));
1032
1018
        mutex_create(kernel_mutex_key, &kernel_mutex, SYNC_KERNEL);
1033
1019
 
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
1020
        mutex_create(srv_innodb_monitor_mutex_key,
1038
1021
                     &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
1039
1022
 
1040
 
        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));
1041
1024
 
1042
1025
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1043
1026
                slot = srv_table_get_nth_slot(i);
1047
1030
                ut_a(slot->event);
1048
1031
        }
1049
1032
 
1050
 
        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));
1051
1034
 
1052
1035
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1053
1036
                slot = srv_mysql_table + i;
1057
1040
                ut_a(slot->event);
1058
1041
        }
1059
1042
 
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
1043
        srv_lock_timeout_thread_event = os_event_create(NULL);
1067
1044
 
1068
1045
        for (i = 0; i < SRV_MASTER + 1; i++) {
1089
1066
 
1090
1067
        UT_LIST_INIT(srv_conc_queue);
1091
1068
 
1092
 
        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));
1093
1070
 
1094
1071
        for (i = 0; i < OS_THREAD_MAX_N; i++) {
1095
1072
                conc_slot = srv_conc_slots + i;
1122
1099
        mem_free(srv_mysql_table);
1123
1100
        srv_mysql_table = NULL;
1124
1101
 
1125
 
        mem_free(commit_id_mutex_temp);
1126
 
        commit_id_mutex_temp = NULL;
1127
 
 
1128
1102
        trx_i_s_cache_free(trx_i_s_cache);
1129
1103
}
1130
1104
 
1645
1619
                row_mysql_unfreeze_data_dictionary(trx);
1646
1620
                break;
1647
1621
        case RW_X_LATCH:
1648
 
                /* There should never be a lock wait when the
1649
 
                dictionary latch is reserved in X mode.  Dictionary
1650
 
                transactions should only acquire locks on dictionary
1651
 
                tables, not other tables. All access to dictionary
1652
 
                tables should be covered by dictionary
1653
 
                transactions. */
1654
 
                ut_print_timestamp(stderr);
1655
 
                fputs("  InnoDB: Error: dict X latch held in "
1656
 
                      "srv_suspend_mysql_thread\n", stderr);
1657
 
                /* This should never occur. This incorrect handling
1658
 
                was added in the early development of
1659
 
                ha_innobase::add_index() in InnoDB Plugin 1.0. */
1660
1622
                /* Release fast index creation latch */
1661
1623
                row_mysql_unlock_data_dictionary(trx);
1662
1624
                break;
1676
1638
                row_mysql_freeze_data_dictionary(trx);
1677
1639
                break;
1678
1640
        case RW_X_LATCH:
1679
 
                /* This should never occur. This incorrect handling
1680
 
                was added in the early development of
1681
 
                ha_innobase::add_index() in InnoDB Plugin 1.0. */
1682
1641
                row_mysql_lock_data_dictionary(trx);
1683
1642
                break;
1684
1643
        }
1945
1904
                (ulong) srv_conc_n_waiting_threads);
1946
1905
 
1947
1906
        fprintf(file, "%lu read views open inside InnoDB\n",
1948
 
                static_cast<ulint>(UT_LIST_GET_LEN(trx_sys->view_list)));
 
1907
                UT_LIST_GET_LEN(trx_sys->view_list));
1949
1908
 
1950
1909
        n_reserved = fil_space_get_n_reserved_extents(0);
1951
1910
        if (n_reserved > 0) {
2083
2042
        export_vars.innodb_rows_inserted = srv_n_rows_inserted;
2084
2043
        export_vars.innodb_rows_updated = srv_n_rows_updated;
2085
2044
        export_vars.innodb_rows_deleted = srv_n_rows_deleted;
2086
 
        export_vars.innodb_truncated_status_writes = srv_truncated_status_writes;
2087
2045
 
2088
2046
        mutex_exit(&srv_innodb_monitor_mutex);
2089
2047
}
2095
2053
os_thread_ret_t
2096
2054
srv_monitor_thread(
2097
2055
/*===============*/
2098
 
        void*   /*arg __attribute__((unused))*/)
 
2056
        void*   arg __attribute__((unused)))
2099
2057
                        /*!< in: a dummy parameter required by
2100
2058
                        os_thread_create */
2101
2059
{
2102
 
        ib_int64_t      sig_count;
2103
2060
        double          time_elapsed;
2104
2061
        time_t          current_time;
2105
2062
        time_t          last_table_monitor_time;
2117
2074
        pfs_register_thread(srv_monitor_thread_key);
2118
2075
#endif
2119
2076
 
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();
 
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);
2124
2082
        mutex_skipped = 0;
2125
2083
        last_srv_print_monitor = srv_print_innodb_monitor;
2126
2084
loop:
2127
2085
        srv_monitor_active = TRUE;
2128
2086
 
2129
2087
        /* 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();
 
2088
        monitor information. */
 
2089
 
 
2090
        os_thread_sleep(5000000);
 
2091
 
 
2092
        current_time = time(NULL);
2137
2093
 
2138
2094
        time_elapsed = difftime(current_time, last_monitor_time);
2139
2095
 
2140
2096
        if (time_elapsed > 15) {
2141
 
                last_monitor_time = ut_time();
 
2097
                last_monitor_time = time(NULL);
2142
2098
 
2143
2099
                if (srv_print_innodb_monitor) {
2144
2100
                        /* Reset mutex_skipped counter everytime
2182
2138
                if (srv_print_innodb_tablespace_monitor
2183
2139
                    && difftime(current_time,
2184
2140
                                last_tablespace_monitor_time) > 60) {
2185
 
                        last_tablespace_monitor_time = ut_time();
 
2141
                        last_tablespace_monitor_time = time(NULL);
2186
2142
 
2187
2143
                        fputs("========================"
2188
2144
                              "========================\n",
2208
2164
                if (srv_print_innodb_table_monitor
2209
2165
                    && difftime(current_time, last_table_monitor_time) > 60) {
2210
2166
 
2211
 
                        last_table_monitor_time = ut_time();
 
2167
                        last_table_monitor_time = time(NULL);
2212
2168
 
2213
2169
                        fputs("===========================================\n",
2214
2170
                              stderr);
2260
2216
os_thread_ret_t
2261
2217
srv_lock_timeout_thread(
2262
2218
/*====================*/
2263
 
        void*   /*arg __attribute__((unused))*/)
 
2219
        void*   arg __attribute__((unused)))
2264
2220
                        /* in: a dummy parameter required by
2265
2221
                        os_thread_create */
2266
2222
{
2268
2224
        ibool           some_waits;
2269
2225
        double          wait_time;
2270
2226
        ulint           i;
2271
 
        ib_int64_t      sig_count;
2272
2227
 
2273
2228
#ifdef UNIV_PFS_THREAD
2274
2229
        pfs_register_thread(srv_lock_timeout_thread_key);
2275
2230
#endif
2276
2231
 
2277
2232
loop:
2278
 
 
2279
2233
        /* When someone is waiting for a lock, we wake up every second
2280
2234
        and check if a timeout has passed for a lock wait */
2281
2235
 
2282
 
        sig_count = os_event_reset(srv_timeout_event);
2283
 
 
2284
 
        os_event_wait_time_low(srv_timeout_event, 1000000, sig_count);
 
2236
        os_thread_sleep(1000000);
2285
2237
 
2286
2238
        srv_lock_timeout_active = TRUE;
2287
2239
 
2368
2320
os_thread_ret_t
2369
2321
srv_error_monitor_thread(
2370
2322
/*=====================*/
2371
 
        void*   /*arg __attribute__((unused))*/)
 
2323
        void*   arg __attribute__((unused)))
2372
2324
                        /*!< in: a dummy parameter required by
2373
2325
                        os_thread_create */
2374
2326
{
2376
2328
        ulint           fatal_cnt       = 0;
2377
2329
        ib_uint64_t     old_lsn;
2378
2330
        ib_uint64_t     new_lsn;
2379
 
        ib_int64_t      sig_count;
2380
2331
 
2381
2332
        old_lsn = srv_start_lsn;
2382
2333
 
2398
2349
        new_lsn = log_get_lsn();
2399
2350
 
2400
2351
        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);
 
2352
                ut_print_timestamp(stderr);
 
2353
                fprintf(stderr,
 
2354
                        "  InnoDB: Error: old log sequence number %"PRIu64""
 
2355
                        " was greater\n"
 
2356
                        "InnoDB: than the new log sequence number %"PRIu64"!\n"
 
2357
                        "InnoDB: Please submit a bug report"
 
2358
                        " to http://bugs.mysql.com\n",
 
2359
                        old_lsn, new_lsn);
2405
2360
        }
2406
2361
 
2407
2362
        old_lsn = new_lsn;
2448
2403
 
2449
2404
        fflush(stderr);
2450
2405
 
2451
 
        sig_count = os_event_reset(srv_error_event);
2452
 
 
2453
 
        os_event_wait_time_low(srv_error_event, 1000000, sig_count);
 
2406
        os_thread_sleep(1000000);
2454
2407
 
2455
2408
        if (srv_shutdown_state < SRV_SHUTDOWN_CLEANUP) {
2456
2409
 
2629
2582
os_thread_ret_t
2630
2583
srv_master_thread(
2631
2584
/*==============*/
2632
 
        void*   /*arg __attribute__((unused))*/)
 
2585
        void*   arg __attribute__((unused)))
2633
2586
                        /*!< in: a dummy parameter required by
2634
2587
                        os_thread_create */
2635
2588
{
2694
2647
        when there is database activity */
2695
2648
 
2696
2649
        srv_last_log_flush_time = time(NULL);
2697
 
 
2698
 
        /* Sleep for 1 second on entrying the for loop below the first time. */
2699
 
        next_itr_time = ut_time_ms() + 1000;
 
2650
        next_itr_time = ut_time_ms();
2700
2651
 
2701
2652
        for (i = 0; i < 10; i++) {
2702
2653
                ulint   cur_time = ut_time_ms();
2703
2654
 
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
2655
                buf_get_total_stat(&buf_stat);
2720
2656
 
2721
2657
                n_ios_old = log_sys->n_log_ios + buf_stat.n_pages_read
2724
2660
                srv_main_thread_op_info = "sleeping";
2725
2661
                srv_main_1_second_loops++;
2726
2662
 
2727
 
                if (next_itr_time > cur_time
2728
 
                    && srv_shutdown_state == SRV_SHUTDOWN_NONE) {
 
2663
                if (next_itr_time > cur_time) {
2729
2664
 
2730
2665
                        /* Get sleep interval in micro seconds. We use
2731
2666
                        ut_min() to avoid long sleep in case of
2739
2674
                /* Each iteration should happen at 1 second interval. */
2740
2675
                next_itr_time = ut_time_ms() + 1000;
2741
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
 
2742
2692
                /* Flush logs if needed */
2743
2693
                srv_sync_log_buffer_in_background();
2744
2694
 
2916
2866
                MySQL tries to drop a table while there are still open handles
2917
2867
                to it and we had to put it to the background drop queue.) */
2918
2868
 
2919
 
                if (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
2920
 
                        os_thread_sleep(100000);
2921
 
                }
 
2869
                os_thread_sleep(100000);
2922
2870
        }
2923
2871
 
2924
2872
        if (srv_n_purge_threads == 0) {
3077
3025
        goto loop;
3078
3026
 
3079
3027
 
3080
 
#if !defined(__SUNPRO_C)
 
3028
#if (!defined(__SUNPRO_C) && !defined(__SUNPRO_CC))
3081
3029
        OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
3082
3030
#endif
3083
3031
}
3089
3037
os_thread_ret_t
3090
3038
srv_purge_thread(
3091
3039
/*=============*/
3092
 
        void*   /*arg __attribute__((unused))*/)        /*!< in: a dummy parameter
 
3040
        void*   arg __attribute__((unused)))    /*!< in: a dummy parameter
3093
3041
                                                required by os_thread_create */
3094
3042
{
3095
3043
        srv_slot_t*     slot;