Permalink
Browse files

BUG#21454472 AUTO-INCREMENT SEQUENCE GETS RESET

autoinc is reset to 0 when table is loaded after table is evicted
without any rows. The solution is store autoinc value in a map when
table is evicted, and restore autoinc when table is loaded.

Reviewed-by: Jimmy Yang <jimmy.yang@oracle.com>
RB: 9694
  • Loading branch information...
Shaohua Wang
Shaohua Wang committed Jul 24, 2015
1 parent edcc07b commit d404923aad4693dc152d02461f858d7ef218c336
@@ -0,0 +1,13 @@
CREATE TABLE t1 (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100)
) ENGINE=InnoDB AUTO_INCREMENT=99;
SET GLOBAL debug="+d,innodb_evict_autoinc_table";
SET GLOBAL innodb_ft_aux_table="test/t1";
ERROR 42000: Variable 'innodb_ft_aux_table' can't be set to the value of 'test/t1'
SET GLOBAL debug="-d,innodb_evict_autoinc_table";
INSERT INTO t1(name) VALUES('mysql');
SELECT * FROM t1;
id name
99 mysql
DROP TABLE t1;
@@ -0,0 +1,25 @@
#
# BUG#21454472 AUTO-INCREMENT SEQUENCE GETS RESET
#
--source include/have_innodb.inc
--source include/have_debug.inc
CREATE TABLE t1 (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100)
) ENGINE=InnoDB AUTO_INCREMENT=99;
SET GLOBAL debug="+d,innodb_evict_autoinc_table";
# Evict t1 from dictionary cache
-- error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL innodb_ft_aux_table="test/t1";
SET GLOBAL debug="-d,innodb_evict_autoinc_table";
INSERT INTO t1(name) VALUES('mysql');
SELECT * FROM t1;
DROP TABLE t1;
@@ -207,14 +207,6 @@ dict_index_remove_from_cache_low(
dict_index_t* index, /*!< in, own: index */
ibool lru_evict); /*!< in: TRUE if page being evicted
to make room in the table LRU list */
/**********************************************************************//**
Removes a table object from the dictionary cache. */
static
void
dict_table_remove_from_cache_low(
/*=============================*/
dict_table_t* table, /*!< in, own: table */
ibool lru_evict); /*!< in: TRUE if evicting from LRU */
#ifdef UNIV_DEBUG
/**********************************************************************//**
Validate the dictionary table LRU list.
@@ -748,6 +740,45 @@ dict_table_get_all_fts_indexes(
return(ib_vector_size(indexes));
}
/** Store autoinc value when the table is evicted.
@param[in] table table evicted */
UNIV_INTERN
void
dict_table_autoinc_store(
const dict_table_t* table)
{
ut_ad(mutex_own(&dict_sys->mutex));
if (table->autoinc != 0) {
ut_ad(dict_sys->autoinc_map->find(table->id)
== dict_sys->autoinc_map->end());
dict_sys->autoinc_map->insert(
std::pair<table_id_t, ib_uint64_t>(
table->id, table->autoinc));
}
}
/** Restore autoinc value when the table is loaded.
@param[in] table table loaded */
UNIV_INTERN
void
dict_table_autoinc_restore(
dict_table_t* table)
{
ut_ad(mutex_own(&dict_sys->mutex));
autoinc_map_t::iterator it;
it = dict_sys->autoinc_map->find(table->id);
if (it != dict_sys->autoinc_map->end()) {
table->autoinc = it->second;
ut_ad(table->autoinc != 0);
dict_sys->autoinc_map->erase(it);
}
}
/********************************************************************//**
Reads the next autoinc value (== autoinc counter value), 0 if not yet
initialized.
@@ -1041,6 +1072,8 @@ dict_init(void)
mutex_create(dict_foreign_err_mutex_key,
&dict_foreign_err_mutex, SYNC_NO_ORDER_CHECK);
}
dict_sys->autoinc_map = new autoinc_map_t();
}
/**********************************************************************//**
@@ -1288,6 +1321,8 @@ dict_table_add_to_cache(
UT_LIST_ADD_FIRST(table_LRU, dict_sys->table_non_LRU, table);
}
dict_table_autoinc_restore(table);
ut_ad(dict_lru_validate());
dict_sys->size += mem_heap_get_size(table->heap)
@@ -1978,7 +2013,6 @@ dict_table_change_id_in_cache(
/**********************************************************************//**
Removes a table object from the dictionary cache. */
static
void
dict_table_remove_from_cache_low(
/*=============================*/
@@ -2040,6 +2074,10 @@ dict_table_remove_from_cache_low(
ut_ad(dict_lru_validate());
if (lru_evict) {
dict_table_autoinc_store(table);
}
if (lru_evict && table->drop_aborted) {
/* Do as dict_table_try_drop_aborted() does. */
@@ -6330,6 +6368,8 @@ dict_close(void)
mutex_free(&dict_foreign_err_mutex);
}
delete dict_sys->autoinc_map;
mem_free(dict_sys);
dict_sys = NULL;
}
@@ -14288,6 +14288,12 @@ innodb_internal_table_validate(
}
dict_table_close(user_table, FALSE, TRUE);
DBUG_EXECUTE_IF("innodb_evict_autoinc_table",
mutex_enter(&dict_sys->mutex);
dict_table_remove_from_cache_low(user_table, TRUE);
mutex_exit(&dict_sys->mutex);
);
}
return(ret);
@@ -309,6 +309,21 @@ dict_table_autoinc_initialize(
dict_table_t* table, /*!< in/out: table */
ib_uint64_t value) /*!< in: next value to assign to a row */
__attribute__((nonnull));
/** Store autoinc value when the table is evicted.
@param[in] table table evicted */
UNIV_INTERN
void
dict_table_autoinc_store(
const dict_table_t* table);
/** Restore autoinc value when the table is loaded.
@param[in] table table loaded */
UNIV_INTERN
void
dict_table_autoinc_restore(
dict_table_t* table);
/********************************************************************//**
Reads the next autoinc value (== autoinc counter value), 0 if not yet
initialized.
@@ -368,6 +383,15 @@ dict_table_remove_from_cache(
dict_table_t* table) /*!< in, own: table */
__attribute__((nonnull));
/**********************************************************************//**
Removes a table object from the dictionary cache. */
UNIV_INTERN
void
dict_table_remove_from_cache_low(
/*=============================*/
dict_table_t* table, /*!< in, own: table */
ibool lru_evict); /*!< in: TRUE if table being evicted
to make room in the table LRU list */
/**********************************************************************//**
Renames a table object.
@return TRUE if success */
UNIV_INTERN
@@ -1543,6 +1567,8 @@ extern dict_sys_t* dict_sys;
/** the data dictionary rw-latch protecting dict_sys */
extern rw_lock_t dict_operation_lock;
typedef std::map<table_id_t, ib_uint64_t> autoinc_map_t;
/* Dictionary system struct */
struct dict_sys_t{
ib_mutex_t mutex; /*!< mutex protecting the data
@@ -1577,6 +1603,8 @@ struct dict_sys_t{
UT_LIST_BASE_NODE_T(dict_table_t)
table_non_LRU; /*!< List of tables that can't be
evicted from the cache */
autoinc_map_t* autoinc_map; /*!< Map to store table id and autoinc
when table is evicted */
};
#endif /* !UNIV_HOTBACKUP */

0 comments on commit d404923

Please sign in to comment.