Skip to content

Commit 5994b68

Browse files
committed
Daemon: TRT check doesn't abort [fixes #335]
Added schema check logging messages.
1 parent 0b40a98 commit 5994b68

File tree

7 files changed

+89
-24
lines changed

7 files changed

+89
-24
lines changed

sql/handler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ int ha_commit_trans(THD *thd, bool all)
14161416

14171417
if (rw_trans || thd->lex->sql_command == SQLCOM_ALTER_TABLE)
14181418
{
1419-
if (opt_transaction_registry && thd->vers_update_trt)
1419+
if (use_transaction_registry && thd->vers_update_trt)
14201420
{
14211421
TR_table trt(thd, true);
14221422
if (trt.update())

sql/mysqld.cc

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ ulong feature_files_opened_with_delayed_keys= 0, feature_check_constraint= 0;
535535
ulonglong denied_connections;
536536
my_decimal decimal_zero;
537537
my_bool opt_transaction_registry= 1;
538+
my_bool use_transaction_registry= 1;
538539

539540
/*
540541
Maximum length of parameter value which can be set through
@@ -6027,25 +6028,35 @@ int mysqld_main(int argc, char **argv)
60276028
if (Events::init((THD*) 0, opt_noacl || opt_bootstrap))
60286029
unireg_abort(1);
60296030

6030-
if (!opt_bootstrap && opt_transaction_registry)
6031+
if (opt_transaction_registry)
60316032
{
6032-
THD *thd = new THD(0);
6033-
thd->thread_stack= (char*) &thd;
6034-
thd->store_globals();
6035-
6033+
use_transaction_registry= true;
6034+
if (opt_bootstrap)
60366035
{
6037-
TR_table trt(thd);
6038-
if (trt.check())
6036+
use_transaction_registry= false;
6037+
}
6038+
else
6039+
{
6040+
THD *thd = new THD(0);
6041+
thd->thread_stack= (char*) &thd;
6042+
thd->store_globals();
60396043
{
6040-
sql_print_error("%s schema is incorrect", trt.table_name);
6041-
delete thd;
6042-
unireg_abort(1);
6044+
TR_table trt(thd);
6045+
if (trt.check())
6046+
{
6047+
use_transaction_registry= false;
6048+
}
60436049
}
6044-
}
60456050

6046-
trans_commit_stmt(thd);
6047-
delete thd;
6051+
trans_commit_stmt(thd);
6052+
delete thd;
6053+
}
60486054
}
6055+
else
6056+
use_transaction_registry= false;
6057+
6058+
if (opt_transaction_registry && !use_transaction_registry)
6059+
sql_print_information("Disabled transaction registry.");
60496060

60506061
if (WSREP_ON)
60516062
{

sql/mysqld.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ extern ulong encryption_algorithm;
313313
extern const char *encryption_algorithm_names[];
314314
extern const char *quoted_string;
315315
extern my_bool opt_transaction_registry;
316+
extern my_bool use_transaction_registry;
316317

317318
#ifdef HAVE_PSI_INTERFACE
318319
#ifdef HAVE_MMAP

sql/sql_table.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7432,7 +7432,7 @@ static bool mysql_inplace_alter_table(THD *thd,
74327432
TR_table trt(thd, true);
74337433
if (thd->vers_update_trt && trt != *table_list)
74347434
{
7435-
if (opt_transaction_registry && trt.update())
7435+
if (use_transaction_registry && trt.update())
74367436
return true;
74377437
}
74387438

sql/table.cc

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8699,57 +8699,108 @@ bool TR_table::query_sees(bool &result, ulonglong trx_id1, ulonglong trx_id0,
86998699
return false;
87008700
}
87018701

8702+
void TR_table::warn_schema_incorrect(const char *reason)
8703+
{
8704+
if (MYSQL_VERSION_ID == table->s->mysql_version)
8705+
{
8706+
sql_print_error("`%s.%s` schema is incorrect: %s.", db, table_name, reason);
8707+
}
8708+
else
8709+
{
8710+
sql_print_error("`%s.%s` schema is incorrect: %s. Created with MariaDB %d, "
8711+
"now running %d.", db, table_name, reason, MYSQL_VERSION_ID,
8712+
static_cast<int>(table->s->mysql_version));
8713+
}
8714+
}
8715+
87028716
bool TR_table::check()
87038717
{
8704-
// InnoDB may not be loaded
87058718
if (!ha_resolve_by_legacy_type(thd, DB_TYPE_INNODB))
8706-
return false;
8719+
{
8720+
sql_print_information("`%s.%s` requires InnoDB storage engine.", db, table_name);
8721+
return true;
8722+
}
87078723

87088724
if (open())
8725+
{
8726+
sql_print_warning("`%s.%s` does not exist (open failed).", db, table_name);
87098727
return true;
8728+
}
87108729

87118730
if (table->file->ht->db_type != DB_TYPE_INNODB)
8731+
{
8732+
warn_schema_incorrect("Wrong table engine (expected InnoDB)");
87128733
return true;
8734+
}
8735+
8736+
#define WARN_SCHEMA(...) \
8737+
char reason[128]; \
8738+
snprintf(reason, 128, __VA_ARGS__); \
8739+
warn_schema_incorrect(reason);
87138740

8714-
if (table->s->fields != 5)
8741+
if (table->s->fields != FIELD_COUNT)
8742+
{
8743+
WARN_SCHEMA("Wrong field count (expected %d)", FIELD_COUNT);
87158744
return true;
8745+
}
87168746

87178747
if (table->field[FLD_TRX_ID]->type() != MYSQL_TYPE_LONGLONG)
8748+
{
8749+
WARN_SCHEMA("Wrong field %d type (expected BIGINT UNSIGNED)", FLD_TRX_ID);
87188750
return true;
8751+
}
87198752

87208753
if (table->field[FLD_COMMIT_ID]->type() != MYSQL_TYPE_LONGLONG)
8754+
{
8755+
WARN_SCHEMA("Wrong field %d type (expected BIGINT UNSIGNED)", FLD_COMMIT_ID);
87218756
return true;
8757+
}
87228758

87238759
if (table->field[FLD_BEGIN_TS]->type() != MYSQL_TYPE_TIMESTAMP)
8760+
{
8761+
WARN_SCHEMA("Wrong field %d type (expected TIMESTAMP(6))", FLD_BEGIN_TS);
87248762
return true;
8763+
}
87258764

87268765
if (table->field[FLD_COMMIT_TS]->type() != MYSQL_TYPE_TIMESTAMP)
8766+
{
8767+
WARN_SCHEMA("Wrong field %d type (expected TIMESTAMP(6))", FLD_COMMIT_TS);
87278768
return true;
8769+
}
87288770

87298771
if (table->field[FLD_ISO_LEVEL]->type() != MYSQL_TYPE_STRING ||
87308772
!(table->field[FLD_ISO_LEVEL]->flags & ENUM_FLAG))
8773+
{
8774+
wrong_enum:
8775+
WARN_SCHEMA("Wrong field %d type (expected ENUM('READ-UNCOMMITTED', "
8776+
"'READ-COMMITTED', 'REPEATABLE-READ', 'SERIALIZABLE'))",
8777+
FLD_ISO_LEVEL);
87318778
return true;
8779+
}
87328780

87338781
Field_enum *iso_level= static_cast<Field_enum *>(table->field[FLD_ISO_LEVEL]);
87348782
st_typelib *typelib= iso_level->typelib;
87358783

87368784
if (typelib->count != 4)
8737-
return true;
8785+
goto wrong_enum;
87388786

87398787
if (strcmp(typelib->type_names[0], "READ-UNCOMMITTED") ||
87408788
strcmp(typelib->type_names[1], "READ-COMMITTED") ||
87418789
strcmp(typelib->type_names[2], "REPEATABLE-READ") ||
87428790
strcmp(typelib->type_names[3], "SERIALIZABLE"))
87438791
{
8744-
return true;
8792+
goto wrong_enum;
87458793
}
87468794

87478795
if (!table->key_info || !table->key_info->key_part)
8748-
return true;
8796+
goto wrong_pk;
87498797

8750-
if (strcmp(table->key_info->key_part->field->field_name.str,
8751-
"transaction_id"))
8798+
if (strcmp(table->key_info->key_part->field->field_name.str, "transaction_id"))
8799+
{
8800+
wrong_pk:
8801+
WARN_SCHEMA("Wrong PRIMARY KEY (expected `transaction_id`)");
87528802
return true;
8803+
}
87538804

87548805
return false;
87558806
}

sql/table.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,6 +2967,8 @@ class TR_table: public TABLE_LIST
29672967
DBUG_ASSERT(iso_level <= ISO_SERIALIZABLE);
29682968
store(FLD_ISO_LEVEL, iso_level + 1);
29692969
}
2970+
2971+
void warn_schema_incorrect(const char *reason);
29702972
bool check();
29712973

29722974
public:

sql/vtmd.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ VTMD_table::update(THD *thd, const char* archive_name)
255255
}
256256

257257
quit:
258-
if (!result && opt_transaction_registry)
258+
if (!result && use_transaction_registry)
259259
{
260260
DBUG_ASSERT(thd->vers_update_trt);
261261
TR_table trt(thd, true);

0 commit comments

Comments
 (0)