~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

Merged Eric from lp:~eday/drizzle/eday-merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
extern "C" void handle_segfault(int sig);
166
166
 
167
167
using namespace std;
 
168
using namespace drizzled;
168
169
 
169
170
/* Constants */
170
171
 
267
268
uint32_t tc_heuristic_recover= 0;
268
269
uint64_t session_startup_options;
269
270
uint32_t back_log;
270
 
uint32_t connect_timeout;
271
271
uint32_t server_id;
272
272
uint64_t table_cache_size;
273
273
uint64_t table_def_size;
274
274
uint64_t aborted_threads;
275
275
uint64_t aborted_connects;
276
276
uint64_t max_connect_errors;
277
 
uint32_t thread_id=1L;
 
277
uint32_t global_thread_id=1L;
278
278
pid_t current_pid;
279
279
 
280
280
const double log_10[] = {
411
411
 
412
412
static void usage(void);
413
413
static void clean_up_mutexes(void);
414
 
static void create_new_thread(Session *session);
415
414
extern "C" void end_thread_signal(int );
416
415
void close_connections(void);
417
416
extern "C" void print_signal_warning(int sig);
451
450
  */
452
451
 
453
452
  Session *tmp;
454
 
  Scheduler &thread_scheduler= get_thread_scheduler();
455
453
 
456
454
  (void) pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
457
455
 
459
457
  {
460
458
    tmp= *it;
461
459
    tmp->killed= Session::KILL_CONNECTION;
462
 
    thread_scheduler.post_kill_notification(tmp);
 
460
    tmp->scheduler->killSession(tmp);
463
461
    if (tmp->mysys_var)
464
462
    {
465
463
      tmp->mysys_var->abort=1;
768
766
  if (session)
769
767
  {
770
768
    statistic_increment(killed_threads, &LOCK_status);
771
 
    Scheduler &thread_scheduler= get_thread_scheduler();
772
 
    (void)thread_scheduler.end_thread(session, 0);
 
769
    session->scheduler->killSessionNow(session);
773
770
  }
774
 
  return;                               /* purecov: deadcode */
 
771
  return;
775
772
}
776
773
 
777
774
 
858
855
  }
859
856
 
860
857
  localtime_r(&curr_time, &tm);
861
 
  Scheduler &thread_scheduler= get_thread_scheduler();
862
858
  
863
859
  fprintf(stderr,"%02d%02d%02d %2d:%02d:%02d - drizzled got signal %d;\n"
864
860
          "This could be because you hit a bug. It is also possible that "
876
872
          (uint32_t) dflt_key_cache->key_cache_mem_size);
877
873
  fprintf(stderr, "read_buffer_size=%ld\n", (long) global_system_variables.read_buff_size);
878
874
  fprintf(stderr, "max_used_connections=%u\n", max_used_connections);
879
 
  fprintf(stderr, "max_threads=%u\n", thread_scheduler.get_max_threads());
880
 
  fprintf(stderr, "thread_count=%u\n", thread_scheduler.count());
881
875
  fprintf(stderr, "connection_count=%u\n", uint32_t(connection_count));
882
876
  fprintf(stderr, _("It is possible that drizzled could use up to \n"
883
877
                    "key_buffer_size + (read_buffer_size + "
884
 
                    "sort_buffer_size)*max_threads = %"PRIu64" K\n"
 
878
                    "sort_buffer_size)*thread_count\n"
885
879
                    "bytes of memory\n"
886
880
                    "Hope that's ok; if not, decrease some variables in the "
887
 
                    "equation.\n\n"),
888
 
          (uint64_t)(((uint32_t) dflt_key_cache->key_cache_mem_size +
889
 
                     (global_system_variables.read_buff_size +
890
 
                      global_system_variables.sortbuff_size) *
891
 
                     thread_scheduler.get_max_threads()) / 1024));
 
881
                    "equation.\n\n"));
892
882
 
893
883
#ifdef HAVE_STACKTRACE
894
884
  Session *session= current_session;
1493
1483
int main(int argc, char **argv)
1494
1484
{
1495
1485
  ListenHandler listen_handler;
1496
 
  Protocol *protocol;
 
1486
  plugin::Protocol *protocol;
1497
1487
  Session *session;
1498
1488
 
1499
1489
 
1591
1581
      continue;
1592
1582
    }
1593
1583
 
1594
 
    create_new_thread(session);
 
1584
    /* If we error on creation we drop the connection and delete the session. */
 
1585
    if (session->schedule())
 
1586
      unlink_session(session);
1595
1587
  }
1596
1588
 
1597
1589
  /* (void) pthread_attr_destroy(&connection_attrib); */
1615
1607
}
1616
1608
 
1617
1609
 
1618
 
/**
1619
 
  Create new thread to handle incoming connection.
1620
 
 
1621
 
    This function will create new thread to handle the incoming
1622
 
    connection.  If there are idle cached threads one will be used.
1623
 
    'session' will be pushed into 'threads'.
1624
 
 
1625
 
    In single-threaded mode (\#define ONE_THREAD) connection will be
1626
 
    handled inside this function.
1627
 
 
1628
 
  @param[in,out] session    Thread handle of future thread.
1629
 
*/
1630
 
 
1631
 
static void create_new_thread(Session *session)
1632
 
{
1633
 
  Scheduler &thread_scheduler= get_thread_scheduler();
1634
 
 
1635
 
  ++connection_count;
1636
 
 
1637
 
  if (connection_count > max_used_connections)
1638
 
    max_used_connections= connection_count;
1639
 
 
1640
 
  /*
1641
 
    The initialization of thread_id is done in create_embedded_session() for
1642
 
    the embedded library.
1643
 
    TODO: refactor this to avoid code duplication there
1644
 
  */
1645
 
  session->thread_id= session->variables.pseudo_thread_id= thread_id++;
1646
 
 
1647
 
  /* 
1648
 
    If we error on creation we drop the connection and delete the session.
1649
 
  */
1650
 
  pthread_mutex_lock(&LOCK_thread_count);
1651
 
  session_list.push_back(session);
1652
 
  pthread_mutex_unlock(&LOCK_thread_count);
1653
 
  if (thread_scheduler.add_connection(session))
1654
 
  {
1655
 
    char error_message_buff[DRIZZLE_ERRMSG_SIZE];
1656
 
 
1657
 
    session->killed= Session::KILL_CONNECTION;                        // Safety
1658
 
 
1659
 
    statistic_increment(aborted_connects, &LOCK_status);
1660
 
 
1661
 
    /* Can't use my_error() since store_globals has not been called. */
1662
 
    snprintf(error_message_buff, sizeof(error_message_buff), ER(ER_CANT_CREATE_THREAD), 1); /* TODO replace will better error message */
1663
 
    session->protocol->sendError(ER_CANT_CREATE_THREAD, error_message_buff);
1664
 
    unlink_session(session);
1665
 
  }
1666
 
}
1667
 
 
1668
 
 
1669
1610
/****************************************************************************
1670
1611
  Handle start options
1671
1612
******************************************************************************/
1687
1628
  OPT_DO_PSTACK,
1688
1629
  OPT_LOCAL_INFILE,
1689
1630
  OPT_BACK_LOG,
1690
 
  OPT_CONNECT_TIMEOUT,
1691
1631
  OPT_JOIN_BUFF_SIZE,
1692
1632
  OPT_KEY_BUFFER_SIZE, OPT_KEY_CACHE_BLOCK_SIZE,
1693
1633
  OPT_KEY_CACHE_DIVISION_LIMIT, OPT_KEY_CACHE_AGE_THRESHOLD,
1704
1644
  OPT_MYISAM_MAX_SORT_FILE_SIZE, OPT_MYISAM_SORT_BUFFER_SIZE,
1705
1645
  OPT_MYISAM_USE_MMAP, OPT_MYISAM_REPAIR_THREADS,
1706
1646
  OPT_MYISAM_STATS_METHOD,
1707
 
  OPT_NET_BUFFER_LENGTH, OPT_NET_RETRY_COUNT,
1708
 
  OPT_NET_READ_TIMEOUT, OPT_NET_WRITE_TIMEOUT,
 
1647
  OPT_NET_BUFFER_LENGTH,
1709
1648
  OPT_PRELOAD_BUFFER_SIZE,
1710
1649
  OPT_RECORD_BUFFER,
1711
1650
  OPT_RECORD_RND_BUFFER, OPT_DIV_PRECINCREMENT,
1739
1678
};
1740
1679
 
1741
1680
 
1742
 
#define LONG_TIMEOUT ((uint32_t) 3600L*24L*365L)
1743
 
 
1744
1681
struct my_option my_long_options[] =
1745
1682
{
1746
1683
  {"help", '?', N_("Display this help and exit."),
1902
1839
    (char**) &global_system_variables.bulk_insert_buff_size,
1903
1840
    (char**) &max_system_variables.bulk_insert_buff_size,
1904
1841
    0, GET_ULL, REQUIRED_ARG, 8192*1024, 0, ULONG_MAX, 0, 1, 0},
1905
 
  { "connect_timeout", OPT_CONNECT_TIMEOUT,
1906
 
    N_("The number of seconds the drizzled server is waiting for a connect "
1907
 
       "packet before responding with 'Bad handshake'."),
1908
 
    (char**) &connect_timeout, (char**) &connect_timeout,
1909
 
    0, GET_UINT32, REQUIRED_ARG, CONNECT_TIMEOUT, 2, LONG_TIMEOUT, 0, 1, 0 },
1910
1842
  { "div_precision_increment", OPT_DIV_PRECINCREMENT,
1911
1843
   N_("Precision of the result of '/' operator will be increased on that "
1912
1844
      "value."),
2020
1952
   (char**) &global_system_variables.net_buffer_length,
2021
1953
   (char**) &max_system_variables.net_buffer_length, 0, GET_UINT32,
2022
1954
   REQUIRED_ARG, 16384, 1024, 1024*1024L, 0, 1024, 0},
2023
 
  {"net_read_timeout", OPT_NET_READ_TIMEOUT,
2024
 
   N_("Number of seconds to wait for more data from a connection before "
2025
 
      "aborting the read."),
2026
 
   (char**) &global_system_variables.net_read_timeout,
2027
 
   (char**) &max_system_variables.net_read_timeout, 0, GET_UINT32,
2028
 
   REQUIRED_ARG, NET_READ_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
2029
 
  {"net_retry_count", OPT_NET_RETRY_COUNT,
2030
 
   N_("If a read on a communication port is interrupted, retry this many "
2031
 
      "times before giving up."),
2032
 
   (char**) &global_system_variables.net_retry_count,
2033
 
   (char**) &max_system_variables.net_retry_count,0,
2034
 
   GET_UINT32, REQUIRED_ARG, MYSQLD_NET_RETRY_COUNT, 1, ULONG_MAX, 0, 1, 0},
2035
 
  {"net_write_timeout", OPT_NET_WRITE_TIMEOUT,
2036
 
   N_("Number of seconds to wait for a block to be written to a connection "
2037
 
      "before aborting the write."),
2038
 
   (char**) &global_system_variables.net_write_timeout,
2039
 
   (char**) &max_system_variables.net_write_timeout, 0, GET_UINT32,
2040
 
   REQUIRED_ARG, NET_WRITE_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
2041
1955
  {"optimizer_prune_level", OPT_OPTIMIZER_PRUNE_LEVEL,
2042
1956
    N_("Controls the heuristic(s) applied during query optimization to prune "
2043
1957
       "less-promising partial plans from the optimizer search space. Meaning: "
2151
2065
   (char**) &global_system_variables.trans_prealloc_size,
2152
2066
   (char**) &max_system_variables.trans_prealloc_size, 0, GET_UINT,
2153
2067
   REQUIRED_ARG, TRANS_ALLOC_PREALLOC_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
2154
 
  {"wait_timeout", OPT_WAIT_TIMEOUT,
2155
 
   N_("The number of seconds the server waits for activity on a connection "
2156
 
      "before closing it."),
2157
 
   (char**) &global_system_variables.net_wait_timeout,
2158
 
   (char**) &max_system_variables.net_wait_timeout, 0, GET_UINT,
2159
 
   REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, LONG_TIMEOUT,
2160
 
   0, 1, 0},
2161
2068
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
2162
2069
};
2163
2070
 
2214
2121
  {"Bytes_received",           (char*) offsetof(STATUS_VAR, bytes_received), SHOW_LONGLONG_STATUS},
2215
2122
  {"Bytes_sent",               (char*) offsetof(STATUS_VAR, bytes_sent), SHOW_LONGLONG_STATUS},
2216
2123
  {"Com",                      (char*) com_status_vars, SHOW_ARRAY},
2217
 
  {"Connections",              (char*) &thread_id,          SHOW_INT_NOFLUSH},
 
2124
  {"Connections",              (char*) &global_thread_id, SHOW_INT_NOFLUSH},
2218
2125
  {"Created_tmp_disk_tables",  (char*) offsetof(STATUS_VAR, created_tmp_disk_tables), SHOW_LONG_STATUS},
2219
2126
  {"Created_tmp_files",        (char*) &my_tmp_file_created,SHOW_INT},
2220
2127
  {"Created_tmp_tables",       (char*) offsetof(STATUS_VAR, created_tmp_tables), SHOW_LONG_STATUS},
2359
2266
  drizzle_data_home= drizzle_real_data_home;
2360
2267
  session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_SQL_NOTES);
2361
2268
  refresh_version= 1L;  /* Increments on each reload */
2362
 
  thread_id= 1;
 
2269
  global_thread_id= 1;
2363
2270
  myisam_stats_method_str= "nulls_unequal";
2364
2271
  session_list.clear();
2365
2272