~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

Refactoring of the drizzle client.

Show diffs side-by-side

added added

removed removed

Lines of Context:
313
313
 
314
314
struct system_variables global_system_variables;
315
315
struct system_variables max_system_variables;
 
316
struct system_status_var global_status_var;
316
317
struct global_counters current_global_counters;
317
318
 
318
319
const CHARSET_INFO *system_charset_info, *files_charset_info ;
365
366
static void drizzle_init_variables(void);
366
367
static void get_options(int *argc,char **argv);
367
368
int drizzled_get_one_option(int, const struct option *, char *);
 
369
static int init_thread_environment();
368
370
static const char *get_relative_path(const char *path);
369
371
static void fix_paths(string &progname);
370
372
 
501
503
  module::Registry &modules= module::Registry::singleton();
502
504
  modules.shutdownModules();
503
505
  xid_cache_free();
 
506
  free_status_vars();
504
507
  if (defaults_argv)
505
508
    internal::free_defaults(defaults_argv);
506
509
  if (opt_secure_file_priv)
675
678
}
676
679
 
677
680
 
 
681
#ifdef THREAD_SPECIFIC_SIGPIPE
 
682
/**
 
683
 
 
684
  @todo
 
685
    One should have to fix that thr_alarm know about this thread too.
 
686
*/
 
687
extern "C" void abort_thread(int )
 
688
{
 
689
  Session *session=current_session;
 
690
  if (session)
 
691
    session->killed= Session::KILL_CONNECTION;
 
692
  return;;
 
693
}
 
694
#endif
 
695
 
 
696
 
678
697
#ifndef SA_RESETHAND
679
698
#define SA_RESETHAND 0
680
699
#endif
690
709
  DRIZZLE_CONFIG_NAME, "server", 0, 0
691
710
};
692
711
 
 
712
static int show_starttime(drizzle_show_var *var, char *buff)
 
713
{
 
714
  var->type= SHOW_LONG;
 
715
  var->value= buff;
 
716
  *((long *)buff)= (long) (time(NULL) - server_start_time);
 
717
  return 0;
 
718
}
 
719
 
 
720
static int show_flushstatustime(drizzle_show_var *var, char *buff)
 
721
{
 
722
  var->type= SHOW_LONG;
 
723
  var->value= buff;
 
724
  *((long *)buff)= (long) (time(NULL) - flush_status_time);
 
725
  return 0;
 
726
}
 
727
 
 
728
static st_show_var_func_container show_starttime_cont= { &show_starttime };
 
729
 
 
730
static st_show_var_func_container show_flushstatustime_cont= { &show_flushstatustime };
 
731
 
 
732
static drizzle_show_var status_vars[]= {
 
733
  {"Aborted_clients",          (char*) &current_global_counters.aborted_threads, SHOW_LONGLONG},
 
734
  {"Aborted_connects",         (char*) &current_global_counters.aborted_connects, SHOW_LONGLONG},
 
735
  {"Bytes_received",           (char*) offsetof(system_status_var, bytes_received), SHOW_LONGLONG_STATUS},
 
736
  {"Bytes_sent",               (char*) offsetof(system_status_var, bytes_sent), SHOW_LONGLONG_STATUS},
 
737
  {"Connections",              (char*) &global_thread_id, SHOW_INT_NOFLUSH},
 
738
  {"Created_tmp_disk_tables",  (char*) offsetof(system_status_var, created_tmp_disk_tables), SHOW_LONG_STATUS},
 
739
  {"Created_tmp_tables",       (char*) offsetof(system_status_var, created_tmp_tables), SHOW_LONG_STATUS},
 
740
  {"Flush_commands",           (char*) &refresh_version,    SHOW_INT_NOFLUSH},
 
741
  {"Handler_commit",           (char*) offsetof(system_status_var, ha_commit_count), SHOW_LONG_STATUS},
 
742
  {"Handler_delete",           (char*) offsetof(system_status_var, ha_delete_count), SHOW_LONG_STATUS},
 
743
  {"Handler_prepare",          (char*) offsetof(system_status_var, ha_prepare_count),  SHOW_LONG_STATUS},
 
744
  {"Handler_read_first",       (char*) offsetof(system_status_var, ha_read_first_count), SHOW_LONG_STATUS},
 
745
  {"Handler_read_key",         (char*) offsetof(system_status_var, ha_read_key_count), SHOW_LONG_STATUS},
 
746
  {"Handler_read_next",        (char*) offsetof(system_status_var, ha_read_next_count), SHOW_LONG_STATUS},
 
747
  {"Handler_read_prev",        (char*) offsetof(system_status_var, ha_read_prev_count), SHOW_LONG_STATUS},
 
748
  {"Handler_read_rnd",         (char*) offsetof(system_status_var, ha_read_rnd_count), SHOW_LONG_STATUS},
 
749
  {"Handler_read_rnd_next",    (char*) offsetof(system_status_var, ha_read_rnd_next_count), SHOW_LONG_STATUS},
 
750
  {"Handler_rollback",         (char*) offsetof(system_status_var, ha_rollback_count), SHOW_LONG_STATUS},
 
751
  {"Handler_savepoint",        (char*) offsetof(system_status_var, ha_savepoint_count), SHOW_LONG_STATUS},
 
752
  {"Handler_savepoint_rollback",(char*) offsetof(system_status_var, ha_savepoint_rollback_count), SHOW_LONG_STATUS},
 
753
  {"Handler_update",           (char*) offsetof(system_status_var, ha_update_count), SHOW_LONG_STATUS},
 
754
  {"Handler_write",            (char*) offsetof(system_status_var, ha_write_count), SHOW_LONG_STATUS},
 
755
  {"Key_blocks_not_flushed",   (char*) offsetof(KEY_CACHE, global_blocks_changed), SHOW_KEY_CACHE_LONG},
 
756
  {"Key_blocks_unused",        (char*) offsetof(KEY_CACHE, blocks_unused), SHOW_KEY_CACHE_LONG},
 
757
  {"Key_blocks_used",          (char*) offsetof(KEY_CACHE, blocks_used), SHOW_KEY_CACHE_LONG},
 
758
  {"Key_read_requests",        (char*) offsetof(KEY_CACHE, global_cache_r_requests), SHOW_KEY_CACHE_LONGLONG},
 
759
  {"Key_reads",                (char*) offsetof(KEY_CACHE, global_cache_read), SHOW_KEY_CACHE_LONGLONG},
 
760
  {"Key_write_requests",       (char*) offsetof(KEY_CACHE, global_cache_w_requests), SHOW_KEY_CACHE_LONGLONG},
 
761
  {"Key_writes",               (char*) offsetof(KEY_CACHE, global_cache_write), SHOW_KEY_CACHE_LONGLONG},
 
762
  {"Last_query_cost",          (char*) offsetof(system_status_var, last_query_cost), SHOW_DOUBLE_STATUS},
 
763
  {"Max_used_connections",     (char*) &current_global_counters.max_used_connections,  SHOW_INT},
 
764
  {"Questions",                (char*) offsetof(system_status_var, questions), SHOW_LONG_STATUS},
 
765
  {"Select_full_join",         (char*) offsetof(system_status_var, select_full_join_count), SHOW_LONG_STATUS},
 
766
  {"Select_full_range_join",   (char*) offsetof(system_status_var, select_full_range_join_count), SHOW_LONG_STATUS},
 
767
  {"Select_range",             (char*) offsetof(system_status_var, select_range_count), SHOW_LONG_STATUS},
 
768
  {"Select_range_check",       (char*) offsetof(system_status_var, select_range_check_count), SHOW_LONG_STATUS},
 
769
  {"Select_scan",              (char*) offsetof(system_status_var, select_scan_count), SHOW_LONG_STATUS},
 
770
  {"Slow_queries",             (char*) offsetof(system_status_var, long_query_count), SHOW_LONG_STATUS},
 
771
  {"Sort_merge_passes",        (char*) offsetof(system_status_var, filesort_merge_passes), SHOW_LONG_STATUS},
 
772
  {"Sort_range",               (char*) offsetof(system_status_var, filesort_range_count), SHOW_LONG_STATUS},
 
773
  {"Sort_rows",                (char*) offsetof(system_status_var, filesort_rows), SHOW_LONG_STATUS},
 
774
  {"Sort_scan",                (char*) offsetof(system_status_var, filesort_scan_count), SHOW_LONG_STATUS},
 
775
  {"Table_locks_immediate",    (char*) &current_global_counters.locks_immediate,        SHOW_INT},
 
776
  {"Table_locks_waited",       (char*) &current_global_counters.locks_waited,           SHOW_INT},
 
777
  {"Threads_connected",        (char*) &connection_count,       SHOW_INT},
 
778
  {"Uptime",                   (char*) &show_starttime_cont,         SHOW_FUNC},
 
779
  {"Uptime_since_flush_status",(char*) &show_flushstatustime_cont,   SHOW_FUNC},
 
780
  {NULL, NULL, SHOW_LONGLONG}
 
781
};
 
782
 
693
783
int init_common_variables(const char *conf_file_name, int argc,
694
784
                          char **argv, const char **groups)
695
785
{
735
825
    strncpy(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
736
826
  strcpy(internal::fn_ext(pidfile_name),".pid");                // Add proper extension
737
827
 
 
828
  if (add_status_vars(status_vars))
 
829
    return 1; // an error was already reported
 
830
 
738
831
  internal::load_defaults(conf_file_name, groups, &argc, &argv);
739
832
  defaults_argv=argv;
740
833
  defaults_argc=argc;
797
890
}
798
891
 
799
892
 
800
 
int init_thread_environment()
 
893
static int init_thread_environment()
801
894
{
802
895
   pthread_mutexattr_t attr; 
803
896
   pthread_mutexattr_init(&attr);
1421
1514
  abort_loop= select_thread_in_use= false;
1422
1515
  ready_to_exit= shutdown_in_progress= 0;
1423
1516
  drizzled_user= drizzled_chroot= 0;
 
1517
  memset(&global_status_var, 0, sizeof(global_status_var));
1424
1518
  memset(&current_global_counters, 0, sizeof(current_global_counters));
1425
1519
  key_map_full.set();
1426
1520
 
1589
1683
  /* Don't print warnings for --loose options during bootstrap */
1590
1684
  if (level == ERROR_LEVEL || global_system_variables.log_warnings)
1591
1685
  {
1592
 
    plugin::ErrorMessage::vprintf(NULL, ERROR_LEVEL, format, args);
 
1686
    plugin::ErrorMessage::vprintf(current_session, ERROR_LEVEL, format, args);
1593
1687
  }
1594
1688
  va_end(args);
1595
1689
}