diff options
author | Timothy Smith <timothy.smith@sun.com> | 2008-12-14 12:25:33 -0700 |
---|---|---|
committer | Timothy Smith <timothy.smith@sun.com> | 2008-12-14 12:25:33 -0700 |
commit | f6bf85c09e54b8232697c3fa6c85a7d61599bf6b (patch) | |
tree | 30a5f966fb71d9dcab35271e5bdbb3bf77542552 /storage/innobase/dict/dict0dict.c | |
parent | 1c0d9aa0825ec1341a31433d3f05e56f22def977 (diff) | |
download | mariadb-git-f6bf85c09e54b8232697c3fa6c85a7d61599bf6b.tar.gz |
Complete application of InnoDB snapshot innodb-5.1-ss2545.
Fix race condition which could result in freeing a struct that is
still in use by another thread.
Detailed revision comments:
r2537 | inaam | 2008-07-15 20:46:03 +0300 (Tue, 15 Jul 2008) | 12 lines
branches/5.1 issue# 4
Fixed a timing hole where a thread dropping an index can free the
in-memory index struct while another thread is still using
that structure to remove entries from adaptive hash index belonging
to one of the pages that belongs to the index being dropped.
The fix is to have a reference counter in the index struct and to
wait for this counter to drop to zero beforing freeing the struct.
Reviewed by: Heikki
r2543 | inaam | 2008-07-22 18:57:43 +0300 (Tue, 22 Jul 2008) | 7 lines
branches/5.1:
Removed UNIV_INLINE qualifier from btr_search_info_get_ref_count().
Otherwise compilation failed on non-debug builds.
Pointed by: Vasil
Diffstat (limited to 'storage/innobase/dict/dict0dict.c')
-rw-r--r-- | storage/innobase/dict/dict0dict.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c index 5eaa44b4615..7bc700c4268 100644 --- a/storage/innobase/dict/dict0dict.c +++ b/storage/innobase/dict/dict0dict.c @@ -1394,12 +1394,59 @@ dict_index_remove_from_cache( dict_index_t* index) /* in, own: index */ { ulint size; + ulint retries = 0; + btr_search_t* info; ut_ad(table && index); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); ut_ad(mutex_own(&(dict_sys->mutex))); + /* We always create search info whether or not adaptive + hash index is enabled or not. */ + info = index->search_info; + ut_ad(info); + + /* We are not allowed to free the in-memory index struct + dict_index_t until all entries in the adaptive hash index + that point to any of the page belonging to his b-tree index + are dropped. This is so because dropping of these entries + require access to dict_index_t struct. To avoid such scenario + We keep a count of number of such pages in the search_info and + only free the dict_index_t struct when this count drops to + zero. */ + + for (;;) { + ulint ref_count = btr_search_info_get_ref_count(info); + if (ref_count == 0) { + break; + } + + /* Sleep for 10ms before trying again. */ + os_thread_sleep(10000); + ++retries; + + if (retries % 500 == 0) { + /* No luck after 5 seconds of wait. */ + fprintf(stderr, "InnoDB: Error: Waited for" + " %lu secs for hash index" + " ref_count (%lu) to drop" + " to 0.\n" + "index: \"%s\"" + " table: \"%s\"\n", + retries/100, + ref_count, + index->name, + table->name); + } + + /* To avoid a hang here we commit suicide if the + ref_count doesn't drop to zero in 600 seconds. */ + if (retries >= 60000) { + ut_error; + } + } + rw_lock_free(&index->lock); /* Remove the index from the list of indexes of the table */ |