Navigation Menu

Skip to content

Commit

Permalink
percona: support upgrading from < 5.6.34 and < 5.7.21
Browse files Browse the repository at this point in the history
[groonga-dev,04599]

Percona Server 5.6.34 and 5.7.21 assign a plugin ID for RocksDB:
percona/percona-server@805173f

The plugin ID can be used third party plugin such as Mroonga before
5.6.34 and 5.7.21. If you upgrade from < 5.6.34 or < 5.7.21 to >=
5.6.34 or >= 5.7.21, you get the following error:

    ERROR 1033 (HY000): Incorrect information in file: './DB/TABLE.frm'

It's caused by auto assigned plugin ID for Mroonga in < 5.6.34 and <
5.7.21 are different from in >= 5.6.34 and >= 5.7.21.

Reported by Takashi Kinoshita. Thanks!!!

Looked into by Satoshi Mitani. Thanks!!!
  • Loading branch information
kou committed Apr 11, 2018
1 parent 666fd32 commit 555d668
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 1 deletion.
114 changes: 113 additions & 1 deletion ha_mroonga.cpp
Expand Up @@ -236,6 +236,13 @@ static PSI_memory_info mrn_all_memory_keys[]=
};
#endif

#ifdef MRN_HAVE_PSI_FILE_KEY
static PSI_file_key mrn_key_file_frm;
static PSI_file_info mrn_all_file_keys[] = {
{&mrn_key_file_frm, "Mroonga: FRM", 0},
};
#endif

static const char *INDEX_COLUMN_NAME = "index";
static const char *MRN_PLUGIN_AUTHOR = "The Mroonga project";

Expand Down Expand Up @@ -1899,6 +1906,101 @@ static ha_create_table_option mrn_index_options[] =
};
#endif

#ifdef MRN_HAVE_DB_TYPE_ROCKSDB
static void
mrn_fix_db_type_static_rocksdb_db_type()
{
// Percona Server 5.6.34 or later and 5.7.21 or later assigns static
// plugin ID for RocksDB that ID was able to be used by third party
// plugin before:
// https://github.com/percona/percona-server/commit/805173fed3db20c9c7be7a5bb41bda9d2a53b6ca

THD *thd = current_thd;

handlerton *rocksdb_hton = ha_resolve_by_legacy_type(thd, DB_TYPE_ROCKSDB);
if (rocksdb_hton) {
return;
}

enum legacy_db_type mroonga_db_type = DB_TYPE_FIRST_DYNAMIC;
while (ha_resolve_by_legacy_type(thd, mroonga_db_type)) {
mroonga_db_type =
static_cast<enum legacy_db_type>(static_cast<int>(mroonga_db_type) + 1);
}

struct st_my_dir *data_dir = my_dir(mysql_real_data_home,
MYF(MY_DONT_SORT | MY_WANT_STAT));
if (!data_dir) {
return;
}

struct fileinfo *data_file_info = data_dir->dir_entry;
for (uint i = 0; i < data_dir->number_off_files; ++i, ++data_file_info) {
if (data_file_info->name[0] == '.')
continue;
if (!MY_S_ISDIR(data_file_info->mystat->st_mode))
continue;

String db_path(mysql_real_data_home, &my_charset_bin);
db_path.append(FN_DIRSEP);
db_path.append(data_file_info->name);
struct st_my_dir *db_dir = my_dir(db_path.c_ptr(), MYF(MY_DONT_SORT));
if (!db_dir)
continue;

struct fileinfo *db_file_info = db_dir->dir_entry;
for (uint j = 0; j < db_dir->number_off_files; ++j, ++db_file_info) {
const char *ext = strrchr(db_file_info->name, '.');
if (!ext)
continue;
if (is_prefix(db_file_info->name, tmp_file_prefix))
continue;
if (strcmp(ext, ".frm") != 0)
continue;

String full_frm_path(db_path);
full_frm_path.append(FN_DIRSEP);
full_frm_path.append(db_file_info->name);
enum legacy_db_type db_type;
frm_type_enum type = dd_frm_type(thd, full_frm_path.c_ptr(), &db_type);
if (type != FRMTYPE_TABLE)
continue;

if (db_type != DB_TYPE_ROCKSDB)
continue;

File frm_file = mysql_file_open(mrn_key_file_frm,
full_frm_path.c_ptr(),
O_WRONLY,
MYF(0));
if (frm_file < 0)
continue;

uchar db_type_buffer[1];
db_type_buffer[0] = static_cast<uchar>(mroonga_db_type);
mysql_file_pwrite(frm_file,
db_type_buffer,
sizeof(db_type_buffer),
3,
MYF(0));
mysql_file_close(frm_file, MYF(0));
}

my_dirend(db_dir);
}

my_dirend(data_dir);
}
#endif

static void
mrn_fix_db_type()
{
#ifdef MRN_HAVE_DB_TYPE_ROCKSDB
mrn_fix_db_type_static_rocksdb_db_type();
#endif
}

static int mrn_init(void *p)
{
// init handlerton
Expand Down Expand Up @@ -1984,12 +2086,20 @@ static int mrn_init(void *p)

#ifdef MRN_HAVE_PSI_MEMORY_KEY
{
const char *category = "ha_mroonga";
const char *category = "mroonga";
int n_keys = array_elements(mrn_all_memory_keys);
mysql_memory_register(category, mrn_all_memory_keys, n_keys);
}
#endif

#ifdef MRN_HAVE_DB_TYPE_ROCKSDB
{
const char *category = "mroonga";
int n_keys = array_elements(mrn_all_file_keys);
mysql_file_register(category, mrn_all_file_keys, n_keys);
}
#endif

if (mysql_mutex_init(mrn_log_mutex_key,
&mrn_log_mutex,
MY_MUTEX_INIT_FAST) != 0) {
Expand Down Expand Up @@ -2083,6 +2193,8 @@ static int mrn_init(void *p)
mrn::PathMapper::default_mysql_data_home_path = mysql_data_home;
#endif

mrn_fix_db_type();

return 0;

error_allocated_long_term_share_hash_init:
Expand Down
11 changes: 11 additions & 0 deletions mrn_mysql_compat.h
Expand Up @@ -253,6 +253,10 @@
# define MRN_HAVE_PSI_MEMORY_KEY
#endif

#ifdef HAVE_PSI_INTERFACE
# define MRN_HAVE_PSI_FILE_KEY
#endif

#ifdef MRN_HAVE_PSI_MEMORY_KEY
# define mrn_my_malloc(size, flags) \
my_malloc(mrn_memory_key, size, flags)
Expand Down Expand Up @@ -586,3 +590,10 @@
(field->vcol_info->expr_item->save_in_field(field, 0))
# endif
#endif

#ifdef MRN_PERCONA_P
# if ((MYSQL_VERSION_ID >= 50634) && (MYSQL_VERSION_ID < 50700)) || \
(MYSQL_VERSION_ID >= 50721)
# define MRN_HAVE_DB_TYPE_ROCKSDB
# endif
#endif

0 comments on commit 555d668

Please sign in to comment.