~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/csv/ha_tina.h

  • Committer: Brian Aker
  • Date: 2008-07-28 18:01:38 UTC
  • Revision ID: brian@tangent.org-20080728180138-q2pxlq0qiapvqsdn
Remove YEAR field type

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#ifndef PLUGIN_CSV_HA_TINA_H
17
 
#define PLUGIN_CSV_HA_TINA_H
18
 
 
19
 
#include <drizzled/cursor.h>
20
 
#include <drizzled/thr_lock.h>
21
 
 
22
16
#include <sys/types.h>
23
17
#include <sys/stat.h>
 
18
#include <my_dir.h>
24
19
#include "transparent_file.h"
25
20
 
26
21
#define DEFAULT_CHAIN_LENGTH 512
31
26
 
32
27
#define TINA_VERSION 1
33
28
 
34
 
class TinaShare
35
 
{
36
 
  TinaShare();
37
 
  TinaShare(const TinaShare &);
38
 
  TinaShare& operator=(const TinaShare &);
39
 
public:
40
 
  explicit TinaShare(const char *name);
41
 
  ~TinaShare();
42
 
 
43
 
  std::string table_name;
 
29
typedef struct st_tina_share {
 
30
  char *table_name;
44
31
  char data_file_name[FN_REFLEN];
45
 
  uint32_t use_count;
 
32
  uint table_name_length, use_count;
 
33
  /*
 
34
    Below flag is needed to make log tables work with concurrent insert.
 
35
    For more details see comment to ha_tina::update_status.
 
36
  */
 
37
  my_bool is_log_table;
46
38
  /*
47
39
    Here we save the length of the file for readers. This is updated by
48
40
    inserts, updates and deletes. The var is initialized along with the
53
45
  THR_LOCK lock;
54
46
  bool update_file_opened;
55
47
  bool tina_write_opened;
56
 
  int meta_file;           /* Meta file we use */
57
 
  int tina_write_filedes;  /* File Cursor for readers */
 
48
  File meta_file;           /* Meta file we use */
 
49
  File tina_write_filedes;  /* File handler for readers */
58
50
  bool crashed;             /* Meta file is crashed */
59
51
  ha_rows rows_recorded;    /* Number of rows in tables */
60
 
  uint32_t data_file_version;   /* Version of the data file used */
61
 
};
 
52
  uint data_file_version;   /* Version of the data file used */
 
53
} TINA_SHARE;
62
54
 
63
55
struct tina_set {
64
56
  off_t begin;
65
57
  off_t end;
66
58
};
67
59
 
68
 
class ha_tina: public Cursor
 
60
class ha_tina: public handler
69
61
{
70
62
  THR_LOCK_DATA lock;      /* MySQL lock */
71
 
  TinaShare *share;       /* Shared lock info */
 
63
  TINA_SHARE *share;       /* Shared lock info */
72
64
  off_t current_position;  /* Current position in the file during a file scan */
73
65
  off_t next_position;     /* Next position in the file scan */
74
66
  off_t local_saved_data_file_length; /* save position for reads */
75
67
  off_t temp_file_length;
76
 
  unsigned char byte_buffer[IO_SIZE];
 
68
  uchar byte_buffer[IO_SIZE];
77
69
  Transparent_file *file_buff;
78
 
  int data_file;                   /* File Cursor for readers */
79
 
  int update_temp_file;
 
70
  File data_file;                   /* File handler for readers */
 
71
  File update_temp_file;
80
72
  String buffer;
81
73
  /*
82
74
    The chain contains "holes" in the file, occured because of
86
78
  tina_set chain_buffer[DEFAULT_CHAIN_LENGTH];
87
79
  tina_set *chain;
88
80
  tina_set *chain_ptr;
89
 
  unsigned char chain_alloced;
 
81
  uchar chain_alloced;
90
82
  uint32_t chain_size;
91
 
  uint32_t local_data_file_version;  /* Saved version of the data file used */
 
83
  uint local_data_file_version;  /* Saved version of the data file used */
92
84
  bool records_is_known;
93
 
  drizzled::memory::Root blobroot;
 
85
  MEM_ROOT blobroot;
94
86
 
 
87
private:
95
88
  bool get_write_pos(off_t *end_pos, tina_set *closest_hole);
96
89
  int open_update_temp_file_if_needed();
97
90
  int init_tina_writer();
98
91
  int init_data_file();
99
92
 
100
93
public:
101
 
  ha_tina(drizzled::plugin::StorageEngine &engine, TableShare &table_arg);
 
94
  ha_tina(handlerton *hton, TABLE_SHARE *table_arg);
102
95
  ~ha_tina()
103
96
  {
104
97
    if (chain_alloced)
105
 
      free(chain);
 
98
      my_free(chain, 0);
106
99
    if (file_buff)
107
100
      delete file_buff;
108
101
  }
109
102
  const char *table_type(void) const { return "CSV"; }
110
 
  const char *index_type(uint32_t)
 
103
  const char *index_type(uint inx __attribute__((unused)))
111
104
  { return "NONE"; }
112
 
 
 
105
  const char **bas_ext() const;
 
106
  uint64_t table_flags() const
 
107
  {
 
108
    return (HA_NO_TRANSACTIONS | HA_REC_NOT_IN_SEQ | HA_NO_AUTO_INCREMENT |
 
109
            HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE);
 
110
  }
 
111
  uint32_t index_flags(uint idx __attribute__((unused)),
 
112
                       uint part __attribute__((unused)),
 
113
                       bool all_parts __attribute__((unused))) const
 
114
  {
 
115
    /*
 
116
      We will never have indexes so this will never be called(AKA we return
 
117
      zero)
 
118
    */
 
119
    return 0;
 
120
  }
 
121
  uint max_record_length() const { return HA_MAX_REC_LENGTH; }
 
122
  uint max_keys()          const { return 0; }
 
123
  uint max_key_parts()     const { return 0; }
 
124
  uint max_key_length()    const { return 0; }
113
125
  /*
114
126
     Called in test_quick_select to determine if indexes should be used.
115
127
   */
116
128
  virtual double scan_time() { return (double) (stats.records+stats.deleted) / 20.0+10; }
117
 
 
118
129
  /* The next method will never be called */
119
130
  virtual bool fast_key_read() { return 1;}
120
 
  /*
 
131
  /* 
121
132
    TODO: return actual upper bound of number of records in the table.
122
133
    (e.g. save number of records seen on full table scan and/or use file size
123
134
    as upper bound)
124
135
  */
125
136
  ha_rows estimate_rows_upper_bound() { return HA_POS_ERROR; }
126
137
 
127
 
  int open(const char *name, int mode, uint32_t open_options);
 
138
  int open(const char *name, int mode, uint open_options);
128
139
  int close(void);
129
 
  int write_row(unsigned char * buf);
130
 
  int update_row(const unsigned char * old_data, unsigned char * new_data);
131
 
  int delete_row(const unsigned char * buf);
 
140
  int write_row(uchar * buf);
 
141
  int update_row(const uchar * old_data, uchar * new_data);
 
142
  int delete_row(const uchar * buf);
132
143
  int rnd_init(bool scan=1);
133
 
  int rnd_next(unsigned char *buf);
134
 
  int rnd_pos(unsigned char * buf, unsigned char *pos);
 
144
  int rnd_next(uchar *buf);
 
145
  int rnd_pos(uchar * buf, uchar *pos);
 
146
  bool check_and_repair(THD *thd);
 
147
  int check(THD* thd, HA_CHECK_OPT* check_opt);
 
148
  bool is_crashed() const;
135
149
  int rnd_end();
136
 
  TinaShare *get_share(const char *table_name);
137
 
  int free_share();
138
 
  int repair(Session* session, HA_CHECK_OPT* check_opt);
 
150
  int repair(THD* thd, HA_CHECK_OPT* check_opt);
139
151
  /* This is required for SQL layer to know that we support autorepair */
140
 
  void position(const unsigned char *record);
 
152
  bool auto_repair() const { return 1; }
 
153
  void position(const uchar *record);
141
154
  int info(uint);
142
155
  int delete_all_rows(void);
 
156
  int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);
 
157
  bool check_if_incompatible_data(HA_CREATE_INFO *info,
 
158
                                  uint table_changes);
 
159
 
 
160
  THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
 
161
      enum thr_lock_type lock_type);
143
162
 
144
163
  /*
145
 
    These functions used to get/update status of the Cursor.
 
164
    These functions used to get/update status of the handler.
146
165
    Needed to enable concurrent inserts.
147
166
  */
148
167
  void get_status();
149
168
  void update_status();
150
169
 
151
170
  /* The following methods were added just for TINA */
152
 
  int encode_quote(unsigned char *buf);
153
 
  int find_current_row(unsigned char *buf);
 
171
  int encode_quote(uchar *buf);
 
172
  int find_current_row(uchar *buf);
154
173
  int chain_append();
155
174
};
156
175
 
157
 
#endif /* PLUGIN_CSV_HA_TINA_H */