~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/filesystem/filesystem.cc

  • Committer: Zimin
  • Date: 2010-07-15 13:10:23 UTC
  • mto: (1675.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1677.
  • Revision ID: ziminq@gmail.com-20100715131023-qf6llrp5v92gbn9m
remove table lock, add FilesystemLock to this storage engine

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
  FilesystemEngine(const string& name_arg)
62
62
   : drizzled::plugin::StorageEngine(name_arg,
63
63
                                     HTON_NULL_IN_KEY |
 
64
                                     HTON_SKIP_STORE_LOCK |
64
65
                                     HTON_CAN_INDEX_BLOBS |
65
66
                                     HTON_AUTO_PART_KEY),
66
67
     fs_open_tables()
360
361
  update_file_opened(false),
361
362
  needs_reopen(false)
362
363
{
363
 
  thr_lock_init(&lock);
364
364
}
365
365
 
366
366
FilesystemTableShare::~FilesystemTableShare()
367
367
{
368
 
  thr_lock_delete(&lock);
369
368
  pthread_mutex_destroy(&mutex);
370
369
}
371
370
 
428
427
  pthread_mutex_unlock(&filesystem_mutex);
429
428
}
430
429
 
 
430
void FilesystemCursor::critical_section_enter()
 
431
{
 
432
  if (sql_command_type == SQLCOM_ALTER_TABLE ||
 
433
      sql_command_type == SQLCOM_UPDATE ||
 
434
      sql_command_type == SQLCOM_DELETE ||
 
435
      sql_command_type == SQLCOM_INSERT ||
 
436
      sql_command_type == SQLCOM_INSERT_SELECT ||
 
437
      sql_command_type == SQLCOM_REPLACE ||
 
438
      sql_command_type == SQLCOM_REPLACE_SELECT)
 
439
    share->filesystem_lock.scan_update_begin();
 
440
  else
 
441
    share->filesystem_lock.scan_begin();
 
442
 
 
443
  thread_locked = true;
 
444
}
 
445
 
 
446
void FilesystemCursor::critical_section_exit()
 
447
{
 
448
  if (sql_command_type == SQLCOM_ALTER_TABLE ||
 
449
      sql_command_type == SQLCOM_UPDATE ||
 
450
      sql_command_type == SQLCOM_DELETE ||
 
451
      sql_command_type == SQLCOM_INSERT ||
 
452
      sql_command_type == SQLCOM_INSERT_SELECT ||
 
453
      sql_command_type == SQLCOM_REPLACE ||
 
454
      sql_command_type == SQLCOM_REPLACE_SELECT)
 
455
    share->filesystem_lock.scan_update_end();
 
456
  else
 
457
    share->filesystem_lock.scan_end();
 
458
 
 
459
  thread_locked = false;
 
460
}
 
461
 
431
462
FilesystemCursor::FilesystemCursor(drizzled::plugin::StorageEngine &engine_arg, TableShare &table_arg)
432
 
  : Cursor(engine_arg, table_arg)
 
463
  : Cursor(engine_arg, table_arg),
 
464
    thread_locked(false)
433
465
{
434
466
  file_buff= new TransparentFile();
435
467
}
447
479
  }
448
480
 
449
481
  ref_length= sizeof(off_t);
450
 
  thr_lock_data_init(&share->lock, &lock, NULL);
451
482
  return 0;
452
483
}
453
484
 
462
493
 
463
494
int FilesystemCursor::doStartTableScan(bool)
464
495
{
 
496
  sql_command_type = session_sql_command(table->getSession());
 
497
 
 
498
  if (thread_locked)
 
499
    critical_section_exit();
 
500
  critical_section_enter();
 
501
 
465
502
  if (share->format.isTagFormat())
466
503
  {
467
504
    tag_depth= 0;
653
690
 
654
691
int FilesystemCursor::doEndTableScan()
655
692
{
 
693
  sql_command_type = session_sql_command(table->getSession());
 
694
 
656
695
  if (share->format.isTagFormat())
 
696
  {
 
697
    if (thread_locked)
 
698
      critical_section_exit();
657
699
    return 0;
 
700
  }
658
701
 
659
702
  if (slots.size() == 0)
 
703
  {
 
704
    if (thread_locked)
 
705
      critical_section_exit();
660
706
    return 0;
 
707
  }
661
708
 
662
709
  int err= -1;
663
710
  sort(slots.begin(), slots.end());
724
771
error:
725
772
  err= errno;
726
773
  pthread_mutex_unlock(&share->mutex);
 
774
 
 
775
  if (thread_locked)
 
776
    critical_section_exit();
727
777
  return err;
728
778
}
729
779
 
764
814
  if (share->format.isTagFormat())
765
815
    return 0;
766
816
 
 
817
  sql_command_type = session_sql_command(table->getSession());
 
818
 
 
819
  critical_section_enter();
 
820
 
767
821
  int err_write= 0;
768
822
  int err_close= 0;
769
823
 
770
824
  string output_line;
771
825
  recordToString(output_line);
772
826
 
773
 
  pthread_mutex_lock(&share->mutex);
774
827
  int fd= ::open(share->format.getFileName().c_str(), O_WRONLY | O_APPEND);
775
828
  if (fd < 0)
776
829
  {
777
 
    pthread_mutex_unlock(&share->mutex);
 
830
    critical_section_exit();
778
831
    return ENOENT;
779
832
  }
780
833
 
788
841
  if (err_close < 0)
789
842
    err_close= errno;
790
843
 
791
 
  pthread_mutex_unlock(&share->mutex);
 
844
  critical_section_exit();
792
845
 
793
846
  if (err_write)
794
847
    return err_write;
845
898
  return FormatInfo::validateOption(key, state);
846
899
}
847
900
 
848
 
THR_LOCK_DATA **FilesystemCursor::store_lock(Session *,
849
 
                                             THR_LOCK_DATA **to,
850
 
                                             thr_lock_type lock_type)
851
 
{
852
 
  if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)
853
 
    lock.type= lock_type;
854
 
  *to++= &lock;
855
 
  return to;
856
 
}
857
 
 
858
901
int FilesystemEngine::doCreateTable(Session &,
859
902
                        Table&,
860
903
                        const drizzled::TableIdentifier &identifier,