~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.cc

  • Committer: Joe Daly
  • Date: 2010-05-27 02:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 1614.
  • Revision ID: skinny.moey@gmail.com-20100527025916-o4wieb1hxk2shq4u
add status_vars to scoreboard, initial pass

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
#include "drizzled/db.h"
54
54
 
55
55
#include <drizzled/table_proto.h>
 
56
#include <drizzled/plugin/event_observer.h>
56
57
 
57
58
static bool shutdown_has_begun= false; // Once we put in the container for the vector/etc for engines this will go away.
58
59
 
98
99
 
99
100
int StorageEngine::renameTable(Session &session, TableIdentifier &from, TableIdentifier &to)
100
101
{
 
102
  int error;
101
103
  setTransactionReadWrite(session);
102
104
 
103
 
  return doRenameTable(session, from, to);
 
105
  if (unlikely(plugin::EventObserver::beforeRenameTable(session, from, to)))
 
106
  {
 
107
    error= ER_EVENT_OBSERVER_PLUGIN;
 
108
  }
 
109
  else
 
110
  {
 
111
    error =  doRenameTable(session, from, to);
 
112
    if (unlikely(plugin::EventObserver::afterRenameTable(session, from, to, error)))
 
113
    {
 
114
      error= ER_EVENT_OBSERVER_PLUGIN;
 
115
    }
 
116
  }
 
117
  
 
118
  return error;
104
119
}
105
120
 
106
121
/**
464
479
  int error;
465
480
 
466
481
  engine.setTransactionReadWrite(session);
467
 
  error= engine.doDropTable(session, identifier);
 
482
  
 
483
  if (unlikely(plugin::EventObserver::beforeDropTable(session, identifier)))
 
484
  {
 
485
    error= ER_EVENT_OBSERVER_PLUGIN;
 
486
  }
 
487
  else
 
488
  {
 
489
    error= engine.doDropTable(session, identifier);
 
490
    if (unlikely(plugin::EventObserver::afterDropTable(session, identifier, error)))
 
491
    {
 
492
      error= ER_EVENT_OBSERVER_PLUGIN;
 
493
    }
 
494
  }
 
495
 
468
496
 
469
497
  return error;
470
498
}
480
508
*/
481
509
int StorageEngine::createTable(Session &session,
482
510
                               TableIdentifier &identifier,
483
 
                               bool update_create_info,
484
511
                               message::Table& table_message)
485
512
{
486
513
  int error= 1;
488
515
  TableShare share(identifier.getSchemaName().c_str(), 0, identifier.getTableName().c_str(), identifier.getPath().c_str());
489
516
  message::Table tmp_proto;
490
517
 
491
 
  if (parse_table_proto(session, table_message, &share) || open_table_from_share(&session, &share, "", 0, 0, &table))
 
518
  if (share.parse_table_proto(session, table_message) || share.open_table_from_share(&session, "", 0, 0, table))
492
519
  { 
493
520
    // @note Error occured, we should probably do a little more here.
494
521
  }
495
522
  else
496
523
  {
497
 
    if (update_create_info)
498
 
      table.updateCreateInfo(&table_message);
499
 
 
500
524
    /* Check for legal operations against the Engine using the proto (if used) */
501
525
    if (table_message.type() == message::Table::TEMPORARY &&
502
526
        share.storage_engine->check_flag(HTON_BIT_TEMPORARY_NOT_SUPPORTED) == true)
523
547
      my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), identifier.getSQLPath().c_str(), error);
524
548
    }
525
549
 
526
 
    table.closefrm(false);
 
550
    table.delete_table(false);
527
551
  }
528
552
 
529
 
  share.free_table_share();
530
553
  return(error != 0);
531
554
}
532
555
 
637
660
  session.doGetTableIdentifiers(directory, schema_identifier, set_of_identifiers);
638
661
}
639
662
 
 
663
class DropTable: public unary_function<TableIdentifier&, bool>
 
664
{
 
665
  Session &session;
 
666
  StorageEngine *engine;
 
667
 
 
668
public:
 
669
 
 
670
  DropTable(Session &session_arg, StorageEngine *engine_arg) :
 
671
    session(session_arg),
 
672
    engine(engine_arg)
 
673
  { }
 
674
 
 
675
  result_type operator() (argument_type identifier)
 
676
  {
 
677
    return engine->doDropTable(session, identifier) == 0;
 
678
  } 
 
679
};
 
680
 
640
681
/* This will later be converted to TableIdentifiers */
641
682
class DropTables: public unary_function<StorageEngine *, void>
642
683
{
652
693
 
653
694
  result_type operator() (argument_type engine)
654
695
  {
655
 
    for (TableIdentifierList::iterator iter= table_identifiers.begin();
656
 
         iter != table_identifiers.end();
657
 
         iter++)
658
 
    {
659
 
      int error= engine->doDropTable(session, const_cast<TableIdentifier&>(*iter));
660
 
 
661
 
      // On a return of zero we know we found and deleted the table. So we
662
 
      // remove it from our search.
663
 
      if (not error)
664
 
        table_identifiers.erase(iter);
665
 
    }
 
696
    // True returning from DropTable means the table has been successfully
 
697
    // deleted, so it should be removed from the list of tables to drop
 
698
    table_identifiers.erase(remove_if(table_identifiers.begin(),
 
699
                                      table_identifiers.end(),
 
700
                                      DropTable(session, engine)),
 
701
                            table_identifiers.end());
666
702
  }
667
703
};
668
704
 
750
786
  @note
751
787
    In case of delete table it's only safe to use the following parts of
752
788
    the 'table' structure:
753
 
    - table->s->path
 
789
    - table->getShare()->path
754
790
    - table->alias
755
791
*/
756
792
void StorageEngine::print_error(int error, myf errflag, Table &table)
822
858
        str.length(max_length-4);
823
859
        str.append(STRING_WITH_LEN("..."));
824
860
      }
825
 
      my_error(ER_FOREIGN_DUPLICATE_KEY, MYF(0), table->s->table_name.str,
 
861
      my_error(ER_FOREIGN_DUPLICATE_KEY, MYF(0), table->getShare()->getTableName(),
826
862
        str.c_ptr(), key_nr+1);
827
863
      return;
828
864
    }
900
936
    break;
901
937
  case HA_ERR_NO_SUCH_TABLE:
902
938
    assert(table);
903
 
    my_error(ER_NO_SUCH_TABLE, MYF(0), table->s->getSchemaName(),
904
 
             table->s->table_name.str);
 
939
    my_error(ER_NO_SUCH_TABLE, MYF(0), table->getShare()->getSchemaName(),
 
940
             table->getShare()->getTableName());
905
941
    return;
906
942
  case HA_ERR_RBR_LOGGING_FAILED:
907
943
    textno= ER_BINLOG_ROW_LOGGING_FAILED;
957
993
      return;
958
994
    }
959
995
  }
960
 
  my_error(textno, errflag, table->s->table_name.str, error);
 
996
  my_error(textno, errflag, table->getShare()->getTableName(), error);
961
997
}
962
998
 
963
999