1
by brian
clean slate |
1 |
/* Copyright (C) 2003 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
#ifdef USE_PRAGMA_INTERFACE
|
|
17 |
#pragma interface /* gcc class implementation */ |
|
18 |
#endif
|
|
19 |
||
20 |
#include <zlib.h> |
|
21 |
#include "azio.h" |
|
22 |
||
23 |
/*
|
|
24 |
Please read ha_archive.cc first. If you are looking for more general
|
|
25 |
answers on how storage engines work, look at ha_example.cc and
|
|
26 |
ha_example.h.
|
|
27 |
*/
|
|
28 |
||
29 |
typedef struct st_archive_record_buffer { |
|
30 |
uchar *buffer; |
|
31 |
uint32 length; |
|
32 |
} archive_record_buffer; |
|
33 |
||
34 |
||
35 |
typedef struct st_archive_share { |
|
36 |
char *table_name; |
|
37 |
char data_file_name[FN_REFLEN]; |
|
38 |
uint table_name_length,use_count; |
|
39 |
pthread_mutex_t mutex; |
|
40 |
THR_LOCK lock; |
|
41 |
azio_stream archive_write; /* Archive file we are working with */ |
|
42 |
bool archive_write_open; |
|
43 |
bool dirty; /* Flag for if a flush should occur */ |
|
44 |
bool crashed; /* Meta file is crashed */ |
|
45 |
ha_rows rows_recorded; /* Number of rows in tables */ |
|
46 |
uint64_t mean_rec_length; |
|
47 |
char real_path[FN_REFLEN]; |
|
48 |
unsigned int version; |
|
49 |
ha_rows version_rows; |
|
50 |
} ARCHIVE_SHARE; |
|
51 |
||
52 |
/*
|
|
53 |
Version for file format.
|
|
54 |
1 - Initial Version (Never Released)
|
|
55 |
2 - Stream Compression, seperate blobs, no packing
|
|
56 |
3 - One steam (row and blobs), with packing
|
|
57 |
*/
|
|
58 |
#define ARCHIVE_VERSION 3
|
|
59 |
||
60 |
class ha_archive: public handler |
|
61 |
{
|
|
62 |
THR_LOCK_DATA lock; /* MySQL lock */ |
|
63 |
ARCHIVE_SHARE *share; /* Shared lock info */ |
|
64 |
||
65 |
azio_stream archive; /* Archive file we are working with */ |
|
66 |
my_off_t current_position; /* The position of the row we just read */ |
|
67 |
uchar byte_buffer[IO_SIZE]; /* Initial buffer for our string */ |
|
68 |
String buffer; /* Buffer used for blob storage */ |
|
69 |
ha_rows scan_rows; /* Number of rows left in scan */ |
|
70 |
bool delayed_insert; /* If the insert is delayed */ |
|
71 |
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; |
|
75 |
archive_record_buffer *record_buffer; |
|
76 |
bool archive_reader_open; |
|
77 |
||
78 |
archive_record_buffer *create_record_buffer(unsigned int length); |
|
79 |
void destroy_record_buffer(archive_record_buffer *r); |
|
80 |
||
81 |
public: |
|
82 |
ha_archive(handlerton *hton, TABLE_SHARE *table_arg); |
|
83 |
~ha_archive() |
|
84 |
{
|
|
85 |
}
|
|
86 |
const char *table_type() const { return "ARCHIVE"; } |
|
87 |
const char *index_type(uint inx) { return "NONE"; } |
|
88 |
const char **bas_ext() const; |
|
89 |
uint64_t table_flags() const |
|
90 |
{
|
|
91 |
return (HA_NO_TRANSACTIONS | HA_REC_NOT_IN_SEQ | HA_CAN_BIT_FIELD | |
|
92 |
HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE | |
|
93 |
HA_STATS_RECORDS_IS_EXACT | |
|
94 |
HA_HAS_RECORDS | |
|
95 |
HA_FILE_BASED | HA_CAN_INSERT_DELAYED | HA_CAN_GEOMETRY); |
|
96 |
}
|
|
97 |
ulong index_flags(uint idx, uint part, bool all_parts) const |
|
98 |
{
|
|
99 |
return HA_ONLY_WHOLE_INDEX; |
|
100 |
}
|
|
101 |
virtual void get_auto_increment(uint64_t offset, uint64_t increment, |
|
102 |
uint64_t nb_desired_values, |
|
103 |
uint64_t *first_value, |
|
104 |
uint64_t *nb_reserved_values); |
|
105 |
uint max_supported_keys() const { return 1; } |
|
106 |
uint max_supported_key_length() const { return sizeof(uint64_t); } |
|
107 |
uint max_supported_key_part_length() const { return sizeof(uint64_t); } |
|
108 |
ha_rows records() { return share->rows_recorded; } |
|
109 |
int index_init(uint keynr, bool sorted); |
|
110 |
virtual int index_read(uchar * buf, const uchar * key, |
|
111 |
uint key_len, enum ha_rkey_function find_flag); |
|
112 |
virtual int index_read_idx(uchar * buf, uint index, const uchar * key, |
|
113 |
uint key_len, enum ha_rkey_function find_flag); |
|
114 |
int index_next(uchar * buf); |
|
115 |
int open(const char *name, int mode, uint test_if_locked); |
|
116 |
int close(void); |
|
117 |
int write_row(uchar * buf); |
|
118 |
int real_write_row(uchar *buf, azio_stream *writer); |
|
119 |
int delete_all_rows(); |
|
120 |
int rnd_init(bool scan=1); |
|
121 |
int rnd_next(uchar *buf); |
|
122 |
int rnd_pos(uchar * buf, uchar *pos); |
|
123 |
int get_row(azio_stream *file_to_read, uchar *buf); |
|
124 |
int get_row_version2(azio_stream *file_to_read, uchar *buf); |
|
125 |
int get_row_version3(azio_stream *file_to_read, uchar *buf); |
|
126 |
ARCHIVE_SHARE *get_share(const char *table_name, int *rc); |
|
127 |
int free_share(); |
|
128 |
int init_archive_writer(); |
|
129 |
int init_archive_reader(); |
|
130 |
bool auto_repair() const { return 1; } // For the moment we just do this |
|
131 |
int read_data_header(azio_stream *file_to_read); |
|
132 |
void position(const uchar *record); |
|
133 |
int info(uint); |
|
134 |
void update_create_info(HA_CREATE_INFO *create_info); |
|
135 |
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); |
|
136 |
int optimize(THD* thd, HA_CHECK_OPT* check_opt); |
|
137 |
int repair(THD* thd, HA_CHECK_OPT* check_opt); |
|
138 |
void start_bulk_insert(ha_rows rows); |
|
139 |
int end_bulk_insert(); |
|
140 |
enum row_type get_row_type() const |
|
141 |
{
|
|
142 |
return ROW_TYPE_COMPRESSED; |
|
143 |
}
|
|
144 |
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, |
|
145 |
enum thr_lock_type lock_type); |
|
146 |
bool is_crashed() const; |
|
147 |
int check(THD* thd, HA_CHECK_OPT* check_opt); |
|
148 |
bool check_and_repair(THD *thd); |
|
149 |
uint32 max_row_length(const uchar *buf); |
|
150 |
bool fix_rec_buff(unsigned int length); |
|
151 |
int unpack_row(azio_stream *file_to_read, uchar *record); |
|
152 |
unsigned int pack_row(uchar *record); |
|
153 |
};
|
|
154 |