~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/blackhole/ha_blackhole.cc

  • Committer: Brian Aker
  • Date: 2008-07-06 15:03:34 UTC
  • Revision ID: brian@tangent.org-20080706150334-xv3xa202trvs0712
USE_RAID cleanup, along with ftbench tools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
  along with this program; if not, write to the Free Software
14
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include <drizzled/common_includes.h>
 
16
 
 
17
#ifdef USE_PRAGMA_IMPLEMENTATION
 
18
#pragma implementation                          // gcc: Class implementation
 
19
#endif
 
20
 
 
21
#include "mysql_priv.h"
17
22
#include "ha_blackhole.h"
18
23
 
19
24
/* Static declarations for handlerton */
45
50
 
46
51
 
47
52
static const char *ha_blackhole_exts[] = {
48
 
  NULL
 
53
  NullS
49
54
};
50
55
 
51
56
const char **ha_blackhole::bas_ext() const
53
58
  return ha_blackhole_exts;
54
59
}
55
60
 
56
 
int ha_blackhole::open(const char *name, int mode __attribute__((unused)),
57
 
                       uint32_t test_if_locked __attribute__((unused)))
 
61
int ha_blackhole::open(const char *name, int mode, uint test_if_locked)
58
62
{
 
63
  DBUG_ENTER("ha_blackhole::open");
 
64
 
59
65
  if (!(share= get_share(name)))
60
 
    return(HA_ERR_OUT_OF_MEM);
 
66
    DBUG_RETURN(HA_ERR_OUT_OF_MEM);
61
67
 
62
68
  thr_lock_data_init(&share->lock, &lock, NULL);
63
 
  return(0);
 
69
  DBUG_RETURN(0);
64
70
}
65
71
 
66
72
int ha_blackhole::close(void)
67
73
{
 
74
  DBUG_ENTER("ha_blackhole::close");
68
75
  free_share(share);
69
 
  return(0);
70
 
}
71
 
 
72
 
int ha_blackhole::create(const char *name __attribute__((unused)),
73
 
                         Table *table_arg __attribute__((unused)),
74
 
                         HA_CREATE_INFO *create_info __attribute__((unused)))
75
 
{
76
 
  return(0);
77
 
}
78
 
 
79
 
const char *ha_blackhole::index_type(uint32_t key_number __attribute__((unused)))
80
 
{
81
 
  return("BTREE");
82
 
}
83
 
 
84
 
int ha_blackhole::write_row(unsigned char * buf __attribute__((unused)))
85
 
{
86
 
  return(table->next_number_field ? update_auto_increment() : 0);
87
 
}
88
 
 
89
 
int ha_blackhole::rnd_init(bool scan __attribute__((unused)))
90
 
{
91
 
  return(0);
92
 
}
93
 
 
94
 
 
95
 
int ha_blackhole::rnd_next(unsigned char *buf __attribute__((unused)))
96
 
{
97
 
  return(HA_ERR_END_OF_FILE);
98
 
}
99
 
 
100
 
 
101
 
int ha_blackhole::rnd_pos(unsigned char * buf __attribute__((unused)),
102
 
                          unsigned char *pos __attribute__((unused)))
103
 
{
104
 
  assert(0);
105
 
  return(0);
106
 
}
107
 
 
108
 
 
109
 
void ha_blackhole::position(const unsigned char *record __attribute__((unused)))
110
 
{
111
 
  assert(0);
112
 
  return;
113
 
}
114
 
 
115
 
 
116
 
int ha_blackhole::info(uint32_t flag)
117
 
{
118
 
  memset(&stats, 0, sizeof(stats));
 
76
  DBUG_RETURN(0);
 
77
}
 
78
 
 
79
int ha_blackhole::create(const char *name, TABLE *table_arg,
 
80
                         HA_CREATE_INFO *create_info)
 
81
{
 
82
  DBUG_ENTER("ha_blackhole::create");
 
83
  DBUG_RETURN(0);
 
84
}
 
85
 
 
86
const char *ha_blackhole::index_type(uint key_number)
 
87
{
 
88
  DBUG_ENTER("ha_blackhole::index_type");
 
89
  DBUG_RETURN((table_share->key_info[key_number].flags & HA_FULLTEXT) ? 
 
90
              "FULLTEXT" :
 
91
              (table_share->key_info[key_number].flags & HA_SPATIAL) ?
 
92
              "SPATIAL" :
 
93
              (table_share->key_info[key_number].algorithm ==
 
94
               HA_KEY_ALG_RTREE) ? "RTREE" : "BTREE");
 
95
}
 
96
 
 
97
int ha_blackhole::write_row(uchar * buf)
 
98
{
 
99
  DBUG_ENTER("ha_blackhole::write_row");
 
100
  DBUG_RETURN(table->next_number_field ? update_auto_increment() : 0);
 
101
}
 
102
 
 
103
int ha_blackhole::rnd_init(bool scan)
 
104
{
 
105
  DBUG_ENTER("ha_blackhole::rnd_init");
 
106
  DBUG_RETURN(0);
 
107
}
 
108
 
 
109
 
 
110
int ha_blackhole::rnd_next(uchar *buf)
 
111
{
 
112
  DBUG_ENTER("ha_blackhole::rnd_next");
 
113
  DBUG_RETURN(HA_ERR_END_OF_FILE);
 
114
}
 
115
 
 
116
 
 
117
int ha_blackhole::rnd_pos(uchar * buf, uchar *pos)
 
118
{
 
119
  DBUG_ENTER("ha_blackhole::rnd_pos");
 
120
  DBUG_ASSERT(0);
 
121
  DBUG_RETURN(0);
 
122
}
 
123
 
 
124
 
 
125
void ha_blackhole::position(const uchar *record)
 
126
{
 
127
  DBUG_ENTER("ha_blackhole::position");
 
128
  DBUG_ASSERT(0);
 
129
  DBUG_VOID_RETURN;
 
130
}
 
131
 
 
132
 
 
133
int ha_blackhole::info(uint flag)
 
134
{
 
135
  DBUG_ENTER("ha_blackhole::info");
 
136
 
 
137
  bzero((char*) &stats, sizeof(stats));
119
138
  if (flag & HA_STATUS_AUTO)
120
139
    stats.auto_increment_value= 1;
121
 
  return(0);
 
140
  DBUG_RETURN(0);
122
141
}
123
142
 
124
 
int ha_blackhole::external_lock(THD *thd __attribute__((unused)),
125
 
                                int lock_type __attribute__((unused)))
 
143
int ha_blackhole::external_lock(THD *thd, int lock_type)
126
144
{
127
 
  return(0);
 
145
  DBUG_ENTER("ha_blackhole::external_lock");
 
146
  DBUG_RETURN(0);
128
147
}
129
148
 
130
149
 
132
151
                                         THR_LOCK_DATA **to,
133
152
                                         enum thr_lock_type lock_type)
134
153
{
 
154
  DBUG_ENTER("ha_blackhole::store_lock");
135
155
  if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)
136
156
  {
137
157
    /*
138
158
      Here is where we get into the guts of a row level lock.
139
159
      If TL_UNLOCK is set
140
 
      If we are not doing a LOCK Table or DISCARD/IMPORT
 
160
      If we are not doing a LOCK TABLE or DISCARD/IMPORT
141
161
      TABLESPACE, then allow multiple writers
142
162
    */
143
163
 
160
180
    lock.type= lock_type;
161
181
  }
162
182
  *to++= &lock;
163
 
  return(to);
164
 
}
165
 
 
166
 
 
167
 
int ha_blackhole::index_read_map(unsigned char * buf __attribute__((unused)),
168
 
                                 const unsigned char * key __attribute__((unused)),
169
 
                                 key_part_map keypart_map  __attribute__((unused)),
170
 
                                 enum ha_rkey_function find_flag __attribute__((unused)))
171
 
{
172
 
  return(HA_ERR_END_OF_FILE);
173
 
}
174
 
 
175
 
 
176
 
int ha_blackhole::index_read_idx_map(unsigned char * buf __attribute__((unused)),
177
 
                                     uint32_t idx __attribute__((unused)),
178
 
                                     const unsigned char * key __attribute__((unused)),
179
 
                                     key_part_map keypart_map __attribute__((unused)),
180
 
                                     enum ha_rkey_function find_flag __attribute__((unused)))
181
 
{
182
 
  return(HA_ERR_END_OF_FILE);
183
 
}
184
 
 
185
 
 
186
 
int ha_blackhole::index_read_last_map(unsigned char * buf __attribute__((unused)),
187
 
                                      const unsigned char * key __attribute__((unused)),
188
 
                                      key_part_map keypart_map __attribute__((unused)))
189
 
{
190
 
  return(HA_ERR_END_OF_FILE);
191
 
}
192
 
 
193
 
 
194
 
int ha_blackhole::index_next(unsigned char * buf __attribute__((unused)))
195
 
{
196
 
  return(HA_ERR_END_OF_FILE);
197
 
}
198
 
 
199
 
 
200
 
int ha_blackhole::index_prev(unsigned char * buf __attribute__((unused)))
201
 
{
202
 
  return(HA_ERR_END_OF_FILE);
203
 
}
204
 
 
205
 
 
206
 
int ha_blackhole::index_first(unsigned char * buf __attribute__((unused)))
207
 
{
208
 
  return(HA_ERR_END_OF_FILE);
209
 
}
210
 
 
211
 
 
212
 
int ha_blackhole::index_last(unsigned char * buf __attribute__((unused)))
213
 
{
214
 
  return(HA_ERR_END_OF_FILE);
 
183
  DBUG_RETURN(to);
 
184
}
 
185
 
 
186
 
 
187
int ha_blackhole::index_read_map(uchar * buf, const uchar * key,
 
188
                                 key_part_map keypart_map,
 
189
                             enum ha_rkey_function find_flag)
 
190
{
 
191
  DBUG_ENTER("ha_blackhole::index_read");
 
192
  DBUG_RETURN(HA_ERR_END_OF_FILE);
 
193
}
 
194
 
 
195
 
 
196
int ha_blackhole::index_read_idx_map(uchar * buf, uint idx, const uchar * key,
 
197
                                 key_part_map keypart_map,
 
198
                                 enum ha_rkey_function find_flag)
 
199
{
 
200
  DBUG_ENTER("ha_blackhole::index_read_idx");
 
201
  DBUG_RETURN(HA_ERR_END_OF_FILE);
 
202
}
 
203
 
 
204
 
 
205
int ha_blackhole::index_read_last_map(uchar * buf, const uchar * key,
 
206
                                      key_part_map keypart_map)
 
207
{
 
208
  DBUG_ENTER("ha_blackhole::index_read_last");
 
209
  DBUG_RETURN(HA_ERR_END_OF_FILE);
 
210
}
 
211
 
 
212
 
 
213
int ha_blackhole::index_next(uchar * buf)
 
214
{
 
215
  DBUG_ENTER("ha_blackhole::index_next");
 
216
  DBUG_RETURN(HA_ERR_END_OF_FILE);
 
217
}
 
218
 
 
219
 
 
220
int ha_blackhole::index_prev(uchar * buf)
 
221
{
 
222
  DBUG_ENTER("ha_blackhole::index_prev");
 
223
  DBUG_RETURN(HA_ERR_END_OF_FILE);
 
224
}
 
225
 
 
226
 
 
227
int ha_blackhole::index_first(uchar * buf)
 
228
{
 
229
  DBUG_ENTER("ha_blackhole::index_first");
 
230
  DBUG_RETURN(HA_ERR_END_OF_FILE);
 
231
}
 
232
 
 
233
 
 
234
int ha_blackhole::index_last(uchar * buf)
 
235
{
 
236
  DBUG_ENTER("ha_blackhole::index_last");
 
237
  DBUG_RETURN(HA_ERR_END_OF_FILE);
215
238
}
216
239
 
217
240
 
218
241
static st_blackhole_share *get_share(const char *table_name)
219
242
{
220
243
  st_blackhole_share *share;
221
 
  uint32_t length;
 
244
  uint length;
222
245
 
223
246
  length= (uint) strlen(table_name);
224
247
  pthread_mutex_lock(&blackhole_mutex);
225
248
    
226
249
  if (!(share= (st_blackhole_share*) hash_search(&blackhole_open_tables,
227
 
                                                 (unsigned char*) table_name, length)))
 
250
                                                 (uchar*) table_name, length)))
228
251
  {
229
252
    if (!(share= (st_blackhole_share*) my_malloc(sizeof(st_blackhole_share) +
230
253
                                                 length,
232
255
      goto error;
233
256
 
234
257
    share->table_name_length= length;
235
 
    my_stpcpy(share->table_name, table_name);
 
258
    strmov(share->table_name, table_name);
236
259
    
237
 
    if (my_hash_insert(&blackhole_open_tables, (unsigned char*) share))
 
260
    if (my_hash_insert(&blackhole_open_tables, (uchar*) share))
238
261
    {
239
 
      free((unsigned char*) share);
 
262
      my_free((uchar*) share, MYF(0));
240
263
      share= NULL;
241
264
      goto error;
242
265
    }
254
277
{
255
278
  pthread_mutex_lock(&blackhole_mutex);
256
279
  if (!--share->use_count)
257
 
    hash_delete(&blackhole_open_tables, (unsigned char*) share);
 
280
    hash_delete(&blackhole_open_tables, (uchar*) share);
258
281
  pthread_mutex_unlock(&blackhole_mutex);
259
282
}
260
283
 
261
284
static void blackhole_free_key(st_blackhole_share *share)
262
285
{
263
286
  thr_lock_delete(&share->lock);
264
 
  free((unsigned char*) share);
 
287
  my_free((uchar*) share, MYF(0));
265
288
}
266
289
 
267
 
static unsigned char* blackhole_get_key(st_blackhole_share *share, size_t *length,
268
 
                                bool not_used __attribute__((unused)))
 
290
static uchar* blackhole_get_key(st_blackhole_share *share, size_t *length,
 
291
                                my_bool not_used __attribute__((unused)))
269
292
{
270
293
  *length= share->table_name_length;
271
 
  return (unsigned char*) share->table_name;
 
294
  return (uchar*) share->table_name;
272
295
}
273
296
 
274
297
static int blackhole_init(void *p)
276
299
  handlerton *blackhole_hton;
277
300
  blackhole_hton= (handlerton *)p;
278
301
  blackhole_hton->state= SHOW_OPTION_YES;
 
302
  blackhole_hton->db_type= DB_TYPE_BLACKHOLE_DB;
279
303
  blackhole_hton->create= blackhole_create_handler;
280
304
  blackhole_hton->flags= HTON_CAN_RECREATE;
281
305
  
282
 
  pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST);
 
306
  VOID(pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST));
283
307
  (void) hash_init(&blackhole_open_tables, system_charset_info,32,0,0,
284
308
                   (hash_get_key) blackhole_get_key,
285
309
                   (hash_free_key) blackhole_free_key, 0);
287
311
  return 0;
288
312
}
289
313
 
290
 
static int blackhole_fini(void *p __attribute__((unused)))
 
314
static int blackhole_fini(void *p)
291
315
{
292
316
  hash_free(&blackhole_open_tables);
293
317
  pthread_mutex_destroy(&blackhole_mutex);
295
319
  return 0;
296
320
}
297
321
 
 
322
struct st_mysql_storage_engine blackhole_storage_engine=
 
323
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
 
324
 
298
325
mysql_declare_plugin(blackhole)
299
326
{
300
 
  DRIZZLE_STORAGE_ENGINE_PLUGIN,
 
327
  MYSQL_STORAGE_ENGINE_PLUGIN,
 
328
  &blackhole_storage_engine,
301
329
  "BLACKHOLE",
302
 
  "1.0",
303
330
  "MySQL AB",
304
331
  "/dev/null storage engine (anything you write to it disappears)",
305
332
  PLUGIN_LICENSE_GPL,
306
333
  blackhole_init, /* Plugin Init */
307
334
  blackhole_fini, /* Plugin Deinit */
 
335
  0x0100 /* 1.0 */,
308
336
  NULL,                       /* status variables                */
309
337
  NULL,                       /* system variables                */
310
338
  NULL                        /* config options                  */