~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/ha_archive.h

  • Committer: Monty Taylor
  • Date: 2009-05-19 21:30:11 UTC
  • mto: (1022.4.2 update-to-gcc-44)
  • mto: This revision was merged to the branch mainline in revision 1031.
  • Revision ID: mordred@inaugust.com-20090519213011-4tpejk7l2f1q7wrh
Added support for using gnutls instead of openssl for the md5 plugin. On Debian,
linking openssl against GPL software is sort of frowned on because it's one
of those murky areas. In this case, we can support gnutls by just changing a
header, so it saves us an argument with someone down the road.

Show diffs side-by-side

added added

removed removed

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