~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/blackhole/ha_blackhole.cc

Merge Revision revid:marko.makela@oracle.com-20100514133144-fe0l0b89tea4x4uu from MySQL InnoDB

Original revid:marko.makela@oracle.com-20100514133144-fe0l0b89tea4x4uu

Original Authors: Marko Mkel <marko.makela@oracle.com>
Original commit message:
Merge from mysql-5.1-innodb:

Post-merge fixes: Remove the MYSQL_VERSION_ID checks, because they only
apply to the InnoDB Plugin. Fix potential race condition accessing
trx->op_info and trx->detailed_error.
------------------------------------------------------------
revno: 3466
revision-id: marko.makela@oracle.com-20100514130815-ym7j7cfu88ro6km4
parent: marko.makela@oracle.com-20100514130228-n3n42nw7ht78k0wn
committer: Marko Mkel <marko.makela@oracle.com>
branch nick: mysql-5.1-innodb2
timestamp: Fri 2010-05-14 16:08:15 +0300
message:
  Make the InnoDB FOREIGN KEY parser understand multi-statements. (Bug #48024)
  Also make InnoDB thinks that /*/ only starts a comment. (Bug #53644).

  This fixes the bugs in the InnoDB Plugin.

  ha_innodb.h: Use trx_query_string() instead of trx_query() when
  available (MySQL 5.1.42 or later).

  innobase_get_stmt(): New function, to retrieve the currently running
  SQL statement.

  struct trx_struct: Remove mysql_query_str. Use innobase_get_stmt() instead.

  dict_strip_comments(): Add and observe the parameter sql_length. Treat
  /*/ as the start of a comment.

  dict_create_foreign_constraints(), row_table_add_foreign_constraints():
  Add the parameter sql_length.

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