~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.cc

Merged trunk and mysql-protocol-password-udf changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
 
67
67
static EngineVector vector_of_engines;
68
68
static EngineVector vector_of_schema_engines;
 
69
static EngineVector vector_of_data_dictionary;
69
70
 
70
71
const std::string UNKNOWN_STRING("UNKNOWN");
71
72
const std::string DEFAULT_DEFINITION_FILE_EXT(".dfe");
125
126
  @retval
126
127
    !0  Error
127
128
*/
128
 
int StorageEngine::doDropTable(Session&,
129
 
                               const string &table_path)
 
129
int StorageEngine::doDropTable(Session&, TableIdentifier &identifier)
 
130
                               
130
131
{
131
132
  int error= 0;
132
133
  int enoent_or_zero= ENOENT;                   // Error if no file was deleted
134
135
 
135
136
  for (const char **ext= bas_ext(); *ext ; ext++)
136
137
  {
137
 
    internal::fn_format(buff, table_path.c_str(), "", *ext,
138
 
              MY_UNPACK_FILENAME|MY_APPEND_EXT);
 
138
    internal::fn_format(buff, identifier.getPath().c_str(), "", *ext,
 
139
                        MY_UNPACK_FILENAME|MY_APPEND_EXT);
139
140
    if (internal::my_delete_with_symlink(buff, MYF(0)))
140
141
    {
141
142
      if ((error= errno) != ENOENT)
148
149
  return error;
149
150
}
150
151
 
151
 
const char *StorageEngine::checkLowercaseNames(const char *path,
152
 
                                                       char *tmp_path)
153
 
{
154
 
  if (flags.test(HTON_BIT_FILE_BASED))
155
 
    return path;
156
 
 
157
 
  /* Ensure that table Cursor get path in lower case */
158
 
  if (tmp_path != path)
159
 
    strcpy(tmp_path, path);
160
 
 
161
 
  /*
162
 
    we only should turn into lowercase database/table part
163
 
    so start the process after homedirectory
164
 
  */
165
 
  if (strstr(tmp_path, drizzle_tmpdir) == tmp_path)
166
 
    my_casedn_str(files_charset_info, tmp_path + strlen(drizzle_tmpdir));
167
 
  else
168
 
    my_casedn_str(files_charset_info, tmp_path + drizzle_data_home_len);
169
 
 
170
 
  return tmp_path;
171
 
}
172
 
 
173
 
 
174
152
bool StorageEngine::addPlugin(StorageEngine *engine)
175
153
{
176
154
 
185
163
  if (engine->check_flag(HTON_BIT_SCHEMA_DICTIONARY))
186
164
    vector_of_schema_engines.push_back(engine);
187
165
 
 
166
  if (engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
 
167
    vector_of_data_dictionary.push_back(engine);
 
168
 
188
169
  return false;
189
170
}
190
171
 
194
175
  {
195
176
    vector_of_engines.clear();
196
177
    vector_of_schema_engines.clear();
 
178
    vector_of_data_dictionary.clear();
197
179
 
198
180
    shutdown_has_begun= true;
199
181
  }
306
288
class StorageEngineGetTableDefinition: public unary_function<StorageEngine *,bool>
307
289
{
308
290
  Session& session;
309
 
  const char* path;
310
 
  const char *db;
311
 
  const char *table_name;
312
 
  const bool is_tmp;
313
 
  message::Table *table_message;
 
291
  TableIdentifier &identifier;
 
292
  message::Table &table_message;
314
293
  int *err;
315
294
 
316
295
public:
317
296
  StorageEngineGetTableDefinition(Session& session_arg,
318
 
                                  const char* path_arg,
319
 
                                  const char *db_arg,
320
 
                                  const char *table_name_arg,
321
 
                                  const bool is_tmp_arg,
322
 
                                  message::Table *table_message_arg,
 
297
                                  TableIdentifier &identifier_arg,
 
298
                                  message::Table &table_message_arg,
323
299
                                  int *err_arg) :
324
300
    session(session_arg), 
325
 
    path(path_arg), 
326
 
    db(db_arg),
327
 
    table_name(table_name_arg),
328
 
    is_tmp(is_tmp_arg),
 
301
    identifier(identifier_arg),
329
302
    table_message(table_message_arg), 
330
303
    err(err_arg) {}
331
304
 
332
305
  result_type operator() (argument_type engine)
333
306
  {
334
307
    int ret= engine->doGetTableDefinition(session,
335
 
                                          path, 
336
 
                                          db,
337
 
                                          table_name,
338
 
                                          is_tmp,
 
308
                                          identifier,
339
309
                                          table_message);
340
310
 
341
311
    if (ret != ENOENT)
345
315
  }
346
316
};
347
317
 
 
318
class StorageEngineDoesTableExist: public unary_function<StorageEngine *, bool>
 
319
{
 
320
  Session& session;
 
321
  TableIdentifier &identifier;
 
322
 
 
323
public:
 
324
  StorageEngineDoesTableExist(Session& session_arg, TableIdentifier &identifier_arg) :
 
325
    session(session_arg), 
 
326
    identifier(identifier_arg) 
 
327
  { }
 
328
 
 
329
  result_type operator() (argument_type engine)
 
330
  {
 
331
    return engine->doDoesTableExist(session, identifier);
 
332
  }
 
333
};
 
334
 
348
335
/**
349
336
  Utility method which hides some of the details of getTableDefinition()
350
337
*/
351
 
bool plugin::StorageEngine::doesTableExist(Session& session,
 
338
bool plugin::StorageEngine::doesTableExist(Session &session,
352
339
                                           TableIdentifier &identifier,
353
340
                                           bool include_temporary_tables)
354
341
{
355
 
  return (plugin::StorageEngine::getTableDefinition(session, identifier, NULL, include_temporary_tables) == EEXIST);
 
342
  if (include_temporary_tables)
 
343
  {
 
344
    if (session.doDoesTableExist(identifier))
 
345
      return true;
 
346
  }
 
347
 
 
348
  EngineVector::iterator iter=
 
349
    find_if(vector_of_data_dictionary.begin(), vector_of_data_dictionary.end(),
 
350
            StorageEngineDoesTableExist(session, identifier));
 
351
 
 
352
  if (iter == vector_of_data_dictionary.end())
 
353
  {
 
354
    return false;
 
355
  }
 
356
 
 
357
  return true;
 
358
}
 
359
 
 
360
bool plugin::StorageEngine::doDoesTableExist(Session&, TableIdentifier&)
 
361
{
 
362
  cerr << " Engine was called for doDoesTableExist() and does not implement it: " << this->getName() << "\n";
 
363
  assert(0);
 
364
  return false;
356
365
}
357
366
 
358
367
/**
362
371
*/
363
372
int StorageEngine::getTableDefinition(Session& session,
364
373
                                      TableIdentifier &identifier,
365
 
                                      message::Table *table_message,
 
374
                                      message::Table &table_message,
366
375
                                      bool include_temporary_tables)
367
376
{
368
 
  return getTableDefinition(session,
369
 
                            identifier.getPath(), identifier.getDBName(), identifier.getTableName(), identifier.isTmp(),
370
 
                            table_message, include_temporary_tables);
371
 
}
372
 
 
373
 
int StorageEngine::getTableDefinition(Session& session,
374
 
                                              const char* path,
375
 
                                              const char *schema_name,
376
 
                                              const char *table_name,
377
 
                                              const bool,
378
 
                                              message::Table *table_message,
379
 
                                              bool include_temporary_tables)
380
 
{
381
377
  int err= ENOENT;
382
378
 
383
379
  if (include_temporary_tables)
384
380
  {
385
 
    if (session.doGetTableDefinition(path, schema_name, table_name, false, table_message) == EEXIST)
 
381
    if (session.doGetTableDefinition(identifier, table_message) == EEXIST)
386
382
      return EEXIST;
387
383
  }
388
384
 
389
385
  EngineVector::iterator iter=
390
386
    find_if(vector_of_engines.begin(), vector_of_engines.end(),
391
 
            StorageEngineGetTableDefinition(session, path, NULL, NULL, true, table_message, &err));
 
387
            StorageEngineGetTableDefinition(session, identifier, table_message, &err));
392
388
 
393
389
  if (iter == vector_of_engines.end())
394
390
  {
448
444
  {
449
445
    // @todo someday check that at least one engine said "true"
450
446
    std::string path(identifier.getPath());
451
 
    bool success= engine->doDropTable(session, path);
 
447
    bool success= engine->doDropTable(session, identifier, path);
452
448
 
453
449
    if (success)
454
450
      success_count++;
467
463
  message::Table src_proto;
468
464
  StorageEngine* engine;
469
465
 
470
 
  error_proto= StorageEngine::getTableDefinition(session,
471
 
                                                 identifier,
472
 
                                                 &src_proto);
 
466
  error_proto= StorageEngine::getTableDefinition(session, identifier, src_proto);
473
467
 
474
468
  if (error_proto == ER_CORRUPT_TABLE_DEFINITION)
475
469
  {
484
478
  {
485
479
    std::string path(identifier.getPath());
486
480
    engine->setTransactionReadWrite(session);
487
 
    error= engine->doDropTable(session, path);
 
481
    error= engine->doDropTable(session, identifier, path);
488
482
 
489
483
    if (not error)
490
484
    {
521
515
{
522
516
  int error= 1;
523
517
  Table table;
524
 
  TableShare share(identifier.getDBName(), 0, identifier.getTableName(), identifier.getPath());
 
518
  TableShare share(identifier.getDBName().c_str(), 0, identifier.getTableName().c_str(), identifier.getPath().c_str());
525
519
  message::Table tmp_proto;
526
520
 
527
521
  if (parse_table_proto(session, table_message, &share))
549
543
  }
550
544
 
551
545
  {
552
 
    char name_buff[FN_REFLEN];
553
 
    const char *table_name_arg;
554
 
 
555
 
    table_name_arg= share.storage_engine->checkLowercaseNames(identifier.getPath(), name_buff);
556
 
 
557
546
    if (not share.storage_engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
558
547
    {
559
548
      int protoerr= StorageEngine::writeDefinitionFromPath(identifier, table_message);
568
557
    share.storage_engine->setTransactionReadWrite(session);
569
558
 
570
559
    error= share.storage_engine->doCreateTable(&session,
571
 
                                               table_name_arg,
572
560
                                               table,
 
561
                                               identifier,
573
562
                                               table_message);
574
563
  }
575
564
 
821
810
 
822
811
void StorageEngine::getTableNames(const string &schema_name, TableNameList &set_of_names)
823
812
{
824
 
  char tmp_path[FN_REFLEN];
 
813
  string tmp_path;
825
814
 
826
 
  build_table_filename(tmp_path, sizeof(tmp_path), schema_name.c_str(), "", false);
 
815
  build_table_filename(tmp_path, schema_name.c_str(), "", false);
827
816
 
828
817
  CachedDirectory directory(tmp_path, set_of_table_definition_ext);
829
818
 
868
857
 
869
858
  result_type operator() (argument_type engine)
870
859
  {
871
 
 
872
860
    for (TableNameList::iterator iter= set_of_names.begin();
873
861
         iter != set_of_names.end();
874
862
         iter++)
875
863
    {
876
 
      int error= engine->doDropTable(session, *iter);
 
864
      TableIdentifier dummy((*iter).c_str());
 
865
      int error= engine->doDropTable(session, dummy, *iter);
877
866
 
878
867
      // On a return of zero we know we found and deleted the table. So we
879
868
      // remove it from our search.
1112
1101
    break;
1113
1102
  case HA_ERR_NO_SUCH_TABLE:
1114
1103
    assert(table);
1115
 
    my_error(ER_NO_SUCH_TABLE, MYF(0), table->s->db.str,
 
1104
    my_error(ER_NO_SUCH_TABLE, MYF(0), table->s->getSchemaName(),
1116
1105
             table->s->table_name.str);
1117
1106
    return;
1118
1107
  case HA_ERR_RBR_LOGGING_FAILED: