~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/csv/ha_tina.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
   : drizzled::plugin::StorageEngine(name_arg,
120
120
                                     HTON_TEMPORARY_ONLY |
121
121
                                     HTON_NO_AUTO_INCREMENT |
122
 
                                     HTON_HAS_DATA_DICTIONARY |
123
 
                                     HTON_SKIP_STORE_LOCK |
124
 
                                     HTON_FILE_BASED),
 
122
                                     HTON_SKIP_STORE_LOCK),
125
123
    tina_open_tables()
126
124
  {}
 
125
  virtual ~Tina()
 
126
  {
 
127
    pthread_mutex_destroy(&tina_mutex);
 
128
  }
 
129
 
127
130
  virtual Cursor *create(TableShare &table,
128
131
                         drizzled::memory::Root *mem_root)
129
132
  {
134
137
    return ha_tina_exts;
135
138
  }
136
139
 
137
 
  int doCreateTable(Session *,
138
 
                    const char *table_name,
139
 
                    Table& table_arg,
 
140
  int doCreateTable(Session &,
 
141
                    Table &table_arg,
 
142
                    drizzled::TableIdentifier &identifier,
140
143
                    drizzled::message::Table&);
141
144
 
142
145
  int doGetTableDefinition(Session& session,
143
 
                           const char* path,
144
 
                           const char *db,
145
 
                           const char *table_name,
146
 
                           const bool is_tmp,
147
 
                           drizzled::message::Table *table_proto);
 
146
                           TableIdentifier &identifier,
 
147
                           drizzled::message::Table &table_message);
148
148
 
149
149
  /* Temp only engine, so do not return values. */
150
 
  void doGetTableNames(drizzled::CachedDirectory &, string& , set<string>&) { };
 
150
  void doGetTableNames(drizzled::CachedDirectory &, SchemaIdentifier&, set<string>&) { };
151
151
 
152
 
  int doDropTable(Session&, const string &table_path);
 
152
  int doDropTable(Session&, TableIdentifier &identifier);
153
153
  TinaShare *findOpenTable(const string table_name);
154
154
  void addOpenTable(const string &table_name, TinaShare *);
155
155
  void deleteOpenTable(const string &table_name);
158
158
  uint32_t max_keys()          const { return 0; }
159
159
  uint32_t max_key_parts()     const { return 0; }
160
160
  uint32_t max_key_length()    const { return 0; }
 
161
  bool doDoesTableExist(Session& session, TableIdentifier &identifier);
 
162
  int doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to);
 
163
 
 
164
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
 
165
                             drizzled::SchemaIdentifier &schema_identifier,
 
166
                             drizzled::TableIdentifiers &set_of_identifiers);
161
167
};
162
168
 
163
 
int Tina::doDropTable(Session&,
164
 
                        const string &table_path)
 
169
void Tina::doGetTableIdentifiers(drizzled::CachedDirectory&,
 
170
                                 drizzled::SchemaIdentifier&,
 
171
                                 drizzled::TableIdentifiers&)
 
172
{
 
173
}
 
174
 
 
175
int Tina::doRenameTable(Session &session,
 
176
                        TableIdentifier &from, TableIdentifier &to)
 
177
{
 
178
  int error= 0;
 
179
  for (const char **ext= bas_ext(); *ext ; ext++)
 
180
  {
 
181
    if (rename_file_ext(from.getPath().c_str(), to.getPath().c_str(), *ext))
 
182
    {
 
183
      if ((error=errno) != ENOENT)
 
184
        break;
 
185
      error= 0;
 
186
    }
 
187
  }
 
188
 
 
189
  session.renameTableMessage(from, to);
 
190
 
 
191
  return error;
 
192
}
 
193
 
 
194
bool Tina::doDoesTableExist(Session &session, TableIdentifier &identifier)
 
195
{
 
196
  return session.doesTableMessageExist(identifier);
 
197
}
 
198
 
 
199
 
 
200
int Tina::doDropTable(Session &session,
 
201
                      TableIdentifier &identifier)
165
202
{
166
203
  int error= 0;
167
204
  int enoent_or_zero= ENOENT;                   // Error if no file was deleted
168
205
  char buff[FN_REFLEN];
169
 
  ProtoCache::iterator iter;
170
206
 
171
207
  for (const char **ext= bas_ext(); *ext ; ext++)
172
208
  {
173
 
    internal::fn_format(buff, table_path.c_str(), "", *ext,
174
 
              MY_UNPACK_FILENAME|MY_APPEND_EXT);
 
209
    internal::fn_format(buff, identifier.getPath().c_str(), "", *ext,
 
210
                        MY_UNPACK_FILENAME|MY_APPEND_EXT);
175
211
    if (internal::my_delete_with_symlink(buff, MYF(0)))
176
212
    {
177
213
      if ((error= errno) != ENOENT)
182
218
    error= enoent_or_zero;
183
219
  }
184
220
 
185
 
  pthread_mutex_lock(&proto_cache_mutex);
186
 
  iter= proto_cache.find(table_path.c_str());
187
 
 
188
 
  if (iter!= proto_cache.end())
189
 
    proto_cache.erase(iter);
190
 
  pthread_mutex_unlock(&proto_cache_mutex);
 
221
  session.removeTableMessage(identifier);
191
222
 
192
223
  return error;
193
224
}
214
245
}
215
246
 
216
247
 
217
 
int Tina::doGetTableDefinition(Session&,
218
 
                               const char* path,
219
 
                               const char *,
220
 
                               const char *,
221
 
                               const bool,
222
 
                               drizzled::message::Table *table_proto)
 
248
int Tina::doGetTableDefinition(Session &session,
 
249
                               drizzled::TableIdentifier &identifier,
 
250
                               drizzled::message::Table &table_message)
223
251
{
224
 
  int error= ENOENT;
225
 
  ProtoCache::iterator iter;
226
 
 
227
 
  pthread_mutex_lock(&proto_cache_mutex);
228
 
  iter= proto_cache.find(path);
229
 
 
230
 
  if (iter!= proto_cache.end())
231
 
  {
232
 
    if (table_proto)
233
 
      table_proto->CopyFrom(((*iter).second));
234
 
    error= EEXIST;
235
 
  }
236
 
  pthread_mutex_unlock(&proto_cache_mutex);
237
 
 
238
 
  return error;
 
252
  if (session.getTableMessage(identifier, table_message))
 
253
    return EEXIST;
 
254
 
 
255
  return ENOENT;
239
256
}
240
257
 
241
258
 
242
259
static Tina *tina_engine= NULL;
243
260
 
244
 
static int tina_init_func(drizzled::plugin::Registry &registry)
 
261
static int tina_init_func(drizzled::plugin::Context &context)
245
262
{
246
263
 
247
264
  tina_engine= new Tina("CSV");
248
 
  registry.add(tina_engine);
 
265
  context.add(tina_engine);
249
266
 
250
267
  pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST);
251
268
  return 0;
252
269
}
253
270
 
254
 
static int tina_done_func(drizzled::plugin::Registry &registry)
255
 
{
256
 
  registry.remove(tina_engine);
257
 
  delete tina_engine;
258
 
 
259
 
  pthread_mutex_destroy(&tina_mutex);
260
 
 
261
 
  return 0;
262
 
}
263
271
 
264
272
 
265
273
TinaShare::TinaShare(const char *table_name_arg)
1385
1393
  this (the database will call ::open() if it needs to).
1386
1394
*/
1387
1395
 
1388
 
int Tina::doCreateTable(Session *, const char *table_name,
 
1396
int Tina::doCreateTable(Session &session,
1389
1397
                        Table& table_arg,
1390
 
                        drizzled::message::Table& create_proto)
 
1398
                        drizzled::TableIdentifier &identifier,
 
1399
                        drizzled::message::Table &create_proto)
1391
1400
{
1392
1401
  char name_buff[FN_REFLEN];
1393
1402
  int create_file;
1405
1414
  }
1406
1415
 
1407
1416
 
1408
 
  if ((create_file= internal::my_create(internal::fn_format(name_buff, table_name, "", CSM_EXT,
1409
 
                                        MY_REPLACE_EXT|MY_UNPACK_FILENAME), 0,
1410
 
                              O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
 
1417
  if ((create_file= internal::my_create(internal::fn_format(name_buff, identifier.getPath().c_str(), "", CSM_EXT,
 
1418
                                                            MY_REPLACE_EXT|MY_UNPACK_FILENAME), 0,
 
1419
                                        O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
1411
1420
    return(-1);
1412
1421
 
1413
1422
  write_meta_file(create_file, 0, false);
1414
1423
  internal::my_close(create_file, MYF(0));
1415
1424
 
1416
 
  if ((create_file= internal::my_create(internal::fn_format(name_buff, table_name, "", CSV_EXT,
1417
 
                                        MY_REPLACE_EXT|MY_UNPACK_FILENAME),0,
1418
 
                              O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
 
1425
  if ((create_file= internal::my_create(internal::fn_format(name_buff, identifier.getPath().c_str(), "", CSV_EXT,
 
1426
                                                            MY_REPLACE_EXT|MY_UNPACK_FILENAME),0,
 
1427
                                        O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
1419
1428
    return(-1);
1420
1429
 
1421
1430
  internal::my_close(create_file, MYF(0));
1422
1431
 
1423
 
  pthread_mutex_lock(&proto_cache_mutex);
1424
 
  proto_cache.insert(make_pair(table_name, create_proto));
1425
 
  pthread_mutex_unlock(&proto_cache_mutex);
 
1432
  session.storeTableMessage(identifier, create_proto);
1426
1433
 
1427
1434
  return 0;
1428
1435
}
1437
1444
  "CSV storage engine",
1438
1445
  PLUGIN_LICENSE_GPL,
1439
1446
  tina_init_func, /* Plugin Init */
1440
 
  tina_done_func, /* Plugin Deinit */
1441
1447
  NULL,                       /* system variables                */
1442
1448
  NULL                        /* config options                  */
1443
1449
}