~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/csv/ha_tina.cc

  • Committer: Stewart Smith
  • Date: 2010-03-15 04:42:26 UTC
  • mto: (1283.38.1)
  • mto: This revision was merged to the branch mainline in revision 1475.
  • Revision ID: stewart@flamingspork.com-20100315044226-q74o953r9h98brm4
basic embedded innodb DATA_DICTIONARY.INNODB_CONFIGURATION test

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
 
 
132
127
  virtual Cursor *create(TableShare &table,
133
128
                         drizzled::memory::Root *mem_root)
134
129
  {
140
135
  }
141
136
 
142
137
  int doCreateTable(Session *,
 
138
                    const char *table_name,
143
139
                    Table& table_arg,
144
 
                    drizzled::TableIdentifier &identifier,
145
140
                    drizzled::message::Table&);
146
141
 
147
142
  int doGetTableDefinition(Session& session,
148
 
                           TableIdentifier &identifier,
149
 
                           drizzled::message::Table &table_message);
 
143
                           const char* path,
 
144
                           const char *db,
 
145
                           const char *table_name,
 
146
                           const bool is_tmp,
 
147
                           drizzled::message::Table *table_proto);
150
148
 
151
149
  /* Temp only engine, so do not return values. */
152
150
  void doGetTableNames(drizzled::CachedDirectory &, string& , set<string>&) { };
153
151
 
154
 
  int doDropTable(Session&, TableIdentifier &identifier);
 
152
  int doDropTable(Session&, const string &table_path);
155
153
  TinaShare *findOpenTable(const string table_name);
156
154
  void addOpenTable(const string &table_name, TinaShare *);
157
155
  void deleteOpenTable(const string &table_name);
160
158
  uint32_t max_keys()          const { return 0; }
161
159
  uint32_t max_key_parts()     const { return 0; }
162
160
  uint32_t max_key_length()    const { return 0; }
163
 
  bool doDoesTableExist(Session& session, TableIdentifier &identifier);
164
 
  int doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to);
165
161
};
166
162
 
167
 
 
168
 
int Tina::doRenameTable(Session &session,
169
 
                        TableIdentifier &from, TableIdentifier &to)
170
 
{
171
 
  int error= 0;
172
 
  for (const char **ext= bas_ext(); *ext ; ext++)
173
 
  {
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
 
    }
180
 
  }
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,
194
 
                      TableIdentifier &identifier)
 
163
int Tina::doDropTable(Session&,
 
164
                        const string &table_path)
195
165
{
196
166
  int error= 0;
197
167
  int enoent_or_zero= ENOENT;                   // Error if no file was deleted
198
168
  char buff[FN_REFLEN];
 
169
  ProtoCache::iterator iter;
199
170
 
200
171
  for (const char **ext= bas_ext(); *ext ; ext++)
201
172
  {
202
 
    internal::fn_format(buff, identifier.getPath().c_str(), "", *ext,
203
 
                        MY_UNPACK_FILENAME|MY_APPEND_EXT);
 
173
    internal::fn_format(buff, table_path.c_str(), "", *ext,
 
174
              MY_UNPACK_FILENAME|MY_APPEND_EXT);
204
175
    if (internal::my_delete_with_symlink(buff, MYF(0)))
205
176
    {
206
177
      if ((error= errno) != ENOENT)
211
182
    error= enoent_or_zero;
212
183
  }
213
184
 
214
 
  session.removeTableMessage(identifier);
 
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);
215
191
 
216
192
  return error;
217
193
}
238
214
}
239
215
 
240
216
 
241
 
int Tina::doGetTableDefinition(Session &session,
242
 
                               drizzled::TableIdentifier &identifier,
243
 
                               drizzled::message::Table &table_message)
 
217
int Tina::doGetTableDefinition(Session&,
 
218
                               const char* path,
 
219
                               const char *,
 
220
                               const char *,
 
221
                               const bool,
 
222
                               drizzled::message::Table *table_proto)
244
223
{
245
 
  if (session.getTableMessage(identifier, table_message))
246
 
    return EEXIST;
247
 
 
248
 
  return ENOENT;
 
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;
249
239
}
250
240
 
251
241
 
252
242
static Tina *tina_engine= NULL;
253
243
 
254
 
static int tina_init_func(drizzled::plugin::Context &context)
 
244
static int tina_init_func(drizzled::plugin::Registry &registry)
255
245
{
256
246
 
257
247
  tina_engine= new Tina("CSV");
258
 
  context.add(tina_engine);
 
248
  registry.add(tina_engine);
259
249
 
260
250
  pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST);
261
251
  return 0;
262
252
}
263
253
 
 
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
}
264
263
 
265
264
 
266
265
TinaShare::TinaShare(const char *table_name_arg)
1386
1385
  this (the database will call ::open() if it needs to).
1387
1386
*/
1388
1387
 
1389
 
int Tina::doCreateTable(Session *session,
 
1388
int Tina::doCreateTable(Session *, const char *table_name,
1390
1389
                        Table& table_arg,
1391
 
                        drizzled::TableIdentifier &identifier,
1392
 
                        drizzled::message::Table &create_proto)
 
1390
                        drizzled::message::Table& create_proto)
1393
1391
{
1394
1392
  char name_buff[FN_REFLEN];
1395
1393
  int create_file;
1407
1405
  }
1408
1406
 
1409
1407
 
1410
 
  if ((create_file= internal::my_create(internal::fn_format(name_buff, identifier.getPath().c_str(), "", CSM_EXT,
1411
 
                                                            MY_REPLACE_EXT|MY_UNPACK_FILENAME), 0,
1412
 
                                        O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
 
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)
1413
1411
    return(-1);
1414
1412
 
1415
1413
  write_meta_file(create_file, 0, false);
1416
1414
  internal::my_close(create_file, MYF(0));
1417
1415
 
1418
 
  if ((create_file= internal::my_create(internal::fn_format(name_buff, identifier.getPath().c_str(), "", CSV_EXT,
1419
 
                                                            MY_REPLACE_EXT|MY_UNPACK_FILENAME),0,
1420
 
                                        O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
 
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)
1421
1419
    return(-1);
1422
1420
 
1423
1421
  internal::my_close(create_file, MYF(0));
1424
1422
 
1425
 
  session->storeTableMessage(identifier, create_proto);
 
1423
  pthread_mutex_lock(&proto_cache_mutex);
 
1424
  proto_cache.insert(make_pair(table_name, create_proto));
 
1425
  pthread_mutex_unlock(&proto_cache_mutex);
1426
1426
 
1427
1427
  return 0;
1428
1428
}
1437
1437
  "CSV storage engine",
1438
1438
  PLUGIN_LICENSE_GPL,
1439
1439
  tina_init_func, /* Plugin Init */
 
1440
  tina_done_func, /* Plugin Deinit */
1440
1441
  NULL,                       /* system variables                */
1441
1442
  NULL                        /* config options                  */
1442
1443
}