~drizzle-trunk/drizzle/development

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
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
20
#include <inttypes.h>
1 by brian
clean slate
21
#include <zlib.h>
22
#include "azio.h"
23
24
/*
25
  Please read ha_archive.cc first. If you are looking for more general
26
  answers on how storage engines work, look at ha_example.cc and
27
  ha_example.h.
28
*/
29
30
typedef struct st_archive_record_buffer {
31
  uchar *buffer;
205 by Brian Aker
uint32 -> uin32_t
32
  uint32_t length;
1 by brian
clean slate
33
} archive_record_buffer;
34
35
36
typedef struct st_archive_share {
37
  char *table_name;
38
  char data_file_name[FN_REFLEN];
39
  uint table_name_length,use_count;
40
  pthread_mutex_t mutex;
41
  THR_LOCK lock;
42
  azio_stream archive_write;     /* Archive file we are working with */
43
  bool archive_write_open;
44
  bool dirty;               /* Flag for if a flush should occur */
45
  bool crashed;             /* Meta file is crashed */
46
  ha_rows rows_recorded;    /* Number of rows in tables */
47
  uint64_t mean_rec_length;
48
  char real_path[FN_REFLEN];
49
  unsigned int  version;
50
  ha_rows version_rows;
51
} ARCHIVE_SHARE;
52
53
/*
54
  Version for file format.
55
  1 - Initial Version (Never Released)
56
  2 - Stream Compression, seperate blobs, no packing
57
  3 - One steam (row and blobs), with packing
58
*/
59
#define ARCHIVE_VERSION 3
60
61
class ha_archive: public handler
62
{
63
  THR_LOCK_DATA lock;        /* MySQL lock */
64
  ARCHIVE_SHARE *share;      /* Shared lock info */
65
  
66
  azio_stream archive;            /* Archive file we are working with */
67
  my_off_t current_position;  /* The position of the row we just read */
68
  uchar byte_buffer[IO_SIZE]; /* Initial buffer for our string */
69
  String buffer;             /* Buffer used for blob storage */
70
  ha_rows scan_rows;         /* Number of rows left in scan */
71
  bool delayed_insert;       /* If the insert is delayed */
72
  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;
76
  archive_record_buffer *record_buffer;
77
  bool archive_reader_open;
78
79
  archive_record_buffer *create_record_buffer(unsigned int length);
80
  void destroy_record_buffer(archive_record_buffer *r);
81
82
public:
83
  ha_archive(handlerton *hton, TABLE_SHARE *table_arg);
84
  ~ha_archive()
85
  {
86
  }
87
  const char *table_type() const { return "ARCHIVE"; }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
88
  const char *index_type(uint inx __attribute__((unused)))
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
89
  { return "NONE"; }
1 by brian
clean slate
90
  const char **bas_ext() const;
91
  uint64_t table_flags() const
92
  {
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
93
    return (HA_NO_TRANSACTIONS | HA_REC_NOT_IN_SEQ |
1 by brian
clean slate
94
            HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE |
95
            HA_STATS_RECORDS_IS_EXACT |
96
            HA_HAS_RECORDS |
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
97
            HA_FILE_BASED);
1 by brian
clean slate
98
  }
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
99
  uint32_t index_flags(uint idx __attribute__((unused)),
100
                       uint part __attribute__((unused)),
101
                       bool all_parts __attribute__((unused))) const
1 by brian
clean slate
102
  {
103
    return HA_ONLY_WHOLE_INDEX;
104
  }
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); }
112
  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);
120
  int close(void);
121
  int write_row(uchar * buf);
122
  int real_write_row(uchar *buf, azio_stream *writer);
123
  int delete_all_rows();
124
  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);
131
  int free_share();
132
  int init_archive_writer();
133
  int init_archive_reader();
134
  bool auto_repair() const { return 1; } // For the moment we just do this
135
  int read_data_header(azio_stream *file_to_read);
136
  void position(const uchar *record);
137
  int info(uint);
138
  void update_create_info(HA_CREATE_INFO *create_info);
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
139
  int create(const char *name, Table *form, HA_CREATE_INFO *create_info);
1 by brian
clean slate
140
  int optimize(THD* thd, HA_CHECK_OPT* check_opt);
141
  int repair(THD* thd, HA_CHECK_OPT* check_opt);
142
  void start_bulk_insert(ha_rows rows);
143
  int end_bulk_insert();
144
  enum row_type get_row_type() const 
145
  { 
146
    return ROW_TYPE_COMPRESSED;
147
  }
148
  THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
149
                             enum thr_lock_type lock_type);
150
  bool is_crashed() const;
151
  int check(THD* thd, HA_CHECK_OPT* check_opt);
152
  bool check_and_repair(THD *thd);
205 by Brian Aker
uint32 -> uin32_t
153
  uint32_t max_row_length(const uchar *buf);
1 by brian
clean slate
154
  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);
157
};
158