~percona-dev/percona-server/release-5.5.11-20.2-fix-bug-764138

« back to all changes in this revision

Viewing changes to HandlerSocket-Plugin-for-MySQL/handlersocket/handlersocket.cpp

  • Committer: Ignacio Nin
  • Date: 2011-03-13 17:18:23 UTC
  • mfrom: (33.3.17 release-5.5.8-20)
  • Revision ID: ignacio.nin@percona.com-20110313171823-m06xs104nekulywb
Merge changes from release-5.5.8-20 to 5.5.9

Merge changes from the release branch of 5.5.8 to 5.5.9. These include
the HandlerSocket and UDF directories and the building scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// vim:sw=2:ai
 
3
 
 
4
/*
 
5
 * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
 
6
 * See COPYRIGHT.txt for details.
 
7
 */
 
8
 
 
9
#include <memory>
 
10
#include <string>
 
11
#include <stdio.h>
 
12
 
 
13
#include "config.hpp"
 
14
#include "hstcpsvr.hpp"
 
15
#include "string_util.hpp"
 
16
#include "mysql_incl.hpp"
 
17
 
 
18
#define DBG_LOG \
 
19
  if (dena::verbose_level >= 100) { \
 
20
    fprintf(stderr, "%s %p\n", __PRETTY_FUNCTION__, this); \
 
21
  }
 
22
#define DBG_DO(x) if (dena::verbose_level >= 100) { x; }
 
23
 
 
24
#define DBG_DIR(x)
 
25
 
 
26
using namespace dena;
 
27
 
 
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;
 
43
 
 
44
struct daemon_handlersocket_data {
 
45
  hstcpsvr_ptr hssvr_rd;
 
46
  hstcpsvr_ptr hssvr_wr;
 
47
};
 
48
 
 
49
static int
 
50
daemon_handlersocket_init(void *p)
 
51
{
 
52
  DENA_VERBOSE(10, fprintf(stderr, "handlersocket: initialized\n"));
 
53
  config conf;
 
54
  conf["use_epoll"] = handlersocket_epoll ? "1" : "0";
 
55
  if (handlersocket_address) {
 
56
    conf["host"] = handlersocket_address;
 
57
  }
 
58
  if (handlersocket_port) {
 
59
    conf["port"] = handlersocket_port;
 
60
  }
 
61
  /*
 
62
   * unix domain socket
 
63
   * conf["host"] = "/";
 
64
   * conf["port"] = "/tmp/handlersocket";
 
65
   */
 
66
  if (handlersocket_threads > 0) {
 
67
    conf["num_threads"] = to_stdstring(handlersocket_threads);
 
68
  } else {
 
69
    conf["num_threads"] = "1";
 
70
  }
 
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;
 
83
    }
 
84
    ap->hssvr_rd = hstcpsvr_i::create(conf);
 
85
    ap->hssvr_rd->start_listen();
 
86
  }
 
87
  if (handlersocket_port_wr != 0) {
 
88
    if (handlersocket_threads_wr > 0) {
 
89
      conf["num_threads"] = to_stdstring(handlersocket_threads_wr);
 
90
    }
 
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;
 
96
    }
 
97
    ap->hssvr_wr = hstcpsvr_i::create(conf);
 
98
    ap->hssvr_wr->start_listen();
 
99
  }
 
100
  st_plugin_int *const plugin = static_cast<st_plugin_int *>(p);
 
101
  plugin->data = ap.release();
 
102
  return 0;
 
103
}
 
104
 
 
105
static int
 
106
daemon_handlersocket_deinit(void *p)
 
107
{
 
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);
 
112
  delete ptr;
 
113
  return 0;
 
114
}
 
115
 
 
116
static struct st_mysql_daemon daemon_handlersocket_plugin = {
 
117
  MYSQL_DAEMON_INTERFACE_VERSION
 
118
};
 
119
 
 
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);
 
152
 
 
153
 
 
154
/* warning: type-punning to incomplete type might break strict-aliasing
 
155
 * rules */
 
156
static struct st_mysql_sys_var *daemon_handlersocket_system_variables[] = {
 
157
  MYSQL_SYSVAR(verbose),
 
158
  MYSQL_SYSVAR(address),
 
159
  MYSQL_SYSVAR(port),
 
160
  MYSQL_SYSVAR(port_wr),
 
161
  MYSQL_SYSVAR(epoll),
 
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),
 
173
  0
 
174
};
 
175
 
 
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},
 
181
  #if 0
 
182
  {"index_exec", (char*) &index_exec_count, SHOW_LONGLONG},
 
183
  #endif
 
184
  {NullS, NullS, SHOW_LONG}
 
185
};
 
186
 
 
187
static int show_hs_vars(THD *thd, SHOW_VAR *var, char *buff)
 
188
{
 
189
  var->type= SHOW_ARRAY;
 
190
  var->value= (char *) &hs_status_variables;
 
191
  return 0;
 
192
}
 
193
 
 
194
static SHOW_VAR daemon_handlersocket_status_variables[] = {
 
195
  {"Hs", (char*) show_hs_vars, SHOW_FUNC},
 
196
  {NullS, NullS, SHOW_LONG}
 
197
};
 
198
 
 
199
 
 
200
mysql_declare_plugin(handlersocket)
 
201
{
 
202
  MYSQL_DAEMON_PLUGIN,
 
203
  &daemon_handlersocket_plugin,
 
204
  "handlersocket",
 
205
  "higuchi dot akira at dena dot jp",
 
206
  "",
 
207
  PLUGIN_LICENSE_BSD,
 
208
  daemon_handlersocket_init,
 
209
  daemon_handlersocket_deinit,
 
210
  0x0100 /* 1.0 */,
 
211
  daemon_handlersocket_status_variables,
 
212
  daemon_handlersocket_system_variables,
 
213
  0
 
214
}
 
215
mysql_declare_plugin_end;
 
216