Commit 7202c21b authored by Michael Widenius's avatar Michael Widenius

Merge of patch lp:~ahiguti100/maria/handlersocket-fix-78 by Akira Higuchi

A bugfix of HandlerSocket is not applied to mariadb yet
parent 53d44ad1
...@@ -66,7 +66,7 @@ Here is a list of other language bindings: ...@@ -66,7 +66,7 @@ Here is a list of other language bindings:
https://github.com/koichik/node-handlersocket https://github.com/koichik/node-handlersocket
The home of HandlerSocket is here: The home of HandlerSocket is here:
https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL https://github.com/DeNADev/HandlerSocket-Plugin-for-MySQL
More documents are available in docs-en/ and docs-ja/ directories. More documents are available in docs-en/ and docs-ja/ directories.
...@@ -17,10 +17,11 @@ crash, etc). ...@@ -17,10 +17,11 @@ crash, etc).
$ ./autogen.sh $ ./autogen.sh
$ ./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 $ ./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
--with-mysql-source refers to the top of MySQL source directory, --with-mysql-source refers to the top of MySQL source directory (which
--with-mysql-bindir refers to where MySQL binary executables (i.e. contains the VERSION file or the configure.in file), --with-mysql-bindir
mysql_config) are located, and --with-mysql-plugindir refers to a plugin refers to where MySQL binary executables (i.e. mysql_config) are located,
directory where plugin libraries (*.so) are installed. and --with-mysql-plugindir refers to a plugin directory where plugin
libraries (*.so) are installed.
$ make $ make
$ sudo make install $ sudo make install
......
...@@ -93,7 +93,6 @@ The execute_single method can be used for inserting records also. ...@@ -93,7 +93,6 @@ The execute_single method can be used for inserting records also.
my $res = $hs->execute_single(3, '+', [ 'foo', 'bar', 'baz' ]); my $res = $hs->execute_single(3, '+', [ 'foo', 'bar', 'baz' ]);
die $hs->get_error() if $res->[0] != 0; die $hs->get_error() if $res->[0] != 0;
my $num_inserted_rows = $res->[1];
The 3rd argument must be an arrayref whose elements correspond to The 3rd argument must be an arrayref whose elements correspond to
the 5th argument for the corresponding open_index call. If there the 5th argument for the corresponding open_index call. If there
...@@ -116,6 +115,15 @@ executing them separatedly. ...@@ -116,6 +115,15 @@ executing them separatedly.
# ... # ...
} }
-----------------------------------------------------------------
If handlersocket is configured to authenticate client connections
(ie., handlersocket_plain_secret or handlersocket_plain_secret_wr
is set), a client must call 'auth' method before any other
methods.
my $res = $hs->auth('password');
die $hs->get_error() if $res->[0] != 0;
----------------------------------------------------------------- -----------------------------------------------------------------
When an error is occured, the first element of the returned When an error is occured, the first element of the returned
arrayref becomes a non-zero value. A negative value indicates arrayref becomes a non-zero value. A negative value indicates
......
...@@ -29,7 +29,7 @@ Request and Response ...@@ -29,7 +29,7 @@ Request and Response
lines) at one time, and receive responses for them at one time. lines) at one time, and receive responses for them at one time.
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
'open_index' request Opening index
The 'open_index' request has the following syntax. The 'open_index' request has the following syntax.
...@@ -74,23 +74,21 @@ FILETER is a sequence of the following parameters. ...@@ -74,23 +74,21 @@ FILETER is a sequence of the following parameters.
HandlerSocket supports '=', '>', '>=', '<', and '<='. HandlerSocket supports '=', '>', '>=', '<', and '<='.
- <vlen> indicates the length of the trailing parameters <v1> ... <vn>. This - <vlen> indicates the length of the trailing parameters <v1> ... <vn>. This
must be smaller than or equal to the number of index columns specified by must be smaller than or equal to the number of index columns specified by
the <columns> parameter of the corresponding 'open_index' request. the <indexname> parameter of the corresponding 'open_index' request.
- <v1> ... <vn> specify the index column values to fetch. - <v1> ... <vn> specify the index column values to fetch.
- LIM is optional. <limit> and <offset> are numbers. When omitted, it works - LIM is optional. <limit> and <offset> are numbers. When omitted, it works
as if 1 and 0 are specified. These parameter works like LIMIT of SQL. as if 1 and 0 are specified. These parameter works like LIMIT of SQL.
These values don't include the number of records skipped by a filter. These values don't include the number of records skipped by a filter.
- IN is optional. It works like WHERE ... IN syntax of SQL. <icol> must be - IN is optional. It works like WHERE ... IN syntax of SQL. <icol> must be
smaller than or equal to the number of index columns specified by the smaller than the number of index columns specified by the <indexname>
<columns> parameter of the corresponding 'open_index' request. If IN is parameter of the corresponding 'open_index' request. If IN is specified in
specified in a find request, the <icol>-th parameter value of <v1> ... a find request, the <icol>-th parameter value of <v1> ... <vn> is ignored.
<vn> is ignored.
smaller than or equal to the number of index columns specified by the
- FILTERs are optional. A FILTER specifies a filter. <ftyp> is either 'F' - FILTERs are optional. A FILTER specifies a filter. <ftyp> is either 'F'
(filter) or 'W' (while). <fop> specifies the comparison operation to use. (filter) or 'W' (while). <fop> specifies the comparison operation to use.
<fcol> must be smaller than or equal to the number of columns specified by <fcol> must be smaller than the number of columns specified by the
the <fcolumns> parameter of the corresponding 'open_index' request. <fcolumns> parameter of the corresponding 'open_index' request. Multiple
Multiple filters can be specified, and work as the logical AND of them. filters can be specified, and work as the logical AND of them. The
The difference of 'F' and 'W' is that, when a record does not meet the difference of 'F' and 'W' is that, when a record does not meet the
specified condition, 'F' simply skips the record, and 'W' stops the loop. specified condition, 'F' simply skips the record, and 'W' stops the loop.
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
...@@ -112,8 +110,8 @@ MOD is a sequence of the following parameters. ...@@ -112,8 +110,8 @@ MOD is a sequence of the following parameters.
<mk> must be smaller than or equal to the length of <columns> specified by <mk> must be smaller than or equal to the length of <columns> specified by
the corresponding 'open_index' request. If <mop> is 'D', these parameters the corresponding 'open_index' request. If <mop> is 'D', these parameters
are ignored. If <mop> is '+' or '-', values must be numeric. If <mop> is are ignored. If <mop> is '+' or '-', values must be numeric. If <mop> is
'-' and it attempts to change column values from negative to positive or '-' and it attempts to change a column value from negative to positive or
positive to negative, it is not modified. positive to negative, the column value is not modified.
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
Inserting data Inserting data
...@@ -187,6 +185,8 @@ syntax. ...@@ -187,6 +185,8 @@ syntax.
0 1 <nummod> 0 1 <nummod>
- <nummod> is the number of modified rows. - <nummod> is the number of modified rows.
- As an exception, if the '?' suffix is specified in <mop>, a response has
the syntax of a response for 'find' instead.
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
Response for 'insert' Response for 'insert'
...@@ -196,3 +196,10 @@ syntax. ...@@ -196,3 +196,10 @@ syntax.
0 1 0 1
----------------------------------------------------------------------------
Response for 'auth'
If 'auth' is succeeded, HanderSocket returns a line of the following syntax.
0 1
...@@ -8,7 +8,8 @@ HandlerSocketプラグインのビルド方法(RPMを使わない方法) ...@@ -8,7 +8,8 @@ HandlerSocketプラグインのビルド方法(RPMを使わない方法)
$ ./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 $ ./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
ここで--with-mysql-sourceにはMySQLのソースコードのトップディレク ここで--with-mysql-sourceにはMySQLのソースコードのトップディレク
トリを指定します。--with-mysql-bindirにはインストール済みのMySQL トリを指定します(そこにVERSIONファイルかconfigure.inファイルがなく
てはなりません)。--with-mysql-bindirにはインストール済みのMySQL
のmysql_configコマンドが有るディレクトリを指定します。 のmysql_configコマンドが有るディレクトリを指定します。
その後以下のようにビルド・インストールします。 その後以下のようにビルド・インストールします。
......
...@@ -86,7 +86,6 @@ execute_singleメソッドは列の挿入にも使用できます。 ...@@ -86,7 +86,6 @@ execute_singleメソッドは列の挿入にも使用できます。
my $res = $hs->execute_single(3, '+', [ 'foo', 'bar', 'baz' ]); my $res = $hs->execute_single(3, '+', [ 'foo', 'bar', 'baz' ]);
die $hs->get_error() if $res->[0] != 0; die $hs->get_error() if $res->[0] != 0;
my $num_inserted_rows = $res->[1];
第3引数は、対応するopen_index呼び出しの第5引数の列リストと同じだ 第3引数は、対応するopen_index呼び出しの第5引数の列リストと同じだ
けの長さの配列への参照でなければなりません。open_index呼び出しの けの長さの配列への参照でなければなりません。open_index呼び出しの
...@@ -109,6 +108,15 @@ execute_multiメソッドを使えば、複数のリクエストを一つの呼 ...@@ -109,6 +108,15 @@ execute_multiメソッドを使えば、複数のリクエストを一つの呼
# ... # ...
} }
-----------------------------------------------------------------
もしhandlersocketが接続を認証するように設定されている
(handlersocket_plain_secret又はhandlersocket_plain_secret_wrがセッ
トされている)ならば、クライアントは他のメソッド呼び出しの前にauth
メソッドを呼び出す必要があります。
my $res = $hs->auth('password');
die $hs->get_error() if $res->[0] != 0;
----------------------------------------------------------------- -----------------------------------------------------------------
エラーが起こると返値の配列参照の最初の要素が0以外になります。負の エラーが起こると返値の配列参照の最初の要素が0以外になります。負の
数の場合はI/Oエラーが起こったことを示し、その場合はその 数の場合はI/Oエラーが起こったことを示し、その場合はその
......
...@@ -658,7 +658,7 @@ dbcontext::cmd_insert_internal(dbcallback_i& cb, const prep_stmt& pst, ...@@ -658,7 +658,7 @@ dbcontext::cmd_insert_internal(dbcallback_i& cb, const prep_stmt& pst,
empty_record(table); empty_record(table);
memset(buf, 0, table->s->null_bytes); /* clear null flags */ memset(buf, 0, table->s->null_bytes); /* clear null flags */
const prep_stmt::fields_type& rf = pst.get_ret_fields(); const prep_stmt::fields_type& rf = pst.get_ret_fields();
const size_t n = rf.size(); const size_t n = std::min(rf.size(), fvalslen);
for (size_t i = 0; i < n; ++i) { for (size_t i = 0; i < n; ++i) {
uint32_t fn = rf[i]; uint32_t fn = rf[i];
Field *const fld = table->field[fn]; Field *const fld = table->field[fn];
......
...@@ -151,7 +151,7 @@ sv_get_string_ref(SV *sv) ...@@ -151,7 +151,7 @@ sv_get_string_ref(SV *sv)
static IV static IV
sv_get_iv(SV *sv) sv_get_iv(SV *sv)
{ {
if (sv == 0 || !SvIOK(sv)) { if (sv == 0 || ( !SvIOK(sv) && !SvPOK(sv) ) ) {
return 0; return 0;
} }
return SvIV(sv); return SvIV(sv);
......
#!/bin/bash #!/bin/bash
TESTS="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23"; TESTS="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24";
source ../common/compat.sh source ../common/compat.sh
......
...@@ -27,7 +27,7 @@ srand(999); ...@@ -27,7 +27,7 @@ srand(999);
my %valmap = (); my %valmap = ();
my $sth = $dbh->prepare("insert into $table values (?,?,?)"); my $sth = $dbh->prepare("insert ignore into $table values (?,?,?)");
for (my $i = 0; $i < $tablesize; ++$i) { for (my $i = 0; $i < $tablesize; ++$i) {
my $k = $i; my $k = $i;
my ($s1, $s2) = ("", ""); my ($s1, $s2) = ("", "");
......
...@@ -60,7 +60,7 @@ sub test_one { ...@@ -60,7 +60,7 @@ sub test_one {
$dbh->do( $dbh->do(
"create table $table (" . "create table $table (" .
"k $typ, " . "k $typ, " .
"v1 varchar(2047), " . "v1 varchar(1000), " .
"v2 $typ, " . "v2 $typ, " .
"primary key(k$keylen_str), " . "primary key(k$keylen_str), " .
"index i1(v1), index i2(v2$keylen_str, v1(300))) " . "index i1(v1), index i2(v2$keylen_str, v1(300))) " .
......
...@@ -113,7 +113,7 @@ sub test_one { ...@@ -113,7 +113,7 @@ sub test_one {
"(k1 int not null, k2 int not null, " . "(k1 int not null, k2 int not null, " .
"v1 int not null, v2 $typ default null, " . "v1 int not null, v2 $typ default null, " .
"primary key (k1, k2) ) engine = innodb"); "primary key (k1, k2) ) engine = innodb");
my $sth = $dbh->prepare("insert into $table values (?,?,?,?)"); my $sth = $dbh->prepare("insert ignore into $table values (?,?,?,?)");
for (my $i = 0; $i < $tablesize; ++$i) { for (my $i = 0; $i < $tablesize; ++$i) {
my $j = 0; my $j = 0;
for my $v (@$values) { for my $v (@$values) {
......
#!/usr/bin/perl
# vim:sw=2:ai
# test for issue #78
BEGIN {
push @INC, "../common/";
};
use strict;
use warnings;
use hstest;
my $dbh = hstest::init_testdb();
my $table = 'hstesttbl';
my $tablesize = 100;
$dbh->do(
"create table $table (" .
"id bigint(20) not null auto_increment, " .
"t1 timestamp not null default current_timestamp, " .
"primary key (id)" .
") engine = innodb");
srand(999);
my %valmap = ();
my $hs = hstest::get_hs_connection(undef, 9999);
my $dbname = $hstest::conf{dbname};
$hs->open_index(0, $dbname, $table, 'PRIMARY', 'id,t1');
my $res = $hs->execute_single(0, '+', [ 321 ], 0, 0);
die $hs->get_error() if $res->[0] != 0;
print "HS\n";
print join(' ', @$res) . "\n";
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment