~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/mysql_protocol.cc

  • Committer: lbieber
  • Date: 2010-09-09 16:13:46 UTC
  • mfrom: (1750.1.1 build)
  • Revision ID: lbieber@orisndriz03-20100909161346-0peqb2kk4bujlgma
Merge Andrew - fix bug 621603: Connections status variable off by one
Merge Andrew - fix bug 621947: show processlist filldown
Merge Andrew - fix bug 628284: --mysql option broken

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "mysql_protocol.h"
32
32
#include "mysql_password.h"
33
33
#include "options.h"
 
34
#include "table_function.h"
34
35
 
35
36
namespace po= boost::program_options;
36
37
using namespace std;
51
52
static const uint32_t random_max= 0x3FFFFFFF;
52
53
static const double random_max_double= (double)0x3FFFFFFF;
53
54
 
 
55
static plugin::TableFunction* mysql_status_table_function_ptr= NULL;
 
56
 
54
57
ListenMySQLProtocol::~ListenMySQLProtocol()
55
58
{
56
59
  /* This is strdup'd from the options */
77
80
  return new (nothrow) ClientMySQLProtocol(new_fd, using_mysql41_protocol);
78
81
}
79
82
 
 
83
drizzled::atomic<uint64_t> ClientMySQLProtocol::connectionCount;
 
84
drizzled::atomic<uint64_t> ClientMySQLProtocol::failedConnections;
 
85
drizzled::atomic<uint64_t> ClientMySQLProtocol::connected;
 
86
 
80
87
ClientMySQLProtocol::ClientMySQLProtocol(int fd, bool using_mysql41_protocol_arg):
81
88
  using_mysql41_protocol(using_mysql41_protocol_arg)
82
89
{
135
142
  { 
136
143
    drizzleclient_net_close(&net);
137
144
    drizzleclient_net_end(&net);
 
145
    connected.decrement();
138
146
  }
139
147
}
140
148
 
142
150
{
143
151
  bool connection_is_valid;
144
152
 
 
153
  connectionCount.increment();
 
154
  connected.increment();
 
155
 
145
156
  /* Use "connect_timeout" value during connection phase */
146
157
  drizzleclient_net_set_read_timeout(&net, connect_timeout);
147
158
  drizzleclient_net_set_write_timeout(&net, connect_timeout);
153
164
  else
154
165
  {
155
166
    sendError(session->main_da.sql_errno(), session->main_da.message());
 
167
    failedConnections.increment();
156
168
    return false;
157
169
  }
158
 
 
159
170
  /* Connect completed, set read/write timeouts back to default */
160
171
  drizzleclient_net_set_read_timeout(&net, read_timeout);
161
172
  drizzleclient_net_set_write_timeout(&net, write_timeout);
886
897
 
887
898
static int init(drizzled::module::Context &context)
888
899
{  
 
900
  mysql_status_table_function_ptr= new MysqlProtocolStatus;
889
901
 
 
902
  context.add(mysql_status_table_function_ptr);
890
903
  /* Initialize random seeds for the MySQL algorithm with minimal changes. */
891
904
  time_t seed_time= time(NULL);
892
905
  random_seed1= seed_time % random_max;
1022
1035
  NULL
1023
1036
};
1024
1037
 
 
1038
static int mysql_protocol_connection_count_func(drizzle_show_var *var, char *buff)
 
1039
{
 
1040
  var->type= SHOW_LONGLONG;
 
1041
  var->value= buff;
 
1042
  *((uint64_t *)buff)= ClientMySQLProtocol::connectionCount;
 
1043
  return 0;
 
1044
}
 
1045
 
 
1046
static int mysql_protocol_connected_count_func(drizzle_show_var *var, char *buff)
 
1047
{
 
1048
  var->type= SHOW_LONGLONG;
 
1049
  var->value= buff;
 
1050
  *((uint64_t *)buff)= ClientMySQLProtocol::connected;
 
1051
  return 0;
 
1052
}
 
1053
 
 
1054
static int mysql_protocol_failed_count_func(drizzle_show_var *var, char *buff)
 
1055
{
 
1056
  var->type= SHOW_LONGLONG;
 
1057
  var->value= buff;
 
1058
  *((uint64_t *)buff)= ClientMySQLProtocol::failedConnections;
 
1059
  return 0;
 
1060
}
 
1061
 
 
1062
static st_show_var_func_container mysql_protocol_connection_count=
 
1063
  { &mysql_protocol_connection_count_func };
 
1064
 
 
1065
static st_show_var_func_container mysql_protocol_connected_count=
 
1066
  { &mysql_protocol_connected_count_func };
 
1067
 
 
1068
static st_show_var_func_container mysql_protocol_failed_count=
 
1069
  { &mysql_protocol_failed_count_func };
 
1070
 
 
1071
static drizzle_show_var mysql_protocol_status_variables[]= {
 
1072
  {"Connections",
 
1073
  (char*) &mysql_protocol_connection_count, SHOW_FUNC},
 
1074
  {"Connected",
 
1075
  (char*) &mysql_protocol_connected_count, SHOW_FUNC},
 
1076
  {"Failed_connections",
 
1077
  (char*) &mysql_protocol_failed_count, SHOW_FUNC},
 
1078
  {NULL, NULL, SHOW_LONGLONG}
 
1079
};
 
1080
 
 
1081
MysqlProtocolStatus::Generator::Generator(drizzled::Field **fields) :
 
1082
  plugin::TableFunction::Generator(fields)
 
1083
{
 
1084
  status_var_ptr= mysql_protocol_status_variables;
 
1085
}
 
1086
 
 
1087
bool MysqlProtocolStatus::Generator::populate()
 
1088
{
 
1089
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
 
1090
  char * const buff= (char *) &buff_data;
 
1091
  drizzle_show_var tmp;
 
1092
 
 
1093
  if (status_var_ptr->name)
 
1094
  {
 
1095
    std::ostringstream oss;
 
1096
    string return_value;
 
1097
    const char *value;
 
1098
    int type;
 
1099
 
 
1100
    push(status_var_ptr->name);
 
1101
 
 
1102
    if (status_var_ptr->type == SHOW_FUNC)
 
1103
    {
 
1104
      ((mysql_show_var_func)((st_show_var_func_container *)status_var_ptr->value)->func)(&tmp, buff);
 
1105
      value= buff;
 
1106
      type= tmp.type;
 
1107
    }
 
1108
    else
 
1109
    {
 
1110
      value= status_var_ptr->value;
 
1111
      type= status_var_ptr->type;
 
1112
    }
 
1113
 
 
1114
    switch(type)
 
1115
    {
 
1116
    case SHOW_LONGLONG:
 
1117
      oss << *(uint64_t*) value;
 
1118
      return_value= oss.str();
 
1119
      break;
 
1120
    default:
 
1121
      assert(0);
 
1122
    }
 
1123
    if (return_value.length())
 
1124
      push(return_value);
 
1125
    else
 
1126
      push(" ");
 
1127
 
 
1128
    status_var_ptr++;
 
1129
 
 
1130
    return true;
 
1131
  }
 
1132
  return false;
 
1133
}
 
1134
 
1025
1135
DRIZZLE_DECLARE_PLUGIN
1026
1136
{
1027
1137
  DRIZZLE_VERSION_ID,