1
by brian
clean slate |
1 |
/* Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
670.2.2
by Monty Taylor
Got rid of the rest of common_includes. Now on to server_includes. |
16 |
#include <drizzled/server_includes.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
17 |
#include <drizzled/table.h> |
1
by brian
clean slate |
18 |
#include "ha_blackhole.h" |
19 |
||
960.2.24
by Monty Taylor
Changed handlerton to StorageEngine. |
20 |
/* Static declarations for StorageEngine */
|
1
by brian
clean slate |
21 |
|
960.2.24
by Monty Taylor
Changed handlerton to StorageEngine. |
22 |
static handler *blackhole_create_handler(StorageEngine *hton, |
1
by brian
clean slate |
23 |
TABLE_SHARE *table, |
24 |
MEM_ROOT *mem_root) |
|
25 |
{
|
|
26 |
return new (mem_root) ha_blackhole(hton, table); |
|
27 |
}
|
|
28 |
||
29 |
||
30 |
/* Static declarations for shared structures */
|
|
31 |
||
32 |
static pthread_mutex_t blackhole_mutex; |
|
33 |
static HASH blackhole_open_tables; |
|
34 |
||
35 |
static st_blackhole_share *get_share(const char *table_name); |
|
36 |
static void free_share(st_blackhole_share *share); |
|
37 |
||
38 |
/*****************************************************************************
|
|
39 |
** BLACKHOLE tables
|
|
40 |
*****************************************************************************/
|
|
41 |
||
960.2.24
by Monty Taylor
Changed handlerton to StorageEngine. |
42 |
ha_blackhole::ha_blackhole(StorageEngine *hton, |
1
by brian
clean slate |
43 |
TABLE_SHARE *table_arg) |
44 |
:handler(hton, table_arg) |
|
45 |
{}
|
|
46 |
||
47 |
||
48 |
static const char *ha_blackhole_exts[] = { |
|
461
by Monty Taylor
Removed NullS. bu-bye. |
49 |
NULL
|
1
by brian
clean slate |
50 |
};
|
51 |
||
52 |
const char **ha_blackhole::bas_ext() const |
|
53 |
{
|
|
54 |
return ha_blackhole_exts; |
|
55 |
}
|
|
56 |
||
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
57 |
|
58 |
uint32_t ha_blackhole::index_flags(uint32_t inx, uint32_t, bool) const |
|
59 |
{
|
|
60 |
return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT) ? |
|
61 |
0 : HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE | |
|
62 |
HA_READ_ORDER | HA_KEYREAD_ONLY); |
|
63 |
}
|
|
64 |
||
653
by Brian Aker
More solaris bits |
65 |
int ha_blackhole::open(const char *name, int, uint32_t) |
1
by brian
clean slate |
66 |
{
|
67 |
if (!(share= get_share(name))) |
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
68 |
return(HA_ERR_OUT_OF_MEM); |
1
by brian
clean slate |
69 |
|
70 |
thr_lock_data_init(&share->lock, &lock, NULL); |
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
71 |
return(0); |
1
by brian
clean slate |
72 |
}
|
73 |
||
74 |
int ha_blackhole::close(void) |
|
75 |
{
|
|
76 |
free_share(share); |
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
77 |
return(0); |
1
by brian
clean slate |
78 |
}
|
79 |
||
653
by Brian Aker
More solaris bits |
80 |
int ha_blackhole::create(const char *, Table *, HA_CREATE_INFO *) |
1
by brian
clean slate |
81 |
{
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
82 |
return(0); |
1
by brian
clean slate |
83 |
}
|
84 |
||
653
by Brian Aker
More solaris bits |
85 |
const char *ha_blackhole::index_type(uint32_t) |
1
by brian
clean slate |
86 |
{
|
249
by Brian Aker
Random key cleanup (it is a friday...) |
87 |
return("BTREE"); |
1
by brian
clean slate |
88 |
}
|
89 |
||
653
by Brian Aker
More solaris bits |
90 |
int ha_blackhole::write_row(unsigned char *) |
1
by brian
clean slate |
91 |
{
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
92 |
return(table->next_number_field ? update_auto_increment() : 0); |
1
by brian
clean slate |
93 |
}
|
94 |
||
653
by Brian Aker
More solaris bits |
95 |
int ha_blackhole::rnd_init(bool) |
1
by brian
clean slate |
96 |
{
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
97 |
return(0); |
1
by brian
clean slate |
98 |
}
|
99 |
||
100 |
||
653
by Brian Aker
More solaris bits |
101 |
int ha_blackhole::rnd_next(unsigned char *) |
1
by brian
clean slate |
102 |
{
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
103 |
return(HA_ERR_END_OF_FILE); |
1
by brian
clean slate |
104 |
}
|
105 |
||
106 |
||
653
by Brian Aker
More solaris bits |
107 |
int ha_blackhole::rnd_pos(unsigned char *, unsigned char *) |
1
by brian
clean slate |
108 |
{
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
109 |
assert(0); |
110 |
return(0); |
|
1
by brian
clean slate |
111 |
}
|
112 |
||
113 |
||
653
by Brian Aker
More solaris bits |
114 |
void ha_blackhole::position(const unsigned char *) |
1
by brian
clean slate |
115 |
{
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
116 |
assert(0); |
117 |
return; |
|
1
by brian
clean slate |
118 |
}
|
119 |
||
120 |
||
482
by Brian Aker
Remove uint. |
121 |
int ha_blackhole::info(uint32_t flag) |
1
by brian
clean slate |
122 |
{
|
212.6.9
by Mats Kindahl
Removing extreneous explicit casts for blackhole storage engine. |
123 |
memset(&stats, 0, sizeof(stats)); |
1
by brian
clean slate |
124 |
if (flag & HA_STATUS_AUTO) |
125 |
stats.auto_increment_value= 1; |
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
126 |
return(0); |
1
by brian
clean slate |
127 |
}
|
128 |
||
653
by Brian Aker
More solaris bits |
129 |
int ha_blackhole::external_lock(Session *, int) |
1
by brian
clean slate |
130 |
{
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
131 |
return(0); |
1
by brian
clean slate |
132 |
}
|
133 |
||
134 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
135 |
THR_LOCK_DATA **ha_blackhole::store_lock(Session *session, |
1
by brian
clean slate |
136 |
THR_LOCK_DATA **to, |
137 |
enum thr_lock_type lock_type) |
|
138 |
{
|
|
139 |
if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK) |
|
140 |
{
|
|
141 |
/*
|
|
142 |
Here is where we get into the guts of a row level lock.
|
|
143 |
If TL_UNLOCK is set
|
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
144 |
If we are not doing a LOCK Table or DISCARD/IMPORT
|
1
by brian
clean slate |
145 |
TABLESPACE, then allow multiple writers
|
146 |
*/
|
|
147 |
||
148 |
if ((lock_type >= TL_WRITE_CONCURRENT_INSERT && |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
149 |
lock_type <= TL_WRITE) && !session_in_lock_tables(session) |
150 |
&& !session_tablespace_op(session)) |
|
1
by brian
clean slate |
151 |
lock_type = TL_WRITE_ALLOW_WRITE; |
152 |
||
153 |
/*
|
|
154 |
In queries of type INSERT INTO t1 SELECT ... FROM t2 ...
|
|
155 |
MySQL would use the lock TL_READ_NO_INSERT on t2, and that
|
|
156 |
would conflict with TL_WRITE_ALLOW_WRITE, blocking all inserts
|
|
157 |
to t2. Convert the lock to a normal read lock to allow
|
|
158 |
concurrent inserts to t2.
|
|
159 |
*/
|
|
160 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
161 |
if (lock_type == TL_READ_NO_INSERT && !session_in_lock_tables(session)) |
1
by brian
clean slate |
162 |
lock_type = TL_READ; |
163 |
||
164 |
lock.type= lock_type; |
|
165 |
}
|
|
166 |
*to++= &lock; |
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
167 |
return(to); |
1
by brian
clean slate |
168 |
}
|
169 |
||
170 |
||
653
by Brian Aker
More solaris bits |
171 |
int ha_blackhole::index_read_map(unsigned char *, const unsigned char *, |
172 |
key_part_map, enum ha_rkey_function) |
|
173 |
{
|
|
174 |
return(HA_ERR_END_OF_FILE); |
|
175 |
}
|
|
176 |
||
177 |
||
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
178 |
int ha_blackhole::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *, |
653
by Brian Aker
More solaris bits |
179 |
key_part_map, enum ha_rkey_function) |
180 |
{
|
|
181 |
return(HA_ERR_END_OF_FILE); |
|
182 |
}
|
|
183 |
||
184 |
||
185 |
int ha_blackhole::index_read_last_map(unsigned char *, const unsigned char *, key_part_map) |
|
186 |
{
|
|
187 |
return(HA_ERR_END_OF_FILE); |
|
188 |
}
|
|
189 |
||
190 |
||
191 |
int ha_blackhole::index_next(unsigned char *) |
|
192 |
{
|
|
193 |
return(HA_ERR_END_OF_FILE); |
|
194 |
}
|
|
195 |
||
196 |
||
197 |
int ha_blackhole::index_prev(unsigned char *) |
|
198 |
{
|
|
199 |
return(HA_ERR_END_OF_FILE); |
|
200 |
}
|
|
201 |
||
202 |
||
203 |
int ha_blackhole::index_first(unsigned char *) |
|
204 |
{
|
|
205 |
return(HA_ERR_END_OF_FILE); |
|
206 |
}
|
|
207 |
||
208 |
||
209 |
int ha_blackhole::index_last(unsigned char *) |
|
1
by brian
clean slate |
210 |
{
|
51.3.8
by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines |
211 |
return(HA_ERR_END_OF_FILE); |
1
by brian
clean slate |
212 |
}
|
213 |
||
214 |
||
215 |
static st_blackhole_share *get_share(const char *table_name) |
|
216 |
{
|
|
217 |
st_blackhole_share *share; |
|
482
by Brian Aker
Remove uint. |
218 |
uint32_t length; |
1
by brian
clean slate |
219 |
|
220 |
length= (uint) strlen(table_name); |
|
221 |
pthread_mutex_lock(&blackhole_mutex); |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
222 |
|
1
by brian
clean slate |
223 |
if (!(share= (st_blackhole_share*) hash_search(&blackhole_open_tables, |
481
by Brian Aker
Remove all of uchar. |
224 |
(unsigned char*) table_name, length))) |
1
by brian
clean slate |
225 |
{
|
656.1.25
by Monty Taylor
Removed my_malloc stuff from storage/ |
226 |
if (!(share= (st_blackhole_share*) malloc(sizeof(st_blackhole_share) + |
227 |
length))) |
|
1
by brian
clean slate |
228 |
goto error; |
656.1.25
by Monty Taylor
Removed my_malloc stuff from storage/ |
229 |
memset(share, 0, sizeof(st_blackhole_share) + length); |
1
by brian
clean slate |
230 |
|
231 |
share->table_name_length= length; |
|
641.4.3
by Toru Maesaka
Final pass of replacing MySQL's my_stpcpy() with appropriate libc calls |
232 |
strcpy(share->table_name, table_name); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
233 |
|
481
by Brian Aker
Remove all of uchar. |
234 |
if (my_hash_insert(&blackhole_open_tables, (unsigned char*) share)) |
1
by brian
clean slate |
235 |
{
|
481
by Brian Aker
Remove all of uchar. |
236 |
free((unsigned char*) share); |
1
by brian
clean slate |
237 |
share= NULL; |
238 |
goto error; |
|
239 |
}
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
240 |
|
1
by brian
clean slate |
241 |
thr_lock_init(&share->lock); |
242 |
}
|
|
243 |
share->use_count++; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
244 |
|
1
by brian
clean slate |
245 |
error: |
246 |
pthread_mutex_unlock(&blackhole_mutex); |
|
247 |
return share; |
|
248 |
}
|
|
249 |
||
250 |
static void free_share(st_blackhole_share *share) |
|
251 |
{
|
|
252 |
pthread_mutex_lock(&blackhole_mutex); |
|
253 |
if (!--share->use_count) |
|
481
by Brian Aker
Remove all of uchar. |
254 |
hash_delete(&blackhole_open_tables, (unsigned char*) share); |
1
by brian
clean slate |
255 |
pthread_mutex_unlock(&blackhole_mutex); |
256 |
}
|
|
257 |
||
258 |
static void blackhole_free_key(st_blackhole_share *share) |
|
259 |
{
|
|
260 |
thr_lock_delete(&share->lock); |
|
481
by Brian Aker
Remove all of uchar. |
261 |
free((unsigned char*) share); |
1
by brian
clean slate |
262 |
}
|
263 |
||
653
by Brian Aker
More solaris bits |
264 |
static unsigned char* blackhole_get_key(st_blackhole_share *share, size_t *length, bool) |
1
by brian
clean slate |
265 |
{
|
266 |
*length= share->table_name_length; |
|
481
by Brian Aker
Remove all of uchar. |
267 |
return (unsigned char*) share->table_name; |
1
by brian
clean slate |
268 |
}
|
269 |
||
270 |
static int blackhole_init(void *p) |
|
271 |
{
|
|
960.2.25
by Monty Taylor
First step of hton rename. |
272 |
StorageEngine *blackhole_engine; |
273 |
blackhole_engine= (StorageEngine *)p; |
|
274 |
blackhole_engine->state= SHOW_OPTION_YES; |
|
275 |
blackhole_engine->create= blackhole_create_handler; |
|
276 |
blackhole_engine->flags= HTON_CAN_RECREATE; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
277 |
|
398.1.10
by Monty Taylor
Actually removed VOID() this time. |
278 |
pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST); |
1
by brian
clean slate |
279 |
(void) hash_init(&blackhole_open_tables, system_charset_info,32,0,0, |
280 |
(hash_get_key) blackhole_get_key, |
|
281 |
(hash_free_key) blackhole_free_key, 0); |
|
282 |
||
283 |
return 0; |
|
284 |
}
|
|
285 |
||
653
by Brian Aker
More solaris bits |
286 |
static int blackhole_fini(void *) |
1
by brian
clean slate |
287 |
{
|
288 |
hash_free(&blackhole_open_tables); |
|
289 |
pthread_mutex_destroy(&blackhole_mutex); |
|
290 |
||
291 |
return 0; |
|
292 |
}
|
|
293 |
||
813.2.1
by Toru Maesaka
Renamed mysql_declare_plugin to drizzle_declare_plugin |
294 |
drizzle_declare_plugin(blackhole) |
1
by brian
clean slate |
295 |
{
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
296 |
DRIZZLE_STORAGE_ENGINE_PLUGIN, |
1
by brian
clean slate |
297 |
"BLACKHOLE", |
177.4.3
by mark
ripped out more plugin ABI and API version checking, and plugin versions are now strings |
298 |
"1.0", |
1
by brian
clean slate |
299 |
"MySQL AB", |
300 |
"/dev/null storage engine (anything you write to it disappears)", |
|
301 |
PLUGIN_LICENSE_GPL, |
|
302 |
blackhole_init, /* Plugin Init */ |
|
303 |
blackhole_fini, /* Plugin Deinit */ |
|
304 |
NULL, /* status variables */ |
|
305 |
NULL, /* system variables */ |
|
306 |
NULL /* config options */ |
|
307 |
}
|
|
813.2.2
by Toru Maesaka
Renamed mysql_declare_plugin_end to drizzle_declare_plugin_end |
308 |
drizzle_declare_plugin_end; |