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