~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/csv/ha_tina.cc

Moved my_getopt.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
 -Brian
42
42
*/
43
 
#include <drizzled/common_includes.h>
 
43
 
 
44
#ifdef USE_PRAGMA_IMPLEMENTATION
 
45
#pragma implementation        // gcc: Class implementation
 
46
#endif
 
47
 
 
48
#include "mysql_priv.h"
44
49
#include "ha_tina.h"
45
50
 
46
51
 
58
63
#define CSM_EXT ".CSM"               // Meta file
59
64
 
60
65
 
61
 
static TINA_SHARE *get_share(const char *table_name, Table *table);
 
66
static TINA_SHARE *get_share(const char *table_name, TABLE *table);
62
67
static int free_share(TINA_SHARE *share);
63
68
static int read_meta_file(File meta_file, ha_rows *rows);
64
69
static int write_meta_file(File meta_file, ha_rows rows, bool dirty);
127
132
  Simple lock controls.
128
133
*/
129
134
static TINA_SHARE *get_share(const char *table_name,
130
 
                             Table *table __attribute__((unused)))
 
135
                             TABLE *table __attribute__((unused)))
131
136
{
132
137
  TINA_SHARE *share;
133
138
  char meta_file_name[FN_REFLEN];
156
161
    }
157
162
 
158
163
    share->use_count= 0;
 
164
    share->is_log_table= false;
159
165
    share->table_name_length= length;
160
166
    share->table_name= tmp_name;
161
167
    share->crashed= false;
163
169
    share->update_file_opened= false;
164
170
    share->tina_write_opened= false;
165
171
    share->data_file_version= 0;
166
 
    stpcpy(share->table_name, table_name);
 
172
    strmov(share->table_name, table_name);
167
173
    fn_format(share->data_file_name, table_name, "", CSV_EXT,
168
174
              MY_REPLACE_EXT|MY_UNPACK_FILENAME);
169
175
    fn_format(meta_file_name, table_name, "", CSM_EXT,
449
455
  String attribute(attribute_buffer, sizeof(attribute_buffer),
450
456
                   &my_charset_bin);
451
457
 
 
458
  my_bitmap_map *org_bitmap= dbug_tmp_use_all_columns(table, table->read_set);
452
459
  buffer.length(0);
453
460
 
454
461
  for (Field **field=table->field ; *field ; field++)
523
530
 
524
531
  //buffer.replace(buffer.length(), 0, "\n", 1);
525
532
 
 
533
  dbug_tmp_restore_column_map(table->read_set, org_bitmap);
526
534
  return (buffer.length());
527
535
}
528
536
 
575
583
{
576
584
  off_t end_offset, curr_offset= current_position;
577
585
  int eoln_len;
 
586
  my_bitmap_map *org_bitmap;
578
587
  int error;
579
588
  bool read_all;
580
589
 
591
600
 
592
601
  /* We must read all columns in case a table is opened for update */
593
602
  read_all= !bitmap_is_clear_all(table->write_set);
 
603
  /* Avoid asserts in ::store() for columns that are not going to be updated */
 
604
  org_bitmap= dbug_tmp_use_all_columns(table, table->write_set);
594
605
  error= HA_ERR_CRASHED_ON_USAGE;
595
606
 
596
607
  memset(buf, 0, table->s->null_bytes);
673
684
        
674
685
        packlength= blob->pack_length_no_ptr();
675
686
        length= blob->get_length(blob->ptr);
676
 
        memcpy(&src, blob->ptr + packlength, sizeof(char*));
 
687
        memcpy_fixed(&src, blob->ptr + packlength, sizeof(char*));
677
688
        if (src)
678
689
        {
679
690
          tgt= (uchar*) alloc_root(&blobroot, length);
680
 
          memcpy(tgt, src, length);
681
 
          memcpy(blob->ptr + packlength, &tgt, sizeof(char*));
 
691
          bmove(tgt, src, length);
 
692
          memcpy_fixed(blob->ptr + packlength, &tgt, sizeof(char*));
682
693
        }
683
694
      }
684
695
    }
687
698
  error= 0;
688
699
 
689
700
err:
 
701
  dbug_tmp_restore_column_map(table->write_set, org_bitmap);
690
702
 
691
703
  return(error);
692
704
}
744
756
 
745
757
void ha_tina::get_status()
746
758
{
 
759
  if (share->is_log_table)
 
760
  {
 
761
    /*
 
762
      We have to use mutex to follow pthreads memory visibility
 
763
      rules for share->saved_data_file_length
 
764
    */
 
765
    pthread_mutex_lock(&share->mutex);
 
766
    local_saved_data_file_length= share->saved_data_file_length;
 
767
    pthread_mutex_unlock(&share->mutex);
 
768
    return;
 
769
  }
747
770
  local_saved_data_file_length= share->saved_data_file_length;
748
771
}
749
772
 
765
788
    For log tables concurrent insert works different. The reason is that
766
789
    log tables are always opened and locked. And as they do not unlock
767
790
    tables, the file length after writes should be updated in a different
768
 
    way. 
 
791
    way. For this purpose we need is_log_table flag. When this flag is set
 
792
    we call update_status() explicitly after each row write.
769
793
*/
770
794
 
771
795
void ha_tina::update_status()
858
882
  pthread_mutex_lock(&share->mutex);
859
883
  share->rows_recorded++;
860
884
  /* update status for the log tables */
 
885
  if (share->is_log_table)
 
886
    update_status();
861
887
  pthread_mutex_unlock(&share->mutex);
862
888
 
863
889
  stats.records++;
923
949
  temp_file_length+= size;
924
950
  rc= 0;
925
951
 
 
952
  /* UPDATE should never happen on the log tables */
 
953
  assert(!share->is_log_table);
 
954
 
926
955
err:
927
956
  return(rc);
928
957
}
951
980
  share->rows_recorded--;
952
981
  pthread_mutex_unlock(&share->mutex);
953
982
 
 
983
  /* DELETE should never happen on the log table */
 
984
  assert(!share->is_log_table);
 
985
 
954
986
  return(0);
955
987
}
956
988
 
1431
1463
  this (the database will call ::open() if it needs to).
1432
1464
*/
1433
1465
 
1434
 
int ha_tina::create(const char *name, Table *table_arg,
 
1466
int ha_tina::create(const char *name, TABLE *table_arg,
1435
1467
                    HA_CREATE_INFO *create_info __attribute__((unused)))
1436
1468
{
1437
1469
  char name_buff[FN_REFLEN];
1526
1558
 
1527
1559
mysql_declare_plugin(csv)
1528
1560
{
1529
 
  DRIZZLE_STORAGE_ENGINE_PLUGIN,
 
1561
  MYSQL_STORAGE_ENGINE_PLUGIN,
1530
1562
  "CSV",
1531
1563
  "1.0",
1532
1564
  "Brian Aker, MySQL AB",