~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/ha_archive.h

Merge of Jay

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