~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/blackhole/ha_blackhole.cc

  • Committer: Monty
  • Date: 2008-11-07 05:51:15 UTC
  • mto: This revision was merged to the branch mainline in revision 579.
  • Revision ID: mordred@palanthas.inaugust.com-20081107055115-0275gvq62buzls77
Fixed a decimal sign thing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
  You should have received a copy of the GNU General Public License
13
13
  along with this program; if not, write to the Free Software
14
 
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
 
 
16
 
#include "config.h"
17
 
 
18
 
#include <drizzled/error.h>
19
 
#include <drizzled/global_charset_info.h>
20
 
#include <drizzled/internal/m_string.h>
21
 
#include <drizzled/internal/my_pthread.h>
22
 
#include <drizzled/message/table.h>
23
 
#include <drizzled/plugin/storage_engine.h>
24
 
#include <drizzled/table.h>
25
 
 
26
 
 
 
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <drizzled/common_includes.h>
27
17
#include "ha_blackhole.h"
28
18
 
29
 
#include <fcntl.h>
30
 
 
31
 
#include <fstream>
32
 
#include <map>
33
 
#include <string>
34
 
 
35
 
#include <google/protobuf/io/zero_copy_stream.h>
36
 
#include <google/protobuf/io/zero_copy_stream_impl.h>
37
 
 
38
 
 
39
 
using namespace std;
40
 
using namespace google;
41
 
using namespace drizzled;
42
 
 
43
 
#define BLACKHOLE_EXT ".blk"
 
19
/* Static declarations for handlerton */
 
20
 
 
21
static handler *blackhole_create_handler(handlerton *hton,
 
22
                                         TABLE_SHARE *table,
 
23
                                         MEM_ROOT *mem_root)
 
24
{
 
25
  return new (mem_root) ha_blackhole(hton, table);
 
26
}
 
27
 
 
28
 
 
29
/* Static declarations for shared structures */
44
30
 
45
31
static pthread_mutex_t blackhole_mutex;
46
 
 
47
 
 
48
 
static const char *ha_blackhole_exts[] = {
49
 
  BLACKHOLE_EXT,
50
 
  NULL
51
 
};
52
 
 
53
 
class BlackholeEngine : public drizzled::plugin::StorageEngine
54
 
{
55
 
  typedef std::map<std::string, BlackholeShare*> BlackholeMap;
56
 
  BlackholeMap blackhole_open_tables;
57
 
 
58
 
public:
59
 
  BlackholeEngine(const string &name_arg)
60
 
   : drizzled::plugin::StorageEngine(name_arg,
61
 
                                     HTON_NULL_IN_KEY |
62
 
                                     HTON_CAN_INDEX_BLOBS |
63
 
                                     HTON_SKIP_STORE_LOCK |
64
 
                                     HTON_AUTO_PART_KEY),
65
 
    blackhole_open_tables()
66
 
  {
67
 
    table_definition_ext= BLACKHOLE_EXT;
68
 
  }
69
 
 
70
 
  virtual ~BlackholeEngine()
71
 
  {
72
 
    pthread_mutex_destroy(&blackhole_mutex);
73
 
  }
74
 
 
75
 
  virtual Cursor *create(Table &table)
76
 
  {
77
 
    return new ha_blackhole(*this, table);
78
 
  }
79
 
 
80
 
  const char **bas_ext() const {
81
 
    return ha_blackhole_exts;
82
 
  }
83
 
 
84
 
  int doCreateTable(Session&,
85
 
                    Table&,
86
 
                    const drizzled::identifier::Table &identifier,
87
 
                    drizzled::message::Table&);
88
 
 
89
 
  int doDropTable(Session&, const drizzled::identifier::Table &identifier);
90
 
 
91
 
  BlackholeShare *findOpenTable(const string table_name);
92
 
  void addOpenTable(const string &table_name, BlackholeShare *);
93
 
  void deleteOpenTable(const string &table_name);
94
 
 
95
 
  int doGetTableDefinition(Session& session,
96
 
                           const drizzled::identifier::Table &identifier,
97
 
                           drizzled::message::Table &table_message);
98
 
 
99
 
  /* The following defines can be increased if necessary */
100
 
  uint32_t max_supported_keys()          const { return BLACKHOLE_MAX_KEY; }
101
 
  uint32_t max_supported_key_length()    const { return BLACKHOLE_MAX_KEY_LENGTH; }
102
 
  uint32_t max_supported_key_part_length() const { return BLACKHOLE_MAX_KEY_LENGTH; }
103
 
 
104
 
  uint32_t index_flags(enum  ha_key_alg) const
105
 
  {
106
 
    return (HA_READ_NEXT |
107
 
            HA_READ_PREV |
108
 
            HA_READ_RANGE |
109
 
            HA_READ_ORDER |
110
 
            HA_KEYREAD_ONLY);
111
 
  }
112
 
 
113
 
  bool doDoesTableExist(Session& session, const drizzled::identifier::Table &identifier);
114
 
  int doRenameTable(Session&, const drizzled::identifier::Table &from, const drizzled::identifier::Table &to);
115
 
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
116
 
                             const drizzled::identifier::Schema &schema_identifier,
117
 
                             drizzled::identifier::Table::vector &set_of_identifiers);
118
 
};
119
 
 
120
 
 
121
 
void BlackholeEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
122
 
                                            const drizzled::identifier::Schema &schema_identifier,
123
 
                                            drizzled::identifier::Table::vector &set_of_identifiers)
124
 
{
125
 
  drizzled::CachedDirectory::Entries entries= directory.getEntries();
126
 
 
127
 
  for (drizzled::CachedDirectory::Entries::iterator entry_iter= entries.begin();
128
 
       entry_iter != entries.end(); ++entry_iter)
129
 
  {
130
 
    drizzled::CachedDirectory::Entry *entry= *entry_iter;
131
 
    const string *filename= &entry->filename;
132
 
 
133
 
    assert(filename->size());
134
 
 
135
 
    const char *ext= strchr(filename->c_str(), '.');
136
 
 
137
 
    if (ext == NULL || my_strcasecmp(system_charset_info, ext, BLACKHOLE_EXT) ||
138
 
        (filename->compare(0, strlen(TMP_FILE_PREFIX), TMP_FILE_PREFIX) == 0))
139
 
    {  }
140
 
    else
141
 
    {
142
 
      char uname[NAME_LEN + 1];
143
 
      uint32_t file_name_len;
144
 
 
145
 
      file_name_len= identifier::Table::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
146
 
      // TODO: Remove need for memory copy here
147
 
      uname[file_name_len - sizeof(BLACKHOLE_EXT) + 1]= '\0'; // Subtract ending, place NULL
148
 
 
149
 
      set_of_identifiers.push_back(identifier::Table(schema_identifier, uname));
150
 
    }
151
 
  }
152
 
}
153
 
 
154
 
int BlackholeEngine::doRenameTable(Session&, const drizzled::identifier::Table &from, const drizzled::identifier::Table &to)
155
 
{
156
 
  int error= 0;
157
 
 
158
 
  for (const char **ext= bas_ext(); *ext ; ext++)
159
 
  {
160
 
    if (rename_file_ext(from.getPath().c_str(), to.getPath().c_str(), *ext))
161
 
    {
162
 
      if ((error=errno) != ENOENT)
163
 
        break;
164
 
      error= 0;
165
 
    }
166
 
  }
167
 
  return error;
168
 
}
169
 
 
170
 
BlackholeShare *BlackholeEngine::findOpenTable(const string table_name)
171
 
{
172
 
  BlackholeMap::iterator find_iter=
173
 
    blackhole_open_tables.find(table_name);
174
 
 
175
 
  if (find_iter != blackhole_open_tables.end())
176
 
    return (*find_iter).second;
177
 
  else
178
 
    return NULL;
179
 
}
180
 
 
181
 
void BlackholeEngine::addOpenTable(const string &table_name, BlackholeShare *share)
182
 
{
183
 
  blackhole_open_tables[table_name]= share;
184
 
}
185
 
 
186
 
void BlackholeEngine::deleteOpenTable(const string &table_name)
187
 
{
188
 
  blackhole_open_tables.erase(table_name);
189
 
}
190
 
 
191
 
 
 
32
static HASH blackhole_open_tables;
 
33
 
 
34
static st_blackhole_share *get_share(const char *table_name);
 
35
static void free_share(st_blackhole_share *share);
192
36
 
193
37
/*****************************************************************************
194
38
** BLACKHOLE tables
195
39
*****************************************************************************/
196
40
 
197
 
ha_blackhole::ha_blackhole(drizzled::plugin::StorageEngine &engine_arg,
198
 
                           Table &table_arg)
199
 
  :Cursor(engine_arg, table_arg), share(NULL)
200
 
{ }
201
 
 
202
 
int ha_blackhole::open(const char *name, int, uint32_t)
 
41
ha_blackhole::ha_blackhole(handlerton *hton,
 
42
                           TABLE_SHARE *table_arg)
 
43
  :handler(hton, table_arg)
 
44
{}
 
45
 
 
46
 
 
47
static const char *ha_blackhole_exts[] = {
 
48
  NULL
 
49
};
 
50
 
 
51
const char **ha_blackhole::bas_ext() const
 
52
{
 
53
  return ha_blackhole_exts;
 
54
}
 
55
 
 
56
int ha_blackhole::open(const char *name, int mode __attribute__((unused)),
 
57
                       uint32_t test_if_locked __attribute__((unused)))
203
58
{
204
59
  if (!(share= get_share(name)))
205
60
    return(HA_ERR_OUT_OF_MEM);
206
61
 
207
 
  lock.init(&share->lock);
208
 
  return 0;
 
62
  thr_lock_data_init(&share->lock, &lock, NULL);
 
63
  return(0);
209
64
}
210
65
 
211
66
int ha_blackhole::close(void)
212
67
{
213
 
  free_share();
214
 
  return 0;
215
 
}
216
 
 
217
 
int BlackholeEngine::doCreateTable(Session&,
218
 
                                   Table&,
219
 
                                   const drizzled::identifier::Table &identifier,
220
 
                                   drizzled::message::Table& proto)
221
 
{
222
 
  string serialized_proto;
223
 
  string new_path;
224
 
 
225
 
  new_path= identifier.getPath();
226
 
  new_path+= BLACKHOLE_EXT;
227
 
  fstream output(new_path.c_str(), ios::out | ios::binary);
228
 
 
229
 
 
230
 
  if (! output)
231
 
    return 1;
232
 
 
233
 
  if (! proto.SerializeToOstream(&output))
234
 
  {
235
 
    output.close();
236
 
    unlink(new_path.c_str());
237
 
    return 1;
238
 
  }
239
 
 
240
 
  return 0;
241
 
}
242
 
 
243
 
 
244
 
int BlackholeEngine::doDropTable(Session&,
245
 
                                 const drizzled::identifier::Table &identifier)
246
 
{
247
 
  string new_path(identifier.getPath());
248
 
 
249
 
  new_path+= BLACKHOLE_EXT;
250
 
 
251
 
  int error= unlink(new_path.c_str());
252
 
 
253
 
  if (error != 0)
254
 
  {
255
 
    error= errno= errno;
256
 
  }
257
 
 
258
 
  return error;
259
 
}
260
 
 
261
 
 
262
 
bool BlackholeEngine::doDoesTableExist(Session&,
263
 
                                       const drizzled::identifier::Table &identifier)
264
 
{
265
 
  string proto_path(identifier.getPath());
266
 
  proto_path.append(BLACKHOLE_EXT);
267
 
 
268
 
  if (access(proto_path.c_str(), F_OK))
269
 
  {
270
 
    return false;
271
 
  }
272
 
 
273
 
  return true;
274
 
}
275
 
 
276
 
 
277
 
int BlackholeEngine::doGetTableDefinition(Session&,
278
 
                                          const drizzled::identifier::Table &identifier,
279
 
                                          drizzled::message::Table &table_proto)
280
 
{
281
 
  string new_path;
282
 
 
283
 
  new_path= identifier.getPath();
284
 
  new_path+= BLACKHOLE_EXT;
285
 
 
286
 
  int fd= open(new_path.c_str(), O_RDONLY);
287
 
 
288
 
  if (fd == -1)
289
 
  {
290
 
    return errno;
291
 
  }
292
 
 
293
 
  google::protobuf::io::ZeroCopyInputStream* input=
294
 
    new google::protobuf::io::FileInputStream(fd);
295
 
 
296
 
  if (not input)
297
 
    return HA_ERR_CRASHED_ON_USAGE;
298
 
 
299
 
  if (not table_proto.ParseFromZeroCopyStream(input))
300
 
  {
301
 
    close(fd);
302
 
    delete input;
303
 
    if (not table_proto.IsInitialized())
304
 
    {
305
 
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
306
 
               table_proto.name().empty() ? " " : table_proto.name().c_str(),
307
 
               table_proto.InitializationErrorString().c_str());
308
 
 
309
 
      return ER_CORRUPT_TABLE_DEFINITION;
310
 
    }
311
 
 
312
 
    return HA_ERR_CRASHED_ON_USAGE;
313
 
  }
314
 
 
315
 
  delete input;
316
 
 
317
 
  return EEXIST;
318
 
}
319
 
 
320
 
const char *ha_blackhole::index_type(uint32_t)
 
68
  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)))
321
80
{
322
81
  return("BTREE");
323
82
}
324
83
 
325
 
int ha_blackhole::doInsertRecord(unsigned char *)
 
84
int ha_blackhole::write_row(unsigned char * buf __attribute__((unused)))
326
85
{
327
 
  return(getTable()->next_number_field ? update_auto_increment() : 0);
 
86
  return(table->next_number_field ? update_auto_increment() : 0);
328
87
}
329
88
 
330
 
int ha_blackhole::doStartTableScan(bool)
 
89
int ha_blackhole::rnd_init(bool scan __attribute__((unused)))
331
90
{
332
91
  return(0);
333
92
}
334
93
 
335
94
 
336
 
int ha_blackhole::rnd_next(unsigned char *)
 
95
int ha_blackhole::rnd_next(unsigned char *buf __attribute__((unused)))
337
96
{
338
97
  return(HA_ERR_END_OF_FILE);
339
98
}
340
99
 
341
100
 
342
 
int ha_blackhole::rnd_pos(unsigned char *, unsigned char *)
 
101
int ha_blackhole::rnd_pos(unsigned char * buf __attribute__((unused)),
 
102
                          unsigned char *pos __attribute__((unused)))
343
103
{
344
104
  assert(0);
345
105
  return(0);
346
106
}
347
107
 
348
108
 
349
 
void ha_blackhole::position(const unsigned char *)
 
109
void ha_blackhole::position(const unsigned char *record __attribute__((unused)))
350
110
{
351
111
  assert(0);
352
112
  return;
361
121
  return(0);
362
122
}
363
123
 
364
 
 
365
 
int ha_blackhole::index_read_map(unsigned char *, const unsigned char *,
366
 
                                 key_part_map, enum ha_rkey_function)
367
 
{
368
 
  return(HA_ERR_END_OF_FILE);
369
 
}
370
 
 
371
 
 
372
 
int ha_blackhole::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *,
373
 
                                     key_part_map, enum ha_rkey_function)
374
 
{
375
 
  return(HA_ERR_END_OF_FILE);
376
 
}
377
 
 
378
 
 
379
 
int ha_blackhole::index_read_last_map(unsigned char *, const unsigned char *, key_part_map)
380
 
{
381
 
  return(HA_ERR_END_OF_FILE);
382
 
}
383
 
 
384
 
 
385
 
int ha_blackhole::index_next(unsigned char *)
386
 
{
387
 
  return(HA_ERR_END_OF_FILE);
388
 
}
389
 
 
390
 
 
391
 
int ha_blackhole::index_prev(unsigned char *)
392
 
{
393
 
  return(HA_ERR_END_OF_FILE);
394
 
}
395
 
 
396
 
 
397
 
int ha_blackhole::index_first(unsigned char *)
398
 
{
399
 
  return(HA_ERR_END_OF_FILE);
400
 
}
401
 
 
402
 
 
403
 
int ha_blackhole::index_last(unsigned char *)
404
 
{
405
 
  return(HA_ERR_END_OF_FILE);
406
 
}
407
 
 
408
 
 
409
 
BlackholeShare *ha_blackhole::get_share(const char *table_name)
410
 
{
 
124
int ha_blackhole::external_lock(Session *session __attribute__((unused)),
 
125
                                int lock_type __attribute__((unused)))
 
126
{
 
127
  return(0);
 
128
}
 
129
 
 
130
 
 
131
THR_LOCK_DATA **ha_blackhole::store_lock(Session *session,
 
132
                                         THR_LOCK_DATA **to,
 
133
                                         enum thr_lock_type lock_type)
 
134
{
 
135
  if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)
 
136
  {
 
137
    /*
 
138
      Here is where we get into the guts of a row level lock.
 
139
      If TL_UNLOCK is set
 
140
      If we are not doing a LOCK Table or DISCARD/IMPORT
 
141
      TABLESPACE, then allow multiple writers
 
142
    */
 
143
 
 
144
    if ((lock_type >= TL_WRITE_CONCURRENT_INSERT &&
 
145
         lock_type <= TL_WRITE) && !session_in_lock_tables(session)
 
146
        && !session_tablespace_op(session))
 
147
      lock_type = TL_WRITE_ALLOW_WRITE;
 
148
 
 
149
    /*
 
150
      In queries of type INSERT INTO t1 SELECT ... FROM t2 ...
 
151
      MySQL would use the lock TL_READ_NO_INSERT on t2, and that
 
152
      would conflict with TL_WRITE_ALLOW_WRITE, blocking all inserts
 
153
      to t2. Convert the lock to a normal read lock to allow
 
154
      concurrent inserts to t2.
 
155
    */
 
156
 
 
157
    if (lock_type == TL_READ_NO_INSERT && !session_in_lock_tables(session))
 
158
      lock_type = TL_READ;
 
159
 
 
160
    lock.type= lock_type;
 
161
  }
 
162
  *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);
 
215
}
 
216
 
 
217
 
 
218
static st_blackhole_share *get_share(const char *table_name)
 
219
{
 
220
  st_blackhole_share *share;
 
221
  uint32_t length;
 
222
 
 
223
  length= (uint) strlen(table_name);
411
224
  pthread_mutex_lock(&blackhole_mutex);
412
 
 
413
 
  BlackholeEngine *a_engine= static_cast<BlackholeEngine *>(getEngine());
414
 
  share= a_engine->findOpenTable(table_name);
415
 
 
416
 
  if (share == NULL)
 
225
    
 
226
  if (!(share= (st_blackhole_share*) hash_search(&blackhole_open_tables,
 
227
                                                 (unsigned char*) table_name, length)))
417
228
  {
418
 
    share= new (nothrow) BlackholeShare(table_name);
419
 
    if (share == NULL)
 
229
    if (!(share= (st_blackhole_share*) my_malloc(sizeof(st_blackhole_share) +
 
230
                                                 length,
 
231
                                                 MYF(MY_WME | MY_ZEROFILL))))
 
232
      goto error;
 
233
 
 
234
    share->table_name_length= length;
 
235
    my_stpcpy(share->table_name, table_name);
 
236
    
 
237
    if (my_hash_insert(&blackhole_open_tables, (unsigned char*) share))
420
238
    {
421
 
      pthread_mutex_unlock(&blackhole_mutex);      
422
 
      return NULL;
 
239
      free((unsigned char*) share);
 
240
      share= NULL;
 
241
      goto error;
423
242
    }
424
 
 
425
 
    a_engine->addOpenTable(share->table_name, share);
 
243
    
 
244
    thr_lock_init(&share->lock);
426
245
  }
427
246
  share->use_count++;
 
247
  
 
248
error:
428
249
  pthread_mutex_unlock(&blackhole_mutex);
429
250
  return share;
430
 
 
431
251
}
432
252
 
433
 
void ha_blackhole::free_share()
 
253
static void free_share(st_blackhole_share *share)
434
254
{
435
255
  pthread_mutex_lock(&blackhole_mutex);
436
256
  if (!--share->use_count)
437
 
  {
438
 
    BlackholeEngine *a_engine= static_cast<BlackholeEngine *>(getEngine());
439
 
    a_engine->deleteOpenTable(share->table_name);
440
 
    delete share;
441
 
  }
 
257
    hash_delete(&blackhole_open_tables, (unsigned char*) share);
442
258
  pthread_mutex_unlock(&blackhole_mutex);
443
259
}
444
260
 
445
 
BlackholeShare::BlackholeShare(const string table_name_arg)
446
 
  : use_count(0), table_name(table_name_arg)
447
 
{
448
 
  thr_lock_init(&lock);
449
 
}
450
 
 
451
 
BlackholeShare::~BlackholeShare()
452
 
{
453
 
  lock.deinit();
454
 
}
455
 
 
456
 
 
457
 
static drizzled::plugin::StorageEngine *blackhole_engine= NULL;
458
 
 
459
 
static int blackhole_init(drizzled::module::Context &context)
460
 
{
461
 
 
462
 
  blackhole_engine= new BlackholeEngine("BLACKHOLE");
463
 
  context.add(blackhole_engine);
 
261
static void blackhole_free_key(st_blackhole_share *share)
 
262
{
 
263
  thr_lock_delete(&share->lock);
 
264
  free((unsigned char*) share);
 
265
}
 
266
 
 
267
static unsigned char* blackhole_get_key(st_blackhole_share *share, size_t *length,
 
268
                                bool not_used __attribute__((unused)))
 
269
{
 
270
  *length= share->table_name_length;
 
271
  return (unsigned char*) share->table_name;
 
272
}
 
273
 
 
274
static int blackhole_init(void *p)
 
275
{
 
276
  handlerton *blackhole_hton;
 
277
  blackhole_hton= (handlerton *)p;
 
278
  blackhole_hton->state= SHOW_OPTION_YES;
 
279
  blackhole_hton->create= blackhole_create_handler;
 
280
  blackhole_hton->flags= HTON_CAN_RECREATE;
464
281
  
465
282
  pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST);
466
 
 
467
 
  return 0;
468
 
}
469
 
 
470
 
 
471
 
DRIZZLE_DECLARE_PLUGIN
472
 
{
473
 
  DRIZZLE_VERSION_ID,
 
283
  (void) hash_init(&blackhole_open_tables, system_charset_info,32,0,0,
 
284
                   (hash_get_key) blackhole_get_key,
 
285
                   (hash_free_key) blackhole_free_key, 0);
 
286
 
 
287
  return 0;
 
288
}
 
289
 
 
290
static int blackhole_fini(void *p __attribute__((unused)))
 
291
{
 
292
  hash_free(&blackhole_open_tables);
 
293
  pthread_mutex_destroy(&blackhole_mutex);
 
294
 
 
295
  return 0;
 
296
}
 
297
 
 
298
mysql_declare_plugin(blackhole)
 
299
{
 
300
  DRIZZLE_STORAGE_ENGINE_PLUGIN,
474
301
  "BLACKHOLE",
475
302
  "1.0",
476
303
  "MySQL AB",
477
304
  "/dev/null storage engine (anything you write to it disappears)",
478
305
  PLUGIN_LICENSE_GPL,
479
 
  blackhole_init,     /* Plugin Init */
480
 
  NULL,               /* depends */
481
 
  NULL                /* config options   */
 
306
  blackhole_init, /* Plugin Init */
 
307
  blackhole_fini, /* Plugin Deinit */
 
308
  NULL,                       /* status variables                */
 
309
  NULL,                       /* system variables                */
 
310
  NULL                        /* config options                  */
482
311
}
483
 
DRIZZLE_DECLARE_PLUGIN_END;
 
312
mysql_declare_plugin_end;