~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Monty Taylor
  • Date: 2009-10-13 06:22:10 UTC
  • mfrom: (1182 staging)
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20091013062210-iwnwwcdamjdvlx1m
Merged up with build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
extern "C" int gethostname(char *name, int namelen);
162
162
#endif
163
163
 
164
 
extern "C" void handle_segfault(int sig);
165
 
 
166
164
using namespace std;
167
165
using namespace drizzled;
168
166
 
408
406
 
409
407
static void usage(void);
410
408
static void clean_up_mutexes(void);
411
 
extern "C" void end_thread_signal(int );
412
409
void close_connections(void);
413
 
extern "C" void print_signal_warning(int sig);
414
410
 
415
411
/****************************************************************************
416
412
** Code to end drizzled
488
484
      break;
489
485
    }
490
486
    tmp= session_list.front();
 
487
    /* Close before unlock, avoiding crash. See LP bug#436685 */
 
488
    tmp->client->close();
491
489
    (void) pthread_mutex_unlock(&LOCK_thread_count);
492
 
    tmp->client->close();
493
490
  }
494
491
}
495
492
 
 
493
extern "C" void print_signal_warning(int sig);
496
494
 
497
 
void print_signal_warning(int sig)
 
495
extern "C" void print_signal_warning(int sig)
498
496
{
499
497
  if (global_system_variables.log_warnings)
500
498
    errmsg_printf(ERRMSG_LVL_WARN, _("Got signal %d from thread %"PRIu64), sig,my_thread_id());
751
749
  }
752
750
}
753
751
 
 
752
extern "C" void end_thread_signal(int );
754
753
 
755
754
/** Called when a thread is aborted. */
756
 
void end_thread_signal(int )
 
755
extern "C" void end_thread_signal(int )
757
756
{
758
757
  Session *session=current_session;
759
758
  if (session)
821
820
}
822
821
#endif
823
822
 
 
823
extern "C" void handle_segfault(int sig);
824
824
 
825
825
extern "C" void handle_segfault(int sig)
826
826
{
1047
1047
  return;;
1048
1048
}
1049
1049
 
1050
 
static void check_data_home(const char *)
1051
 
{}
1052
 
 
 
1050
extern "C" void my_message_sql(uint32_t error, const char *str, myf MyFlags);
1053
1051
 
1054
1052
/**
1055
1053
  All global error messages are sent here where the first one is stored
1056
1054
  for the client.
1057
1055
*/
1058
 
/* ARGSUSED */
1059
 
extern "C" void my_message_sql(uint32_t error, const char *str, myf MyFlags);
1060
 
 
1061
 
void my_message_sql(uint32_t error, const char *str, myf MyFlags)
 
1056
extern "C" void my_message_sql(uint32_t error, const char *str, myf MyFlags)
1062
1057
{
1063
1058
  Session *session;
1064
1059
  /*
1114
1109
static const char *load_default_groups[]= {
1115
1110
DRIZZLE_CONFIG_NAME, "server", 0, 0};
1116
1111
 
1117
 
SHOW_VAR com_status_vars[]= {
 
1112
static int show_starttime(SHOW_VAR *var, char *buff)
 
1113
{
 
1114
  var->type= SHOW_LONG;
 
1115
  var->value= buff;
 
1116
  *((long *)buff)= (long) (time(NULL) - server_start_time);
 
1117
  return 0;
 
1118
}
 
1119
 
 
1120
static int show_flushstatustime(SHOW_VAR *var, char *buff)
 
1121
{
 
1122
  var->type= SHOW_LONG;
 
1123
  var->value= buff;
 
1124
  *((long *)buff)= (long) (time(NULL) - flush_status_time);
 
1125
  return 0;
 
1126
}
 
1127
 
 
1128
static int show_open_tables(SHOW_VAR *var, char *buff)
 
1129
{
 
1130
  var->type= SHOW_LONG;
 
1131
  var->value= buff;
 
1132
  *((long *)buff)= (long)cached_open_tables();
 
1133
  return 0;
 
1134
}
 
1135
 
 
1136
static int show_table_definitions(SHOW_VAR *var, char *buff)
 
1137
{
 
1138
  var->type= SHOW_LONG;
 
1139
  var->value= buff;
 
1140
  *((long *)buff)= (long)cached_table_definitions();
 
1141
  return 0;
 
1142
}
 
1143
 
 
1144
static st_show_var_func_container
 
1145
show_open_tables_cont= { &show_open_tables };
 
1146
static st_show_var_func_container
 
1147
show_table_definitions_cont= { &show_table_definitions };
 
1148
static st_show_var_func_container
 
1149
show_starttime_cont= { &show_starttime };
 
1150
static st_show_var_func_container
 
1151
show_flushstatustime_cont= { &show_flushstatustime };
 
1152
 
 
1153
/*
 
1154
  Variables shown by SHOW STATUS in alphabetical order
 
1155
*/
 
1156
static SHOW_VAR com_status_vars[]= {
1118
1157
  {"admin_commands",       (char*) offsetof(STATUS_VAR, com_other), SHOW_LONG_STATUS},
1119
1158
  {"alter_db",             (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ALTER_DB]), SHOW_LONG_STATUS},
1120
1159
  {"alter_table",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ALTER_TABLE]), SHOW_LONG_STATUS},
1167
1206
  {NULL, NULL, SHOW_LONGLONG}
1168
1207
};
1169
1208
 
 
1209
static SHOW_VAR status_vars[]= {
 
1210
  {"Aborted_clients",          (char*) &aborted_threads,        SHOW_LONGLONG},
 
1211
  {"Aborted_connects",         (char*) &aborted_connects,       SHOW_LONGLONG},
 
1212
  {"Bytes_received",           (char*) offsetof(STATUS_VAR, bytes_received), SHOW_LONGLONG_STATUS},
 
1213
  {"Bytes_sent",               (char*) offsetof(STATUS_VAR, bytes_sent), SHOW_LONGLONG_STATUS},
 
1214
  {"Com",                      (char*) com_status_vars, SHOW_ARRAY},
 
1215
  {"Connections",              (char*) &global_thread_id, SHOW_INT_NOFLUSH},
 
1216
  {"Created_tmp_disk_tables",  (char*) offsetof(STATUS_VAR, created_tmp_disk_tables), SHOW_LONG_STATUS},
 
1217
  {"Created_tmp_files",        (char*) &my_tmp_file_created,SHOW_INT},
 
1218
  {"Created_tmp_tables",       (char*) offsetof(STATUS_VAR, created_tmp_tables), SHOW_LONG_STATUS},
 
1219
  {"Flush_commands",           (char*) &refresh_version,    SHOW_INT_NOFLUSH},
 
1220
  {"Handler_commit",           (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS},
 
1221
  {"Handler_delete",           (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS},
 
1222
  {"Handler_prepare",          (char*) offsetof(STATUS_VAR, ha_prepare_count),  SHOW_LONG_STATUS},
 
1223
  {"Handler_read_first",       (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS},
 
1224
  {"Handler_read_key",         (char*) offsetof(STATUS_VAR, ha_read_key_count), SHOW_LONG_STATUS},
 
1225
  {"Handler_read_next",        (char*) offsetof(STATUS_VAR, ha_read_next_count), SHOW_LONG_STATUS},
 
1226
  {"Handler_read_prev",        (char*) offsetof(STATUS_VAR, ha_read_prev_count), SHOW_LONG_STATUS},
 
1227
  {"Handler_read_rnd",         (char*) offsetof(STATUS_VAR, ha_read_rnd_count), SHOW_LONG_STATUS},
 
1228
  {"Handler_read_rnd_next",    (char*) offsetof(STATUS_VAR, ha_read_rnd_next_count), SHOW_LONG_STATUS},
 
1229
  {"Handler_rollback",         (char*) offsetof(STATUS_VAR, ha_rollback_count), SHOW_LONG_STATUS},
 
1230
  {"Handler_savepoint",        (char*) offsetof(STATUS_VAR, ha_savepoint_count), SHOW_LONG_STATUS},
 
1231
  {"Handler_savepoint_rollback",(char*) offsetof(STATUS_VAR, ha_savepoint_rollback_count), SHOW_LONG_STATUS},
 
1232
  {"Handler_update",           (char*) offsetof(STATUS_VAR, ha_update_count), SHOW_LONG_STATUS},
 
1233
  {"Handler_write",            (char*) offsetof(STATUS_VAR, ha_write_count), SHOW_LONG_STATUS},
 
1234
  {"Key_blocks_not_flushed",   (char*) offsetof(KEY_CACHE, global_blocks_changed), SHOW_KEY_CACHE_LONG},
 
1235
  {"Key_blocks_unused",        (char*) offsetof(KEY_CACHE, blocks_unused), SHOW_KEY_CACHE_LONG},
 
1236
  {"Key_blocks_used",          (char*) offsetof(KEY_CACHE, blocks_used), SHOW_KEY_CACHE_LONG},
 
1237
  {"Key_read_requests",        (char*) offsetof(KEY_CACHE, global_cache_r_requests), SHOW_KEY_CACHE_LONGLONG},
 
1238
  {"Key_reads",                (char*) offsetof(KEY_CACHE, global_cache_read), SHOW_KEY_CACHE_LONGLONG},
 
1239
  {"Key_write_requests",       (char*) offsetof(KEY_CACHE, global_cache_w_requests), SHOW_KEY_CACHE_LONGLONG},
 
1240
  {"Key_writes",               (char*) offsetof(KEY_CACHE, global_cache_write), SHOW_KEY_CACHE_LONGLONG},
 
1241
  {"Last_query_cost",          (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
 
1242
  {"Max_used_connections",     (char*) &max_used_connections,  SHOW_INT},
 
1243
  {"Open_files",               (char*) &my_file_opened,    SHOW_INT_NOFLUSH},
 
1244
  {"Open_streams",             (char*) &my_stream_opened,  SHOW_INT_NOFLUSH},
 
1245
  {"Open_table_definitions",   (char*) &show_table_definitions_cont, SHOW_FUNC},
 
1246
  {"Open_tables",              (char*) &show_open_tables_cont,       SHOW_FUNC},
 
1247
  {"Opened_files",             (char*) &my_file_total_opened, SHOW_INT_NOFLUSH},
 
1248
  {"Opened_tables",            (char*) offsetof(STATUS_VAR, opened_tables), SHOW_LONG_STATUS},
 
1249
  {"Opened_table_definitions", (char*) offsetof(STATUS_VAR, opened_shares), SHOW_LONG_STATUS},
 
1250
  {"Questions",                (char*) offsetof(STATUS_VAR, questions), SHOW_LONG_STATUS},
 
1251
  {"Select_full_join",         (char*) offsetof(STATUS_VAR, select_full_join_count), SHOW_LONG_STATUS},
 
1252
  {"Select_full_range_join",   (char*) offsetof(STATUS_VAR, select_full_range_join_count), SHOW_LONG_STATUS},
 
1253
  {"Select_range",             (char*) offsetof(STATUS_VAR, select_range_count), SHOW_LONG_STATUS},
 
1254
  {"Select_range_check",       (char*) offsetof(STATUS_VAR, select_range_check_count), SHOW_LONG_STATUS},
 
1255
  {"Select_scan",              (char*) offsetof(STATUS_VAR, select_scan_count), SHOW_LONG_STATUS},
 
1256
  {"Slow_queries",             (char*) offsetof(STATUS_VAR, long_query_count), SHOW_LONG_STATUS},
 
1257
  {"Sort_merge_passes",        (char*) offsetof(STATUS_VAR, filesort_merge_passes), SHOW_LONG_STATUS},
 
1258
  {"Sort_range",               (char*) offsetof(STATUS_VAR, filesort_range_count), SHOW_LONG_STATUS},
 
1259
  {"Sort_rows",                (char*) offsetof(STATUS_VAR, filesort_rows), SHOW_LONG_STATUS},
 
1260
  {"Sort_scan",                (char*) offsetof(STATUS_VAR, filesort_scan_count), SHOW_LONG_STATUS},
 
1261
  {"Table_locks_immediate",    (char*) &locks_immediate,        SHOW_INT},
 
1262
  {"Table_locks_waited",       (char*) &locks_waited,           SHOW_INT},
 
1263
  {"Threads_connected",        (char*) &connection_count,       SHOW_INT},
 
1264
  {"Uptime",                   (char*) &show_starttime_cont,         SHOW_FUNC},
 
1265
  {"Uptime_since_flush_status",(char*) &show_flushstatustime_cont,   SHOW_FUNC},
 
1266
  {NULL, NULL, SHOW_LONGLONG}
 
1267
};
 
1268
 
1170
1269
static int init_common_variables(const char *conf_file_name, int argc,
1171
1270
                                 char **argv, const char **groups)
1172
1271
{
1508
1607
  select_thread=pthread_self();
1509
1608
  select_thread_in_use=1;
1510
1609
 
1511
 
  check_data_home(drizzle_real_data_home);
1512
1610
  if (chdir(drizzle_real_data_home) && !opt_help)
1513
1611
    unireg_abort(1);
1514
1612
  drizzle_data_home= drizzle_data_home_buff;
2046
2144
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
2047
2145
};
2048
2146
 
2049
 
static int show_starttime(SHOW_VAR *var, char *buff)
2050
 
{
2051
 
  var->type= SHOW_LONG;
2052
 
  var->value= buff;
2053
 
  *((uint32_t *)buff)= (uint32_t) (time(NULL) - server_start_time);
2054
 
  return 0;
2055
 
}
2056
 
 
2057
 
static st_show_var_func_container
2058
 
show_starttime_cont= { &show_starttime };
2059
 
 
2060
 
static int show_flushstatustime(SHOW_VAR *var, char *buff)
2061
 
{
2062
 
  var->type= SHOW_LONG;
2063
 
  var->value= buff;
2064
 
  *((uint32_t *)buff)= (uint32_t) (time(NULL) - flush_status_time);
2065
 
  return 0;
2066
 
}
2067
 
 
2068
 
static st_show_var_func_container
2069
 
show_flushstatustime_cont= { &show_flushstatustime };
2070
 
 
2071
 
static int show_open_tables(SHOW_VAR *var, char *buff)
2072
 
{
2073
 
  var->type= SHOW_LONG;
2074
 
  var->value= buff;
2075
 
  *((uint32_t *)buff)= (uint32_t)cached_open_tables();
2076
 
  return 0;
2077
 
}
2078
 
 
2079
 
static int show_table_definitions(SHOW_VAR *var, char *buff)
2080
 
{
2081
 
  var->type= SHOW_LONG;
2082
 
  var->value= buff;
2083
 
  *((uint32_t *)buff)= (uint32_t)cached_table_definitions();
2084
 
  return 0;
2085
 
}
2086
 
 
2087
 
static st_show_var_func_container
2088
 
show_open_tables_cont= { &show_open_tables };
2089
 
static st_show_var_func_container
2090
 
show_table_definitions_cont= { &show_table_definitions };
2091
 
 
2092
 
/*
2093
 
  Variables shown by SHOW STATUS in alphabetical order
2094
 
*/
2095
 
 
2096
 
SHOW_VAR status_vars[]= {
2097
 
  {"Aborted_clients",          (char*) &aborted_threads,        SHOW_LONGLONG},
2098
 
  {"Aborted_connects",         (char*) &aborted_connects,       SHOW_LONGLONG},
2099
 
  {"Bytes_received",           (char*) offsetof(STATUS_VAR, bytes_received), SHOW_LONGLONG_STATUS},
2100
 
  {"Bytes_sent",               (char*) offsetof(STATUS_VAR, bytes_sent), SHOW_LONGLONG_STATUS},
2101
 
  {"Com",                      (char*) com_status_vars, SHOW_ARRAY},
2102
 
  {"Connections",              (char*) &global_thread_id, SHOW_INT_NOFLUSH},
2103
 
  {"Created_tmp_disk_tables",  (char*) offsetof(STATUS_VAR, created_tmp_disk_tables), SHOW_LONG_STATUS},
2104
 
  {"Created_tmp_files",        (char*) &my_tmp_file_created,SHOW_INT},
2105
 
  {"Created_tmp_tables",       (char*) offsetof(STATUS_VAR, created_tmp_tables), SHOW_LONG_STATUS},
2106
 
  {"Flush_commands",           (char*) &refresh_version,    SHOW_INT_NOFLUSH},
2107
 
  {"Handler_commit",           (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS},
2108
 
  {"Handler_delete",           (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS},
2109
 
  {"Handler_prepare",          (char*) offsetof(STATUS_VAR, ha_prepare_count),  SHOW_LONG_STATUS},
2110
 
  {"Handler_read_first",       (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS},
2111
 
  {"Handler_read_key",         (char*) offsetof(STATUS_VAR, ha_read_key_count), SHOW_LONG_STATUS},
2112
 
  {"Handler_read_next",        (char*) offsetof(STATUS_VAR, ha_read_next_count), SHOW_LONG_STATUS},
2113
 
  {"Handler_read_prev",        (char*) offsetof(STATUS_VAR, ha_read_prev_count), SHOW_LONG_STATUS},
2114
 
  {"Handler_read_rnd",         (char*) offsetof(STATUS_VAR, ha_read_rnd_count), SHOW_LONG_STATUS},
2115
 
  {"Handler_read_rnd_next",    (char*) offsetof(STATUS_VAR, ha_read_rnd_next_count), SHOW_LONG_STATUS},
2116
 
  {"Handler_rollback",         (char*) offsetof(STATUS_VAR, ha_rollback_count), SHOW_LONG_STATUS},
2117
 
  {"Handler_savepoint",        (char*) offsetof(STATUS_VAR, ha_savepoint_count), SHOW_LONG_STATUS},
2118
 
  {"Handler_savepoint_rollback",(char*) offsetof(STATUS_VAR, ha_savepoint_rollback_count), SHOW_LONG_STATUS},
2119
 
  {"Handler_update",           (char*) offsetof(STATUS_VAR, ha_update_count), SHOW_LONG_STATUS},
2120
 
  {"Handler_write",            (char*) offsetof(STATUS_VAR, ha_write_count), SHOW_LONG_STATUS},
2121
 
  {"Key_blocks_not_flushed",   (char*) offsetof(KEY_CACHE, global_blocks_changed), SHOW_KEY_CACHE_LONG},
2122
 
  {"Key_blocks_unused",        (char*) offsetof(KEY_CACHE, blocks_unused), SHOW_KEY_CACHE_LONG},
2123
 
  {"Key_blocks_used",          (char*) offsetof(KEY_CACHE, blocks_used), SHOW_KEY_CACHE_LONG},
2124
 
  {"Key_read_requests",        (char*) offsetof(KEY_CACHE, global_cache_r_requests), SHOW_KEY_CACHE_LONGLONG},
2125
 
  {"Key_reads",                (char*) offsetof(KEY_CACHE, global_cache_read), SHOW_KEY_CACHE_LONGLONG},
2126
 
  {"Key_write_requests",       (char*) offsetof(KEY_CACHE, global_cache_w_requests), SHOW_KEY_CACHE_LONGLONG},
2127
 
  {"Key_writes",               (char*) offsetof(KEY_CACHE, global_cache_write), SHOW_KEY_CACHE_LONGLONG},
2128
 
  {"Last_query_cost",          (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
2129
 
  {"Max_used_connections",     (char*) &max_used_connections,  SHOW_INT},
2130
 
  {"Open_files",               (char*) &my_file_opened,    SHOW_INT_NOFLUSH},
2131
 
  {"Open_streams",             (char*) &my_stream_opened,  SHOW_INT_NOFLUSH},
2132
 
  {"Open_table_definitions",   (char*) &show_table_definitions_cont, SHOW_FUNC},
2133
 
  {"Open_tables",              (char*) &show_open_tables_cont,       SHOW_FUNC},
2134
 
  {"Opened_files",             (char*) &my_file_total_opened, SHOW_INT_NOFLUSH},
2135
 
  {"Opened_tables",            (char*) offsetof(STATUS_VAR, opened_tables), SHOW_LONG_STATUS},
2136
 
  {"Opened_table_definitions", (char*) offsetof(STATUS_VAR, opened_shares), SHOW_LONG_STATUS},
2137
 
  {"Questions",                (char*) offsetof(STATUS_VAR, questions), SHOW_LONG_STATUS},
2138
 
  {"Select_full_join",         (char*) offsetof(STATUS_VAR, select_full_join_count), SHOW_LONG_STATUS},
2139
 
  {"Select_full_range_join",   (char*) offsetof(STATUS_VAR, select_full_range_join_count), SHOW_LONG_STATUS},
2140
 
  {"Select_range",             (char*) offsetof(STATUS_VAR, select_range_count), SHOW_LONG_STATUS},
2141
 
  {"Select_range_check",       (char*) offsetof(STATUS_VAR, select_range_check_count), SHOW_LONG_STATUS},
2142
 
  {"Select_scan",              (char*) offsetof(STATUS_VAR, select_scan_count), SHOW_LONG_STATUS},
2143
 
  {"Slow_queries",             (char*) offsetof(STATUS_VAR, long_query_count), SHOW_LONG_STATUS},
2144
 
  {"Sort_merge_passes",        (char*) offsetof(STATUS_VAR, filesort_merge_passes), SHOW_LONG_STATUS},
2145
 
  {"Sort_range",               (char*) offsetof(STATUS_VAR, filesort_range_count), SHOW_LONG_STATUS},
2146
 
  {"Sort_rows",                (char*) offsetof(STATUS_VAR, filesort_rows), SHOW_LONG_STATUS},
2147
 
  {"Sort_scan",                (char*) offsetof(STATUS_VAR, filesort_scan_count), SHOW_LONG_STATUS},
2148
 
  {"Table_locks_immediate",    (char*) &locks_immediate,        SHOW_INT},
2149
 
  {"Table_locks_waited",       (char*) &locks_waited,           SHOW_INT},
2150
 
  {"Threads_connected",        (char*) &connection_count,       SHOW_INT},
2151
 
  {"Uptime",                   (char*) &show_starttime_cont,         SHOW_FUNC},
2152
 
  {"Uptime_since_flush_status",(char*) &show_flushstatustime_cont,   SHOW_FUNC},
2153
 
  {NULL, NULL, SHOW_LONGLONG}
2154
 
};
2155
 
 
2156
2147
static void print_version(void)
2157
2148
{
2158
2149
  /*
2280
2271
}
2281
2272
 
2282
2273
 
2283
 
bool
 
2274
extern "C" bool
2284
2275
drizzled_get_one_option(int optid, const struct my_option *opt,
2285
2276
                        char *argument)
2286
2277
{
2387
2378
  return 0;
2388
2379
}
2389
2380
 
2390
 
 
2391
2381
extern "C" void option_error_reporter(enum loglevel level, const char *format, ...);
2392
2382
 
2393
 
void option_error_reporter(enum loglevel level, const char *format, ...)
 
2383
extern "C" void option_error_reporter(enum loglevel level, const char *format, ...)
2394
2384
{
2395
2385
  va_list args;
2396
2386
  va_start(args, format);