| 1 | /* Copyright (C) 2003-2007 MySQL AB |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License as published by |
| 5 | the Free Software Foundation; version 2 of the License. |
| 6 | |
| 7 | This program is distributed in the hope that it will be useful, |
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | GNU General Public License for more details. |
| 11 | |
| 12 | You should have received a copy of the GNU General Public License |
| 13 | along with this program; if not, write to the Free Software |
| 14 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ |
| 15 | |
| 16 | /* |
| 17 | Handling of multiple key caches |
| 18 | |
| 19 | The idea is to have a thread safe hash on the table name, |
| 20 | with a default key cache value that is returned if the table name is not in |
| 21 | the cache. |
| 22 | */ |
| 23 | |
| 24 | #include "maria_def.h"cxx . . $ `<file>/storage/maria/maria_def.h`/ |
| 25 | #include "ma_pagecache.h"cxx . . $ `<file>/storage/maria/ma_pagecache.h`/ |
| 26 | #include <hash.h>cxx . . $ `<file>/include/hash.h`/ |
| 27 | #include <m_string.h>cxx . . $ `<file>/include/m_string.h`/ |
| 28 | #include "../../mysys/my_safehash.h"cxx . . $ `<file>/mysys/my_safehash.h`/ |
| 29 | |
| 30 | /***************************************************************************** |
| 31 | Functions to handle the pagecache objects |
| 32 | *****************************************************************************/ |
| 33 | |
| 34 | /* Variable to store all key cache objects */ |
| 35 | static SAFE_HASHcxx . . $ SAFE_HASH# pagecache_hashcxx . . $ pagecache_hash.; |
| 36 | |
| 37 | |
| 38 | my_boolcxx . . $ my_bool# multi_pagecache_initcxx . . $ multi_pagecache_init(6e9c618e4dd2eafc).(void) |
| 39 | { |
| 40 | return safe_hash_initcxx . . $ safe_hash_init(c4eb53e0ab2be53f).(&pagecache_hashcxx . . $ pagecache_hash., 16, (ucharcxx . . $ uchar#*) maria_pagecachecxx . . $ maria_pagecache.); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | void multi_pagecache_freecxx . . $ multi_pagecache_free(49f6e7a06ebc5aa8).(void) |
| 45 | { |
| 46 | safe_hash_freecxx . . $ safe_hash_free(fe428ce838e63110).(&pagecache_hashcxx . . $ pagecache_hash.); |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | Get a key cache to be used for a specific table. |
| 51 | |
| 52 | SYNOPSIS |
| 53 | multi_pagecache_search() |
| 54 | key key to find (usually table path) |
| 55 | uint length Length of key. |
| 56 | def Default value if no key cache |
| 57 | |
| 58 | NOTES |
| 59 | This function is coded in such a way that we will return the |
| 60 | default key cache even if one never called multi_pagecache_init. |
| 61 | This will ensure that it works with old MyISAM clients. |
| 62 | |
| 63 | RETURN |
| 64 | key cache to use |
| 65 | */ |
| 66 | |
| 67 | PAGECACHEcxx . . $ PAGECACHE# *multi_pagecache_searchcxx . . $ multi_pagecache_search(2943b023477beb1d).(ucharcxx . . $ uchar# *key, uintcxx . . $ uint# length, |
| 68 | PAGECACHEcxx . . $ PAGECACHE# *def) |
| 69 | { |
| 70 | if (!pagecache_hashcxx . . $ pagecache_hash..hashcxx . . $ st_safe_hash_with_default#hash..recordscxx . . $ st_hash#records.) |
| 71 | return def; |
| 72 | return (PAGECACHEcxx . . $ PAGECACHE#*) safe_hash_searchcxx . . $ safe_hash_search(1c9606cc74cc46e5).(&pagecache_hashcxx . . $ pagecache_hash., key, length, |
| 73 | (void*) def); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | /* |
| 78 | Assosiate a key cache with a key |
| 79 | |
| 80 | |
| 81 | SYONOPSIS |
| 82 | multi_pagecache_set() |
| 83 | key key (path to table etc..) |
| 84 | length Length of key |
| 85 | pagecache cache to assococite with the table |
| 86 | |
| 87 | NOTES |
| 88 | This can be used both to insert a new entry and change an existing |
| 89 | entry |
| 90 | */ |
| 91 | |
| 92 | |
| 93 | my_boolcxx . . $ my_bool# multi_pagecache_setcxx . . $ multi_pagecache_set(59edd29ac1140086).(const ucharcxx . . $ uchar# *key, uintcxx . . $ uint# length, |
| 94 | PAGECACHEcxx . . $ PAGECACHE# *pagecache) |
| 95 | { |
| 96 | return safe_hash_setcxx . . $ safe_hash_set(8008e205fce338b9).(&pagecache_hashcxx . . $ pagecache_hash., key, length, (ucharcxx . . $ uchar#*) pagecache); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | void multi_pagecache_changecxx . . $ multi_pagecache_change(8e2c9b1382507802).(PAGECACHEcxx . . $ PAGECACHE# *old_data, |
| 101 | PAGECACHEcxx . . $ PAGECACHE# *new_data) |
| 102 | { |
| 103 | safe_hash_changecxx . . $ safe_hash_change(8ba9ba868b826381).(&pagecache_hashcxx . . $ pagecache_hash., (ucharcxx . . $ uchar#*) old_data, (ucharcxx . . $ uchar#*) new_data); |
| 104 | } |