~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/blackhole/ha_blackhole.cc

  • Committer: Jay Pipes
  • Date: 2008-07-21 17:52:33 UTC
  • mto: (201.2.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: jay@mysql.com-20080721175233-mtyz298j8xl3v63y
cleanup of FAQ file

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 __attribute__((__unused__)),
 
62
                       uint test_if_locked __attribute__((__unused__)))
58
63
{
59
64
  if (!(share= get_share(name)))
60
65
    return(HA_ERR_OUT_OF_MEM);
69
74
  return(0);
70
75
}
71
76
 
72
 
int ha_blackhole::create(const char *name __attribute__((unused)),
73
 
                         Table *table_arg __attribute__((unused)),
74
 
                         HA_CREATE_INFO *create_info __attribute__((unused)))
 
77
int ha_blackhole::create(const char *name __attribute__((__unused__)),
 
78
                         TABLE *table_arg __attribute__((__unused__)),
 
79
                         HA_CREATE_INFO *create_info __attribute__((__unused__)))
75
80
{
76
81
  return(0);
77
82
}
78
83
 
79
 
const char *ha_blackhole::index_type(uint32_t key_number __attribute__((unused)))
 
84
const char *ha_blackhole::index_type(uint key_number)
80
85
{
81
 
  return("BTREE");
 
86
  return((table_share->key_info[key_number].flags & HA_FULLTEXT) ? 
 
87
              "FULLTEXT" :
 
88
              (table_share->key_info[key_number].flags & HA_SPATIAL) ?
 
89
              "SPATIAL" :
 
90
              (table_share->key_info[key_number].algorithm ==
 
91
               HA_KEY_ALG_RTREE) ? "RTREE" : "BTREE");
82
92
}
83
93
 
84
 
int ha_blackhole::write_row(unsigned char * buf __attribute__((unused)))
 
94
int ha_blackhole::write_row(uchar * buf __attribute__((__unused__)))
85
95
{
86
96
  return(table->next_number_field ? update_auto_increment() : 0);
87
97
}
88
98
 
89
 
int ha_blackhole::rnd_init(bool scan __attribute__((unused)))
 
99
int ha_blackhole::rnd_init(bool scan __attribute__((__unused__)))
90
100
{
91
101
  return(0);
92
102
}
93
103
 
94
104
 
95
 
int ha_blackhole::rnd_next(unsigned char *buf __attribute__((unused)))
 
105
int ha_blackhole::rnd_next(uchar *buf __attribute__((__unused__)))
96
106
{
97
107
  return(HA_ERR_END_OF_FILE);
98
108
}
99
109
 
100
110
 
101
 
int ha_blackhole::rnd_pos(unsigned char * buf __attribute__((unused)),
102
 
                          unsigned char *pos __attribute__((unused)))
 
111
int ha_blackhole::rnd_pos(uchar * buf __attribute__((__unused__)),
 
112
                          uchar *pos __attribute__((__unused__)))
103
113
{
104
114
  assert(0);
105
115
  return(0);
106
116
}
107
117
 
108
118
 
109
 
void ha_blackhole::position(const unsigned char *record __attribute__((unused)))
 
119
void ha_blackhole::position(const uchar *record __attribute__((__unused__)))
110
120
{
111
121
  assert(0);
112
122
  return;
113
123
}
114
124
 
115
125
 
116
 
int ha_blackhole::info(uint32_t flag)
 
126
int ha_blackhole::info(uint flag)
117
127
{
118
 
  memset(&stats, 0, sizeof(stats));
 
128
  bzero((char*) &stats, sizeof(stats));
119
129
  if (flag & HA_STATUS_AUTO)
120
130
    stats.auto_increment_value= 1;
121
131
  return(0);
122
132
}
123
133
 
124
 
int ha_blackhole::external_lock(THD *thd __attribute__((unused)),
125
 
                                int lock_type __attribute__((unused)))
 
134
int ha_blackhole::external_lock(THD *thd __attribute__((__unused__)),
 
135
                                int lock_type __attribute__((__unused__)))
126
136
{
127
137
  return(0);
128
138
}
137
147
    /*
138
148
      Here is where we get into the guts of a row level lock.
139
149
      If TL_UNLOCK is set
140
 
      If we are not doing a LOCK Table or DISCARD/IMPORT
 
150
      If we are not doing a LOCK TABLE or DISCARD/IMPORT
141
151
      TABLESPACE, then allow multiple writers
142
152
    */
143
153
 
164
174
}
165
175
 
166
176
 
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)))
 
177
int ha_blackhole::index_read_map(uchar * buf __attribute__((__unused__)),
 
178
                                 const uchar * 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_idx_map(uchar * buf __attribute__((__unused__)),
 
187
                                     uint idx __attribute__((__unused__)),
 
188
                                     const uchar * key __attribute__((__unused__)),
 
189
                                     key_part_map keypart_map __attribute__((__unused__)),
 
190
                                     enum ha_rkey_function find_flag __attribute__((__unused__)))
 
191
{
 
192
  return(HA_ERR_END_OF_FILE);
 
193
}
 
194
 
 
195
 
 
196
int ha_blackhole::index_read_last_map(uchar * buf __attribute__((__unused__)),
 
197
                                      const uchar * key __attribute__((__unused__)),
 
198
                                      key_part_map keypart_map __attribute__((__unused__)))
 
199
{
 
200
  return(HA_ERR_END_OF_FILE);
 
201
}
 
202
 
 
203
 
 
204
int ha_blackhole::index_next(uchar * buf __attribute__((__unused__)))
 
205
{
 
206
  return(HA_ERR_END_OF_FILE);
 
207
}
 
208
 
 
209
 
 
210
int ha_blackhole::index_prev(uchar * buf __attribute__((__unused__)))
 
211
{
 
212
  return(HA_ERR_END_OF_FILE);
 
213
}
 
214
 
 
215
 
 
216
int ha_blackhole::index_first(uchar * buf __attribute__((__unused__)))
 
217
{
 
218
  return(HA_ERR_END_OF_FILE);
 
219
}
 
220
 
 
221
 
 
222
int ha_blackhole::index_last(uchar * buf __attribute__((__unused__)))
213
223
{
214
224
  return(HA_ERR_END_OF_FILE);
215
225
}
218
228
static st_blackhole_share *get_share(const char *table_name)
219
229
{
220
230
  st_blackhole_share *share;
221
 
  uint32_t length;
 
231
  uint length;
222
232
 
223
233
  length= (uint) strlen(table_name);
224
234
  pthread_mutex_lock(&blackhole_mutex);
225
235
    
226
236
  if (!(share= (st_blackhole_share*) hash_search(&blackhole_open_tables,
227
 
                                                 (unsigned char*) table_name, length)))
 
237
                                                 (uchar*) table_name, length)))
228
238
  {
229
239
    if (!(share= (st_blackhole_share*) my_malloc(sizeof(st_blackhole_share) +
230
240
                                                 length,
232
242
      goto error;
233
243
 
234
244
    share->table_name_length= length;
235
 
    my_stpcpy(share->table_name, table_name);
 
245
    strmov(share->table_name, table_name);
236
246
    
237
 
    if (my_hash_insert(&blackhole_open_tables, (unsigned char*) share))
 
247
    if (my_hash_insert(&blackhole_open_tables, (uchar*) share))
238
248
    {
239
 
      free((unsigned char*) share);
 
249
      my_free((uchar*) share, MYF(0));
240
250
      share= NULL;
241
251
      goto error;
242
252
    }
254
264
{
255
265
  pthread_mutex_lock(&blackhole_mutex);
256
266
  if (!--share->use_count)
257
 
    hash_delete(&blackhole_open_tables, (unsigned char*) share);
 
267
    hash_delete(&blackhole_open_tables, (uchar*) share);
258
268
  pthread_mutex_unlock(&blackhole_mutex);
259
269
}
260
270
 
261
271
static void blackhole_free_key(st_blackhole_share *share)
262
272
{
263
273
  thr_lock_delete(&share->lock);
264
 
  free((unsigned char*) share);
 
274
  my_free((uchar*) share, MYF(0));
265
275
}
266
276
 
267
 
static unsigned char* blackhole_get_key(st_blackhole_share *share, size_t *length,
268
 
                                bool not_used __attribute__((unused)))
 
277
static uchar* blackhole_get_key(st_blackhole_share *share, size_t *length,
 
278
                                my_bool not_used __attribute__((unused)))
269
279
{
270
280
  *length= share->table_name_length;
271
 
  return (unsigned char*) share->table_name;
 
281
  return (uchar*) share->table_name;
272
282
}
273
283
 
274
284
static int blackhole_init(void *p)
276
286
  handlerton *blackhole_hton;
277
287
  blackhole_hton= (handlerton *)p;
278
288
  blackhole_hton->state= SHOW_OPTION_YES;
 
289
  blackhole_hton->db_type= DB_TYPE_BLACKHOLE_DB;
279
290
  blackhole_hton->create= blackhole_create_handler;
280
291
  blackhole_hton->flags= HTON_CAN_RECREATE;
281
292
  
282
 
  pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST);
 
293
  VOID(pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST));
283
294
  (void) hash_init(&blackhole_open_tables, system_charset_info,32,0,0,
284
295
                   (hash_get_key) blackhole_get_key,
285
296
                   (hash_free_key) blackhole_free_key, 0);
287
298
  return 0;
288
299
}
289
300
 
290
 
static int blackhole_fini(void *p __attribute__((unused)))
 
301
static int blackhole_fini(void *p __attribute__((__unused__)))
291
302
{
292
303
  hash_free(&blackhole_open_tables);
293
304
  pthread_mutex_destroy(&blackhole_mutex);
297
308
 
298
309
mysql_declare_plugin(blackhole)
299
310
{
300
 
  DRIZZLE_STORAGE_ENGINE_PLUGIN,
 
311
  MYSQL_STORAGE_ENGINE_PLUGIN,
301
312
  "BLACKHOLE",
302
313
  "1.0",
303
314
  "MySQL AB",