~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/drizzle_protocol/drizzle_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:
33
33
#include "errmsg.h"
34
34
#include "drizzle_protocol.h"
35
35
#include "options.h"
 
36
#include "table_function.h"
36
37
 
37
38
#define PROTOCOL_VERSION 10
38
39
 
54
55
static uint32_t buffer_length;
55
56
static char* bind_address= NULL;
56
57
 
 
58
static plugin::TableFunction* drizzle_status_table_function_ptr= NULL;
 
59
 
57
60
ListenDrizzleProtocol::~ListenDrizzleProtocol()
58
61
{
59
62
  /* This is strdup'd from the options */
92
95
  return new (nothrow) ClientDrizzleProtocol(new_fd, using_mysql41_protocol);
93
96
}
94
97
 
 
98
drizzled::atomic<uint64_t> ClientDrizzleProtocol::connectionCount;
 
99
drizzled::atomic<uint64_t> ClientDrizzleProtocol::failedConnections;
 
100
drizzled::atomic<uint64_t> ClientDrizzleProtocol::connected;
 
101
 
95
102
ClientDrizzleProtocol::ClientDrizzleProtocol(int fd, bool using_mysql41_protocol_arg):
96
103
  using_mysql41_protocol(using_mysql41_protocol_arg)
97
104
{
150
157
  { 
151
158
    drizzleclient_net_close(&net);
152
159
    drizzleclient_net_end(&net);
 
160
    connected.decrement();
153
161
  }
154
162
}
155
163
 
157
165
{
158
166
  bool connection_is_valid;
159
167
 
 
168
  connectionCount.increment();
 
169
  connected.increment();
 
170
 
160
171
  /* Use "connect_timeout" value during connection phase */
161
172
  drizzleclient_net_set_read_timeout(&net, connect_timeout);
162
173
  drizzleclient_net_set_write_timeout(&net, connect_timeout);
168
179
  else
169
180
  {
170
181
    sendError(session->main_da.sql_errno(), session->main_da.message());
 
182
    failedConnections.increment();
171
183
    return false;
172
184
  }
173
185
 
818
830
 
819
831
static int init(module::Context &context)
820
832
{
 
833
  drizzle_status_table_function_ptr= new DrizzleProtocolStatus;
 
834
 
 
835
  context.add(drizzle_status_table_function_ptr);
 
836
 
821
837
  const module::option_map &vm= context.getOptions();
822
838
  if (vm.count("port"))
823
839
  { 
947
963
  NULL
948
964
};
949
965
 
 
966
static int drizzle_protocol_connection_count_func(drizzle_show_var *var, char *buff)
 
967
{
 
968
  var->type= SHOW_LONGLONG;
 
969
  var->value= buff;
 
970
  *((uint64_t *)buff)= ClientDrizzleProtocol::connectionCount;
 
971
  return 0;
 
972
}
 
973
 
 
974
static int drizzle_protocol_connected_count_func(drizzle_show_var *var, char *buff)
 
975
{
 
976
  var->type= SHOW_LONGLONG;
 
977
  var->value= buff;
 
978
  *((uint64_t *)buff)= ClientDrizzleProtocol::connected;
 
979
  return 0;
 
980
}
 
981
 
 
982
static int drizzle_protocol_failed_count_func(drizzle_show_var *var, char *buff)
 
983
{
 
984
  var->type= SHOW_LONGLONG;
 
985
  var->value= buff;
 
986
  *((uint64_t *)buff)= ClientDrizzleProtocol::failedConnections;
 
987
  return 0;
 
988
}
 
989
 
 
990
static st_show_var_func_container drizzle_protocol_connection_count=
 
991
  { &drizzle_protocol_connection_count_func };
 
992
 
 
993
static st_show_var_func_container drizzle_protocol_connected_count=
 
994
  { &drizzle_protocol_connected_count_func };
 
995
 
 
996
static st_show_var_func_container drizzle_protocol_failed_count=
 
997
  { &drizzle_protocol_failed_count_func };
 
998
 
 
999
static drizzle_show_var drizzle_protocol_status_variables[]= {
 
1000
  {"Connections",
 
1001
  (char*) &drizzle_protocol_connection_count, SHOW_FUNC},
 
1002
  {"Connected",
 
1003
  (char*) &drizzle_protocol_connected_count, SHOW_FUNC},
 
1004
  {"Failed_connections",
 
1005
  (char*) &drizzle_protocol_failed_count, SHOW_FUNC},
 
1006
  {NULL, NULL, SHOW_LONGLONG}
 
1007
};
 
1008
 
 
1009
DrizzleProtocolStatus::Generator::Generator(drizzled::Field **fields) :
 
1010
  plugin::TableFunction::Generator(fields)
 
1011
{
 
1012
  status_var_ptr= drizzle_protocol_status_variables;
 
1013
}
 
1014
 
 
1015
bool DrizzleProtocolStatus::Generator::populate()
 
1016
{
 
1017
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
 
1018
  char * const buff= (char *) &buff_data;
 
1019
  drizzle_show_var tmp;
 
1020
 
 
1021
  if (status_var_ptr->name)
 
1022
  {
 
1023
    std::ostringstream oss;
 
1024
    string return_value;
 
1025
    const char *value;
 
1026
    int type;
 
1027
 
 
1028
    push(status_var_ptr->name);
 
1029
 
 
1030
    if (status_var_ptr->type == SHOW_FUNC)
 
1031
    {
 
1032
      ((mysql_show_var_func)((st_show_var_func_container *)status_var_ptr->value)->func)(&tmp, buff);
 
1033
      value= buff;
 
1034
      type= tmp.type;
 
1035
    }
 
1036
    else
 
1037
    {
 
1038
      value= status_var_ptr->value;
 
1039
      type= status_var_ptr->type;
 
1040
    }
 
1041
 
 
1042
    switch(type)
 
1043
    {
 
1044
    case SHOW_LONGLONG:
 
1045
      oss << *(uint64_t*) value;
 
1046
      return_value= oss.str();
 
1047
      break;
 
1048
    default:
 
1049
      assert(0);
 
1050
    }
 
1051
    if (return_value.length())
 
1052
      push(return_value);
 
1053
    else
 
1054
      push(" ");
 
1055
 
 
1056
    status_var_ptr++;
 
1057
 
 
1058
    return true;
 
1059
  }
 
1060
  return false;
 
1061
}
 
1062
 
950
1063
} /* namespace drizzle_protocol */
951
1064
 
952
1065
DRIZZLE_PLUGIN(drizzle_protocol::init, drizzle_protocol::sys_variables, drizzle_protocol::init_options);