null+****@clear*****
null+****@clear*****
2011年 10月 13日 (木) 16:48:33 JST
Kouhei Sutou 2011-10-13 07:48:33 +0000 (Thu, 13 Oct 2011)
New Revision: bd6f20c601c29240fff9ab8336b6892f752ea566
Log:
[storage] add groonga_dry_write variable to control write data.
Added files:
test/sql/groonga_storage/r/dry_write_delete.result
test/sql/groonga_storage/r/dry_write_insert.result
test/sql/groonga_storage/r/dry_write_update.result
test/sql/groonga_storage/t/dry_write_delete.test
test/sql/groonga_storage/t/dry_write_insert.test
test/sql/groonga_storage/t/dry_write_update.test
Modified files:
ha_mroonga.cc
Modified: ha_mroonga.cc (+45 -1)
===================================================================
--- ha_mroonga.cc 2011-10-12 00:15:44 +0000 (68dbeef)
+++ ha_mroonga.cc 2011-10-13 07:48:33 +0000 (0bcab22)
@@ -128,6 +128,8 @@ FILE *mrn_logfile = NULL;
static bool mrn_logfile_opened = false;
grn_log_level mrn_log_level_default = GRN_LOG_DEFAULT_LEVEL;
ulong mrn_log_level = (ulong) mrn_log_level_default;
+static char mrn_dry_write_default = false;
+static char mrn_dry_write = mrn_dry_write_default;
char mrn_default_parser_name[MRN_MAX_KEY_SIZE];
char *mrn_default_parser;
@@ -259,13 +261,38 @@ static MYSQL_SYSVAR_STR(default_parser, mrn_default_parser,
mrn_default_parser_update,
MRN_PARSER_DEFAULT);
+static void mrn_dry_write_update(THD *thd, struct st_mysql_sys_var *var,
+ void *var_ptr, const void *save)
+{
+ MRN_DBUG_ENTER_FUNCTION();
+ bool new_value = *(bool *)save;
+ bool old_value = mrn_dry_write;
+ mrn_dry_write = new_value;
+ grn_ctx ctx;
+ grn_ctx_init(&ctx, 0);
+ GRN_LOG(&ctx, GRN_LOG_NOTICE, "dry write changed from '%s' to '%s'",
+ old_value ? "true" : "false",
+ new_value ? "true" : "false");
+ grn_ctx_fin(&ctx);
+ DBUG_VOID_RETURN;
+}
+
+ static MYSQL_SYSVAR_BOOL(dry_write, mrn_dry_write,
+ PLUGIN_VAR_RQCMDARG,
+ "If dry_write is true, any write operations are ignored.",
+ NULL,
+ mrn_dry_write_update,
+ mrn_dry_write_default);
+
struct st_mysql_sys_var *mrn_system_variables[] =
{
MYSQL_SYSVAR(log_level),
MYSQL_SYSVAR(default_parser),
+ MYSQL_SYSVAR(dry_write),
NULL
};
+
/* UDF - last_insert_grn_id() */
my_bool last_insert_grn_id_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
@@ -3275,10 +3302,16 @@ err:
int ha_mroonga::storage_write_row(uchar *buf)
{
MRN_DBUG_ENTER_METHOD();
+ int error = 0;
+
+ if (mrn_dry_write) {
+ DBUG_PRINT("info", ("mroonga: dry write: ha_mroonga::%s", __FUNCTION__));
+ DBUG_RETURN(error);
+ }
+
THD *thd = ha_thd();
int i, col_size;
int n_columns = table->s->fields;
- int error = 0;
if (table->next_number_field && buf == table->record[0])
{
@@ -3657,6 +3690,11 @@ int ha_mroonga::storage_update_row(const uchar *old_data, uchar *new_data)
MRN_DBUG_ENTER_METHOD();
int error = 0;
+ if (mrn_dry_write) {
+ DBUG_PRINT("info", ("mroonga: dry write: ha_mroonga::%s", __FUNCTION__));
+ DBUG_RETURN(error);
+ }
+
grn_obj colbuf;
int i, col_size;
int n_columns = table->s->fields;
@@ -3947,6 +3985,12 @@ int ha_mroonga::storage_delete_row(const uchar *buf)
{
MRN_DBUG_ENTER_METHOD();
int error = 0;
+
+ if (mrn_dry_write) {
+ DBUG_PRINT("info", ("mroonga: dry write: ha_mroonga::%s", __FUNCTION__));
+ DBUG_RETURN(error);
+ }
+
grn_table_delete_by_id(ctx, grn_table, record_id);
if (ctx->rc) {
my_message(ER_ERROR_ON_WRITE, ctx->errbuf, MYF(0));
Added: test/sql/groonga_storage/r/dry_write_delete.result (+28 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_storage/r/dry_write_delete.result 2011-10-13 07:48:33 +0000 (38824ac)
@@ -0,0 +1,28 @@
+drop table if exists diaries;
+create table diaries (
+id int primary key auto_increment,
+body text,
+fulltext index body_index (body)
+) default charset utf8;
+show create table diaries;
+Table Create Table
+diaries CREATE TABLE `diaries` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `body` text,
+ PRIMARY KEY (`id`),
+ FULLTEXT KEY `body_index` (`body`)
+) ENGINE=groonga DEFAULT CHARSET=utf8
+insert into diaries (body) values ("will start groonga!");
+select * from diaries;
+id body
+1 will start groonga!
+set global groonga_dry_write=true;
+delete from diaries where id = 1;
+select * from diaries;
+id body
+1 will start groonga!
+set global groonga_dry_write=false;
+delete from diaries where id = 1;
+select * from diaries;
+id body
+drop table diaries;
Added: test/sql/groonga_storage/r/dry_write_insert.result (+30 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_storage/r/dry_write_insert.result 2011-10-13 07:48:33 +0000 (b0ba24f)
@@ -0,0 +1,30 @@
+drop table if exists diaries;
+create table diaries (
+id int primary key auto_increment,
+body text,
+fulltext index body_index (body)
+) default charset utf8;
+show create table diaries;
+Table Create Table
+diaries CREATE TABLE `diaries` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `body` text,
+ PRIMARY KEY (`id`),
+ FULLTEXT KEY `body_index` (`body`)
+) ENGINE=groonga DEFAULT CHARSET=utf8
+insert into diaries (body) values ("will start groonga!");
+select * from diaries;
+id body
+1 will start groonga!
+set global groonga_dry_write=true;
+insert into diaries (body) values ("starting groonga...");
+select * from diaries;
+id body
+1 will start groonga!
+set global groonga_dry_write=false;
+insert into diaries (body) values ("started groonga.");
+select * from diaries;
+id body
+1 will start groonga!
+2 started groonga.
+drop table diaries;
Added: test/sql/groonga_storage/r/dry_write_update.result (+26 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_storage/r/dry_write_update.result 2011-10-13 07:48:33 +0000 (4f6881a)
@@ -0,0 +1,26 @@
+drop table if exists diaries;
+create table diaries (
+id int primary key auto_increment,
+body text,
+fulltext index body_index (body)
+) default charset utf8;
+show create table diaries;
+Table Create Table
+diaries CREATE TABLE `diaries` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `body` text,
+ PRIMARY KEY (`id`),
+ FULLTEXT KEY `body_index` (`body`)
+) ENGINE=groonga DEFAULT CHARSET=utf8
+insert into diaries (body) values ("will start groonga!");
+set global groonga_dry_write=true;
+update diaries set body = "starting groonga..." where id = 1;
+select * from diaries;
+id body
+1 will start groonga!
+set global groonga_dry_write=false;
+update diaries set body = "starting groonga..." where id = 1;
+select * from diaries;
+id body
+1 starting groonga...
+drop table diaries;
Added: test/sql/groonga_storage/t/dry_write_delete.test (+39 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_storage/t/dry_write_delete.test 2011-10-13 07:48:33 +0000 (9f45bd8)
@@ -0,0 +1,39 @@
+# Copyright(C) 2011 Kouhei Sutou <kou****@clear*****>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+--source suite/groonga_include/groonga_init.inc
+
+--disable_warnings
+drop table if exists diaries;
+--enable_warnings
+
+create table diaries (
+ id int primary key auto_increment,
+ body text,
+ fulltext index body_index (body)
+) default charset utf8;
+show create table diaries;
+insert into diaries (body) values ("will start groonga!");
+select * from diaries;
+set global groonga_dry_write=true;
+delete from diaries where id = 1;
+select * from diaries;
+set global groonga_dry_write=false;
+delete from diaries where id = 1;
+select * from diaries;
+drop table diaries;
+
+--source suite/groonga_include/groonga_deinit.inc
Added: test/sql/groonga_storage/t/dry_write_insert.test (+39 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_storage/t/dry_write_insert.test 2011-10-13 07:48:33 +0000 (e17d590)
@@ -0,0 +1,39 @@
+# Copyright(C) 2011 Kouhei Sutou <kou****@clear*****>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+--source suite/groonga_include/groonga_init.inc
+
+--disable_warnings
+drop table if exists diaries;
+--enable_warnings
+
+create table diaries (
+ id int primary key auto_increment,
+ body text,
+ fulltext index body_index (body)
+) default charset utf8;
+show create table diaries;
+insert into diaries (body) values ("will start groonga!");
+select * from diaries;
+set global groonga_dry_write=true;
+insert into diaries (body) values ("starting groonga...");
+select * from diaries;
+set global groonga_dry_write=false;
+insert into diaries (body) values ("started groonga.");
+select * from diaries;
+drop table diaries;
+
+--source suite/groonga_include/groonga_deinit.inc
Added: test/sql/groonga_storage/t/dry_write_update.test (+38 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_storage/t/dry_write_update.test 2011-10-13 07:48:33 +0000 (7a1a6a2)
@@ -0,0 +1,38 @@
+# Copyright(C) 2011 Kouhei Sutou <kou****@clear*****>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+--source suite/groonga_include/groonga_init.inc
+
+--disable_warnings
+drop table if exists diaries;
+--enable_warnings
+
+create table diaries (
+ id int primary key auto_increment,
+ body text,
+ fulltext index body_index (body)
+) default charset utf8;
+show create table diaries;
+insert into diaries (body) values ("will start groonga!");
+set global groonga_dry_write=true;
+update diaries set body = "starting groonga..." where id = 1;
+select * from diaries;
+set global groonga_dry_write=false;
+update diaries set body = "starting groonga..." where id = 1;
+select * from diaries;
+drop table diaries;
+
+--source suite/groonga_include/groonga_deinit.inc