| 2977 | */ |
| 2978 | |
| 2979 | int key_cache_write(KEY_CACHE *keycache, |
| 2980 | File file, my_off_t filepos, int level, |
| 2981 | uchar *buff, uint length, |
| 2982 | uint block_length __attribute__((unused)), |
| 2983 | int dont_write) |
| 2984 | { |
| 2985 | my_bool locked_and_incremented= FALSE; |
| 2986 | int error=0; |
| 2987 | DBUG_ENTER("key_cache_write"); |
| 2988 | DBUG_PRINT("enter", |
| 2989 | ("fd: %u pos: %lu length: %u block_length: %u" |
| 2990 | " key_block_length: %u", |
| 2991 | (uint) file, (ulong) filepos, length, block_length, |
| 2992 | keycache ? keycache->key_cache_block_size : 0)); |
| 2993 | |
| 2994 | if (!dont_write) |
| 2995 | { |
| 2996 | /* purecov: begin inspected */ |
| 2997 | /* Not used in the server. */ |
| 2998 | /* Force writing from buff into disk. */ |
| 2999 | keycache->global_cache_w_requests++; |
| 3000 | keycache->global_cache_write++; |
| 3001 | if (my_pwrite(file, buff, length, filepos, MYF(MY_NABP | MY_WAIT_IF_FULL))) |
| 3002 | DBUG_RETURN(1); |
| 3003 | /* purecov: end */ |
| 3004 | } |
| 3005 | |
| 3006 | #if !defined(DBUG_OFF) && defined(EXTRA_DEBUG) |
| 3007 | DBUG_EXECUTE("check_keycache", |
| 3008 | test_key_cache(keycache, "start of key_cache_write", 1);); |
| 3009 | #endif |
| 3010 | |
| 3011 | if (keycache->key_cache_inited) |
| 3012 | { |
| 3013 | /* Key cache is used */ |
| 3014 | reg1 BLOCK_LINK *block; |
| 3015 | uint read_length; |
| 3016 | uint offset; |
| 3017 | int page_st; |
| 3018 | |
| 3019 | if (MYSQL_KEYCACHE_WRITE_START_ENABLED()) |
| 3020 | { |
| 3021 | MYSQL_KEYCACHE_WRITE_START(my_filename(file), length, |
| 3022 | (ulong) (keycache->blocks_used * |
| 3023 | keycache->key_cache_block_size), |
| 3024 | (ulong) (keycache->blocks_unused * |
| 3025 | keycache->key_cache_block_size)); |
| 3026 | } |
| 3027 | |
| 3028 | /* |
| 3029 | When the key cache is once initialized, we use the cache_lock to |
| 3030 | reliably distinguish the cases of normal operation, resizing, and |
| 3031 | disabled cache. We always increment and decrement |
| 3032 | 'cnt_for_resize_op' so that a resizer can wait for pending I/O. |
| 3033 | */ |
| 3034 | keycache_pthread_mutex_lock(&keycache->cache_lock); |
| 3035 | /* |
| 3036 | Cache resizing has two phases: Flushing and re-initializing. In |
nothing calls this directly
no test coverage detected