3098
3098
ut_ad(!mutex_own(&kernel_mutex));
3100
/* The convoluted mutex acquire is to overcome latching order
3101
issues: The problem is that the fil_mutex is at a lower level
3102
than the tablespace latch and the buffer pool mutex. We have to
3103
first prevent any operations on the file system by acquiring the
3104
dictionary mutex. Then acquire the tablespace latch to obey the
3105
latching order and then release the dictionary mutex. That way we
3106
ensure that the tablespace instance can't be freed while we are
3107
examining its contents (see fil_space_free()).
3109
However, there is one further complication, we release the fil_mutex
3110
when we need to invalidate the the pages in the buffer pool and we
3111
reacquire the fil_mutex when deleting and freeing the tablespace
3112
instance in fil0fil.c. Here we need to account for that situation
3115
mutex_enter(&dict_sys->mutex);
3117
/* At this stage there is no guarantee that the tablespace even
3118
exists in the cache. */
3120
if (fil_tablespace_deleted_or_being_deleted_in_mem(space, -1)) {
3122
mutex_exit(&dict_sys->mutex);
3124
return(ULLINT_UNDEFINED);
3100
3127
mtr_start(&mtr);
3102
3129
latch = fil_space_get_latch(space, &flags);
3131
/* This should ensure that the tablespace instance can't be freed
3132
by another thread. However, the tablespace pages can still be freed
3133
from the buffer pool. We need to check for that again. */
3103
3135
zip_size = dict_table_flags_to_zip_size(flags);
3105
3137
mtr_x_lock(latch, &mtr);
3139
mutex_exit(&dict_sys->mutex);
3141
/* At this point it is possible for the tablespace to be deleted and
3142
its pages removed from the buffer pool. We need to check for that
3143
situation. However, the tablespace instance can't be deleted because
3144
our latching above should ensure that. */
3146
if (fil_tablespace_is_being_deleted(space)) {
3150
return(ULLINT_UNDEFINED);
3153
/* From here on even if the user has dropped the tablespace, the
3154
pages _must_ still exist in the buffer pool and the tablespace
3155
instance _must_ be in the file system hash table. */
3107
3157
space_header = fsp_get_space_header(space, zip_size, &mtr);
3109
3159
size = mtr_read_ulint(space_header + FSP_SIZE, MLOG_4BYTES, &mtr);