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 02111-1301 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" |
25 | #include "ma_pagecache.h" |
26 | #include <hash.h> |
27 | #include <m_string.h> |
28 | #include "../../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_HASH pagecache_hash; |
36 | |
37 | |
38 | my_bool multi_pagecache_init(void) |
39 | { |
40 | return safe_hash_init(&pagecache_hash, 16, (uchar*) maria_pagecache); |
41 | } |
42 | |
43 | |
44 | void multi_pagecache_free(void) |
45 | { |
46 | safe_hash_free(&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 | PAGECACHE *multi_pagecache_search(uchar *key, uint length, |
68 | PAGECACHE *def) |
69 | { |
70 | if (!pagecache_hash.hash.records) |
71 | return def; |
72 | return (PAGECACHE*) safe_hash_search(&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_bool multi_pagecache_set(const uchar *key, uint length, |
94 | PAGECACHE *pagecache) |
95 | { |
96 | return safe_hash_set(&pagecache_hash, key, length, (uchar*) pagecache); |
97 | } |
98 | |
99 | |
100 | void multi_pagecache_change(PAGECACHE *old_data, |
101 | PAGECACHE *new_data) |
102 | { |
103 | safe_hash_change(&pagecache_hash, (uchar*) old_data, (uchar*) new_data); |
104 | } |
105 | |