diff options
author | Jan Lindström <jan.lindstrom@mariadb.com> | 2015-06-24 07:16:08 +0300 |
---|---|---|
committer | Jan Lindström <jan.lindstrom@mariadb.com> | 2015-06-24 07:16:08 +0300 |
commit | 2e4984c185ddcd2da789017cd147338846ff409a (patch) | |
tree | 0293831900c860600efbaa747ea886d9d1cbf5bd /storage/mroonga/lib | |
parent | 792b53e80806df893ee62c9a1c1bd117114c8c6d (diff) | |
parent | a6087e7dc1ef3561d8189c8db15e9591d0f9b520 (diff) | |
download | mariadb-git-2e4984c185ddcd2da789017cd147338846ff409a.tar.gz |
Merge tag 'mariadb-10.0.20' into 10.0-FusionIO10.0-FusionIO
Conflicts:
storage/innobase/os/os0file.cc
storage/xtradb/os/os0file.cc
storage/xtradb/srv/srv0start.cc
Diffstat (limited to 'storage/mroonga/lib')
-rw-r--r-- | storage/mroonga/lib/libmrn_need_mysql_sources.am | 6 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_condition_converter.hpp | 2 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_database_manager.cpp | 44 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_database_manager.hpp | 5 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_database_repairer.cpp | 246 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_database_repairer.hpp | 58 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_encoding.cpp | 1 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_field_normalizer.cpp | 7 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_lock.cpp | 6 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_lock.hpp | 4 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_multiple_column_key_codec.cpp | 9 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_parameters_parser.cpp | 11 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_path_mapper.cpp | 97 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_path_mapper.hpp | 8 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_value_decoder.cpp | 64 | ||||
-rw-r--r-- | storage/mroonga/lib/mrn_value_decoder.hpp | 33 |
16 files changed, 521 insertions, 80 deletions
diff --git a/storage/mroonga/lib/libmrn_need_mysql_sources.am b/storage/mroonga/lib/libmrn_need_mysql_sources.am index bd852829467..575f38adbd1 100644 --- a/storage/mroonga/lib/libmrn_need_mysql_sources.am +++ b/storage/mroonga/lib/libmrn_need_mysql_sources.am @@ -24,4 +24,8 @@ libmrn_need_mysql_la_SOURCES = \ mrn_time_converter.cpp \ mrn_time_converter.hpp \ mrn_database_manager.cpp \ - mrn_database_manager.hpp + mrn_database_manager.hpp \ + mrn_value_decoder.cpp \ + mrn_value_decoder.hpp \ + mrn_database_repairer.cpp \ + mrn_database_repairer.hpp diff --git a/storage/mroonga/lib/mrn_condition_converter.hpp b/storage/mroonga/lib/mrn_condition_converter.hpp index 3cf97c62bbe..bb85f5cdef5 100644 --- a/storage/mroonga/lib/mrn_condition_converter.hpp +++ b/storage/mroonga/lib/mrn_condition_converter.hpp @@ -23,6 +23,8 @@ #include <groonga.h> #include <mrn_mysql_compat.h> +#include <item_cmpfunc.h> + namespace mrn { class ConditionConverter { public: diff --git a/storage/mroonga/lib/mrn_database_manager.cpp b/storage/mroonga/lib/mrn_database_manager.cpp index 52ec78fccc0..365f47337fa 100644 --- a/storage/mroonga/lib/mrn_database_manager.cpp +++ b/storage/mroonga/lib/mrn_database_manager.cpp @@ -26,6 +26,8 @@ #include "mrn_lock.hpp" #include "mrn_path_mapper.hpp" +#include <groonga/plugin.h> + // for debug #define MRN_CLASS_NAME "mrn::DatabaseManager" @@ -38,19 +40,19 @@ # define MRN_MKDIR(pathname, mode) mkdir((pathname), (mode)) #endif +extern "C" { + grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(init, normalizers_mysql)(grn_ctx *ctx); + grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(register, normalizers_mysql)(grn_ctx *ctx); +} + namespace mrn { - DatabaseManager::DatabaseManager(grn_ctx *ctx) + DatabaseManager::DatabaseManager(grn_ctx *ctx, mysql_mutex_t *mutex) : ctx_(ctx), cache_(NULL), - mutex_(), - mutex_initialized_(false) { + mutex_(mutex) { } DatabaseManager::~DatabaseManager(void) { - if (mutex_initialized_) { - pthread_mutex_destroy(&mutex_); - } - if (cache_) { void *db_address; GRN_HASH_EACH(ctx_, cache_, id, NULL, 0, &db_address, { @@ -75,13 +77,6 @@ namespace mrn { DBUG_RETURN(false); } - if (pthread_mutex_init(&mutex_, NULL) != 0) { - GRN_LOG(ctx_, GRN_LOG_ERROR, - "failed to initialize mutex for opened database cache hash table"); - DBUG_RETURN(false); - } - - mutex_initialized_ = true; DBUG_RETURN(true); } @@ -92,7 +87,7 @@ namespace mrn { *db = NULL; mrn::PathMapper mapper(path); - mrn::Lock lock(&mutex_); + mrn::Lock lock(mutex_); error = mrn::encoding::set(ctx_, system_charset_info); if (error) { @@ -145,7 +140,7 @@ namespace mrn { MRN_DBUG_ENTER_METHOD(); mrn::PathMapper mapper(path); - mrn::Lock lock(&mutex_); + mrn::Lock lock(mutex_); grn_id id; void *db_address; @@ -171,7 +166,7 @@ namespace mrn { MRN_DBUG_ENTER_METHOD(); mrn::PathMapper mapper(path); - mrn::Lock lock(&mutex_); + mrn::Lock lock(mutex_); grn_id id; void *db_address; @@ -211,7 +206,7 @@ namespace mrn { int error = 0; - mrn::Lock lock(&mutex_); + mrn::Lock lock(mutex_); grn_hash_cursor *cursor; cursor = grn_hash_cursor_open(ctx_, cache_, @@ -323,15 +318,12 @@ namespace mrn { if (mysql_normalizer) { grn_obj_unlink(ctx_, mysql_normalizer); } else { -#ifdef GROONGA_NORMALIZER_MYSQL_PLUGIN_IS_BUNDLED_STATIC - char ref_path[FN_REFLEN + 1], *tmp; - tmp = strmov(ref_path, opt_plugin_dir); - tmp = strmov(tmp, "/ha_mroonga"); - strcpy(tmp, SO_EXT); - grn_plugin_register_by_path(ctx_, ref_path); -#else +# ifdef MRN_GROONGA_NORMALIZER_MYSQL_EMBED + GRN_PLUGIN_IMPL_NAME_TAGGED(init, normalizers_mysql)(ctx_); + GRN_PLUGIN_IMPL_NAME_TAGGED(register, normalizers_mysql)(ctx_); +# else grn_plugin_register(ctx_, GROONGA_NORMALIZER_MYSQL_PLUGIN_NAME); -#endif +# endif } } #endif diff --git a/storage/mroonga/lib/mrn_database_manager.hpp b/storage/mroonga/lib/mrn_database_manager.hpp index 46bce7ab1a5..76c76dab6d5 100644 --- a/storage/mroonga/lib/mrn_database_manager.hpp +++ b/storage/mroonga/lib/mrn_database_manager.hpp @@ -27,7 +27,7 @@ namespace mrn { class DatabaseManager { public: - DatabaseManager(grn_ctx *ctx); + DatabaseManager(grn_ctx *ctx, mysql_mutex_t *mutex); ~DatabaseManager(void); bool init(void); int open(const char *path, grn_obj **db); @@ -38,8 +38,7 @@ namespace mrn { private: grn_ctx *ctx_; grn_hash *cache_; - pthread_mutex_t mutex_; - bool mutex_initialized_; + mysql_mutex_t *mutex_; void mkdir_p(const char *directory); void ensure_database_directory(void); diff --git a/storage/mroonga/lib/mrn_database_repairer.cpp b/storage/mroonga/lib/mrn_database_repairer.cpp new file mode 100644 index 00000000000..151330c9999 --- /dev/null +++ b/storage/mroonga/lib/mrn_database_repairer.cpp @@ -0,0 +1,246 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2015 Kouhei Sutou <kou@clear-code.com> + + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include <mrn_mysql.h> +#include <mrn_mysql_compat.h> +#include <mrn_constants.hpp> + +#include "mrn_database_repairer.hpp" +#include "mrn_path_mapper.hpp" + +// for debug +#define MRN_CLASS_NAME "mrn::DatabaseRepairer" + +#include <sys/stat.h> +#include <sys/types.h> +#include <errno.h> + +#ifndef WIN32 +# include <dirent.h> +#endif + +namespace mrn { + DatabaseRepairer::DatabaseRepairer(grn_ctx *ctx, THD *thd) + : ctx_(ctx), + thd_(thd), + base_directory_(NULL), + base_directory_buffer_(), + path_prefix_(NULL), + path_prefix_buffer_(), + path_prefix_length_(0), + mrn_db_file_suffix_length_(strlen(MRN_DB_FILE_SUFFIX)) { + } + + DatabaseRepairer::~DatabaseRepairer() { + } + + bool DatabaseRepairer::is_crashed(void) { + MRN_DBUG_ENTER_METHOD(); + + bool is_crashed = false; + each_database(&DatabaseRepairer::is_crashed_body, &is_crashed); + + DBUG_RETURN(is_crashed); + } + + bool DatabaseRepairer::repair(void) { + MRN_DBUG_ENTER_METHOD(); + + bool succeeded = true; + each_database(&DatabaseRepairer::repair_body, &succeeded); + + DBUG_RETURN(succeeded); + } + + void DatabaseRepairer::each_database(EachBodyFunc each_body_func, + void *user_data) { + MRN_DBUG_ENTER_METHOD(); + + detect_paths(); + +#ifdef WIN32 + WIN32_FIND_DATA data; + HANDLE finder = FindFirstFile(base_directory_, &data); + if (finder == INVALID_HANDLE_VALUE) { + DBUG_VOID_RETURN; + } + + do { + each_database_body(data.cFileName, each_body_func, user_data); + } while (FindNextFile(finder, &data) != 0); + FindClose(finder); +#else + DIR *dir = opendir(base_directory_); + if (!dir) { + DBUG_VOID_RETURN; + } + + while (struct dirent *entry = readdir(dir)) { + each_database_body(entry->d_name, each_body_func, user_data); + } + closedir(dir); +#endif + + DBUG_VOID_RETURN; + } + + void DatabaseRepairer::each_database_body(const char *base_path, + EachBodyFunc each_body_func, + void *user_data) { + MRN_DBUG_ENTER_METHOD(); + + if (path_prefix_length_ > 0 && + strncmp(base_path, path_prefix_, path_prefix_length_) != 0) { + DBUG_VOID_RETURN; + } + + size_t path_length = strlen(base_path); + if (path_length <= mrn_db_file_suffix_length_) { + DBUG_VOID_RETURN; + } + + if (strncmp(base_path + (path_length - mrn_db_file_suffix_length_), + MRN_DB_FILE_SUFFIX, mrn_db_file_suffix_length_) != 0) { + DBUG_VOID_RETURN; + } + + char db_path[MRN_MAX_PATH_SIZE]; + snprintf(db_path, MRN_MAX_PATH_SIZE, + "%s%c%s", base_directory_, FN_LIBCHAR, base_path); + grn_obj *db = grn_db_open(ctx_, db_path); + if (!db) { + DBUG_VOID_RETURN; + } + + (this->*each_body_func)(db, db_path, user_data); + + grn_obj_close(ctx_, db); + + DBUG_VOID_RETURN; + } + + void DatabaseRepairer::detect_paths(void) { + MRN_DBUG_ENTER_METHOD(); + + const char *raw_path_prefix = mrn::PathMapper::default_path_prefix; + + if (!raw_path_prefix) { + base_directory_ = "."; + path_prefix_ = NULL; + DBUG_VOID_RETURN; + } + + strcpy(base_directory_buffer_, raw_path_prefix); + size_t raw_path_prefix_length = strlen(raw_path_prefix); + size_t separator_position = raw_path_prefix_length; + for (; separator_position > 0; separator_position--) { + if (base_directory_buffer_[separator_position] == FN_LIBCHAR || + base_directory_buffer_[separator_position] == FN_LIBCHAR2) { + break; + } + } + if (separator_position == 0 || + separator_position == raw_path_prefix_length) { + base_directory_ = "."; + } else { + base_directory_buffer_[separator_position] = '\0'; + base_directory_ = base_directory_buffer_; + strcpy(path_prefix_buffer_, raw_path_prefix + separator_position + 1); + path_prefix_ = path_prefix_buffer_; + path_prefix_length_ = strlen(path_prefix_); + } + + DBUG_VOID_RETURN; + } + + void DatabaseRepairer::is_crashed_body(grn_obj *db, + const char *db_path, + void *user_data) { + MRN_DBUG_ENTER_METHOD(); + + bool *is_crashed = static_cast<bool *>(user_data); + + if (grn_obj_is_locked(ctx_, db)) { + *is_crashed = true; + DBUG_VOID_RETURN; + } + + grn_table_cursor *cursor; + cursor = grn_table_cursor_open(ctx_, db, + NULL, 0, + NULL, 0, + 0, -1, GRN_CURSOR_BY_ID); + if (!cursor) { + *is_crashed = true; + DBUG_VOID_RETURN; + } + + grn_id id; + while ((id = grn_table_cursor_next(ctx_, cursor)) != GRN_ID_NIL) { + grn_obj *object = grn_ctx_at(ctx_, id); + + if (!object) { + continue; + } + + switch (object->header.type) { + case GRN_TABLE_HASH_KEY : + case GRN_TABLE_PAT_KEY: + case GRN_TABLE_DAT_KEY: + case GRN_TABLE_NO_KEY: + case GRN_COLUMN_FIX_SIZE: + case GRN_COLUMN_VAR_SIZE: + case GRN_COLUMN_INDEX: + grn_obj_is_locked(ctx_, object); + *is_crashed = true; + break; + default: + break; + } + + grn_obj_unlink(ctx_, object); + + if (*is_crashed) { + break; + } + } + grn_table_cursor_close(ctx_, cursor); + + DBUG_VOID_RETURN; + } + + void DatabaseRepairer::repair_body(grn_obj *db, + const char *db_path, + void *user_data) { + MRN_DBUG_ENTER_METHOD(); + + bool *succeeded = static_cast<bool *>(user_data); + if (grn_db_recover(ctx_, db) != GRN_SUCCESS) { + push_warning_printf(thd_, + Sql_condition::WARN_LEVEL_WARN, + ER_NOT_KEYFILE, + "mroonga: repair: " + "Failed to recover database: <%s>: <%s>", + db_path, ctx_->errbuf); + *succeeded = false; + } + + DBUG_VOID_RETURN; + } +} diff --git a/storage/mroonga/lib/mrn_database_repairer.hpp b/storage/mroonga/lib/mrn_database_repairer.hpp new file mode 100644 index 00000000000..12e2bbc9c79 --- /dev/null +++ b/storage/mroonga/lib/mrn_database_repairer.hpp @@ -0,0 +1,58 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2015 Kouhei Sutou <kou@clear-code.com> + + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef MRN_DATABASE_REPAIRER_HPP_ +#define MRN_DATABASE_REPAIRER_HPP_ + +#include <groonga.h> + +namespace mrn { + class DatabaseRepairer { + public: + DatabaseRepairer(grn_ctx *ctx, THD *thd); + ~DatabaseRepairer(void); + bool is_crashed(void); + bool repair(void); + + private: + grn_ctx *ctx_; + THD *thd_; + const char *base_directory_; + char base_directory_buffer_[MRN_MAX_PATH_SIZE]; + const char *path_prefix_; + char path_prefix_buffer_[MRN_MAX_PATH_SIZE]; + size_t path_prefix_length_; + size_t mrn_db_file_suffix_length_; + + typedef void (DatabaseRepairer::*EachBodyFunc)(grn_obj *db, + const char *db_path, + void *user_data); + + void each_database(EachBodyFunc each_body_func, void *user_data); + void each_database_body(const char *base_path, + EachBodyFunc each_body_func, + void *user_data); + void detect_paths(void); + + void is_crashed_body(grn_obj *db, const char *db_path, void *user_data); + void repair_body(grn_obj *db, const char *db_path, void *user_data); + }; +} + +#endif /* MRN_DATABASE_REPAIRER_HPP_ */ diff --git a/storage/mroonga/lib/mrn_encoding.cpp b/storage/mroonga/lib/mrn_encoding.cpp index f6f66758b2f..35b8909fba2 100644 --- a/storage/mroonga/lib/mrn_encoding.cpp +++ b/storage/mroonga/lib/mrn_encoding.cpp @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include <mrn_mysql.h> #include <mrn_err.h> #include "mrn_encoding.hpp" diff --git a/storage/mroonga/lib/mrn_field_normalizer.cpp b/storage/mroonga/lib/mrn_field_normalizer.cpp index c34f9975e37..f0b9d921599 100644 --- a/storage/mroonga/lib/mrn_field_normalizer.cpp +++ b/storage/mroonga/lib/mrn_field_normalizer.cpp @@ -17,6 +17,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include <mrn_mysql.h> + #include "mrn_field_normalizer.hpp" #include "mrn_encoding.hpp" @@ -114,6 +116,9 @@ namespace mrn { } else if ((strcmp(charset_info->name, "utf8_unicode_ci") == 0) || (strcmp(charset_info->name, "utf8mb4_unicode_ci") == 0)) { normalizer_name = "NormalizerMySQLUnicodeCI"; + } else if ((strcmp(charset_info->name, "utf8_unicode_520_ci") == 0) || + (strcmp(charset_info->name, "utf8mb4_unicode_520_ci") == 0)) { + normalizer_name = "NormalizerMySQLUnicode520CI"; } grn_obj *normalizer = NULL; @@ -128,7 +133,7 @@ namespace mrn { normalizer_name, charset_info->name, default_normalizer_name); - push_warning(thread_, Sql_condition::WARN_LEVEL_WARN, + push_warning(thread_, MRN_SEVERITY_WARNING, HA_ERR_UNSUPPORTED, error_message); } } diff --git a/storage/mroonga/lib/mrn_lock.cpp b/storage/mroonga/lib/mrn_lock.cpp index 94f8a4774af..3340149b237 100644 --- a/storage/mroonga/lib/mrn_lock.cpp +++ b/storage/mroonga/lib/mrn_lock.cpp @@ -20,12 +20,12 @@ #include "mrn_lock.hpp" namespace mrn { - Lock::Lock(pthread_mutex_t *mutex) + Lock::Lock(mysql_mutex_t *mutex) : mutex_(mutex) { - pthread_mutex_lock(mutex_); + mysql_mutex_lock(mutex_); } Lock::~Lock() { - pthread_mutex_unlock(mutex_); + mysql_mutex_unlock(mutex_); } } diff --git a/storage/mroonga/lib/mrn_lock.hpp b/storage/mroonga/lib/mrn_lock.hpp index 31dd7b3e53b..08e47b39c58 100644 --- a/storage/mroonga/lib/mrn_lock.hpp +++ b/storage/mroonga/lib/mrn_lock.hpp @@ -26,10 +26,10 @@ namespace mrn { class Lock { public: - Lock(pthread_mutex_t *mutex); + Lock(mysql_mutex_t *mutex); ~Lock(); private: - pthread_mutex_t *mutex_; + mysql_mutex_t *mutex_; }; } diff --git a/storage/mroonga/lib/mrn_multiple_column_key_codec.cpp b/storage/mroonga/lib/mrn_multiple_column_key_codec.cpp index 5ce736a49b8..1e55636f1bc 100644 --- a/storage/mroonga/lib/mrn_multiple_column_key_codec.cpp +++ b/storage/mroonga/lib/mrn_multiple_column_key_codec.cpp @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2 -*- */ /* - Copyright(C) 2012-2014 Kouhei Sutou <kou@clear-code.com> + Copyright(C) 2012-2015 Kouhei Sutou <kou@clear-code.com> Copyright(C) 2013 Kentoku SHIBA This library is free software; you can redistribute it and/or @@ -23,6 +23,7 @@ #include "mrn_multiple_column_key_codec.hpp" #include "mrn_field_normalizer.hpp" #include "mrn_smart_grn_obj.hpp" +#include "mrn_value_decoder.hpp" // for debug #define MRN_CLASS_NAME "mrn::MultipleColumnKeyCodec" @@ -121,14 +122,14 @@ namespace mrn { case TYPE_FLOAT: { float value; - float4get(value, current_mysql_key); + value_decoder::decode(&value, current_mysql_key); encode_float(value, data_size, current_grn_key); } break; case TYPE_DOUBLE: { double value; - float8get(value, current_mysql_key); + value_decoder::decode(&value, current_mysql_key); encode_double(value, data_size, current_grn_key); } break; @@ -523,7 +524,7 @@ namespace mrn { new_blob_data_length = normalized_length; } else { push_warning_printf(thread_, - Sql_condition::WARN_LEVEL_WARN, + MRN_SEVERITY_WARNING, WARN_DATA_TRUNCATED, "normalized data truncated " "for multiple column index: " diff --git a/storage/mroonga/lib/mrn_parameters_parser.cpp b/storage/mroonga/lib/mrn_parameters_parser.cpp index 9a05097e548..bc075b07068 100644 --- a/storage/mroonga/lib/mrn_parameters_parser.cpp +++ b/storage/mroonga/lib/mrn_parameters_parser.cpp @@ -1,7 +1,7 @@ /* -*- c-basic-offset: 2 -*- */ /* Copyright(C) 2011-2013 Kentoku SHIBA - Copyright(C) 2011-2013 Kouhei Sutou <kou@clear-code.com> + Copyright(C) 2011-2015 Kouhei Sutou <kou@clear-code.com> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -21,6 +21,7 @@ #include "mrn_parameters_parser.hpp" #include <mrn_mysql_compat.h> +#include <mrn_variables.hpp> namespace mrn { class Parameter { @@ -30,15 +31,15 @@ namespace mrn { Parameter(const char *key, unsigned int key_length, const char *value, unsigned int value_length) - : key_(my_strndup(key, key_length, MYF(0))), - value_(my_strndup(value, value_length, MYF(0))) { + : key_(mrn_my_strndup(key, key_length, MYF(0))), + value_(mrn_my_strndup(value, value_length, MYF(0))) { }; ~Parameter() { if (key_) { - my_free(key_, MYF(0)); + my_free(key_); } if (value_) { - my_free(value_, MYF(0)); + my_free(value_); } }; }; diff --git a/storage/mroonga/lib/mrn_path_mapper.cpp b/storage/mroonga/lib/mrn_path_mapper.cpp index ee5432f16bb..7a595986f01 100644 --- a/storage/mroonga/lib/mrn_path_mapper.cpp +++ b/storage/mroonga/lib/mrn_path_mapper.cpp @@ -2,7 +2,7 @@ /* Copyright(C) 2010 Tetsuro IKEDA Copyright(C) 2011-2013 Kentoku SHIBA - Copyright(C) 2011-2012 Kouhei Sutou <kou@clear-code.com> + Copyright(C) 2011-2015 Kouhei Sutou <kou@clear-code.com> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -29,16 +29,17 @@ namespace mrn { char *PathMapper::default_path_prefix = NULL; char *PathMapper::default_mysql_data_home_path = NULL; - PathMapper::PathMapper(const char *mysql_path, + PathMapper::PathMapper(const char *original_mysql_path, const char *path_prefix, const char *mysql_data_home_path) - : mysql_path_(mysql_path), + : original_mysql_path_(original_mysql_path), path_prefix_(path_prefix), mysql_data_home_path_(mysql_data_home_path) { db_path_[0] = '\0'; db_name_[0] = '\0'; table_name_[0] = '\0'; mysql_table_name_[0] = '\0'; + mysql_path_[0] = '\0'; } /** @@ -52,22 +53,25 @@ namespace mrn { return db_path_; } - if (mysql_path_[0] == FN_CURLIB && mysql_path_[1] == FN_LIBCHAR) { + if (original_mysql_path_[0] == FN_CURLIB && + original_mysql_path_[1] == FN_LIBCHAR) { if (path_prefix_) { strcpy(db_path_, path_prefix_); } int i = 2, j = strlen(db_path_), len; - len = strlen(mysql_path_); - while (mysql_path_[i] != FN_LIBCHAR && i < len) { - db_path_[j++] = mysql_path_[i++]; + len = strlen(original_mysql_path_); + while (original_mysql_path_[i] != FN_LIBCHAR && i < len) { + db_path_[j++] = original_mysql_path_[i++]; } db_path_[j] = '\0'; } else if (mysql_data_home_path_) { - int len = strlen(mysql_path_); + int len = strlen(original_mysql_path_); int mysql_data_home_len = strlen(mysql_data_home_path_); if (len > mysql_data_home_len && - !strncmp(mysql_path_, mysql_data_home_path_, mysql_data_home_len)) { + !strncmp(original_mysql_path_, + mysql_data_home_path_, + mysql_data_home_len)) { int i = mysql_data_home_len, j; if (path_prefix_ && path_prefix_[0] == FN_LIBCHAR) { strcpy(db_path_, path_prefix_); @@ -87,19 +91,19 @@ namespace mrn { } } - while (mysql_path_[i] != FN_LIBCHAR && i < len) { - db_path_[j++] = mysql_path_[i++]; + while (original_mysql_path_[i] != FN_LIBCHAR && i < len) { + db_path_[j++] = original_mysql_path_[i++]; } if (i == len) { - memcpy(db_path_, mysql_path_, len); + memcpy(db_path_, original_mysql_path_, len); } else { db_path_[j] = '\0'; } } else { - strcpy(db_path_, mysql_path_); + strcpy(db_path_, original_mysql_path_); } } else { - strcpy(db_path_, mysql_path_); + strcpy(db_path_, original_mysql_path_); } strcat(db_path_, MRN_DB_FILE_SUFFIX); return db_path_; @@ -116,32 +120,35 @@ namespace mrn { return db_name_; } - if (mysql_path_[0] == FN_CURLIB && mysql_path_[1] == FN_LIBCHAR) { + if (original_mysql_path_[0] == FN_CURLIB && + original_mysql_path_[1] == FN_LIBCHAR) { int i = 2, j = 0, len; - len = strlen(mysql_path_); - while (mysql_path_[i] != FN_LIBCHAR && i < len) { - db_name_[j++] = mysql_path_[i++]; + len = strlen(original_mysql_path_); + while (original_mysql_path_[i] != FN_LIBCHAR && i < len) { + db_name_[j++] = original_mysql_path_[i++]; } db_name_[j] = '\0'; } else if (mysql_data_home_path_) { - int len = strlen(mysql_path_); + int len = strlen(original_mysql_path_); int mysql_data_home_len = strlen(mysql_data_home_path_); if (len > mysql_data_home_len && - !strncmp(mysql_path_, mysql_data_home_path_, mysql_data_home_len)) { + !strncmp(original_mysql_path_, + mysql_data_home_path_, + mysql_data_home_len)) { int i = mysql_data_home_len, j = 0; - while (mysql_path_[i] != FN_LIBCHAR && i < len) { - db_name_[j++] = mysql_path_[i++]; + while (original_mysql_path_[i] != FN_LIBCHAR && i < len) { + db_name_[j++] = original_mysql_path_[i++]; } if (i == len) { - memcpy(db_name_, mysql_path_, len); + memcpy(db_name_, original_mysql_path_, len); } else { db_name_[j] = '\0'; } } else { - strcpy(db_name_, mysql_path_); + strcpy(db_name_, original_mysql_path_); } } else { - strcpy(db_name_, mysql_path_); + strcpy(db_name_, original_mysql_path_); } return db_name_; } @@ -154,10 +161,10 @@ namespace mrn { return table_name_; } - int len = strlen(mysql_path_); + int len = strlen(original_mysql_path_); int i = len, j = 0; - for (; mysql_path_[--i] != FN_LIBCHAR ;) {} - if (mysql_path_[i + 1] == '_') { + for (; original_mysql_path_[--i] != FN_LIBCHAR ;) {} + if (original_mysql_path_[i + 1] == '_') { table_name_[j++] = '@'; table_name_[j++] = '0'; table_name_[j++] = '0'; @@ -166,7 +173,7 @@ namespace mrn { i++; } for (; i < len ;) { - table_name_[j++] = mysql_path_[++i]; + table_name_[j++] = original_mysql_path_[++i]; } table_name_[j] = '\0'; return table_name_; @@ -180,13 +187,39 @@ namespace mrn { return mysql_table_name_; } - int len = strlen(mysql_path_); + int len = strlen(original_mysql_path_); int i = len, j = 0; - for (; mysql_path_[--i] != FN_LIBCHAR ;) {} + for (; original_mysql_path_[--i] != FN_LIBCHAR ;) {} for (; i < len ;) { - mysql_table_name_[j++] = mysql_path_[++i]; + if (len - i - 1 >= 3 && + strncmp(original_mysql_path_ + i + 1, "#P#", 3) == 0) { + break; + } + mysql_table_name_[j++] = original_mysql_path_[++i]; } mysql_table_name_[j] = '\0'; return mysql_table_name_; } + + /** + * "./${db}/${table}" ==> "./${db}/${table}" + * "./${db}/${table}#P#xxx" ==> "./${db}/${table}" + */ + const char *PathMapper::mysql_path() { + if (mysql_path_[0] != '\0') { + return mysql_path_; + } + + int i; + int len = strlen(original_mysql_path_); + for (i = 0; i < len; i++) { + if (len - i >= 3 && + strncmp(original_mysql_path_ + i, "#P#", 3) == 0) { + break; + } + mysql_path_[i] = original_mysql_path_[i]; + } + mysql_path_[i] = '\0'; + return mysql_path_; + } } diff --git a/storage/mroonga/lib/mrn_path_mapper.hpp b/storage/mroonga/lib/mrn_path_mapper.hpp index f70cd7b5587..607bfe4cdce 100644 --- a/storage/mroonga/lib/mrn_path_mapper.hpp +++ b/storage/mroonga/lib/mrn_path_mapper.hpp @@ -2,7 +2,7 @@ /* Copyright(C) 2010 Tetsuro IKEDA Copyright(C) 2010-2013 Kentoku SHIBA - Copyright(C) 2011-2012 Kouhei Sutou <kou@clear-code.com> + Copyright(C) 2011-2015 Kouhei Sutou <kou@clear-code.com> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -30,21 +30,23 @@ namespace mrn { static char *default_path_prefix; static char *default_mysql_data_home_path; - PathMapper(const char *mysql_path, + PathMapper(const char *original_mysql_path, const char *path_prefix=default_path_prefix, const char *mysql_data_home_path=default_mysql_data_home_path); const char *db_path(); const char *db_name(); const char *table_name(); const char *mysql_table_name(); + const char *mysql_path(); private: - const char *mysql_path_; + const char *original_mysql_path_; const char *path_prefix_; const char *mysql_data_home_path_; char db_path_[MRN_MAX_PATH_SIZE]; char db_name_[MRN_MAX_PATH_SIZE]; char table_name_[MRN_MAX_PATH_SIZE]; char mysql_table_name_[MRN_MAX_PATH_SIZE]; + char mysql_path_[MRN_MAX_PATH_SIZE]; }; } diff --git a/storage/mroonga/lib/mrn_value_decoder.cpp b/storage/mroonga/lib/mrn_value_decoder.cpp new file mode 100644 index 00000000000..8356789915f --- /dev/null +++ b/storage/mroonga/lib/mrn_value_decoder.cpp @@ -0,0 +1,64 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2015 Kouhei Sutou <kou@clear-code.com> + + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "mrn_value_decoder.hpp" + +#if MYSQL_VERSION_ID >= 50706 && !defined(MRN_MARIADB_P) +# define MRN_DEST_IS_POINTER +#endif + +namespace mrn { + namespace value_decoder { + void decode(uint16 *dest, const uchar *source) { + MRN_DBUG_ENTER_FUNCTION(); +#ifdef MRN_DEST_IS_POINTER + ushortget(dest, source); +#else + uint16 value; + ushortget(value, source); + *dest = value; +#endif + DBUG_VOID_RETURN; + }; + + void decode(float *dest, const uchar *source) { + MRN_DBUG_ENTER_FUNCTION(); +#ifdef MRN_DEST_IS_POINTER + float4get(dest, source); +#else + float value; + float4get(value, source); + *dest = value; +#endif + DBUG_VOID_RETURN; + }; + + void decode(double *dest, const uchar *source) { + MRN_DBUG_ENTER_FUNCTION(); +#ifdef MRN_DEST_IS_POINTER + float8get(dest, source); +#else + double value; + float8get(value, source); + *dest = value; +#endif + DBUG_VOID_RETURN; + } + } +} diff --git a/storage/mroonga/lib/mrn_value_decoder.hpp b/storage/mroonga/lib/mrn_value_decoder.hpp new file mode 100644 index 00000000000..8a48de0b003 --- /dev/null +++ b/storage/mroonga/lib/mrn_value_decoder.hpp @@ -0,0 +1,33 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2015 Kouhei Sutou <kou@clear-code.com> + + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef MRN_VALUE_DECODER_HPP_ +#define MRN_VALUE_DECODER_HPP_ + +#include <mrn_mysql.h> + +namespace mrn { + namespace value_decoder { + void decode(uint16 *dest, const uchar *source); + void decode(float *dest, const uchar *source); + void decode(double *dest, const uchar *source); + } +} + +#endif // MRN_VALUE_DECODER_HPP_ |