5
* Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
6
* See COPYRIGHT.txt for details.
14
#include "hstcpsvr.hpp"
15
#include "string_util.hpp"
16
#include "mysql_incl.hpp"
19
if (dena::verbose_level >= 100) { \
20
fprintf(stderr, "%s %p\n", __PRETTY_FUNCTION__, this); \
22
#define DBG_DO(x) if (dena::verbose_level >= 100) { x; }
28
static char *handlersocket_address = 0;
29
static char *handlersocket_port = 0;
30
static char *handlersocket_port_wr = 0;
31
static unsigned int handlersocket_epoll = 1;
32
static unsigned int handlersocket_threads = 32;
33
static unsigned int handlersocket_threads_wr = 1;
34
static unsigned int handlersocket_timeout = 30;
35
static unsigned int handlersocket_backlog = 32768;
36
static unsigned int handlersocket_sndbuf = 0;
37
static unsigned int handlersocket_rcvbuf = 0;
38
static unsigned int handlersocket_readsize = 0;
39
static unsigned int handlersocket_accept_balance = 0;
40
static unsigned int handlersocket_wrlock_timeout = 0;
41
static char *handlersocket_plain_secret = 0;
42
static char *handlersocket_plain_secret_wr = 0;
44
struct daemon_handlersocket_data {
45
hstcpsvr_ptr hssvr_rd;
46
hstcpsvr_ptr hssvr_wr;
50
daemon_handlersocket_init(void *p)
52
DENA_VERBOSE(10, fprintf(stderr, "handlersocket: initialized\n"));
54
conf["use_epoll"] = handlersocket_epoll ? "1" : "0";
55
if (handlersocket_address) {
56
conf["host"] = handlersocket_address;
58
if (handlersocket_port) {
59
conf["port"] = handlersocket_port;
64
* conf["port"] = "/tmp/handlersocket";
66
if (handlersocket_threads > 0) {
67
conf["num_threads"] = to_stdstring(handlersocket_threads);
69
conf["num_threads"] = "1";
71
conf["timeout"] = to_stdstring(handlersocket_timeout);
72
conf["listen_backlog"] = to_stdstring(handlersocket_backlog);
73
conf["sndbuf"] = to_stdstring(handlersocket_sndbuf);
74
conf["rcvbuf"] = to_stdstring(handlersocket_rcvbuf);
75
conf["readsize"] = to_stdstring(handlersocket_readsize);
76
conf["accept_balance"] = to_stdstring(handlersocket_accept_balance);
77
conf["wrlock_timeout"] = to_stdstring(handlersocket_wrlock_timeout);
78
std::auto_ptr<daemon_handlersocket_data> ap(new daemon_handlersocket_data);
79
if (handlersocket_port != 0 && handlersocket_port_wr != handlersocket_port) {
80
conf["port"] = handlersocket_port;
81
if (handlersocket_plain_secret) {
82
conf["plain_secret"] = handlersocket_plain_secret;
84
ap->hssvr_rd = hstcpsvr_i::create(conf);
85
ap->hssvr_rd->start_listen();
87
if (handlersocket_port_wr != 0) {
88
if (handlersocket_threads_wr > 0) {
89
conf["num_threads"] = to_stdstring(handlersocket_threads_wr);
91
conf["port"] = handlersocket_port_wr;
92
conf["for_write"] = "1";
93
conf["plain_secret"] = "";
94
if (handlersocket_plain_secret_wr) {
95
conf["plain_secret"] = handlersocket_plain_secret_wr;
97
ap->hssvr_wr = hstcpsvr_i::create(conf);
98
ap->hssvr_wr->start_listen();
100
st_plugin_int *const plugin = static_cast<st_plugin_int *>(p);
101
plugin->data = ap.release();
106
daemon_handlersocket_deinit(void *p)
108
DENA_VERBOSE(10, fprintf(stderr, "handlersocket: terminated\n"));
109
st_plugin_int *const plugin = static_cast<st_plugin_int *>(p);
110
daemon_handlersocket_data *ptr =
111
static_cast<daemon_handlersocket_data *>(plugin->data);
116
static struct st_mysql_daemon daemon_handlersocket_plugin = {
117
MYSQL_DAEMON_INTERFACE_VERSION
120
static MYSQL_SYSVAR_UINT(verbose, dena::verbose_level, 0,
121
"0..10000", 0, 0, 10 /* default */, 0, 10000, 0);
122
static MYSQL_SYSVAR_UINT(epoll, handlersocket_epoll, PLUGIN_VAR_READONLY,
123
"0..1", 0, 0, 1 /* default */, 0, 1, 0);
124
static MYSQL_SYSVAR_STR(address, handlersocket_address,
125
PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC, "", NULL, NULL, NULL);
126
static MYSQL_SYSVAR_STR(port, handlersocket_port,
127
PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC, "", NULL, NULL, NULL);
128
static MYSQL_SYSVAR_STR(port_wr, handlersocket_port_wr,
129
PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC, "", NULL, NULL, NULL);
130
static MYSQL_SYSVAR_UINT(threads, handlersocket_threads, PLUGIN_VAR_READONLY,
131
"1..3000", 0, 0, 16 /* default */, 1, 3000, 0);
132
static MYSQL_SYSVAR_UINT(threads_wr, handlersocket_threads_wr,
133
PLUGIN_VAR_READONLY, "1..3000", 0, 0, 1 /* default */, 1, 3000, 0);
134
static MYSQL_SYSVAR_UINT(timeout, handlersocket_timeout, PLUGIN_VAR_READONLY,
135
"30..3600", 0, 0, 300 /* default */, 30, 3600, 0);
136
static MYSQL_SYSVAR_UINT(backlog, handlersocket_backlog, PLUGIN_VAR_READONLY,
137
"5..1000000", 0, 0, 32768 /* default */, 5, 1000000, 0);
138
static MYSQL_SYSVAR_UINT(sndbuf, handlersocket_sndbuf, PLUGIN_VAR_READONLY,
139
"0..16777216", 0, 0, 0 /* default */, 0, 16777216, 0);
140
static MYSQL_SYSVAR_UINT(rcvbuf, handlersocket_rcvbuf, PLUGIN_VAR_READONLY,
141
"0..16777216", 0, 0, 0 /* default */, 0, 16777216, 0);
142
static MYSQL_SYSVAR_UINT(readsize, handlersocket_readsize, PLUGIN_VAR_READONLY,
143
"0..16777216", 0, 0, 0 /* default */, 0, 16777216, 0);
144
static MYSQL_SYSVAR_UINT(accept_balance, handlersocket_accept_balance,
145
PLUGIN_VAR_READONLY, "0..10000", 0, 0, 0 /* default */, 0, 10000, 0);
146
static MYSQL_SYSVAR_UINT(wrlock_timeout, handlersocket_wrlock_timeout,
147
PLUGIN_VAR_READONLY, "0..3600", 0, 0, 12 /* default */, 0, 3600, 0);
148
static MYSQL_SYSVAR_STR(plain_secret, handlersocket_plain_secret,
149
PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC, "", NULL, NULL, NULL);
150
static MYSQL_SYSVAR_STR(plain_secret_wr, handlersocket_plain_secret_wr,
151
PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC, "", NULL, NULL, NULL);
154
/* warning: type-punning to incomplete type might break strict-aliasing
156
static struct st_mysql_sys_var *daemon_handlersocket_system_variables[] = {
157
MYSQL_SYSVAR(verbose),
158
MYSQL_SYSVAR(address),
160
MYSQL_SYSVAR(port_wr),
162
MYSQL_SYSVAR(threads),
163
MYSQL_SYSVAR(threads_wr),
164
MYSQL_SYSVAR(timeout),
165
MYSQL_SYSVAR(backlog),
166
MYSQL_SYSVAR(sndbuf),
167
MYSQL_SYSVAR(rcvbuf),
168
MYSQL_SYSVAR(readsize),
169
MYSQL_SYSVAR(accept_balance),
170
MYSQL_SYSVAR(wrlock_timeout),
171
MYSQL_SYSVAR(plain_secret),
172
MYSQL_SYSVAR(plain_secret_wr),
176
static SHOW_VAR hs_status_variables[] = {
177
{"table_open", (char*) &open_tables_count, SHOW_LONGLONG},
178
{"table_close", (char*) &close_tables_count, SHOW_LONGLONG},
179
{"table_lock", (char*) &lock_tables_count, SHOW_LONGLONG},
180
{"table_unlock", (char*) &unlock_tables_count, SHOW_LONGLONG},
182
{"index_exec", (char*) &index_exec_count, SHOW_LONGLONG},
184
{NullS, NullS, SHOW_LONG}
187
static int show_hs_vars(THD *thd, SHOW_VAR *var, char *buff)
189
var->type= SHOW_ARRAY;
190
var->value= (char *) &hs_status_variables;
194
static SHOW_VAR daemon_handlersocket_status_variables[] = {
195
{"Hs", (char*) show_hs_vars, SHOW_FUNC},
196
{NullS, NullS, SHOW_LONG}
200
mysql_declare_plugin(handlersocket)
203
&daemon_handlersocket_plugin,
205
"higuchi dot akira at dena dot jp",
208
daemon_handlersocket_init,
209
daemon_handlersocket_deinit,
211
daemon_handlersocket_status_variables,
212
daemon_handlersocket_system_variables,
215
mysql_declare_plugin_end;