~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/csv/ha_tina.h

Reverted 1103

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