Skip to content

Commit ff32b94

Browse files
committed
Setup explicit separate list for system table metrics
The `is_system_table` flag is also used for logical checks and not only for metrics anymore. This is causing corruption to show right now on the `_vt` tables, since they are now also treated special. On upgrades, the table layout can change and I suspect the `_vt` tables are not updated immediately as they are not actual system tables. But then the logic expects them later to be system tables. With this change I don't see the corruption anymore on the `_vt` tables.
1 parent 2ca1b0c commit ff32b94

File tree

7 files changed

+59
-22
lines changed

7 files changed

+59
-22
lines changed

storage/innobase/api/api0api.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ static ib_err_t ib_execute_insert_query_graph(
10701070

10711071
dict_table_n_rows_inc(table);
10721072

1073-
if (table->is_system_table) {
1073+
if (table->is_system_table_metrics) {
10741074
srv_stats.n_system_rows_inserted.inc();
10751075
} else {
10761076
srv_stats.n_rows_inserted.inc();
@@ -1395,13 +1395,13 @@ static inline ib_err_t ib_execute_update_query_graph(
13951395
if (node->is_delete) {
13961396
dict_table_n_rows_dec(table);
13971397

1398-
if (table->is_system_table) {
1398+
if (table->is_system_table_metrics) {
13991399
srv_stats.n_system_rows_deleted.inc();
14001400
} else {
14011401
srv_stats.n_rows_deleted.inc();
14021402
}
14031403
} else {
1404-
if (table->is_system_table) {
1404+
if (table->is_system_table_metrics) {
14051405
srv_stats.n_system_rows_updated.inc();
14061406
} else {
14071407
srv_stats.n_rows_updated.inc();

storage/innobase/dict/mem.cc

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ this program; if not, write to the Free Software Foundation, Inc.,
3535
other files in library. The code in this file is used to make a library for
3636
external tools. */
3737

38-
#include <algorithm>
3938
#include <new>
4039

4140
#include "dict0dict.h"
@@ -148,14 +147,45 @@ void dict_mem_table_free(dict_table_t *table) /*!< in: table */
148147
}
149148

150149
/** System databases */
151-
static std::vector<std::string> innobase_system_databases({
150+
static std::string innobase_system_databases[] = {
151+
"mysql/", "information_schema/", "performance_schema/", ""};
152+
153+
/** Determines if a table is a system table
154+
@param[in] name table_name
155+
@return true if table is system table */
156+
static bool dict_mem_table_is_system(const std::string name) {
157+
/* Table has the following format: database/table and some system table are
158+
of the form SYS_* */
159+
if (name.find('/') != std::string::npos) {
160+
size_t table_len = name.length();
161+
162+
std::string system_db = std::string(innobase_system_databases[0]);
163+
int i = 0;
164+
165+
while (system_db.compare("") != 0) {
166+
size_t len = system_db.length();
167+
168+
if (table_len > len && name.compare(0, len, system_db) == 0) {
169+
return true;
170+
}
171+
172+
system_db = std::string(innobase_system_databases[++i]);
173+
}
174+
175+
return false;
176+
} else {
177+
return true;
178+
}
179+
}
180+
181+
static std::vector<std::string> innobase_system_databases_metrics({
152182
"mysql/", "information_schema/", "performance_schema/"
153183
});
154184

155-
/** Determines if a table is a system table
185+
/** Determines if a table is a system table for metrics purposes
156186
@param[in] name table_name
157187
@return true if table is system table */
158-
static bool dict_mem_table_is_system(const std::string &name) {
188+
static bool dict_mem_table_is_system_metrics(const std::string &name) {
159189
/* Table has the following format: database/table and some system table are
160190
of the form SYS_* */
161191
if (name.find('/') == std::string::npos)
@@ -169,15 +199,15 @@ static bool dict_mem_table_is_system(const std::string &name) {
169199
return false;
170200
}
171201

172-
void dict_add_system_prefix(const char *pfx) {
202+
void dict_add_system_metrics_prefix(const char *pfx) {
173203
if (!pfx || !pfx[0])
174204
return;
175205

176206
std::string pfx_s = pfx;
177207
if (pfx_s[pfx_s.size()-1] != '/')
178208
pfx_s += '/';
179-
if (std::find(innobase_system_databases.begin(), innobase_system_databases.end(), pfx_s) == innobase_system_databases.end())
180-
innobase_system_databases.push_back(pfx_s);
209+
if (std::find(innobase_system_databases_metrics.begin(), innobase_system_databases_metrics.end(), pfx_s) == innobase_system_databases_metrics.end())
210+
innobase_system_databases_metrics.push_back(pfx_s);
181211
}
182212

183213
dict_table_t *dict_mem_table_create(const char *name, space_id_t space,
@@ -213,6 +243,7 @@ dict_table_t *dict_mem_table_create(const char *name, space_id_t space,
213243
table->flags2 = (unsigned int)flags2;
214244
table->name.m_name = mem_strdup(name);
215245
table->is_system_table = dict_mem_table_is_system(table->name.m_name);
246+
table->is_system_table_metrics = dict_mem_table_is_system_metrics(table->name.m_name);
216247
table->space = (unsigned int)space;
217248
table->dd_space_id = dd::INVALID_OBJECT_ID;
218249
table->n_t_cols = (unsigned int)(n_cols + table->get_n_sys_cols());

storage/innobase/dict/mem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,5 @@ const char *dict_add_col_name(const char *col_names, /*!< in: existing column
109109
/** Add the prefix 'pfx' to the list of database names that count as
110110
* system tables, rather than user tables, for the purposes of rows
111111
* {read,inserted,updated,deleted} counters. */
112-
void dict_add_system_prefix(const char *pfx);
112+
void dict_add_system_metrics_prefix(const char *pfx);
113113
#endif

storage/innobase/handler/ha_innodb.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5606,7 +5606,7 @@ static int innobase_init_files(dict_init_mode_t dict_init_mode,
56065606
char *copy = strdup(extra_system_table_prefixes);
56075607
char *saveptr, *tok;
56085608
for (tok=my_strtok_r(copy, ",", &saveptr); tok; tok=my_strtok_r(NULL, ",", &saveptr)) {
5609-
dict_add_system_prefix(tok);
5609+
dict_add_system_metrics_prefix(tok);
56105610
}
56115611
free(copy);
56125612
}
@@ -10299,7 +10299,7 @@ int ha_innobase::index_read(
1029910299
switch (ret) {
1030010300
case DB_SUCCESS:
1030110301
error = 0;
10302-
if (m_prebuilt->table->is_system_table) {
10302+
if (m_prebuilt->table->is_system_table_metrics) {
1030310303
srv_stats.n_system_rows_read.add(
1030410304
thd_get_thread_id(m_prebuilt->trx->mysql_thd), 1);
1030510305
} else if (!m_user_thd->security_context()->exclude_user_from_rows_read()) {
@@ -10547,7 +10547,7 @@ int ha_innobase::general_fetch(
1054710547
switch (ret) {
1054810548
case DB_SUCCESS:
1054910549
error = 0;
10550-
if (m_prebuilt->table->is_system_table) {
10550+
if (m_prebuilt->table->is_system_table_metrics) {
1055110551
srv_stats.n_system_rows_read.add(
1055210552
thd_get_thread_id(m_prebuilt->trx->mysql_thd), 1);
1055310553
} else if (!m_user_thd->security_context()->exclude_user_from_rows_read()) {

storage/innobase/include/dict0mem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,10 @@ struct dict_table_t {
20592059
or performance_schema) */
20602060
bool is_system_table;
20612061

2062+
/** True if the table stats should be seen as a system table (mysql, information_schema
2063+
or performance_schema) */
2064+
bool is_system_table_metrics;
2065+
20622066
/** Hash chain node. */
20632067
hash_node_t name_hash;
20642068

storage/innobase/mtr/mtr0log.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,7 @@ byte *mlog_parse_index(byte *ptr, const byte *end_ptr, dict_index_t **index) {
12821282
ind->n_fields = n - n_dropped;
12831283
ind->n_total_fields = n;
12841284
table->is_system_table = false;
1285+
table->is_system_table_metrics = false;
12851286

12861287
if (is_instant || is_versioned) {
12871288
if (is_versioned) {
@@ -1548,6 +1549,7 @@ static byte *mlog_parse_index_8029(byte *ptr, const byte *end_ptr,
15481549
ind->n_fields = n - n_dropped;
15491550
ind->n_total_fields = n;
15501551
table->is_system_table = false;
1552+
table->is_system_table_metrics = false;
15511553

15521554
if (is_instant || is_versioned) {
15531555
if (is_versioned) {

storage/innobase/row/row0mysql.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ static dberr_t row_insert_for_mysql_using_cursor(const byte *mysql_rec,
14851485
, with a latch. */
14861486
dict_table_n_rows_inc(node->table);
14871487

1488-
if (node->table->is_system_table) {
1488+
if (node->table->is_system_table_metrics) {
14891489
srv_stats.n_system_rows_inserted.inc();
14901490
} else {
14911491
srv_stats.n_rows_inserted.inc();
@@ -1679,7 +1679,7 @@ static dberr_t row_insert_for_mysql_using_ins_graph(const byte *mysql_rec,
16791679

16801680
que_thr_stop_for_mysql_no_error(thr, trx);
16811681

1682-
if (table->is_system_table) {
1682+
if (table->is_system_table_metrics) {
16831683
srv_stats.n_system_rows_inserted.inc();
16841684
} else {
16851685
srv_stats.n_rows_inserted.inc();
@@ -2225,7 +2225,7 @@ static dberr_t row_del_upd_for_mysql_using_cursor(row_prebuilt_t *prebuilt) {
22252225
if (node->is_delete) {
22262226
if (err == DB_SUCCESS) {
22272227
dict_table_n_rows_dec(prebuilt->table);
2228-
if (node->table->is_system_table) {
2228+
if (node->table->is_system_table_metrics) {
22292229
srv_stats.n_system_rows_deleted.inc();
22302230
} else {
22312231
srv_stats.n_rows_deleted.inc();
@@ -2239,7 +2239,7 @@ static dberr_t row_del_upd_for_mysql_using_cursor(row_prebuilt_t *prebuilt) {
22392239
err = row_update_for_mysql_using_cursor(node, delete_entries, thr);
22402240

22412241
if (err == DB_SUCCESS) {
2242-
if (node->table->is_system_table) {
2242+
if (node->table->is_system_table_metrics) {
22432243
srv_stats.n_system_rows_updated.inc();
22442244
} else {
22452245
srv_stats.n_rows_updated.inc();
@@ -2408,13 +2408,13 @@ static dberr_t row_update_for_mysql_using_upd_graph(const byte *mysql_rec,
24082408
with a latch. */
24092409
dict_table_n_rows_dec(prebuilt->table);
24102410

2411-
if (table->is_system_table) {
2411+
if (table->is_system_table_metrics) {
24122412
srv_stats.n_system_rows_deleted.inc();
24132413
} else {
24142414
srv_stats.n_rows_deleted.inc();
24152415
}
24162416
} else {
2417-
if (table->is_system_table) {
2417+
if (table->is_system_table_metrics) {
24182418
srv_stats.n_system_rows_updated.inc();
24192419
} else {
24202420
srv_stats.n_rows_updated.inc();
@@ -2639,13 +2639,13 @@ dberr_t row_update_cascade_for_mysql(
26392639
with a latch. */
26402640
dict_table_n_rows_dec(table);
26412641

2642-
if (table->is_system_table) {
2642+
if (table->is_system_table_metrics) {
26432643
srv_stats.n_system_rows_deleted.add((size_t)trx->id, 1);
26442644
} else {
26452645
srv_stats.n_rows_deleted.add((size_t)trx->id, 1);
26462646
}
26472647
} else {
2648-
if (table->is_system_table) {
2648+
if (table->is_system_table_metrics) {
26492649
srv_stats.n_system_rows_updated.add((size_t)trx->id, 1);
26502650
} else {
26512651
srv_stats.n_rows_updated.add((size_t)trx->id, 1);

0 commit comments

Comments
 (0)