~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/filesystem_engine/filesystem_engine.cc

  • Committer: lbieber
  • Date: 2010-10-05 22:23:12 UTC
  • mfrom: (1813.1.4 build)
  • Revision ID: lbieber@orisndriz08-20101005222312-weuq0ardk3gcryau
Merge Travis - 621861 - convert structs to classes
Merge Billy - 621331 - Replace use of stringstream with boost::lexical_cast
Merge Travis - 621861 = To change C structs to C++ classes in Drizzle
Merge Andrew - fix bug 653300 - Syntax error on inport of a SQL file produced by drizzledump

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "config.h"
20
20
#include <drizzled/field.h>
21
21
#include <drizzled/field/blob.h>
 
22
#include <drizzled/field/timestamp.h>
22
23
#include <drizzled/error.h>
23
24
#include <drizzled/table.h>
24
25
#include <drizzled/session.h>
73
74
    pthread_mutex_destroy(&filesystem_mutex);
74
75
  }
75
76
 
76
 
  virtual Cursor *create(Table &table)
 
77
  virtual Cursor *create(TableShare &table)
77
78
  {
78
79
    return new FilesystemCursor(*this, table);
79
80
  }
86
87
 
87
88
  int doCreateTable(Session &,
88
89
                    Table &table_arg,
89
 
                    const drizzled::identifier::Table &identifier,
 
90
                    const drizzled::TableIdentifier &identifier,
90
91
                    drizzled::message::Table&);
91
92
 
92
93
  int doGetTableDefinition(Session& ,
93
 
                           const drizzled::identifier::Table &,
 
94
                           const drizzled::TableIdentifier &,
94
95
                           drizzled::message::Table &);
95
96
 
96
 
  int doDropTable(Session&, const identifier::Table &);
 
97
  int doDropTable(Session&, const TableIdentifier &);
97
98
 
98
99
  /* operations on FilesystemTableShare */
99
100
  FilesystemTableShare *findOpenTable(const string table_name);
103
104
  uint32_t max_keys()          const { return 0; }
104
105
  uint32_t max_key_parts()     const { return 0; }
105
106
  uint32_t max_key_length()    const { return 0; }
106
 
  bool doDoesTableExist(Session& , const identifier::Table &);
107
 
  int doRenameTable(Session&, const identifier::Table &, const identifier::Table &);
 
107
  bool doDoesTableExist(Session& , const TableIdentifier &);
 
108
  int doRenameTable(Session&, const TableIdentifier &, const TableIdentifier &);
108
109
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
109
 
                             const drizzled::identifier::Schema &schema_identifier,
110
 
                             drizzled::identifier::Table::vector &set_of_identifiers);
 
110
                             const drizzled::SchemaIdentifier &schema_identifier,
 
111
                             drizzled::TableIdentifiers &set_of_identifiers);
111
112
private:
112
113
  void getTableNamesFromFilesystem(drizzled::CachedDirectory &directory,
113
 
                                   const drizzled::identifier::Schema &schema_identifier,
 
114
                                   const drizzled::SchemaIdentifier &schema_identifier,
114
115
                                   drizzled::plugin::TableNameList *set_of_names,
115
 
                                   drizzled::identifier::Table::vector *set_of_identifiers);
 
116
                                   drizzled::TableIdentifiers *set_of_identifiers);
116
117
};
117
118
 
118
119
void FilesystemEngine::getTableNamesFromFilesystem(drizzled::CachedDirectory &directory,
119
 
                                                   const drizzled::identifier::Schema &schema_identifier,
 
120
                                                   const drizzled::SchemaIdentifier &schema_identifier,
120
121
                                                   drizzled::plugin::TableNameList *set_of_names,
121
 
                                                   drizzled::identifier::Table::vector *set_of_identifiers)
 
122
                                                   drizzled::TableIdentifiers *set_of_identifiers)
122
123
{
123
124
  drizzled::CachedDirectory::Entries entries= directory.getEntries();
124
125
 
140
141
      char uname[NAME_LEN + 1];
141
142
      uint32_t file_name_len;
142
143
 
143
 
      file_name_len= identifier::Table::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
 
144
      file_name_len= TableIdentifier::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
144
145
      uname[file_name_len - sizeof(FILESYSTEM_EXT) + 1]= '\0';
145
146
      if (set_of_names)
146
147
        set_of_names->insert(uname);
147
148
      if (set_of_identifiers)
148
 
        set_of_identifiers->push_back(identifier::Table(schema_identifier, uname));
 
149
        set_of_identifiers->push_back(TableIdentifier(schema_identifier, uname));
149
150
    }
150
151
  }
151
152
}
152
153
 
153
154
void FilesystemEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
154
 
                                             const drizzled::identifier::Schema &schema_identifier,
155
 
                                             drizzled::identifier::Table::vector &set_of_identifiers)
 
155
                                             const drizzled::SchemaIdentifier &schema_identifier,
 
156
                                             drizzled::TableIdentifiers &set_of_identifiers)
156
157
{
157
158
  getTableNamesFromFilesystem(directory, schema_identifier, NULL, &set_of_identifiers);
158
159
}
159
160
 
160
 
int FilesystemEngine::doDropTable(Session &, const identifier::Table &identifier)
 
161
int FilesystemEngine::doDropTable(Session &, const TableIdentifier &identifier)
161
162
{
162
163
  string new_path(identifier.getPath());
163
164
  new_path+= FILESYSTEM_EXT;
169
170
  return err;
170
171
}
171
172
 
172
 
bool FilesystemEngine::doDoesTableExist(Session &, const identifier::Table &identifier)
 
173
bool FilesystemEngine::doDoesTableExist(Session &, const TableIdentifier &identifier)
173
174
{
174
175
  string proto_path(identifier.getPath());
175
176
  proto_path.append(FILESYSTEM_EXT);
281
282
}
282
283
 
283
284
int FilesystemEngine::doGetTableDefinition(Session &,
284
 
                                           const drizzled::identifier::Table &identifier,
 
285
                                           const drizzled::TableIdentifier &identifier,
285
286
                                           drizzled::message::Table &table_proto)
286
287
{
287
288
  string new_path(identifier.getPath());
304
305
    if (not table_proto.IsInitialized())
305
306
    {
306
307
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
307
 
               table_proto.name().empty() ? " " : table_proto.name().c_str(),
308
308
               table_proto.InitializationErrorString().c_str());
309
 
 
310
309
      return ER_CORRUPT_TABLE_DEFINITION;
311
310
    }
312
311
 
318
317
  // then columns of this table are added dynamically here.
319
318
  FormatInfo format;
320
319
  format.parseFromTable(&table_proto);
321
 
  if (not format.isTagFormat() || not format.isFileGiven())
322
 
  {
 
320
  if (!format.isTagFormat() || !format.isFileGiven()) {
323
321
    close(fd);
324
322
    return EEXIST;
325
323
  }
326
324
 
327
 
  std::vector< std::map<std::string, std::string> > vm;
328
 
  if (parseTaggedFile(format, vm) != 0)
329
 
  {
 
325
  vector< map<string, string> > vm;
 
326
  if (parseTaggedFile(format, vm) != 0) {
330
327
    close(fd);
331
328
 
332
329
    return EEXIST;
339
336
  // we don't care what user provides, just clear them all
340
337
  table_proto.clear_field();
341
338
  // we take the first section as sample
342
 
  std::map<string, string> kv= vm[0];
343
 
  for (std::map<string, string>::iterator iter= kv.begin();
 
339
  map<string, string> kv= vm[0];
 
340
  for (map<string, string>::iterator iter= kv.begin();
344
341
       iter != kv.end();
345
342
       ++iter)
346
343
  {
372
369
{
373
370
  Guard g(filesystem_mutex);
374
371
 
375
 
  FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(getEngine());
 
372
  FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(engine);
376
373
  share= a_engine->findOpenTable(table_name);
377
374
 
378
375
  /*
387
384
      return NULL;
388
385
    }
389
386
 
390
 
    share->format.parseFromTable(getTable()->getShare()->getTableProto());
 
387
    share->format.parseFromTable(table->getShare()->getTableProto());
391
388
    if (!share->format.isFileGiven())
392
389
    {
393
390
      return NULL;
417
414
  Guard g(filesystem_mutex);
418
415
 
419
416
  if (!--share->use_count){
420
 
    FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(getEngine());
 
417
    FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(engine);
421
418
    a_engine->deleteOpenTable(share->table_name);
422
419
    pthread_mutex_destroy(&share->mutex);
423
420
    delete share;
456
453
  thread_locked = false;
457
454
}
458
455
 
459
 
FilesystemCursor::FilesystemCursor(drizzled::plugin::StorageEngine &engine_arg, Table &table_arg)
 
456
FilesystemCursor::FilesystemCursor(drizzled::plugin::StorageEngine &engine_arg, TableShare &table_arg)
460
457
  : Cursor(engine_arg, table_arg),
461
458
    file_buff(new TransparentFile),
462
459
    thread_locked(false)
463
460
{
464
461
}
465
462
 
466
 
int FilesystemCursor::doOpen(const drizzled::identifier::Table &identifier, int, uint32_t)
 
463
int FilesystemCursor::doOpen(const drizzled::TableIdentifier &identifier, int, uint32_t)
467
464
{
468
465
  if (!(share= get_share(identifier.getPath().c_str())))
469
466
    return ENOENT;
490
487
 
491
488
int FilesystemCursor::doStartTableScan(bool)
492
489
{
493
 
  sql_command_type = getTable()->getSession()->getSqlCommand();
 
490
  sql_command_type = session_sql_command(table->getSession());
494
491
 
495
492
  if (thread_locked)
496
493
    critical_section_exit();
518
515
 
519
516
int FilesystemCursor::find_current_row(unsigned char *buf)
520
517
{
521
 
  ptrdiff_t row_offset= buf - getTable()->record[0];
 
518
  ptrdiff_t row_offset= buf - table->record[0];
522
519
 
523
520
  next_position= current_position;
524
521
 
525
522
  string content;
526
523
  bool line_done= false;
527
524
  bool line_blank= true;
528
 
  Field **field= getTable()->getFields();
 
525
  Field **field= table->getFields();
529
526
  for (; !line_done && *field; ++next_position)
530
527
  {
531
528
    char ch= file_buff->get_value(next_position);
564
561
        if ((*field)->isReadSet() || (*field)->isWriteSet())
565
562
        {
566
563
          (*field)->setWriteSet();
567
 
          (*field)->store_and_check(CHECK_FIELD_WARN,
568
 
                                    content.c_str(),
569
 
                                    (uint32_t)content.length(),
570
 
                                    &my_charset_bin);
 
564
          (*field)->store(content.c_str(),
 
565
                          (uint32_t)content.length(),
 
566
                          &my_charset_bin,
 
567
                          CHECK_FIELD_WARN);
571
568
        }
572
569
        else
573
 
        {
574
570
          (*field)->set_default();
575
 
        }
576
571
      }
577
572
      else
578
573
        (*field)->set_null();
621
616
    if (tag_depth >= share->vm.size())
622
617
      return HA_ERR_END_OF_FILE;
623
618
 
624
 
    ptrdiff_t row_offset= buf - getTable()->record[0];
625
 
    for (Field **field= getTable()->getFields(); *field; field++)
 
619
    ptrdiff_t row_offset= buf - table->record[0];
 
620
    for (Field **field= table->getFields(); *field; field++)
626
621
    {
627
622
      string key((*field)->field_name);
628
623
      string content= share->vm[tag_depth][key];
634
629
        if ((*field)->isReadSet() || (*field)->isWriteSet())
635
630
        {
636
631
          (*field)->setWriteSet();
637
 
          (*field)->store_and_check(CHECK_FIELD_WARN,
638
 
                                    content.c_str(),
639
 
                                    (uint32_t)content.length(),
640
 
                                    &my_charset_bin);
 
632
          (*field)->store(content.c_str(),
 
633
                          (uint32_t)content.length(),
 
634
                          &my_charset_bin,
 
635
                          CHECK_FIELD_WARN);
641
636
        }
642
637
        else
643
638
        {
701
696
 
702
697
int FilesystemCursor::doEndTableScan()
703
698
{
704
 
  sql_command_type = getTable->getSession()->getSqlCommand();
 
699
  sql_command_type = session_sql_command(table->getSession());
705
700
 
706
701
  if (share->format.isTagFormat())
707
702
  {
789
784
{
790
785
  bool first= true;
791
786
  drizzled::String attribute;
792
 
  for (Field **field= getTable()->getFields(); *field; ++field)
 
787
  for (Field **field= table->getFields(); *field; ++field)
793
788
  {
794
789
    if (first == true)
795
790
    {
822
817
  if (share->format.isTagFormat())
823
818
    return 0;
824
819
 
825
 
  sql_command_type = getTable()->getSession()->getSqlCommand();
 
820
  sql_command_type = session_sql_command(table->getSession());
826
821
 
827
822
  critical_section_enter();
828
823
 
893
888
  return 0;
894
889
}
895
890
 
896
 
int FilesystemEngine::doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to)
 
891
int FilesystemEngine::doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to)
897
892
{
898
893
  if (rename_file_ext(from.getPath().c_str(), to.getPath().c_str(), FILESYSTEM_EXT))
899
894
    return errno;
907
902
}
908
903
 
909
904
int FilesystemEngine::doCreateTable(Session &,
910
 
                                    Table&,
911
 
                                    const drizzled::identifier::Table &identifier,
912
 
                                    drizzled::message::Table &proto)
 
905
                        Table&,
 
906
                        const drizzled::TableIdentifier &identifier,
 
907
                        drizzled::message::Table &proto)
913
908
{
914
909
  FormatInfo format;
915
910
  format.parseFromTable(&proto);
956
951
  "Filesystem Engine",
957
952
  PLUGIN_LICENSE_GPL,
958
953
  filesystem_init_func, /* Plugin Init */
959
 
  NULL,                       /* depends */
 
954
  NULL,                       /* system variables                */
960
955
  NULL                        /* config options                  */
961
956
}
962
957
DRIZZLE_DECLARE_PLUGIN_END;