diff options
author | unknown <istruewing@chilla.local> | 2007-01-31 18:49:07 +0100 |
---|---|---|
committer | unknown <istruewing@chilla.local> | 2007-01-31 18:49:07 +0100 |
commit | 3514500e8d46ce566e80a3b052f47ab393187cc3 (patch) | |
tree | c59739dc4babff33523b8cf8656966e704cea069 /include/keycache.h | |
parent | 247bd923c2d7baee7a2bef5de3bbf9ee3b940abc (diff) | |
download | mariadb-git-3514500e8d46ce566e80a3b052f47ab393187cc3.tar.gz |
Bug#17332 - changing key_buffer_size on a running server
can crash under load
Resizing a key cache while it was in heavy use could crash the
server. There were several race conditions.
I reworked some of the algorithms to fix the race conditions.
No test case. Repeating the crashes requires heavy concurrent
load on the key cache. A test script is attached to the bug report.
More explanations to the changes are contained in a text file
attached to the bug report.
include/keycache.h:
Bug#17332 - changing key_buffer_size on a running server
can crash under load
Added KEY_CACHE components in_resize and waiting_for_resize_cnt.
mysys/mf_keycache.c:
Bug#17332 - changing key_buffer_size on a running server
can crash under load
Changed resize_key_cache() to not disable the key cache
after the flush phase. Changed queue handling to use
standard functions. Wake all threads waiting on resize_queue.
We can now have read/write threads waiting there (see below).
Combined add_to_queue() and the wait loops that were always
following it to the new function wait_on_queue().
Combined release_queue() and the condition that was always
preceding it to the new function release_whole_queue().
Added code to flag and respect the exceptional situation
BLOCK_IN_EVICTION.
Rewrote the resize branch of find_key_block().
Added code to the eviction handling in find_key_block()
to catch more exceptional cases.
Changed key_cache_read(), key_cache_insert() and key_cache_write()
so that they lock keycache->cache_lock whenever the key cache is
initialized. Checking for a disabled cache and incrementing and
decrementing the "resize counter" is always done within the lock.
Locking and unlocking as well as counting the "resize counter" is
now done once outside the loop. All three functions can now handle
a NULL return from find_key_block. This happens in the flush phase
of a resize and demands direct file I/O. Care is taken for
secondary requests (PAGE_WAIT_TO_BE_READ) to wait in any case.
Moved block status changes behind the copying of buffer data.
key_cache_insert() does now read the block if the caller did
supply less data than a full cache block.
key_cache_write() does now take care of parallel running flushes
(BLOCK_FOR_UPDATE, BLOCK_IN_FLUSHWRITE).
Changed free_block() to un-initialize block variables in the
correct order and respect an exceptional BLOCK_IN_EVICTION state.
Changed flushing to take care for parallel running writes.
Changed flushing to avoid freeing blocks in eviction.
Changed flushing to consider that parallel writes can move blocks
from the file_blocks hash to the changed_blocks hash.
Changed flushing to take care for other parallel flushes.
Changed flushing to assure that it ends with everything flushed.
Added some comments and debugging statements. ;-)
mysys/my_static.c:
Bug#17332 - changing key_buffer_size on a running server
can crash under load
Removed an unused global variable.
sql/handler.cc:
Bug#17332 - changing key_buffer_size on a running server
can crash under load
Changed types of local variables to match their use
for init_key_cache().
sql/sql_table.cc:
Bug#17332 - changing key_buffer_size on a running server
can crash under load
Changed TL_READ to TL_READ_NO_INSERT in mysql_preload_keys.
storage/myisam/ha_myisam.cc:
Bug#17332 - changing key_buffer_size on a running server
can crash under load
Moved an automatic (stack) variable to the scope where it is used.
storage/myisam/mi_preload.c:
Bug#17332 - changing key_buffer_size on a running server
can crash under load
Added some preliminary code to
- allow LOAD INDEX to load indexes of different block size,
- align load chunks to key cache blocks.
Diffstat (limited to 'include/keycache.h')
-rw-r--r-- | include/keycache.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/include/keycache.h b/include/keycache.h index dc763b8cc08..4d99c68844f 100644 --- a/include/keycache.h +++ b/include/keycache.h @@ -44,6 +44,7 @@ typedef struct st_keycache_wqueue typedef struct st_key_cache { my_bool key_cache_inited; + my_bool in_resize; /* true during resize operation */ my_bool resize_in_flush; /* true during flush of resize operation */ my_bool can_be_used; /* usage of cache for read/write is allowed */ uint key_cache_shift; @@ -72,6 +73,11 @@ typedef struct st_key_cache BLOCK_LINK *used_ins; /* ptr to the insertion block in LRU chain */ pthread_mutex_t cache_lock; /* to lock access to the cache structure */ KEYCACHE_WQUEUE resize_queue; /* threads waiting during resize operation */ + /* + Waiting for a zero resize count. Using a queue for symmetry though + only one thread can wait here. + */ + KEYCACHE_WQUEUE waiting_for_resize_cnt; KEYCACHE_WQUEUE waiting_for_hash_link; /* waiting for a free hash link */ KEYCACHE_WQUEUE waiting_for_block; /* requests waiting for a free block */ BLOCK_LINK *changed_blocks[CHANGED_BLOCKS_HASH]; /* hash for dirty file bl.*/ |