~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/ha_archive.cc

  • Committer: lbieber
  • Date: 2010-09-16 19:28:14 UTC
  • mfrom: (1768.2.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 1770.
  • Revision ID: lbieber@orisndriz08-20100916192814-t17x4rtyllidoxh8
Merge Brian - IO cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
129
129
}
130
130
 
131
131
 
132
 
void ArchiveEngine::doGetTableNames(drizzled::CachedDirectory &directory, 
133
 
                                    const SchemaIdentifier&,
134
 
                                    set<string>& set_of_names)
135
 
{
136
 
  drizzled::CachedDirectory::Entries entries= directory.getEntries();
137
 
 
138
 
  for (drizzled::CachedDirectory::Entries::iterator entry_iter= entries.begin(); 
139
 
       entry_iter != entries.end(); ++entry_iter)
140
 
  {
141
 
    drizzled::CachedDirectory::Entry *entry= *entry_iter;
142
 
    const string *filename= &entry->filename;
143
 
 
144
 
    assert(filename->size());
145
 
 
146
 
    const char *ext= strchr(filename->c_str(), '.');
147
 
 
148
 
    if (ext == NULL || my_strcasecmp(system_charset_info, ext, ARZ) ||
149
 
        (filename->compare(0, strlen(TMP_FILE_PREFIX), TMP_FILE_PREFIX) == 0))
150
 
    {  }
151
 
    else
152
 
    {
153
 
      char uname[NAME_LEN + 1];
154
 
      uint32_t file_name_len;
155
 
 
156
 
      file_name_len= TableIdentifier::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
157
 
      // TODO: Remove need for memory copy here
158
 
      uname[file_name_len - sizeof(ARZ) + 1]= '\0'; // Subtract ending, place NULL 
159
 
      set_of_names.insert(uname);
160
 
    }
161
 
  }
162
 
}
163
 
 
164
 
 
165
132
int ArchiveEngine::doDropTable(Session&, const TableIdentifier &identifier)
166
133
{
167
134
  string new_path(identifier.getPath());
267
234
{
268
235
  memset(&archive_write, 0, sizeof(azio_stream));     /* Archive file we are working with */
269
236
  table_name.append(name);
270
 
  internal::fn_format(data_file_name, table_name.c_str(), "",
271
 
            ARZ, MY_REPLACE_EXT | MY_UNPACK_FILENAME);
 
237
  data_file_name.assign(table_name);
 
238
  data_file_name.append(ARZ);
272
239
  /*
273
240
    We will use this lock for rows.
274
241
  */
300
267
    anything but reading... open it for write and we will generate null
301
268
    compression writes).
302
269
  */
303
 
  if (!(azopen(&archive_tmp, data_file_name, O_RDONLY,
 
270
  if (!(azopen(&archive_tmp, data_file_name.c_str(), O_RDONLY,
304
271
               AZ_METHOD_BLOCK)))
305
272
    return false;
306
273
 
392
359
    a gzip file that can be both read and written we keep a writer open
393
360
    that is shared amoung all open tables.
394
361
  */
395
 
  if (!(azopen(&(share->archive_write), share->data_file_name,
 
362
  if (!(azopen(&(share->archive_write), share->data_file_name.c_str(),
396
363
               O_RDWR, AZ_METHOD_BLOCK)))
397
364
  {
398
365
    share->crashed= true;
429
396
    default:
430
397
      method= AZ_METHOD_BLOCK;
431
398
    }
432
 
    if (!(azopen(&archive, share->data_file_name, O_RDONLY,
 
399
    if (!(azopen(&archive, share->data_file_name.c_str(), O_RDONLY,
433
400
                 method)))
434
401
    {
435
402
      share->crashed= true;
536
503
                                 const drizzled::TableIdentifier &identifier,
537
504
                                 drizzled::message::Table& proto)
538
505
{
539
 
  char name_buff[FN_REFLEN];
540
506
  int error= 0;
541
507
  azio_stream create_stream;            /* Archive file we are working with */
542
508
  uint64_t auto_increment_value;
556
522
 
557
523
      if (!(field->flags & AUTO_INCREMENT_FLAG))
558
524
      {
559
 
        error= -1;
560
 
        goto error;
 
525
        return -1;
561
526
      }
562
527
    }
563
528
  }
564
529
 
565
 
  /*
566
 
    We reuse name_buff since it is available.
567
 
  */
568
 
  internal::fn_format(name_buff, identifier.getPath().c_str(), "", ARZ,
569
 
                      MY_REPLACE_EXT | MY_UNPACK_FILENAME);
 
530
  std::string named_file= identifier.getPath();
 
531
  named_file.append(ARZ);
570
532
 
571
533
  errno= 0;
572
 
  if (azopen(&create_stream, name_buff, O_CREAT|O_RDWR,
 
534
  if (azopen(&create_stream, named_file.c_str(), O_CREAT|O_RDWR,
573
535
             AZ_METHOD_BLOCK) == 0)
574
536
  {
575
537
    error= errno;
576
 
    goto error2;
 
538
    unlink(named_file.c_str());
 
539
 
 
540
    return(error ? error : -1);
577
541
  }
578
542
 
579
543
  try {
581
545
  }
582
546
  catch (...)
583
547
  {
584
 
    goto error2;
 
548
    unlink(named_file.c_str());
 
549
 
 
550
    return(error ? error : -1);
585
551
  }
586
552
 
587
553
  if (azwrite_frm(&create_stream, serialized_proto.c_str(),
588
554
                  serialized_proto.length()))
589
555
  {
590
 
    goto error2;
 
556
    unlink(named_file.c_str());
 
557
 
 
558
    return(error ? error : -1);
591
559
  }
592
560
 
593
561
  if (proto.options().has_comment())
601
569
    if (write_length < 0)
602
570
    {
603
571
      error= errno;
604
 
      goto error2;
 
572
      unlink(named_file.c_str());
 
573
 
 
574
      return(error ? error : -1);
605
575
    }
606
576
  }
607
577
 
615
585
  if (azclose(&create_stream))
616
586
  {
617
587
    error= errno;
618
 
    goto error2;
 
588
    unlink(named_file.c_str());
 
589
 
 
590
    return(error ? error : -1);
619
591
  }
620
592
 
621
593
  return(0);
622
 
 
623
 
error2:
624
 
  unlink(name_buff);
625
 
 
626
 
error:
627
 
  /* Return error number, if we got one */
628
 
  return(error ? error : -1);
629
594
}
630
595
 
631
596
/*
988
953
{
989
954
  int rc= 0;
990
955
  azio_stream writer;
991
 
  char writer_filename[FN_REFLEN];
992
956
 
993
957
  init_archive_reader();
994
958
 
1008
972
  azread_frm(&archive, proto_string);
1009
973
 
1010
974
  /* Lets create a file to contain the new data */
1011
 
  internal::fn_format(writer_filename, share->table_name.c_str(), "", ARN,
1012
 
            MY_REPLACE_EXT | MY_UNPACK_FILENAME);
 
975
  std::string writer_filename= share->table_name;
 
976
  writer_filename.append(ARN);
1013
977
 
1014
 
  if (!(azopen(&writer, writer_filename, O_CREAT|O_RDWR, AZ_METHOD_BLOCK)))
 
978
  if (!(azopen(&writer, writer_filename.c_str(), O_CREAT|O_RDWR, AZ_METHOD_BLOCK)))
1015
979
  {
1016
980
    free(proto_string);
1017
981
    return(HA_ERR_CRASHED_ON_USAGE);
1090
1054
  azclose(&archive);
1091
1055
 
1092
1056
  // make the file we just wrote be our data file
1093
 
  rc = internal::my_rename(writer_filename,share->data_file_name,MYF(0));
 
1057
  rc = internal::my_rename(writer_filename.c_str(), share->data_file_name.c_str(), MYF(0));
1094
1058
 
1095
1059
  free(proto_string);
1096
1060
  return(rc);
1181
1145
  {
1182
1146
    struct stat file_stat;  // Stat information for the data file
1183
1147
 
1184
 
    stat(share->data_file_name, &file_stat);
 
1148
    stat(share->data_file_name.c_str(), &file_stat);
1185
1149
 
1186
1150
    stats.mean_rec_length= table->getRecordLength()+ buffer.alloced_length();
1187
1151
    stats.data_file_length= file_stat.st_size;
1347
1311
    }
1348
1312
  }
1349
1313
}
1350