~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
770
768
  if (session)
771
769
  {
772
770
    statistic_increment(killed_threads, &LOCK_status);
773
 
    Scheduler &thread_scheduler= get_thread_scheduler();
774
 
    (void)thread_scheduler.end_thread(session, 0);
 
771
    session->scheduler->killSessionNow(session);
775
772
  }
776
 
  return;                               /* purecov: deadcode */
 
773
  return;
777
774
}
778
775
 
779
776
 
860
857
  }
861
858
 
862
859
  localtime_r(&curr_time, &tm);
863
 
  Scheduler &thread_scheduler= get_thread_scheduler();
864
860
  
865
861
  fprintf(stderr,"%02d%02d%02d %2d:%02d:%02d - drizzled got signal %d;\n"
866
862
          "This could be because you hit a bug. It is also possible that "
878
874
          (uint32_t) dflt_key_cache->key_cache_mem_size);
879
875
  fprintf(stderr, "read_buffer_size=%ld\n", (long) global_system_variables.read_buff_size);
880
876
  fprintf(stderr, "max_used_connections=%u\n", max_used_connections);
881
 
  fprintf(stderr, "max_threads=%u\n", thread_scheduler.get_max_threads());
882
 
  fprintf(stderr, "thread_count=%u\n", thread_scheduler.count());
883
877
  fprintf(stderr, "connection_count=%u\n", uint32_t(connection_count));
884
878
  fprintf(stderr, _("It is possible that drizzled could use up to \n"
885
879
                    "key_buffer_size + (read_buffer_size + "
886
 
                    "sort_buffer_size)*max_threads = %"PRIu64" K\n"
 
880
                    "sort_buffer_size)*thread_count\n"
887
881
                    "bytes of memory\n"
888
882
                    "Hope that's ok; if not, decrease some variables in the "
889
 
                    "equation.\n\n"),
890
 
          (uint64_t)(((uint32_t) dflt_key_cache->key_cache_mem_size +
891
 
                     (global_system_variables.read_buff_size +
892
 
                      global_system_variables.sortbuff_size) *
893
 
                     thread_scheduler.get_max_threads()) / 1024));
 
883
                    "equation.\n\n"));
894
884
 
895
885
#ifdef HAVE_STACKTRACE
896
886
  Session *session= current_session;
1601
1591
      continue;
1602
1592
    }
1603
1593
 
1604
 
    create_new_thread(session);
 
1594
    /* If we error on creation we drop the connection and delete the session. */
 
1595
    if (session->schedule())
 
1596
      unlink_session(session);
1605
1597
  }
1606
1598
 
1607
1599
  /* (void) pthread_attr_destroy(&connection_attrib); */
1625
1617
}
1626
1618
 
1627
1619
 
1628
 
/**
1629
 
  Create new thread to handle incoming connection.
1630
 
 
1631
 
    This function will create new thread to handle the incoming
1632
 
    connection.  If there are idle cached threads one will be used.
1633
 
    'session' will be pushed into 'threads'.
1634
 
 
1635
 
    In single-threaded mode (\#define ONE_THREAD) connection will be
1636
 
    handled inside this function.
1637
 
 
1638
 
  @param[in,out] session    Thread handle of future thread.
1639
 
*/
1640
 
 
1641
 
static void create_new_thread(Session *session)
1642
 
{
1643
 
  Scheduler &thread_scheduler= get_thread_scheduler();
1644
 
 
1645
 
  ++connection_count;
1646
 
 
1647
 
  if (connection_count > max_used_connections)
1648
 
    max_used_connections= connection_count;
1649
 
 
1650
 
  /*
1651
 
    The initialization of thread_id is done in create_embedded_session() for
1652
 
    the embedded library.
1653
 
    TODO: refactor this to avoid code duplication there
1654
 
  */
1655
 
  session->thread_id= session->variables.pseudo_thread_id= thread_id++;
1656
 
 
1657
 
  /* 
1658
 
    If we error on creation we drop the connection and delete the session.
1659
 
  */
1660
 
  pthread_mutex_lock(&LOCK_thread_count);
1661
 
  session_list.push_back(session);
1662
 
  pthread_mutex_unlock(&LOCK_thread_count);
1663
 
  if (thread_scheduler.add_connection(session))
1664
 
  {
1665
 
    char error_message_buff[DRIZZLE_ERRMSG_SIZE];
1666
 
 
1667
 
    session->killed= Session::KILL_CONNECTION;                        // Safety
1668
 
 
1669
 
    statistic_increment(aborted_connects, &LOCK_status);
1670
 
 
1671
 
    /* Can't use my_error() since store_globals has not been called. */
1672
 
    snprintf(error_message_buff, sizeof(error_message_buff), ER(ER_CANT_CREATE_THREAD), 1); /* TODO replace will better error message */
1673
 
    session->protocol->sendError(ER_CANT_CREATE_THREAD, error_message_buff);
1674
 
    unlink_session(session);
1675
 
  }
1676
 
}
1677
 
 
1678
 
 
1679
1620
/****************************************************************************
1680
1621
  Handle start options
1681
1622
******************************************************************************/