Navigation Menu

Skip to content

Commit

Permalink
Support recording operations
Browse files Browse the repository at this point in the history
It will be able to used for crash detection.
  • Loading branch information
kou committed Oct 18, 2015
1 parent 8536f66 commit c8e881c
Show file tree
Hide file tree
Showing 26 changed files with 150 additions and 7 deletions.
19 changes: 19 additions & 0 deletions ha_mroonga.cpp
Expand Up @@ -95,6 +95,7 @@
#include <mrn_grn.hpp>
#include <mrn_value_decoder.hpp>
#include <mrn_database_repairer.hpp>
#include <mrn_operation.hpp>

#ifdef MRN_SUPPORT_FOREIGN_KEYS
# include <sql_table.h>
Expand Down Expand Up @@ -2368,12 +2369,18 @@ ha_mroonga::ha_mroonga(handlerton *hton, TABLE_SHARE *share_arg)
GRN_TEXT_INIT(&encoded_key_buffer, 0);
GRN_VOID_INIT(&old_value_buffer);
GRN_VOID_INIT(&new_value_buffer);

storage_.operations_ = NULL;

DBUG_VOID_RETURN;
}

ha_mroonga::~ha_mroonga()
{
MRN_DBUG_ENTER_METHOD();

delete storage_.operations_;

if (analyzed_for_create) {
if (wrap_handler_for_create) {
delete wrap_handler_for_create;
Expand Down Expand Up @@ -3919,6 +3926,9 @@ int ha_mroonga::ensure_database_open(const char *name)

grn_ctx_use(ctx, db);

delete storage_.operations_;
storage_.operations_ = new mrn::Operations(ctx);

DBUG_RETURN(error);
}

Expand All @@ -3932,6 +3942,9 @@ int ha_mroonga::ensure_database_remove(const char *name)
if (error)
DBUG_RETURN(error);

delete storage_.operations_;
storage_.operations_ = NULL;

mrn_db_manager->close(name);

mrn::PathMapper mapper(name);
Expand Down Expand Up @@ -5413,6 +5426,11 @@ int ha_mroonga::storage_write_row(uchar *buf)
DBUG_RETURN(error);
}

mrn::Operation operation(storage_.operations_,
"write",
table->s->table_name.str,
table->s->table_name.length);

THD *thd = ha_thd();
int i;
int n_columns = table->s->fields;
Expand Down Expand Up @@ -5514,6 +5532,7 @@ int ha_mroonga::storage_write_row(uchar *buf)
}
DBUG_RETURN(error);
}
operation.record_target(record_id);
}

grn_obj colbuf;
Expand Down
5 changes: 5 additions & 0 deletions ha_mroonga.hpp
Expand Up @@ -32,6 +32,7 @@ extern "C" {

#include <groonga.h>
#include "mrn_mysql_compat.h"
#include <mrn_operations.hpp>

#if (MYSQL_VERSION_ID >= 50514 && MYSQL_VERSION_ID < 50600)
# define MRN_HANDLER_HAVE_FINAL_ADD_INDEX 1
Expand Down Expand Up @@ -347,6 +348,10 @@ class ha_mroonga: public handler
// for ft in where clause test
Item_func_match *current_ft_item;

struct {
mrn::Operations *operations_;
} storage_;

public:
ha_mroonga(handlerton *hton, TABLE_SHARE *share_arg);
~ha_mroonga();
Expand Down
6 changes: 5 additions & 1 deletion lib/libmrn_need_mysql_sources.am
Expand Up @@ -30,4 +30,8 @@ libmrn_need_mysql_la_SOURCES = \
mrn_database_repairer.cpp \
mrn_database_repairer.hpp \
mrn_context_pool.cpp \
mrn_context_pool.hpp
mrn_context_pool.hpp \
mrn_operations.cpp \
mrn_operations.hpp \
mrn_operation.cpp \
mrn_operation.hpp
Expand Up @@ -4,6 +4,11 @@ id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
ALTER TABLE tags ADD COLUMN name VARCHAR(64) COMMENT 'flags "COLUMN_VECTOR"';
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create tags TABLE_PAT_KEY UInt32
column_create tags id COLUMN_SCALAR UInt32
column_create tags name COLUMN_VECTOR ShortText
Expand Down
Expand Up @@ -7,6 +7,11 @@ id INT UNSIGNED PRIMARY KEY
ALTER TABLE bugs ADD COLUMN name VARCHAR(64) COMMENT 'groonga_type "tags"';
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create tags TABLE_PAT_KEY UInt32
column_create tags id COLUMN_SCALAR UInt32

Expand Down
Expand Up @@ -7,6 +7,11 @@ id INT UNSIGNED PRIMARY KEY
ALTER TABLE bugs ADD COLUMN name VARCHAR(64) COMMENT 'type "tags"';
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create tags TABLE_PAT_KEY UInt32
column_create tags id COLUMN_SCALAR UInt32

Expand Down
Expand Up @@ -8,6 +8,11 @@ content VARCHAR(64) NOT NULL
ALTER TABLE memos ADD FULLTEXT INDEX (content) COMMENT 'token_filters "TokenFilterStopWord"';
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create memos TABLE_NO_KEY
column_create memos content COLUMN_SCALAR ShortText

Expand Down
Expand Up @@ -10,6 +10,11 @@ FULLTEXT INDEX content_index (content) COMMENT 'table "terms"'
) DEFAULT CHARSET=utf8;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
column_create terms term COLUMN_SCALAR ShortText

Expand All @@ -21,6 +26,11 @@ column_create terms content_index COLUMN_INDEX|WITH_POSITION memos content
ALTER TABLE memos DISABLE KEYS;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
column_create terms term COLUMN_SCALAR ShortText

Expand Down
Expand Up @@ -11,6 +11,11 @@ FULLTEXT INDEX content_index (content) COMMENT 'table "terms"'
ALTER TABLE memos DISABLE KEYS;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
column_create terms term COLUMN_SCALAR ShortText

Expand All @@ -20,6 +25,11 @@ column_create memos id COLUMN_SCALAR Int32
ALTER TABLE memos ENABLE KEYS;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
column_create terms term COLUMN_SCALAR ShortText

Expand Down
Expand Up @@ -12,6 +12,11 @@ FULLTEXT INDEX (content) COMMENT 'table "terms"'
) DEFAULT CHARSET=utf8;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerMySQLGeneralCI
column_create terms is_stop_word COLUMN_SCALAR Int8
column_create terms term COLUMN_SCALAR ShortText
Expand All @@ -24,6 +29,11 @@ column_create terms content COLUMN_INDEX|WITH_POSITION memos content
ALTER TABLE terms COMMENT='default_tokenizer "TokenBigram", token_filters "TokenFilterStopWord"';
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create memos TABLE_PAT_KEY Int32
column_create memos content COLUMN_SCALAR LongText
column_create memos id COLUMN_SCALAR Int32
Expand All @@ -35,6 +45,11 @@ ALTER TABLE memos DISABLE KEYS;
ALTER TABLE memos ENABLE KEYS;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create memos TABLE_PAT_KEY Int32
column_create memos content COLUMN_SCALAR LongText
column_create memos id COLUMN_SCALAR Int32
Expand Down
Expand Up @@ -14,6 +14,11 @@ FULLTEXT INDEX bugs_tags_index (tags) COMMENT 'table "tags"'
INSERT INTO bugs (id, tags) VALUES (1, "Linux MySQL groonga");
SELECT mroonga_command("dump --dump_plugins no --dump_records no");
mroonga_command("dump --dump_plugins no --dump_records no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create tags TABLE_PAT_KEY ShortText --default_tokenizer TokenDelimit
column_create tags name COLUMN_SCALAR ShortText

Expand Down
Expand Up @@ -15,6 +15,11 @@ INSERT INTO bugs (id, priority) VALUES (2, 3);
INSERT INTO bugs (id, priority) VALUES (3, -2);
SELECT mroonga_command("dump --dump_plugins no --dump_records no");
mroonga_command("dump --dump_plugins no --dump_records no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create priorities TABLE_PAT_KEY Int32
column_create priorities id COLUMN_SCALAR Int32

Expand Down
Expand Up @@ -4,6 +4,11 @@ tags TEXT COMMENT 'flags "COLUMN_VECTOR"'
) DEFAULT CHARSET=utf8;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create bugs TABLE_PAT_KEY UInt32
column_create bugs id COLUMN_SCALAR UInt32
column_create bugs tags COLUMN_VECTOR LongText
Expand Down
Expand Up @@ -7,6 +7,11 @@ tag VARCHAR(64) COMMENT 'groonga_type "tags"'
) DEFAULT CHARSET=utf8;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create tags TABLE_PAT_KEY ShortText
column_create tags name COLUMN_SCALAR ShortText

Expand Down
Expand Up @@ -7,6 +7,11 @@ tag VARCHAR(64) COMMENT 'type "tags"'
) DEFAULT CHARSET=utf8;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create tags TABLE_PAT_KEY ShortText
column_create tags name COLUMN_SCALAR ShortText

Expand Down
Expand Up @@ -8,6 +8,11 @@ FULLTEXT INDEX (content) COMMENT 'token_filters "TokenFilterStopWord,TokenFilter
) DEFAULT CHARSET=utf8;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create memos TABLE_NO_KEY
column_create memos content COLUMN_SCALAR ShortText

Expand Down
Expand Up @@ -8,6 +8,11 @@ FULLTEXT INDEX (content) COMMENT 'token_filters "TokenFilterStopWord"'
) DEFAULT CHARSET=utf8;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create memos TABLE_NO_KEY
column_create memos content COLUMN_SCALAR ShortText

Expand Down
Expand Up @@ -5,6 +5,11 @@ COLLATE=utf8_bin
COMMENT='default_tokenizer "TokenDelimit"';
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create tags TABLE_PAT_KEY ShortText --default_tokenizer TokenDelimit
column_create tags name COLUMN_SCALAR ShortText
DROP TABLE tags;
Expand Up @@ -12,6 +12,11 @@ FULLTEXT INDEX (content) COMMENT 'table "terms"'
) DEFAULT CHARSET=utf8;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerMySQLGeneralCI --token_filters TokenFilterStopWord,TokenFilterStopWord
column_create terms is_stop_word COLUMN_SCALAR Int8
column_create terms term COLUMN_SCALAR ShortText
Expand Down
Expand Up @@ -12,6 +12,11 @@ FULLTEXT INDEX (content) COMMENT 'table "terms"'
) DEFAULT CHARSET=utf8;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerMySQLGeneralCI --token_filters TokenFilterStopWord
column_create terms is_stop_word COLUMN_SCALAR Int8
column_create terms term COLUMN_SCALAR ShortText
Expand Down
Expand Up @@ -23,7 +23,7 @@ id title body
2 Groonga (1) starting Groonga...
FLUSH TABLES;
SELECT * FROM diaries WHERE MATCH(body) AGAINST("+starting" IN BOOLEAN MODE);
ERROR HY000: syscall error 'repair_test.mrn.000010A.c' (No such file or directory)
ERROR HY000: syscall error 'repair_test.mrn.000010E.c' (No such file or directory)
REPAIR TABLE diaries;
Table Op Msg_type Msg_text
repair_test.diaries repair status OK
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/mroonga/storage/repair_table/t/no_index_file.test
Expand Up @@ -35,11 +35,11 @@ INSERT INTO diaries (title, body) VALUES ("Groonga (2)", "started Groonga.");

SELECT * FROM diaries WHERE MATCH(body) AGAINST("+starting" IN BOOLEAN MODE);

--remove_file $MYSQLD_DATADIR/repair_test.mrn.000010A.c
--remove_file $MYSQLD_DATADIR/repair_test.mrn.000010E.c

FLUSH TABLES;

# Error ER_CANT_OPEN_FILE syscall error 'repair_test.mrn.000010A.c' (No such file or directory)
# Error ER_CANT_OPEN_FILE syscall error 'repair_test.mrn.000010E.c' (No such file or directory)
--error ER_CANT_OPEN_FILE
SELECT * FROM diaries WHERE MATCH(body) AGAINST("+starting" IN BOOLEAN MODE);

Expand Down
Expand Up @@ -9,6 +9,11 @@ FULLTEXT INDEX (content) COMMENT 'token_filters "TokenFilterStopWord,TokenFilter
) COMMENT='engine "InnoDB"' DEFAULT CHARSET=utf8;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create memos TABLE_HASH_KEY ShortText

table_create memos-content TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerMySQLGeneralCI --token_filters TokenFilterStopWord,TokenFilterStopWord
Expand Down
Expand Up @@ -9,6 +9,11 @@ FULLTEXT INDEX (content) COMMENT 'token_filters "TokenFilterStopWord"'
) COMMENT='engine "InnoDB"' DEFAULT CHARSET=utf8;
SELECT mroonga_command("dump --dump_plugins no");
mroonga_command("dump --dump_plugins no")
table_create mrn_operations TABLE_NO_KEY
column_create mrn_operations record COLUMN_SCALAR UInt32
column_create mrn_operations table COLUMN_SCALAR ShortText
column_create mrn_operations type COLUMN_SCALAR ShortText

table_create memos TABLE_HASH_KEY ShortText

table_create memos-content TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerMySQLGeneralCI --token_filters TokenFilterStopWord
Expand Down

0 comments on commit c8e881c

Please sign in to comment.