26
26
#include "drizzled/internal/my_sys.h"
27
27
#include "drizzled/internal/m_string.h"
28
28
#include <algorithm>
30
#include <boost/program_options.hpp>
31
#include <drizzled/module/option_map.h>
31
33
#include "errmsg.h"
32
34
#include "drizzle_protocol.h"
33
35
#include "options.h"
36
#include "table_function.h"
35
38
#define PROTOCOL_VERSION 10
39
extern uint32_t global_thread_id;
40
namespace po= boost::program_options;
42
41
using namespace drizzled;
43
42
using namespace std;
54
53
static uint32_t write_timeout;
55
54
static uint32_t retry_count;
56
55
static uint32_t buffer_length;
57
static char* bind_address;
56
static char* bind_address= NULL;
58
static plugin::TableFunction* drizzle_status_table_function_ptr= NULL;
60
ListenDrizzleProtocol::~ListenDrizzleProtocol()
62
/* This is strdup'd from the options */
59
66
const char* ListenDrizzleProtocol::getHost(void) const
88
95
return new (nothrow) ClientDrizzleProtocol(new_fd, using_mysql41_protocol);
98
drizzled::atomic<uint64_t> ClientDrizzleProtocol::connectionCount;
99
drizzled::atomic<uint64_t> ClientDrizzleProtocol::failedConnections;
100
drizzled::atomic<uint64_t> ClientDrizzleProtocol::connected;
91
102
ClientDrizzleProtocol::ClientDrizzleProtocol(int fd, bool using_mysql41_protocol_arg):
92
103
using_mysql41_protocol(using_mysql41_protocol_arg)
154
166
bool connection_is_valid;
168
connectionCount.increment();
169
connected.increment();
156
171
/* Use "connect_timeout" value during connection phase */
157
172
drizzleclient_net_set_read_timeout(&net, connect_timeout);
158
173
drizzleclient_net_set_write_timeout(&net, connect_timeout);
663
679
server_capabilites|= CLIENT_COMPRESS;
664
680
#endif /* HAVE_COMPRESS */
666
end= buff + strlen(VERSION);
682
end= buff + strlen(PANDORA_RELEASE_VERSION);
667
683
if ((end - buff) >= SERVER_VERSION_LENGTH)
668
684
end= buff + (SERVER_VERSION_LENGTH - 1);
669
memcpy(buff, VERSION, end - buff);
685
memcpy(buff, PANDORA_RELEASE_VERSION, end - buff);
673
int4store((unsigned char*) end, global_thread_id);
689
int4store((unsigned char*) end, session->variables.pseudo_thread_id);
676
692
/* We don't use scramble anymore. */
812
828
drizzleclient_net_write(&net, buff, 5);
815
static ListenDrizzleProtocol *listen_obj= NULL;
817
static int init(plugin::Registry ®istry)
819
listen_obj= new ListenDrizzleProtocol("drizzle_protocol", false);
820
registry.add(listen_obj);
824
static int deinit(plugin::Registry ®istry)
826
registry.remove(listen_obj);
831
static int init(module::Context &context)
833
drizzle_status_table_function_ptr= new DrizzleProtocolStatus;
835
context.add(drizzle_status_table_function_ptr);
837
const module::option_map &vm= context.getOptions();
838
if (vm.count("port"))
842
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of port\n"));
847
if (vm.count("connect-timeout"))
849
if (connect_timeout < 1 || connect_timeout > 300)
851
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for connect_timeout\n"));
856
if (vm.count("read-timeout"))
858
if (read_timeout < 1 || read_timeout > 300)
860
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for read_timeout\n"));
865
if (vm.count("write-timeout"))
867
if (write_timeout < 1 || write_timeout > 300)
869
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for write_timeout\n"));
874
if (vm.count("retry-count"))
876
if (retry_count < 1 || retry_count > 100)
878
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for retry_count\n"));
883
if (vm.count("buffer-length"))
885
if (buffer_length < 1024 || buffer_length > 1024*1024)
887
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for buffer_length\n"));
892
if (vm.count("bind-address"))
894
bind_address= strdup(vm["bind-address"].as<string>().c_str());
902
context.add(new ListenDrizzleProtocol("drizzle_protocol", false));
849
924
static DRIZZLE_SYSVAR_STR(bind_address, bind_address, PLUGIN_VAR_READONLY,
850
925
N_("Address to bind to."), NULL, NULL, NULL);
927
static void init_options(drizzled::module::option_context &context)
930
po::value<uint32_t>(&port)->default_value(0),
931
N_("Port number to use for connection or 0 for "
932
"default to, in order of "
933
"preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
934
"built-in default (4427)."));
935
context("connect-timeout",
936
po::value<uint32_t>(&connect_timeout)->default_value(10),
937
N_("Connect Timeout."));
938
context("read-timeout",
939
po::value<uint32_t>(&read_timeout)->default_value(30),
940
N_("Read Timeout."));
941
context("write-timeout",
942
po::value<uint32_t>(&write_timeout)->default_value(60),
943
N_("Write Timeout."));
944
context("retry-count",
945
po::value<uint32_t>(&retry_count)->default_value(10),
947
context("buffer-length",
948
po::value<uint32_t>(&buffer_length)->default_value(16384),
949
N_("Buffer length."));
950
context("bind-address",
952
N_("Address to bind to."));
852
955
static drizzle_sys_var* sys_variables[]= {
853
956
DRIZZLE_SYSVAR(port),
854
957
DRIZZLE_SYSVAR(connect_timeout),
966
static int drizzle_protocol_connection_count_func(drizzle_show_var *var, char *buff)
968
var->type= SHOW_LONGLONG;
970
*((uint64_t *)buff)= ClientDrizzleProtocol::connectionCount;
974
static int drizzle_protocol_connected_count_func(drizzle_show_var *var, char *buff)
976
var->type= SHOW_LONGLONG;
978
*((uint64_t *)buff)= ClientDrizzleProtocol::connected;
982
static int drizzle_protocol_failed_count_func(drizzle_show_var *var, char *buff)
984
var->type= SHOW_LONGLONG;
986
*((uint64_t *)buff)= ClientDrizzleProtocol::failedConnections;
990
static st_show_var_func_container drizzle_protocol_connection_count=
991
{ &drizzle_protocol_connection_count_func };
993
static st_show_var_func_container drizzle_protocol_connected_count=
994
{ &drizzle_protocol_connected_count_func };
996
static st_show_var_func_container drizzle_protocol_failed_count=
997
{ &drizzle_protocol_failed_count_func };
999
static drizzle_show_var drizzle_protocol_status_variables[]= {
1001
(char*) &drizzle_protocol_connection_count, SHOW_FUNC},
1003
(char*) &drizzle_protocol_connected_count, SHOW_FUNC},
1004
{"Failed_connections",
1005
(char*) &drizzle_protocol_failed_count, SHOW_FUNC},
1006
{NULL, NULL, SHOW_LONGLONG}
1009
DrizzleProtocolStatus::Generator::Generator(drizzled::Field **fields) :
1010
plugin::TableFunction::Generator(fields)
1012
status_var_ptr= drizzle_protocol_status_variables;
1015
bool DrizzleProtocolStatus::Generator::populate()
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;
1021
if (status_var_ptr->name)
1023
std::ostringstream oss;
1024
string return_value;
1028
push(status_var_ptr->name);
1030
if (status_var_ptr->type == SHOW_FUNC)
1032
((mysql_show_var_func)((st_show_var_func_container *)status_var_ptr->value)->func)(&tmp, buff);
1038
value= status_var_ptr->value;
1039
type= status_var_ptr->type;
1045
oss << *(uint64_t*) value;
1046
return_value= oss.str();
1051
if (return_value.length())
863
1063
} /* namespace drizzle_protocol */
865
DRIZZLE_PLUGIN(drizzle_protocol::init, drizzle_protocol::deinit, drizzle_protocol::sys_variables);
1065
DRIZZLE_PLUGIN(drizzle_protocol::init, drizzle_protocol::sys_variables, drizzle_protocol::init_options);