16 #include "rpl_info_table_access.h"
17 #include "rpl_utility.h"
19 #include "sql_parse.h"
50 enum thr_lock_type lock_type,
52 Open_tables_backup* backup)
55 Query_tables_list query_tables_list_backup;
57 uint
flags= (MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK |
58 MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |
59 MYSQL_OPEN_IGNORE_FLUSH |
60 MYSQL_LOCK_IGNORE_TIMEOUT |
61 MYSQL_LOCK_RPL_INFO_TABLE);
63 DBUG_ENTER(
"Rpl_info_table_access::open_table");
69 if (thd->slave_thread || !current_thd)
83 thd->lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
84 thd->reset_n_backup_open_tables_state(backup);
86 tables.
init_one_table(dbstr.str, dbstr.length, tbstr.str, tbstr.length,
87 tbstr.str, lock_type);
91 close_thread_tables(thd);
92 thd->restore_backup_open_tables_state(backup);
93 thd->lex->restore_backup_query_tables_list(&query_tables_list_backup);
94 my_error(ER_NO_SUCH_TABLE, MYF(0), dbstr.str, tbstr.str);
98 DBUG_ASSERT(tables.table->s->
table_category == TABLE_CATEGORY_RPL_INFO);
100 if (tables.table->s->fields < max_num_field)
106 ha_rollback_trans(thd, FALSE);
107 close_thread_tables(thd);
108 thd->restore_backup_open_tables_state(backup);
109 thd->lex->restore_backup_query_tables_list(&query_tables_list_backup);
110 my_error(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2, MYF(0),
111 tables.table->s->db.str, tables.table->s->table_name.str,
112 max_num_field, tables.table->s->fields);
116 thd->lex->restore_backup_query_tables_list(&query_tables_list_backup);
118 *table= tables.table;
119 tables.table->use_all_columns();
146 Open_tables_backup *backup,
149 Query_tables_list query_tables_list_backup;
151 DBUG_ENTER(
"Rpl_info_table_access::close_table");
156 ha_rollback_trans(thd, FALSE);
165 if (saved_current_thd != current_thd)
168 ha_rollback_trans(thd, TRUE);
183 thd->lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
184 close_thread_tables(thd);
185 thd->lex->restore_backup_query_tables_list(&query_tables_list_backup);
186 thd->restore_backup_open_tables_state(backup);
210 uchar key[MAX_KEY_LENGTH];
212 DBUG_ENTER(
"Rpl_info_table_access::find_info");
217 if (table->s->primary_key >= MAX_KEY ||
218 !table->s->keys_in_use.is_set(table->s->primary_key))
224 DBUG_RETURN(ERROR_ID);
227 keyinfo= table->s->key_info + (uint) table->s->primary_key;
230 uint fieldnr= keyinfo->key_part[idx].fieldnr - 1;
235 if (field_values->
value[fieldnr].length() >
236 table->field[fieldnr]->field_length)
237 DBUG_RETURN(ERROR_ID);
239 table->field[fieldnr]->store(field_values->
value[fieldnr].c_ptr_safe(),
240 field_values->
value[fieldnr].length(),
243 key_copy(key, table->record[0], table->key_info, table->key_info->
key_length);
247 DBUG_RETURN(NOT_FOUND_ID);
249 DBUG_RETURN(FOUND_ID);
274 enum enum_return_id
ret= NOT_FOUND_ID;
276 DBUG_ENTER(
"Rpl_info_table_access::scan_info");
279 DBUG_RETURN(ERROR_ID);
288 if (counter == instance)
291 error= HA_ERR_END_OF_FILE;
295 case HA_ERR_END_OF_FILE:
300 DBUG_PRINT(
"info", (
"Failed to get next record"
301 " (ha_rnd_next returns %d)", error));
334 DBUG_ENTER(
"Rpl_info_table_access::count_info");
348 case HA_ERR_END_OF_FILE:
353 DBUG_PRINT(
"info", (
"Failed to get next record"
354 " (ha_rnd_next returns %d)", error));
362 DBUG_RETURN(end ?
false :
true);
381 DBUG_ENTER(
"Rpl_info_table_access::load_info_values");
382 char buff[MAX_FIELD_WIDTH];
383 String str(buff,
sizeof(buff), &my_charset_bin);
386 while (field_idx < max_num_field)
388 fields[field_idx]->val_str(&str);
389 field_values->
value[field_idx].copy(str.c_ptr_safe(), str.length(),
413 DBUG_ENTER(
"Rpl_info_table_access::store_info_values");
416 while (field_idx < max_num_field)
418 fields[field_idx]->set_notnull();
420 if (fields[field_idx]->store(field_values->
value[field_idx].c_ptr_safe(),
421 field_values->
value[field_idx].length(),
424 my_error(ER_RPL_INFO_DATA_TOO_LONG, MYF(0),
425 fields[field_idx]->field_name);
445 saved_current_thd= current_thd;
450 thd->thread_stack= (
char*) &thd;
451 thd->store_globals();
452 thd->security_ctx->skip_grants();
453 thd->system_thread= SYSTEM_THREAD_INFO_REPOSITORY;
473 DBUG_ENTER(
"Rpl_info::drop_thd");
475 if (saved_current_thd != current_thd)
478 my_pthread_setspecific_ptr(THR_THD, NULL);