~stewart/drizzle/embedded-innodb-rnd-read

« back to all changes in this revision

Viewing changes to plugin/csv/ha_tina.cc

  • Committer: Stewart Smith
  • Date: 2010-03-30 13:09:42 UTC
  • mfrom: (1310.1.38)
  • Revision ID: stewart@flamingspork.com-20100330130942-859uivdm20p36sk3
Merged embedded-innodb-write-row into embedded-innodb-rnd-read.

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
                                     HTON_FILE_BASED),
125
125
    tina_open_tables()
126
126
  {}
 
127
  virtual ~Tina()
 
128
  {
 
129
    pthread_mutex_destroy(&tina_mutex);
 
130
  }
 
131
 
127
132
  virtual Cursor *create(TableShare &table,
128
133
                         drizzled::memory::Root *mem_root)
129
134
  {
156
161
  uint32_t max_key_parts()     const { return 0; }
157
162
  uint32_t max_key_length()    const { return 0; }
158
163
  bool doDoesTableExist(Session& session, TableIdentifier &identifier);
 
164
  int doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to);
159
165
};
160
166
 
161
167
 
162
 
bool Tina::doDoesTableExist(Session&, TableIdentifier &identifier)
 
168
int Tina::doRenameTable(Session &session,
 
169
                        TableIdentifier &from, TableIdentifier &to)
163
170
{
164
 
  ProtoCache::iterator iter;
165
 
 
166
 
  pthread_mutex_lock(&proto_cache_mutex);
167
 
  iter= proto_cache.find(identifier.getPath());
168
 
 
169
 
  if (iter != proto_cache.end())
 
171
  int error= 0;
 
172
  for (const char **ext= bas_ext(); *ext ; ext++)
170
173
  {
171
 
    return true;
 
174
    if (rename_file_ext(from.getPath().c_str(), to.getPath().c_str(), *ext))
 
175
    {
 
176
      if ((error=errno) != ENOENT)
 
177
        break;
 
178
      error= 0;
 
179
    }
172
180
  }
173
 
  pthread_mutex_unlock(&proto_cache_mutex);
174
 
 
175
 
  return false;
176
 
}
177
 
 
178
 
 
179
 
int Tina::doDropTable(Session&,
 
181
 
 
182
  session.renameTableMessage(from, to);
 
183
 
 
184
  return error;
 
185
}
 
186
 
 
187
bool Tina::doDoesTableExist(Session &session, TableIdentifier &identifier)
 
188
{
 
189
  return session.doesTableMessageExist(identifier);
 
190
}
 
191
 
 
192
 
 
193
int Tina::doDropTable(Session &session,
180
194
                      TableIdentifier &identifier)
181
195
{
182
196
  int error= 0;
183
197
  int enoent_or_zero= ENOENT;                   // Error if no file was deleted
184
198
  char buff[FN_REFLEN];
185
 
  ProtoCache::iterator iter;
186
199
 
187
200
  for (const char **ext= bas_ext(); *ext ; ext++)
188
201
  {
198
211
    error= enoent_or_zero;
199
212
  }
200
213
 
201
 
  pthread_mutex_lock(&proto_cache_mutex);
202
 
  iter= proto_cache.find(identifier.getPath());
203
 
 
204
 
  if (iter!= proto_cache.end())
205
 
    proto_cache.erase(iter);
206
 
  pthread_mutex_unlock(&proto_cache_mutex);
 
214
  session.removeTableMessage(identifier);
207
215
 
208
216
  return error;
209
217
}
230
238
}
231
239
 
232
240
 
233
 
int Tina::doGetTableDefinition(Session&,
 
241
int Tina::doGetTableDefinition(Session &session,
234
242
                               drizzled::TableIdentifier &identifier,
235
243
                               drizzled::message::Table &table_message)
236
244
{
237
 
  int error= ENOENT;
238
 
  ProtoCache::iterator iter;
239
 
 
240
 
  pthread_mutex_lock(&proto_cache_mutex);
241
 
  iter= proto_cache.find(identifier.getPath());
242
 
 
243
 
  if (iter!= proto_cache.end())
244
 
  {
245
 
    table_message.CopyFrom(((*iter).second));
246
 
    error= EEXIST;
247
 
  }
248
 
  pthread_mutex_unlock(&proto_cache_mutex);
249
 
 
250
 
  return error;
 
245
  if (session.getTableMessage(identifier, table_message))
 
246
    return EEXIST;
 
247
 
 
248
  return ENOENT;
251
249
}
252
250
 
253
251
 
254
252
static Tina *tina_engine= NULL;
255
253
 
256
 
static int tina_init_func(drizzled::plugin::Registry &registry)
 
254
static int tina_init_func(drizzled::plugin::Context &context)
257
255
{
258
256
 
259
257
  tina_engine= new Tina("CSV");
260
 
  registry.add(tina_engine);
 
258
  context.add(tina_engine);
261
259
 
262
260
  pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST);
263
261
  return 0;
264
262
}
265
263
 
266
 
static int tina_done_func(drizzled::plugin::Registry &registry)
267
 
{
268
 
  registry.remove(tina_engine);
269
 
  delete tina_engine;
270
 
 
271
 
  pthread_mutex_destroy(&tina_mutex);
272
 
 
273
 
  return 0;
274
 
}
275
264
 
276
265
 
277
266
TinaShare::TinaShare(const char *table_name_arg)
1397
1386
  this (the database will call ::open() if it needs to).
1398
1387
*/
1399
1388
 
1400
 
int Tina::doCreateTable(Session *,
 
1389
int Tina::doCreateTable(Session *session,
1401
1390
                        Table& table_arg,
1402
1391
                        drizzled::TableIdentifier &identifier,
1403
 
                        drizzled::message::Table& create_proto)
 
1392
                        drizzled::message::Table &create_proto)
1404
1393
{
1405
1394
  char name_buff[FN_REFLEN];
1406
1395
  int create_file;
1433
1422
 
1434
1423
  internal::my_close(create_file, MYF(0));
1435
1424
 
1436
 
  pthread_mutex_lock(&proto_cache_mutex);
1437
 
  proto_cache.insert(make_pair(identifier.getPath(), create_proto));
1438
 
  pthread_mutex_unlock(&proto_cache_mutex);
 
1425
  session->storeTableMessage(identifier, create_proto);
1439
1426
 
1440
1427
  return 0;
1441
1428
}
1450
1437
  "CSV storage engine",
1451
1438
  PLUGIN_LICENSE_GPL,
1452
1439
  tina_init_func, /* Plugin Init */
1453
 
  tina_done_func, /* Plugin Deinit */
1454
1440
  NULL,                       /* system variables                */
1455
1441
  NULL                        /* config options                  */
1456
1442
}