Merge lp:~tsarev/percona-server/5.5.12-794345 into lp:~percona-dev/percona-server/5.5.12
- 5.5.12-794345
- Merge into 5.5.12
Proposed by
Oleg Tsarev
Status: | Superseded | ||||||||
---|---|---|---|---|---|---|---|---|---|
Proposed branch: | lp:~tsarev/percona-server/5.5.12-794345 | ||||||||
Merge into: | lp:~percona-dev/percona-server/5.5.12 | ||||||||
Diff against target: |
60254 lines (has conflicts)
Text conflict in series |
||||||||
To merge this branch: | bzr merge lp:~tsarev/percona-server/5.5.12-794345 | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Percona developers | Pending | ||
Valentine Gostev | qa | Pending | |
Review via email: mp+63793@code.launchpad.net |
This proposal supersedes a proposal from 2011-06-08.
This proposal has been superseded by a proposal from 2011-06-08.
Commit message
Description of the change
Reason of bugs #786645 and #794345: when we run test under valgrind test work long time, and slow query log has extra query "call mtr.check_
I disable slow query log on startup, and enable only when I need.
This is actual for tests:
* percona_
* percona_
* percona_
* percona_
* percona_
To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) wrote : Posted in a previous version of this proposal | # |
review:
Needs Fixing
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'HandlerSocket-Plugin-for-MySQL' | |||
2 | === added file 'HandlerSocket-Plugin-for-MySQL/AUTHORS' | |||
3 | --- HandlerSocket-Plugin-for-MySQL/AUTHORS 1970-01-01 00:00:00 +0000 | |||
4 | +++ HandlerSocket-Plugin-for-MySQL/AUTHORS 2011-06-08 01:58:05 +0000 | |||
5 | @@ -0,0 +1,19 @@ | |||
6 | 1 | Akira Higuchi (https://github.com/ahiguti) | ||
7 | 2 | - developed HanderSocket plugin, libhsclient, and perl-Net-HandlerSocket | ||
8 | 3 | |||
9 | 4 | Yoshinori Matsunobu (https://github.com/yoshinorim) | ||
10 | 5 | - introduced autotools, added support for MySQL 5.5.6, added statistics | ||
11 | 6 | variables | ||
12 | 7 | |||
13 | 8 | Jeff Hodges (https://github.com/jmhodges) | ||
14 | 9 | - fixed some autotools scripts | ||
15 | 10 | |||
16 | 11 | Toru Yamaguchi (https://github.com/zigorou) | ||
17 | 12 | - ported to MacOS X | ||
18 | 13 | |||
19 | 14 | Moriyoshi Koizumi (https://github.com/moriyoshi) | ||
20 | 15 | - fixed some autotools scripts | ||
21 | 16 | |||
22 | 17 | takeda-at (https://github.com/takada-at) | ||
23 | 18 | - added simple authorization function | ||
24 | 19 | |||
25 | 0 | 20 | ||
26 | === added file 'HandlerSocket-Plugin-for-MySQL/COPYING' | |||
27 | --- HandlerSocket-Plugin-for-MySQL/COPYING 1970-01-01 00:00:00 +0000 | |||
28 | +++ HandlerSocket-Plugin-for-MySQL/COPYING 2011-06-08 01:58:05 +0000 | |||
29 | @@ -0,0 +1,30 @@ | |||
30 | 1 | ----------------------------------------------------------------------------- | ||
31 | 2 | HandlerSocket plugin for MySQL | ||
32 | 3 | |||
33 | 4 | Copyright (c) 2010 DeNA Co.,Ltd. | ||
34 | 5 | All rights reserved. | ||
35 | 6 | |||
36 | 7 | Redistribution and use in source and binary forms, with or without | ||
37 | 8 | modification, are permitted provided that the following conditions are met: | ||
38 | 9 | |||
39 | 10 | * Redistributions of source code must retain the above copyright | ||
40 | 11 | notice, this list of conditions and the following disclaimer. | ||
41 | 12 | * Redistributions in binary form must reproduce the above copyright | ||
42 | 13 | notice, this list of conditions and the following disclaimer in the | ||
43 | 14 | documentation and/or other materials provided with the distribution. | ||
44 | 15 | * Neither the name of DeNA Co.,Ltd. nor the names of its contributors | ||
45 | 16 | may be used to endorse or promote products derived from this software | ||
46 | 17 | without specific prior written permission. | ||
47 | 18 | |||
48 | 19 | THIS SOFTWARE IS PROVIDED BY DeNA Co.,Ltd. "AS IS" AND ANY EXPRESS OR | ||
49 | 20 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
50 | 21 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | ||
51 | 22 | EVENT SHALL DeNA Co.,Ltd. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
52 | 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
53 | 24 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
54 | 25 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
55 | 26 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
56 | 27 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
57 | 28 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
58 | 29 | |||
59 | 30 | |||
60 | 0 | 31 | ||
61 | === added file 'HandlerSocket-Plugin-for-MySQL/ChangeLog' | |||
62 | --- HandlerSocket-Plugin-for-MySQL/ChangeLog 1970-01-01 00:00:00 +0000 | |||
63 | +++ HandlerSocket-Plugin-for-MySQL/ChangeLog 2011-06-08 01:58:05 +0000 | |||
64 | @@ -0,0 +1,12 @@ | |||
65 | 1 | 1.0.6 - 2010-10-29 | ||
66 | 2 | * Changed build instruction (autoreconf/configure/make), removed auto-generated files (Contributed by jmhodges) | ||
67 | 3 | * | ||
68 | 4 | |||
69 | 5 | 1.0.5 - 2010-10-18 | ||
70 | 6 | * Changed build procedures (using typical configure/make) | ||
71 | 7 | * Supported 5.5.6 | ||
72 | 8 | * Added status variables | ||
73 | 9 | |||
74 | 10 | 1.0.4 - 2010-08-15 | ||
75 | 11 | * Initial public release | ||
76 | 12 | |||
77 | 0 | 13 | ||
78 | === added file 'HandlerSocket-Plugin-for-MySQL/Makefile.am' | |||
79 | --- HandlerSocket-Plugin-for-MySQL/Makefile.am 1970-01-01 00:00:00 +0000 | |||
80 | +++ HandlerSocket-Plugin-for-MySQL/Makefile.am 2011-06-08 01:58:05 +0000 | |||
81 | @@ -0,0 +1,87 @@ | |||
82 | 1 | |||
83 | 2 | ACLOCAL_AMFLAGS = -I m4 | ||
84 | 3 | |||
85 | 4 | SUBDIRS = @HANDLERSOCKET_SUBDIRS@ | ||
86 | 5 | |||
87 | 6 | perl: | ||
88 | 7 | cd perl-Net-HandlerSocket && perl Makefile.PL && make | ||
89 | 8 | |||
90 | 9 | install_perl: | ||
91 | 10 | cd perl-Net-HandlerSocket && make install | ||
92 | 11 | |||
93 | 12 | rpms: rpm_cli rpm_perl rpm_c | ||
94 | 13 | |||
95 | 14 | rpm_dir: | ||
96 | 15 | - mkdir dist | ||
97 | 16 | - mkdir dist/BUILD dist/RPMS dist/SOURCES dist/SPECS dist/SRPMS | ||
98 | 17 | |||
99 | 18 | rpm_cli: clean_cli rpm_dir | ||
100 | 19 | sed -e "s/HANDLERSOCKET_VERSION/$(VERSION)/" \ | ||
101 | 20 | libhsclient/libhsclient.spec.template \ | ||
102 | 21 | > libhsclient/libhsclient.spec | ||
103 | 22 | tar cvfz dist/libhsclient.tar.gz libhsclient | ||
104 | 23 | rpmbuild --define "_topdir `pwd`/dist" -ta \ | ||
105 | 24 | dist/libhsclient.tar.gz | ||
106 | 25 | |||
107 | 26 | rpm_perl: clean_perl rpm_dir | ||
108 | 27 | sed -e "s/HANDLERSOCKET_VERSION/$(VERSION)/" \ | ||
109 | 28 | perl-Net-HandlerSocket/perl-Net-HandlerSocket.spec.template \ | ||
110 | 29 | > perl-Net-HandlerSocket/perl-Net-HandlerSocket.spec | ||
111 | 30 | cd perl-Net-HandlerSocket && perl Makefile.PL && make clean && \ | ||
112 | 31 | rm -f Makefile.old | ||
113 | 32 | tar cvfz dist/perl-Net-HandlerSocket.tar.gz perl-Net-HandlerSocket | ||
114 | 33 | rpmbuild --define "_topdir `pwd`/dist" -ta \ | ||
115 | 34 | dist/perl-Net-HandlerSocket.tar.gz | ||
116 | 35 | |||
117 | 36 | rpm_c: clean_c rpm_dir | ||
118 | 37 | sed -e "s/HANDLERSOCKET_VERSION/$(VERSION)/" \ | ||
119 | 38 | handlersocket/handlersocket.spec.template \ | ||
120 | 39 | > handlersocket/handlersocket.spec | ||
121 | 40 | sed -e "s|HANDLERSOCKET_MYSQL_INC|$(MYSQL_CFLAGS) $(MYSQL_INC)|" \ | ||
122 | 41 | -e "s|HANDLERSOCKET_MYSQL_LIB|$(MYSQL_LIB)|" \ | ||
123 | 42 | handlersocket/Makefile.plain.template \ | ||
124 | 43 | > handlersocket/Makefile.plain | ||
125 | 44 | tar cvfz dist/handlersocket.tar.gz handlersocket | ||
126 | 45 | rpmbuild --define "_topdir `pwd`/dist" -ta \ | ||
127 | 46 | dist/handlersocket.tar.gz | ||
128 | 47 | |||
129 | 48 | install_rpm_pl: | ||
130 | 49 | - sudo rpm -e perl-Net-HandlerSocket | ||
131 | 50 | - sudo rpm -e perl-Net-HandlerSocket-debuginfo | ||
132 | 51 | make clean | ||
133 | 52 | make rpm_perl | ||
134 | 53 | - sudo rpm -U dist/RPMS/*/perl*.rpm | ||
135 | 54 | |||
136 | 55 | installrpms: | ||
137 | 56 | - sudo rpm -e handlersocket | ||
138 | 57 | - sudo rpm -e handlersocket-debuginfo | ||
139 | 58 | - sudo rpm -e perl-Net-HandlerSocket | ||
140 | 59 | - sudo rpm -e perl-Net-HandlerSocket-debuginfo | ||
141 | 60 | - sudo rpm -e libhsclient | ||
142 | 61 | - sudo rpm -e libhsclient-debuginfo | ||
143 | 62 | make clean | ||
144 | 63 | make rpm_cli | ||
145 | 64 | - sudo rpm -U dist/RPMS/*/libhsclient*.rpm | ||
146 | 65 | make clean | ||
147 | 66 | make rpm_perl | ||
148 | 67 | - sudo rpm -U dist/RPMS/*/perl*.rpm | ||
149 | 68 | make clean | ||
150 | 69 | make rpm_c | ||
151 | 70 | - sudo rpm -U dist/RPMS/*/handlersocket*.rpm | ||
152 | 71 | |||
153 | 72 | clean_cli: | ||
154 | 73 | cd libhsclient && make clean | ||
155 | 74 | cd client && make clean | ||
156 | 75 | |||
157 | 76 | clean_perl: | ||
158 | 77 | cd perl-Net-HandlerSocket && perl Makefile.PL && make clean && \ | ||
159 | 78 | rm -f Makefile.old | ||
160 | 79 | |||
161 | 80 | clean_c: | ||
162 | 81 | cd handlersocket && make clean | ||
163 | 82 | |||
164 | 83 | clean_all: clean_cli clean_perl clean_c | ||
165 | 84 | cd regtest && make clean | ||
166 | 85 | rm -rf dist/*/* | ||
167 | 86 | rm -f dist/*.tar.gz | ||
168 | 87 | |||
169 | 0 | 88 | ||
170 | === added file 'HandlerSocket-Plugin-for-MySQL/README' | |||
171 | --- HandlerSocket-Plugin-for-MySQL/README 1970-01-01 00:00:00 +0000 | |||
172 | +++ HandlerSocket-Plugin-for-MySQL/README 2011-06-08 01:58:05 +0000 | |||
173 | @@ -0,0 +1,76 @@ | |||
174 | 1 | |||
175 | 2 | ----------------------------------------------------------------------------- | ||
176 | 3 | HandlerSocket plugin for MySQL | ||
177 | 4 | |||
178 | 5 | Copyright (c) 2010 DeNA Co.,Ltd. | ||
179 | 6 | All rights reserved. | ||
180 | 7 | |||
181 | 8 | Redistribution and use in source and binary forms, with or without | ||
182 | 9 | modification, are permitted provided that the following conditions are met: | ||
183 | 10 | |||
184 | 11 | * Redistributions of source code must retain the above copyright | ||
185 | 12 | notice, this list of conditions and the following disclaimer. | ||
186 | 13 | * Redistributions in binary form must reproduce the above copyright | ||
187 | 14 | notice, this list of conditions and the following disclaimer in the | ||
188 | 15 | documentation and/or other materials provided with the distribution. | ||
189 | 16 | * Neither the name of DeNA Co.,Ltd. nor the names of its contributors | ||
190 | 17 | may be used to endorse or promote products derived from this software | ||
191 | 18 | without specific prior written permission. | ||
192 | 19 | |||
193 | 20 | THIS SOFTWARE IS PROVIDED BY DeNA Co.,Ltd. "AS IS" AND ANY EXPRESS OR | ||
194 | 21 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
195 | 22 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | ||
196 | 23 | EVENT SHALL DeNA Co.,Ltd. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
197 | 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
198 | 25 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
199 | 26 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
200 | 27 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
201 | 28 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
202 | 29 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
203 | 30 | |||
204 | 31 | |||
205 | 32 | ----------------------------------------------------------------------------- | ||
206 | 33 | About HandlerSocket | ||
207 | 34 | |||
208 | 35 | HandlerSocket is a NoSQL plugin for MySQL. It works as a daemon inside the | ||
209 | 36 | mysqld process, accept tcp connections, and execute requests from clients. | ||
210 | 37 | HandlerSocket does not support SQL queries. Instead, it supports simple CRUD | ||
211 | 38 | operations on tables. | ||
212 | 39 | |||
213 | 40 | Because of the following reasons, HandlerSocket is much faster than the | ||
214 | 41 | mysqld/libmysql pair in some circumstances: | ||
215 | 42 | |||
216 | 43 | - HandlerSocket manipulates data without parsing SQL, which causes less | ||
217 | 44 | CPU usage. | ||
218 | 45 | - HandlerSocket reads many requests from clients and executes their | ||
219 | 46 | requests in bulk, which causes less CPU and disk usage. | ||
220 | 47 | - HandlerSocket client/server protocol is more compact than the | ||
221 | 48 | mysql/libmysql pair, which causes less network usage. | ||
222 | 49 | |||
223 | 50 | The current version of HandlerSocket only works with GNU/Linux. The source | ||
224 | 51 | archive of HandlerSocket includes a C++ and a Perl client libraries. | ||
225 | 52 | Here is a list of client libraries for other languages: | ||
226 | 53 | |||
227 | 54 | - PHP | ||
228 | 55 | http://openpear.org/package/Net_HandlerSocket | ||
229 | 56 | http://github.com/tz-lom/HSPHP | ||
230 | 57 | http://code.google.com/p/php-handlersocket/ | ||
231 | 58 | - Java | ||
232 | 59 | http://code.google.com/p/hs4j/ | ||
233 | 60 | http://code.google.com/p/handlersocketforjava/ | ||
234 | 61 | - Python | ||
235 | 62 | http://pypi.python.org/pypi/python-handler-socket | ||
236 | 63 | https://code.launchpad.net/~songofacandy/+junk/pyhandlersocket | ||
237 | 64 | - Ruby | ||
238 | 65 | https://github.com/winebarrel/ruby-handlersocket | ||
239 | 66 | https://github.com/miyucy/handlersocket | ||
240 | 67 | - JavaScript | ||
241 | 68 | https://github.com/koichik/node-handlersocket | ||
242 | 69 | - Scala | ||
243 | 70 | https://github.com/fujohnwang/hs2client | ||
244 | 71 | |||
245 | 72 | The home of HandlerSocket is here: | ||
246 | 73 | https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL | ||
247 | 74 | |||
248 | 75 | More documents are available in docs-en/ and docs-ja/ directories. | ||
249 | 76 | |||
250 | 0 | 77 | ||
251 | === added file 'HandlerSocket-Plugin-for-MySQL/autogen.sh' | |||
252 | --- HandlerSocket-Plugin-for-MySQL/autogen.sh 1970-01-01 00:00:00 +0000 | |||
253 | +++ HandlerSocket-Plugin-for-MySQL/autogen.sh 2011-06-08 01:58:05 +0000 | |||
254 | @@ -0,0 +1,117 @@ | |||
255 | 1 | #!/bin/sh | ||
256 | 2 | |||
257 | 3 | warn() { | ||
258 | 4 | echo -e "\tWARNING: $@" 1>&2 | ||
259 | 5 | } | ||
260 | 6 | |||
261 | 7 | # init | ||
262 | 8 | |||
263 | 9 | LIBTOOLIZE=libtoolize | ||
264 | 10 | ACLOCAL=aclocal | ||
265 | 11 | AUTOCONF=autoconf | ||
266 | 12 | AUTOHEADER=autoheader | ||
267 | 13 | AUTOMAKE=automake | ||
268 | 14 | |||
269 | 15 | case `uname -s` in | ||
270 | 16 | Darwin) | ||
271 | 17 | LIBTOOLIZE=glibtoolize | ||
272 | 18 | ;; | ||
273 | 19 | FreeBSD) | ||
274 | 20 | ACLOCAL_ARGS="$ACLOCAL_ARGS -I /usr/local/share/aclocal/" | ||
275 | 21 | ;; | ||
276 | 22 | esac | ||
277 | 23 | |||
278 | 24 | |||
279 | 25 | # libtoolize | ||
280 | 26 | echo "Searching libtoolize..." | ||
281 | 27 | if [ `which $LIBTOOLIZE` ] ; then | ||
282 | 28 | echo -e "\tFOUND: libtoolize -> $LIBTOOLIZE" | ||
283 | 29 | else | ||
284 | 30 | warn "Cannot Found libtoolize... input libtool command" | ||
285 | 31 | read LIBTOOLIZE | ||
286 | 32 | LIBTOOLIZE=`which $LIBTOOLIZE` | ||
287 | 33 | if [ `which $LIBTOOLIZE` ] ; then | ||
288 | 34 | echo -e "\tSET: libtoolize -> $LIBTOOLIZE" | ||
289 | 35 | else | ||
290 | 36 | warn "$LIBTOOLIZE: Command not found." | ||
291 | 37 | exit 1; | ||
292 | 38 | fi | ||
293 | 39 | fi | ||
294 | 40 | |||
295 | 41 | # aclocal | ||
296 | 42 | echo "Searching aclocal..." | ||
297 | 43 | if [ `which $ACLOCAL` ] ; then | ||
298 | 44 | echo -e "\tFOUND: aclocal -> $ACLOCAL" | ||
299 | 45 | else | ||
300 | 46 | warn "Cannot Found aclocal... input aclocal command" | ||
301 | 47 | read ACLOCAL | ||
302 | 48 | ACLOCAL=`which $ACLOCAL` | ||
303 | 49 | if [ `which $ACLOCAL` ] ; then | ||
304 | 50 | echo -e "\tSET: aclocal -> $ACLOCAL" | ||
305 | 51 | else | ||
306 | 52 | warn "$ACLOCAL: Command not found." | ||
307 | 53 | exit 1; | ||
308 | 54 | fi | ||
309 | 55 | fi | ||
310 | 56 | |||
311 | 57 | # automake | ||
312 | 58 | echo "Searching automake..." | ||
313 | 59 | if [ `which $AUTOMAKE` ] ; then | ||
314 | 60 | echo -e "\tFOUND: automake -> $AUTOMAKE" | ||
315 | 61 | else | ||
316 | 62 | warn "Cannot Found automake... input automake command" | ||
317 | 63 | read AUTOMAKE | ||
318 | 64 | ACLOCAL=`which $AUTOMAKE` | ||
319 | 65 | if [ `which $AUTOMAKE` ] ; then | ||
320 | 66 | echo -e "\tSET: automake -> $AUTOMAKE" | ||
321 | 67 | else | ||
322 | 68 | warn "$AUTOMAKE: Command not found." | ||
323 | 69 | exit 1; | ||
324 | 70 | fi | ||
325 | 71 | fi | ||
326 | 72 | |||
327 | 73 | # autoheader | ||
328 | 74 | echo "Searching autoheader..." | ||
329 | 75 | if [ `which $AUTOHEADER` ] ; then | ||
330 | 76 | echo -e "\tFOUND: autoheader -> $AUTOHEADER" | ||
331 | 77 | else | ||
332 | 78 | warn "Cannot Found autoheader... input autoheader command" | ||
333 | 79 | read AUTOHEADER | ||
334 | 80 | ACLOCAL=`which $AUTOHEADER` | ||
335 | 81 | if [ `which $AUTOHEADER` ] ; then | ||
336 | 82 | echo -e "\tSET: autoheader -> $AUTOHEADER" | ||
337 | 83 | else | ||
338 | 84 | warn "$AUTOHEADER: Command not found." | ||
339 | 85 | exit 1; | ||
340 | 86 | fi | ||
341 | 87 | fi | ||
342 | 88 | |||
343 | 89 | # autoconf | ||
344 | 90 | echo "Searching autoconf..." | ||
345 | 91 | if [ `which $AUTOCONF` ] ; then | ||
346 | 92 | echo -e "\tFOUND: autoconf -> $AUTOCONF" | ||
347 | 93 | else | ||
348 | 94 | warn "Cannot Found autoconf... input autoconf command" | ||
349 | 95 | read AUTOCONF | ||
350 | 96 | ACLOCAL=`which $AUTOCONF` | ||
351 | 97 | if [ `which $AUTOCONF` ] ; then | ||
352 | 98 | echo -e "\tSET: autoconf -> $AUTOCONF" | ||
353 | 99 | else | ||
354 | 100 | warn "$AUTOCONF: Command not found." | ||
355 | 101 | exit 1; | ||
356 | 102 | fi | ||
357 | 103 | fi | ||
358 | 104 | |||
359 | 105 | echo "Running libtoolize ..." | ||
360 | 106 | $LIBTOOLIZE --force --copy | ||
361 | 107 | echo "Running aclocal ..." | ||
362 | 108 | $ACLOCAL ${ACLOCAL_ARGS} -I . | ||
363 | 109 | echo "Running autoheader..." | ||
364 | 110 | $AUTOHEADER | ||
365 | 111 | echo "Running automake ..." | ||
366 | 112 | $AUTOMAKE --add-missing --copy | ||
367 | 113 | echo "Running autoconf ..." | ||
368 | 114 | $AUTOCONF | ||
369 | 115 | |||
370 | 116 | mkdir -p m4 | ||
371 | 117 | |||
372 | 0 | 118 | ||
373 | === added directory 'HandlerSocket-Plugin-for-MySQL/client' | |||
374 | === added file 'HandlerSocket-Plugin-for-MySQL/client/Makefile.am' | |||
375 | --- HandlerSocket-Plugin-for-MySQL/client/Makefile.am 1970-01-01 00:00:00 +0000 | |||
376 | +++ HandlerSocket-Plugin-for-MySQL/client/Makefile.am 2011-06-08 01:58:05 +0000 | |||
377 | @@ -0,0 +1,24 @@ | |||
378 | 1 | AM_INCLUDES= -I../libhsclient | ||
379 | 2 | bin_PROGRAMS=hsclient | ||
380 | 3 | hsclient_SOURCES= hsclient.cpp | ||
381 | 4 | hsclient_LDFLAGS= -static -L../libhsclient -lhsclient | ||
382 | 5 | hsclient_CXXFLAGS= $(AM_INCLUDES) | ||
383 | 6 | |||
384 | 7 | hstest: hstest.o | ||
385 | 8 | $(CXX) $(CXXFLAGS) $(LFLAGS) hstest.o \ | ||
386 | 9 | -L../libhsclient/.libs -lhsclient $$(mysql_config --libs_r) \ | ||
387 | 10 | -o hstest | ||
388 | 11 | |||
389 | 12 | hstest.o: hstest.cpp | ||
390 | 13 | $(CXX) $(CXXFLAGS) $(AM_INCLUDES) $$(mysql_config --include) \ | ||
391 | 14 | -c hstest.cpp | ||
392 | 15 | |||
393 | 16 | hslongrun: hslongrun.o | ||
394 | 17 | $(CXX) $(CXXFLAGS) $(LFLAGS) hslongrun.o \ | ||
395 | 18 | -L../libhsclient/.libs -lhsclient $$(mysql_config --libs_r) \ | ||
396 | 19 | -o hslongrun | ||
397 | 20 | |||
398 | 21 | hslongrun.o: hslongrun.cpp | ||
399 | 22 | $(CXX) $(CXXFLAGS) $(AM_INCLUDES) $$(mysql_config --include) \ | ||
400 | 23 | -c hslongrun.cpp | ||
401 | 24 | |||
402 | 0 | 25 | ||
403 | === added file 'HandlerSocket-Plugin-for-MySQL/client/hsclient.cpp' | |||
404 | --- HandlerSocket-Plugin-for-MySQL/client/hsclient.cpp 1970-01-01 00:00:00 +0000 | |||
405 | +++ HandlerSocket-Plugin-for-MySQL/client/hsclient.cpp 2011-06-08 01:58:05 +0000 | |||
406 | @@ -0,0 +1,88 @@ | |||
407 | 1 | |||
408 | 2 | // vim:sw=2:ai | ||
409 | 3 | |||
410 | 4 | #include "hstcpcli.hpp" | ||
411 | 5 | #include "string_util.hpp" | ||
412 | 6 | |||
413 | 7 | namespace dena { | ||
414 | 8 | |||
415 | 9 | int | ||
416 | 10 | hstcpcli_main(int argc, char **argv) | ||
417 | 11 | { | ||
418 | 12 | config conf; | ||
419 | 13 | parse_args(argc, argv, conf); | ||
420 | 14 | socket_args sockargs; | ||
421 | 15 | sockargs.set(conf); | ||
422 | 16 | hstcpcli_ptr cli = hstcpcli_i::create(sockargs); | ||
423 | 17 | const std::string dbname = conf.get_str("dbname", "hstest"); | ||
424 | 18 | const std::string table = conf.get_str("table", "hstest_table1"); | ||
425 | 19 | const std::string index = conf.get_str("index", "PRIMARY"); | ||
426 | 20 | const std::string fields = conf.get_str("fields", "k,v"); | ||
427 | 21 | const int limit = conf.get_int("limit", 0); | ||
428 | 22 | const int skip = conf.get_int("skip", 0); | ||
429 | 23 | std::vector<std::string> keys; | ||
430 | 24 | std::vector<string_ref> keyrefs; | ||
431 | 25 | size_t num_keys = 0; | ||
432 | 26 | while (true) { | ||
433 | 27 | const std::string conf_key = std::string("k") + to_stdstring(num_keys); | ||
434 | 28 | const std::string k = conf.get_str(conf_key, ""); | ||
435 | 29 | const std::string kx = conf.get_str(conf_key, "x"); | ||
436 | 30 | if (k.empty() && kx == "x") { | ||
437 | 31 | break; | ||
438 | 32 | } | ||
439 | 33 | ++num_keys; | ||
440 | 34 | keys.push_back(k); | ||
441 | 35 | } | ||
442 | 36 | for (size_t i = 0; i < keys.size(); ++i) { | ||
443 | 37 | const string_ref ref(keys[i].data(), keys[i].size()); | ||
444 | 38 | keyrefs.push_back(ref); | ||
445 | 39 | } | ||
446 | 40 | const std::string op = conf.get_str("op", "="); | ||
447 | 41 | const string_ref op_ref(op.data(), op.size()); | ||
448 | 42 | cli->request_buf_open_index(0, dbname.c_str(), table.c_str(), | ||
449 | 43 | index.c_str(), fields.c_str()); | ||
450 | 44 | cli->request_buf_exec_generic(0, op_ref, num_keys == 0 ? 0 : &keyrefs[0], | ||
451 | 45 | num_keys, limit, skip, string_ref(), 0, 0); | ||
452 | 46 | int code = 0; | ||
453 | 47 | size_t numflds = 0; | ||
454 | 48 | do { | ||
455 | 49 | if (cli->request_send() != 0) { | ||
456 | 50 | fprintf(stderr, "request_send: %s\n", cli->get_error().c_str()); | ||
457 | 51 | break; | ||
458 | 52 | } | ||
459 | 53 | if ((code = cli->response_recv(numflds)) != 0) { | ||
460 | 54 | fprintf(stderr, "response_recv: %s\n", cli->get_error().c_str()); | ||
461 | 55 | break; | ||
462 | 56 | } | ||
463 | 57 | } while (false); | ||
464 | 58 | cli->response_buf_remove(); | ||
465 | 59 | do { | ||
466 | 60 | if ((code = cli->response_recv(numflds)) != 0) { | ||
467 | 61 | fprintf(stderr, "response_recv: %s\n", cli->get_error().c_str()); | ||
468 | 62 | break; | ||
469 | 63 | } | ||
470 | 64 | while (true) { | ||
471 | 65 | const string_ref *const row = cli->get_next_row(); | ||
472 | 66 | if (row == 0) { | ||
473 | 67 | break; | ||
474 | 68 | } | ||
475 | 69 | printf("REC:"); | ||
476 | 70 | for (size_t i = 0; i < numflds; ++i) { | ||
477 | 71 | const std::string val(row[i].begin(), row[i].size()); | ||
478 | 72 | printf(" %s", val.c_str()); | ||
479 | 73 | } | ||
480 | 74 | printf("\n"); | ||
481 | 75 | } | ||
482 | 76 | } while (false); | ||
483 | 77 | cli->response_buf_remove(); | ||
484 | 78 | return 0; | ||
485 | 79 | } | ||
486 | 80 | |||
487 | 81 | }; | ||
488 | 82 | |||
489 | 83 | int | ||
490 | 84 | main(int argc, char **argv) | ||
491 | 85 | { | ||
492 | 86 | return dena::hstcpcli_main(argc, argv); | ||
493 | 87 | } | ||
494 | 88 | |||
495 | 0 | 89 | ||
496 | === added file 'HandlerSocket-Plugin-for-MySQL/client/hslongrun.cpp' | |||
497 | --- HandlerSocket-Plugin-for-MySQL/client/hslongrun.cpp 1970-01-01 00:00:00 +0000 | |||
498 | +++ HandlerSocket-Plugin-for-MySQL/client/hslongrun.cpp 2011-06-08 01:58:05 +0000 | |||
499 | @@ -0,0 +1,1041 @@ | |||
500 | 1 | |||
501 | 2 | // vim:sw=2:ai | ||
502 | 3 | |||
503 | 4 | #include <signal.h> | ||
504 | 5 | #include <sys/time.h> | ||
505 | 6 | #include <stdio.h> | ||
506 | 7 | #include <string.h> | ||
507 | 8 | #include <vector> | ||
508 | 9 | #include <map> | ||
509 | 10 | #include <stdlib.h> | ||
510 | 11 | #include <memory> | ||
511 | 12 | #include <errno.h> | ||
512 | 13 | #include <mysql.h> | ||
513 | 14 | #include <time.h> | ||
514 | 15 | #include <sys/types.h> | ||
515 | 16 | #include <sys/stat.h> | ||
516 | 17 | #include <fcntl.h> | ||
517 | 18 | |||
518 | 19 | #include "util.hpp" | ||
519 | 20 | #include "auto_ptrcontainer.hpp" | ||
520 | 21 | #include "socket.hpp" | ||
521 | 22 | #include "hstcpcli.hpp" | ||
522 | 23 | #include "string_util.hpp" | ||
523 | 24 | #include "mutex.hpp" | ||
524 | 25 | |||
525 | 26 | namespace dena { | ||
526 | 27 | |||
527 | 28 | struct auto_mysql : private noncopyable { | ||
528 | 29 | auto_mysql() : db(0) { | ||
529 | 30 | reset(); | ||
530 | 31 | } | ||
531 | 32 | ~auto_mysql() { | ||
532 | 33 | if (db) { | ||
533 | 34 | mysql_close(db); | ||
534 | 35 | } | ||
535 | 36 | } | ||
536 | 37 | void reset() { | ||
537 | 38 | if (db) { | ||
538 | 39 | mysql_close(db); | ||
539 | 40 | } | ||
540 | 41 | if ((db = mysql_init(0)) == 0) { | ||
541 | 42 | fatal_exit("failed to initialize mysql client"); | ||
542 | 43 | } | ||
543 | 44 | } | ||
544 | 45 | operator MYSQL *() const { return db; } | ||
545 | 46 | private: | ||
546 | 47 | MYSQL *db; | ||
547 | 48 | }; | ||
548 | 49 | |||
549 | 50 | struct auto_mysql_res : private noncopyable { | ||
550 | 51 | auto_mysql_res(MYSQL *db) { | ||
551 | 52 | res = mysql_store_result(db); | ||
552 | 53 | } | ||
553 | 54 | ~auto_mysql_res() { | ||
554 | 55 | if (res) { | ||
555 | 56 | mysql_free_result(res); | ||
556 | 57 | } | ||
557 | 58 | } | ||
558 | 59 | operator MYSQL_RES *() const { return res; } | ||
559 | 60 | private: | ||
560 | 61 | MYSQL_RES *res; | ||
561 | 62 | }; | ||
562 | 63 | |||
563 | 64 | struct auto_mysql_stmt : private noncopyable { | ||
564 | 65 | auto_mysql_stmt(MYSQL *db) { | ||
565 | 66 | stmt = mysql_stmt_init(db); | ||
566 | 67 | } | ||
567 | 68 | ~auto_mysql_stmt() { | ||
568 | 69 | if (stmt) { | ||
569 | 70 | mysql_stmt_close(stmt); | ||
570 | 71 | } | ||
571 | 72 | } | ||
572 | 73 | operator MYSQL_STMT *() const { return stmt; } | ||
573 | 74 | private: | ||
574 | 75 | MYSQL_STMT *stmt; | ||
575 | 76 | }; | ||
576 | 77 | |||
577 | 78 | double | ||
578 | 79 | gettimeofday_double() | ||
579 | 80 | { | ||
580 | 81 | struct timeval tv = { }; | ||
581 | 82 | if (gettimeofday(&tv, 0) != 0) { | ||
582 | 83 | fatal_abort("gettimeofday"); | ||
583 | 84 | } | ||
584 | 85 | return static_cast<double>(tv.tv_usec) / 1000000 + tv.tv_sec; | ||
585 | 86 | } | ||
586 | 87 | |||
587 | 88 | struct record_value { | ||
588 | 89 | mutex lock; | ||
589 | 90 | bool deleted; | ||
590 | 91 | bool unknown_state; | ||
591 | 92 | std::string key; | ||
592 | 93 | std::vector<std::string> values; | ||
593 | 94 | record_value() : deleted(true), unknown_state(false) { } | ||
594 | 95 | }; | ||
595 | 96 | |||
596 | 97 | struct hs_longrun_shared { | ||
597 | 98 | config conf; | ||
598 | 99 | socket_args arg; | ||
599 | 100 | int verbose; | ||
600 | 101 | long num_threads; | ||
601 | 102 | int usleep; | ||
602 | 103 | volatile mutable int running; | ||
603 | 104 | auto_ptrcontainer< std::vector<record_value *> > records; | ||
604 | 105 | hs_longrun_shared() : verbose(0), num_threads(0), usleep(0), running(1) { } | ||
605 | 106 | }; | ||
606 | 107 | |||
607 | 108 | struct thread_base { | ||
608 | 109 | thread_base() : need_join(false), stack_size(256 * 1024) { } | ||
609 | 110 | virtual ~thread_base() { | ||
610 | 111 | join(); | ||
611 | 112 | } | ||
612 | 113 | virtual void run() = 0; | ||
613 | 114 | void start() { | ||
614 | 115 | if (!start_nothrow()) { | ||
615 | 116 | fatal_abort("thread::start"); | ||
616 | 117 | } | ||
617 | 118 | } | ||
618 | 119 | bool start_nothrow() { | ||
619 | 120 | if (need_join) { | ||
620 | 121 | return need_join; /* true */ | ||
621 | 122 | } | ||
622 | 123 | void *const arg = this; | ||
623 | 124 | pthread_attr_t attr; | ||
624 | 125 | if (pthread_attr_init(&attr) != 0) { | ||
625 | 126 | fatal_abort("pthread_attr_init"); | ||
626 | 127 | } | ||
627 | 128 | if (pthread_attr_setstacksize(&attr, stack_size) != 0) { | ||
628 | 129 | fatal_abort("pthread_attr_setstacksize"); | ||
629 | 130 | } | ||
630 | 131 | const int r = pthread_create(&thr, &attr, thread_main, arg); | ||
631 | 132 | if (pthread_attr_destroy(&attr) != 0) { | ||
632 | 133 | fatal_abort("pthread_attr_destroy"); | ||
633 | 134 | } | ||
634 | 135 | if (r != 0) { | ||
635 | 136 | return need_join; /* false */ | ||
636 | 137 | } | ||
637 | 138 | need_join = true; | ||
638 | 139 | return need_join; /* true */ | ||
639 | 140 | } | ||
640 | 141 | void join() { | ||
641 | 142 | if (!need_join) { | ||
642 | 143 | return; | ||
643 | 144 | } | ||
644 | 145 | int e = 0; | ||
645 | 146 | if ((e = pthread_join(thr, 0)) != 0) { | ||
646 | 147 | fatal_abort("pthread_join"); | ||
647 | 148 | } | ||
648 | 149 | need_join = false; | ||
649 | 150 | } | ||
650 | 151 | private: | ||
651 | 152 | static void *thread_main(void *arg) { | ||
652 | 153 | thread_base *p = static_cast<thread_base *>(arg); | ||
653 | 154 | p->run(); | ||
654 | 155 | return 0; | ||
655 | 156 | } | ||
656 | 157 | private: | ||
657 | 158 | pthread_t thr; | ||
658 | 159 | bool need_join; | ||
659 | 160 | size_t stack_size; | ||
660 | 161 | }; | ||
661 | 162 | |||
662 | 163 | struct hs_longrun_stat { | ||
663 | 164 | unsigned long long verify_error_count; | ||
664 | 165 | unsigned long long runtime_error_count; | ||
665 | 166 | unsigned long long unknown_count; | ||
666 | 167 | unsigned long long success_count; | ||
667 | 168 | hs_longrun_stat() | ||
668 | 169 | : verify_error_count(0), runtime_error_count(0), | ||
669 | 170 | unknown_count(0), success_count(0) { } | ||
670 | 171 | void add(const hs_longrun_stat& x) { | ||
671 | 172 | verify_error_count += x.verify_error_count; | ||
672 | 173 | runtime_error_count += x.runtime_error_count; | ||
673 | 174 | unknown_count += x.unknown_count; | ||
674 | 175 | success_count += x.success_count; | ||
675 | 176 | } | ||
676 | 177 | }; | ||
677 | 178 | |||
678 | 179 | struct hs_longrun_thread_base : public thread_base { | ||
679 | 180 | struct arg_type { | ||
680 | 181 | int id; | ||
681 | 182 | std::string worker_type; | ||
682 | 183 | char op; | ||
683 | 184 | int lock_flag; | ||
684 | 185 | const hs_longrun_shared& sh; | ||
685 | 186 | arg_type(int id, const std::string& worker_type, char op, int lock_flag, | ||
686 | 187 | const hs_longrun_shared& sh) | ||
687 | 188 | : id(id), worker_type(worker_type), op(op), lock_flag(lock_flag), | ||
688 | 189 | sh(sh) { } | ||
689 | 190 | }; | ||
690 | 191 | arg_type arg; | ||
691 | 192 | hs_longrun_stat stat; | ||
692 | 193 | drand48_data randbuf; | ||
693 | 194 | unsigned int seed; | ||
694 | 195 | hs_longrun_thread_base(const arg_type& arg) | ||
695 | 196 | : arg(arg), seed(0) { | ||
696 | 197 | seed = time(0) + arg.id + 1; | ||
697 | 198 | srand48_r(seed, &randbuf); | ||
698 | 199 | } | ||
699 | 200 | virtual ~hs_longrun_thread_base() { } | ||
700 | 201 | virtual void run() = 0; | ||
701 | 202 | size_t rand_record() { | ||
702 | 203 | double v = 0; | ||
703 | 204 | drand48_r(&randbuf, &v); | ||
704 | 205 | const size_t sz = arg.sh.records.size(); | ||
705 | 206 | size_t r = size_t(v * sz); | ||
706 | 207 | if (r >= sz) { | ||
707 | 208 | r = 0; | ||
708 | 209 | } | ||
709 | 210 | return r; | ||
710 | 211 | } | ||
711 | 212 | int verify_update(const std::string& k, const std::string& v1, | ||
712 | 213 | const std::string& v2, const std::string& v3, record_value& rec, | ||
713 | 214 | uint32_t num_rows, bool cur_unknown_state); | ||
714 | 215 | int verify_read(const std::string& k, uint32_t num_rows, uint32_t num_flds, | ||
715 | 216 | const std::string rrec[4], record_value& rec); | ||
716 | 217 | int verify_readnolock(const std::string& k, uint32_t num_rows, | ||
717 | 218 | uint32_t num_flds, const std::string rrec[4]); | ||
718 | 219 | }; | ||
719 | 220 | |||
720 | 221 | int | ||
721 | 222 | hs_longrun_thread_base::verify_update(const std::string& k, | ||
722 | 223 | const std::string& v1, const std::string& v2, const std::string& v3, | ||
723 | 224 | record_value& rec, uint32_t num_rows, bool cur_unknown_state) | ||
724 | 225 | { | ||
725 | 226 | const bool op_success = num_rows == 1; | ||
726 | 227 | int ret = 0; | ||
727 | 228 | if (!rec.unknown_state) { | ||
728 | 229 | if (!rec.deleted && !op_success) { | ||
729 | 230 | ++stat.verify_error_count; | ||
730 | 231 | if (arg.sh.verbose > 0) { | ||
731 | 232 | fprintf(stderr, "VERIFY_ERROR: %s wid=%d k=%s " | ||
732 | 233 | "unexpected_update_failure\n", | ||
733 | 234 | arg.worker_type.c_str(), arg.id, k.c_str()); | ||
734 | 235 | } | ||
735 | 236 | ret = 1; | ||
736 | 237 | } else if (rec.deleted && op_success) { | ||
737 | 238 | ++stat.verify_error_count; | ||
738 | 239 | if (arg.sh.verbose > 0) { | ||
739 | 240 | fprintf(stderr, "VERIFY_ERROR: %s wid=%d k=%s " | ||
740 | 241 | "unexpected_update_success\n", | ||
741 | 242 | arg.worker_type.c_str(), arg.id, k.c_str()); | ||
742 | 243 | } | ||
743 | 244 | ret = 1; | ||
744 | 245 | } | ||
745 | 246 | } | ||
746 | 247 | if (op_success) { | ||
747 | 248 | rec.values.resize(4); | ||
748 | 249 | rec.values[0] = k; | ||
749 | 250 | rec.values[1] = v1; | ||
750 | 251 | rec.values[2] = v2; | ||
751 | 252 | rec.values[3] = v3; | ||
752 | 253 | if (ret == 0 && !rec.unknown_state) { | ||
753 | 254 | ++stat.success_count; | ||
754 | 255 | } | ||
755 | 256 | } | ||
756 | 257 | rec.unknown_state = cur_unknown_state; | ||
757 | 258 | if (arg.sh.verbose >= 100 && ret == 0) { | ||
758 | 259 | fprintf(stderr, "%s %s %s %s %s\n", arg.worker_type.c_str(), | ||
759 | 260 | k.c_str(), v1.c_str(), v2.c_str(), v3.c_str()); | ||
760 | 261 | } | ||
761 | 262 | return ret; | ||
762 | 263 | } | ||
763 | 264 | |||
764 | 265 | int | ||
765 | 266 | hs_longrun_thread_base::verify_read(const std::string& k, | ||
766 | 267 | uint32_t num_rows, uint32_t num_flds, const std::string rrec[4], | ||
767 | 268 | record_value& rec) | ||
768 | 269 | { | ||
769 | 270 | const bool op_success = num_rows != 0; | ||
770 | 271 | int ret = 0; | ||
771 | 272 | if (!rec.unknown_state) { | ||
772 | 273 | if (!rec.deleted && !op_success) { | ||
773 | 274 | ++stat.verify_error_count; | ||
774 | 275 | if (arg.sh.verbose > 0) { | ||
775 | 276 | fprintf(stderr, "VERIFY_ERROR: %s wid=%d k=%s " | ||
776 | 277 | "unexpected_read_failure\n", | ||
777 | 278 | arg.worker_type.c_str(), arg.id, k.c_str()); | ||
778 | 279 | } | ||
779 | 280 | ret = 1; | ||
780 | 281 | } else if (rec.deleted && op_success) { | ||
781 | 282 | ++stat.verify_error_count; | ||
782 | 283 | if (arg.sh.verbose > 0) { | ||
783 | 284 | fprintf(stderr, "VERIFY_ERROR: %s wid=%d k=%s " | ||
784 | 285 | "unexpected_read_success\n", | ||
785 | 286 | arg.worker_type.c_str(), arg.id, k.c_str()); | ||
786 | 287 | } | ||
787 | 288 | ret = 1; | ||
788 | 289 | } else if (num_flds != 4) { | ||
789 | 290 | ++stat.verify_error_count; | ||
790 | 291 | if (arg.sh.verbose > 0) { | ||
791 | 292 | fprintf(stderr, "VERIFY_ERROR: %s wid=%d k=%s " | ||
792 | 293 | "unexpected_read_fldnum %d\n", | ||
793 | 294 | arg.worker_type.c_str(), arg.id, k.c_str(), | ||
794 | 295 | static_cast<int>(num_flds)); | ||
795 | 296 | } | ||
796 | 297 | ret = 1; | ||
797 | 298 | } else if (rec.deleted) { | ||
798 | 299 | /* nothing to verify */ | ||
799 | 300 | } else { | ||
800 | 301 | int diff = 0; | ||
801 | 302 | for (size_t i = 0; i < 4; ++i) { | ||
802 | 303 | if (rec.values[i] == rrec[i]) { | ||
803 | 304 | /* ok */ | ||
804 | 305 | } else { | ||
805 | 306 | diff = 1; | ||
806 | 307 | } | ||
807 | 308 | } | ||
808 | 309 | if (diff) { | ||
809 | 310 | std::string mess; | ||
810 | 311 | for (size_t i = 0; i < 4; ++i) { | ||
811 | 312 | const std::string& expected = rec.values[i]; | ||
812 | 313 | const std::string& val = rrec[i]; | ||
813 | 314 | mess += " " + val + "/" + expected; | ||
814 | 315 | } | ||
815 | 316 | if (arg.sh.verbose > 0) { | ||
816 | 317 | fprintf(stderr, "VERIFY_ERROR: %s wid=%d k=%s " | ||
817 | 318 | "unexpected_read_value %s\n", | ||
818 | 319 | arg.worker_type.c_str(), arg.id, k.c_str(), mess.c_str()); | ||
819 | 320 | } | ||
820 | 321 | ret = 1; | ||
821 | 322 | } | ||
822 | 323 | } | ||
823 | 324 | } | ||
824 | 325 | if (arg.sh.verbose >= 100 && ret == 0) { | ||
825 | 326 | fprintf(stderr, "%s %s\n", arg.worker_type.c_str(), k.c_str()); | ||
826 | 327 | } | ||
827 | 328 | if (ret == 0 && !rec.unknown_state) { | ||
828 | 329 | ++stat.success_count; | ||
829 | 330 | } | ||
830 | 331 | return ret; | ||
831 | 332 | } | ||
832 | 333 | |||
833 | 334 | int | ||
834 | 335 | hs_longrun_thread_base::verify_readnolock(const std::string& k, | ||
835 | 336 | uint32_t num_rows, uint32_t num_flds, const std::string rrec[4]) | ||
836 | 337 | { | ||
837 | 338 | int ret = 0; | ||
838 | 339 | if (num_rows != 1 || num_flds != 4) { | ||
839 | 340 | ++stat.verify_error_count; | ||
840 | 341 | if (arg.sh.verbose > 0) { | ||
841 | 342 | fprintf(stderr, "VERIFY_ERROR: %s wid=%d k=%s " | ||
842 | 343 | "unexpected_read_failure\n", | ||
843 | 344 | arg.worker_type.c_str(), arg.id, k.c_str()); | ||
844 | 345 | } | ||
845 | 346 | ret = 1; | ||
846 | 347 | } | ||
847 | 348 | if (arg.sh.verbose >= 100 && ret == 0) { | ||
848 | 349 | fprintf(stderr, "%s -> %s %s %s %s %s\n", arg.worker_type.c_str(), | ||
849 | 350 | k.c_str(), rrec[0].c_str(), rrec[1].c_str(), rrec[2].c_str(), | ||
850 | 351 | rrec[3].c_str()); | ||
851 | 352 | } | ||
852 | 353 | if (ret == 0) { | ||
853 | 354 | ++stat.success_count; | ||
854 | 355 | } | ||
855 | 356 | return ret; | ||
856 | 357 | } | ||
857 | 358 | |||
858 | 359 | struct hs_longrun_thread_hs : public hs_longrun_thread_base { | ||
859 | 360 | hs_longrun_thread_hs(const arg_type& arg) | ||
860 | 361 | : hs_longrun_thread_base(arg) { } | ||
861 | 362 | void run(); | ||
862 | 363 | int check_hs_error(const char *mess, record_value *rec); | ||
863 | 364 | int op_insert(record_value& rec); | ||
864 | 365 | int op_delete(record_value& rec); | ||
865 | 366 | int op_update(record_value& rec); | ||
866 | 367 | int op_read(record_value& rec); | ||
867 | 368 | int op_readnolock(int k); | ||
868 | 369 | hstcpcli_ptr cli; | ||
869 | 370 | socket_args sockargs; | ||
870 | 371 | }; | ||
871 | 372 | |||
872 | 373 | struct lock_guard : noncopyable { | ||
873 | 374 | lock_guard(mutex& mtx) : mtx(mtx) { | ||
874 | 375 | mtx.lock(); | ||
875 | 376 | } | ||
876 | 377 | ~lock_guard() { | ||
877 | 378 | mtx.unlock(); | ||
878 | 379 | } | ||
879 | 380 | mutex& mtx; | ||
880 | 381 | }; | ||
881 | 382 | |||
882 | 383 | string_ref | ||
883 | 384 | to_string_ref(const std::string& s) | ||
884 | 385 | { | ||
885 | 386 | return string_ref(s.data(), s.size()); | ||
886 | 387 | } | ||
887 | 388 | |||
888 | 389 | std::string | ||
889 | 390 | to_string(const string_ref& s) | ||
890 | 391 | { | ||
891 | 392 | return std::string(s.begin(), s.size()); | ||
892 | 393 | } | ||
893 | 394 | |||
894 | 395 | void | ||
895 | 396 | hs_longrun_thread_hs::run() | ||
896 | 397 | { | ||
897 | 398 | config c = arg.sh.conf; | ||
898 | 399 | if (arg.op == 'R' || arg.op == 'N') { | ||
899 | 400 | c["port"] = to_stdstring(arg.sh.conf.get_int("hsport", 9998)); | ||
900 | 401 | } else { | ||
901 | 402 | c["port"] = to_stdstring(arg.sh.conf.get_int("hsport_wr", 9999)); | ||
902 | 403 | } | ||
903 | 404 | sockargs.set(c); | ||
904 | 405 | |||
905 | 406 | while (arg.sh.running) { | ||
906 | 407 | if (cli.get() == 0 || !cli->stable_point()) { | ||
907 | 408 | cli = hstcpcli_i::create(sockargs); | ||
908 | 409 | if (check_hs_error("connect", 0) != 0) { | ||
909 | 410 | cli.reset(); | ||
910 | 411 | continue; | ||
911 | 412 | } | ||
912 | 413 | cli->request_buf_open_index(0, "hstestdb", "hstesttbl", "PRIMARY", | ||
913 | 414 | "k,v1,v2,v3", "k,v1,v2,v3"); | ||
914 | 415 | cli->request_send(); | ||
915 | 416 | if (check_hs_error("openindex_send", 0) != 0) { | ||
916 | 417 | cli.reset(); | ||
917 | 418 | continue; | ||
918 | 419 | } | ||
919 | 420 | size_t num_flds = 0; | ||
920 | 421 | cli->response_recv(num_flds); | ||
921 | 422 | if (check_hs_error("openindex_recv", 0) != 0) { | ||
922 | 423 | cli.reset(); | ||
923 | 424 | continue; | ||
924 | 425 | } | ||
925 | 426 | cli->response_buf_remove(); | ||
926 | 427 | } | ||
927 | 428 | const size_t rec_id = rand_record(); | ||
928 | 429 | if (arg.lock_flag) { | ||
929 | 430 | record_value& rec = *arg.sh.records[rec_id]; | ||
930 | 431 | lock_guard g(rec.lock); | ||
931 | 432 | int e = 0; | ||
932 | 433 | switch (arg.op) { | ||
933 | 434 | case 'I': | ||
934 | 435 | e = op_insert(rec); | ||
935 | 436 | break; | ||
936 | 437 | case 'D': | ||
937 | 438 | e = op_delete(rec); | ||
938 | 439 | break; | ||
939 | 440 | case 'U': | ||
940 | 441 | e = op_update(rec); | ||
941 | 442 | break; | ||
942 | 443 | case 'R': | ||
943 | 444 | e = op_read(rec); | ||
944 | 445 | break; | ||
945 | 446 | default: | ||
946 | 447 | break; | ||
947 | 448 | } | ||
948 | 449 | } else { | ||
949 | 450 | int e = 0; | ||
950 | 451 | switch (arg.op) { | ||
951 | 452 | case 'N': | ||
952 | 453 | e = op_readnolock(rec_id); | ||
953 | 454 | break; | ||
954 | 455 | default: | ||
955 | 456 | break; | ||
956 | 457 | } | ||
957 | 458 | } | ||
958 | 459 | } | ||
959 | 460 | } | ||
960 | 461 | |||
961 | 462 | int | ||
962 | 463 | hs_longrun_thread_hs::op_insert(record_value& rec) | ||
963 | 464 | { | ||
964 | 465 | const std::string k = rec.key; | ||
965 | 466 | const std::string v1 = "iv1_" + k + "_" + to_stdstring(arg.id); | ||
966 | 467 | const std::string v2 = "iv2_" + k + "_" + to_stdstring(arg.id); | ||
967 | 468 | const std::string v3 = "iv3_" + k + "_" + to_stdstring(arg.id); | ||
968 | 469 | const string_ref op_ref("+", 1); | ||
969 | 470 | const string_ref op_args[4] = { | ||
970 | 471 | to_string_ref(k), | ||
971 | 472 | to_string_ref(v1), | ||
972 | 473 | to_string_ref(v2), | ||
973 | 474 | to_string_ref(v3) | ||
974 | 475 | }; | ||
975 | 476 | cli->request_buf_exec_generic(0, op_ref, op_args, 4, 1, 0, | ||
976 | 477 | string_ref(), 0, 0, 0, 0); | ||
977 | 478 | cli->request_send(); | ||
978 | 479 | if (check_hs_error("op_insert_send", &rec) != 0) { return 1; } | ||
979 | 480 | size_t numflds = 0; | ||
980 | 481 | cli->response_recv(numflds); | ||
981 | 482 | if (arg.sh.verbose > 10) { | ||
982 | 483 | const string_ref *row = cli->get_next_row(); | ||
983 | 484 | fprintf(stderr, "HS op=+ errrcode=%d errmess=[%s]\n", cli->get_error_code(), | ||
984 | 485 | row ? to_string(row[0]).c_str() : ""); | ||
985 | 486 | } | ||
986 | 487 | const bool op_success = cli->get_error_code() == 0; | ||
987 | 488 | int ret = 0; | ||
988 | 489 | if (!rec.unknown_state) { | ||
989 | 490 | if (rec.deleted && !op_success) { | ||
990 | 491 | ++stat.verify_error_count; | ||
991 | 492 | if (arg.sh.verbose > 0) { | ||
992 | 493 | fprintf(stderr, "VERIFY_ERROR: %s wid=%d k=%s " | ||
993 | 494 | "unexpected_insert_failure\n", | ||
994 | 495 | arg.worker_type.c_str(), arg.id, k.c_str()); | ||
995 | 496 | } | ||
996 | 497 | ret = 1; | ||
997 | 498 | } else if (!rec.deleted && op_success) { | ||
998 | 499 | ++stat.verify_error_count; | ||
999 | 500 | if (arg.sh.verbose > 0) { | ||
1000 | 501 | fprintf(stderr, "VERIFY_ERROR: %s wid=%d k=%s " | ||
1001 | 502 | "unexpected_insert_success\n", | ||
1002 | 503 | arg.worker_type.c_str(), arg.id, k.c_str()); | ||
1003 | 504 | } | ||
1004 | 505 | ret = 1; | ||
1005 | 506 | } | ||
1006 | 507 | } else { | ||
1007 | 508 | ++stat.unknown_count; | ||
1008 | 509 | } | ||
1009 | 510 | if (op_success) { | ||
1010 | 511 | rec.values.resize(4); | ||
1011 | 512 | rec.values[0] = k; | ||
1012 | 513 | rec.values[1] = v1; | ||
1013 | 514 | rec.values[2] = v2; | ||
1014 | 515 | rec.values[3] = v3; | ||
1015 | 516 | rec.deleted = false; | ||
1016 | 517 | if (arg.sh.verbose >= 100 && ret == 0) { | ||
1017 | 518 | fprintf(stderr, "HS_INSERT %s %s %s %s\n", k.c_str(), v1.c_str(), | ||
1018 | 519 | v2.c_str(), v3.c_str()); | ||
1019 | 520 | } | ||
1020 | 521 | if (ret == 0 && !rec.unknown_state) { | ||
1021 | 522 | ++stat.success_count; | ||
1022 | 523 | } | ||
1023 | 524 | rec.unknown_state = false; | ||
1024 | 525 | } | ||
1025 | 526 | cli->response_buf_remove(); | ||
1026 | 527 | return ret; | ||
1027 | 528 | } | ||
1028 | 529 | |||
1029 | 530 | int | ||
1030 | 531 | hs_longrun_thread_hs::op_delete(record_value& rec) | ||
1031 | 532 | { | ||
1032 | 533 | const std::string k = rec.key; | ||
1033 | 534 | const string_ref op_ref("=", 1); | ||
1034 | 535 | const string_ref op_args[1] = { | ||
1035 | 536 | to_string_ref(k), | ||
1036 | 537 | }; | ||
1037 | 538 | const string_ref modop_ref("D", 1); | ||
1038 | 539 | cli->request_buf_exec_generic(0, op_ref, op_args, 1, 1, 0, | ||
1039 | 540 | modop_ref, 0, 0, 0, 0); | ||
1040 | 541 | cli->request_send(); | ||
1041 | 542 | if (check_hs_error("op_delete_send", &rec) != 0) { return 1; } | ||
1042 | 543 | size_t numflds = 0; | ||
1043 | 544 | cli->response_recv(numflds); | ||
1044 | 545 | if (check_hs_error("op_delete_recv", &rec) != 0) { return 1; } | ||
1045 | 546 | const string_ref *row = cli->get_next_row(); | ||
1046 | 547 | const bool op_success = (numflds > 0 && row != 0 && | ||
1047 | 548 | to_string(row[0]) == "1"); | ||
1048 | 549 | int ret = 0; | ||
1049 | 550 | if (!rec.unknown_state) { | ||
1050 | 551 | if (!rec.deleted && !op_success) { | ||
1051 | 552 | ++stat.verify_error_count; | ||
1052 | 553 | if (arg.sh.verbose > 0) { | ||
1053 | 554 | fprintf(stderr, "VERIFY_ERROR: %s wid=%d k=%s " | ||
1054 | 555 | "unexpected_delete_failure\n", | ||
1055 | 556 | arg.worker_type.c_str(), arg.id, k.c_str()); | ||
1056 | 557 | } | ||
1057 | 558 | ret = 1; | ||
1058 | 559 | } else if (rec.deleted && op_success) { | ||
1059 | 560 | ++stat.verify_error_count; | ||
1060 | 561 | if (arg.sh.verbose > 0) { | ||
1061 | 562 | fprintf(stderr, "VERIFY_ERROR: %s wid=%d k=%s " | ||
1062 | 563 | "unexpected_delete_success\n", | ||
1063 | 564 | arg.worker_type.c_str(), arg.id, k.c_str()); | ||
1064 | 565 | } | ||
1065 | 566 | ret = 1; | ||
1066 | 567 | } | ||
1067 | 568 | } | ||
1068 | 569 | cli->response_buf_remove(); | ||
1069 | 570 | if (op_success) { | ||
1070 | 571 | rec.deleted = true; | ||
1071 | 572 | if (ret == 0 && !rec.unknown_state) { | ||
1072 | 573 | ++stat.success_count; | ||
1073 | 574 | } | ||
1074 | 575 | rec.unknown_state = false; | ||
1075 | 576 | } | ||
1076 | 577 | if (arg.sh.verbose >= 100 && ret == 0) { | ||
1077 | 578 | fprintf(stderr, "HS_DELETE %s\n", k.c_str()); | ||
1078 | 579 | } | ||
1079 | 580 | return ret; | ||
1080 | 581 | } | ||
1081 | 582 | |||
1082 | 583 | int | ||
1083 | 584 | hs_longrun_thread_hs::op_update(record_value& rec) | ||
1084 | 585 | { | ||
1085 | 586 | const std::string k = rec.key; | ||
1086 | 587 | const std::string v1 = "uv1_" + k + "_" + to_stdstring(arg.id); | ||
1087 | 588 | const std::string v2 = "uv2_" + k + "_" + to_stdstring(arg.id); | ||
1088 | 589 | const std::string v3 = "uv3_" + k + "_" + to_stdstring(arg.id); | ||
1089 | 590 | const string_ref op_ref("=", 1); | ||
1090 | 591 | const string_ref op_args[1] = { | ||
1091 | 592 | to_string_ref(k), | ||
1092 | 593 | }; | ||
1093 | 594 | const string_ref modop_ref("U", 1); | ||
1094 | 595 | const string_ref modop_args[4] = { | ||
1095 | 596 | to_string_ref(k), | ||
1096 | 597 | to_string_ref(v1), | ||
1097 | 598 | to_string_ref(v2), | ||
1098 | 599 | to_string_ref(v3) | ||
1099 | 600 | }; | ||
1100 | 601 | cli->request_buf_exec_generic(0, op_ref, op_args, 1, 1, 0, | ||
1101 | 602 | modop_ref, modop_args, 4, 0, 0); | ||
1102 | 603 | cli->request_send(); | ||
1103 | 604 | if (check_hs_error("op_update_send", &rec) != 0) { return 1; } | ||
1104 | 605 | size_t numflds = 0; | ||
1105 | 606 | cli->response_recv(numflds); | ||
1106 | 607 | if (check_hs_error("op_update_recv", &rec) != 0) { return 1; } | ||
1107 | 608 | const string_ref *row = cli->get_next_row(); | ||
1108 | 609 | uint32_t num_rows = row | ||
1109 | 610 | ? atoi_uint32_nocheck(row[0].begin(), row[0].end()) : 0; | ||
1110 | 611 | cli->response_buf_remove(); | ||
1111 | 612 | const bool cur_unknown_state = (num_rows == 1); | ||
1112 | 613 | return verify_update(k, v1, v2, v3, rec, num_rows, cur_unknown_state); | ||
1113 | 614 | } | ||
1114 | 615 | |||
1115 | 616 | int | ||
1116 | 617 | hs_longrun_thread_hs::op_read(record_value& rec) | ||
1117 | 618 | { | ||
1118 | 619 | const std::string k = rec.key; | ||
1119 | 620 | const string_ref op_ref("=", 1); | ||
1120 | 621 | const string_ref op_args[1] = { | ||
1121 | 622 | to_string_ref(k), | ||
1122 | 623 | }; | ||
1123 | 624 | cli->request_buf_exec_generic(0, op_ref, op_args, 1, 1, 0, | ||
1124 | 625 | string_ref(), 0, 0, 0, 0); | ||
1125 | 626 | cli->request_send(); | ||
1126 | 627 | if (check_hs_error("op_read_send", 0) != 0) { return 1; } | ||
1127 | 628 | size_t num_flds = 0; | ||
1128 | 629 | size_t num_rows = 0; | ||
1129 | 630 | cli->response_recv(num_flds); | ||
1130 | 631 | if (check_hs_error("op_read_recv", 0) != 0) { return 1; } | ||
1131 | 632 | const string_ref *row = cli->get_next_row(); | ||
1132 | 633 | std::string rrec[4]; | ||
1133 | 634 | if (row != 0 && num_flds == 4) { | ||
1134 | 635 | for (int i = 0; i < 4; ++i) { | ||
1135 | 636 | rrec[i] = to_string(row[i]); | ||
1136 | 637 | } | ||
1137 | 638 | ++num_rows; | ||
1138 | 639 | } | ||
1139 | 640 | row = cli->get_next_row(); | ||
1140 | 641 | if (row != 0) { | ||
1141 | 642 | ++num_rows; | ||
1142 | 643 | } | ||
1143 | 644 | cli->response_buf_remove(); | ||
1144 | 645 | return verify_read(k, num_rows, num_flds, rrec, rec); | ||
1145 | 646 | } | ||
1146 | 647 | |||
1147 | 648 | int | ||
1148 | 649 | hs_longrun_thread_hs::op_readnolock(int key) | ||
1149 | 650 | { | ||
1150 | 651 | const std::string k = to_stdstring(key); | ||
1151 | 652 | const string_ref op_ref("=", 1); | ||
1152 | 653 | const string_ref op_args[1] = { | ||
1153 | 654 | to_string_ref(k), | ||
1154 | 655 | }; | ||
1155 | 656 | cli->request_buf_exec_generic(0, op_ref, op_args, 1, 1, 0, | ||
1156 | 657 | string_ref(), 0, 0, 0, 0); | ||
1157 | 658 | cli->request_send(); | ||
1158 | 659 | if (check_hs_error("op_read_send", 0) != 0) { return 1; } | ||
1159 | 660 | size_t num_flds = 0; | ||
1160 | 661 | size_t num_rows = 0; | ||
1161 | 662 | cli->response_recv(num_flds); | ||
1162 | 663 | if (check_hs_error("op_read_recv", 0) != 0) { return 1; } | ||
1163 | 664 | const string_ref *row = cli->get_next_row(); | ||
1164 | 665 | std::string rrec[4]; | ||
1165 | 666 | if (row != 0 && num_flds == 4) { | ||
1166 | 667 | for (int i = 0; i < 4; ++i) { | ||
1167 | 668 | rrec[i] = to_string(row[i]); | ||
1168 | 669 | } | ||
1169 | 670 | ++num_rows; | ||
1170 | 671 | } | ||
1171 | 672 | row = cli->get_next_row(); | ||
1172 | 673 | if (row != 0) { | ||
1173 | 674 | ++num_rows; | ||
1174 | 675 | } | ||
1175 | 676 | cli->response_buf_remove(); | ||
1176 | 677 | return verify_readnolock(k, num_rows, num_flds, rrec); | ||
1177 | 678 | } | ||
1178 | 679 | |||
1179 | 680 | int | ||
1180 | 681 | hs_longrun_thread_hs::check_hs_error(const char *mess, record_value *rec) | ||
1181 | 682 | { | ||
1182 | 683 | const int err = cli->get_error_code(); | ||
1183 | 684 | if (err == 0) { | ||
1184 | 685 | return 0; | ||
1185 | 686 | } | ||
1186 | 687 | ++stat.runtime_error_count; | ||
1187 | 688 | if (arg.sh.verbose > 0) { | ||
1188 | 689 | const std::string estr = cli->get_error(); | ||
1189 | 690 | fprintf(stderr, "RUNTIME_ERROR: op=%c wid=%d %s: %d %s\n", | ||
1190 | 691 | arg.op, arg.id, mess, err, estr.c_str()); | ||
1191 | 692 | } | ||
1192 | 693 | if (rec) { | ||
1193 | 694 | rec->unknown_state = true; | ||
1194 | 695 | } | ||
1195 | 696 | return 1; | ||
1196 | 697 | } | ||
1197 | 698 | |||
1198 | 699 | struct hs_longrun_thread_my : public hs_longrun_thread_base { | ||
1199 | 700 | hs_longrun_thread_my(const arg_type& arg) | ||
1200 | 701 | : hs_longrun_thread_base(arg), connected(false) { } | ||
1201 | 702 | void run(); | ||
1202 | 703 | void show_mysql_error(const char *mess, record_value *rec); | ||
1203 | 704 | int op_insert(record_value& rec); | ||
1204 | 705 | int op_delete(record_value& rec); | ||
1205 | 706 | int op_update(record_value& rec); | ||
1206 | 707 | int op_delins(record_value& rec); | ||
1207 | 708 | int op_read(record_value& rec); | ||
1208 | 709 | auto_mysql db; | ||
1209 | 710 | bool connected; | ||
1210 | 711 | }; | ||
1211 | 712 | |||
1212 | 713 | void | ||
1213 | 714 | hs_longrun_thread_my::run() | ||
1214 | 715 | { | ||
1215 | 716 | const std::string mysql_host = arg.sh.conf.get_str("host", "localhost"); | ||
1216 | 717 | const std::string mysql_user = arg.sh.conf.get_str("mysqluser", "root"); | ||
1217 | 718 | const std::string mysql_passwd = arg.sh.conf.get_str("mysqlpass", ""); | ||
1218 | 719 | const std::string mysql_dbname = "hstestdb"; | ||
1219 | 720 | |||
1220 | 721 | while (arg.sh.running) { | ||
1221 | 722 | if (!connected) { | ||
1222 | 723 | if (!mysql_real_connect(db, mysql_host.c_str(), mysql_user.c_str(), | ||
1223 | 724 | mysql_passwd.c_str(), mysql_dbname.c_str(), mysql_port, 0, 0)) { | ||
1224 | 725 | show_mysql_error("mysql_real_connect", 0); | ||
1225 | 726 | continue; | ||
1226 | 727 | } | ||
1227 | 728 | } | ||
1228 | 729 | connected = true; | ||
1229 | 730 | const size_t rec_id = rand_record(); | ||
1230 | 731 | record_value& rec = *arg.sh.records[rec_id]; | ||
1231 | 732 | lock_guard g(rec.lock); | ||
1232 | 733 | int e = 0; | ||
1233 | 734 | switch (arg.op) { | ||
1234 | 735 | #if 0 | ||
1235 | 736 | case 'I': | ||
1236 | 737 | e = op_insert(rec); | ||
1237 | 738 | break; | ||
1238 | 739 | case 'D': | ||
1239 | 740 | e = op_delete(rec); | ||
1240 | 741 | break; | ||
1241 | 742 | case 'U': | ||
1242 | 743 | e = op_update(rec); | ||
1243 | 744 | break; | ||
1244 | 745 | #endif | ||
1245 | 746 | case 'T': | ||
1246 | 747 | e = op_delins(rec); | ||
1247 | 748 | break; | ||
1248 | 749 | case 'R': | ||
1249 | 750 | e = op_read(rec); | ||
1250 | 751 | break; | ||
1251 | 752 | default: | ||
1252 | 753 | break; | ||
1253 | 754 | } | ||
1254 | 755 | } | ||
1255 | 756 | } | ||
1256 | 757 | |||
1257 | 758 | int | ||
1258 | 759 | hs_longrun_thread_my::op_delins(record_value& rec) | ||
1259 | 760 | { | ||
1260 | 761 | const std::string k = rec.key; | ||
1261 | 762 | const std::string v1 = "div1_" + k + "_" + to_stdstring(arg.id); | ||
1262 | 763 | const std::string v2 = "div2_" + k + "_" + to_stdstring(arg.id); | ||
1263 | 764 | const std::string v3 = "div3_" + k + "_" + to_stdstring(arg.id); | ||
1264 | 765 | int success = 0; | ||
1265 | 766 | bool cur_unknown_state = false; | ||
1266 | 767 | do { | ||
1267 | 768 | char query[1024]; | ||
1268 | 769 | #if 1 | ||
1269 | 770 | if (mysql_query(db, "begin") != 0) { | ||
1270 | 771 | if (arg.sh.verbose >= 20) { | ||
1271 | 772 | fprintf(stderr, "mysql: e=[%s] q=[%s]\n", mysql_error(db), "begin"); | ||
1272 | 773 | } | ||
1273 | 774 | break; | ||
1274 | 775 | } | ||
1275 | 776 | #endif | ||
1276 | 777 | cur_unknown_state = true; | ||
1277 | 778 | snprintf(query, 1024, | ||
1278 | 779 | "delete from hstesttbl where k = '%s'", k.c_str()); | ||
1279 | 780 | if (mysql_query(db, query) != 0) { | ||
1280 | 781 | if (arg.sh.verbose >= 20) { | ||
1281 | 782 | fprintf(stderr, "mysql: e=[%s] q=[%s]\n", mysql_error(db), query); | ||
1282 | 783 | } | ||
1283 | 784 | break; | ||
1284 | 785 | } | ||
1285 | 786 | if (mysql_affected_rows(db) != 1) { | ||
1286 | 787 | if (arg.sh.verbose >= 20) { | ||
1287 | 788 | fprintf(stderr, "mysql: notfound: [%s]\n", query); | ||
1288 | 789 | } | ||
1289 | 790 | break; | ||
1290 | 791 | } | ||
1291 | 792 | snprintf(query, 1024, | ||
1292 | 793 | "insert into hstesttbl values ('%s', '%s', '%s', '%s')", | ||
1293 | 794 | k.c_str(), v1.c_str(), v2.c_str(), v3.c_str()); | ||
1294 | 795 | if (mysql_query(db, query) != 0) { | ||
1295 | 796 | if (arg.sh.verbose >= 20) { | ||
1296 | 797 | fprintf(stderr, "mysql: e=[%s] q=[%s]\n", mysql_error(db), query); | ||
1297 | 798 | } | ||
1298 | 799 | break; | ||
1299 | 800 | } | ||
1300 | 801 | #if 1 | ||
1301 | 802 | if (mysql_query(db, "commit") != 0) { | ||
1302 | 803 | if (arg.sh.verbose >= 20) { | ||
1303 | 804 | fprintf(stderr, "mysql: e=[%s] q=[%s]\n", mysql_error(db), "commit"); | ||
1304 | 805 | } | ||
1305 | 806 | break; | ||
1306 | 807 | } | ||
1307 | 808 | #endif | ||
1308 | 809 | success = true; | ||
1309 | 810 | cur_unknown_state = false; | ||
1310 | 811 | } while (false); | ||
1311 | 812 | return verify_update(k, v1, v2, v3, rec, (success != 0), cur_unknown_state); | ||
1312 | 813 | } | ||
1313 | 814 | |||
1314 | 815 | int | ||
1315 | 816 | hs_longrun_thread_my::op_read(record_value& rec) | ||
1316 | 817 | { | ||
1317 | 818 | const std::string k = rec.key; | ||
1318 | 819 | char query[1024] = { 0 }; | ||
1319 | 820 | const int len = snprintf(query, 1024, | ||
1320 | 821 | "select k,v1,v2,v3 from hstesttbl where k='%s'", k.c_str()); | ||
1321 | 822 | const int r = mysql_real_query(db, query, len > 0 ? len : 0); | ||
1322 | 823 | if (r != 0) { | ||
1323 | 824 | show_mysql_error(query, 0); | ||
1324 | 825 | return 1; | ||
1325 | 826 | } | ||
1326 | 827 | MYSQL_ROW row = 0; | ||
1327 | 828 | unsigned long *lengths = 0; | ||
1328 | 829 | unsigned int num_rows = 0; | ||
1329 | 830 | unsigned int num_flds = 0; | ||
1330 | 831 | auto_mysql_res res(db); | ||
1331 | 832 | std::string rrec[4]; | ||
1332 | 833 | if (res != 0) { | ||
1333 | 834 | num_flds = mysql_num_fields(res); | ||
1334 | 835 | row = mysql_fetch_row(res); | ||
1335 | 836 | if (row != 0) { | ||
1336 | 837 | lengths = mysql_fetch_lengths(res); | ||
1337 | 838 | if (num_flds == 4) { | ||
1338 | 839 | for (int i = 0; i < 4; ++i) { | ||
1339 | 840 | rrec[i] = std::string(row[i], lengths[i]); | ||
1340 | 841 | } | ||
1341 | 842 | } | ||
1342 | 843 | ++num_rows; | ||
1343 | 844 | row = mysql_fetch_row(res); | ||
1344 | 845 | if (row != 0) { | ||
1345 | 846 | ++num_rows; | ||
1346 | 847 | } | ||
1347 | 848 | } | ||
1348 | 849 | } | ||
1349 | 850 | return verify_read(k, num_rows, num_flds, rrec, rec); | ||
1350 | 851 | } | ||
1351 | 852 | |||
1352 | 853 | void | ||
1353 | 854 | hs_longrun_thread_my::show_mysql_error(const char *mess, record_value *rec) | ||
1354 | 855 | { | ||
1355 | 856 | ++stat.runtime_error_count; | ||
1356 | 857 | if (arg.sh.verbose > 0) { | ||
1357 | 858 | fprintf(stderr, "RUNTIME_ERROR: op=%c wid=%d [%s]: %s\n", | ||
1358 | 859 | arg.op, arg.id, mess, mysql_error(db)); | ||
1359 | 860 | } | ||
1360 | 861 | if (rec) { | ||
1361 | 862 | rec->unknown_state = true; | ||
1362 | 863 | } | ||
1363 | 864 | db.reset(); | ||
1364 | 865 | connected = false; | ||
1365 | 866 | } | ||
1366 | 867 | |||
1367 | 868 | void | ||
1368 | 869 | mysql_do(MYSQL *db, const char *query) | ||
1369 | 870 | { | ||
1370 | 871 | if (mysql_real_query(db, query, strlen(query)) != 0) { | ||
1371 | 872 | fprintf(stderr, "mysql: e=[%s] q=[%s]\n", mysql_error(db), query); | ||
1372 | 873 | fatal_exit("mysql_do"); | ||
1373 | 874 | } | ||
1374 | 875 | } | ||
1375 | 876 | |||
1376 | 877 | void | ||
1377 | 878 | hs_longrun_init_table(const config& conf, int num_prepare, | ||
1378 | 879 | hs_longrun_shared& shared) | ||
1379 | 880 | { | ||
1380 | 881 | const std::string mysql_host = conf.get_str("host", "localhost"); | ||
1381 | 882 | const std::string mysql_user = conf.get_str("mysqluser", "root"); | ||
1382 | 883 | const std::string mysql_passwd = conf.get_str("mysqlpass", ""); | ||
1383 | 884 | const std::string mysql_dbname = ""; | ||
1384 | 885 | auto_mysql db; | ||
1385 | 886 | if (!mysql_real_connect(db, mysql_host.c_str(), mysql_user.c_str(), | ||
1386 | 887 | mysql_passwd.c_str(), mysql_dbname.c_str(), mysql_port, 0, 0)) { | ||
1387 | 888 | fprintf(stderr, "mysql: error=[%s]\n", mysql_error(db)); | ||
1388 | 889 | fatal_exit("hs_longrun_init_table"); | ||
1389 | 890 | } | ||
1390 | 891 | mysql_do(db, "drop database if exists hstestdb"); | ||
1391 | 892 | mysql_do(db, "create database hstestdb"); | ||
1392 | 893 | mysql_do(db, "use hstestdb"); | ||
1393 | 894 | mysql_do(db, | ||
1394 | 895 | "create table hstesttbl (" | ||
1395 | 896 | "k int primary key," | ||
1396 | 897 | "v1 varchar(32) not null," | ||
1397 | 898 | "v2 varchar(32) not null," | ||
1398 | 899 | "v3 varchar(32) not null" | ||
1399 | 900 | ") character set utf8 collate utf8_bin engine = innodb"); | ||
1400 | 901 | for (int i = 0; i < num_prepare; ++i) { | ||
1401 | 902 | const std::string i_str = to_stdstring(i); | ||
1402 | 903 | const std::string v1 = "pv1_" + i_str; | ||
1403 | 904 | const std::string v2 = "pv2_" + i_str; | ||
1404 | 905 | const std::string v3 = "pv3_" + i_str; | ||
1405 | 906 | char buf[1024]; | ||
1406 | 907 | snprintf(buf, 1024, "insert into hstesttbl(k, v1, v2, v3) values" | ||
1407 | 908 | "(%d, '%s', '%s', '%s')", i, v1.c_str(), v2.c_str(), v3.c_str()); | ||
1408 | 909 | mysql_do(db, buf); | ||
1409 | 910 | record_value *rec = shared.records[i]; | ||
1410 | 911 | rec->key = i_str; | ||
1411 | 912 | rec->values.resize(4); | ||
1412 | 913 | rec->values[0] = i_str; | ||
1413 | 914 | rec->values[1] = v1; | ||
1414 | 915 | rec->values[2] = v2; | ||
1415 | 916 | rec->values[3] = v3; | ||
1416 | 917 | rec->deleted = false; | ||
1417 | 918 | } | ||
1418 | 919 | } | ||
1419 | 920 | |||
1420 | 921 | int | ||
1421 | 922 | hs_longrun_main(int argc, char **argv) | ||
1422 | 923 | { | ||
1423 | 924 | hs_longrun_shared shared; | ||
1424 | 925 | parse_args(argc, argv, shared.conf); | ||
1425 | 926 | shared.conf["host"] = shared.conf.get_str("host", "localhost"); | ||
1426 | 927 | shared.verbose = shared.conf.get_int("verbose", 1); | ||
1427 | 928 | const int table_size = shared.conf.get_int("table_size", 10000); | ||
1428 | 929 | for (int i = 0; i < table_size; ++i) { | ||
1429 | 930 | std::auto_ptr<record_value> rec(new record_value()); | ||
1430 | 931 | rec->key = to_stdstring(i); | ||
1431 | 932 | shared.records.push_back_ptr(rec); | ||
1432 | 933 | } | ||
1433 | 934 | mysql_library_init(0, 0, 0); | ||
1434 | 935 | const int duration = shared.conf.get_int("duration", 10); | ||
1435 | 936 | const int num_hsinsert = shared.conf.get_int("num_hsinsert", 10); | ||
1436 | 937 | const int num_hsdelete = shared.conf.get_int("num_hsdelete", 10); | ||
1437 | 938 | const int num_hsupdate = shared.conf.get_int("num_hsupdate", 10); | ||
1438 | 939 | const int num_hsread = shared.conf.get_int("num_hsread", 10); | ||
1439 | 940 | const int num_myread = shared.conf.get_int("num_myread", 10); | ||
1440 | 941 | const int num_mydelins = shared.conf.get_int("num_mydelins", 10); | ||
1441 | 942 | int num_hsreadnolock = shared.conf.get_int("num_hsreadnolock", 10); | ||
1442 | 943 | const bool always_filled = (num_hsinsert == 0 && num_hsdelete == 0); | ||
1443 | 944 | if (!always_filled) { | ||
1444 | 945 | num_hsreadnolock = 0; | ||
1445 | 946 | } | ||
1446 | 947 | hs_longrun_init_table(shared.conf, always_filled ? table_size : 0, | ||
1447 | 948 | shared); | ||
1448 | 949 | /* create worker threads */ | ||
1449 | 950 | static const struct thrtmpl_type { | ||
1450 | 951 | const char *type; char op; int num; int hs; int lock; | ||
1451 | 952 | } thrtmpl[] = { | ||
1452 | 953 | { "hsinsert", 'I', num_hsinsert, 1, 1 }, | ||
1453 | 954 | { "hsdelete", 'D', num_hsdelete, 1, 1 }, | ||
1454 | 955 | { "hsupdate", 'U', num_hsupdate, 1, 1 }, | ||
1455 | 956 | { "hsread", 'R', num_hsread, 1, 1 }, | ||
1456 | 957 | { "hsreadnolock", 'N', num_hsreadnolock, 1, 0 }, | ||
1457 | 958 | { "myread", 'R', num_myread, 0, 1 }, | ||
1458 | 959 | { "mydelins", 'T', num_mydelins, 0, 1 }, | ||
1459 | 960 | }; | ||
1460 | 961 | typedef auto_ptrcontainer< std::vector<hs_longrun_thread_base *> > thrs_type; | ||
1461 | 962 | thrs_type thrs; | ||
1462 | 963 | for (size_t i = 0; i < sizeof(thrtmpl)/sizeof(thrtmpl[0]); ++i) { | ||
1463 | 964 | const thrtmpl_type& e = thrtmpl[i]; | ||
1464 | 965 | for (int j = 0; j < e.num; ++j) { | ||
1465 | 966 | int id = thrs.size(); | ||
1466 | 967 | const hs_longrun_thread_hs::arg_type arg(id, e.type, e.op, e.lock, | ||
1467 | 968 | shared); | ||
1468 | 969 | std::auto_ptr<hs_longrun_thread_base> thr; | ||
1469 | 970 | if (e.hs) { | ||
1470 | 971 | thr.reset(new hs_longrun_thread_hs(arg)); | ||
1471 | 972 | } else { | ||
1472 | 973 | thr.reset(new hs_longrun_thread_my(arg)); | ||
1473 | 974 | } | ||
1474 | 975 | thrs.push_back_ptr(thr); | ||
1475 | 976 | } | ||
1476 | 977 | } | ||
1477 | 978 | shared.num_threads = thrs.size(); | ||
1478 | 979 | /* start threads */ | ||
1479 | 980 | fprintf(stderr, "START\n"); | ||
1480 | 981 | shared.running = 1; | ||
1481 | 982 | for (size_t i = 0; i < thrs.size(); ++i) { | ||
1482 | 983 | thrs[i]->start(); | ||
1483 | 984 | } | ||
1484 | 985 | /* wait */ | ||
1485 | 986 | sleep(duration); | ||
1486 | 987 | /* stop thread */ | ||
1487 | 988 | shared.running = 0; | ||
1488 | 989 | for (size_t i = 0; i < thrs.size(); ++i) { | ||
1489 | 990 | thrs[i]->join(); | ||
1490 | 991 | } | ||
1491 | 992 | fprintf(stderr, "DONE\n"); | ||
1492 | 993 | /* summary */ | ||
1493 | 994 | typedef std::map<std::string, hs_longrun_stat> stat_map; | ||
1494 | 995 | stat_map sm; | ||
1495 | 996 | for (size_t i = 0; i < thrs.size(); ++i) { | ||
1496 | 997 | hs_longrun_thread_base *const thr = thrs[i]; | ||
1497 | 998 | const std::string wt = thr->arg.worker_type; | ||
1498 | 999 | hs_longrun_stat& v = sm[wt]; | ||
1499 | 1000 | v.add(thr->stat); | ||
1500 | 1001 | } | ||
1501 | 1002 | hs_longrun_stat total; | ||
1502 | 1003 | for (stat_map::const_iterator i = sm.begin(); i != sm.end(); ++i) { | ||
1503 | 1004 | if (i->second.verify_error_count != 0) { | ||
1504 | 1005 | fprintf(stderr, "%s verify_error %llu\n", i->first.c_str(), | ||
1505 | 1006 | i->second.verify_error_count); | ||
1506 | 1007 | } | ||
1507 | 1008 | if (i->second.runtime_error_count) { | ||
1508 | 1009 | fprintf(stderr, "%s runtime_error %llu\n", i->first.c_str(), | ||
1509 | 1010 | i->second.runtime_error_count); | ||
1510 | 1011 | } | ||
1511 | 1012 | if (i->second.unknown_count) { | ||
1512 | 1013 | fprintf(stderr, "%s unknown %llu\n", i->first.c_str(), | ||
1513 | 1014 | i->second.unknown_count); | ||
1514 | 1015 | } | ||
1515 | 1016 | fprintf(stderr, "%s success %llu\n", i->first.c_str(), | ||
1516 | 1017 | i->second.success_count); | ||
1517 | 1018 | total.add(i->second); | ||
1518 | 1019 | } | ||
1519 | 1020 | if (total.verify_error_count != 0) { | ||
1520 | 1021 | fprintf(stderr, "TOTAL verify_error %llu\n", total.verify_error_count); | ||
1521 | 1022 | } | ||
1522 | 1023 | if (total.runtime_error_count != 0) { | ||
1523 | 1024 | fprintf(stderr, "TOTAL runtime_error %llu\n", total.runtime_error_count); | ||
1524 | 1025 | } | ||
1525 | 1026 | if (total.unknown_count != 0) { | ||
1526 | 1027 | fprintf(stderr, "TOTAL unknown %llu\n", total.unknown_count); | ||
1527 | 1028 | } | ||
1528 | 1029 | fprintf(stderr, "TOTAL success %llu\n", total.success_count); | ||
1529 | 1030 | mysql_library_end(); | ||
1530 | 1031 | return 0; | ||
1531 | 1032 | } | ||
1532 | 1033 | |||
1533 | 1034 | }; | ||
1534 | 1035 | |||
1535 | 1036 | int | ||
1536 | 1037 | main(int argc, char **argv) | ||
1537 | 1038 | { | ||
1538 | 1039 | return dena::hs_longrun_main(argc, argv); | ||
1539 | 1040 | } | ||
1540 | 1041 | |||
1541 | 0 | 1042 | ||
1542 | === added file 'HandlerSocket-Plugin-for-MySQL/client/hspool_test.pl' | |||
1543 | --- HandlerSocket-Plugin-for-MySQL/client/hspool_test.pl 1970-01-01 00:00:00 +0000 | |||
1544 | +++ HandlerSocket-Plugin-for-MySQL/client/hspool_test.pl 2011-06-08 01:58:05 +0000 | |||
1545 | @@ -0,0 +1,224 @@ | |||
1546 | 1 | #!/usr/bin/perl | ||
1547 | 2 | |||
1548 | 3 | use strict; | ||
1549 | 4 | use warnings; | ||
1550 | 5 | use DB::HandlerSocket::Pool; | ||
1551 | 6 | use DBI; | ||
1552 | 7 | |||
1553 | 8 | my %conf = (); | ||
1554 | 9 | for my $i (@ARGV) { | ||
1555 | 10 | my ($k, $v) = split(/=/, $i); | ||
1556 | 11 | $conf{$k} = $v; | ||
1557 | 12 | } | ||
1558 | 13 | |||
1559 | 14 | my $verbose = get_conf("verbose", 0); | ||
1560 | 15 | my $actions_str = get_conf("actions", | ||
1561 | 16 | "create,insert,verify,verify2,verify3,verify4,clean"); | ||
1562 | 17 | my $tablesize = get_conf("tablesize", 1000); | ||
1563 | 18 | my $db = get_conf("db", "hstestdb"); | ||
1564 | 19 | my $table = get_conf("table", "testtbl"); | ||
1565 | 20 | my $table_schema = get_conf("table_schema", undef); | ||
1566 | 21 | my $engine = get_conf("engine", "innodb"); | ||
1567 | 22 | my $host = get_conf("host", "localhost"); | ||
1568 | 23 | my $mysqlport = get_conf("mysqlport", 3306); | ||
1569 | 24 | my $hsport_rd = get_conf("hsport_rd", 9998); | ||
1570 | 25 | my $hsport_wr = get_conf("hsport_wr", 9999); | ||
1571 | 26 | my $loop = get_conf("loop", 10000); | ||
1572 | 27 | my $op = get_conf("op", "="); | ||
1573 | 28 | my $ssps = get_conf("ssps", 0); | ||
1574 | 29 | my $num_moreflds = get_conf("moreflds", 0); | ||
1575 | 30 | my $moreflds_prefix = get_conf("moreflds_prefix", "f"); | ||
1576 | 31 | my $mysql_user = 'root'; | ||
1577 | 32 | my $mysql_password = ''; | ||
1578 | 33 | |||
1579 | 34 | my $dsn = "DBI:mysql:database=;host=$host;port=$mysqlport" | ||
1580 | 35 | . ";mysql_server_prepare=$ssps"; | ||
1581 | 36 | my $dbh = DBI->connect($dsn, $mysql_user, $mysql_password, | ||
1582 | 37 | { RaiseError => 1 }); | ||
1583 | 38 | my $hsargs = { 'host' => $host, 'port' => $hsport_rd }; | ||
1584 | 39 | my $hspool = new DB::HandlerSocket::Pool({ | ||
1585 | 40 | hostmap => { | ||
1586 | 41 | "$db.$table" => { | ||
1587 | 42 | host => $host, | ||
1588 | 43 | port => $hsport_rd, | ||
1589 | 44 | }, | ||
1590 | 45 | }, | ||
1591 | 46 | resolve => undef, | ||
1592 | 47 | error => undef, | ||
1593 | 48 | }); | ||
1594 | 49 | $table_schema = "(k int primary key, fc30 varchar(30), ft text)" | ||
1595 | 50 | if (!defined($table_schema)); | ||
1596 | 51 | |||
1597 | 52 | my @actions = split(/,/, $actions_str); | ||
1598 | 53 | for my $action (@actions) { | ||
1599 | 54 | print "ACTION: $action\n"; | ||
1600 | 55 | eval "hstest_$action()"; | ||
1601 | 56 | if ($@) { | ||
1602 | 57 | die $@; | ||
1603 | 58 | } | ||
1604 | 59 | print "ACTION: $action DONE\n"; | ||
1605 | 60 | } | ||
1606 | 61 | |||
1607 | 62 | sub get_conf { | ||
1608 | 63 | my ($key, $def) = @_; | ||
1609 | 64 | my $val = $conf{$key}; | ||
1610 | 65 | if ($val) { | ||
1611 | 66 | print "$key=$val\n"; | ||
1612 | 67 | } else { | ||
1613 | 68 | $val = $def; | ||
1614 | 69 | my $defstr = $def || "(undef)"; | ||
1615 | 70 | print "$key=$defstr(default)\n"; | ||
1616 | 71 | } | ||
1617 | 72 | return $val; | ||
1618 | 73 | } | ||
1619 | 74 | |||
1620 | 75 | sub hstest_create { | ||
1621 | 76 | $dbh->do("drop database if exists $db"); | ||
1622 | 77 | $dbh->do("create database $db"); | ||
1623 | 78 | $dbh->do("use $db"); | ||
1624 | 79 | $dbh->do("create table $table $table_schema engine=$engine"); | ||
1625 | 80 | } | ||
1626 | 81 | |||
1627 | 82 | sub hstest_dump { | ||
1628 | 83 | $dbh->do("use $db"); | ||
1629 | 84 | my $sth = $dbh->prepare("select * from $table"); | ||
1630 | 85 | $sth->execute(); | ||
1631 | 86 | my $arr = $sth->fetchall_arrayref(); | ||
1632 | 87 | for my $rec (@$arr) { | ||
1633 | 88 | print "REC:"; | ||
1634 | 89 | for my $row (@$rec) { | ||
1635 | 90 | print " $row"; | ||
1636 | 91 | } | ||
1637 | 92 | print "\n"; | ||
1638 | 93 | } | ||
1639 | 94 | } | ||
1640 | 95 | |||
1641 | 96 | sub hstest_insert { | ||
1642 | 97 | $dbh->do("use $db"); | ||
1643 | 98 | my $sth = $dbh->prepare("insert into $table values (?, ?, ?)"); | ||
1644 | 99 | for (my $k = 0; $k < $tablesize; ++$k) { | ||
1645 | 100 | my $fc30 = "fc30_$k"; | ||
1646 | 101 | my $ft = "ft_$k"; | ||
1647 | 102 | $sth->execute($k, $fc30, $ft); | ||
1648 | 103 | } | ||
1649 | 104 | } | ||
1650 | 105 | |||
1651 | 106 | sub hstest_verify { | ||
1652 | 107 | $dbh->do("use $db"); | ||
1653 | 108 | my $sth = $dbh->prepare("select * from $table order by k"); | ||
1654 | 109 | $sth->execute(); | ||
1655 | 110 | my $arr = $sth->fetchall_arrayref(); | ||
1656 | 111 | my $hsres = $hspool->index_find($db, $table, "PRIMARY", "k,fc30,ft", | ||
1657 | 112 | ">=", [ 0 ], $tablesize, 0); | ||
1658 | 113 | for (my $i = 0; $i < $tablesize; ++$i) { | ||
1659 | 114 | my $rec = $arr->[$i]; | ||
1660 | 115 | my $differ = 0; | ||
1661 | 116 | print "REC:" if $verbose; | ||
1662 | 117 | for (my $j = 0; $j < 3; ++$j) { | ||
1663 | 118 | my $fld = $rec->[$j]; | ||
1664 | 119 | my $hsidx = $i * 3 + $j; | ||
1665 | 120 | my $hsfld = $hsres->[$hsidx]; | ||
1666 | 121 | if ($hsfld ne $fld) { | ||
1667 | 122 | $differ = 1; | ||
1668 | 123 | } | ||
1669 | 124 | if ($differ) { | ||
1670 | 125 | print " $fld:$hsfld" if $verbose; | ||
1671 | 126 | } else { | ||
1672 | 127 | print " $hsfld" if $verbose; | ||
1673 | 128 | } | ||
1674 | 129 | } | ||
1675 | 130 | print "\n" if $verbose; | ||
1676 | 131 | if ($differ) { | ||
1677 | 132 | die "verification failed"; | ||
1678 | 133 | } | ||
1679 | 134 | } | ||
1680 | 135 | } | ||
1681 | 136 | |||
1682 | 137 | sub hstest_verify2 { | ||
1683 | 138 | $dbh->do("use $db"); | ||
1684 | 139 | my $sth = $dbh->prepare("select * from $table order by k"); | ||
1685 | 140 | $sth->execute(); | ||
1686 | 141 | my $arr = $sth->fetchall_arrayref(); | ||
1687 | 142 | my $hsresa = $hspool->index_find_multi($db, $table, "PRIMARY", | ||
1688 | 143 | "k,fc30,ft", [ [ -1, ">=", [ 0 ], $tablesize, 0 ] ]); | ||
1689 | 144 | my $hsres = $hsresa->[0]; | ||
1690 | 145 | for (my $i = 0; $i < $tablesize; ++$i) { | ||
1691 | 146 | my $rec = $arr->[$i]; | ||
1692 | 147 | my $differ = 0; | ||
1693 | 148 | print "REC:" if $verbose; | ||
1694 | 149 | for (my $j = 0; $j < 3; ++$j) { | ||
1695 | 150 | my $fld = $rec->[$j]; | ||
1696 | 151 | my $hsidx = $i * 3 + $j; | ||
1697 | 152 | my $hsfld = $hsres->[$hsidx]; | ||
1698 | 153 | if ($hsfld ne $fld) { | ||
1699 | 154 | $differ = 1; | ||
1700 | 155 | } | ||
1701 | 156 | if ($differ) { | ||
1702 | 157 | print " $fld:$hsfld" if $verbose; | ||
1703 | 158 | } else { | ||
1704 | 159 | print " $hsfld" if $verbose; | ||
1705 | 160 | } | ||
1706 | 161 | } | ||
1707 | 162 | print "\n" if $verbose; | ||
1708 | 163 | if ($differ) { | ||
1709 | 164 | die "verification failed"; | ||
1710 | 165 | } | ||
1711 | 166 | } | ||
1712 | 167 | } | ||
1713 | 168 | |||
1714 | 169 | sub hashref_to_str { | ||
1715 | 170 | my $href = $_[0]; | ||
1716 | 171 | my $r = ''; | ||
1717 | 172 | for my $k (sort keys %$href) { | ||
1718 | 173 | my $v = $href->{$k}; | ||
1719 | 174 | $r .= "($k=>$v)"; | ||
1720 | 175 | } | ||
1721 | 176 | return $r; | ||
1722 | 177 | } | ||
1723 | 178 | |||
1724 | 179 | sub hstest_verify3 { | ||
1725 | 180 | $dbh->do("use $db"); | ||
1726 | 181 | my $sth = $dbh->prepare("select * from $table order by k"); | ||
1727 | 182 | $sth->execute(); | ||
1728 | 183 | my $hsres_t = $hspool->index_find($db, $table, "PRIMARY", "k,fc30,ft", | ||
1729 | 184 | ">=", [ 0 ], $tablesize, 0); | ||
1730 | 185 | my $hsres = DB::HandlerSocket::Pool::result_single_to_hasharr( | ||
1731 | 186 | [ 'k', 'fc30', 'ft' ], $hsres_t); | ||
1732 | 187 | for (my $i = 0; $i < $tablesize; ++$i) { | ||
1733 | 188 | my $mystr = hashref_to_str($sth->fetchrow_hashref()); | ||
1734 | 189 | my $hsstr = hashref_to_str($hsres->[$i]); | ||
1735 | 190 | if ($mystr ne $hsstr) { | ||
1736 | 191 | print "DIFF my=[$mystr] hs=[$hsstr]\n" if $verbose; | ||
1737 | 192 | die "verification failed"; | ||
1738 | 193 | } else { | ||
1739 | 194 | print "OK $hsstr\n" if $verbose; | ||
1740 | 195 | } | ||
1741 | 196 | } | ||
1742 | 197 | } | ||
1743 | 198 | |||
1744 | 199 | sub hstest_verify4 { | ||
1745 | 200 | $dbh->do("use $db"); | ||
1746 | 201 | my $sth = $dbh->prepare("select * from $table order by k"); | ||
1747 | 202 | $sth->execute(); | ||
1748 | 203 | my $hsres_t = $hspool->index_find($db, $table, "PRIMARY", "k,fc30,ft", | ||
1749 | 204 | ">=", [ 0 ], $tablesize, 0); | ||
1750 | 205 | my $hsres = DB::HandlerSocket::Pool::result_single_to_hashhash( | ||
1751 | 206 | [ 'k', 'fc30', 'ft' ], 'k', $hsres_t); | ||
1752 | 207 | my $rechash = $sth->fetchall_hashref('k'); | ||
1753 | 208 | while (my ($k, $href) = each (%$rechash)) { | ||
1754 | 209 | my $mystr = hashref_to_str($href); | ||
1755 | 210 | my $hsstr = hashref_to_str($hsres->{$k}); | ||
1756 | 211 | if ($mystr ne $hsstr) { | ||
1757 | 212 | print "DIFF my=[$mystr] hs=[$hsstr]\n" if $verbose; | ||
1758 | 213 | die "verification failed"; | ||
1759 | 214 | } else { | ||
1760 | 215 | print "OK $hsstr\n" if $verbose; | ||
1761 | 216 | } | ||
1762 | 217 | } | ||
1763 | 218 | } | ||
1764 | 219 | |||
1765 | 220 | sub hstest_clean { | ||
1766 | 221 | $hspool->clear_pool(); | ||
1767 | 222 | $dbh->do("drop database if exists $db"); | ||
1768 | 223 | } | ||
1769 | 224 | |||
1770 | 0 | 225 | ||
1771 | === added file 'HandlerSocket-Plugin-for-MySQL/client/hstest.cpp' | |||
1772 | --- HandlerSocket-Plugin-for-MySQL/client/hstest.cpp 1970-01-01 00:00:00 +0000 | |||
1773 | +++ HandlerSocket-Plugin-for-MySQL/client/hstest.cpp 2011-06-08 01:58:05 +0000 | |||
1774 | @@ -0,0 +1,1532 @@ | |||
1775 | 1 | |||
1776 | 2 | // vim:sw=2:ai | ||
1777 | 3 | |||
1778 | 4 | #include <signal.h> | ||
1779 | 5 | #include <sys/time.h> | ||
1780 | 6 | #include <stdio.h> | ||
1781 | 7 | #include <string.h> | ||
1782 | 8 | #include <vector> | ||
1783 | 9 | #include <stdlib.h> | ||
1784 | 10 | #include <memory> | ||
1785 | 11 | #include <errno.h> | ||
1786 | 12 | #include <mysql.h> | ||
1787 | 13 | #include <time.h> | ||
1788 | 14 | #include <sys/types.h> | ||
1789 | 15 | #include <sys/stat.h> | ||
1790 | 16 | #include <fcntl.h> | ||
1791 | 17 | |||
1792 | 18 | #include "util.hpp" | ||
1793 | 19 | #include "auto_ptrcontainer.hpp" | ||
1794 | 20 | #include "socket.hpp" | ||
1795 | 21 | #include "thread.hpp" | ||
1796 | 22 | #include "hstcpcli.hpp" | ||
1797 | 23 | |||
1798 | 24 | #if __GNUC__ >= 4 | ||
1799 | 25 | long atomic_exchange_and_add(volatile long *valp, long c) | ||
1800 | 26 | { | ||
1801 | 27 | return __sync_fetch_and_add(valp, c); | ||
1802 | 28 | } | ||
1803 | 29 | #else | ||
1804 | 30 | #include <bits/atomicity.h> | ||
1805 | 31 | using namespace __gnu_cxx; | ||
1806 | 32 | long atomic_exchange_and_add(volatile long *valp, long c) | ||
1807 | 33 | { | ||
1808 | 34 | return __exchange_and_add((volatile _Atomic_word *)valp, c); | ||
1809 | 35 | } | ||
1810 | 36 | #endif | ||
1811 | 37 | |||
1812 | 38 | namespace dena { | ||
1813 | 39 | |||
1814 | 40 | struct auto_mysql : private noncopyable { | ||
1815 | 41 | auto_mysql() : db(0) { | ||
1816 | 42 | reset(); | ||
1817 | 43 | } | ||
1818 | 44 | ~auto_mysql() { | ||
1819 | 45 | if (db) { | ||
1820 | 46 | mysql_close(db); | ||
1821 | 47 | } | ||
1822 | 48 | } | ||
1823 | 49 | void reset() { | ||
1824 | 50 | if (db) { | ||
1825 | 51 | mysql_close(db); | ||
1826 | 52 | } | ||
1827 | 53 | if ((db = mysql_init(0)) == 0) { | ||
1828 | 54 | fatal_abort("failed to initialize mysql client"); | ||
1829 | 55 | } | ||
1830 | 56 | } | ||
1831 | 57 | operator MYSQL *() const { return db; } | ||
1832 | 58 | private: | ||
1833 | 59 | MYSQL *db; | ||
1834 | 60 | }; | ||
1835 | 61 | |||
1836 | 62 | struct auto_mysql_res : private noncopyable { | ||
1837 | 63 | auto_mysql_res(MYSQL *db) { | ||
1838 | 64 | res = mysql_store_result(db); | ||
1839 | 65 | } | ||
1840 | 66 | ~auto_mysql_res() { | ||
1841 | 67 | if (res) { | ||
1842 | 68 | mysql_free_result(res); | ||
1843 | 69 | } | ||
1844 | 70 | } | ||
1845 | 71 | operator MYSQL_RES *() const { return res; } | ||
1846 | 72 | private: | ||
1847 | 73 | MYSQL_RES *res; | ||
1848 | 74 | }; | ||
1849 | 75 | |||
1850 | 76 | struct auto_mysql_stmt : private noncopyable { | ||
1851 | 77 | auto_mysql_stmt(MYSQL *db) { | ||
1852 | 78 | stmt = mysql_stmt_init(db); | ||
1853 | 79 | } | ||
1854 | 80 | ~auto_mysql_stmt() { | ||
1855 | 81 | if (stmt) { | ||
1856 | 82 | mysql_stmt_close(stmt); | ||
1857 | 83 | } | ||
1858 | 84 | } | ||
1859 | 85 | operator MYSQL_STMT *() const { return stmt; } | ||
1860 | 86 | private: | ||
1861 | 87 | MYSQL_STMT *stmt; | ||
1862 | 88 | }; | ||
1863 | 89 | |||
1864 | 90 | namespace { | ||
1865 | 91 | |||
1866 | 92 | double | ||
1867 | 93 | gettimeofday_double() | ||
1868 | 94 | { | ||
1869 | 95 | struct timeval tv = { }; | ||
1870 | 96 | if (gettimeofday(&tv, 0) != 0) { | ||
1871 | 97 | fatal_abort("gettimeofday"); | ||
1872 | 98 | } | ||
1873 | 99 | return static_cast<double>(tv.tv_usec) / 1000000 + tv.tv_sec; | ||
1874 | 100 | } | ||
1875 | 101 | |||
1876 | 102 | // unused | ||
1877 | 103 | void | ||
1878 | 104 | wait_close(int fd) | ||
1879 | 105 | { | ||
1880 | 106 | char buf[1024]; | ||
1881 | 107 | while (true) { | ||
1882 | 108 | int r = read(fd, buf, sizeof(buf)); | ||
1883 | 109 | if (r <= 0) { | ||
1884 | 110 | break; | ||
1885 | 111 | } | ||
1886 | 112 | } | ||
1887 | 113 | } | ||
1888 | 114 | |||
1889 | 115 | // unused | ||
1890 | 116 | void | ||
1891 | 117 | gentle_close(int fd) | ||
1892 | 118 | { | ||
1893 | 119 | int r = shutdown(fd, SHUT_WR); | ||
1894 | 120 | if (r != 0) { | ||
1895 | 121 | return; | ||
1896 | 122 | } | ||
1897 | 123 | wait_close(fd); | ||
1898 | 124 | } | ||
1899 | 125 | |||
1900 | 126 | }; | ||
1901 | 127 | |||
1902 | 128 | struct hstest_shared { | ||
1903 | 129 | config conf; | ||
1904 | 130 | socket_args arg; | ||
1905 | 131 | int verbose; | ||
1906 | 132 | size_t loop; | ||
1907 | 133 | size_t pipe; | ||
1908 | 134 | char op; | ||
1909 | 135 | long num_threads; | ||
1910 | 136 | mutable volatile long count; | ||
1911 | 137 | mutable volatile long conn_count; | ||
1912 | 138 | long wait_conn; | ||
1913 | 139 | volatile char *keygen; | ||
1914 | 140 | long keygen_size; | ||
1915 | 141 | mutable volatile int enable_timing; | ||
1916 | 142 | int usleep; | ||
1917 | 143 | int dump; | ||
1918 | 144 | hstest_shared() : verbose(0), loop(0), pipe(0), op('G'), num_threads(0), | ||
1919 | 145 | count(0), conn_count(0), wait_conn(0), keygen(0), keygen_size(0), | ||
1920 | 146 | enable_timing(0), usleep(0), dump(0) { } | ||
1921 | 147 | void increment_count(unsigned int c = 1) const volatile { | ||
1922 | 148 | atomic_exchange_and_add(&count, c); | ||
1923 | 149 | } | ||
1924 | 150 | void increment_conn(unsigned int c) const volatile { | ||
1925 | 151 | atomic_exchange_and_add(&conn_count, c); | ||
1926 | 152 | while (wait_conn != 0 && conn_count < wait_conn) { | ||
1927 | 153 | sleep(1); | ||
1928 | 154 | } | ||
1929 | 155 | // fprintf(stderr, "wait_conn=%ld done\n", wait_conn); | ||
1930 | 156 | } | ||
1931 | 157 | }; | ||
1932 | 158 | |||
1933 | 159 | struct hstest_thread { | ||
1934 | 160 | struct arg_type { | ||
1935 | 161 | size_t id; | ||
1936 | 162 | const hstest_shared& sh; | ||
1937 | 163 | bool watch_flag; | ||
1938 | 164 | arg_type(size_t i, const hstest_shared& s, bool w) | ||
1939 | 165 | : id(i), sh(s), watch_flag(w) { } | ||
1940 | 166 | }; | ||
1941 | 167 | hstest_thread(const arg_type& a) : arg(a), io_success_count(0), | ||
1942 | 168 | op_success_count(0), response_min(99999), response_max(0), | ||
1943 | 169 | response_sum(0), response_avg(0) { } | ||
1944 | 170 | void operator ()(); | ||
1945 | 171 | void test_1(); | ||
1946 | 172 | void test_2_3(int test_num); | ||
1947 | 173 | void test_4_5(int test_num); | ||
1948 | 174 | void test_6(int test_num); | ||
1949 | 175 | void test_7(int test_num); | ||
1950 | 176 | void test_8(int test_num); | ||
1951 | 177 | void test_9(int test_num); | ||
1952 | 178 | void test_10(int test_num); | ||
1953 | 179 | void test_11(int test_num); | ||
1954 | 180 | void test_12(int test_num); | ||
1955 | 181 | void test_21(int test_num); | ||
1956 | 182 | void test_22(int test_num); | ||
1957 | 183 | void test_watch(); | ||
1958 | 184 | void sleep_if(); | ||
1959 | 185 | void set_timing(double time_spent); | ||
1960 | 186 | arg_type arg; | ||
1961 | 187 | auto_file fd; | ||
1962 | 188 | size_t io_success_count; | ||
1963 | 189 | size_t op_success_count; | ||
1964 | 190 | double response_min, response_max, response_sum, response_avg; | ||
1965 | 191 | }; | ||
1966 | 192 | |||
1967 | 193 | void | ||
1968 | 194 | hstest_thread::test_1() | ||
1969 | 195 | { | ||
1970 | 196 | char buf[1024]; | ||
1971 | 197 | unsigned int seed = arg.id; | ||
1972 | 198 | seed ^= arg.sh.conf.get_int("seed_xor", 0); | ||
1973 | 199 | std::string err; | ||
1974 | 200 | if (socket_connect(fd, arg.sh.arg, err) != 0) { | ||
1975 | 201 | fprintf(stderr, "connect: %d %s\n", errno, strerror(errno)); | ||
1976 | 202 | return; | ||
1977 | 203 | } | ||
1978 | 204 | const char op = arg.sh.op; | ||
1979 | 205 | const int tablesize = arg.sh.conf.get_int("tablesize", 0); | ||
1980 | 206 | for (size_t i = 0; i < arg.sh.loop; ++i) { | ||
1981 | 207 | for (size_t j = 0; j < arg.sh.pipe; ++j) { | ||
1982 | 208 | int k = 0, v = 0, len = 0; | ||
1983 | 209 | if (op == 'G') { | ||
1984 | 210 | k = rand_r(&seed); | ||
1985 | 211 | v = rand_r(&seed); /* unused */ | ||
1986 | 212 | if (tablesize != 0) { | ||
1987 | 213 | k &= tablesize; | ||
1988 | 214 | } | ||
1989 | 215 | len = snprintf(buf, sizeof(buf), "%c\tk%d\n", op, k); | ||
1990 | 216 | } else { | ||
1991 | 217 | k = rand_r(&seed); | ||
1992 | 218 | v = rand_r(&seed); | ||
1993 | 219 | if (tablesize != 0) { | ||
1994 | 220 | k &= tablesize; | ||
1995 | 221 | } | ||
1996 | 222 | len = snprintf(buf, sizeof(buf), "%c\tk%d\tv%d\n", op, k, v); | ||
1997 | 223 | } | ||
1998 | 224 | const int wlen = write(fd.get(), buf, len); | ||
1999 | 225 | if (wlen != len) { | ||
2000 | 226 | return; | ||
2001 | 227 | } | ||
2002 | 228 | } | ||
2003 | 229 | size_t read_cnt = 0; | ||
2004 | 230 | size_t read_pos = 0; | ||
2005 | 231 | while (read_cnt < arg.sh.pipe) { | ||
2006 | 232 | const int rlen = read(fd.get(), buf + read_pos, sizeof(buf) - read_pos); | ||
2007 | 233 | if (rlen <= 0) { | ||
2008 | 234 | return; | ||
2009 | 235 | } | ||
2010 | 236 | read_pos += rlen; | ||
2011 | 237 | while (true) { | ||
2012 | 238 | const char *const p = static_cast<const char *>(memchr(buf, '\n', | ||
2013 | 239 | read_pos)); | ||
2014 | 240 | if (p == 0) { | ||
2015 | 241 | break; | ||
2016 | 242 | } | ||
2017 | 243 | ++read_cnt; | ||
2018 | 244 | ++io_success_count; | ||
2019 | 245 | arg.sh.increment_count(); | ||
2020 | 246 | if (p != buf && buf[0] == '=') { | ||
2021 | 247 | ++op_success_count; | ||
2022 | 248 | } | ||
2023 | 249 | const size_t rest_size = buf + read_pos - (p + 1); | ||
2024 | 250 | if (rest_size != 0) { | ||
2025 | 251 | memmove(buf, p + 1, rest_size); | ||
2026 | 252 | } | ||
2027 | 253 | read_pos = rest_size; | ||
2028 | 254 | } | ||
2029 | 255 | } | ||
2030 | 256 | } | ||
2031 | 257 | } | ||
2032 | 258 | |||
2033 | 259 | void | ||
2034 | 260 | hstest_thread::test_2_3(int test_num) | ||
2035 | 261 | { | ||
2036 | 262 | #if 0 | ||
2037 | 263 | char buf_k[128], buf_v[128]; | ||
2038 | 264 | unsigned int seed = arg.id; | ||
2039 | 265 | op_base_t op = static_cast<op_base_t>(arg.sh.op); | ||
2040 | 266 | micli_ptr hnd; | ||
2041 | 267 | if (test_num == 2) { | ||
2042 | 268 | hnd = micli_i::create_remote(arg.sh.conf); | ||
2043 | 269 | } else if (test_num == 3) { | ||
2044 | 270 | // hnd = micli_i::create_inproc(arg.sh.localdb); | ||
2045 | 271 | } | ||
2046 | 272 | if (hnd.get() == 0) { | ||
2047 | 273 | return; | ||
2048 | 274 | } | ||
2049 | 275 | for (size_t i = 0; i < arg.sh.loop; ++i) { | ||
2050 | 276 | for (size_t j = 0; j < arg.sh.pipe; ++j) { | ||
2051 | 277 | int k = 0, v = 0, klen = 0, vlen = 0; | ||
2052 | 278 | k = rand_r(&seed); | ||
2053 | 279 | klen = snprintf(buf_k, sizeof(buf_k), "k%d", k); | ||
2054 | 280 | v = rand_r(&seed); /* unused */ | ||
2055 | 281 | vlen = snprintf(buf_v, sizeof(buf_v), "v%d", v); | ||
2056 | 282 | string_ref arr[2]; | ||
2057 | 283 | arr[0] = string_ref(buf_k, klen); | ||
2058 | 284 | arr[1] = string_ref(buf_v, vlen); | ||
2059 | 285 | pstrarr_ptr rec(arr, 2); | ||
2060 | 286 | if (hnd->execute(op, 0, 0, rec.get_const())) { | ||
2061 | 287 | ++io_success_count; | ||
2062 | 288 | arg.sh.increment_count(); | ||
2063 | 289 | const dataset& res = hnd->get_result_ref(); | ||
2064 | 290 | if (res.size() == 1) { | ||
2065 | 291 | ++op_success_count; | ||
2066 | 292 | } | ||
2067 | 293 | } | ||
2068 | 294 | } | ||
2069 | 295 | } | ||
2070 | 296 | #endif | ||
2071 | 297 | } | ||
2072 | 298 | |||
2073 | 299 | void | ||
2074 | 300 | hstest_thread::test_4_5(int test_num) | ||
2075 | 301 | { | ||
2076 | 302 | #if 0 | ||
2077 | 303 | char buf_k[128], buf_v[8192]; | ||
2078 | 304 | memset(buf_v, ' ', sizeof(buf_v)); | ||
2079 | 305 | unsigned int seed = arg.id; | ||
2080 | 306 | op_base_t op = static_cast<op_base_t>(arg.sh.op); | ||
2081 | 307 | micli_ptr hnd; | ||
2082 | 308 | if (test_num == 4) { | ||
2083 | 309 | hnd = micli_i::create_remote(arg.sh.conf); | ||
2084 | 310 | } else if (test_num == 5) { | ||
2085 | 311 | hnd = micli_i::create_inproc(arg.sh.localdb); | ||
2086 | 312 | } | ||
2087 | 313 | if (hnd.get() == 0) { | ||
2088 | 314 | return; | ||
2089 | 315 | } | ||
2090 | 316 | for (size_t i = 0; i < arg.sh.loop; ++i) { | ||
2091 | 317 | for (size_t j = 0; j < arg.sh.pipe; ++j) { | ||
2092 | 318 | int k = 0, klen = 0, vlen = 0; | ||
2093 | 319 | k = i & 0x0000ffffUL; | ||
2094 | 320 | if (k == 0) { | ||
2095 | 321 | fprintf(stderr, "k=0\n"); | ||
2096 | 322 | } | ||
2097 | 323 | klen = snprintf(buf_k, sizeof(buf_k), "k%d", k); | ||
2098 | 324 | vlen = rand_r(&seed) % 8192; | ||
2099 | 325 | string_ref arr[2]; | ||
2100 | 326 | arr[0] = string_ref(buf_k, klen); | ||
2101 | 327 | arr[1] = string_ref(buf_v, vlen); | ||
2102 | 328 | pstrarr_ptr rec(arr, 2); | ||
2103 | 329 | if (hnd->execute(op, 0, 0, rec.get_const())) { | ||
2104 | 330 | ++io_success_count; | ||
2105 | 331 | const dataset& res = hnd->get_result_ref(); | ||
2106 | 332 | if (res.size() == 1) { | ||
2107 | 333 | ++op_success_count; | ||
2108 | 334 | } | ||
2109 | 335 | } | ||
2110 | 336 | } | ||
2111 | 337 | } | ||
2112 | 338 | #endif | ||
2113 | 339 | } | ||
2114 | 340 | |||
2115 | 341 | void | ||
2116 | 342 | hstest_thread::test_6(int test_num) | ||
2117 | 343 | { | ||
2118 | 344 | int count = arg.sh.conf.get_int("count", 1); | ||
2119 | 345 | auto_file fds[count]; | ||
2120 | 346 | for (int i = 0; i < count; ++i) { | ||
2121 | 347 | const double t1 = gettimeofday_double(); | ||
2122 | 348 | std::string err; | ||
2123 | 349 | if (socket_connect(fds[i], arg.sh.arg, err) != 0) { | ||
2124 | 350 | fprintf(stderr, "id=%zu i=%d err=%s\n", arg.id, i, err.c_str()); | ||
2125 | 351 | } | ||
2126 | 352 | const double t2 = gettimeofday_double(); | ||
2127 | 353 | if (t2 - t1 > 1) { | ||
2128 | 354 | fprintf(stderr, "id=%zu i=%d time %f\n", arg.id, i, t2 - t1); | ||
2129 | 355 | } | ||
2130 | 356 | } | ||
2131 | 357 | } | ||
2132 | 358 | |||
2133 | 359 | void | ||
2134 | 360 | hstest_thread::test_7(int num) | ||
2135 | 361 | { | ||
2136 | 362 | /* | ||
2137 | 363 | set foo 0 0 10 | ||
2138 | 364 | 0123456789 | ||
2139 | 365 | STORED | ||
2140 | 366 | get foo | ||
2141 | 367 | VALUE foo 0 10 | ||
2142 | 368 | 0123456789 | ||
2143 | 369 | END | ||
2144 | 370 | get var | ||
2145 | 371 | END | ||
2146 | 372 | */ | ||
2147 | 373 | char buf[1024]; | ||
2148 | 374 | const int keep_connection = arg.sh.conf.get_int("keep_connection", 1); | ||
2149 | 375 | unsigned int seed = arg.id; | ||
2150 | 376 | seed ^= arg.sh.conf.get_int("seed_xor", 0); | ||
2151 | 377 | const int tablesize = arg.sh.conf.get_int("tablesize", 0); | ||
2152 | 378 | const char op = arg.sh.op; | ||
2153 | 379 | for (size_t i = 0; i < arg.sh.loop; ++i) { | ||
2154 | 380 | const double tm1 = gettimeofday_double(); | ||
2155 | 381 | std::string err; | ||
2156 | 382 | if (fd.get() < 0 && socket_connect(fd, arg.sh.arg, err) != 0) { | ||
2157 | 383 | fprintf(stderr, "connect: %d %s\n", errno, strerror(errno)); | ||
2158 | 384 | return; | ||
2159 | 385 | } | ||
2160 | 386 | for (size_t j = 0; j < arg.sh.pipe; ++j) { | ||
2161 | 387 | int k = 0, v = 0, len = 0; | ||
2162 | 388 | if (op == 'G') { | ||
2163 | 389 | k = rand_r(&seed); | ||
2164 | 390 | v = rand_r(&seed); /* unused */ | ||
2165 | 391 | if (tablesize != 0) { | ||
2166 | 392 | k &= tablesize; | ||
2167 | 393 | } | ||
2168 | 394 | len = snprintf(buf, sizeof(buf), "get k%d\r\n", k); | ||
2169 | 395 | } else { | ||
2170 | 396 | k = rand_r(&seed); | ||
2171 | 397 | v = rand_r(&seed); | ||
2172 | 398 | if (tablesize != 0) { | ||
2173 | 399 | k &= tablesize; | ||
2174 | 400 | } | ||
2175 | 401 | char vbuf[1024]; | ||
2176 | 402 | int vlen = snprintf(vbuf, sizeof(vbuf), | ||
2177 | 403 | "v%d" | ||
2178 | 404 | // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
2179 | 405 | // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
2180 | 406 | // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
2181 | 407 | // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
2182 | 408 | // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
2183 | 409 | , v); | ||
2184 | 410 | len = snprintf(buf, sizeof(buf), "set k%d 0 0 %d\r\n%s\r\n", | ||
2185 | 411 | k, vlen, vbuf); | ||
2186 | 412 | } | ||
2187 | 413 | const int wlen = write(fd.get(), buf, len); | ||
2188 | 414 | if (wlen != len) { | ||
2189 | 415 | return; | ||
2190 | 416 | } | ||
2191 | 417 | } | ||
2192 | 418 | size_t read_cnt = 0; | ||
2193 | 419 | size_t read_pos = 0; | ||
2194 | 420 | bool read_response_done = false; | ||
2195 | 421 | bool expect_value = false; | ||
2196 | 422 | while (!read_response_done) { | ||
2197 | 423 | const int rlen = read(fd.get(), buf + read_pos, sizeof(buf) - read_pos); | ||
2198 | 424 | if (rlen <= 0) { | ||
2199 | 425 | return; | ||
2200 | 426 | } | ||
2201 | 427 | read_pos += rlen; | ||
2202 | 428 | while (true) { | ||
2203 | 429 | const char *const p = static_cast<const char *>(memchr(buf, '\n', | ||
2204 | 430 | read_pos)); | ||
2205 | 431 | if (p == 0) { | ||
2206 | 432 | break; | ||
2207 | 433 | } | ||
2208 | 434 | ++read_cnt; | ||
2209 | 435 | if (expect_value) { | ||
2210 | 436 | expect_value = false; | ||
2211 | 437 | } else if (p >= buf + 6 && memcmp(buf, "VALUE ", 6) == 0) { | ||
2212 | 438 | expect_value = true; | ||
2213 | 439 | ++op_success_count; | ||
2214 | 440 | } else { | ||
2215 | 441 | if (p == buf + 7 && memcmp(buf, "STORED\r", 7) == 0) { | ||
2216 | 442 | ++op_success_count; | ||
2217 | 443 | } | ||
2218 | 444 | read_response_done = true; | ||
2219 | 445 | } | ||
2220 | 446 | const size_t rest_size = buf + read_pos - (p + 1); | ||
2221 | 447 | if (rest_size != 0) { | ||
2222 | 448 | memmove(buf, p + 1, rest_size); | ||
2223 | 449 | } | ||
2224 | 450 | read_pos = rest_size; | ||
2225 | 451 | } | ||
2226 | 452 | ++io_success_count; | ||
2227 | 453 | } | ||
2228 | 454 | arg.sh.increment_count(); | ||
2229 | 455 | if (!keep_connection) { | ||
2230 | 456 | fd.close(); | ||
2231 | 457 | } | ||
2232 | 458 | const double tm2 = gettimeofday_double(); | ||
2233 | 459 | set_timing(tm2 - tm1); | ||
2234 | 460 | sleep_if(); | ||
2235 | 461 | } | ||
2236 | 462 | } | ||
2237 | 463 | |||
2238 | 464 | struct rec { | ||
2239 | 465 | std::string key; | ||
2240 | 466 | std::string value; | ||
2241 | 467 | }; | ||
2242 | 468 | |||
2243 | 469 | void | ||
2244 | 470 | hstest_thread::test_8(int test_num) | ||
2245 | 471 | { | ||
2246 | 472 | #if 0 | ||
2247 | 473 | char buf_k[128], buf_v[128]; | ||
2248 | 474 | unsigned int seed = arg.id; | ||
2249 | 475 | // op_base_t op = static_cast<op_base_t>(arg.sh.op); | ||
2250 | 476 | using namespace boost::multi_index; | ||
2251 | 477 | typedef member<rec, std::string, &rec::key> rec_get_key; | ||
2252 | 478 | typedef ordered_unique<rec_get_key> oui; | ||
2253 | 479 | typedef multi_index_container< rec, indexed_by<oui> > mic; | ||
2254 | 480 | #if 0 | ||
2255 | 481 | typedef std::map<std::string, std::string> m_type; | ||
2256 | 482 | m_type m; | ||
2257 | 483 | #endif | ||
2258 | 484 | mic m; | ||
2259 | 485 | for (size_t i = 0; i < arg.sh.loop; ++i) { | ||
2260 | 486 | for (size_t j = 0; j < arg.sh.pipe; ++j) { | ||
2261 | 487 | int k = 0, v = 0, klen = 0, vlen = 0; | ||
2262 | 488 | k = rand_r(&seed); | ||
2263 | 489 | klen = snprintf(buf_k, sizeof(buf_k), "k%d", k); | ||
2264 | 490 | v = rand_r(&seed); /* unused */ | ||
2265 | 491 | vlen = snprintf(buf_v, sizeof(buf_v), "v%d", v); | ||
2266 | 492 | const std::string ks(buf_k, klen); | ||
2267 | 493 | const std::string vs(buf_v, vlen); | ||
2268 | 494 | rec r; | ||
2269 | 495 | r.key = ks; | ||
2270 | 496 | r.value = vs; | ||
2271 | 497 | m.insert(r); | ||
2272 | 498 | // m.insert(std::make_pair(ks, vs)); | ||
2273 | 499 | ++io_success_count; | ||
2274 | 500 | ++op_success_count; | ||
2275 | 501 | arg.sh.increment_count(); | ||
2276 | 502 | } | ||
2277 | 503 | } | ||
2278 | 504 | #endif | ||
2279 | 505 | } | ||
2280 | 506 | |||
2281 | 507 | struct mysqltest_thread_initobj : private noncopyable { | ||
2282 | 508 | mysqltest_thread_initobj() { | ||
2283 | 509 | mysql_thread_init(); | ||
2284 | 510 | } | ||
2285 | 511 | ~mysqltest_thread_initobj() { | ||
2286 | 512 | mysql_thread_end(); | ||
2287 | 513 | } | ||
2288 | 514 | }; | ||
2289 | 515 | |||
2290 | 516 | void | ||
2291 | 517 | hstest_thread::test_9(int test_num) | ||
2292 | 518 | { | ||
2293 | 519 | /* create table hstest | ||
2294 | 520 | * ( k varchar(255) not null, v varchar(255) not null, primary key(k)) | ||
2295 | 521 | * engine = innodb; */ | ||
2296 | 522 | auto_mysql db; | ||
2297 | 523 | // mysqltest_thread_initobj initobj; | ||
2298 | 524 | std::string err; | ||
2299 | 525 | const char op = arg.sh.op; | ||
2300 | 526 | const std::string suffix = arg.sh.conf.get_str("value_suffix", "upd"); | ||
2301 | 527 | unsigned long long err_cnt = 0; | ||
2302 | 528 | unsigned long long query_cnt = 0; | ||
2303 | 529 | #if 0 | ||
2304 | 530 | my_bool reconnect = 0; | ||
2305 | 531 | if (mysql_options(db, MYSQL_OPT_RECONNECT, &reconnect) != 0) { | ||
2306 | 532 | err = "mysql_options() failed"; | ||
2307 | 533 | ++err_cnt; | ||
2308 | 534 | return; | ||
2309 | 535 | } | ||
2310 | 536 | #endif | ||
2311 | 537 | unsigned int seed = time(0) + arg.id + 1; | ||
2312 | 538 | seed ^= arg.sh.conf.get_int("seed_xor", 0); | ||
2313 | 539 | drand48_data randbuf; | ||
2314 | 540 | srand48_r(seed, &randbuf); | ||
2315 | 541 | const std::string mysql_host = arg.sh.conf.get_str("host", "localhost"); | ||
2316 | 542 | const int mysql_port = arg.sh.conf.get_int("mysqlport", 3306); | ||
2317 | 543 | const int num = arg.sh.loop; | ||
2318 | 544 | const std::string mysql_user = arg.sh.conf.get_str("mysqluser", "root"); | ||
2319 | 545 | const std::string mysql_passwd = arg.sh.conf.get_str("mysqlpass", ""); | ||
2320 | 546 | const std::string mysql_dbname = arg.sh.conf.get_str("dbname", "hstest"); | ||
2321 | 547 | const int keep_connection = arg.sh.conf.get_int("keep_connection", 1); | ||
2322 | 548 | const int verbose = arg.sh.conf.get_int("verbose", 1); | ||
2323 | 549 | const int tablesize = arg.sh.conf.get_int("tablesize", 10000); | ||
2324 | 550 | const int moreflds = arg.sh.conf.get_int("moreflds", 0); | ||
2325 | 551 | const std::string moreflds_prefix = arg.sh.conf.get_str( | ||
2326 | 552 | "moreflds_prefix", "column0123456789_"); | ||
2327 | 553 | const int use_handler = arg.sh.conf.get_int("handler", 0); | ||
2328 | 554 | const int sched_flag = arg.sh.conf.get_int("sched", 0); | ||
2329 | 555 | const int use_in = arg.sh.conf.get_int("in", 0); | ||
2330 | 556 | const int ssps = use_in ? 0 : arg.sh.conf.get_int("ssps", 0); | ||
2331 | 557 | std::string flds = "v"; | ||
2332 | 558 | for (int i = 0; i < moreflds; ++i) { | ||
2333 | 559 | char buf[1024]; | ||
2334 | 560 | snprintf(buf, sizeof(buf), ",%s%d", moreflds_prefix.c_str(), i); | ||
2335 | 561 | flds += std::string(buf); | ||
2336 | 562 | } | ||
2337 | 563 | int connected = 0; | ||
2338 | 564 | std::auto_ptr<auto_mysql_stmt> stmt; | ||
2339 | 565 | string_buffer wbuf; | ||
2340 | 566 | for (int i = 0; i < num; ++i) { | ||
2341 | 567 | const double tm1 = gettimeofday_double(); | ||
2342 | 568 | const int flags = 0; | ||
2343 | 569 | if (connected == 0) { | ||
2344 | 570 | if (!mysql_real_connect(db, mysql_host.c_str(), | ||
2345 | 571 | mysql_user.c_str(), mysql_user.empty() ? 0 : mysql_passwd.c_str(), | ||
2346 | 572 | mysql_dbname.c_str(), mysql_port, 0, flags)) { | ||
2347 | 573 | err = "failed to connect: " + std::string(mysql_error(db)); | ||
2348 | 574 | if (verbose >= 1) { | ||
2349 | 575 | fprintf(stderr, "e=[%s]\n", err.c_str()); | ||
2350 | 576 | } | ||
2351 | 577 | ++err_cnt; | ||
2352 | 578 | return; | ||
2353 | 579 | } | ||
2354 | 580 | arg.sh.increment_conn(1); | ||
2355 | 581 | } | ||
2356 | 582 | int r = 0; | ||
2357 | 583 | if (connected == 0 && use_handler) { | ||
2358 | 584 | const char *const q = "handler hstest_table1 open"; | ||
2359 | 585 | r = mysql_real_query(db, q, strlen(q)); | ||
2360 | 586 | if (r != 0) { | ||
2361 | 587 | err = 1; | ||
2362 | 588 | } | ||
2363 | 589 | } | ||
2364 | 590 | if (connected == 0 && ssps) { | ||
2365 | 591 | stmt.reset(new auto_mysql_stmt(db)); | ||
2366 | 592 | const char *const q = "select v from hstest_table1 where k = ?"; | ||
2367 | 593 | r = mysql_stmt_prepare(*stmt, q, strlen(q)); | ||
2368 | 594 | if (r != 0) { | ||
2369 | 595 | fprintf(stderr, "ssps err\n"); | ||
2370 | 596 | ++err_cnt; | ||
2371 | 597 | return; | ||
2372 | 598 | } | ||
2373 | 599 | } | ||
2374 | 600 | connected = 1; | ||
2375 | 601 | std::string result_str; | ||
2376 | 602 | unsigned int err = 0; | ||
2377 | 603 | unsigned int num_flds = 0, num_affected_rows = 0; | ||
2378 | 604 | int got_data = 0; | ||
2379 | 605 | char buf_query[16384]; | ||
2380 | 606 | int buf_query_len = 0; | ||
2381 | 607 | int k = 0, v = 0; | ||
2382 | 608 | { | ||
2383 | 609 | double kf = 0, vf = 0; | ||
2384 | 610 | drand48_r(&randbuf, &kf); | ||
2385 | 611 | drand48_r(&randbuf, &vf); | ||
2386 | 612 | k = int(kf * tablesize); | ||
2387 | 613 | v = int(vf * tablesize); | ||
2388 | 614 | #if 0 | ||
2389 | 615 | k = rand_r(&seed); | ||
2390 | 616 | v = rand_r(&seed); | ||
2391 | 617 | if (tablesize != 0) { | ||
2392 | 618 | k %= tablesize; | ||
2393 | 619 | } | ||
2394 | 620 | #endif | ||
2395 | 621 | if (op == 'G') { | ||
2396 | 622 | if (use_handler) { | ||
2397 | 623 | buf_query_len = snprintf(buf_query, sizeof(buf_query), | ||
2398 | 624 | "handler hstest_table1 read `primary` = ( '%d' )", k); | ||
2399 | 625 | // TODO: moreflds | ||
2400 | 626 | } else if (ssps) { | ||
2401 | 627 | // | ||
2402 | 628 | } else if (use_in) { | ||
2403 | 629 | wbuf.clear(); | ||
2404 | 630 | char *p = wbuf.make_space(1024); | ||
2405 | 631 | int len = snprintf(p, 1024, "select %s from hstest_table1 where k in ('%d'", flds.c_str(), k); | ||
2406 | 632 | wbuf.space_wrote(len); | ||
2407 | 633 | for (int j = 1; j < use_in; ++j) { | ||
2408 | 634 | /* generate more key */ | ||
2409 | 635 | drand48_r(&randbuf, &kf); | ||
2410 | 636 | k = int(kf * tablesize); | ||
2411 | 637 | p = wbuf.make_space(1024); | ||
2412 | 638 | int len = snprintf(p, 1024, ", '%d'", k); | ||
2413 | 639 | wbuf.space_wrote(len); | ||
2414 | 640 | } | ||
2415 | 641 | wbuf.append_literal(")"); | ||
2416 | 642 | } else { | ||
2417 | 643 | buf_query_len = snprintf(buf_query, sizeof(buf_query), | ||
2418 | 644 | "select %s from hstest_table1 where k = '%d'", flds.c_str(), k); | ||
2419 | 645 | } | ||
2420 | 646 | } else if (op == 'U') { | ||
2421 | 647 | buf_query_len = snprintf(buf_query, sizeof(buf_query), | ||
2422 | 648 | "update hstest_table1 set v = '%d_%d%s' where k = '%d'", | ||
2423 | 649 | v, k, suffix.c_str(), k); | ||
2424 | 650 | } else if (op == 'R') { | ||
2425 | 651 | buf_query_len = snprintf(buf_query, sizeof(buf_query), | ||
2426 | 652 | "replace into hstest_table1 values ('%d', 'v%d')", k, v); | ||
2427 | 653 | // TODO: moreflds | ||
2428 | 654 | } | ||
2429 | 655 | } | ||
2430 | 656 | if (r == 0) { | ||
2431 | 657 | if (ssps) { | ||
2432 | 658 | MYSQL_BIND bind[1] = { }; | ||
2433 | 659 | bind[0].buffer_type = MYSQL_TYPE_LONG; | ||
2434 | 660 | bind[0].buffer = (char *)&k; | ||
2435 | 661 | bind[0].is_null = 0; | ||
2436 | 662 | bind[0].length = 0; | ||
2437 | 663 | if (mysql_stmt_bind_param(*stmt, bind)) { | ||
2438 | 664 | fprintf(stderr, "err: %s\n", mysql_stmt_error(*stmt)); | ||
2439 | 665 | ++err_cnt; | ||
2440 | 666 | return; | ||
2441 | 667 | } | ||
2442 | 668 | r = mysql_stmt_execute(*stmt); | ||
2443 | 669 | // fprintf(stderr, "stmt exec\n"); | ||
2444 | 670 | } else if (use_in) { | ||
2445 | 671 | r = mysql_real_query(db, wbuf.begin(), wbuf.size()); | ||
2446 | 672 | } else { | ||
2447 | 673 | r = mysql_real_query(db, buf_query, buf_query_len); | ||
2448 | 674 | // fprintf(stderr, "real query\n"); | ||
2449 | 675 | } | ||
2450 | 676 | ++query_cnt; | ||
2451 | 677 | } | ||
2452 | 678 | if (r != 0) { | ||
2453 | 679 | err = 1; | ||
2454 | 680 | } else if (ssps) { | ||
2455 | 681 | if (verbose >= 0) { | ||
2456 | 682 | char resbuf[1024]; | ||
2457 | 683 | unsigned long res_len = 0; | ||
2458 | 684 | MYSQL_BIND bind[1] = { }; | ||
2459 | 685 | bind[0].buffer_type = MYSQL_TYPE_STRING; | ||
2460 | 686 | bind[0].buffer = resbuf; | ||
2461 | 687 | bind[0].buffer_length = sizeof(resbuf); | ||
2462 | 688 | bind[0].length = &res_len; | ||
2463 | 689 | if (mysql_stmt_bind_result(*stmt, bind)) { | ||
2464 | 690 | fprintf(stderr, "err: %s\n", mysql_stmt_error(*stmt)); | ||
2465 | 691 | ++err_cnt; | ||
2466 | 692 | return; | ||
2467 | 693 | } | ||
2468 | 694 | if (mysql_stmt_fetch(*stmt)) { | ||
2469 | 695 | fprintf(stderr, "err: %s\n", mysql_stmt_error(*stmt)); | ||
2470 | 696 | ++err_cnt; | ||
2471 | 697 | return; | ||
2472 | 698 | } | ||
2473 | 699 | if (!result_str.empty()) { | ||
2474 | 700 | result_str += " "; | ||
2475 | 701 | } | ||
2476 | 702 | result_str += std::string(resbuf, res_len); | ||
2477 | 703 | // fprintf(stderr, "SSPS RES: %s\n", result_str.c_str()); | ||
2478 | 704 | got_data = 1; | ||
2479 | 705 | } else { | ||
2480 | 706 | got_data = 1; | ||
2481 | 707 | } | ||
2482 | 708 | } else { | ||
2483 | 709 | auto_mysql_res res(db); | ||
2484 | 710 | if (res != 0) { | ||
2485 | 711 | if (verbose >= 0) { | ||
2486 | 712 | num_flds = mysql_num_fields(res); | ||
2487 | 713 | MYSQL_ROW row = 0; | ||
2488 | 714 | while ((row = mysql_fetch_row(res)) != 0) { | ||
2489 | 715 | got_data += 1; | ||
2490 | 716 | unsigned long *const lengths = mysql_fetch_lengths(res); | ||
2491 | 717 | if (verbose >= 2) { | ||
2492 | 718 | for (unsigned int i = 0; i < num_flds; ++i) { | ||
2493 | 719 | if (!result_str.empty()) { | ||
2494 | 720 | result_str += " "; | ||
2495 | 721 | } | ||
2496 | 722 | result_str += std::string(row[i], lengths[i]); | ||
2497 | 723 | } | ||
2498 | 724 | } | ||
2499 | 725 | } | ||
2500 | 726 | } else { | ||
2501 | 727 | MYSQL_ROW row = 0; | ||
2502 | 728 | while ((row = mysql_fetch_row(res)) != 0) { | ||
2503 | 729 | got_data += 1; | ||
2504 | 730 | } | ||
2505 | 731 | } | ||
2506 | 732 | } else { | ||
2507 | 733 | if (mysql_field_count(db) == 0) { | ||
2508 | 734 | num_affected_rows = mysql_affected_rows(db); | ||
2509 | 735 | } else { | ||
2510 | 736 | err = 1; | ||
2511 | 737 | } | ||
2512 | 738 | } | ||
2513 | 739 | } | ||
2514 | 740 | if (verbose >= 2 || (verbose >= 1 && err != 0)) { | ||
2515 | 741 | if (err) { | ||
2516 | 742 | ++err_cnt; | ||
2517 | 743 | const char *const errstr = mysql_error(db); | ||
2518 | 744 | fprintf(stderr, "e=[%s] a=%u q=[%s]\n", errstr, | ||
2519 | 745 | num_affected_rows, buf_query); | ||
2520 | 746 | } else { | ||
2521 | 747 | fprintf(stderr, "a=%u q=[%s] r=[%s]\n", num_affected_rows, buf_query, | ||
2522 | 748 | result_str.c_str()); | ||
2523 | 749 | } | ||
2524 | 750 | } | ||
2525 | 751 | if (err == 0) { | ||
2526 | 752 | ++io_success_count; | ||
2527 | 753 | if (num_affected_rows > 0 || got_data > 0) { | ||
2528 | 754 | op_success_count += got_data; | ||
2529 | 755 | } else { | ||
2530 | 756 | if (verbose >= 1) { | ||
2531 | 757 | fprintf(stderr, "k=%d numaff=%u gotdata=%d\n", | ||
2532 | 758 | k, num_affected_rows, got_data); | ||
2533 | 759 | } | ||
2534 | 760 | } | ||
2535 | 761 | arg.sh.increment_count(); | ||
2536 | 762 | } | ||
2537 | 763 | if (!keep_connection) { | ||
2538 | 764 | if (stmt.get() != 0) { | ||
2539 | 765 | stmt.reset(); | ||
2540 | 766 | } | ||
2541 | 767 | db.reset(); | ||
2542 | 768 | connected = 0; | ||
2543 | 769 | } | ||
2544 | 770 | const double tm2 = gettimeofday_double(); | ||
2545 | 771 | set_timing(tm2 - tm1); | ||
2546 | 772 | sleep_if(); | ||
2547 | 773 | if (sched_flag) { | ||
2548 | 774 | sched_yield(); | ||
2549 | 775 | } | ||
2550 | 776 | } | ||
2551 | 777 | if (verbose >= 1) { | ||
2552 | 778 | fprintf(stderr, "thread finished (error_count=%llu)\n", err_cnt); | ||
2553 | 779 | } | ||
2554 | 780 | } | ||
2555 | 781 | |||
2556 | 782 | void | ||
2557 | 783 | hstest_thread::test_10(int test_num) | ||
2558 | 784 | { | ||
2559 | 785 | const int keep_connection = arg.sh.conf.get_int("keep_connection", 1); | ||
2560 | 786 | unsigned int seed = time(0) + arg.id + 1; | ||
2561 | 787 | seed ^= arg.sh.conf.get_int("seed_xor", 0); | ||
2562 | 788 | drand48_data randbuf; | ||
2563 | 789 | srand48_r(seed, &randbuf); | ||
2564 | 790 | std::string err; | ||
2565 | 791 | int keepconn_count = 0; | ||
2566 | 792 | const char op = arg.sh.op; | ||
2567 | 793 | const int verbose = arg.sh.conf.get_int("verbose", 1); | ||
2568 | 794 | const std::string suffix = arg.sh.conf.get_str("value_suffix", "upd"); | ||
2569 | 795 | const int tablesize = arg.sh.conf.get_int("tablesize", 10000); | ||
2570 | 796 | const int firstkey = arg.sh.conf.get_int("firstkey", 0); | ||
2571 | 797 | const int sched_flag = arg.sh.conf.get_int("sched", 0); | ||
2572 | 798 | const int moreflds = arg.sh.conf.get_int("moreflds", 0); | ||
2573 | 799 | const std::string dbname = arg.sh.conf.get_str("dbname", "hstest"); | ||
2574 | 800 | const std::string table = arg.sh.conf.get_str("table", "hstest_table1"); | ||
2575 | 801 | const std::string index = arg.sh.conf.get_str("index", "PRIMARY"); | ||
2576 | 802 | const std::string field = arg.sh.conf.get_str("field", "v"); | ||
2577 | 803 | const int use_in = arg.sh.conf.get_int("in", 0); | ||
2578 | 804 | const std::string moreflds_prefix = arg.sh.conf.get_str( | ||
2579 | 805 | "moreflds_prefix", "column0123456789_"); | ||
2580 | 806 | const int dump = arg.sh.dump; | ||
2581 | 807 | const int nodup = arg.sh.conf.get_int("nodup", 0); | ||
2582 | 808 | std::string moreflds_str; | ||
2583 | 809 | for (int i = 0; i < moreflds; ++i) { | ||
2584 | 810 | char sbuf[1024]; | ||
2585 | 811 | snprintf(sbuf, sizeof(sbuf), ",%s%d", moreflds_prefix.c_str(), i); | ||
2586 | 812 | moreflds_str += std::string(sbuf); | ||
2587 | 813 | } | ||
2588 | 814 | string_buffer wbuf; | ||
2589 | 815 | char rbuf[16384]; | ||
2590 | 816 | for (size_t i = 0; i < arg.sh.loop; ++i) { | ||
2591 | 817 | int len = 0, rlen = 0, wlen = 0; | ||
2592 | 818 | #if 0 | ||
2593 | 819 | const double tm1 = gettimeofday_double(); | ||
2594 | 820 | #endif | ||
2595 | 821 | if (fd.get() < 0) { | ||
2596 | 822 | if (socket_connect(fd, arg.sh.arg, err) != 0) { | ||
2597 | 823 | fprintf(stderr, "connect: %d %s\n", errno, strerror(errno)); | ||
2598 | 824 | return; | ||
2599 | 825 | } | ||
2600 | 826 | char *wp = wbuf.make_space(1024); | ||
2601 | 827 | len = snprintf(wp, 1024, | ||
2602 | 828 | "P\t1\t%s\t%s\tPRIMARY\t%s%s\n", dbname.c_str(), table.c_str(), | ||
2603 | 829 | field.c_str(), moreflds_str.c_str()); | ||
2604 | 830 | /* pst_num, db, table, index, retflds */ | ||
2605 | 831 | wbuf.space_wrote(len); | ||
2606 | 832 | wlen = write(fd.get(), wbuf.begin(), len); | ||
2607 | 833 | if (len != wlen) { | ||
2608 | 834 | fprintf(stderr, "write: %d %d\n", len, wlen); | ||
2609 | 835 | return; | ||
2610 | 836 | } | ||
2611 | 837 | wbuf.clear(); | ||
2612 | 838 | rlen = read(fd.get(), rbuf, sizeof(rbuf)); | ||
2613 | 839 | if (rlen <= 0 || rbuf[rlen - 1] != '\n') { | ||
2614 | 840 | fprintf(stderr, "read: rlen=%d errno=%d\n", rlen, errno); | ||
2615 | 841 | return; | ||
2616 | 842 | } | ||
2617 | 843 | if (rbuf[0] != '0') { | ||
2618 | 844 | fprintf(stderr, "failed to open table\n"); | ||
2619 | 845 | return; | ||
2620 | 846 | } | ||
2621 | 847 | arg.sh.increment_conn(1); | ||
2622 | 848 | } | ||
2623 | 849 | const double tm1 = gettimeofday_double(); | ||
2624 | 850 | for (size_t j = 0; j < arg.sh.pipe; ++j) { | ||
2625 | 851 | int k = 0, v = 0; | ||
2626 | 852 | { | ||
2627 | 853 | while (true) { | ||
2628 | 854 | double kf = 0, vf = 0; | ||
2629 | 855 | drand48_r(&randbuf, &kf); | ||
2630 | 856 | drand48_r(&randbuf, &vf); | ||
2631 | 857 | k = int(kf * tablesize) + firstkey; | ||
2632 | 858 | v = int(vf * tablesize) + firstkey; | ||
2633 | 859 | if (k - firstkey < arg.sh.keygen_size) { | ||
2634 | 860 | volatile char *const ptr = arg.sh.keygen + (k - firstkey); | ||
2635 | 861 | // int oldv = __sync_fetch_and_or(ptr, 1); | ||
2636 | 862 | int oldv = *ptr; | ||
2637 | 863 | *ptr += 1; | ||
2638 | 864 | if (nodup && oldv != 0) { | ||
2639 | 865 | if (dump) { | ||
2640 | 866 | fprintf(stderr, "retry\n"); | ||
2641 | 867 | } | ||
2642 | 868 | continue; | ||
2643 | 869 | } | ||
2644 | 870 | } else { | ||
2645 | 871 | if (nodup) { | ||
2646 | 872 | if (dump) { | ||
2647 | 873 | fprintf(stderr, "retry2\n"); | ||
2648 | 874 | } | ||
2649 | 875 | continue; | ||
2650 | 876 | } | ||
2651 | 877 | } | ||
2652 | 878 | size_t len = 0; | ||
2653 | 879 | if (op == 'G') { | ||
2654 | 880 | if (use_in) { | ||
2655 | 881 | char *wp = wbuf.make_space(1024); | ||
2656 | 882 | len = snprintf(wp, 1024, "1\t=\t1\t\t%d\t0\t@\t0\t%d\t%d", | ||
2657 | 883 | use_in, use_in, k); | ||
2658 | 884 | wbuf.space_wrote(len); | ||
2659 | 885 | for (int j = 1; j < use_in; ++j) { | ||
2660 | 886 | drand48_r(&randbuf, &kf); | ||
2661 | 887 | k = int(kf * tablesize) + firstkey; | ||
2662 | 888 | char *wp = wbuf.make_space(1024); | ||
2663 | 889 | len = snprintf(wp, 1024, "\t%d", k); | ||
2664 | 890 | wbuf.space_wrote(len); | ||
2665 | 891 | } | ||
2666 | 892 | wbuf.append_literal("\n"); | ||
2667 | 893 | } else { | ||
2668 | 894 | char *wp = wbuf.make_space(1024); | ||
2669 | 895 | len = snprintf(wp, 1024, "1\t=\t1\t%d\n", k); | ||
2670 | 896 | wbuf.space_wrote(len); | ||
2671 | 897 | } | ||
2672 | 898 | } else if (op == 'U') { | ||
2673 | 899 | char *wp = wbuf.make_space(1024); | ||
2674 | 900 | len = snprintf(wp, 1024, | ||
2675 | 901 | "1\t=\t1\t%d\t1\t0\tU\t%d_%d%s\n", k, v, k, suffix.c_str()); | ||
2676 | 902 | wbuf.space_wrote(len); | ||
2677 | 903 | } | ||
2678 | 904 | break; | ||
2679 | 905 | } | ||
2680 | 906 | } | ||
2681 | 907 | } | ||
2682 | 908 | wlen = write(fd.get(), wbuf.begin(), wbuf.size()); | ||
2683 | 909 | if (wlen != wbuf.size()) { | ||
2684 | 910 | fprintf(stderr, "write: %d %d\n", (int)wbuf.size(), wlen); | ||
2685 | 911 | return; | ||
2686 | 912 | } | ||
2687 | 913 | wbuf.clear(); | ||
2688 | 914 | size_t read_cnt = 0; | ||
2689 | 915 | size_t read_pos = 0; | ||
2690 | 916 | while (read_cnt < arg.sh.pipe) { | ||
2691 | 917 | rlen = read(fd.get(), rbuf + read_pos, sizeof(rbuf) - read_pos); | ||
2692 | 918 | if (rlen <= 0) { | ||
2693 | 919 | fprintf(stderr, "read: %d\n", rlen); | ||
2694 | 920 | return; | ||
2695 | 921 | } | ||
2696 | 922 | read_pos += rlen; | ||
2697 | 923 | while (true) { | ||
2698 | 924 | const char *const nl = static_cast<const char *>(memchr(rbuf, '\n', | ||
2699 | 925 | read_pos)); | ||
2700 | 926 | if (nl == 0) { | ||
2701 | 927 | break; | ||
2702 | 928 | } | ||
2703 | 929 | ++read_cnt; | ||
2704 | 930 | ++io_success_count; | ||
2705 | 931 | const char *t1 = static_cast<const char *>(memchr(rbuf, '\t', | ||
2706 | 932 | nl - rbuf)); | ||
2707 | 933 | if (t1 == 0) { | ||
2708 | 934 | fprintf(stderr, "error \n"); | ||
2709 | 935 | break; | ||
2710 | 936 | } | ||
2711 | 937 | ++t1; | ||
2712 | 938 | const char *t2 = static_cast<const char *>(memchr(t1, '\t', | ||
2713 | 939 | nl - t1)); | ||
2714 | 940 | if (t2 == 0) { | ||
2715 | 941 | if (verbose > 1) { | ||
2716 | 942 | fprintf(stderr, "key: notfound \n"); | ||
2717 | 943 | } | ||
2718 | 944 | break; | ||
2719 | 945 | } | ||
2720 | 946 | ++t2; | ||
2721 | 947 | if (t1 == rbuf + 2 && rbuf[0] == '0') { | ||
2722 | 948 | if (op == 'G') { | ||
2723 | 949 | ++op_success_count; | ||
2724 | 950 | arg.sh.increment_count(); | ||
2725 | 951 | } else if (op == 'U') { | ||
2726 | 952 | const char *t3 = t2; | ||
2727 | 953 | while (t3 != nl && t3[0] >= 0x10) { | ||
2728 | 954 | ++t3; | ||
2729 | 955 | } | ||
2730 | 956 | if (t3 != t2 + 1 || t2[0] != '1') { | ||
2731 | 957 | const std::string mess(t2, t3); | ||
2732 | 958 | fprintf(stderr, "mod: %s\n", mess.c_str()); | ||
2733 | 959 | } else { | ||
2734 | 960 | ++op_success_count; | ||
2735 | 961 | arg.sh.increment_count(); | ||
2736 | 962 | if (arg.sh.dump && arg.sh.pipe == 1) { | ||
2737 | 963 | fwrite(wbuf, wbuflen, 1, stderr); | ||
2738 | 964 | } | ||
2739 | 965 | } | ||
2740 | 966 | } | ||
2741 | 967 | } else { | ||
2742 | 968 | const char *t3 = t2; | ||
2743 | 969 | while (t3 != nl && t3[0] >= 0x10) { | ||
2744 | 970 | ++t3; | ||
2745 | 971 | } | ||
2746 | 972 | const std::string mess(t2, t3); | ||
2747 | 973 | fprintf(stderr, "err: %s\n", mess.c_str()); | ||
2748 | 974 | } | ||
2749 | 975 | const size_t rest_size = rbuf + read_pos - (nl + 1); | ||
2750 | 976 | if (rest_size != 0) { | ||
2751 | 977 | memmove(rbuf, nl + 1, rest_size); | ||
2752 | 978 | } | ||
2753 | 979 | read_pos = rest_size; | ||
2754 | 980 | } | ||
2755 | 981 | } | ||
2756 | 982 | if (!keep_connection) { | ||
2757 | 983 | fd.reset(); | ||
2758 | 984 | arg.sh.increment_conn(-1); | ||
2759 | 985 | } else if (keep_connection > 1 && ++keepconn_count > keep_connection) { | ||
2760 | 986 | keepconn_count = 0; | ||
2761 | 987 | fd.reset(); | ||
2762 | 988 | arg.sh.increment_conn(-1); | ||
2763 | 989 | } | ||
2764 | 990 | const double tm2 = gettimeofday_double(); | ||
2765 | 991 | set_timing(tm2 - tm1); | ||
2766 | 992 | sleep_if(); | ||
2767 | 993 | if (sched_flag) { | ||
2768 | 994 | sched_yield(); | ||
2769 | 995 | } | ||
2770 | 996 | } | ||
2771 | 997 | if (dump) { | ||
2772 | 998 | fprintf(stderr, "done\n"); | ||
2773 | 999 | } | ||
2774 | 1000 | } | ||
2775 | 1001 | |||
2776 | 1002 | void | ||
2777 | 1003 | hstest_thread::sleep_if() | ||
2778 | 1004 | { | ||
2779 | 1005 | if (arg.sh.usleep) { | ||
2780 | 1006 | struct timespec ts = { | ||
2781 | 1007 | arg.sh.usleep / 1000000, | ||
2782 | 1008 | (arg.sh.usleep % 1000000) * 1000 | ||
2783 | 1009 | }; | ||
2784 | 1010 | nanosleep(&ts, 0); | ||
2785 | 1011 | } | ||
2786 | 1012 | } | ||
2787 | 1013 | |||
2788 | 1014 | void | ||
2789 | 1015 | hstest_thread::set_timing(double time_spent) | ||
2790 | 1016 | { | ||
2791 | 1017 | response_min = std::min(response_min, time_spent); | ||
2792 | 1018 | response_max = std::max(response_max, time_spent); | ||
2793 | 1019 | response_sum += time_spent; | ||
2794 | 1020 | if (op_success_count != 0) { | ||
2795 | 1021 | response_avg = response_sum / op_success_count; | ||
2796 | 1022 | } | ||
2797 | 1023 | } | ||
2798 | 1024 | |||
2799 | 1025 | void | ||
2800 | 1026 | hstest_thread::test_11(int test_num) | ||
2801 | 1027 | { | ||
2802 | 1028 | const int keep_connection = arg.sh.conf.get_int("keep_connection", 1); | ||
2803 | 1029 | const int tablesize = arg.sh.conf.get_int("tablesize", 0); | ||
2804 | 1030 | unsigned int seed = arg.id; | ||
2805 | 1031 | seed ^= arg.sh.conf.get_int("seed_xor", 0); | ||
2806 | 1032 | std::string err; | ||
2807 | 1033 | hstcpcli_ptr cli; | ||
2808 | 1034 | for (size_t i = 0; i < arg.sh.loop; ++i) { | ||
2809 | 1035 | if (cli.get() == 0) { | ||
2810 | 1036 | cli = hstcpcli_i::create(arg.sh.arg); | ||
2811 | 1037 | cli->request_buf_open_index(0, "hstest", "hstest_table1", "", "v"); | ||
2812 | 1038 | /* pst_num, db, table, index, retflds */ | ||
2813 | 1039 | if (cli->request_send() != 0) { | ||
2814 | 1040 | fprintf(stderr, "reuqest_send: %s\n", cli->get_error().c_str()); | ||
2815 | 1041 | return; | ||
2816 | 1042 | } | ||
2817 | 1043 | size_t num_flds = 0; | ||
2818 | 1044 | if (cli->response_recv(num_flds) != 0) { | ||
2819 | 1045 | fprintf(stderr, "reuqest_recv: %s\n", cli->get_error().c_str()); | ||
2820 | 1046 | return; | ||
2821 | 1047 | } | ||
2822 | 1048 | cli->response_buf_remove(); | ||
2823 | 1049 | } | ||
2824 | 1050 | for (size_t j = 0; j < arg.sh.pipe; ++j) { | ||
2825 | 1051 | char buf[256]; | ||
2826 | 1052 | int k = 0, v = 0, len = 0; | ||
2827 | 1053 | { | ||
2828 | 1054 | k = rand_r(&seed); | ||
2829 | 1055 | v = rand_r(&seed); /* unused */ | ||
2830 | 1056 | if (tablesize != 0) { | ||
2831 | 1057 | k &= tablesize; | ||
2832 | 1058 | } | ||
2833 | 1059 | len = snprintf(buf, sizeof(buf), "%d", k); | ||
2834 | 1060 | } | ||
2835 | 1061 | const string_ref key(buf, len); | ||
2836 | 1062 | const string_ref op("=", 1); | ||
2837 | 1063 | cli->request_buf_exec_generic(0, op, &key, 1, 1, 0, string_ref(), 0, 0); | ||
2838 | 1064 | } | ||
2839 | 1065 | if (cli->request_send() != 0) { | ||
2840 | 1066 | fprintf(stderr, "reuqest_send: %s\n", cli->get_error().c_str()); | ||
2841 | 1067 | return; | ||
2842 | 1068 | } | ||
2843 | 1069 | size_t read_cnt = 0; | ||
2844 | 1070 | for (size_t j = 0; j < arg.sh.pipe; ++j) { | ||
2845 | 1071 | size_t num_flds = 0; | ||
2846 | 1072 | if (cli->response_recv(num_flds) != 0) { | ||
2847 | 1073 | fprintf(stderr, "reuqest_recv: %s\n", cli->get_error().c_str()); | ||
2848 | 1074 | return; | ||
2849 | 1075 | } | ||
2850 | 1076 | { | ||
2851 | 1077 | ++read_cnt; | ||
2852 | 1078 | ++io_success_count; | ||
2853 | 1079 | arg.sh.increment_count(); | ||
2854 | 1080 | { | ||
2855 | 1081 | ++op_success_count; | ||
2856 | 1082 | } | ||
2857 | 1083 | } | ||
2858 | 1084 | cli->response_buf_remove(); | ||
2859 | 1085 | } | ||
2860 | 1086 | if (!keep_connection) { | ||
2861 | 1087 | cli.reset(); | ||
2862 | 1088 | } | ||
2863 | 1089 | } | ||
2864 | 1090 | } | ||
2865 | 1091 | |||
2866 | 1092 | void | ||
2867 | 1093 | hstest_thread::test_watch() | ||
2868 | 1094 | { | ||
2869 | 1095 | const int timelimit = arg.sh.conf.get_int("timelimit", 0); | ||
2870 | 1096 | const int timelimit_offset = timelimit / 2; | ||
2871 | 1097 | int loop = 0; | ||
2872 | 1098 | double t1 = 0, t2 = 0; | ||
2873 | 1099 | size_t cnt_t1 = 0, cnt_t2 = 0; | ||
2874 | 1100 | size_t prev_cnt = 0; | ||
2875 | 1101 | double now_f = 0; | ||
2876 | 1102 | while (true) { | ||
2877 | 1103 | sleep(1); | ||
2878 | 1104 | const size_t cnt = arg.sh.count; | ||
2879 | 1105 | const size_t df = cnt - prev_cnt; | ||
2880 | 1106 | prev_cnt = cnt; | ||
2881 | 1107 | const double now_prev = now_f; | ||
2882 | 1108 | now_f = gettimeofday_double(); | ||
2883 | 1109 | if (now_prev != 0) { | ||
2884 | 1110 | const double rps = static_cast<double>(df) / (now_f - now_prev); | ||
2885 | 1111 | fprintf(stderr, "now: %zu cntdiff: %zu tdiff: %f rps: %f\n", | ||
2886 | 1112 | static_cast<size_t>(now_f), df, now_f - now_prev, rps); | ||
2887 | 1113 | } | ||
2888 | 1114 | if (timelimit != 0) { | ||
2889 | 1115 | if (arg.sh.wait_conn == 0 || arg.sh.conn_count >= arg.sh.wait_conn) { | ||
2890 | 1116 | ++loop; | ||
2891 | 1117 | } | ||
2892 | 1118 | if (loop == timelimit_offset) { | ||
2893 | 1119 | t1 = gettimeofday_double(); | ||
2894 | 1120 | cnt_t1 = cnt; | ||
2895 | 1121 | arg.sh.enable_timing = 1; | ||
2896 | 1122 | fprintf(stderr, "start timing\n"); | ||
2897 | 1123 | } else if (loop == timelimit_offset + timelimit) { | ||
2898 | 1124 | t2 = gettimeofday_double(); | ||
2899 | 1125 | cnt_t2 = cnt; | ||
2900 | 1126 | const size_t cnt_diff = cnt_t2 - cnt_t1; | ||
2901 | 1127 | const double tdiff = t2 - t1; | ||
2902 | 1128 | const double qps = cnt_diff / (tdiff != 0 ? tdiff : 1); | ||
2903 | 1129 | fprintf(stderr, "(%f: %zu, %f: %zu), %10.5f qps\n", | ||
2904 | 1130 | t1, cnt_t1, t2, cnt_t2, qps); | ||
2905 | 1131 | size_t keycnt = 0; | ||
2906 | 1132 | for (int i = 0; i < arg.sh.keygen_size; ++i) { | ||
2907 | 1133 | if (arg.sh.keygen[i]) { | ||
2908 | 1134 | ++keycnt; | ||
2909 | 1135 | } | ||
2910 | 1136 | } | ||
2911 | 1137 | fprintf(stderr, "keygen=%zu\n", keycnt); | ||
2912 | 1138 | break; | ||
2913 | 1139 | } | ||
2914 | 1140 | } | ||
2915 | 1141 | } | ||
2916 | 1142 | #if 0 | ||
2917 | 1143 | int loop = 0; | ||
2918 | 1144 | double t1 = 0, t2 = 0; | ||
2919 | 1145 | size_t cnt_t1 = 0, cnt_t2 = 0; | ||
2920 | 1146 | size_t prev_cnt = 0; | ||
2921 | 1147 | while (true) { | ||
2922 | 1148 | sleep(1); | ||
2923 | 1149 | const size_t cnt = arg.sh.count; | ||
2924 | 1150 | const size_t df = cnt - prev_cnt; | ||
2925 | 1151 | prev_cnt = cnt; | ||
2926 | 1152 | const size_t now = time(0); | ||
2927 | 1153 | fprintf(stderr, "%zu %zu\n", now, df); | ||
2928 | 1154 | if (timelimit != 0) { | ||
2929 | 1155 | ++loop; | ||
2930 | 1156 | if (loop == timelimit_offset) { | ||
2931 | 1157 | t1 = gettimeofday_double(); | ||
2932 | 1158 | cnt_t1 = cnt; | ||
2933 | 1159 | } else if (loop == timelimit_offset + timelimit) { | ||
2934 | 1160 | t2 = gettimeofday_double(); | ||
2935 | 1161 | cnt_t2 = cnt; | ||
2936 | 1162 | const size_t cnt_diff = cnt_t2 - cnt_t1; | ||
2937 | 1163 | const double tdiff = t2 - t1; | ||
2938 | 1164 | const double qps = cnt_diff / (tdiff != 0 ? tdiff : 1); | ||
2939 | 1165 | fprintf(stderr, "(%f: %zu, %f: %zu), %10.5f qps\n", | ||
2940 | 1166 | t1, cnt_t1, t2, cnt_t2, qps); | ||
2941 | 1167 | size_t keycnt = 0; | ||
2942 | 1168 | for (int i = 0; i < arg.sh.keygen_size; ++i) { | ||
2943 | 1169 | if (arg.sh.keygen[i]) { | ||
2944 | 1170 | ++keycnt; | ||
2945 | 1171 | } | ||
2946 | 1172 | } | ||
2947 | 1173 | fprintf(stderr, "keygen=%zu\n", keycnt); | ||
2948 | 1174 | _exit(0); | ||
2949 | 1175 | } | ||
2950 | 1176 | } | ||
2951 | 1177 | } | ||
2952 | 1178 | #endif | ||
2953 | 1179 | } | ||
2954 | 1180 | |||
2955 | 1181 | void | ||
2956 | 1182 | hstest_thread::test_12(int test_num) | ||
2957 | 1183 | { | ||
2958 | 1184 | /* NOTE: num_threads should be 1 */ | ||
2959 | 1185 | /* create table hstest | ||
2960 | 1186 | * ( k varchar(255) not null, v varchar(255) not null, primary key(k)) | ||
2961 | 1187 | * engine = innodb; */ | ||
2962 | 1188 | mysqltest_thread_initobj initobj; | ||
2963 | 1189 | auto_mysql db; | ||
2964 | 1190 | std::string err; | ||
2965 | 1191 | unsigned long long err_cnt = 0; | ||
2966 | 1192 | unsigned long long query_cnt = 0; | ||
2967 | 1193 | #if 0 | ||
2968 | 1194 | my_bool reconnect = 0; | ||
2969 | 1195 | if (mysql_options(db, MYSQL_OPT_RECONNECT, &reconnect) != 0) { | ||
2970 | 1196 | err = "mysql_options() failed"; | ||
2971 | 1197 | ++err_cnt; | ||
2972 | 1198 | return; | ||
2973 | 1199 | } | ||
2974 | 1200 | #endif | ||
2975 | 1201 | const std::string mysql_host = arg.sh.conf.get_str("host", "localhost"); | ||
2976 | 1202 | const int mysql_port = arg.sh.conf.get_int("mysqlport", 3306); | ||
2977 | 1203 | const unsigned int num = arg.sh.loop; | ||
2978 | 1204 | const size_t pipe = arg.sh.pipe; | ||
2979 | 1205 | const std::string mysql_user = arg.sh.conf.get_str("mysqluser", "root"); | ||
2980 | 1206 | const std::string mysql_passwd = arg.sh.conf.get_str("mysqlpass", ""); | ||
2981 | 1207 | const std::string mysql_dbname = arg.sh.conf.get_str("db", "hstest"); | ||
2982 | 1208 | const int keep_connection = arg.sh.conf.get_int("keep_connection", 1); | ||
2983 | 1209 | const int verbose = arg.sh.conf.get_int("verbose", 1); | ||
2984 | 1210 | const int use_handler = arg.sh.conf.get_int("handler", 0); | ||
2985 | 1211 | int connected = 0; | ||
2986 | 1212 | unsigned int k = 0; | ||
2987 | 1213 | string_buffer buf; | ||
2988 | 1214 | for (unsigned int i = 0; i < num; ++i) { | ||
2989 | 1215 | const int flags = 0; | ||
2990 | 1216 | if (connected == 0 && !mysql_real_connect(db, mysql_host.c_str(), | ||
2991 | 1217 | mysql_user.c_str(), mysql_user.empty() ? 0 : mysql_passwd.c_str(), | ||
2992 | 1218 | mysql_dbname.c_str(), mysql_port, 0, flags)) { | ||
2993 | 1219 | err = "failed to connect: " + std::string(mysql_error(db)); | ||
2994 | 1220 | if (verbose >= 1) { | ||
2995 | 1221 | fprintf(stderr, "e=[%s]\n", err.c_str()); | ||
2996 | 1222 | } | ||
2997 | 1223 | ++err_cnt; | ||
2998 | 1224 | return; | ||
2999 | 1225 | } | ||
3000 | 1226 | int r = 0; | ||
3001 | 1227 | if (connected == 0 && use_handler) { | ||
3002 | 1228 | const char *const q = "handler hstest open"; | ||
3003 | 1229 | r = mysql_real_query(db, q, strlen(q)); | ||
3004 | 1230 | if (r != 0) { | ||
3005 | 1231 | err = 1; | ||
3006 | 1232 | } | ||
3007 | 1233 | } | ||
3008 | 1234 | connected = 1; | ||
3009 | 1235 | std::string result_str; | ||
3010 | 1236 | unsigned int err = 0; | ||
3011 | 1237 | unsigned int num_flds = 0, num_affected_rows = 0; | ||
3012 | 1238 | int got_data = 0; | ||
3013 | 1239 | buf.clear(); | ||
3014 | 1240 | buf.append_literal("insert into hstest values "); | ||
3015 | 1241 | for (size_t j = 0; j < pipe; ++j) { | ||
3016 | 1242 | const unsigned int v = ~k; | ||
3017 | 1243 | if (j != 0) { | ||
3018 | 1244 | buf.append_literal(","); | ||
3019 | 1245 | } | ||
3020 | 1246 | char *wp = buf.make_space(64); | ||
3021 | 1247 | int buf_query_len = snprintf(wp, 64, "('k%u', 'v%u')", k, v); | ||
3022 | 1248 | buf.space_wrote(buf_query_len); | ||
3023 | 1249 | ++k; | ||
3024 | 1250 | } | ||
3025 | 1251 | if (r == 0) { | ||
3026 | 1252 | r = mysql_real_query(db, buf.begin(), buf.size()); | ||
3027 | 1253 | ++query_cnt; | ||
3028 | 1254 | } | ||
3029 | 1255 | if (r != 0) { | ||
3030 | 1256 | err = 1; | ||
3031 | 1257 | } else { | ||
3032 | 1258 | auto_mysql_res res(db); | ||
3033 | 1259 | if (res != 0) { | ||
3034 | 1260 | if (verbose >= 0) { | ||
3035 | 1261 | num_flds = mysql_num_fields(res); | ||
3036 | 1262 | MYSQL_ROW row = 0; | ||
3037 | 1263 | while ((row = mysql_fetch_row(res)) != 0) { | ||
3038 | 1264 | got_data = 1; | ||
3039 | 1265 | unsigned long *const lengths = mysql_fetch_lengths(res); | ||
3040 | 1266 | if (verbose >= 2) { | ||
3041 | 1267 | for (unsigned int i = 0; i < num_flds; ++i) { | ||
3042 | 1268 | if (!result_str.empty()) { | ||
3043 | 1269 | result_str += " "; | ||
3044 | 1270 | } | ||
3045 | 1271 | result_str += std::string(row[i], lengths[i]); | ||
3046 | 1272 | } | ||
3047 | 1273 | } | ||
3048 | 1274 | } | ||
3049 | 1275 | } | ||
3050 | 1276 | } else { | ||
3051 | 1277 | if (mysql_field_count(db) == 0) { | ||
3052 | 1278 | num_affected_rows = mysql_affected_rows(db); | ||
3053 | 1279 | } else { | ||
3054 | 1280 | err = 1; | ||
3055 | 1281 | } | ||
3056 | 1282 | } | ||
3057 | 1283 | } | ||
3058 | 1284 | if (verbose >= 2 || (verbose >= 1 && err != 0)) { | ||
3059 | 1285 | if (err) { | ||
3060 | 1286 | ++err_cnt; | ||
3061 | 1287 | const char *const errstr = mysql_error(db); | ||
3062 | 1288 | fprintf(stderr, "e=[%s] a=%u q=[%s]\n", errstr, | ||
3063 | 1289 | num_affected_rows, std::string(buf.begin(), buf.size()).c_str()); | ||
3064 | 1290 | } else { | ||
3065 | 1291 | fprintf(stderr, "a=%u q=[%s] r=[%s]\n", num_affected_rows, | ||
3066 | 1292 | std::string(buf.begin(), buf.size()).c_str(), | ||
3067 | 1293 | result_str.c_str()); | ||
3068 | 1294 | } | ||
3069 | 1295 | } | ||
3070 | 1296 | if (err == 0) { | ||
3071 | 1297 | ++io_success_count; | ||
3072 | 1298 | if (num_affected_rows > 0 || got_data > 0) { | ||
3073 | 1299 | ++op_success_count; | ||
3074 | 1300 | } | ||
3075 | 1301 | arg.sh.increment_count(pipe); | ||
3076 | 1302 | } | ||
3077 | 1303 | if (!keep_connection) { | ||
3078 | 1304 | db.reset(); | ||
3079 | 1305 | connected = 0; | ||
3080 | 1306 | } | ||
3081 | 1307 | } | ||
3082 | 1308 | if (verbose >= 1) { | ||
3083 | 1309 | fprintf(stderr, "thread finished (error_count=%llu)\n", err_cnt); | ||
3084 | 1310 | } | ||
3085 | 1311 | } | ||
3086 | 1312 | |||
3087 | 1313 | void | ||
3088 | 1314 | hstest_thread::test_21(int num) | ||
3089 | 1315 | { | ||
3090 | 1316 | /* fsync test */ | ||
3091 | 1317 | unsigned int id = arg.id; | ||
3092 | 1318 | std::string err; | ||
3093 | 1319 | #if 0 | ||
3094 | 1320 | if (socket_connect(fd, arg.sh.arg, err) != 0) { | ||
3095 | 1321 | fprintf(stderr, "connect: %d %s\n", errno, strerror(errno)); | ||
3096 | 1322 | return; | ||
3097 | 1323 | } | ||
3098 | 1324 | #endif | ||
3099 | 1325 | auto_file logfd; | ||
3100 | 1326 | char fname[1024]; | ||
3101 | 1327 | snprintf(fname, sizeof(fname), "synctest_%u", id); | ||
3102 | 1328 | int open_flags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND; | ||
3103 | 1329 | logfd.reset(open(fname, open_flags, 0644)); | ||
3104 | 1330 | if (logfd.get() < 0) { | ||
3105 | 1331 | fprintf(stderr, "open: %s: %d %s\n", fname, errno, strerror(errno)); | ||
3106 | 1332 | return; | ||
3107 | 1333 | } | ||
3108 | 1334 | char buf[1024]; | ||
3109 | 1335 | unsigned long long count = 0; | ||
3110 | 1336 | while (true) { | ||
3111 | 1337 | snprintf(buf, sizeof(buf), "%u %llu\n", id, count); | ||
3112 | 1338 | const size_t len = strlen(buf); | ||
3113 | 1339 | if (write(logfd.get(), buf, len) != (ssize_t)len) { | ||
3114 | 1340 | fprintf(stderr, "write: %s: %d %s\n", fname, errno, strerror(errno)); | ||
3115 | 1341 | return; | ||
3116 | 1342 | } | ||
3117 | 1343 | #if 0 | ||
3118 | 1344 | if (write(fd.get(), buf, len) != (ssize_t)len) { | ||
3119 | 1345 | fprintf(stderr, "write(sock): %d %s\n", errno, strerror(errno)); | ||
3120 | 1346 | return; | ||
3121 | 1347 | } | ||
3122 | 1348 | #endif | ||
3123 | 1349 | if (fdatasync(logfd.get()) != 0) { | ||
3124 | 1350 | fprintf(stderr, "fsync: %s: %d %s\n", fname, errno, strerror(errno)); | ||
3125 | 1351 | return; | ||
3126 | 1352 | } | ||
3127 | 1353 | ++count; | ||
3128 | 1354 | ++op_success_count; | ||
3129 | 1355 | arg.sh.increment_count(); | ||
3130 | 1356 | } | ||
3131 | 1357 | } | ||
3132 | 1358 | |||
3133 | 1359 | void | ||
3134 | 1360 | hstest_thread::test_22(int num) | ||
3135 | 1361 | { | ||
3136 | 1362 | /* dd if=/dev/zero of=dummy.dat bs=1024M count=100 */ | ||
3137 | 1363 | unsigned int id = arg.id; | ||
3138 | 1364 | std::string err; | ||
3139 | 1365 | auto_file filefd; | ||
3140 | 1366 | char fname[1024]; | ||
3141 | 1367 | snprintf(fname, sizeof(fname), "dummy.dat"); | ||
3142 | 1368 | int open_flags = O_RDONLY | O_DIRECT; | ||
3143 | 1369 | filefd.reset(open(fname, open_flags, 0644)); | ||
3144 | 1370 | if (filefd.get() < 0) { | ||
3145 | 1371 | fprintf(stderr, "open: %s: %d %s\n", fname, errno, strerror(errno)); | ||
3146 | 1372 | return; | ||
3147 | 1373 | } | ||
3148 | 1374 | char buf_x[4096 * 2]; | ||
3149 | 1375 | char *const buf = (char *)(size_t(buf_x + 4096) / 4096 * 4096); | ||
3150 | 1376 | unsigned long long count = 0; | ||
3151 | 1377 | drand48_data randbuf; | ||
3152 | 1378 | unsigned long long seed = time(0); | ||
3153 | 1379 | seed *= 10; | ||
3154 | 1380 | seed += id; | ||
3155 | 1381 | srand48_r(seed, &randbuf); | ||
3156 | 1382 | for (unsigned int i = 0; i < arg.sh.loop; ++i) { | ||
3157 | 1383 | double kf = 0; | ||
3158 | 1384 | drand48_r(&randbuf, &kf); | ||
3159 | 1385 | kf *= (209715200 / 1); | ||
3160 | 1386 | // fprintf(stderr, "v=%f\n", kf); | ||
3161 | 1387 | off_t v = static_cast<off_t>(kf); | ||
3162 | 1388 | v %= (209715200 / 1); | ||
3163 | 1389 | v *= (512 * 1); | ||
3164 | 1390 | const double tm1 = gettimeofday_double(); | ||
3165 | 1391 | const ssize_t r = pread(filefd.get(), buf, (512 * 1), v); | ||
3166 | 1392 | const double tm2 = gettimeofday_double(); | ||
3167 | 1393 | if (r < 0) { | ||
3168 | 1394 | fprintf(stderr, "pread: %s: %d %s\n", fname, errno, strerror(errno)); | ||
3169 | 1395 | return; | ||
3170 | 1396 | } | ||
3171 | 1397 | ++count; | ||
3172 | 1398 | ++op_success_count; | ||
3173 | 1399 | arg.sh.increment_count(); | ||
3174 | 1400 | set_timing(tm2 - tm1); | ||
3175 | 1401 | } | ||
3176 | 1402 | } | ||
3177 | 1403 | |||
3178 | 1404 | void | ||
3179 | 1405 | hstest_thread::operator ()() | ||
3180 | 1406 | { | ||
3181 | 1407 | if (arg.watch_flag) { | ||
3182 | 1408 | return test_watch(); | ||
3183 | 1409 | } | ||
3184 | 1410 | int test_num = arg.sh.conf.get_int("test", 1); | ||
3185 | 1411 | if (test_num == 1) { | ||
3186 | 1412 | test_1(); | ||
3187 | 1413 | } else if (test_num == 2 || test_num == 3) { | ||
3188 | 1414 | test_2_3(test_num); | ||
3189 | 1415 | } else if (test_num == 4 || test_num == 5) { | ||
3190 | 1416 | test_4_5(test_num); | ||
3191 | 1417 | } else if (test_num == 6) { | ||
3192 | 1418 | test_6(test_num); | ||
3193 | 1419 | } else if (test_num == 7) { | ||
3194 | 1420 | test_7(test_num); | ||
3195 | 1421 | } else if (test_num == 8) { | ||
3196 | 1422 | test_8(test_num); | ||
3197 | 1423 | } else if (test_num == 9) { | ||
3198 | 1424 | test_9(test_num); | ||
3199 | 1425 | } else if (test_num == 10) { | ||
3200 | 1426 | test_10(test_num); | ||
3201 | 1427 | } else if (test_num == 11) { | ||
3202 | 1428 | test_11(test_num); | ||
3203 | 1429 | } else if (test_num == 12) { | ||
3204 | 1430 | test_12(test_num); | ||
3205 | 1431 | } else if (test_num == 21) { | ||
3206 | 1432 | test_21(test_num); | ||
3207 | 1433 | } else if (test_num == 22) { | ||
3208 | 1434 | test_22(test_num); | ||
3209 | 1435 | } | ||
3210 | 1436 | const int halt = arg.sh.conf.get_int("halt", 0); | ||
3211 | 1437 | if (halt) { | ||
3212 | 1438 | fprintf(stderr, "thread halted\n"); | ||
3213 | 1439 | while (true) { | ||
3214 | 1440 | sleep(100000); | ||
3215 | 1441 | } | ||
3216 | 1442 | } | ||
3217 | 1443 | fprintf(stderr, "thread finished\n"); | ||
3218 | 1444 | } | ||
3219 | 1445 | |||
3220 | 1446 | int | ||
3221 | 1447 | hstest_main(int argc, char **argv) | ||
3222 | 1448 | { | ||
3223 | 1449 | ignore_sigpipe(); | ||
3224 | 1450 | hstest_shared shared; | ||
3225 | 1451 | parse_args(argc, argv, shared.conf); | ||
3226 | 1452 | shared.conf["port"] = shared.conf["hsport"]; | ||
3227 | 1453 | shared.arg.set(shared.conf); | ||
3228 | 1454 | shared.loop = shared.conf.get_int("num", 1000); | ||
3229 | 1455 | shared.pipe = shared.conf.get_int("pipe", 1); | ||
3230 | 1456 | shared.verbose = shared.conf.get_int("verbose", 1); | ||
3231 | 1457 | const int tablesize = shared.conf.get_int("tablesize", 0); | ||
3232 | 1458 | std::vector<char> keygen(tablesize); | ||
3233 | 1459 | shared.keygen = &keygen[0]; | ||
3234 | 1460 | shared.keygen_size = tablesize; | ||
3235 | 1461 | shared.usleep = shared.conf.get_int("usleep", 0); | ||
3236 | 1462 | shared.dump = shared.conf.get_int("dump", 0); | ||
3237 | 1463 | shared.num_threads = shared.conf.get_int("num_threads", 10); | ||
3238 | 1464 | shared.wait_conn = shared.conf.get_int("wait_conn", 0); | ||
3239 | 1465 | const std::string op = shared.conf.get_str("op", "G"); | ||
3240 | 1466 | if (op.size() > 0) { | ||
3241 | 1467 | shared.op = op[0]; | ||
3242 | 1468 | } | ||
3243 | 1469 | #if 0 | ||
3244 | 1470 | const int localdb_flag = shared.conf.get_int("local", 0); | ||
3245 | 1471 | if (localdb_flag) { | ||
3246 | 1472 | shared.localdb = database_i::create(shared.conf); | ||
3247 | 1473 | } | ||
3248 | 1474 | #endif | ||
3249 | 1475 | const int num_thrs = shared.num_threads; | ||
3250 | 1476 | typedef thread<hstest_thread> thread_type; | ||
3251 | 1477 | typedef std::auto_ptr<thread_type> thread_ptr; | ||
3252 | 1478 | typedef auto_ptrcontainer< std::vector<thread_type *> > thrs_type; | ||
3253 | 1479 | thrs_type thrs; | ||
3254 | 1480 | for (int i = 0; i < num_thrs; ++i) { | ||
3255 | 1481 | const hstest_thread::arg_type arg(i, shared, false); | ||
3256 | 1482 | thread_ptr thr(new thread<hstest_thread>(arg)); | ||
3257 | 1483 | thrs.push_back_ptr(thr); | ||
3258 | 1484 | } | ||
3259 | 1485 | for (size_t i = 0; i < thrs.size(); ++i) { | ||
3260 | 1486 | thrs[i]->start(); | ||
3261 | 1487 | } | ||
3262 | 1488 | thread_ptr watch_thread; | ||
3263 | 1489 | const int timelimit = shared.conf.get_int("timelimit", 0); | ||
3264 | 1490 | { | ||
3265 | 1491 | const hstest_thread::arg_type arg(0, shared, true); | ||
3266 | 1492 | watch_thread = thread_ptr(new thread<hstest_thread>(arg)); | ||
3267 | 1493 | watch_thread->start(); | ||
3268 | 1494 | } | ||
3269 | 1495 | size_t iocnt = 0, opcnt = 0; | ||
3270 | 1496 | double respmin = 999999, respmax = 0; | ||
3271 | 1497 | double respsum = 0; | ||
3272 | 1498 | if (timelimit != 0) { | ||
3273 | 1499 | watch_thread->join(); | ||
3274 | 1500 | } | ||
3275 | 1501 | for (size_t i = 0; i < thrs.size(); ++i) { | ||
3276 | 1502 | if (timelimit == 0) { | ||
3277 | 1503 | thrs[i]->join(); | ||
3278 | 1504 | } | ||
3279 | 1505 | iocnt += (*thrs[i])->io_success_count; | ||
3280 | 1506 | opcnt += (*thrs[i])->op_success_count; | ||
3281 | 1507 | respmin = std::min(respmin, (*thrs[i])->response_min); | ||
3282 | 1508 | respmax = std::max(respmax, (*thrs[i])->response_max); | ||
3283 | 1509 | respsum += (*thrs[i])->response_sum; | ||
3284 | 1510 | } | ||
3285 | 1511 | fprintf(stderr, "io_success_count=%zu op_success_count=%zu\n", iocnt, opcnt); | ||
3286 | 1512 | fprintf(stderr, "respmin=%f respmax=%f respsum=%f respavg=%f\n", | ||
3287 | 1513 | respmin, respmax, respsum, respsum / opcnt); | ||
3288 | 1514 | size_t keycnt = 0; | ||
3289 | 1515 | for (size_t i = 0; i < keygen.size(); ++i) { | ||
3290 | 1516 | if (keygen[i]) { | ||
3291 | 1517 | ++keycnt; | ||
3292 | 1518 | } | ||
3293 | 1519 | } | ||
3294 | 1520 | fprintf(stderr, "keycnt=%zu\n", keycnt); | ||
3295 | 1521 | _exit(0); | ||
3296 | 1522 | return 0; | ||
3297 | 1523 | } | ||
3298 | 1524 | |||
3299 | 1525 | }; | ||
3300 | 1526 | |||
3301 | 1527 | int | ||
3302 | 1528 | main(int argc, char **argv) | ||
3303 | 1529 | { | ||
3304 | 1530 | return dena::hstest_main(argc, argv); | ||
3305 | 1531 | } | ||
3306 | 1532 | |||
3307 | 0 | 1533 | ||
3308 | === added file 'HandlerSocket-Plugin-for-MySQL/client/hstest.pl' | |||
3309 | --- HandlerSocket-Plugin-for-MySQL/client/hstest.pl 1970-01-01 00:00:00 +0000 | |||
3310 | +++ HandlerSocket-Plugin-for-MySQL/client/hstest.pl 2011-06-08 01:58:05 +0000 | |||
3311 | @@ -0,0 +1,228 @@ | |||
3312 | 1 | #!/usr/bin/perl | ||
3313 | 2 | |||
3314 | 3 | # vim:sw=8:ai:ts=8 | ||
3315 | 4 | |||
3316 | 5 | use strict; | ||
3317 | 6 | use warnings; | ||
3318 | 7 | |||
3319 | 8 | use DBI; | ||
3320 | 9 | use Net::HandlerSocket; | ||
3321 | 10 | |||
3322 | 11 | my %conf = (); | ||
3323 | 12 | for my $i (@ARGV) { | ||
3324 | 13 | my ($k, $v) = split(/=/, $i); | ||
3325 | 14 | $conf{$k} = $v; | ||
3326 | 15 | } | ||
3327 | 16 | |||
3328 | 17 | my $verbose = get_conf("verbose", 0); | ||
3329 | 18 | my $actions_str = get_conf("actions", "hsread"); | ||
3330 | 19 | my $tablesize = get_conf("tablesize", 10000); | ||
3331 | 20 | my $db = get_conf("db", "hstest"); | ||
3332 | 21 | my $table = get_conf("table", "hstest_table1"); | ||
3333 | 22 | my $engine = get_conf("engine", "innodb"); | ||
3334 | 23 | my $host = get_conf("host", "localhost"); | ||
3335 | 24 | my $mysqlport = get_conf("mysqlport", 3306); | ||
3336 | 25 | my $mysqluser = get_conf("mysqluser", "root"); | ||
3337 | 26 | my $mysqlpass = get_conf("mysqlpass", ""); | ||
3338 | 27 | my $hsport = get_conf("hsport", 9999); | ||
3339 | 28 | my $loop = get_conf("loop", 10000); | ||
3340 | 29 | my $op = get_conf("op", "="); | ||
3341 | 30 | my $ssps = get_conf("ssps", 0); | ||
3342 | 31 | my $num_moreflds = get_conf("moreflds", 0); | ||
3343 | 32 | my $moreflds_prefix = get_conf("moreflds_prefix", "column0123456789_"); | ||
3344 | 33 | my $keytype = get_conf("keytype", "varchar(32)"); | ||
3345 | 34 | my $file = get_conf("file", undef); | ||
3346 | 35 | |||
3347 | 36 | my $dsn = "DBI:mysql:database=;host=$host;port=$mysqlport" | ||
3348 | 37 | . ";mysql_server_prepare=$ssps"; | ||
3349 | 38 | my $dbh = DBI->connect($dsn, $mysqluser, $mysqlpass, { RaiseError => 1 }); | ||
3350 | 39 | my $hsargs = { 'host' => $host, 'port' => $hsport }; | ||
3351 | 40 | my $cli = new Net::HandlerSocket($hsargs); | ||
3352 | 41 | |||
3353 | 42 | my @actions = split(/,/, $actions_str); | ||
3354 | 43 | for my $action (@actions) { | ||
3355 | 44 | if ($action eq "table") { | ||
3356 | 45 | print("TABLE $db.$table\n"); | ||
3357 | 46 | $dbh->do("drop database if exists $db"); | ||
3358 | 47 | $dbh->do("create database $db"); | ||
3359 | 48 | $dbh->do("use $db"); | ||
3360 | 49 | my $moreflds = get_createtbl_moreflds_str(); | ||
3361 | 50 | $dbh->do( | ||
3362 | 51 | "create table $table (" . | ||
3363 | 52 | "k $keytype primary key" . | ||
3364 | 53 | ",v varchar(32) not null" . | ||
3365 | 54 | $moreflds . | ||
3366 | 55 | ") character set utf8 collate utf8_bin " . | ||
3367 | 56 | "engine = $engine"); | ||
3368 | 57 | } elsif ($action eq "insert") { | ||
3369 | 58 | print("INSERT $db.$table tablesize=$tablesize\n"); | ||
3370 | 59 | $dbh->do("use $db"); | ||
3371 | 60 | my $moreflds = get_insert_moreflds_str(); | ||
3372 | 61 | for (my $i = 0; $i < $tablesize; $i += 100) { | ||
3373 | 62 | my $qstr = "insert into $db.$table values"; | ||
3374 | 63 | for (my $j = 0; $j < 100; ++$j) { | ||
3375 | 64 | if ($j != 0) { | ||
3376 | 65 | $qstr .= ","; | ||
3377 | 66 | } | ||
3378 | 67 | my $k = "" . ($i + $j); | ||
3379 | 68 | my $v = "v" . int(rand(1000)) . ($i + $j); | ||
3380 | 69 | $qstr .= "('$k', '$v'"; | ||
3381 | 70 | for (my $j = 0; $j < $num_moreflds; ++$j) { | ||
3382 | 71 | $qstr .= ",'$j'"; | ||
3383 | 72 | } | ||
3384 | 73 | $qstr .= ")"; | ||
3385 | 74 | } | ||
3386 | 75 | $dbh->do($qstr); | ||
3387 | 76 | print "$i/$tablesize\n" if $i % 1000 == 0; | ||
3388 | 77 | } | ||
3389 | 78 | } elsif ($action eq "read") { | ||
3390 | 79 | print("READ $db.$table op=$op loop=$loop\n"); | ||
3391 | 80 | $dbh->do("use $db"); | ||
3392 | 81 | my $moreflds = get_select_moreflds_str(); | ||
3393 | 82 | my $sth = $dbh->prepare( | ||
3394 | 83 | "select k,v$moreflds from $db.$table where k = ?"); | ||
3395 | 84 | for (my $i = 0; $i < $loop; ++$i) { | ||
3396 | 85 | my $k = "" . int(rand($tablesize)); | ||
3397 | 86 | # print "k=$k\n"; | ||
3398 | 87 | $sth->execute($k); | ||
3399 | 88 | if ($verbose >= 10) { | ||
3400 | 89 | print "RET:"; | ||
3401 | 90 | while (my $ref = $sth->fetchrow_arrayref()) { | ||
3402 | 91 | my $rk = $ref->[0]; | ||
3403 | 92 | my $rv = $ref->[1]; | ||
3404 | 93 | print " $rk $rv"; | ||
3405 | 94 | } | ||
3406 | 95 | print "\n"; | ||
3407 | 96 | } | ||
3408 | 97 | print "$i/$loop\n" if $i % 1000 == 0; | ||
3409 | 98 | } | ||
3410 | 99 | } elsif ($action eq "hsinsert") { | ||
3411 | 100 | print("HSINSERT $db.$table tablesize=$tablesize\n"); | ||
3412 | 101 | $cli->open_index(1, $db, $table, '', 'k,v'); | ||
3413 | 102 | for (my $i = 0; $i < $tablesize; ++$i) { | ||
3414 | 103 | my $k = "" . $i; | ||
3415 | 104 | my $v = "v" . int(rand(1000)) . $i; | ||
3416 | 105 | my $r = $cli->execute_insert(1, [ $k, $v ]); | ||
3417 | 106 | if ($r->[0] != 0) { | ||
3418 | 107 | die; | ||
3419 | 108 | } | ||
3420 | 109 | print "$i/$tablesize\n" if $i % 1000 == 0; | ||
3421 | 110 | } | ||
3422 | 111 | } elsif ($action eq "hsread") { | ||
3423 | 112 | print("HSREAD $db.$table op=$op loop=$loop\n"); | ||
3424 | 113 | my $moreflds = get_select_moreflds_str(); | ||
3425 | 114 | $cli->open_index(1, $db, $table, '', "k,v$moreflds"); | ||
3426 | 115 | for (my $i = 0; $i < $loop; ++$i) { | ||
3427 | 116 | my $k = "" . int(rand($tablesize)); | ||
3428 | 117 | # print "k=$k\n"; | ||
3429 | 118 | my $r = $cli->execute_find(1, $op, [ $k ], 1, 0); | ||
3430 | 119 | if ($verbose >= 10) { | ||
3431 | 120 | my $len = scalar(@{$r}); | ||
3432 | 121 | print "LEN=$len"; | ||
3433 | 122 | for my $e (@{$r}) { | ||
3434 | 123 | print " [$e]"; | ||
3435 | 124 | } | ||
3436 | 125 | print "\n"; | ||
3437 | 126 | } | ||
3438 | 127 | print "$i/$loop\n" if $i % 1000 == 0; | ||
3439 | 128 | } | ||
3440 | 129 | } elsif ($action eq "hsupdate") { | ||
3441 | 130 | my $vbase = "v" . int(rand(1000)); | ||
3442 | 131 | print("HSUPDATE $db.$table op=$op loop=$loop vbase=$vbase\n"); | ||
3443 | 132 | $cli->open_index(1, $db, $table, '', 'v'); | ||
3444 | 133 | for (my $i = 0; $i < $loop; ++$i) { | ||
3445 | 134 | my $k = "" . int(rand($tablesize)); | ||
3446 | 135 | my $v = $vbase . $i; | ||
3447 | 136 | print "k=$k v=$v\n"; | ||
3448 | 137 | my $r = $cli->execute_update(1, $op, [ $k ], 1, 0, | ||
3449 | 138 | [ $v ]); | ||
3450 | 139 | if ($verbose >= 10) { | ||
3451 | 140 | print "UP k=$k v=$v\n"; | ||
3452 | 141 | } | ||
3453 | 142 | print "$i/$loop\n" if $i % 1000 == 0; | ||
3454 | 143 | } | ||
3455 | 144 | } elsif ($action eq "hsdelete") { | ||
3456 | 145 | print("HSDELETE $db.$table op=$op loop=$loop\n"); | ||
3457 | 146 | $cli->open_index(1, $db, $table, '', ''); | ||
3458 | 147 | for (my $i = 0; $i < $loop; ++$i) { | ||
3459 | 148 | my $k = "" . int(rand($tablesize)); | ||
3460 | 149 | print "k=$k\n"; | ||
3461 | 150 | my $r = $cli->execute_delete(1, $op, [ $k ], 1, 0); | ||
3462 | 151 | if ($verbose >= 10) { | ||
3463 | 152 | print "DEL k=$k\n"; | ||
3464 | 153 | } | ||
3465 | 154 | print "$i/$loop\n" if $i % 1000 == 0; | ||
3466 | 155 | } | ||
3467 | 156 | } elsif ($action eq "verify") { | ||
3468 | 157 | verify_do(); | ||
3469 | 158 | } | ||
3470 | 159 | } | ||
3471 | 160 | |||
3472 | 161 | sub verify_do { | ||
3473 | 162 | my ($fail_cnt, $ok_cnt) = (0, 0); | ||
3474 | 163 | my $sth = $dbh->prepare("select v from $db.$table where k = ?"); | ||
3475 | 164 | use FileHandle; | ||
3476 | 165 | my $fh = new FileHandle($file, "r"); | ||
3477 | 166 | while (my $line = <$fh>) { | ||
3478 | 167 | chomp($line); | ||
3479 | 168 | my @vec = split(/\t/, $line); | ||
3480 | 169 | my $k = $vec[3]; | ||
3481 | 170 | my $v = $vec[7]; | ||
3482 | 171 | next if (!defined($k) || !defined($v)); | ||
3483 | 172 | # print "$k $v\n"; | ||
3484 | 173 | $sth->execute($k); | ||
3485 | 174 | my $aref = $sth->fetchrow_arrayref(); | ||
3486 | 175 | if (!defined($aref)) { | ||
3487 | 176 | print "FAILED: $k notfound\n"; | ||
3488 | 177 | ++$fail_cnt; | ||
3489 | 178 | } else { | ||
3490 | 179 | my $gv = $aref->[0]; | ||
3491 | 180 | if ($gv ne $v) { | ||
3492 | 181 | print "FAILED: $k got=$gv expected=$v\n"; | ||
3493 | 182 | ++$fail_cnt; | ||
3494 | 183 | } else { | ||
3495 | 184 | print "OK: $k $v $gv\n" if $verbose >= 10; | ||
3496 | 185 | ++$ok_cnt; | ||
3497 | 186 | } | ||
3498 | 187 | } | ||
3499 | 188 | } | ||
3500 | 189 | print "OK=$ok_cnt FAIL=$fail_cnt\n"; | ||
3501 | 190 | } | ||
3502 | 191 | |||
3503 | 192 | sub get_conf { | ||
3504 | 193 | my ($key, $def) = @_; | ||
3505 | 194 | my $val = $conf{$key}; | ||
3506 | 195 | if ($val) { | ||
3507 | 196 | print "$key=$val\n"; | ||
3508 | 197 | } else { | ||
3509 | 198 | $val = $def; | ||
3510 | 199 | $def ||= ''; | ||
3511 | 200 | print "$key=$def(default)\n"; | ||
3512 | 201 | } | ||
3513 | 202 | return $val; | ||
3514 | 203 | } | ||
3515 | 204 | |||
3516 | 205 | sub get_createtbl_moreflds_str { | ||
3517 | 206 | my $s = ""; | ||
3518 | 207 | for (my $j = 0; $j < $num_moreflds; ++$j) { | ||
3519 | 208 | $s .= ",$moreflds_prefix$j varchar(30)"; | ||
3520 | 209 | } | ||
3521 | 210 | return $s; | ||
3522 | 211 | } | ||
3523 | 212 | |||
3524 | 213 | sub get_select_moreflds_str { | ||
3525 | 214 | my $s = ""; | ||
3526 | 215 | for (my $i = 0; $i < $num_moreflds; ++$i) { | ||
3527 | 216 | $s .= ",$moreflds_prefix$i"; | ||
3528 | 217 | } | ||
3529 | 218 | return $s; | ||
3530 | 219 | } | ||
3531 | 220 | |||
3532 | 221 | sub get_insert_moreflds_str { | ||
3533 | 222 | my $s = ""; | ||
3534 | 223 | for (my $i = 0; $i < $num_moreflds; ++$i) { | ||
3535 | 224 | $s .= ",?"; | ||
3536 | 225 | } | ||
3537 | 226 | return $s; | ||
3538 | 227 | } | ||
3539 | 228 | |||
3540 | 0 | 229 | ||
3541 | === added file 'HandlerSocket-Plugin-for-MySQL/client/hstest_hs.sh' | |||
3542 | --- HandlerSocket-Plugin-for-MySQL/client/hstest_hs.sh 1970-01-01 00:00:00 +0000 | |||
3543 | +++ HandlerSocket-Plugin-for-MySQL/client/hstest_hs.sh 2011-06-08 01:58:05 +0000 | |||
3544 | @@ -0,0 +1,4 @@ | |||
3545 | 1 | #!/bin/bash | ||
3546 | 2 | |||
3547 | 3 | exec ./hstest test=10 tablesize=10000 host=localhost hsport=9998 num=10000000 \ | ||
3548 | 4 | num_threads=100 timelimit=10 $@ | ||
3549 | 0 | 5 | ||
3550 | === added file 'HandlerSocket-Plugin-for-MySQL/client/hstest_hs_more50.sh' | |||
3551 | --- HandlerSocket-Plugin-for-MySQL/client/hstest_hs_more50.sh 1970-01-01 00:00:00 +0000 | |||
3552 | +++ HandlerSocket-Plugin-for-MySQL/client/hstest_hs_more50.sh 2011-06-08 01:58:05 +0000 | |||
3553 | @@ -0,0 +1,4 @@ | |||
3554 | 1 | #!/bin/bash | ||
3555 | 2 | |||
3556 | 3 | exec ./hstest test=10 key_mask=9999 host=localhost port=9998 num=10000000 \ | ||
3557 | 4 | num_threads=100 timelimit=10 moreflds=50 $@ | ||
3558 | 0 | 5 | ||
3559 | === added file 'HandlerSocket-Plugin-for-MySQL/client/hstest_md.sh' | |||
3560 | --- HandlerSocket-Plugin-for-MySQL/client/hstest_md.sh 1970-01-01 00:00:00 +0000 | |||
3561 | +++ HandlerSocket-Plugin-for-MySQL/client/hstest_md.sh 2011-06-08 01:58:05 +0000 | |||
3562 | @@ -0,0 +1,7 @@ | |||
3563 | 1 | #!/bin/bash | ||
3564 | 2 | |||
3565 | 3 | ./hstest test=7 key_mask=9999 host=localhost port=11211 num=10000 \ | ||
3566 | 4 | num_threads=10 timelimit=10 op=R $@ | ||
3567 | 5 | ./hstest test=7 key_mask=9999 host=localhost port=11211 num=1000000 \ | ||
3568 | 6 | num_threads=100 timelimit=10 op=G $@ | ||
3569 | 7 | |||
3570 | 0 | 8 | ||
3571 | === added file 'HandlerSocket-Plugin-for-MySQL/client/hstest_my.sh' | |||
3572 | --- HandlerSocket-Plugin-for-MySQL/client/hstest_my.sh 1970-01-01 00:00:00 +0000 | |||
3573 | +++ HandlerSocket-Plugin-for-MySQL/client/hstest_my.sh 2011-06-08 01:58:05 +0000 | |||
3574 | @@ -0,0 +1,3 @@ | |||
3575 | 1 | #!/bin/bash | ||
3576 | 2 | exec ./hstest test=9 tablesize=9999 host=localhost mysqlport=3306 num=1000000 \ | ||
3577 | 3 | num_threads=100 verbose=1 timelimit=10 $@ | ||
3578 | 0 | 4 | ||
3579 | === added file 'HandlerSocket-Plugin-for-MySQL/client/hstest_my_more50.sh' | |||
3580 | --- HandlerSocket-Plugin-for-MySQL/client/hstest_my_more50.sh 1970-01-01 00:00:00 +0000 | |||
3581 | +++ HandlerSocket-Plugin-for-MySQL/client/hstest_my_more50.sh 2011-06-08 01:58:05 +0000 | |||
3582 | @@ -0,0 +1,3 @@ | |||
3583 | 1 | #!/bin/bash | ||
3584 | 2 | exec ./hstest test=9 key_mask=9999 host=localhost port=3306 num=1000000 \ | ||
3585 | 3 | num_threads=100 verbose=1 timelimit=10 moreflds=50 $@ | ||
3586 | 0 | 4 | ||
3587 | === added file 'HandlerSocket-Plugin-for-MySQL/configure.ac' | |||
3588 | --- HandlerSocket-Plugin-for-MySQL/configure.ac 1970-01-01 00:00:00 +0000 | |||
3589 | +++ HandlerSocket-Plugin-for-MySQL/configure.ac 2011-06-08 01:58:05 +0000 | |||
3590 | @@ -0,0 +1,144 @@ | |||
3591 | 1 | # -*- Autoconf -*- | ||
3592 | 2 | # Process this file with autoconf to produce a configure script. | ||
3593 | 3 | |||
3594 | 4 | #AC_PREREQ([2.63b]) | ||
3595 | 5 | AC_INIT([handlersocket-plugin], [1.0.6], [https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL/issues]) | ||
3596 | 6 | AC_CONFIG_HEADERS([config.h]) | ||
3597 | 7 | AM_INIT_AUTOMAKE([-Wall -Werror foreign]) | ||
3598 | 8 | AC_CONFIG_SRCDIR([libhsclient/fatal.cpp]) | ||
3599 | 9 | AC_CONFIG_MACRO_DIR([m4]) | ||
3600 | 10 | |||
3601 | 11 | AC_PROG_CC | ||
3602 | 12 | AC_PROG_CXX | ||
3603 | 13 | AC_PROG_CPP | ||
3604 | 14 | AC_PROG_LIBTOOL | ||
3605 | 15 | |||
3606 | 16 | ac_mysql_debug= | ||
3607 | 17 | AC_ARG_ENABLE(mysql-debug, | ||
3608 | 18 | [AS_HELP_STRING([--enable-mysql-debug], [specify whether MySQL is build with DBUG_ON])],[ac_mysql_debug="$enableval"],[ac_mysql_debug=no]) | ||
3609 | 19 | AC_MSG_CHECKING([if --enable-mysql-debug is specified]) | ||
3610 | 20 | AC_MSG_RESULT($ac_mysql_debug) | ||
3611 | 21 | |||
3612 | 22 | AC_DEFUN([CONFIG_OPTION_MYSQL],[ | ||
3613 | 23 | AC_MSG_CHECKING([mysql source]) | ||
3614 | 24 | |||
3615 | 25 | MYSQL_SOURCE_VERSION= | ||
3616 | 26 | MYSQL_INC= | ||
3617 | 27 | ac_mysql_source_dir= | ||
3618 | 28 | AC_ARG_WITH([mysql-source], | ||
3619 | 29 | [AS_HELP_STRING([--with-mysql-source=PATH], [MySQL source directory PATH])], | ||
3620 | 30 | [ | ||
3621 | 31 | ac_mysql_source_dir=`cd $withval && pwd` | ||
3622 | 32 | if test -f "$ac_mysql_source_dir/sql/handler.h" ; then | ||
3623 | 33 | MYSQL_INC="-I$ac_mysql_source_dir/sql" | ||
3624 | 34 | MYSQL_INC="$MYSQL_INC -I$ac_mysql_source_dir/include" | ||
3625 | 35 | MYSQL_INC="$MYSQL_INC -I$ac_mysql_source_dir/regex" | ||
3626 | 36 | MYSQL_INC="$MYSQL_INC -I$ac_mysql_source_dir" | ||
3627 | 37 | AC_SUBST(MYSQL_INC) | ||
3628 | 38 | if test -f "$ac_mysql_source_dir/VERSION"; then | ||
3629 | 39 | source "$ac_mysql_source_dir/VERSION" | ||
3630 | 40 | MYSQL_SOURCE_VERSION="$MYSQL_VERSION_MAJOR.$MYSQL_VERSION_MINOR.$MYSQL_VERSION_PATCH" | ||
3631 | 41 | else | ||
3632 | 42 | if test -f "$ac_mysql_source_dir/configure.in"; then | ||
3633 | 43 | MYSQL_SOURCE_VERSION=`cat $ac_mysql_source_dir/configure.in | grep "\[[MySQL Server\]]" | sed -e "s|.*\([[0-9]]\+\.[[0-9]]\+\.[[0-9]]\+[[0-9a-zA-Z\_\-]]*\).*|\1|"` | ||
3634 | 44 | else | ||
3635 | 45 | AC_MSG_ERROR([invalid MySQL source directory: $ac_mysql_source_dir]) | ||
3636 | 46 | fi | ||
3637 | 47 | fi | ||
3638 | 48 | AC_MSG_RESULT([yes: Using $ac_mysql_source_dir, version $MYSQL_SOURCE_VERSION]) | ||
3639 | 49 | else | ||
3640 | 50 | AC_MSG_ERROR([invalid MySQL source directory: $ac_mysql_source_dir]) | ||
3641 | 51 | fi | ||
3642 | 52 | ], | ||
3643 | 53 | [AC_MSG_ERROR([--with-mysql-source=PATH is required for standalone build])] | ||
3644 | 54 | ) | ||
3645 | 55 | |||
3646 | 56 | MYSQL_BIN_VERSION= | ||
3647 | 57 | ac_mysql_config= | ||
3648 | 58 | AC_ARG_WITH([mysql-bindir], | ||
3649 | 59 | [AS_HELP_STRING([--with-mysql-bindir=PATH], [MySQL binary directory PATH. This should be the directory where mysql_config is located.])], | ||
3650 | 60 | [ | ||
3651 | 61 | mysql_bin_dir=`cd $withval 2> /dev/null && pwd || echo ""` | ||
3652 | 62 | ac_mysql_config="$mysql_bin_dir/mysql_config" | ||
3653 | 63 | ], | ||
3654 | 64 | [ | ||
3655 | 65 | AC_PATH_PROG([ac_mysql_config], [mysql_config]) | ||
3656 | 66 | ] | ||
3657 | 67 | ) | ||
3658 | 68 | |||
3659 | 69 | AC_MSG_CHECKING([mysql binary]) | ||
3660 | 70 | if test ! -x "$ac_mysql_config" ; then | ||
3661 | 71 | AC_MSG_ERROR([mysql_config not found! You have to specify the directory where mysql_config resides to --with-mysql-bindir=PATH.]) | ||
3662 | 72 | fi | ||
3663 | 73 | |||
3664 | 74 | MYSQL_CFLAGS_ADD=`"$ac_mysql_config" --cflags` | ||
3665 | 75 | MYSQL_CFLAGS="$MYSQL_CFLAGS $MYSQL_CFLAGS_ADD" | ||
3666 | 76 | if test "$ac_mysql_debug" = "yes"; then | ||
3667 | 77 | MYSQL_CFLAGS="$MYSQL_CFLAGS -DDBUG_ON -DENABLED_DEBUG_SYNC" | ||
3668 | 78 | else | ||
3669 | 79 | MYSQL_CFLAGS="$MYSQL_CFLAGS -DDBUG_OFF" | ||
3670 | 80 | fi | ||
3671 | 81 | AC_SUBST(MYSQL_CFLAGS) | ||
3672 | 82 | |||
3673 | 83 | MYSQL_BIN_VERSION=`"$ac_mysql_config" --version` | ||
3674 | 84 | AC_MSG_RESULT([yes: Using $ac_mysql_config, version $MYSQL_BIN_VERSION]) | ||
3675 | 85 | |||
3676 | 86 | MYSQL_LIB=`"$ac_mysql_config" --libs_r` | ||
3677 | 87 | LIB_DIR=`echo $MYSQL_LIB | sed -e "s|.*-L/|/|" | sed -e "s| .*||"` | ||
3678 | 88 | # FIXME | ||
3679 | 89 | if test a`basename "$LIB_DIR"` = amysql ; then | ||
3680 | 90 | MYSQL_LIB="-L`dirname $LIB_DIR` $MYSQL_LIB" | ||
3681 | 91 | # FIXME | ||
3682 | 92 | fi | ||
3683 | 93 | AC_SUBST(MYSQL_LIB) | ||
3684 | 94 | |||
3685 | 95 | if test a$MYSQL_SOURCE_VERSION != a$MYSQL_BIN_VERSION ; then | ||
3686 | 96 | AC_MSG_ERROR([MySQL source version does not match MySQL binary version]) | ||
3687 | 97 | fi | ||
3688 | 98 | |||
3689 | 99 | AC_MSG_CHECKING([mysql plugin dir]) | ||
3690 | 100 | ac_mysql_plugin_dir= | ||
3691 | 101 | AC_ARG_WITH([mysql-plugindir], | ||
3692 | 102 | [AS_HELP_STRING([--with-mysql-plugindir=PATH], [MySQL plugin directory where handlersocket.so to be copied])], | ||
3693 | 103 | [ | ||
3694 | 104 | ac_mysql_plugin_dir=`cd $withval && pwd` | ||
3695 | 105 | if test -d "$ac_mysql_plugin_dir/" ; then | ||
3696 | 106 | PLUGIN_DIR="$ac_mysql_plugin_dir" | ||
3697 | 107 | AC_SUBST(PLUGIN_DIR) | ||
3698 | 108 | AC_MSG_RESULT([yes: Using $ac_mysql_plugin_dir]) | ||
3699 | 109 | else | ||
3700 | 110 | AC_MSG_ERROR([invalid MySQL plugin directory : $ac_mysql_plugin_dir]) | ||
3701 | 111 | fi | ||
3702 | 112 | ], | ||
3703 | 113 | [ | ||
3704 | 114 | LIB_DIR_TMP=`"$ac_mysql_config" --plugindir` | ||
3705 | 115 | if test ! -d "$LIB_DIR_TMP"; then | ||
3706 | 116 | LIB_DIR_TMP=`"$ac_mysql_config" --libs_r | sed -e "s|.*-L/|/|" | sed -e "s| .*||"`/plugin | ||
3707 | 117 | # FIXME | ||
3708 | 118 | fi | ||
3709 | 119 | ac_mysql_plugin_dir=$LIB_DIR_TMP | ||
3710 | 120 | PLUGIN_DIR="$ac_mysql_plugin_dir" | ||
3711 | 121 | AC_SUBST(PLUGIN_DIR) | ||
3712 | 122 | AC_MSG_RESULT([--with-mysql-plugindir was not set. Using $ac_mysql_plugin_dir]) | ||
3713 | 123 | ] | ||
3714 | 124 | ) | ||
3715 | 125 | ]) | ||
3716 | 126 | |||
3717 | 127 | HANDLERSOCKET_SUBDIRS="libhsclient" | ||
3718 | 128 | AC_ARG_ENABLE(handlersocket_server, | ||
3719 | 129 | [ --enable-handlersocket-server build HandlerSocket plugin (defalut=yes)]) | ||
3720 | 130 | if test "$enable_handlersocket_server" != "no"; then | ||
3721 | 131 | CONFIG_OPTION_MYSQL | ||
3722 | 132 | HANDLERSOCKET_SUBDIRS="libhsclient handlersocket client" | ||
3723 | 133 | fi | ||
3724 | 134 | AC_SUBST(HANDLERSOCKET_SUBDIRS) | ||
3725 | 135 | |||
3726 | 136 | CFLAGS="$CFLAGS -Werror" | ||
3727 | 137 | CXXFLAGS="$CXXFLAGS -Wall -g -fno-rtti -fno-exceptions -fPIC -DPIC" | ||
3728 | 138 | |||
3729 | 139 | AC_CONFIG_FILES([Makefile | ||
3730 | 140 | handlersocket/Makefile | ||
3731 | 141 | libhsclient/Makefile | ||
3732 | 142 | client/Makefile]) | ||
3733 | 143 | |||
3734 | 144 | AC_OUTPUT | ||
3735 | 0 | 145 | ||
3736 | === added directory 'HandlerSocket-Plugin-for-MySQL/docs-en' | |||
3737 | === added file 'HandlerSocket-Plugin-for-MySQL/docs-en/about-handlersocket.en.txt' | |||
3738 | --- HandlerSocket-Plugin-for-MySQL/docs-en/about-handlersocket.en.txt 1970-01-01 00:00:00 +0000 | |||
3739 | +++ HandlerSocket-Plugin-for-MySQL/docs-en/about-handlersocket.en.txt 2011-06-08 01:58:05 +0000 | |||
3740 | @@ -0,0 +1,72 @@ | |||
3741 | 1 | |||
3742 | 2 | ----------------------------------------------------------------------------- | ||
3743 | 3 | HandlerSocket plugin for MySQL | ||
3744 | 4 | |||
3745 | 5 | Copyright (c) 2010 DeNA Co.,Ltd. | ||
3746 | 6 | All rights reserved. | ||
3747 | 7 | |||
3748 | 8 | Redistribution and use in source and binary forms, with or without | ||
3749 | 9 | modification, are permitted provided that the following conditions are met: | ||
3750 | 10 | |||
3751 | 11 | * Redistributions of source code must retain the above copyright | ||
3752 | 12 | notice, this list of conditions and the following disclaimer. | ||
3753 | 13 | * Redistributions in binary form must reproduce the above copyright | ||
3754 | 14 | notice, this list of conditions and the following disclaimer in the | ||
3755 | 15 | documentation and/or other materials provided with the distribution. | ||
3756 | 16 | * Neither the name of DeNA Co.,Ltd. nor the names of its contributors | ||
3757 | 17 | may be used to endorse or promote products derived from this software | ||
3758 | 18 | without specific prior written permission. | ||
3759 | 19 | |||
3760 | 20 | THIS SOFTWARE IS PROVIDED BY DeNA Co.,Ltd. "AS IS" AND ANY EXPRESS OR | ||
3761 | 21 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
3762 | 22 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | ||
3763 | 23 | EVENT SHALL DeNA Co.,Ltd. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
3764 | 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
3765 | 25 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
3766 | 26 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
3767 | 27 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
3768 | 28 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
3769 | 29 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
3770 | 30 | |||
3771 | 31 | |||
3772 | 32 | ----------------------------------------------------------------------------- | ||
3773 | 33 | About HandlerSocket | ||
3774 | 34 | |||
3775 | 35 | HandlerSocket is a NoSQL plugin for MySQL. It works as a daemon inside the | ||
3776 | 36 | mysqld process, accept tcp connections, and execute requests from clients. | ||
3777 | 37 | HandlerSocket does not support SQL queries. Instead, it supports simple CRUD | ||
3778 | 38 | operations on tables. | ||
3779 | 39 | |||
3780 | 40 | Because of the following reasons, HandlerSocket is much faster than the | ||
3781 | 41 | mysqld/libmysql pair in some circumstances: | ||
3782 | 42 | |||
3783 | 43 | - HandlerSocket manipulates data without parsing SQL, which causes less | ||
3784 | 44 | CPU usage. | ||
3785 | 45 | - HandlerSocket reads many requests from clients and executes their | ||
3786 | 46 | requests in bulk, which causes less CPU and disk usage. | ||
3787 | 47 | - HandlerSocket client/server protocol is more compact than the | ||
3788 | 48 | mysql/libmysql pair, which causes less network usage. | ||
3789 | 49 | |||
3790 | 50 | The current version of HandlerSocket only works with GNU/Linux. The source | ||
3791 | 51 | archive of HandlerSocket includes a C++ and a Perl client libraries. | ||
3792 | 52 | Here is a list of other language bindings: | ||
3793 | 53 | |||
3794 | 54 | - PHP | ||
3795 | 55 | http://openpear.org/package/Net_HandlerSocket | ||
3796 | 56 | http://github.com/tz-lom/HSPHP | ||
3797 | 57 | http://code.google.com/p/php-handlersocket/ | ||
3798 | 58 | - Java | ||
3799 | 59 | http://code.google.com/p/handlersocketforjava/ | ||
3800 | 60 | - Python | ||
3801 | 61 | https://code.launchpad.net/~songofacandy/+junk/pyhandlersocket | ||
3802 | 62 | - Ruby | ||
3803 | 63 | https://github.com/winebarrel/ruby-handlersocket | ||
3804 | 64 | https://github.com/miyucy/handlersocket | ||
3805 | 65 | - JavaScript(Node.js) | ||
3806 | 66 | https://github.com/koichik/node-handlersocket | ||
3807 | 67 | |||
3808 | 68 | The home of HandlerSocket is here: | ||
3809 | 69 | https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL | ||
3810 | 70 | |||
3811 | 71 | More documents are available in docs-en/ and docs-ja/ directories. | ||
3812 | 72 | |||
3813 | 0 | 73 | ||
3814 | === added file 'HandlerSocket-Plugin-for-MySQL/docs-en/configuration-options.en.txt' | |||
3815 | --- HandlerSocket-Plugin-for-MySQL/docs-en/configuration-options.en.txt 1970-01-01 00:00:00 +0000 | |||
3816 | +++ HandlerSocket-Plugin-for-MySQL/docs-en/configuration-options.en.txt 2011-06-08 01:58:05 +0000 | |||
3817 | @@ -0,0 +1,87 @@ | |||
3818 | 1 | |||
3819 | 2 | ----------------------------------------------------------------- | ||
3820 | 3 | handlersocket_verbose (default = 10, min = 0, max = 10000) | ||
3821 | 4 | |||
3822 | 5 | Specify the logging verboseness. | ||
3823 | 6 | |||
3824 | 7 | ----------------------------------------------------------------- | ||
3825 | 8 | handlersocket_address (default = '') | ||
3826 | 9 | |||
3827 | 10 | Specify the address to bind. If empty, it binds to 0.0.0.0. | ||
3828 | 11 | |||
3829 | 12 | ----------------------------------------------------------------- | ||
3830 | 13 | handlersocket_port (default = '9998') | ||
3831 | 14 | |||
3832 | 15 | Specify the port to bind. This option is for the listener for | ||
3833 | 16 | read requests. If empty, the listener is disabled. | ||
3834 | 17 | |||
3835 | 18 | ----------------------------------------------------------------- | ||
3836 | 19 | handlersocket_port_wr (default = '9999') | ||
3837 | 20 | |||
3838 | 21 | Specify the port to bind. This option is for the listener for | ||
3839 | 22 | write requests. If empty, the listener is disabled. | ||
3840 | 23 | |||
3841 | 24 | ----------------------------------------------------------------- | ||
3842 | 25 | handlersocket_epoll (default = 1, min = 0, max = 1) | ||
3843 | 26 | |||
3844 | 27 | Specify whether handlersocket uses epoll for I/O multiplexing. | ||
3845 | 28 | |||
3846 | 29 | ----------------------------------------------------------------- | ||
3847 | 30 | handlersocket_threads (default = 16, min = 1, max = 3000) | ||
3848 | 31 | |||
3849 | 32 | Specify the number of handlersocket worker threads. This option | ||
3850 | 33 | is for the listener for read requests. Recommended value is | ||
3851 | 34 | (the number of CPU cores * 2). | ||
3852 | 35 | |||
3853 | 36 | ----------------------------------------------------------------- | ||
3854 | 37 | handlersocket_threads_wr (default = 1, min = 1, max = 3000) | ||
3855 | 38 | |||
3856 | 39 | Specify the number of handlersocket worker threads. This option | ||
3857 | 40 | is for the listener for write requests. Recommended value is 1. | ||
3858 | 41 | |||
3859 | 42 | ----------------------------------------------------------------- | ||
3860 | 43 | handlersocket_timeout (default = 300, min = 30, max = 3600) | ||
3861 | 44 | |||
3862 | 45 | Specify the socket timeout in seconds. | ||
3863 | 46 | |||
3864 | 47 | ----------------------------------------------------------------- | ||
3865 | 48 | handlersocket_backlog (default = 32768, min = 5, max = 1000000) | ||
3866 | 49 | |||
3867 | 50 | Specify the length of the listen backlog. | ||
3868 | 51 | |||
3869 | 52 | ----------------------------------------------------------------- | ||
3870 | 53 | handlersocket_sndbuf (default = 0, min = 0, max = 1677216) | ||
3871 | 54 | |||
3872 | 55 | Specify the maximum socket send buffer in bytes. If 0, the | ||
3873 | 56 | system-wide default value is set. | ||
3874 | 57 | |||
3875 | 58 | ----------------------------------------------------------------- | ||
3876 | 59 | handlersocket_rcvbuf (default = 0, min = 0, max = 1677216) | ||
3877 | 60 | |||
3878 | 61 | Specify the maximum socket receive buffer in bytes. If 0, the | ||
3879 | 62 | system-wide default value is set. | ||
3880 | 63 | |||
3881 | 64 | ----------------------------------------------------------------- | ||
3882 | 65 | handlersocket_readsize (default = 0, min = 0, max = 1677216) | ||
3883 | 66 | |||
3884 | 67 | Specify the minimum length of the handlersocket request buffer. | ||
3885 | 68 | Larger value can make handlersocket faster for large requests, | ||
3886 | 69 | but can consume memory. The default value is possibly 4096. | ||
3887 | 70 | |||
3888 | 71 | ----------------------------------------------------------------- | ||
3889 | 72 | handlersocket_accept_balance (default = 0, min = 0, max = 10000) | ||
3890 | 73 | |||
3891 | 74 | When this option is set to non-zero, handlersocket tries to | ||
3892 | 75 | balance accepted connections among threads. Non-zero is | ||
3893 | 76 | recommended if you use persistent connections (i.e., connection | ||
3894 | 77 | pooling on the client side). | ||
3895 | 78 | |||
3896 | 79 | ----------------------------------------------------------------- | ||
3897 | 80 | handlersocket_wrlock_timeout (default = 12, min = 0, max = 3600) | ||
3898 | 81 | |||
3899 | 82 | Specify the lock timeout in seconds. When a write request is | ||
3900 | 83 | performed, handlersocket locks an advisory lock named | ||
3901 | 84 | 'handlersocket_wr'. This option sets the timeout for the | ||
3902 | 85 | locking. | ||
3903 | 86 | |||
3904 | 87 | |||
3905 | 0 | 88 | ||
3906 | === added file 'HandlerSocket-Plugin-for-MySQL/docs-en/installation.en.txt' | |||
3907 | --- HandlerSocket-Plugin-for-MySQL/docs-en/installation.en.txt 1970-01-01 00:00:00 +0000 | |||
3908 | +++ HandlerSocket-Plugin-for-MySQL/docs-en/installation.en.txt 2011-06-08 01:58:05 +0000 | |||
3909 | @@ -0,0 +1,91 @@ | |||
3910 | 1 | 1. Building Handlersocket | ||
3911 | 2 | |||
3912 | 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. | ||
3913 | 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. | ||
3914 | 5 | Since Handlersocket uses daemon plugin interface supported from MySQL 5.1, | ||
3915 | 6 | MySQL 5.1 or higher version is required. | ||
3916 | 7 | Please make sure that you use identical MySQL version between MySQL source | ||
3917 | 8 | and MySQL binary. Otherwise you might encounter serious problems (i.e. server | ||
3918 | 9 | crash, etc). | ||
3919 | 10 | Here are steps to build Handlersocket. | ||
3920 | 11 | |||
3921 | 12 | * Get MySQL source code | ||
3922 | 13 | |||
3923 | 14 | * Get MySQL binary | ||
3924 | 15 | |||
3925 | 16 | * Build Handlersocket | ||
3926 | 17 | $ ./autogen.sh | ||
3927 | 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 | ||
3928 | 19 | |||
3929 | 20 | --with-mysql-source refers to the top of MySQL source directory, | ||
3930 | 21 | --with-mysql-bindir refers to where MySQL binary executables (i.e. | ||
3931 | 22 | mysql_config) are located, and --with-mysql-plugindir refers to a plugin | ||
3932 | 23 | directory where plugin libraries (*.so) are installed. | ||
3933 | 24 | |||
3934 | 25 | $ make | ||
3935 | 26 | $ sudo make install | ||
3936 | 27 | |||
3937 | 28 | Both libhsclient and the handlersocket plugin will be installed. | ||
3938 | 29 | |||
3939 | 30 | |||
3940 | 31 | 2. Using Handlersocket | ||
3941 | 32 | |||
3942 | 33 | Append configuration options for handlersocket to my.cnf. | ||
3943 | 34 | |||
3944 | 35 | [mysqld] | ||
3945 | 36 | loose_handlersocket_port = 9998 | ||
3946 | 37 | # the port number to bind to (for read requests) | ||
3947 | 38 | loose_handlersocket_port_wr = 9999 | ||
3948 | 39 | # the port number to bind to (for write requests) | ||
3949 | 40 | loose_handlersocket_threads = 16 | ||
3950 | 41 | # the number of worker threads (for read requests) | ||
3951 | 42 | loose_handlersocket_threads_wr = 1 | ||
3952 | 43 | # the number of worker threads (for write requests) | ||
3953 | 44 | open_files_limit = 65535 | ||
3954 | 45 | # to allow handlersocket accept many concurrent | ||
3955 | 46 | # connections, make open_files_limit as large as | ||
3956 | 47 | # possible. | ||
3957 | 48 | |||
3958 | 49 | Log in to mysql as root, and execute the following query. | ||
3959 | 50 | |||
3960 | 51 | mysql> install plugin handlersocket soname 'handlersocket.so'; | ||
3961 | 52 | |||
3962 | 53 | If handlersocket.so is successfully installed, it starts | ||
3963 | 54 | accepting connections on port 9998 and 9999. Running | ||
3964 | 55 | 'show processlist' should show handlersocket worker threads. | ||
3965 | 56 | |||
3966 | 57 | ----------------------------------------------------------------- | ||
3967 | 58 | On the client side, you need to install libhsclient for c++ apps | ||
3968 | 59 | and perl-Net-HandlerSocket for perl apps. They do not require | ||
3969 | 60 | MySQL to compile. | ||
3970 | 61 | |||
3971 | 62 | $ ./autogen.sh | ||
3972 | 63 | $ ./configure --disable-handlersocket-server | ||
3973 | 64 | $ make | ||
3974 | 65 | $ sudo make install | ||
3975 | 66 | $ cd perl-Net-HandlerSocket | ||
3976 | 67 | $ perl Makefile.PL | ||
3977 | 68 | $ make | ||
3978 | 69 | $ sudo make install | ||
3979 | 70 | |||
3980 | 71 | ----------------------------------------------------------------- | ||
3981 | 72 | Alternatively, you can use the rpm installation. If your OS | ||
3982 | 73 | supports rpms, you can use the following commands to build and | ||
3983 | 74 | install handlersocket rpm packages. | ||
3984 | 75 | |||
3985 | 76 | (Server side, installs HandlerSocket plugin) | ||
3986 | 77 | $ ./autogen.sh | ||
3987 | 78 | $ ./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 | ||
3988 | 79 | $ make rpm_cli | ||
3989 | 80 | $ sudo rpm -U dist/RPMS/*/libhsclient*.rpm | ||
3990 | 81 | $ make rpm_c | ||
3991 | 82 | $ sudo rpm -U dist/RPMS/*/handlersocket*.rpm | ||
3992 | 83 | |||
3993 | 84 | (Client side, installs client libraries) | ||
3994 | 85 | $ ./autogen.sh | ||
3995 | 86 | $ ./configure --disable-handlersocket-server | ||
3996 | 87 | $ make rpm_cli | ||
3997 | 88 | $ sudo rpm -U dist/RPMS/*/libhsclient*.rpm | ||
3998 | 89 | $ make rpm_perl | ||
3999 | 90 | $ sudo rpm -U dist/RPMS/*/perl-Net-HandlerSocket*.rpm | ||
4000 | 91 | |||
4001 | 0 | 92 | ||
4002 | === added file 'HandlerSocket-Plugin-for-MySQL/docs-en/perl-client.en.txt' | |||
4003 | --- HandlerSocket-Plugin-for-MySQL/docs-en/perl-client.en.txt 1970-01-01 00:00:00 +0000 | |||
4004 | +++ HandlerSocket-Plugin-for-MySQL/docs-en/perl-client.en.txt 2011-06-08 01:58:05 +0000 | |||
4005 | @@ -0,0 +1,126 @@ | |||
4006 | 1 | |||
4007 | 2 | ----------------------------------------------------------------- | ||
4008 | 3 | To open a connection to the handlersocket plugin, you need to | ||
4009 | 4 | create a Net::HandlerSocket object. | ||
4010 | 5 | |||
4011 | 6 | use Net::HandlerSocket; | ||
4012 | 7 | my $args = { host => 'localhost', port => 9998 }; | ||
4013 | 8 | my $hs = new Net::HandlerSocket($args); | ||
4014 | 9 | |||
4015 | 10 | ----------------------------------------------------------------- | ||
4016 | 11 | Before executing table operations, you need to open an index to | ||
4017 | 12 | work with. | ||
4018 | 13 | |||
4019 | 14 | my $err = $hs->open_index(3, 'database1', 'table1', 'PRIMARY', | ||
4020 | 15 | 'f1,f2'); | ||
4021 | 16 | die $hs->get_error() if $res->[0] != 0; | ||
4022 | 17 | |||
4023 | 18 | The first argument for open_index is an integer value which is | ||
4024 | 19 | used to identify an open table, which is only valid within the | ||
4025 | 20 | same Net::HandlerSocket object. The 4th argument is the name of | ||
4026 | 21 | index to open. If 'PRIMARY' is specified, the primary index is | ||
4027 | 22 | open. The 5th argument is a comma-separated list of column names. | ||
4028 | 23 | |||
4029 | 24 | ----------------------------------------------------------------- | ||
4030 | 25 | To read a record from a table using an index, call the | ||
4031 | 26 | execute_single method. | ||
4032 | 27 | |||
4033 | 28 | my $res = $hs->execute_single(3, '=', [ 'foo' ], 1, 0); | ||
4034 | 29 | die $hs->get_error() if $res->[0] != 0; | ||
4035 | 30 | shift(@$res); | ||
4036 | 31 | |||
4037 | 32 | The first argument must be an integer which has specified as the | ||
4038 | 33 | first argument for open_index on the same Net::HandlerSocket | ||
4039 | 34 | object. The second argument specifies the search operation. The | ||
4040 | 35 | current version of handlersocket supports '=', '>=', '<=', '>', | ||
4041 | 36 | and '<'. The 3rd argument specifies the key to find, which must | ||
4042 | 37 | an arrayref whose length is equal to or smaller than the number | ||
4043 | 38 | of key columns of the index. The 4th and the 5th arguments | ||
4044 | 39 | specify the maximum number of records to be retrieved, and the | ||
4045 | 40 | number of records skipped before retrieving records. The columns | ||
4046 | 41 | to be retrieved are specified by the 5th argument for the | ||
4047 | 42 | corresponding open_index call. | ||
4048 | 43 | |||
4049 | 44 | The execute_single method always returns an arrayref. The first | ||
4050 | 45 | element is the error code, which is 0 when no error is occured. | ||
4051 | 46 | The remaining are the field values. If more than one record is | ||
4052 | 47 | returned, it is flatten to an 1-dimensional array. For example, | ||
4053 | 48 | when 5 records that have 3 columns are returned, you can retrieve | ||
4054 | 49 | values using the following code. | ||
4055 | 50 | |||
4056 | 51 | die $hs->get_error() if $res->[0] != 0; | ||
4057 | 52 | shift(@$res); | ||
4058 | 53 | for (my $row = 0; $row < 5; ++$row) { | ||
4059 | 54 | for (my $col = 0; $col < 3; ++$col) { | ||
4060 | 55 | my $value = $res->[$row * 5 + $col]; | ||
4061 | 56 | # ... | ||
4062 | 57 | } | ||
4063 | 58 | } | ||
4064 | 59 | |||
4065 | 60 | ----------------------------------------------------------------- | ||
4066 | 61 | To update or delete records, you need to specify more arguments | ||
4067 | 62 | for the execute_single method. Note that the Net::HandlerSocket | ||
4068 | 63 | object must be connected to a handlersocket worker for write | ||
4069 | 64 | operations, which is port 9999 by default. | ||
4070 | 65 | (For safety, the port 9998 only allows read operations, and the | ||
4071 | 66 | port 9999 allows write operations also. The port 9999 allows | ||
4072 | 67 | read operations too, but slower than 9998 because of record | ||
4073 | 68 | locking etc.. Port numbers can be changed using the | ||
4074 | 69 | 'handlersocket_port' and the 'handlersocket_port_wr' | ||
4075 | 70 | configuration options of mysqld.) | ||
4076 | 71 | |||
4077 | 72 | my $args = { host => 'localhost', port => 9999 }; | ||
4078 | 73 | my $hs = new Net::HandlerSocket($args); | ||
4079 | 74 | |||
4080 | 75 | my $res = $hs->execute_single(3, '=', [ 'bar' ], 1, 0, 'U', | ||
4081 | 76 | [ 'fubar', 'hoge' ]); | ||
4082 | 77 | die $hs->get_error() if $res->[0] != 0; | ||
4083 | 78 | my $num_updated_rows = $res->[1]; | ||
4084 | 79 | |||
4085 | 80 | my $res = $hs->execute_single(3, '=', [ 'baz' ], 1, 0, 'D'); | ||
4086 | 81 | die $hs->get_error() if $res->[0] != 0; | ||
4087 | 82 | my $num_deleted_rows = $res->[1]; | ||
4088 | 83 | |||
4089 | 84 | The 6th argument for execute_single specifies the modification | ||
4090 | 85 | operation. The current version supports 'U' and 'D'. For the 'U' | ||
4091 | 86 | operation, the 7th argument specifies the new value for the row. | ||
4092 | 87 | The columns to be modified are specified by the 5th argument for | ||
4093 | 88 | the corresponding open_index call. For the 'D' operation, the | ||
4094 | 89 | 7th argument can be omitted. | ||
4095 | 90 | |||
4096 | 91 | ----------------------------------------------------------------- | ||
4097 | 92 | The execute_single method can be used for inserting records also. | ||
4098 | 93 | |||
4099 | 94 | my $res = $hs->execute_single(3, '+', [ 'foo', 'bar', 'baz' ]); | ||
4100 | 95 | die $hs->get_error() if $res->[0] != 0; | ||
4101 | 96 | my $num_inserted_rows = $res->[1]; | ||
4102 | 97 | |||
4103 | 98 | The 3rd argument must be an arrayref whose elements correspond to | ||
4104 | 99 | the 5th argument for the corresponding open_index call. If there | ||
4105 | 100 | is a column which is not appeared in the 5th argument for the | ||
4106 | 101 | open_index, the default value for the column is set. | ||
4107 | 102 | |||
4108 | 103 | ----------------------------------------------------------------- | ||
4109 | 104 | Multiple operations can be executed in a single call. Executing | ||
4110 | 105 | multiple operations in a single call is much faster than | ||
4111 | 106 | executing them separatedly. | ||
4112 | 107 | |||
4113 | 108 | my $rarr = $hs->execute_multi([ | ||
4114 | 109 | [ 0, '>=', [ 'foo' ], 5, 0 ], | ||
4115 | 110 | [ 2, '=', [ 'bar' ], 1, 0 ], | ||
4116 | 111 | [ 4, '<', [ 'baz' ], 10, 5 ], | ||
4117 | 112 | ]); | ||
4118 | 113 | for my $res (@$rarr) { | ||
4119 | 114 | die $hs->get_error() if $res->[0] != 0; | ||
4120 | 115 | shift(@$res); | ||
4121 | 116 | # ... | ||
4122 | 117 | } | ||
4123 | 118 | |||
4124 | 119 | ----------------------------------------------------------------- | ||
4125 | 120 | When an error is occured, the first element of the returned | ||
4126 | 121 | arrayref becomes a non-zero value. A negative value indicates | ||
4127 | 122 | that an I/O error is occured and the Net::HandlerSocket object | ||
4128 | 123 | should be disposed. A positive value means that the connection is | ||
4129 | 124 | still active and the Net::HandlerSocket object can be reused | ||
4130 | 125 | later. | ||
4131 | 126 | |||
4132 | 0 | 127 | ||
4133 | === added file 'HandlerSocket-Plugin-for-MySQL/docs-en/protocol.en.txt' | |||
4134 | --- HandlerSocket-Plugin-for-MySQL/docs-en/protocol.en.txt 1970-01-01 00:00:00 +0000 | |||
4135 | +++ HandlerSocket-Plugin-for-MySQL/docs-en/protocol.en.txt 2011-06-08 01:58:05 +0000 | |||
4136 | @@ -0,0 +1,148 @@ | |||
4137 | 1 | |||
4138 | 2 | ---------------------------------------------------------------------------- | ||
4139 | 3 | The HandlerSocket protocol | ||
4140 | 4 | |||
4141 | 5 | ---------------------------------------------------------------------------- | ||
4142 | 6 | Basic syntax | ||
4143 | 7 | |||
4144 | 8 | - The HandlerSocket protocol is line-based. Each line ends with LF(0x0a). | ||
4145 | 9 | - Each line consists a concatenation of tokens separated by HT(0x09). | ||
4146 | 10 | - A token is either NULL or an encoded string. Note that you need to | ||
4147 | 11 | distinguish NULL from an empty string, as most DBMs does so. | ||
4148 | 12 | - NULL is expressed as a single NUL(0x00). | ||
4149 | 13 | - An encoded string is a string with the following encoding rules. | ||
4150 | 14 | - Characters in the range [0x10 - 0xff] are not encoded. | ||
4151 | 15 | - A character in the range [0x00 - 0x0f] is prefixed by 0x01 and | ||
4152 | 16 | shifted by 0x40. For example, 0x03 is encoded as 0x01 0x43. | ||
4153 | 17 | - Note that a string can be empty. A continuation of 0x09 0x09 means that | ||
4154 | 18 | there is an empty string between them. A continuation of 0x09 0x0a means | ||
4155 | 19 | that there is an empty string at the end of the line. | ||
4156 | 20 | |||
4157 | 21 | ---------------------------------------------------------------------------- | ||
4158 | 22 | Request and Response | ||
4159 | 23 | |||
4160 | 24 | - The HandlerSocket protocol is a simple request/response protocol. After a | ||
4161 | 25 | connection is established, the client side sends a request, and then the | ||
4162 | 26 | server side sends a response. | ||
4163 | 27 | - A request/response consists of a single line. | ||
4164 | 28 | - Requests can be pipelined; That is, you can send multiple requests (ie. | ||
4165 | 29 | lines) at one time, and receive responses for them at one time. | ||
4166 | 30 | |||
4167 | 31 | ---------------------------------------------------------------------------- | ||
4168 | 32 | 'open_index' request | ||
4169 | 33 | |||
4170 | 34 | The 'open_index' request has the following syntax. | ||
4171 | 35 | |||
4172 | 36 | P <indexid> <dbname> <tablename> <indexname> <columns> | ||
4173 | 37 | |||
4174 | 38 | - <indexid> is a number in decimal. | ||
4175 | 39 | - <dbname>, <tablename>, and <indexname> are strings. To open the primary | ||
4176 | 40 | key, use PRIMARY as <indexname>. | ||
4177 | 41 | - <columns> is a comma-separated list of column names. | ||
4178 | 42 | |||
4179 | 43 | Once an 'open_index' request is issued, the HandlerSocket plugin opens the | ||
4180 | 44 | specified index and keep it open until the client connection is closed. Each | ||
4181 | 45 | open index is identified by <indexid>. If <indexid> is already open, the old | ||
4182 | 46 | open index is closed. You can open the same combination of <dbname> | ||
4183 | 47 | <tablename> <indexname> multple times, possibly with different <columns>. | ||
4184 | 48 | For efficiency, keep <indexid> small as far as possible. | ||
4185 | 49 | |||
4186 | 50 | ---------------------------------------------------------------------------- | ||
4187 | 51 | Getting data | ||
4188 | 52 | |||
4189 | 53 | The 'find' request has the following syntax. | ||
4190 | 54 | |||
4191 | 55 | <indexid> <op> <vlen> <v1> ... <vn> <limit> <offset> | ||
4192 | 56 | |||
4193 | 57 | - <indexid> is a number. This number must be an <indexid> specified by a | ||
4194 | 58 | 'open_index' request executed previously on the same connection. | ||
4195 | 59 | - <op> specifies the comparison operation to use. The current version of | ||
4196 | 60 | HandlerSocket supports '=', '>', '>=', '<', and '<='. | ||
4197 | 61 | - <vlen> indicates the length of the trailing parameters <v1> ... <vn>. This | ||
4198 | 62 | must be smaller than or equal to the number of index columns specified by | ||
4199 | 63 | specified by the corresponding 'open_index' request. | ||
4200 | 64 | - <v1> ... <vn> specify the index column values to fetch. | ||
4201 | 65 | - <limit> and <offset> are numbers. These parameters can be omitted. When | ||
4202 | 66 | omitted, it works as if 1 and 0 are specified. | ||
4203 | 67 | |||
4204 | 68 | ---------------------------------------------------------------------------- | ||
4205 | 69 | Updating/Deleting data | ||
4206 | 70 | |||
4207 | 71 | The 'find_modify' request has the following syntax. | ||
4208 | 72 | |||
4209 | 73 | <indexid> <op> <vlen> <v1> ... <vn> <limit> <offset> <mop> <m1> ... <mk> | ||
4210 | 74 | |||
4211 | 75 | - <mop> is either 'U' (update) or 'D' (delete). | ||
4212 | 76 | - <m1> ... <mk> specifies the column values to set. The length of <m1> ... | ||
4213 | 77 | <mk> must be smaller than or equal to the length of <columns> specified by | ||
4214 | 78 | the corresponding 'open_index' request. If <mop> is 'D', these parameters | ||
4215 | 79 | are ignored. | ||
4216 | 80 | |||
4217 | 81 | ---------------------------------------------------------------------------- | ||
4218 | 82 | Inserting data | ||
4219 | 83 | |||
4220 | 84 | The 'insert' request has the following syntax. | ||
4221 | 85 | |||
4222 | 86 | <indexid> '+' <vlen> <v1> ... <vn> | ||
4223 | 87 | |||
4224 | 88 | - <vlen> indicates the length of the trailing parameters <v1> ... <vn>. This | ||
4225 | 89 | must be smaller than or equal to the length of <columns> specified by the | ||
4226 | 90 | corresponding 'open_index' request. | ||
4227 | 91 | - <v1> ... <vn> specify the column values to set. For columns not in | ||
4228 | 92 | <columns>, the default values for each column are set. | ||
4229 | 93 | |||
4230 | 94 | ---------------------------------------------------------------------------- | ||
4231 | 95 | Response syntax | ||
4232 | 96 | |||
4233 | 97 | HandlerSocket returns a response of the following syntax for each request. | ||
4234 | 98 | |||
4235 | 99 | <errorcode> <numcolumns> <r1> ... <rn> | ||
4236 | 100 | |||
4237 | 101 | - <errorcode> indicates whether the request has successfully executed or not. | ||
4238 | 102 | '0' means success. Non-zero means an error. | ||
4239 | 103 | - <numcolumns> indicates the number of columns of the result set. | ||
4240 | 104 | - <r1> ... <rn> is the result set. The length of <r1> ... <rn> is always a | ||
4241 | 105 | multiple of <numcolumns>. It is possible that <r1> ... <rn> is empty. | ||
4242 | 106 | |||
4243 | 107 | If <errorcode> is non-zero, <numcolumns> is always 1 and <r1> indicates a | ||
4244 | 108 | human-readable error message, though sometimes <r1> is not provided. | ||
4245 | 109 | |||
4246 | 110 | ---------------------------------------------------------------------------- | ||
4247 | 111 | Response for 'open_index' | ||
4248 | 112 | |||
4249 | 113 | If 'open_index' is succeeded, HandlerSocket returns a line of the following | ||
4250 | 114 | syntax. | ||
4251 | 115 | |||
4252 | 116 | 0 1 | ||
4253 | 117 | |||
4254 | 118 | ---------------------------------------------------------------------------- | ||
4255 | 119 | Response for 'find' | ||
4256 | 120 | |||
4257 | 121 | If 'find' is succeeded, HandlerSocket returns a line of the following | ||
4258 | 122 | syntax. | ||
4259 | 123 | |||
4260 | 124 | 0 <numcolumns> <r1> ... <rn> | ||
4261 | 125 | |||
4262 | 126 | - <numcolumns> always equals to the length of <columns> of the corresponding | ||
4263 | 127 | 'open_index' request. | ||
4264 | 128 | - <r1> ... <rn> is the result set. If N rows are found, the length of <r1> | ||
4265 | 129 | ... <rn> becomes ( <numcolumns> * N ). | ||
4266 | 130 | |||
4267 | 131 | ---------------------------------------------------------------------------- | ||
4268 | 132 | Response for 'find_modify' | ||
4269 | 133 | |||
4270 | 134 | If 'find_modify' is succeeded, HandlerSocket returns a line of the following | ||
4271 | 135 | syntax. | ||
4272 | 136 | |||
4273 | 137 | 0 1 <nummod> | ||
4274 | 138 | |||
4275 | 139 | - <nummod> is the number of modified rows. | ||
4276 | 140 | |||
4277 | 141 | ---------------------------------------------------------------------------- | ||
4278 | 142 | Response for 'insert' | ||
4279 | 143 | |||
4280 | 144 | If 'insert' is succeeded, HanderSocket returns a line of the following | ||
4281 | 145 | syntax. | ||
4282 | 146 | |||
4283 | 147 | 0 1 | ||
4284 | 148 | |||
4285 | 0 | 149 | ||
4286 | === added directory 'HandlerSocket-Plugin-for-MySQL/docs-ja' | |||
4287 | === added file 'HandlerSocket-Plugin-for-MySQL/docs-ja/about-handlersocket.ja.txt' | |||
4288 | --- HandlerSocket-Plugin-for-MySQL/docs-ja/about-handlersocket.ja.txt 1970-01-01 00:00:00 +0000 | |||
4289 | +++ HandlerSocket-Plugin-for-MySQL/docs-ja/about-handlersocket.ja.txt 2011-06-08 01:58:05 +0000 | |||
4290 | @@ -0,0 +1,51 @@ | |||
4291 | 1 | |||
4292 | 2 | |||
4293 | 3 | ----------------------------------------------------------------- | ||
4294 | 4 | ソースコードの利用にあたっての免責事項 | ||
4295 | 5 | |||
4296 | 6 | 本ソフトウェアの開発者および株式会社ディー・エヌ・エーは、本フト | ||
4297 | 7 | ウェアの不稼動、稼動不良を含む法律上の瑕疵担保責任、その他保証責 | ||
4298 | 8 | 任を負わないものとします。また、本ソフトウエアの開発者および株式 | ||
4299 | 9 | 会社ディー・エヌ・エーは、本ソフトウェアの商品性、またはお客様の | ||
4300 | 10 | 特定の目的に対する適合性について、いかなる保証も負わないものとし | ||
4301 | 11 | ます。 | ||
4302 | 12 | |||
4303 | 13 | ----------------------------------------------------------------- | ||
4304 | 14 | handlersocket pluginについて | ||
4305 | 15 | |||
4306 | 16 | mysqlサーバに常駐し、innodb等のストレージエンジンへの直接のアクセ | ||
4307 | 17 | スを提供するプラグインです。handlersocketプラグインは自前のリス | ||
4308 | 18 | ナーを持ち、専用のクライアントライブラリ(libhsclient)を使ってそれ | ||
4309 | 19 | にアクセスします。 | ||
4310 | 20 | |||
4311 | 21 | mysqlの標準クライアントライブラリ(libmysql)を使ったアクセスと比べ | ||
4312 | 22 | て、以下のような利点があります。 | ||
4313 | 23 | ・接続あたりに消費するリソースが少ないため、同時接続数が事実上無 | ||
4314 | 24 | 制限。したがって接続数を気にせず持続接続を使えます。 | ||
4315 | 25 | ・高速(単純な参照クエリで3倍〜10倍程度)。 | ||
4316 | 26 | ・通信プロトコルがコンパクト。libmysqlを使うとデータ転送時にレ | ||
4317 | 27 | コード名などが付随するために通信内容が冗長ですが、libhsclientで | ||
4318 | 28 | はデータのみが転送されるため、帯域消費が少なくなります。場合に | ||
4319 | 29 | よっては10倍以上libmysqlのほうが冗長になります。 | ||
4320 | 30 | |||
4321 | 31 | 現在のバージョンでは以下のような処理をサポートしています。 | ||
4322 | 32 | ・指定された索引について、指定された値と完全一致するようなレコー | ||
4323 | 33 | ドを取得。(SELECT ??? FROM tbl WHERE k1 = v1 AND k2 = v2...)。 | ||
4324 | 34 | 索引を使わない検索はサポートしていません。 | ||
4325 | 35 | ・指定された索引について、指定された値の位置の前後のレコードを取 | ||
4326 | 36 | 得。(SELECT ??? FROM tbl WHERE k1 >= v1 LIMIT 100) | ||
4327 | 37 | ・前述のような手段で取得したレコードに対するUPDATEとDELETE | ||
4328 | 38 | ・レコードのINSERT | ||
4329 | 39 | |||
4330 | 40 | 以下のような言語をサポートします。 | ||
4331 | 41 | ・C++。libhsclientをリンクします。 | ||
4332 | 42 | ・Perl。Net::HandlerSocketをuseします。 | ||
4333 | 43 | |||
4334 | 44 | 現在のバージョンではGNU/Linuxでのみ動作します。 | ||
4335 | 45 | |||
4336 | 46 | ----------------------------------------------------------------- | ||
4337 | 47 | 既知の問題 | ||
4338 | 48 | |||
4339 | 49 | ・killでhandlersocketスレッドを殺すと、スレッド数が減ったまま回復 | ||
4340 | 50 | しません。 | ||
4341 | 51 | |||
4342 | 0 | 52 | ||
4343 | === added file 'HandlerSocket-Plugin-for-MySQL/docs-ja/installation.ja.txt' | |||
4344 | --- HandlerSocket-Plugin-for-MySQL/docs-ja/installation.ja.txt 1970-01-01 00:00:00 +0000 | |||
4345 | +++ HandlerSocket-Plugin-for-MySQL/docs-ja/installation.ja.txt 2011-06-08 01:58:05 +0000 | |||
4346 | @@ -0,0 +1,87 @@ | |||
4347 | 1 | |||
4348 | 2 | ----------------------------------------------------------------- | ||
4349 | 3 | HandlerSocketプラグインのビルド方法(RPMを使わない方法) | ||
4350 | 4 | |||
4351 | 5 | 以下のようにしてconfigureを実行します。 | ||
4352 | 6 | |||
4353 | 7 | $ ./autogen.sh | ||
4354 | 8 | $ ./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 | ||
4355 | 9 | |||
4356 | 10 | ここで--with-mysql-sourceにはMySQLのソースコードのトップディレク | ||
4357 | 11 | トリを指定します。--with-mysql-bindirにはインストール済みのMySQL | ||
4358 | 12 | のmysql_configコマンドが有るディレクトリを指定します。 | ||
4359 | 13 | その後以下のようにビルド・インストールします。 | ||
4360 | 14 | |||
4361 | 15 | $ make | ||
4362 | 16 | $ sudo make install | ||
4363 | 17 | |||
4364 | 18 | ----------------------------------------------------------------- | ||
4365 | 19 | クライアントライブラリのビルド方法(RPMを使わない方法) | ||
4366 | 20 | |||
4367 | 21 | クライアントライブラリをビルドする際には、MySQLのソースコードは | ||
4368 | 22 | 必要ありません。またMySQLがインストールされている必要もありません。 | ||
4369 | 23 | |||
4370 | 24 | $ ./autogen.sh | ||
4371 | 25 | $ ./configure --disable-handlersocket-server | ||
4372 | 26 | $ make | ||
4373 | 27 | $ sudo make install | ||
4374 | 28 | $ cd perl-Net-HandlerSocket | ||
4375 | 29 | $ perl Makefile.PL | ||
4376 | 30 | $ make | ||
4377 | 31 | $ sudo make install | ||
4378 | 32 | |||
4379 | 33 | ----------------------------------------------------------------- | ||
4380 | 34 | ビルド方法(RPM) | ||
4381 | 35 | |||
4382 | 36 | 以下のように実行すれば、rpmパッケージがビルド&インストールされま | ||
4383 | 37 | す。 | ||
4384 | 38 | |||
4385 | 39 | (MySQLサーバ側、HandlerSocketプラグインをインストールする) | ||
4386 | 40 | $ ./autogen.sh | ||
4387 | 41 | $ ./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 | ||
4388 | 42 | $ make rpm_cli | ||
4389 | 43 | $ sudo rpm -U dist/RPMS/*/libhsclient*.rpm | ||
4390 | 44 | $ make rpm_c | ||
4391 | 45 | $ sudo rpm -U dist/RPMS/*/handlersocket*.rpm | ||
4392 | 46 | |||
4393 | 47 | (クライアント側、クライアントライブラリをインストールする) | ||
4394 | 48 | $ ./autogen.sh | ||
4395 | 49 | $ ./configure --disable-handlersocket-server | ||
4396 | 50 | $ make rpm_cli | ||
4397 | 51 | $ sudo rpm -U dist/RPMS/*/libhsclient*.rpm | ||
4398 | 52 | $ make rpm_perl | ||
4399 | 53 | $ sudo rpm -U dist/RPMS/*/perl-Net-HandlerSocket*.rpm | ||
4400 | 54 | |||
4401 | 55 | ----------------------------------------------------------------- | ||
4402 | 56 | 起動 | ||
4403 | 57 | |||
4404 | 58 | mysqlを起動した状態で、mysqlの設定ファイル(my.cnf等)に以下の内容を | ||
4405 | 59 | 追加します。 | ||
4406 | 60 | |||
4407 | 61 | [mysqld] | ||
4408 | 62 | handlersocket_port = 9998 | ||
4409 | 63 | # handlersocketが接続を受け付けるポート(参照系リクエスト用) | ||
4410 | 64 | handlersocket_port_wr = 9999 | ||
4411 | 65 | # handlersocketが接続を受け付けるポート(更新系リクエスト用) | ||
4412 | 66 | handlersocket_address = | ||
4413 | 67 | # handlersocketがバインドするアドレス(空のままでOK) | ||
4414 | 68 | handlersocket_verbose = 0 | ||
4415 | 69 | # デバッグ用 | ||
4416 | 70 | handlersocket_timeout = 300 | ||
4417 | 71 | # 通信タイムアウト(秒) | ||
4418 | 72 | handlersocket_threads = 16 | ||
4419 | 73 | # handlersocketのワーカースレッド数 | ||
4420 | 74 | thread_concurrency = 128 | ||
4421 | 75 | # handlersocketが幾つかのスレッドを占有するため、大きめの | ||
4422 | 76 | # 値を指定してください | ||
4423 | 77 | open_files_limit = 65535 | ||
4424 | 78 | # ソケットを大量に開けるようにするため、大きめの値を指定し | ||
4425 | 79 | # てください | ||
4426 | 80 | |||
4427 | 81 | 以下のクエリを実行します。 | ||
4428 | 82 | |||
4429 | 83 | mysql> install plugin handlersocket soname 'handlersocket.so'; | ||
4430 | 84 | Query OK, 0 rows affected (0.06 sec) | ||
4431 | 85 | |||
4432 | 86 | 以上でhandlersocketへクライアントからアクセスできるようになります。 | ||
4433 | 87 | |||
4434 | 0 | 88 | ||
4435 | === added file 'HandlerSocket-Plugin-for-MySQL/docs-ja/perl-client.ja.txt' | |||
4436 | --- HandlerSocket-Plugin-for-MySQL/docs-ja/perl-client.ja.txt 1970-01-01 00:00:00 +0000 | |||
4437 | +++ HandlerSocket-Plugin-for-MySQL/docs-ja/perl-client.ja.txt 2011-06-08 01:58:05 +0000 | |||
4438 | @@ -0,0 +1,118 @@ | |||
4439 | 1 | |||
4440 | 2 | ----------------------------------------------------------------- | ||
4441 | 3 | handlersocketプラグインへの接続を開くには、Net::HandlerSocketオブ | ||
4442 | 4 | ジェクトを作成します。 | ||
4443 | 5 | |||
4444 | 6 | use Net::HandlerSocket; | ||
4445 | 7 | my $args = { host => 'localhost', port => 9998 }; | ||
4446 | 8 | my $hs = new Net::HandlerSocket($args); | ||
4447 | 9 | |||
4448 | 10 | ----------------------------------------------------------------- | ||
4449 | 11 | 検索などの命令を実行する前に、処理対象となる索引を開く必要があり | ||
4450 | 12 | ます。 | ||
4451 | 13 | |||
4452 | 14 | my $err = $hs->open_index(3, 'database1', 'table1', 'PRIMARY', | ||
4453 | 15 | 'f1,f2'); | ||
4454 | 16 | die $hs->get_error() if $res->[0] != 0; | ||
4455 | 17 | |||
4456 | 18 | 最初の引数は開く索引に付ける番号です。付けた番号は同一の | ||
4457 | 19 | Net::HandlerSocketオブジェクトについてのみ有効です。第4引数は開く | ||
4458 | 20 | 索引の名前で、「PRIMARY」が指定され場合はプライマリキーが開かれま | ||
4459 | 21 | す。第5引数は「,」で区切られた列名のリストです。 | ||
4460 | 22 | |||
4461 | 23 | ----------------------------------------------------------------- | ||
4462 | 24 | テーブルから索引を使って行を取得するには、execute_singleメソッド | ||
4463 | 25 | を呼びます。 | ||
4464 | 26 | |||
4465 | 27 | my $res = $hs->execute_single(3, '=', [ 'foo' ], 1, 0); | ||
4466 | 28 | die $hs->get_error() if $res->[0] != 0; | ||
4467 | 29 | shift(@$res); | ||
4468 | 30 | |||
4469 | 31 | 最初の引数は索引の番号で、同じNet::HandlerSocketオブジェクトへ | ||
4470 | 32 | open_indexで付けたものでなければなりません。第2引数には操作を指定 | ||
4471 | 33 | します。現在のバージョンでは、「=」、「>=」、「<=」、「>」、「<」 | ||
4472 | 34 | の操作が利用可能です。第3引数は配列への参照で、これは探すべき行の | ||
4473 | 35 | キー値を指定します。配列の長さは索引のキーの個数と同じか少ない数 | ||
4474 | 36 | でなければなりません。第4引数と第5引数はそれぞれ、取得する最大行 | ||
4475 | 37 | 数、取得前に読み飛ばす行数を指定します。取得される列は対応する | ||
4476 | 38 | open_index呼び出しの第5引数で指定されたものになります。 | ||
4477 | 39 | |||
4478 | 40 | execute_singleメソッドは常に配列への参照を返します。最初の要素は | ||
4479 | 41 | エラーコードで、これが0ならば成功を表します。残りの要素は列の値で | ||
4480 | 42 | す。もし取得されたデータが複数行の場合は、それが一つの配列へ連結 | ||
4481 | 43 | された形で格納されています。例えば、5行3列のデータの場合、次のよ | ||
4482 | 44 | うなコードによってその内容を取得できます。 | ||
4483 | 45 | |||
4484 | 46 | die $hs->get_error() if $res->[0] != 0; | ||
4485 | 47 | shift(@$res); | ||
4486 | 48 | for (my $row = 0; $row < 5; ++$row) { | ||
4487 | 49 | for (my $col = 0; $col < 3; ++$col) { | ||
4488 | 50 | my $value = $res->[$row * 5 + $col]; | ||
4489 | 51 | # ... | ||
4490 | 52 | } | ||
4491 | 53 | } | ||
4492 | 54 | |||
4493 | 55 | ----------------------------------------------------------------- | ||
4494 | 56 | 行を更新または削除するには、更に多くの引数を指定して | ||
4495 | 57 | execute_singleメソッドを呼び出します。書き込み処理をするには、 | ||
4496 | 58 | 対象のNet::HandlerSocketオブジェクトは更新用handlersocketワーカ(既 | ||
4497 | 59 | 定ではポート9999)へ接続されたものでなくてはなりません。 | ||
4498 | 60 | (安全のため、ポート9998は参照処理だけを受け付け、ポート9999は更新 | ||
4499 | 61 | 処理も受け付けるようになっています。ポート9999は参照処理も受け付 | ||
4500 | 62 | けますが、レコードロック等の影響で遅くなります。ポート番号は | ||
4501 | 63 | mysqldの「handlersocket_port」と「handlersocket_port_wr」の設定項 | ||
4502 | 64 | 目で変更できます。) | ||
4503 | 65 | |||
4504 | 66 | my $args = { host => 'localhost', port => 9999 }; | ||
4505 | 67 | my $hs = new Net::HandlerSocket($args); | ||
4506 | 68 | |||
4507 | 69 | my $res = $hs->execute_single(3, '=', [ 'bar' ], 1, 0, 'U', | ||
4508 | 70 | [ 'fubar', 'hoge' ]); | ||
4509 | 71 | die $hs->get_error() if $res->[0] != 0; | ||
4510 | 72 | my $num_updated_rows = $res->[1]; | ||
4511 | 73 | |||
4512 | 74 | my $res = $hs->execute_single(3, '=', [ 'baz' ], 1, 0, 'D'); | ||
4513 | 75 | die $hs->get_error() if $res->[0] != 0; | ||
4514 | 76 | my $num_deleted_rows = $res->[1]; | ||
4515 | 77 | |||
4516 | 78 | execute_singleの第6引数は変更処理の種類を指定します。現在のバー | ||
4517 | 79 | ジョンでは「U」と「D」が利用可能です。「U」については、第7引数で | ||
4518 | 80 | 新しい値を指定します。更新される列は、対応するopen_index呼び出し | ||
4519 | 81 | の第5引数で指定されたものになります。「D」については第7引数は省 | ||
4520 | 82 | 略できます。 | ||
4521 | 83 | |||
4522 | 84 | ----------------------------------------------------------------- | ||
4523 | 85 | execute_singleメソッドは列の挿入にも使用できます。 | ||
4524 | 86 | |||
4525 | 87 | my $res = $hs->execute_single(3, '+', [ 'foo', 'bar', 'baz' ]); | ||
4526 | 88 | die $hs->get_error() if $res->[0] != 0; | ||
4527 | 89 | my $num_inserted_rows = $res->[1]; | ||
4528 | 90 | |||
4529 | 91 | 第3引数は、対応するopen_index呼び出しの第5引数の列リストと同じだ | ||
4530 | 92 | けの長さの配列への参照でなければなりません。open_index呼び出しの | ||
4531 | 93 | 第5引数に指定されていない列については、その列の既定値がセットされ | ||
4532 | 94 | ます。 | ||
4533 | 95 | |||
4534 | 96 | ----------------------------------------------------------------- | ||
4535 | 97 | execute_multiメソッドを使えば、複数のリクエストを一つの呼び出しで | ||
4536 | 98 | 実行することができます。これはリクエストを個別に実行するより高速 | ||
4537 | 99 | です。 | ||
4538 | 100 | |||
4539 | 101 | my $rarr = $hs->execute_multi([ | ||
4540 | 102 | [ 0, '>=', [ 'foo' ], 5, 0 ], | ||
4541 | 103 | [ 2, '=', [ 'bar' ], 1, 0 ], | ||
4542 | 104 | [ 4, '<', [ 'baz' ], 10, 5 ], | ||
4543 | 105 | ]); | ||
4544 | 106 | for my $res (@$rarr) { | ||
4545 | 107 | die $hs->get_error() if $res->[0] != 0; | ||
4546 | 108 | shift(@$res); | ||
4547 | 109 | # ... | ||
4548 | 110 | } | ||
4549 | 111 | |||
4550 | 112 | ----------------------------------------------------------------- | ||
4551 | 113 | エラーが起こると返値の配列参照の最初の要素が0以外になります。負の | ||
4552 | 114 | 数の場合はI/Oエラーが起こったことを示し、その場合はその | ||
4553 | 115 | Net::HandlerSocketオブジェクトは破棄するべきです。正の値の場合は | ||
4554 | 116 | 接続は維持されているため、そのオブジェクトはそれ以後も再利用でき | ||
4555 | 117 | ます。 | ||
4556 | 118 | |||
4557 | 0 | 119 | ||
4558 | === added file 'HandlerSocket-Plugin-for-MySQL/docs-ja/protocol.ja.txt' | |||
4559 | --- HandlerSocket-Plugin-for-MySQL/docs-ja/protocol.ja.txt 1970-01-01 00:00:00 +0000 | |||
4560 | +++ HandlerSocket-Plugin-for-MySQL/docs-ja/protocol.ja.txt 2011-06-08 01:58:05 +0000 | |||
4561 | @@ -0,0 +1,94 @@ | |||
4562 | 1 | |||
4563 | 2 | ----------------------------------------------------------------- | ||
4564 | 3 | handlersocketの通信プロトコル | ||
4565 | 4 | |||
4566 | 5 | ----------------------------------------------------------------- | ||
4567 | 6 | 構文 | ||
4568 | 7 | |||
4569 | 8 | ・コマンド行は改行(LF)で終わる。 | ||
4570 | 9 | ・コマンド行は複数のトークンからなり、トークン間はTABで区切られる。 | ||
4571 | 10 | ・トークンはNULLトークンか、文字列トークンのいずれか。 | ||
4572 | 11 | ・NULLトークンは単一のNUL文字であらわされる。 | ||
4573 | 12 | ・文字列トークンは、0バイト以上の文字列であらわされる。ただし0x10 | ||
4574 | 13 | 未満の文字については0x01を前置し、0x40を加えたコードであらわさ | ||
4575 | 14 | れる。それ以外の文字はその文字自身のコードであらわされる。 | ||
4576 | 15 | |||
4577 | 16 | ----------------------------------------------------------------- | ||
4578 | 17 | リクエストとレスポンス | ||
4579 | 18 | |||
4580 | 19 | ・接続が確立した直後の状態では、まずクライアントがコマンド行を送 | ||
4581 | 20 | る。(リクエスト) | ||
4582 | 21 | ・サーバはクライアントが送ったリクエストと丁度同じ数のコマンド行 | ||
4583 | 22 | を返す。(レスポンス) | ||
4584 | 23 | ・リクエストはパイプライン化してよい。つまりクライアントは前に | ||
4585 | 24 | 送ったリクエストに対する返事を待たずに次のリクエストを送っても | ||
4586 | 25 | よい。 | ||
4587 | 26 | |||
4588 | 27 | ----------------------------------------------------------------- | ||
4589 | 28 | リクエスト | ||
4590 | 29 | |||
4591 | 30 | ・open_index命令は次のような構文を持つ。 | ||
4592 | 31 | 'P' indexid dbname tablename indexname fieldlist | ||
4593 | 32 | indexidは開いている索引に付けられる番号で、同一接続上で後に実行 | ||
4594 | 33 | する命令の、対象索引を指定するために使われる。dbname、tablename、 | ||
4595 | 34 | indexnameはそれぞれ開きたいDB、テーブル、索引の名前。索引の名前 | ||
4596 | 35 | として"PRIMARY"を指定するとプライマリキーが開かれる。fieldlist | ||
4597 | 36 | はカンマ区切りの列名のリスト。 | ||
4598 | 37 | ・find命令は次のような構文を持つ。 | ||
4599 | 38 | indexid op nflds v1 ... vn limit offset | ||
4600 | 39 | indexidは実行対象の索引を指定する。opは索引検索の演算子(後述)。 | ||
4601 | 40 | v1からvnは可変長で、その個数はnflds。nfldsはindexidで指定された | ||
4602 | 41 | open_index命令のindexnameの索引のfieldlistのフィールド数に等し | ||
4603 | 42 | いか小さくなくてはならない。m2からmkは可変長で、その個数は | ||
4604 | 43 | indexidで指定されたopen_index命令が発行された際のfieldlistに一 | ||
4605 | 44 | 致しなければならない。コマンド行のlimit以降は省略できる。limit | ||
4606 | 45 | とoffsetは、検索条件に合致する列のうちレスポンスに返す列数の上 | ||
4607 | 46 | 限と、スキップする列数。limitとoffsetを省略した場合はそれぞれ1 | ||
4608 | 47 | と0が指定されたときと同じ動作をする。find命令はレスポンスとして、 | ||
4609 | 48 | 条件に合致した列のリストを返す。opとして指定できる演算子は次の | ||
4610 | 49 | とおり。 | ||
4611 | 50 | '=' - v1 ... vnと一致するものを取得 | ||
4612 | 51 | '>' - v1 ... vnより大きいものを昇順に取得 | ||
4613 | 52 | '>=' - v1 ... vnに一致するか大きいものを昇順に取得 | ||
4614 | 53 | '<' - v1 ... vnより小さいものを降順に取得 | ||
4615 | 54 | '<=' - v1 ... vnに一致するか等しいものを降順に取得 | ||
4616 | 55 | nfldsが1より大きい(v1 ... vnが2個以上)ときは辞書式順序で比較さ | ||
4617 | 56 | れる。 | ||
4618 | 57 | ・find_modify命令は次のような構文を持つ。 | ||
4619 | 58 | indexid op nflds v1 ... vn limit offset modop m1 ... mk | ||
4620 | 59 | modopより前の部分はfind命令と同等で、これによって操作対象の行を | ||
4621 | 60 | 指定する。その操作対象の行に対しmodopで指定された変更処理を実行 | ||
4622 | 61 | する。m1 ... mkは可変長で、省略できる。modopは次いずれか。 | ||
4623 | 62 | 'U' - indexidで指定されたopen_index命令のfieldlist列 | ||
4624 | 63 | の内容を、m1 ... mkの値で更新する。 | ||
4625 | 64 | 'D' - 対象の行を削除する。m1 ... mkの値は無視される。 | ||
4626 | 65 | ・insert命令はのような構文を持つ。 | ||
4627 | 66 | indexid '+' nflds v1 ... vn | ||
4628 | 67 | indexidで指定されたテーブルに、列を挿入する。v1 ... vnは可変長 | ||
4629 | 68 | で、その個数はnflds。nfldsはindexidで指定されたopen_index命令の | ||
4630 | 69 | indexnameの索引のfieldlistのフィールド数に等しいか小さくなくて | ||
4631 | 70 | はならない。 | ||
4632 | 71 | |||
4633 | 72 | ----------------------------------------------------------------- | ||
4634 | 73 | レスポンス | ||
4635 | 74 | |||
4636 | 75 | ・open_index命令が成功したとき、レスポンスは次の構文を持つ。 | ||
4637 | 76 | '0' '1' | ||
4638 | 77 | ・find命令が成功したとき、レスポンスは次の構文を持つ。 | ||
4639 | 78 | '0' nflds v1 ... vn | ||
4640 | 79 | nfldsは結果セットの列の数をあらわす。v1 ... vnは可変長で、その | ||
4641 | 80 | 長さはnfldsの整数倍。v1 ... vnは空のこともあり、それは条件に合 | ||
4642 | 81 | 致するレコードが存在しなかったことをあらわす。結果セットが複数 | ||
4643 | 82 | 行になったときはv1 ... vnの長さがnfldsの2倍以上となり、最初の | ||
4644 | 83 | 行から順にv1 ... vnにセットされる。 | ||
4645 | 84 | ・modify命令が成功したとき、レスポンスは次の構文を持つ。 | ||
4646 | 85 | '0' '1' nummod | ||
4647 | 86 | nummodは変更が施された行数。nummodが0のときは変更された行が無 | ||
4648 | 87 | かったことをあらわす。 | ||
4649 | 88 | ・insert命令が成功したとき、レスポンスは次の構文を持つ。 | ||
4650 | 89 | '0' '1' | ||
4651 | 90 | ・命令が失敗したとき、レスポンスは命令に関わらず次の構文を持つ。 | ||
4652 | 91 | err '1' message | ||
4653 | 92 | errは0以外の数値で、エラーコードをあらわす。messageは人間可読な | ||
4654 | 93 | エラーメッセージ。ただしmessageが無いこともある。 | ||
4655 | 94 | |||
4656 | 0 | 95 | ||
4657 | === added directory 'HandlerSocket-Plugin-for-MySQL/handlersocket' | |||
4658 | === added file 'HandlerSocket-Plugin-for-MySQL/handlersocket/COPYRIGHT.txt' | |||
4659 | --- HandlerSocket-Plugin-for-MySQL/handlersocket/COPYRIGHT.txt 1970-01-01 00:00:00 +0000 | |||
4660 | +++ HandlerSocket-Plugin-for-MySQL/handlersocket/COPYRIGHT.txt 2011-06-08 01:58:05 +0000 | |||
4661 | @@ -0,0 +1,27 @@ | |||
4662 | 1 | |||
4663 | 2 | Copyright (c) 2010 DeNA Co.,Ltd. | ||
4664 | 3 | All rights reserved. | ||
4665 | 4 | |||
4666 | 5 | Redistribution and use in source and binary forms, with or without | ||
4667 | 6 | modification, are permitted provided that the following conditions are met: | ||
4668 | 7 | |||
4669 | 8 | * Redistributions of source code must retain the above copyright | ||
4670 | 9 | notice, this list of conditions and the following disclaimer. | ||
4671 | 10 | * Redistributions in binary form must reproduce the above copyright | ||
4672 | 11 | notice, this list of conditions and the following disclaimer in the | ||
4673 | 12 | documentation and/or other materials provided with the distribution. | ||
4674 | 13 | * Neither the name of DeNA Co.,Ltd. nor the names of its contributors | ||
4675 | 14 | may be used to endorse or promote products derived from this software | ||
4676 | 15 | without specific prior written permission. | ||
4677 | 16 | |||
4678 | 17 | THIS SOFTWARE IS PROVIDED BY DeNA Co.,Ltd. "AS IS" AND ANY EXPRESS OR | ||
4679 | 18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
4680 | 19 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | ||
4681 | 20 | EVENT SHALL DeNA Co.,Ltd. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
4682 | 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
4683 | 22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
4684 | 23 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
4685 | 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
4686 | 25 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
4687 | 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
4688 | 27 | |||
4689 | 0 | 28 | ||
4690 | === added file 'HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.am' | |||
4691 | --- HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.am 1970-01-01 00:00:00 +0000 | |||
4692 | +++ HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.am 2011-06-08 01:58:05 +0000 | |||
4693 | @@ -0,0 +1,10 @@ | |||
4694 | 1 | pkgplugindir = $(PLUGIN_DIR) | ||
4695 | 2 | noinst_HEADERS = database.hpp hstcpsvr.hpp hstcpsvr_worker.hpp mysql_incl.hpp | ||
4696 | 3 | pkgplugin_LTLIBRARIES = handlersocket.la | ||
4697 | 4 | handlersocket_la_LDFLAGS = -module ../libhsclient/libhsclient.la | ||
4698 | 5 | handlersocket_la_CFLAGS = $(MYSQL_INC) $(MYSQL_CFLAGS) $(AM_CFLAGS) \ | ||
4699 | 6 | -I../libhsclient | ||
4700 | 7 | handlersocket_la_CXXFLAGS = $(MYSQL_INC) $(MYSQL_CFLAGS) $(AM_CFLAGS) \ | ||
4701 | 8 | -I../libhsclient | ||
4702 | 9 | handlersocket_la_SOURCES = database.cpp handlersocket.cpp \ | ||
4703 | 10 | hstcpsvr_worker.cpp hstcpsvr.cpp | ||
4704 | 0 | 11 | ||
4705 | === added file 'HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.plain.template' | |||
4706 | --- HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.plain.template 1970-01-01 00:00:00 +0000 | |||
4707 | +++ HandlerSocket-Plugin-for-MySQL/handlersocket/Makefile.plain.template 2011-06-08 01:58:05 +0000 | |||
4708 | @@ -0,0 +1,31 @@ | |||
4709 | 1 | |||
4710 | 2 | MYSQL_INC = HANDLERSOCKET_MYSQL_INC | ||
4711 | 3 | MYSQL_LIB = HANDLERSOCKET_MYSQL_LIB | ||
4712 | 4 | |||
4713 | 5 | CXX = g++ -Wall -g -fno-rtti -fno-exceptions -fPIC -DPIC | ||
4714 | 6 | LIBS = $(MYSQL_LIB) -lhsclient -lpthread -lz | ||
4715 | 7 | CXXFLAGS = -I/usr/include/handlersocket $(MYSQL_INC) | ||
4716 | 8 | LDFLAGS = | ||
4717 | 9 | |||
4718 | 10 | CXXFLAGS += -O3 -DNDEBUG | ||
4719 | 11 | |||
4720 | 12 | HANDLERSOCKET_OBJS = database.o hstcpsvr.o hstcpsvr_worker.o | ||
4721 | 13 | |||
4722 | 14 | all: handlersocket.so | ||
4723 | 15 | |||
4724 | 16 | handlersocket.so: $(HANDLERSOCKET_OBJS) handlersocket.cpp | ||
4725 | 17 | $(CXX) $(CXXFLAGS) -fno-strict-aliasing -shared $^ -o $@ $(LDFLAGS) \ | ||
4726 | 18 | -Wl,-soname -Wl,$@ $(LIBS) | ||
4727 | 19 | clean: | ||
4728 | 20 | rm -f *.a *.so *.o | ||
4729 | 21 | |||
4730 | 22 | LIBDIR = $(shell \ | ||
4731 | 23 | if [ -e /usr/lib64/mysql ]; then echo /usr/lib64; else echo /usr/lib; fi) | ||
4732 | 24 | |||
4733 | 25 | install: handlersocket.so | ||
4734 | 26 | sudo sh -c 'ulimit -c unlimited ; /etc/init.d/mysql stop ; \ | ||
4735 | 27 | cp handlersocket.so handlersocket.so.cpy && \ | ||
4736 | 28 | mv handlersocket.so.cpy \ | ||
4737 | 29 | $(LIBDIR)/mysql/plugin/handlersocket.so && \ | ||
4738 | 30 | /etc/init.d/mysql start' | ||
4739 | 31 | |||
4740 | 0 | 32 | ||
4741 | === added file 'HandlerSocket-Plugin-for-MySQL/handlersocket/database.cpp' | |||
4742 | --- HandlerSocket-Plugin-for-MySQL/handlersocket/database.cpp 1970-01-01 00:00:00 +0000 | |||
4743 | +++ HandlerSocket-Plugin-for-MySQL/handlersocket/database.cpp 2011-06-08 01:58:05 +0000 | |||
4744 | @@ -0,0 +1,1183 @@ | |||
4745 | 1 | |||
4746 | 2 | // vim:sw=2:ai | ||
4747 | 3 | |||
4748 | 4 | /* | ||
4749 | 5 | * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved. | ||
4750 | 6 | * See COPYRIGHT.txt for details. | ||
4751 | 7 | */ | ||
4752 | 8 | |||
4753 | 9 | #include <stdlib.h> | ||
4754 | 10 | #include <stdio.h> | ||
4755 | 11 | #include <string.h> | ||
4756 | 12 | |||
4757 | 13 | #include "database.hpp" | ||
4758 | 14 | #include "string_util.hpp" | ||
4759 | 15 | #include "escape.hpp" | ||
4760 | 16 | #include "mysql_incl.hpp" | ||
4761 | 17 | |||
4762 | 18 | #define DBG_KEY(x) | ||
4763 | 19 | #define DBG_SHUT(x) | ||
4764 | 20 | #define DBG_LOCK(x) | ||
4765 | 21 | #define DBG_THR(x) | ||
4766 | 22 | #define DBG_CMP(x) | ||
4767 | 23 | #define DBG_FLD(x) | ||
4768 | 24 | #define DBG_FILTER(x) | ||
4769 | 25 | #define DBG_REFCNT(x) | ||
4770 | 26 | #define DBG_KEYLEN(x) | ||
4771 | 27 | #define DBG_DELETED | ||
4772 | 28 | |||
4773 | 29 | /* status variables */ | ||
4774 | 30 | unsigned long long int open_tables_count; | ||
4775 | 31 | unsigned long long int close_tables_count; | ||
4776 | 32 | unsigned long long int lock_tables_count; | ||
4777 | 33 | unsigned long long int unlock_tables_count; | ||
4778 | 34 | unsigned long long int index_exec_count; | ||
4779 | 35 | |||
4780 | 36 | namespace dena { | ||
4781 | 37 | |||
4782 | 38 | prep_stmt::prep_stmt() | ||
4783 | 39 | : dbctx(0), table_id(static_cast<size_t>(-1)), | ||
4784 | 40 | idxnum(static_cast<size_t>(-1)) | ||
4785 | 41 | { | ||
4786 | 42 | } | ||
4787 | 43 | prep_stmt::prep_stmt(dbcontext_i *c, size_t tbl, size_t idx, | ||
4788 | 44 | const fields_type& rf, const fields_type& ff) | ||
4789 | 45 | : dbctx(c), table_id(tbl), idxnum(idx), ret_fields(rf), filter_fields(ff) | ||
4790 | 46 | { | ||
4791 | 47 | if (dbctx) { | ||
4792 | 48 | dbctx->table_addref(table_id); | ||
4793 | 49 | } | ||
4794 | 50 | } | ||
4795 | 51 | prep_stmt::~prep_stmt() | ||
4796 | 52 | { | ||
4797 | 53 | if (dbctx) { | ||
4798 | 54 | dbctx->table_release(table_id); | ||
4799 | 55 | } | ||
4800 | 56 | } | ||
4801 | 57 | |||
4802 | 58 | prep_stmt::prep_stmt(const prep_stmt& x) | ||
4803 | 59 | : dbctx(x.dbctx), table_id(x.table_id), idxnum(x.idxnum), | ||
4804 | 60 | ret_fields(x.ret_fields), filter_fields(x.filter_fields) | ||
4805 | 61 | { | ||
4806 | 62 | if (dbctx) { | ||
4807 | 63 | dbctx->table_addref(table_id); | ||
4808 | 64 | } | ||
4809 | 65 | } | ||
4810 | 66 | |||
4811 | 67 | prep_stmt& | ||
4812 | 68 | prep_stmt::operator =(const prep_stmt& x) | ||
4813 | 69 | { | ||
4814 | 70 | if (this != &x) { | ||
4815 | 71 | if (dbctx) { | ||
4816 | 72 | dbctx->table_release(table_id); | ||
4817 | 73 | } | ||
4818 | 74 | dbctx = x.dbctx; | ||
4819 | 75 | table_id = x.table_id; | ||
4820 | 76 | idxnum = x.idxnum; | ||
4821 | 77 | ret_fields = x.ret_fields; | ||
4822 | 78 | filter_fields = x.filter_fields; | ||
4823 | 79 | if (dbctx) { | ||
4824 | 80 | dbctx->table_addref(table_id); | ||
4825 | 81 | } | ||
4826 | 82 | } | ||
4827 | 83 | return *this; | ||
4828 | 84 | } | ||
4829 | 85 | |||
4830 | 86 | struct database : public database_i, private noncopyable { | ||
4831 | 87 | database(const config& c); | ||
4832 | 88 | virtual ~database(); | ||
4833 | 89 | virtual dbcontext_ptr create_context(bool for_write) volatile; | ||
4834 | 90 | virtual void stop() volatile; | ||
4835 | 91 | virtual const config& get_conf() const volatile; | ||
4836 | 92 | public: | ||
4837 | 93 | int child_running; | ||
4838 | 94 | private: | ||
4839 | 95 | config conf; | ||
4840 | 96 | }; | ||
4841 | 97 | |||
4842 | 98 | struct tablevec_entry { | ||
4843 | 99 | TABLE *table; | ||
4844 | 100 | size_t refcount; | ||
4845 | 101 | bool modified; | ||
4846 | 102 | tablevec_entry() : table(0), refcount(0), modified(false) { } | ||
4847 | 103 | }; | ||
4848 | 104 | |||
4849 | 105 | struct expr_user_lock : private noncopyable { | ||
4850 | 106 | expr_user_lock(THD *thd, int timeout) | ||
4851 | 107 | : lck_key("handlersocket_wr", 16, &my_charset_latin1), | ||
4852 | 108 | lck_timeout(timeout), | ||
4853 | 109 | lck_func_get_lock(&lck_key, &lck_timeout), | ||
4854 | 110 | lck_func_release_lock(&lck_key) | ||
4855 | 111 | { | ||
4856 | 112 | lck_key.fix_fields(thd, 0); | ||
4857 | 113 | lck_timeout.fix_fields(thd, 0); | ||
4858 | 114 | lck_func_get_lock.fix_fields(thd, 0); | ||
4859 | 115 | lck_func_release_lock.fix_fields(thd, 0); | ||
4860 | 116 | } | ||
4861 | 117 | long long get_lock() { | ||
4862 | 118 | return lck_func_get_lock.val_int(); | ||
4863 | 119 | } | ||
4864 | 120 | long long release_lock() { | ||
4865 | 121 | return lck_func_release_lock.val_int(); | ||
4866 | 122 | } | ||
4867 | 123 | private: | ||
4868 | 124 | Item_string lck_key; | ||
4869 | 125 | Item_int lck_timeout; | ||
4870 | 126 | Item_func_get_lock lck_func_get_lock; | ||
4871 | 127 | Item_func_release_lock lck_func_release_lock; | ||
4872 | 128 | }; | ||
4873 | 129 | |||
4874 | 130 | struct dbcontext : public dbcontext_i, private noncopyable { | ||
4875 | 131 | dbcontext(volatile database *d, bool for_write); | ||
4876 | 132 | virtual ~dbcontext(); | ||
4877 | 133 | virtual void init_thread(const void *stack_botton, | ||
4878 | 134 | volatile int& shutdown_flag); | ||
4879 | 135 | virtual void term_thread(); | ||
4880 | 136 | virtual bool check_alive(); | ||
4881 | 137 | virtual void lock_tables_if(); | ||
4882 | 138 | virtual void unlock_tables_if(); | ||
4883 | 139 | virtual bool get_commit_error(); | ||
4884 | 140 | virtual void clear_error(); | ||
4885 | 141 | virtual void close_tables_if(); | ||
4886 | 142 | virtual void table_addref(size_t tbl_id); | ||
4887 | 143 | virtual void table_release(size_t tbl_id); | ||
4888 | 144 | virtual void cmd_open(dbcallback_i& cb, const cmd_open_args& args); | ||
4889 | 145 | virtual void cmd_exec(dbcallback_i& cb, const cmd_exec_args& args); | ||
4890 | 146 | virtual void set_statistics(size_t num_conns, size_t num_active); | ||
4891 | 147 | private: | ||
4892 | 148 | int set_thread_message(const char *fmt, ...) | ||
4893 | 149 | __attribute__((format (printf, 2, 3))); | ||
4894 | 150 | bool parse_fields(TABLE *const table, const char *str, | ||
4895 | 151 | prep_stmt::fields_type& flds); | ||
4896 | 152 | void cmd_insert_internal(dbcallback_i& cb, const prep_stmt& pst, | ||
4897 | 153 | const string_ref *fvals, size_t fvalslen); | ||
4898 | 154 | void cmd_sql_internal(dbcallback_i& cb, const prep_stmt& pst, | ||
4899 | 155 | const string_ref *fvals, size_t fvalslen); | ||
4900 | 156 | void cmd_find_internal(dbcallback_i& cb, const prep_stmt& pst, | ||
4901 | 157 | ha_rkey_function find_flag, const cmd_exec_args& args); | ||
4902 | 158 | size_t calc_filter_buf_size(TABLE *table, const prep_stmt& pst, | ||
4903 | 159 | const record_filter *filters); | ||
4904 | 160 | bool fill_filter_buf(TABLE *table, const prep_stmt& pst, | ||
4905 | 161 | const record_filter *filters, uchar *filter_buf, size_t len); | ||
4906 | 162 | int check_filter(dbcallback_i& cb, TABLE *table, const prep_stmt& pst, | ||
4907 | 163 | const record_filter *filters, const uchar *filter_buf); | ||
4908 | 164 | void resp_record(dbcallback_i& cb, TABLE *const table, const prep_stmt& pst); | ||
4909 | 165 | void dump_record(dbcallback_i& cb, TABLE *const table, const prep_stmt& pst); | ||
4910 | 166 | int modify_record(dbcallback_i& cb, TABLE *const table, | ||
4911 | 167 | const prep_stmt& pst, const cmd_exec_args& args, char mod_op, | ||
4912 | 168 | size_t& modified_count); | ||
4913 | 169 | private: | ||
4914 | 170 | typedef std::vector<tablevec_entry> table_vec_type; | ||
4915 | 171 | typedef std::pair<std::string, std::string> table_name_type; | ||
4916 | 172 | typedef std::map<table_name_type, size_t> table_map_type; | ||
4917 | 173 | private: | ||
4918 | 174 | volatile database *const dbref; | ||
4919 | 175 | bool for_write_flag; | ||
4920 | 176 | THD *thd; | ||
4921 | 177 | MYSQL_LOCK *lock; | ||
4922 | 178 | bool lock_failed; | ||
4923 | 179 | std::auto_ptr<expr_user_lock> user_lock; | ||
4924 | 180 | int user_level_lock_timeout; | ||
4925 | 181 | bool user_level_lock_locked; | ||
4926 | 182 | bool commit_error; | ||
4927 | 183 | std::vector<char> info_message_buf; | ||
4928 | 184 | table_vec_type table_vec; | ||
4929 | 185 | table_map_type table_map; | ||
4930 | 186 | }; | ||
4931 | 187 | |||
4932 | 188 | database::database(const config& c) | ||
4933 | 189 | : child_running(1), conf(c) | ||
4934 | 190 | { | ||
4935 | 191 | } | ||
4936 | 192 | |||
4937 | 193 | database::~database() | ||
4938 | 194 | { | ||
4939 | 195 | } | ||
4940 | 196 | |||
4941 | 197 | dbcontext_ptr | ||
4942 | 198 | database::create_context(bool for_write) volatile | ||
4943 | 199 | { | ||
4944 | 200 | return dbcontext_ptr(new dbcontext(this, for_write)); | ||
4945 | 201 | } | ||
4946 | 202 | |||
4947 | 203 | void | ||
4948 | 204 | database::stop() volatile | ||
4949 | 205 | { | ||
4950 | 206 | child_running = false; | ||
4951 | 207 | } | ||
4952 | 208 | |||
4953 | 209 | const config& | ||
4954 | 210 | database::get_conf() const volatile | ||
4955 | 211 | { | ||
4956 | 212 | return const_cast<const config&>(conf); | ||
4957 | 213 | } | ||
4958 | 214 | |||
4959 | 215 | database_ptr | ||
4960 | 216 | database_i::create(const config& conf) | ||
4961 | 217 | { | ||
4962 | 218 | return database_ptr(new database(conf)); | ||
4963 | 219 | } | ||
4964 | 220 | |||
4965 | 221 | dbcontext::dbcontext(volatile database *d, bool for_write) | ||
4966 | 222 | : dbref(d), for_write_flag(for_write), thd(0), lock(0), lock_failed(false), | ||
4967 | 223 | user_level_lock_timeout(0), user_level_lock_locked(false), | ||
4968 | 224 | commit_error(false) | ||
4969 | 225 | { | ||
4970 | 226 | info_message_buf.resize(8192); | ||
4971 | 227 | user_level_lock_timeout = d->get_conf().get_int("wrlock_timeout", 12); | ||
4972 | 228 | } | ||
4973 | 229 | |||
4974 | 230 | dbcontext::~dbcontext() | ||
4975 | 231 | { | ||
4976 | 232 | } | ||
4977 | 233 | |||
4978 | 234 | namespace { | ||
4979 | 235 | |||
4980 | 236 | int | ||
4981 | 237 | wait_server_to_start(THD *thd, volatile int& shutdown_flag) | ||
4982 | 238 | { | ||
4983 | 239 | int r = 0; | ||
4984 | 240 | DBG_SHUT(fprintf(stderr, "HNDSOCK wsts\n")); | ||
4985 | 241 | pthread_mutex_lock(&LOCK_server_started); | ||
4986 | 242 | while (!mysqld_server_started) { | ||
4987 | 243 | timespec abstime = { }; | ||
4988 | 244 | set_timespec(abstime, 1); | ||
4989 | 245 | pthread_cond_timedwait(&COND_server_started, &LOCK_server_started, | ||
4990 | 246 | &abstime); | ||
4991 | 247 | pthread_mutex_unlock(&LOCK_server_started); | ||
4992 | 248 | pthread_mutex_lock(&thd->mysys_var->mutex); | ||
4993 | 249 | THD::killed_state st = thd->killed; | ||
4994 | 250 | pthread_mutex_unlock(&thd->mysys_var->mutex); | ||
4995 | 251 | DBG_SHUT(fprintf(stderr, "HNDSOCK wsts kst %d\n", (int)st)); | ||
4996 | 252 | pthread_mutex_lock(&LOCK_server_started); | ||
4997 | 253 | if (st != THD::NOT_KILLED) { | ||
4998 | 254 | DBG_SHUT(fprintf(stderr, "HNDSOCK wsts kst %d break\n", (int)st)); | ||
4999 | 255 | r = -1; | ||
5000 | 256 | break; |
The diff has been truncated for viewing.
You should be merging to release-5.5.12-20.3 rather than lp:percona-server which is a very outdated branch currently. Makes reviewing the diff impossible.