~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/ha_archive.h

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

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