~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/drizzle_protocol/drizzle_protocol.cc

  • Committer: LinuxJedi
  • Date: 2010-09-01 19:17:03 UTC
  • mto: (1750.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1751.
  • Revision ID: linuxjedi@linuxjedi-laptop-20100901191703-xuvub2vpiglzvxs2
Add data_dictionary table for drizzle protocol status

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
 
58
59
static uint32_t buffer_length;
59
60
static char* bind_address= NULL;
60
61
 
 
62
static plugin::TableFunction* drizzle_status_table_function_ptr= NULL;
 
63
 
61
64
ListenDrizzleProtocol::~ListenDrizzleProtocol()
62
65
{
63
66
  /* This is strdup'd from the options */
96
99
  return new (nothrow) ClientDrizzleProtocol(new_fd, using_mysql41_protocol);
97
100
}
98
101
 
 
102
drizzled::atomic<uint64_t> ClientDrizzleProtocol::connectionCount;
 
103
drizzled::atomic<uint64_t> ClientDrizzleProtocol::failedConnections;
 
104
drizzled::atomic<uint64_t> ClientDrizzleProtocol::connected;
 
105
 
99
106
ClientDrizzleProtocol::ClientDrizzleProtocol(int fd, bool using_mysql41_protocol_arg):
100
107
  using_mysql41_protocol(using_mysql41_protocol_arg)
101
108
{
154
161
  { 
155
162
    drizzleclient_net_close(&net);
156
163
    drizzleclient_net_end(&net);
 
164
    connected.decrement();
157
165
  }
158
166
}
159
167
 
161
169
{
162
170
  bool connection_is_valid;
163
171
 
 
172
  connectionCount.increment();
 
173
  connected.increment();
 
174
 
164
175
  /* Use "connect_timeout" value during connection phase */
165
176
  drizzleclient_net_set_read_timeout(&net, connect_timeout);
166
177
  drizzleclient_net_set_write_timeout(&net, connect_timeout);
172
183
  else
173
184
  {
174
185
    sendError(session->main_da.sql_errno(), session->main_da.message());
 
186
    failedConnections.increment();
175
187
    return false;
176
188
  }
177
189
 
822
834
 
823
835
static int init(module::Context &context)
824
836
{
 
837
  drizzle_status_table_function_ptr= new DrizzleProtocolStatus;
 
838
 
 
839
  context.add(drizzle_status_table_function_ptr);
 
840
 
825
841
  const module::option_map &vm= context.getOptions();
826
842
  if (vm.count("port"))
827
843
  { 
951
967
  NULL
952
968
};
953
969
 
 
970
static int drizzle_protocol_connection_count_func(drizzle_show_var *var, char *buff)
 
971
{
 
972
  var->type= SHOW_LONGLONG;
 
973
  var->value= buff;
 
974
  *((uint64_t *)buff)= ClientDrizzleProtocol::connectionCount;
 
975
  return 0;
 
976
}
 
977
 
 
978
static int drizzle_protocol_connected_count_func(drizzle_show_var *var, char *buff)
 
979
{
 
980
  var->type= SHOW_LONGLONG;
 
981
  var->value= buff;
 
982
  *((uint64_t *)buff)= ClientDrizzleProtocol::connected;
 
983
  return 0;
 
984
}
 
985
 
 
986
static int drizzle_protocol_failed_count_func(drizzle_show_var *var, char *buff)
 
987
{
 
988
  var->type= SHOW_LONGLONG;
 
989
  var->value= buff;
 
990
  *((uint64_t *)buff)= ClientDrizzleProtocol::failedConnections;
 
991
  return 0;
 
992
}
 
993
 
 
994
static st_show_var_func_container drizzle_protocol_connection_count=
 
995
  { &drizzle_protocol_connection_count_func };
 
996
 
 
997
static st_show_var_func_container drizzle_protocol_connected_count=
 
998
  { &drizzle_protocol_connected_count_func };
 
999
 
 
1000
static st_show_var_func_container drizzle_protocol_failed_count=
 
1001
  { &drizzle_protocol_failed_count_func };
 
1002
 
 
1003
static drizzle_show_var drizzle_protocol_status_variables[]= {
 
1004
  {"Connections",
 
1005
  (char*) &drizzle_protocol_connection_count, SHOW_FUNC},
 
1006
  {"Connected",
 
1007
  (char*) &drizzle_protocol_connected_count, SHOW_FUNC},
 
1008
  {"Failed_connections",
 
1009
  (char*) &drizzle_protocol_failed_count, SHOW_FUNC},
 
1010
  {NULL, NULL, SHOW_LONGLONG}
 
1011
};
 
1012
 
 
1013
DrizzleProtocolStatus::Generator::Generator(drizzled::Field **fields) :
 
1014
  plugin::TableFunction::Generator(fields)
 
1015
{
 
1016
  status_var_ptr= drizzle_protocol_status_variables;
 
1017
}
 
1018
 
 
1019
bool DrizzleProtocolStatus::Generator::populate()
 
1020
{
 
1021
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
 
1022
  char * const buff= (char *) &buff_data;
 
1023
  drizzle_show_var tmp;
 
1024
 
 
1025
  if (status_var_ptr->name)
 
1026
  {
 
1027
    std::ostringstream oss;
 
1028
    string return_value;
 
1029
    const char *value;
 
1030
    int type;
 
1031
 
 
1032
    push(status_var_ptr->name);
 
1033
 
 
1034
    if (status_var_ptr->type == SHOW_FUNC)
 
1035
    {
 
1036
      ((mysql_show_var_func)((st_show_var_func_container *)status_var_ptr->value)->func)(&tmp, buff);
 
1037
      value= buff;
 
1038
      type= tmp.type;
 
1039
    }
 
1040
    else
 
1041
    {
 
1042
      value= status_var_ptr->value;
 
1043
      type= status_var_ptr->type;
 
1044
    }
 
1045
 
 
1046
    switch(type)
 
1047
    {
 
1048
    case SHOW_LONGLONG:
 
1049
      oss << *(uint64_t*) value;
 
1050
      return_value= oss.str();
 
1051
      break;
 
1052
    default:
 
1053
      assert(0);
 
1054
    }
 
1055
    if (return_value.length())
 
1056
      push(return_value);
 
1057
    else
 
1058
      push(" ");
 
1059
 
 
1060
    status_var_ptr++;
 
1061
 
 
1062
    return true;
 
1063
  }
 
1064
  return false;
 
1065
}
 
1066
 
954
1067
} /* namespace drizzle_protocol */
955
1068
 
956
1069
DRIZZLE_PLUGIN(drizzle_protocol::init, drizzle_protocol::sys_variables, drizzle_protocol::init_options);