~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/mysql_protocol.cc

Merge Andrew - First part of admin client blueprint. Add max-connections per-protocol 

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
static const double random_max_double= (double)0x3FFFFFFF;
58
58
 
59
59
 
 
60
ProtocolCounters *ListenMySQLProtocol::mysql_counters= new ProtocolCounters();
 
61
 
60
62
ListenMySQLProtocol::~ListenMySQLProtocol()
61
63
{ }
62
64
 
77
79
  if (new_fd == -1)
78
80
    return NULL;
79
81
 
80
 
  return new ClientMySQLProtocol(new_fd, _using_mysql41_protocol);
 
82
  return new ClientMySQLProtocol(new_fd, _using_mysql41_protocol, getCounters());
81
83
}
82
84
 
83
 
drizzled::atomic<uint64_t> ClientMySQLProtocol::connectionCount;
84
 
drizzled::atomic<uint64_t> ClientMySQLProtocol::failedConnections;
85
 
drizzled::atomic<uint64_t> ClientMySQLProtocol::connected;
86
 
 
87
 
ClientMySQLProtocol::ClientMySQLProtocol(int fd, bool using_mysql41_protocol):
88
 
  _using_mysql41_protocol(using_mysql41_protocol)
 
85
ClientMySQLProtocol::ClientMySQLProtocol(int fd, bool using_mysql41_protocol, ProtocolCounters *set_counters):
 
86
  _using_mysql41_protocol(using_mysql41_protocol),
 
87
  counters(set_counters)
89
88
{
90
89
  
91
90
  net.vio= 0;
143
142
  { 
144
143
    drizzleclient_net_close(&net);
145
144
    drizzleclient_net_end(&net);
146
 
    connected.decrement();
 
145
    counters->connected.decrement();
147
146
  }
148
147
}
149
148
 
151
150
{
152
151
  bool connection_is_valid;
153
152
 
154
 
  connectionCount.increment();
155
 
  connected.increment();
 
153
  counters->connectionCount.increment();
 
154
  counters->connected.increment();
156
155
 
157
156
  /* Use "connect_timeout" value during connection phase */
158
157
  drizzleclient_net_set_read_timeout(&net, connect_timeout.get());
161
160
  connection_is_valid= checkConnection();
162
161
 
163
162
  if (connection_is_valid)
164
 
    sendOK();
 
163
    if (counters->connected > counters->max_connections)
 
164
    {
 
165
      std::string errmsg(ER(ER_CON_COUNT_ERROR));
 
166
      sendError(ER_CON_COUNT_ERROR, errmsg.c_str());
 
167
    }
 
168
    else
 
169
      sendOK();
165
170
  else
166
171
  {
167
172
    sendError(session->main_da.sql_errno(), session->main_da.message());
168
 
    failedConnections.increment();
 
173
    counters->failedConnections.increment();
169
174
    return false;
170
175
  }
 
176
 
171
177
  /* Connect completed, set read/write timeouts back to default */
172
178
  drizzleclient_net_set_read_timeout(&net, read_timeout.get());
173
179
  drizzleclient_net_set_write_timeout(&net, write_timeout.get());
923
929
  context.registerVariable(new sys_var_const_string_val("bind_address",
924
930
                                                        vm["bind-address"].as<std::string>()));
925
931
 
 
932
  context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &ListenMySQLProtocol::mysql_counters->max_connections));
 
933
 
926
934
  return 0;
927
935
}
928
936
 
950
958
  context("bind-address",
951
959
          po::value<string>()->default_value(""),
952
960
          N_("Address to bind to."));
 
961
  context("max-connections",
 
962
          po::value<uint32_t>(&ListenMySQLProtocol::mysql_counters->max_connections)->default_value(1000),
 
963
          N_("Maximum simultaneous connections."));
953
964
}
954
965
 
955
966
static int mysql_protocol_connection_count_func(drizzle_show_var *var, char *buff)
956
967
{
957
968
  var->type= SHOW_LONGLONG;
958
969
  var->value= buff;
959
 
  *((uint64_t *)buff)= ClientMySQLProtocol::connectionCount;
 
970
  *((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->connectionCount;
960
971
  return 0;
961
972
}
962
973
 
964
975
{
965
976
  var->type= SHOW_LONGLONG;
966
977
  var->value= buff;
967
 
  *((uint64_t *)buff)= ClientMySQLProtocol::connected;
 
978
  *((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->connected;
968
979
  return 0;
969
980
}
970
981
 
972
983
{
973
984
  var->type= SHOW_LONGLONG;
974
985
  var->value= buff;
975
 
  *((uint64_t *)buff)= ClientMySQLProtocol::failedConnections;
 
986
  *((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->failedConnections;
976
987
  return 0;
977
988
}
978
989