~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/csv/ha_tina.h

  • Committer: Monty Taylor
  • Date: 2008-09-16 00:00:48 UTC
  • mto: This revision was merged to the branch mainline in revision 391.
  • Revision ID: monty@inaugust.com-20080916000048-3rvrv3gv9l0ad3gs
Fixed copyright headers in drizzled/

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
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>
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
21
15
 
22
16
#include <sys/types.h>
23
17
#include <sys/stat.h>
24
18
#include "transparent_file.h"
25
19
 
 
20
#define DEFAULT_CHAIN_LENGTH 512
26
21
/*
27
22
  Version for file format.
28
23
  1 - Initial Version. That is, the version when the metafile was introduced.
30
25
 
31
26
#define TINA_VERSION 1
32
27
 
33
 
class TinaShare
34
 
{
35
 
  TinaShare();
36
 
  TinaShare(const TinaShare &);
37
 
  TinaShare& operator=(const TinaShare &);
38
 
public:
39
 
  explicit TinaShare(const std::string &name);
40
 
  ~TinaShare();
41
 
 
42
 
  std::string table_name;
43
 
  std::string data_file_name;
44
 
  uint32_t use_count;
 
28
typedef struct st_tina_share {
 
29
  char *table_name;
 
30
  char data_file_name[FN_REFLEN];
 
31
  uint table_name_length, use_count;
45
32
  /*
46
33
    Here we save the length of the file for readers. This is updated by
47
34
    inserts, updates and deletes. The var is initialized along with the
49
36
  */
50
37
  off_t saved_data_file_length;
51
38
  pthread_mutex_t mutex;
 
39
  THR_LOCK lock;
52
40
  bool update_file_opened;
53
41
  bool tina_write_opened;
54
 
  int meta_file;           /* Meta file we use */
55
 
  int tina_write_filedes;  /* File Cursor for readers */
 
42
  File meta_file;           /* Meta file we use */
 
43
  File tina_write_filedes;  /* File handler for readers */
56
44
  bool crashed;             /* Meta file is crashed */
57
 
  drizzled::ha_rows rows_recorded;    /* Number of rows in tables */
58
 
  uint32_t data_file_version;   /* Version of the data file used */
 
45
  ha_rows rows_recorded;    /* Number of rows in tables */
 
46
  uint data_file_version;   /* Version of the data file used */
 
47
} TINA_SHARE;
 
48
 
 
49
struct tina_set {
 
50
  off_t begin;
 
51
  off_t end;
59
52
};
60
53
 
61
 
class ha_tina: public drizzled::Cursor
 
54
class ha_tina: public handler
62
55
{
63
 
  drizzled::THR_LOCK_DATA lock;      /* MySQL lock */
64
 
  TinaShare *share;       /* Shared lock info */
 
56
  THR_LOCK_DATA lock;      /* MySQL lock */
 
57
  TINA_SHARE *share;       /* Shared lock info */
65
58
  off_t current_position;  /* Current position in the file during a file scan */
66
59
  off_t next_position;     /* Next position in the file scan */
67
60
  off_t local_saved_data_file_length; /* save position for reads */
68
61
  off_t temp_file_length;
69
 
  unsigned char byte_buffer[IO_SIZE];
 
62
  uchar byte_buffer[IO_SIZE];
70
63
  Transparent_file *file_buff;
71
 
  int data_file;                   /* File Cursor for readers */
72
 
  int update_temp_file;
73
 
  drizzled::String buffer;
 
64
  File data_file;                   /* File handler for readers */
 
65
  File update_temp_file;
 
66
  String buffer;
74
67
  /*
75
68
    The chain contains "holes" in the file, occured because of
76
 
    deletes/updates. It is used in doEndTableScan() to get rid of them
 
69
    deletes/updates. It is used in rnd_end() to get rid of them
77
70
    in the end of the query.
78
71
  */
79
 
  std::vector< std::pair<off_t, off_t> > chain;
80
 
  uint32_t local_data_file_version;  /* Saved version of the data file used */
 
72
  tina_set chain_buffer[DEFAULT_CHAIN_LENGTH];
 
73
  tina_set *chain;
 
74
  tina_set *chain_ptr;
 
75
  uchar chain_alloced;
 
76
  uint32_t chain_size;
 
77
  uint local_data_file_version;  /* Saved version of the data file used */
81
78
  bool records_is_known;
82
 
  drizzled::memory::Root blobroot;
 
79
  MEM_ROOT blobroot;
83
80
 
84
 
  bool get_write_pos(off_t *end_pos,
85
 
                     std::vector< std::pair<off_t, off_t> >::iterator &closest_hole);
 
81
private:
 
82
  bool get_write_pos(off_t *end_pos, tina_set *closest_hole);
86
83
  int open_update_temp_file_if_needed();
87
84
  int init_tina_writer();
88
85
  int init_data_file();
89
86
 
90
87
public:
91
 
  ha_tina(drizzled::plugin::StorageEngine &engine, drizzled::Table &table_arg);
 
88
  ha_tina(handlerton *hton, TABLE_SHARE *table_arg);
92
89
  ~ha_tina()
93
90
  {
 
91
    if (chain_alloced)
 
92
      my_free(chain, 0);
94
93
    if (file_buff)
95
94
      delete file_buff;
96
95
  }
97
96
  const char *table_type(void) const { return "CSV"; }
98
 
  const char *index_type(uint32_t)
 
97
  const char *index_type(uint inx __attribute__((unused)))
99
98
  { return "NONE"; }
100
 
 
 
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; }
101
119
  /*
102
120
     Called in test_quick_select to determine if indexes should be used.
103
121
   */
104
122
  virtual double scan_time() { return (double) (stats.records+stats.deleted) / 20.0+10; }
105
 
 
106
123
  /* The next method will never be called */
107
124
  virtual bool fast_key_read() { return 1;}
108
 
  /*
109
 
    @TODO return actual upper bound of number of records in the table.
 
125
  /* 
 
126
    TODO: return actual upper bound of number of records in the table.
110
127
    (e.g. save number of records seen on full table scan and/or use file size
111
128
    as upper bound)
112
129
  */
113
 
  drizzled::ha_rows estimate_rows_upper_bound() { return HA_POS_ERROR; }
 
130
  ha_rows estimate_rows_upper_bound() { return HA_POS_ERROR; }
114
131
 
115
 
  int doOpen(const drizzled::identifier::Table &identifier, int mode, uint32_t test_if_locked);
116
 
  int open(const char *, int , uint32_t ) { assert(0); return -1; }
 
132
  int open(const char *name, int mode, uint open_options);
117
133
  int close(void);
118
 
  int doInsertRecord(unsigned char * buf);
119
 
  int doUpdateRecord(const unsigned char * old_data, unsigned char * new_data);
120
 
  int doDeleteRecord(const unsigned char * buf);
121
 
  int doStartTableScan(bool scan=1);
122
 
  int rnd_next(unsigned char *buf);
123
 
  int rnd_pos(unsigned char * buf, unsigned char *pos);
124
 
  int doEndTableScan();
125
 
  TinaShare *get_share(const std::string &table_name);
126
 
  int free_share();
127
 
  int repair(drizzled::Session* session, drizzled::HA_CHECK_OPT* check_opt);
 
134
  int write_row(uchar * buf);
 
135
  int update_row(const uchar * old_data, uchar * new_data);
 
136
  int delete_row(const uchar * buf);
 
137
  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;
 
143
  int rnd_end();
 
144
  int repair(THD* thd, HA_CHECK_OPT* check_opt);
128
145
  /* This is required for SQL layer to know that we support autorepair */
129
 
  void position(const unsigned char *record);
 
146
  bool auto_repair() const { return 1; }
 
147
  void position(const uchar *record);
130
148
  int info(uint);
131
149
  int delete_all_rows(void);
132
 
  void get_auto_increment(uint64_t, uint64_t,
133
 
                          uint64_t,
134
 
                          uint64_t *,
135
 
                          uint64_t *)
136
 
  {}
 
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
 
 
157
  /*
 
158
    These functions used to get/update status of the handler.
 
159
    Needed to enable concurrent inserts.
 
160
  */
 
161
  void get_status();
 
162
  void update_status();
137
163
 
138
164
  /* The following methods were added just for TINA */
139
 
  int encode_quote(unsigned char *buf);
140
 
  int find_current_row(unsigned char *buf);
 
165
  int encode_quote(uchar *buf);
 
166
  int find_current_row(uchar *buf);
141
167
  int chain_append();
142
168
};
143
169
 
144
 
#endif /* PLUGIN_CSV_HA_TINA_H */