~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.cc

Merge trunk and resolve all conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
#include <drizzled/definitions.h>
35
35
#include <drizzled/base.h>
36
 
#include <drizzled/handler.h>
 
36
#include <drizzled/cursor.h>
37
37
#include <drizzled/plugin/storage_engine.h>
38
38
#include <drizzled/session.h>
39
39
#include <drizzled/error.h>
40
40
#include <drizzled/gettext.h>
41
 
#include <drizzled/registry.h>
 
41
#include <drizzled/name_map.h>
42
42
#include <drizzled/unireg.h>
43
43
#include <drizzled/data_home.h>
44
44
#include "drizzled/errmsg_print.h"
45
 
#include <drizzled/plugin/registry.h>
 
45
#include "drizzled/name_map.h"
46
46
#include "drizzled/xid.h"
47
47
 
48
48
#include <drizzled/table_proto.h>
52
52
namespace drizzled
53
53
{
54
54
 
55
 
Registry<plugin::StorageEngine *> all_engines;
 
55
NameMap<plugin::StorageEngine *> all_engines;
56
56
 
57
57
plugin::StorageEngine::StorageEngine(const string name_arg,
58
58
                                     const bitset<HTON_BIT_SIZE> &flags_arg,
127
127
  @param name           Base name of table
128
128
 
129
129
  @note
130
 
    We assume that the handler may return more extensions than
 
130
    We assume that the Cursor may return more extensions than
131
131
    was actually used for the file.
132
132
 
133
133
  @retval
165
165
  if (flags.test(HTON_BIT_FILE_BASED))
166
166
    return path;
167
167
 
168
 
  /* Ensure that table handler get path in lower case */
 
168
  /* Ensure that table Cursor get path in lower case */
169
169
  if (tmp_path != path)
170
170
    strcpy(tmp_path, path);
171
171
 
206
206
            find_str.begin(), ::tolower);
207
207
  string default_str("default");
208
208
  if (find_str == default_str)
209
 
    return ha_default_storage_engine(session);
 
209
    return session->getDefaultStorageEngine();
210
210
 
211
211
  plugin::StorageEngine *engine= all_engines.find(find_str);
212
212
 
273
273
  or the EOF mark to the client. It releases a possible adaptive hash index
274
274
  S-latch held by session in InnoDB and also releases a possible InnoDB query
275
275
  FIFO ticket to enter InnoDB. To save CPU time, InnoDB allows a session to
276
 
  keep them over several calls of the InnoDB handler interface when a join
 
276
  keep them over several calls of the InnoDB Cursor interface when a join
277
277
  is executed. But when we let the control to pass to the client they have
278
278
  to be released because if the application program uses mysql_use_result(),
279
279
  it may deadlock on the S-latch if the application on another connection
516
516
}
517
517
 
518
518
/**
519
 
  Call this function in order to give the handler the possiblity
 
519
  Call this function in order to give the Cursor the possiblity
520
520
  to ask engine if there are any new tables that should be written to disk
521
521
  or any dropped tables that need to be removed from disk
522
522
*/
525
525
{
526
526
  int err= ENOENT;
527
527
 
528
 
  ::drizzled::Registry<plugin::StorageEngine *>::iterator iter=
 
528
  NameMap<plugin::StorageEngine *>::iterator iter=
529
529
    find_if(all_engines.begin(), all_engines.end(),
530
530
            StorageEngineGetTableProto(path, table_proto, &err));
531
531
  if (iter == all_engines.end())
590
590
{
591
591
  Session *session;
592
592
  const char *path;
593
 
  handler **file;
 
593
  Cursor **file;
594
594
  int *dt_error;
595
595
public:
596
596
  DeleteTableStorageEngine(Session *session_arg, const char *path_arg,
597
 
                           handler **file_arg, int *error_arg)
 
597
                           Cursor **file_arg, int *error_arg)
598
598
    : session(session_arg), path(path_arg), file(file_arg), dt_error(error_arg) {}
599
599
 
600
600
  result_type operator() (argument_type engine)
601
601
  {
602
602
    char tmp_path[FN_REFLEN];
603
 
    handler *tmp_file;
 
603
    Cursor *tmp_file;
604
604
 
605
605
    if(*dt_error!=ENOENT) /* already deleted table */
606
606
      return;
660
660
  dummy_table.s= &dummy_share;
661
661
 
662
662
  int error= ENOENT;
663
 
  handler *file= NULL;
 
663
  Cursor *file= NULL;
664
664
 
665
665
  for_each(all_engines.begin(), all_engines.end(),
666
666
           DeleteTableStorageEngine(session, path, &file, &error));
672
672
  {
673
673
    /*
674
674
      Because file->print_error() use my_error() to generate the error message
675
 
      we use an internal error handler to intercept it and store the text
 
675
      we use an internal error Cursor to intercept it and store the text
676
676
      in a temporary buffer. Later the message will be presented to user
677
677
      as a warning.
678
678
    */
779
779
 
780
780
    file= dirp->dir_entry + current_entry;
781
781
 
782
 
    if (my_strcasecmp(system_charset_info, ext=fn_rext(file->name),".dfe") ||
783
 
        is_prefix(file->name, TMP_FILE_PREFIX))
784
 
      continue;
785
 
    *ext=0;
 
782
    ext= fn_rext(file->name);
 
783
 
 
784
    if (ext != NULL)
 
785
    {
 
786
      if (my_strcasecmp(system_charset_info, ext, ".dfe") ||
 
787
          is_prefix(file->name, TMP_FILE_PREFIX))
 
788
        continue;
 
789
      *ext=0;
 
790
    }
786
791
 
787
792
    file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
788
793
 
854
859
 
855
860
 
856
861
/**
 
862
  Return the default storage engine plugin::StorageEngine for thread
 
863
 
 
864
  defaultStorageEngine(session)
 
865
  @param session         current thread
 
866
 
 
867
  @return
 
868
    pointer to plugin::StorageEngine
 
869
*/
 
870
plugin::StorageEngine *plugin::StorageEngine::defaultStorageEngine(Session *session)
 
871
{
 
872
  if (session->variables.storage_engine)
 
873
    return session->variables.storage_engine;
 
874
  return global_system_variables.storage_engine;
 
875
}
 
876
 
 
877
/**
857
878
  Initiates table-file and calls appropriate database-creator.
858
879
 
859
880
  @retval
865
886
                                       const char *db, const char *table_name,
866
887
                                       HA_CREATE_INFO *create_info,
867
888
                                       bool update_create_info,
868
 
                                       drizzled::message::Table *table_proto)
 
889
                                       message::Table *table_proto)
869
890
{
870
891
  int error= 1;
871
892
  Table table;
872
893
  TableShare share(db, 0, table_name, path);
873
 
  drizzled::message::Table tmp_proto;
 
894
  message::Table tmp_proto;
874
895
 
875
896
  if (table_proto)
876
897
  {
905
926
  return(error != 0);
906
927
}
907
928
 
 
929
Cursor *plugin::StorageEngine::getCursor(TableShare *share, MEM_ROOT *alloc)
 
930
{
 
931
  Cursor *file;
 
932
 
 
933
  assert(enabled);
 
934
 
 
935
  if ((file= create(share, alloc)))
 
936
    file->init();
 
937
  return file;
 
938
}
908
939
 
909
940
 
910
941
} /* namespace drizzled */
911
 
 
912
 
 
913
 
 
914
 
handler *get_new_handler(TableShare *share, MEM_ROOT *alloc,
915
 
                         drizzled::plugin::StorageEngine *engine)
916
 
{
917
 
  handler *file;
918
 
 
919
 
  if (engine && engine->is_enabled())
920
 
  {
921
 
    if ((file= engine->create(share, alloc)))
922
 
      file->init();
923
 
    return(file);
924
 
  }
925
 
  /*
926
 
    Try the default table type
927
 
    Here the call to current_session() is ok as we call this function a lot of
928
 
    times but we enter this branch very seldom.
929
 
  */
930
 
  return(get_new_handler(share, alloc, ha_default_storage_engine(current_session)));
931
 
}
932
 
 
933
 
 
934
 
/**
935
 
  Return the default storage engine plugin::StorageEngine for thread
936
 
 
937
 
  @param ha_default_storage_engine(session)
938
 
  @param session         current thread
939
 
 
940
 
  @return
941
 
    pointer to plugin::StorageEngine
942
 
*/
943
 
drizzled::plugin::StorageEngine *ha_default_storage_engine(Session *session)
944
 
{
945
 
  if (session->variables.storage_engine)
946
 
    return session->variables.storage_engine;
947
 
  return global_system_variables.storage_engine;
948
 
}