~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/ha_archive.h

Merge Monty.

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
 
#ifdef USE_PRAGMA_INTERFACE
17
 
#pragma interface                       /* gcc class implementation */
18
 
#endif
 
16
#ifndef PLUGIN_ARCHIVE_HA_ARCHIVE_H
 
17
#define PLUGIN_ARCHIVE_HA_ARCHIVE_H
19
18
 
 
19
#include <inttypes.h>
20
20
#include <zlib.h>
21
21
#include "azio.h"
 
22
#include <drizzled/thr_lock.h>
 
23
#include <drizzled/my_hash.h>
 
24
#include <drizzled/cursor.h>
 
25
#include <string>
22
26
 
23
27
/*
24
28
  Please read ha_archive.cc first. If you are looking for more general
27
31
*/
28
32
 
29
33
typedef struct st_archive_record_buffer {
30
 
  uchar *buffer;
 
34
  unsigned char *buffer;
31
35
  uint32_t length;
32
36
} archive_record_buffer;
33
37
 
34
38
 
35
 
typedef struct st_archive_share {
36
 
  char *table_name;
 
39
class ArchiveShare {
 
40
public:
 
41
  ArchiveShare();
 
42
  ArchiveShare(const char *name);
 
43
  ~ArchiveShare();
 
44
 
 
45
  bool prime(uint64_t *auto_increment);
 
46
 
 
47
  std::string table_name;
37
48
  char data_file_name[FN_REFLEN];
38
 
  uint table_name_length,use_count;
 
49
  uint32_t use_count;
39
50
  pthread_mutex_t mutex;
40
51
  THR_LOCK lock;
41
52
  azio_stream archive_write;     /* Archive file we are working with */
42
53
  bool archive_write_open;
43
54
  bool dirty;               /* Flag for if a flush should occur */
44
55
  bool crashed;             /* Meta file is crashed */
45
 
  ha_rows rows_recorded;    /* Number of rows in tables */
46
56
  uint64_t mean_rec_length;
47
57
  char real_path[FN_REFLEN];
48
58
  unsigned int  version;
 
59
  ha_rows rows_recorded;    /* Number of rows in tables */
49
60
  ha_rows version_rows;
50
 
} ARCHIVE_SHARE;
 
61
};
51
62
 
52
63
/*
53
64
  Version for file format.
57
68
*/
58
69
#define ARCHIVE_VERSION 3
59
70
 
60
 
class ha_archive: public handler
 
71
class ha_archive: public Cursor
61
72
{
62
73
  THR_LOCK_DATA lock;        /* MySQL lock */
63
 
  ARCHIVE_SHARE *share;      /* Shared lock info */
64
 
  
 
74
  ArchiveShare *share;      /* Shared lock info */
 
75
 
65
76
  azio_stream archive;            /* Archive file we are working with */
66
77
  my_off_t current_position;  /* The position of the row we just read */
67
 
  uchar byte_buffer[IO_SIZE]; /* Initial buffer for our string */
 
78
  unsigned char byte_buffer[IO_SIZE]; /* Initial buffer for our string */
68
79
  String buffer;             /* Buffer used for blob storage */
69
80
  ha_rows scan_rows;         /* Number of rows left in scan */
70
81
  bool delayed_insert;       /* If the insert is delayed */
71
82
  bool bulk_insert;          /* If we are performing a bulk insert */
72
 
  const uchar *current_key;
73
 
  uint current_key_len;
74
 
  uint current_k_offset;
 
83
  const unsigned char *current_key;
 
84
  uint32_t current_key_len;
 
85
  uint32_t current_k_offset;
75
86
  archive_record_buffer *record_buffer;
76
87
  bool archive_reader_open;
77
88
 
79
90
  void destroy_record_buffer(archive_record_buffer *r);
80
91
 
81
92
public:
82
 
  ha_archive(handlerton *hton, TABLE_SHARE *table_arg);
 
93
  ha_archive(drizzled::plugin::StorageEngine &engine_arg,
 
94
             TableShare &table_arg);
83
95
  ~ha_archive()
84
 
  {
85
 
  }
86
 
  const char *table_type() const { return "ARCHIVE"; }
87
 
  const char *index_type(uint inx __attribute__((unused)))
 
96
  { }
 
97
 
 
98
  const char *index_type(uint32_t)
88
99
  { return "NONE"; }
89
 
  const char **bas_ext() const;
90
 
  uint64_t table_flags() const
91
 
  {
92
 
    return (HA_NO_TRANSACTIONS | HA_REC_NOT_IN_SEQ | HA_CAN_BIT_FIELD |
93
 
            HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE |
94
 
            HA_STATS_RECORDS_IS_EXACT |
95
 
            HA_HAS_RECORDS |
96
 
            HA_FILE_BASED | HA_CAN_INSERT_DELAYED | HA_CAN_GEOMETRY);
97
 
  }
98
 
  uint32_t index_flags(uint idx __attribute__((unused)),
99
 
                       uint part __attribute__((unused)),
100
 
                       bool all_parts __attribute__((unused))) const
101
 
  {
102
 
    return HA_ONLY_WHOLE_INDEX;
103
 
  }
104
 
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
105
 
                                  uint64_t nb_desired_values,
106
 
                                  uint64_t *first_value,
107
 
                                  uint64_t *nb_reserved_values);
108
 
  uint max_supported_keys()          const { return 1; }
109
 
  uint max_supported_key_length()    const { return sizeof(uint64_t); }
110
 
  uint max_supported_key_part_length() const { return sizeof(uint64_t); }
 
100
  void get_auto_increment(uint64_t, uint64_t, uint64_t,
 
101
                          uint64_t *first_value, uint64_t *nb_reserved_values);
111
102
  ha_rows records() { return share->rows_recorded; }
112
 
  int index_init(uint keynr, bool sorted);
113
 
  virtual int index_read(uchar * buf, const uchar * key,
114
 
                         uint key_len, enum ha_rkey_function find_flag);
115
 
  virtual int index_read_idx(uchar * buf, uint index, const uchar * key,
116
 
                             uint key_len, enum ha_rkey_function find_flag);
117
 
  int index_next(uchar * buf);
118
 
  int open(const char *name, int mode, uint test_if_locked);
 
103
  int index_init(uint32_t keynr, bool sorted);
 
104
  virtual int index_read(unsigned char * buf, const unsigned char * key,
 
105
                         uint32_t key_len, enum ha_rkey_function find_flag);
 
106
  virtual int index_read_idx(unsigned char * buf, uint32_t index, const unsigned char * key,
 
107
                             uint32_t key_len, enum ha_rkey_function find_flag);
 
108
  int index_next(unsigned char * buf);
 
109
  int open(const char *name, int mode, uint32_t test_if_locked);
119
110
  int close(void);
120
 
  int write_row(uchar * buf);
121
 
  int real_write_row(uchar *buf, azio_stream *writer);
 
111
  int write_row(unsigned char * buf);
 
112
  int real_write_row(unsigned char *buf, azio_stream *writer);
122
113
  int delete_all_rows();
123
114
  int rnd_init(bool scan=1);
124
 
  int rnd_next(uchar *buf);
125
 
  int rnd_pos(uchar * buf, uchar *pos);
126
 
  int get_row(azio_stream *file_to_read, uchar *buf);
127
 
  int get_row_version2(azio_stream *file_to_read, uchar *buf);
128
 
  int get_row_version3(azio_stream *file_to_read, uchar *buf);
129
 
  ARCHIVE_SHARE *get_share(const char *table_name, int *rc);
 
115
  int rnd_next(unsigned char *buf);
 
116
  int rnd_pos(unsigned char * buf, unsigned char *pos);
 
117
  ArchiveShare *get_share(const char *table_name, int *rc);
130
118
  int free_share();
131
119
  int init_archive_writer();
132
120
  int init_archive_reader();
133
 
  bool auto_repair() const { return 1; } // For the moment we just do this
 
121
  void position(const unsigned char *record);
 
122
  int info(uint);
 
123
private:
 
124
  int get_row(azio_stream *file_to_read, unsigned char *buf);
 
125
  int get_row_version2(azio_stream *file_to_read, unsigned char *buf);
 
126
  int get_row_version3(azio_stream *file_to_read, unsigned char *buf);
134
127
  int read_data_header(azio_stream *file_to_read);
135
 
  void position(const uchar *record);
136
 
  int info(uint);
137
 
  void update_create_info(HA_CREATE_INFO *create_info);
138
 
  int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);
139
 
  int optimize(THD* thd, HA_CHECK_OPT* check_opt);
140
 
  int repair(THD* thd, HA_CHECK_OPT* check_opt);
 
128
  int optimize();
 
129
  int repair();
 
130
public:
141
131
  void start_bulk_insert(ha_rows rows);
142
132
  int end_bulk_insert();
143
 
  enum row_type get_row_type() const 
144
 
  { 
 
133
  enum row_type get_row_type() const
 
134
  {
145
135
    return ROW_TYPE_COMPRESSED;
146
136
  }
147
 
  THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
 
137
  THR_LOCK_DATA **store_lock(Session *session, THR_LOCK_DATA **to,
148
138
                             enum thr_lock_type lock_type);
149
 
  bool is_crashed() const;
150
 
  int check(THD* thd, HA_CHECK_OPT* check_opt);
151
 
  bool check_and_repair(THD *thd);
152
 
  uint32_t max_row_length(const uchar *buf);
 
139
  int check(Session* session);
 
140
  bool check_and_repair(Session *session);
 
141
  uint32_t max_row_length(const unsigned char *buf);
153
142
  bool fix_rec_buff(unsigned int length);
154
 
  int unpack_row(azio_stream *file_to_read, uchar *record);
155
 
  unsigned int pack_row(uchar *record);
 
143
  int unpack_row(azio_stream *file_to_read, unsigned char *record);
 
144
  unsigned int pack_row(unsigned char *record);
156
145
};
157
146
 
 
147
#endif /* PLUGIN_ARCHIVE_HA_ARCHIVE_H */