~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/csv/ha_tina.h

  • Committer: Brian Aker
  • Date: 2010-01-22 00:53:13 UTC
  • Revision ID: brian@gaz-20100122005313-jmizcbcdi1lt4tcx
Revert db patch.

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