MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ha_archive.h
1 /* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #include <zlib.h>
17 #include "azlib.h"
18 
19 /*
20  Please read ha_archive.cc first. If you are looking for more general
21  answers on how storage engines work, look at ha_example.cc and
22  ha_example.h.
23 */
24 
25 typedef struct st_archive_record_buffer {
26  uchar *buffer;
27  uint32 length;
29 
30 
32 {
33 public:
34  mysql_mutex_t mutex;
35  THR_LOCK lock;
36  azio_stream archive_write; /* Archive file we are working with */
37  ha_rows rows_recorded; /* Number of rows in tables */
38  char table_name[FN_REFLEN];
39  char data_file_name[FN_REFLEN];
40  bool in_optimize;
41  bool archive_write_open;
42  bool dirty; /* Flag for if a flush should occur */
43  bool crashed; /* Meta file is crashed */
44  Archive_share();
45  ~Archive_share()
46  {
47  DBUG_PRINT("ha_archive", ("~Archive_share: %p",
48  this));
49  if (archive_write_open)
50  {
51  mysql_mutex_lock(&mutex);
52  (void) close_archive_writer();
53  mysql_mutex_unlock(&mutex);
54  }
55  thr_lock_delete(&lock);
56  mysql_mutex_destroy(&mutex);
57  }
58  int init_archive_writer();
59  void close_archive_writer();
60  int write_v1_metafile();
61  int read_v1_metafile();
62 };
63 
64 /*
65  Version for file format.
66  1 - Initial Version (Never Released)
67  2 - Stream Compression, seperate blobs, no packing
68  3 - One steam (row and blobs), with packing
69 */
70 #define ARCHIVE_VERSION 3
71 
72 class ha_archive: public handler
73 {
74  THR_LOCK_DATA lock; /* MySQL lock */
75  Archive_share *share; /* Shared lock info */
76 
77  azio_stream archive; /* Archive file we are working with */
78  my_off_t current_position; /* The position of the row we just read */
79  uchar byte_buffer[IO_SIZE]; /* Initial buffer for our string */
80  String buffer; /* Buffer used for blob storage */
81  ha_rows scan_rows; /* Number of rows left in scan */
82  bool delayed_insert; /* If the insert is delayed */
83  bool bulk_insert; /* If we are performing a bulk insert */
84  const uchar *current_key;
85  uint current_key_len;
86  uint current_k_offset;
87  archive_record_buffer *record_buffer;
88  bool archive_reader_open;
89 
90  archive_record_buffer *create_record_buffer(unsigned int length);
91  void destroy_record_buffer(archive_record_buffer *r);
92  int frm_copy(azio_stream *src, azio_stream *dst);
93  void frm_load(const char *name, azio_stream *dst);
94  unsigned int pack_row_v1(uchar *record);
95 
96 public:
97  ha_archive(handlerton *hton, TABLE_SHARE *table_arg);
98  ~ha_archive()
99  {
100  }
101  const char *table_type() const { return "ARCHIVE"; }
102  const char *index_type(uint inx) { return "NONE"; }
103  const char **bas_ext() const;
104  ulonglong table_flags() const
105  {
106  return (HA_NO_TRANSACTIONS | HA_REC_NOT_IN_SEQ | HA_CAN_BIT_FIELD |
107  HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE |
108  HA_STATS_RECORDS_IS_EXACT |
109  HA_HAS_RECORDS | HA_CAN_REPAIR |
110  HA_FILE_BASED | HA_CAN_INSERT_DELAYED | HA_CAN_GEOMETRY);
111  }
112  ulong index_flags(uint idx, uint part, bool all_parts) const
113  {
114  return HA_ONLY_WHOLE_INDEX;
115  }
116  virtual void get_auto_increment(ulonglong offset, ulonglong increment,
117  ulonglong nb_desired_values,
118  ulonglong *first_value,
119  ulonglong *nb_reserved_values);
120  uint max_supported_keys() const { return 1; }
121  uint max_supported_key_length() const { return sizeof(ulonglong); }
122  uint max_supported_key_part_length() const { return sizeof(ulonglong); }
123  ha_rows records() { return share->rows_recorded; }
124  int index_init(uint keynr, bool sorted);
125  virtual int index_read(uchar * buf, const uchar * key,
126  uint key_len, enum ha_rkey_function find_flag);
127  virtual int index_read_idx(uchar * buf, uint index, const uchar * key,
128  uint key_len, enum ha_rkey_function find_flag);
129  int index_next(uchar * buf);
130  int open(const char *name, int mode, uint test_if_locked);
131  int close(void);
132  int write_row(uchar * buf);
133  int real_write_row(uchar *buf, azio_stream *writer);
134  int truncate();
135  int rnd_init(bool scan=1);
136  int rnd_next(uchar *buf);
137  int rnd_pos(uchar * buf, uchar *pos);
138  int get_row(azio_stream *file_to_read, uchar *buf);
139  int get_row_version2(azio_stream *file_to_read, uchar *buf);
140  int get_row_version3(azio_stream *file_to_read, uchar *buf);
141  Archive_share *get_share(const char *table_name, int *rc);
142  int init_archive_reader();
143  bool auto_repair() const { return 1; } // For the moment we just do this
144  int read_data_header(azio_stream *file_to_read);
145  void position(const uchar *record);
146  int info(uint);
147  int extra(enum ha_extra_function operation);
148  void update_create_info(HA_CREATE_INFO *create_info);
149  int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);
150  int optimize(THD* thd, HA_CHECK_OPT* check_opt);
151  int repair(THD* thd, HA_CHECK_OPT* check_opt);
152  void start_bulk_insert(ha_rows rows);
153  int end_bulk_insert();
154  enum row_type get_row_type() const
155  {
156  return ROW_TYPE_COMPRESSED;
157  }
159  enum thr_lock_type lock_type);
160  bool is_crashed() const;
161  int check_for_upgrade(HA_CHECK_OPT *check_opt);
162  int check(THD* thd, HA_CHECK_OPT* check_opt);
163  bool check_and_repair(THD *thd);
164  uint32 max_row_length(const uchar *buf);
165  bool fix_rec_buff(unsigned int length);
166  int unpack_row(azio_stream *file_to_read, uchar *record);
167  unsigned int pack_row(uchar *record, azio_stream *writer);
168  bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes);
169 };
170