vincentchu-handlersocket 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/HandlerSocket-Plugin-for-MySQL/AUTHORS +22 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/COPYING +30 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/ChangeLog +12 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/Makefile.am +87 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/README +78 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/autogen.sh +117 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/Makefile.am +24 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hsclient.cpp +88 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hslongrun.cpp +1041 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hspool_test.pl +224 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest.cpp +1532 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest.pl +228 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_hs.sh +4 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_hs_more50.sh +4 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_md.sh +7 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_my.sh +3 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/client/hstest_my_more50.sh +3 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/configure.ac +144 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/about-handlersocket.en.txt +72 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/configuration-options.en.txt +99 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/installation.en.txt +92 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/perl-client.en.txt +135 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-en/protocol.en.txt +205 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/about-handlersocket.ja.txt +51 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/installation.ja.txt +88 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/perl-client.ja.txt +127 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/docs-ja/protocol.ja.txt +180 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/COPYRIGHT.txt +27 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.am +10 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.plain.template +31 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/database.cpp +1190 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/database.hpp +142 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/handlersocket.cpp +222 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/handlersocket.spec.template +29 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr.cpp +149 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr.hpp +58 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr_worker.cpp +951 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/hstcpsvr_worker.hpp +35 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/handlersocket/mysql_incl.hpp +50 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/COPYRIGHT.txt +27 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/Makefile.am +12 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/Makefile.plain +27 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/allocator.hpp +64 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/auto_addrinfo.hpp +49 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/auto_file.hpp +64 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/auto_ptrcontainer.hpp +67 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/config.cpp +67 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/config.hpp +32 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/escape.cpp +127 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/escape.hpp +66 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/fatal.cpp +36 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/fatal.hpp +22 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/hstcpcli.cpp +441 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/hstcpcli.hpp +62 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/libhsclient.spec.template +39 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/mutex.hpp +51 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/socket.cpp +186 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/socket.hpp +51 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_buffer.hpp +118 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_ref.hpp +63 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_util.cpp +182 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/string_util.hpp +53 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/thread.hpp +84 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/libhsclient/util.hpp +25 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/misc/microbench-hs.log +130 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/misc/microbench-my.log +125 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/COPYRIGHT.txt +27 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/Changes +6 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/HandlerSocket.xs +632 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/MANIFEST +8 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/Makefile.PL +18 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/Makefile.PL.installed +20 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/README +30 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/lib/Net/HandlerSocket.pm +68 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/lib/Net/HandlerSocket/Pool.pm +362 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/perl-Net-HandlerSocket.spec.template +127 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/ppport.h +6375 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/perl-Net-HandlerSocket/t/Net-HandlerSocket.t +15 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/Makefile +79 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/common/binary_my.cnf +4 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/common/compat.sh +29 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/common/hstest.pm +66 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/Makefile +4 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/run.sh +27 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test01.expected +100 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test01.pl +38 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test02.expected +100 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test02.pl +49 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test03.expected +771 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test03.pl +61 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test04.expected +0 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test04.pl +63 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test05.expected +771 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test05.pl +59 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test06.expected +644 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test06.pl +90 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test07.expected +304 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test07.pl +98 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test08.expected +2 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test08.pl +48 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test09.expected +12 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test09.pl +67 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test10.expected +771 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test10.pl +93 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test11.expected +37 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test11.pl +112 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test12.expected +273 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test12.pl +134 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test13.expected +92 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test13.pl +92 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test14.expected +144 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test14.pl +80 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test15.expected +764 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test15.pl +114 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test16.expected +66 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test16.pl +88 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test17.expected +0 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test17.pl +125 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test18.expected +22 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test18.pl +63 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test19.expected +14894 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test19.pl +190 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test20.expected +2 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test20.pl +33 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test21.expected +11 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test21.pl +58 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test22.expected +9 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test22.pl +61 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test23.expected +101 -0
- data/ext/HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test23.pl +53 -0
- data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/README +33 -0
- data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/extconf.rb +27 -0
- data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/handlersocket.cpp +437 -0
- data/ext/winebarrel-ruby-handlersocket-c19841e47ea2/handlersocket.h +32 -0
- metadata +200 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
|
2
|
+
-----------------------------------------------------------------
|
3
|
+
handlersocket_verbose (default = 10, min = 0, max = 10000)
|
4
|
+
|
5
|
+
Specify the logging verboseness.
|
6
|
+
|
7
|
+
-----------------------------------------------------------------
|
8
|
+
handlersocket_address (default = '')
|
9
|
+
|
10
|
+
Specify the address to bind. If empty, it binds to 0.0.0.0.
|
11
|
+
|
12
|
+
-----------------------------------------------------------------
|
13
|
+
handlersocket_port (default = '9998')
|
14
|
+
|
15
|
+
Specify the port to bind. This option is for the listener for
|
16
|
+
read requests. If empty, the listener is disabled.
|
17
|
+
|
18
|
+
-----------------------------------------------------------------
|
19
|
+
handlersocket_port_wr (default = '9999')
|
20
|
+
|
21
|
+
Specify the port to bind. This option is for the listener for
|
22
|
+
write requests. If empty, the listener is disabled.
|
23
|
+
|
24
|
+
-----------------------------------------------------------------
|
25
|
+
handlersocket_epoll (default = 1, min = 0, max = 1)
|
26
|
+
|
27
|
+
Specify whether handlersocket uses epoll for I/O multiplexing.
|
28
|
+
|
29
|
+
-----------------------------------------------------------------
|
30
|
+
handlersocket_threads (default = 16, min = 1, max = 3000)
|
31
|
+
|
32
|
+
Specify the number of handlersocket worker threads. This option
|
33
|
+
is for the listener for read requests. Recommended value is
|
34
|
+
(the number of CPU cores * 2).
|
35
|
+
|
36
|
+
-----------------------------------------------------------------
|
37
|
+
handlersocket_threads_wr (default = 1, min = 1, max = 3000)
|
38
|
+
|
39
|
+
Specify the number of handlersocket worker threads. This option
|
40
|
+
is for the listener for write requests. Recommended value is 1.
|
41
|
+
|
42
|
+
-----------------------------------------------------------------
|
43
|
+
handlersocket_timeout (default = 300, min = 30, max = 3600)
|
44
|
+
|
45
|
+
Specify the socket timeout in seconds.
|
46
|
+
|
47
|
+
-----------------------------------------------------------------
|
48
|
+
handlersocket_backlog (default = 32768, min = 5, max = 1000000)
|
49
|
+
|
50
|
+
Specify the length of the listen backlog.
|
51
|
+
|
52
|
+
-----------------------------------------------------------------
|
53
|
+
handlersocket_sndbuf (default = 0, min = 0, max = 1677216)
|
54
|
+
|
55
|
+
Specify the maximum socket send buffer in bytes. If 0, the
|
56
|
+
system-wide default value is set.
|
57
|
+
|
58
|
+
-----------------------------------------------------------------
|
59
|
+
handlersocket_rcvbuf (default = 0, min = 0, max = 1677216)
|
60
|
+
|
61
|
+
Specify the maximum socket receive buffer in bytes. If 0, the
|
62
|
+
system-wide default value is set.
|
63
|
+
|
64
|
+
-----------------------------------------------------------------
|
65
|
+
handlersocket_readsize (default = 0, min = 0, max = 1677216)
|
66
|
+
|
67
|
+
Specify the minimum length of the handlersocket request buffer.
|
68
|
+
Larger value can make handlersocket faster for large requests,
|
69
|
+
but can consume memory. The default value is possibly 4096.
|
70
|
+
|
71
|
+
-----------------------------------------------------------------
|
72
|
+
handlersocket_accept_balance (default = 0, min = 0, max = 10000)
|
73
|
+
|
74
|
+
When this option is set to non-zero, handlersocket tries to
|
75
|
+
balance accepted connections among threads. Non-zero is
|
76
|
+
recommended if you use persistent connections (i.e., connection
|
77
|
+
pooling on the client side).
|
78
|
+
|
79
|
+
-----------------------------------------------------------------
|
80
|
+
handlersocket_wrlock_timeout (default = 12, min = 0, max = 3600)
|
81
|
+
|
82
|
+
Specify the lock timeout in seconds. When a write request is
|
83
|
+
performed, handlersocket acquires an advisory lock named
|
84
|
+
'handlersocket_wr'. This option sets the timeout for the
|
85
|
+
locking.
|
86
|
+
|
87
|
+
-----------------------------------------------------------------
|
88
|
+
handlersocket_plain_secret (default = '')
|
89
|
+
|
90
|
+
When this option is specified, a plain-text authentication is
|
91
|
+
enabled for the listener for read requests. This option
|
92
|
+
specifies the secret key for the authentication.
|
93
|
+
|
94
|
+
-----------------------------------------------------------------
|
95
|
+
handlersocket_plain_secret_wr (default = '')
|
96
|
+
|
97
|
+
This option specifies the secret key for the listener for write
|
98
|
+
requests.
|
99
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
1. Building Handlersocket
|
2
|
+
|
3
|
+
Handlersocket mainly consists of libhsclient, handlersocket, and C++/Perl clients. libhsclient is a common library shared from both client and server(plugin). handlersocket is a MySQL daemon plugin.
|
4
|
+
To build Handlersocket, you need both MySQL source code and MySQL binary. It is not required to pre-build MySQL source code, but source itself is needed because Handlersocket depends on MySQL header files that only MySQL source distribution contains. MySQL binary is just a normal MySQL binary distribution. You can use official MySQL binaries provided by Oracle.
|
5
|
+
Since Handlersocket uses daemon plugin interface supported from MySQL 5.1,
|
6
|
+
MySQL 5.1 or higher version is required.
|
7
|
+
Please make sure that you use identical MySQL version between MySQL source
|
8
|
+
and MySQL binary. Otherwise you might encounter serious problems (i.e. server
|
9
|
+
crash, etc).
|
10
|
+
Here are steps to build Handlersocket.
|
11
|
+
|
12
|
+
* Get MySQL source code
|
13
|
+
|
14
|
+
* Get MySQL binary
|
15
|
+
|
16
|
+
* Build Handlersocket
|
17
|
+
$ ./autogen.sh
|
18
|
+
$ ./configure --with-mysql-source=/work/mysql-5.1.50 --with-mysql-bindir=/work/mysql-5.1.50-linux-x86_64-glibc23/bin --with-mysql-plugindir=/work/mysql-5.1.50-linux-x86_64-glibc23/lib/plugin
|
19
|
+
|
20
|
+
--with-mysql-source refers to the top of MySQL source directory (which
|
21
|
+
contains the VERSION file or the configure.in file), --with-mysql-bindir
|
22
|
+
refers to where MySQL binary executables (i.e. mysql_config) are located,
|
23
|
+
and --with-mysql-plugindir refers to a plugin directory where plugin
|
24
|
+
libraries (*.so) are installed.
|
25
|
+
|
26
|
+
$ make
|
27
|
+
$ sudo make install
|
28
|
+
|
29
|
+
Both libhsclient and the handlersocket plugin will be installed.
|
30
|
+
|
31
|
+
|
32
|
+
2. Using Handlersocket
|
33
|
+
|
34
|
+
Append configuration options for handlersocket to my.cnf.
|
35
|
+
|
36
|
+
[mysqld]
|
37
|
+
loose_handlersocket_port = 9998
|
38
|
+
# the port number to bind to (for read requests)
|
39
|
+
loose_handlersocket_port_wr = 9999
|
40
|
+
# the port number to bind to (for write requests)
|
41
|
+
loose_handlersocket_threads = 16
|
42
|
+
# the number of worker threads (for read requests)
|
43
|
+
loose_handlersocket_threads_wr = 1
|
44
|
+
# the number of worker threads (for write requests)
|
45
|
+
open_files_limit = 65535
|
46
|
+
# to allow handlersocket accept many concurrent
|
47
|
+
# connections, make open_files_limit as large as
|
48
|
+
# possible.
|
49
|
+
|
50
|
+
Log in to mysql as root, and execute the following query.
|
51
|
+
|
52
|
+
mysql> install plugin handlersocket soname 'handlersocket.so';
|
53
|
+
|
54
|
+
If handlersocket.so is successfully installed, it starts
|
55
|
+
accepting connections on port 9998 and 9999. Running
|
56
|
+
'show processlist' should show handlersocket worker threads.
|
57
|
+
|
58
|
+
-----------------------------------------------------------------
|
59
|
+
On the client side, you need to install libhsclient for c++ apps
|
60
|
+
and perl-Net-HandlerSocket for perl apps. They do not require
|
61
|
+
MySQL to compile.
|
62
|
+
|
63
|
+
$ ./autogen.sh
|
64
|
+
$ ./configure --disable-handlersocket-server
|
65
|
+
$ make
|
66
|
+
$ sudo make install
|
67
|
+
$ cd perl-Net-HandlerSocket
|
68
|
+
$ perl Makefile.PL
|
69
|
+
$ make
|
70
|
+
$ sudo make install
|
71
|
+
|
72
|
+
-----------------------------------------------------------------
|
73
|
+
Alternatively, you can use the rpm installation. If your OS
|
74
|
+
supports rpms, you can use the following commands to build and
|
75
|
+
install handlersocket rpm packages.
|
76
|
+
|
77
|
+
(Server side, installs HandlerSocket plugin)
|
78
|
+
$ ./autogen.sh
|
79
|
+
$ ./configure --with-mysql-source=/work/mysql-5.1.50 --with-mysql-bindir=/work/mysql-5.1.50-linux-x86_64-glibc23/bin --with-mysql-plugindir=/work/mysql-5.1.50-linux-x86_64-glibc23/lib/plugin
|
80
|
+
$ make rpm_cli
|
81
|
+
$ sudo rpm -U dist/RPMS/*/libhsclient*.rpm
|
82
|
+
$ make rpm_c
|
83
|
+
$ sudo rpm -U dist/RPMS/*/handlersocket*.rpm
|
84
|
+
|
85
|
+
(Client side, installs client libraries)
|
86
|
+
$ ./autogen.sh
|
87
|
+
$ ./configure --disable-handlersocket-server
|
88
|
+
$ make rpm_cli
|
89
|
+
$ sudo rpm -U dist/RPMS/*/libhsclient*.rpm
|
90
|
+
$ make rpm_perl
|
91
|
+
$ sudo rpm -U dist/RPMS/*/perl-Net-HandlerSocket*.rpm
|
92
|
+
|
@@ -0,0 +1,135 @@
|
|
1
|
+
|
2
|
+
-----------------------------------------------------------------
|
3
|
+
To open a connection to the handlersocket plugin, you need to
|
4
|
+
create a Net::HandlerSocket object.
|
5
|
+
|
6
|
+
use Net::HandlerSocket;
|
7
|
+
my $args = { host => 'localhost', port => 9998 };
|
8
|
+
my $hs = new Net::HandlerSocket($args);
|
9
|
+
|
10
|
+
-----------------------------------------------------------------
|
11
|
+
Before executing table operations, you need to open an index to
|
12
|
+
work with.
|
13
|
+
|
14
|
+
my $err = $hs->open_index(3, 'database1', 'table1', 'PRIMARY',
|
15
|
+
'f1,f2');
|
16
|
+
die $hs->get_error() if $res->[0] != 0;
|
17
|
+
|
18
|
+
The first argument for open_index is an integer value which is
|
19
|
+
used to identify an open table, which is only valid within the
|
20
|
+
same Net::HandlerSocket object. The 4th argument is the name of
|
21
|
+
index to open. If 'PRIMARY' is specified, the primary index is
|
22
|
+
open. The 5th argument is a comma-separated list of column names.
|
23
|
+
|
24
|
+
-----------------------------------------------------------------
|
25
|
+
To read a record from a table using an index, call the
|
26
|
+
execute_single method.
|
27
|
+
|
28
|
+
my $res = $hs->execute_single(3, '=', [ 'foo' ], 1, 0);
|
29
|
+
die $hs->get_error() if $res->[0] != 0;
|
30
|
+
shift(@$res);
|
31
|
+
|
32
|
+
The first argument must be an integer which has specified as the
|
33
|
+
first argument for open_index on the same Net::HandlerSocket
|
34
|
+
object. The second argument specifies the search operation. The
|
35
|
+
current version of handlersocket supports '=', '>=', '<=', '>',
|
36
|
+
and '<'. The 3rd argument specifies the key to find, which must
|
37
|
+
an arrayref whose length is equal to or smaller than the number
|
38
|
+
of key columns of the index. The 4th and the 5th arguments
|
39
|
+
specify the maximum number of records to be retrieved, and the
|
40
|
+
number of records skipped before retrieving records. The columns
|
41
|
+
to be retrieved are specified by the 5th argument for the
|
42
|
+
corresponding open_index call.
|
43
|
+
|
44
|
+
The execute_single method always returns an arrayref. The first
|
45
|
+
element is the error code, which is 0 when no error is occured.
|
46
|
+
The remaining are the field values. If more than one record is
|
47
|
+
returned, it is flatten to an 1-dimensional array. For example,
|
48
|
+
when 5 records that have 3 columns are returned, you can retrieve
|
49
|
+
values using the following code.
|
50
|
+
|
51
|
+
die $hs->get_error() if $res->[0] != 0;
|
52
|
+
shift(@$res);
|
53
|
+
for (my $row = 0; $row < 5; ++$row) {
|
54
|
+
for (my $col = 0; $col < 3; ++$col) {
|
55
|
+
my $value = $res->[$row * 5 + $col];
|
56
|
+
# ...
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
-----------------------------------------------------------------
|
61
|
+
To update or delete records, you need to specify more arguments
|
62
|
+
for the execute_single method. Note that the Net::HandlerSocket
|
63
|
+
object must be connected to a handlersocket worker for write
|
64
|
+
operations, which is port 9999 by default.
|
65
|
+
(For safety, the port 9998 only allows read operations, and the
|
66
|
+
port 9999 allows write operations also. The port 9999 allows
|
67
|
+
read operations too, but slower than 9998 because of record
|
68
|
+
locking etc.. Port numbers can be changed using the
|
69
|
+
'handlersocket_port' and the 'handlersocket_port_wr'
|
70
|
+
configuration options of mysqld.)
|
71
|
+
|
72
|
+
my $args = { host => 'localhost', port => 9999 };
|
73
|
+
my $hs = new Net::HandlerSocket($args);
|
74
|
+
|
75
|
+
my $res = $hs->execute_single(3, '=', [ 'bar' ], 1, 0, 'U',
|
76
|
+
[ 'fubar', 'hoge' ]);
|
77
|
+
die $hs->get_error() if $res->[0] != 0;
|
78
|
+
my $num_updated_rows = $res->[1];
|
79
|
+
|
80
|
+
my $res = $hs->execute_single(3, '=', [ 'baz' ], 1, 0, 'D');
|
81
|
+
die $hs->get_error() if $res->[0] != 0;
|
82
|
+
my $num_deleted_rows = $res->[1];
|
83
|
+
|
84
|
+
The 6th argument for execute_single specifies the modification
|
85
|
+
operation. The current version supports 'U' and 'D'. For the 'U'
|
86
|
+
operation, the 7th argument specifies the new value for the row.
|
87
|
+
The columns to be modified are specified by the 5th argument for
|
88
|
+
the corresponding open_index call. For the 'D' operation, the
|
89
|
+
7th argument can be omitted.
|
90
|
+
|
91
|
+
-----------------------------------------------------------------
|
92
|
+
The execute_single method can be used for inserting records also.
|
93
|
+
|
94
|
+
my $res = $hs->execute_single(3, '+', [ 'foo', 'bar', 'baz' ]);
|
95
|
+
die $hs->get_error() if $res->[0] != 0;
|
96
|
+
my $num_inserted_rows = $res->[1];
|
97
|
+
|
98
|
+
The 3rd argument must be an arrayref whose elements correspond to
|
99
|
+
the 5th argument for the corresponding open_index call. If there
|
100
|
+
is a column which is not appeared in the 5th argument for the
|
101
|
+
open_index, the default value for the column is set.
|
102
|
+
|
103
|
+
-----------------------------------------------------------------
|
104
|
+
Multiple operations can be executed in a single call. Executing
|
105
|
+
multiple operations in a single call is much faster than
|
106
|
+
executing them separatedly.
|
107
|
+
|
108
|
+
my $rarr = $hs->execute_multi([
|
109
|
+
[ 0, '>=', [ 'foo' ], 5, 0 ],
|
110
|
+
[ 2, '=', [ 'bar' ], 1, 0 ],
|
111
|
+
[ 4, '<', [ 'baz' ], 10, 5 ],
|
112
|
+
]);
|
113
|
+
for my $res (@$rarr) {
|
114
|
+
die $hs->get_error() if $res->[0] != 0;
|
115
|
+
shift(@$res);
|
116
|
+
# ...
|
117
|
+
}
|
118
|
+
|
119
|
+
-----------------------------------------------------------------
|
120
|
+
If handlersocket is configured to authenticate client connections
|
121
|
+
(ie., handlersocket_plain_secret or handlersocket_plain_secret_wr
|
122
|
+
is set), a client must call 'auth' method before any other
|
123
|
+
methods.
|
124
|
+
|
125
|
+
my $res = $hs->auth('password');
|
126
|
+
die $hs->get_error() if $res->[0] != 0;
|
127
|
+
|
128
|
+
-----------------------------------------------------------------
|
129
|
+
When an error is occured, the first element of the returned
|
130
|
+
arrayref becomes a non-zero value. A negative value indicates
|
131
|
+
that an I/O error is occured and the Net::HandlerSocket object
|
132
|
+
should be disposed. A positive value means that the connection is
|
133
|
+
still active and the Net::HandlerSocket object can be reused
|
134
|
+
later.
|
135
|
+
|
@@ -0,0 +1,205 @@
|
|
1
|
+
|
2
|
+
----------------------------------------------------------------------------
|
3
|
+
The HandlerSocket protocol
|
4
|
+
|
5
|
+
----------------------------------------------------------------------------
|
6
|
+
Basic syntax
|
7
|
+
|
8
|
+
- The HandlerSocket protocol is line-based. Each line ends with LF(0x0a).
|
9
|
+
- Each line consists a concatenation of tokens separated by HT(0x09).
|
10
|
+
- A token is either NULL or an encoded string. Note that you need to
|
11
|
+
distinguish NULL from an empty string, as most DBMs does so.
|
12
|
+
- NULL is expressed as a single NUL(0x00).
|
13
|
+
- An encoded string is a string with the following encoding rules.
|
14
|
+
- Characters in the range [0x10 - 0xff] are encoded as itselves.
|
15
|
+
- A character in the range [0x00 - 0x0f] is prefixed by 0x01 and
|
16
|
+
shifted by 0x40. For example, 0x03 is encoded as 0x01 0x43.
|
17
|
+
- Note that a string can be empty. A continuation of 0x09 0x09 means that
|
18
|
+
there is an empty string between them. A continuation of 0x09 0x0a means
|
19
|
+
that there is an empty string at the end of the line.
|
20
|
+
|
21
|
+
----------------------------------------------------------------------------
|
22
|
+
Request and Response
|
23
|
+
|
24
|
+
- The HandlerSocket protocol is a simple request/response protocol. After a
|
25
|
+
connection is established, the client side sends a request, and then the
|
26
|
+
server side sends a response.
|
27
|
+
- A request/response consists of a single line.
|
28
|
+
- Requests can be pipelined; That is, you can send multiple requests (ie.
|
29
|
+
lines) at one time, and receive responses for them at one time.
|
30
|
+
|
31
|
+
----------------------------------------------------------------------------
|
32
|
+
Opening index
|
33
|
+
|
34
|
+
The 'open_index' request has the following syntax.
|
35
|
+
|
36
|
+
P <indexid> <dbname> <tablename> <indexname> <columns> [<fcolumns>]
|
37
|
+
|
38
|
+
- <indexid> is a number in decimal.
|
39
|
+
- <dbname>, <tablename>, and <indexname> are strings. To open the primary
|
40
|
+
key, use PRIMARY as <indexname>.
|
41
|
+
- <columns> is a comma-separated list of column names.
|
42
|
+
- <fcolumns> is a comma-separated list of column names. This parameter is
|
43
|
+
optional.
|
44
|
+
|
45
|
+
Once an 'open_index' request is issued, the HandlerSocket plugin opens the
|
46
|
+
specified index and keep it open until the client connection is closed. Each
|
47
|
+
open index is identified by <indexid>. If <indexid> is already open, the old
|
48
|
+
open index is closed. You can open the same combination of <dbname>
|
49
|
+
<tablename> <indexname> multple times, possibly with different <columns>.
|
50
|
+
For efficiency, keep <indexid> small as far as possible.
|
51
|
+
|
52
|
+
----------------------------------------------------------------------------
|
53
|
+
Getting data
|
54
|
+
|
55
|
+
The 'find' request has the following syntax.
|
56
|
+
|
57
|
+
<indexid> <op> <vlen> <v1> ... <vn> [LIM] [IN] [FILTER ...]
|
58
|
+
|
59
|
+
LIM is a sequence of the following parameters.
|
60
|
+
|
61
|
+
<limit> <offset>
|
62
|
+
|
63
|
+
IN is a sequence of the following parameters.
|
64
|
+
|
65
|
+
@ <icol> <ivlen> <iv1> ... <ivn>
|
66
|
+
|
67
|
+
FILETER is a sequence of the following parameters.
|
68
|
+
|
69
|
+
<ftyp> <fop> <fcol> <fval>
|
70
|
+
|
71
|
+
- <indexid> is a number. This number must be an <indexid> specified by a
|
72
|
+
'open_index' request executed previously on the same connection.
|
73
|
+
- <op> specifies the comparison operation to use. The current version of
|
74
|
+
HandlerSocket supports '=', '>', '>=', '<', and '<='.
|
75
|
+
- <vlen> indicates the length of the trailing parameters <v1> ... <vn>. This
|
76
|
+
must be smaller than or equal to the number of index columns specified by
|
77
|
+
the <indexname> parameter of the corresponding 'open_index' request.
|
78
|
+
- <v1> ... <vn> specify the index column values to fetch.
|
79
|
+
- LIM is optional. <limit> and <offset> are numbers. When omitted, it works
|
80
|
+
as if 1 and 0 are specified. These parameter works like LIMIT of SQL.
|
81
|
+
These values don't include the number of records skipped by a filter.
|
82
|
+
- IN is optional. It works like WHERE ... IN syntax of SQL. <icol> must be
|
83
|
+
smaller than the number of index columns specified by the <indexname>
|
84
|
+
parameter of the corresponding 'open_index' request. If IN is specified in
|
85
|
+
a find request, the <icol>-th parameter value of <v1> ... <vn> is ignored.
|
86
|
+
- FILTERs are optional. A FILTER specifies a filter. <ftyp> is either 'F'
|
87
|
+
(filter) or 'W' (while). <fop> specifies the comparison operation to use.
|
88
|
+
<fcol> must be smaller than the number of columns specified by the
|
89
|
+
<fcolumns> parameter of the corresponding 'open_index' request. Multiple
|
90
|
+
filters can be specified, and work as the logical AND of them. The
|
91
|
+
difference of 'F' and 'W' is that, when a record does not meet the
|
92
|
+
specified condition, 'F' simply skips the record, and 'W' stops the loop.
|
93
|
+
|
94
|
+
----------------------------------------------------------------------------
|
95
|
+
Updating/Deleting data
|
96
|
+
|
97
|
+
The 'find_modify' request has the following syntax.
|
98
|
+
|
99
|
+
<indexid> <op> <vlen> <v1> ... <vn> [LIM] [IN] [FILTER ...] MOD
|
100
|
+
|
101
|
+
MOD is a sequence of the following parameters.
|
102
|
+
|
103
|
+
<mop> <m1> ... <mk>
|
104
|
+
|
105
|
+
- <mop> is 'U' (update), '+' (increment), '-' (decrement), 'D' (delete),
|
106
|
+
'U?', '+?', '-?', or 'D?'. If the '?' suffix is specified, it returns
|
107
|
+
the contents of the records before modification (as if it's a 'find'
|
108
|
+
request), instead of the number of modified records.
|
109
|
+
- <m1> ... <mk> specifies the column values to set. The length of <m1> ...
|
110
|
+
<mk> must be smaller than or equal to the length of <columns> specified by
|
111
|
+
the corresponding 'open_index' request. If <mop> is 'D', these parameters
|
112
|
+
are ignored. If <mop> is '+' or '-', values must be numeric. If <mop> is
|
113
|
+
'-' and it attempts to change a column value from negative to positive or
|
114
|
+
positive to negative, the column value is not modified.
|
115
|
+
|
116
|
+
----------------------------------------------------------------------------
|
117
|
+
Inserting data
|
118
|
+
|
119
|
+
The 'insert' request has the following syntax.
|
120
|
+
|
121
|
+
<indexid> + <vlen> <v1> ... <vn>
|
122
|
+
|
123
|
+
- <vlen> indicates the length of the trailing parameters <v1> ... <vn>. This
|
124
|
+
must be smaller than or equal to the length of <columns> specified by the
|
125
|
+
corresponding 'open_index' request.
|
126
|
+
- <v1> ... <vn> specify the column values to set. For columns not in
|
127
|
+
<columns>, the default values for each column are set.
|
128
|
+
|
129
|
+
----------------------------------------------------------------------------
|
130
|
+
Authentication
|
131
|
+
|
132
|
+
The 'auth' request has the following syntax.
|
133
|
+
|
134
|
+
A <atyp> <akey>
|
135
|
+
|
136
|
+
- <atyp> must be '1'
|
137
|
+
- An 'auth' request succeeds iff <akey> is the correct secret specified by
|
138
|
+
the 'handlersocket_plain_secret' or 'handlersocket_plain_secret_rw'.
|
139
|
+
- If an authentication is enabled for a listener, any other requests on a
|
140
|
+
connection fail before an 'auth' request succeeded on the connection.
|
141
|
+
|
142
|
+
----------------------------------------------------------------------------
|
143
|
+
Response syntax
|
144
|
+
|
145
|
+
HandlerSocket returns a response of the following syntax for each request.
|
146
|
+
|
147
|
+
<errorcode> <numcolumns> <r1> ... <rn>
|
148
|
+
|
149
|
+
- <errorcode> indicates whether the request has successfully executed or not.
|
150
|
+
'0' means success. Non-zero means an error.
|
151
|
+
- <numcolumns> indicates the number of columns of the result set.
|
152
|
+
- <r1> ... <rn> is the result set. The length of <r1> ... <rn> is always a
|
153
|
+
multiple of <numcolumns>. It is possible that <r1> ... <rn> is empty.
|
154
|
+
|
155
|
+
If <errorcode> is non-zero, <numcolumns> is always 1 and <r1> indicates a
|
156
|
+
human-readable error message, though sometimes <r1> is not provided.
|
157
|
+
|
158
|
+
----------------------------------------------------------------------------
|
159
|
+
Response for 'open_index'
|
160
|
+
|
161
|
+
If 'open_index' is succeeded, HandlerSocket returns a line of the following
|
162
|
+
syntax.
|
163
|
+
|
164
|
+
0 1
|
165
|
+
|
166
|
+
----------------------------------------------------------------------------
|
167
|
+
Response for 'find'
|
168
|
+
|
169
|
+
If 'find' is succeeded, HandlerSocket returns a line of the following
|
170
|
+
syntax.
|
171
|
+
|
172
|
+
0 <numcolumns> <r1> ... <rn>
|
173
|
+
|
174
|
+
- <numcolumns> always equals to the length of <columns> of the corresponding
|
175
|
+
'open_index' request.
|
176
|
+
- <r1> ... <rn> is the result set. If N rows are found, the length of <r1>
|
177
|
+
... <rn> becomes ( <numcolumns> * N ).
|
178
|
+
|
179
|
+
----------------------------------------------------------------------------
|
180
|
+
Response for 'find_modify'
|
181
|
+
|
182
|
+
If 'find_modify' is succeeded, HandlerSocket returns a line of the following
|
183
|
+
syntax.
|
184
|
+
|
185
|
+
0 1 <nummod>
|
186
|
+
|
187
|
+
- <nummod> is the number of modified rows.
|
188
|
+
- As an exception, if the '?' suffix is specified in <mop>, a response has
|
189
|
+
the syntax of a response for 'find' instead.
|
190
|
+
|
191
|
+
----------------------------------------------------------------------------
|
192
|
+
Response for 'insert'
|
193
|
+
|
194
|
+
If 'insert' is succeeded, HanderSocket returns a line of the following
|
195
|
+
syntax.
|
196
|
+
|
197
|
+
0 1
|
198
|
+
|
199
|
+
----------------------------------------------------------------------------
|
200
|
+
Response for 'auth'
|
201
|
+
|
202
|
+
If 'auth' is succeeded, HanderSocket returns a line of the following syntax.
|
203
|
+
|
204
|
+
0 1
|
205
|
+
|