~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
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
17
#include <inttypes.h>
1 by brian
clean slate
18
#include <zlib.h>
19
#include "azio.h"
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
20
#include <mysys/thr_lock.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
21
#include <mysys/hash.h>
22
#include <drizzled/handler.h>
1002 by Brian Aker
Refactored out the share to being an object (playing with the structure to
23
#include <string>
24
1 by brian
clean slate
25
/*
26
  Please read ha_archive.cc first. If you are looking for more general
27
  answers on how storage engines work, look at ha_example.cc and
28
  ha_example.h.
29
*/
30
31
typedef struct st_archive_record_buffer {
481 by Brian Aker
Remove all of uchar.
32
  unsigned char *buffer;
205 by Brian Aker
uint32 -> uin32_t
33
  uint32_t length;
1 by brian
clean slate
34
} archive_record_buffer;
35
36
1002 by Brian Aker
Refactored out the share to being an object (playing with the structure to
37
class ArchiveShare {
38
public:
39
  ArchiveShare();
40
  ArchiveShare(const char *name);
41
  ~ArchiveShare();
42
43
  bool prime(uint64_t *auto_increment);
44
1093.5.3 by Monty Taylor
Removed using namespace entries from bare headers.
45
  std::string table_name;
1 by brian
clean slate
46
  char data_file_name[FN_REFLEN];
1002 by Brian Aker
Refactored out the share to being an object (playing with the structure to
47
  uint32_t use_count;
1 by brian
clean slate
48
  pthread_mutex_t mutex;
49
  THR_LOCK lock;
50
  azio_stream archive_write;     /* Archive file we are working with */
51
  bool archive_write_open;
52
  bool dirty;               /* Flag for if a flush should occur */
53
  bool crashed;             /* Meta file is crashed */
54
  uint64_t mean_rec_length;
55
  char real_path[FN_REFLEN];
56
  unsigned int  version;
1002 by Brian Aker
Refactored out the share to being an object (playing with the structure to
57
  ha_rows rows_recorded;    /* Number of rows in tables */
1 by brian
clean slate
58
  ha_rows version_rows;
1002 by Brian Aker
Refactored out the share to being an object (playing with the structure to
59
};
1 by brian
clean slate
60
61
/*
62
  Version for file format.
63
  1 - Initial Version (Never Released)
64
  2 - Stream Compression, seperate blobs, no packing
65
  3 - One steam (row and blobs), with packing
66
*/
67
#define ARCHIVE_VERSION 3
68
69
class ha_archive: public handler
70
{
71
  THR_LOCK_DATA lock;        /* MySQL lock */
1002 by Brian Aker
Refactored out the share to being an object (playing with the structure to
72
  ArchiveShare *share;      /* Shared lock info */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
73
1 by brian
clean slate
74
  azio_stream archive;            /* Archive file we are working with */
75
  my_off_t current_position;  /* The position of the row we just read */
481 by Brian Aker
Remove all of uchar.
76
  unsigned char byte_buffer[IO_SIZE]; /* Initial buffer for our string */
1 by brian
clean slate
77
  String buffer;             /* Buffer used for blob storage */
78
  ha_rows scan_rows;         /* Number of rows left in scan */
79
  bool delayed_insert;       /* If the insert is delayed */
80
  bool bulk_insert;          /* If we are performing a bulk insert */
481 by Brian Aker
Remove all of uchar.
81
  const unsigned char *current_key;
482 by Brian Aker
Remove uint.
82
  uint32_t current_key_len;
83
  uint32_t current_k_offset;
1 by brian
clean slate
84
  archive_record_buffer *record_buffer;
85
  bool archive_reader_open;
86
87
  archive_record_buffer *create_record_buffer(unsigned int length);
88
  void destroy_record_buffer(archive_record_buffer *r);
89
90
public:
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
91
  ha_archive(StorageEngine *engine, TableShare *table_arg);
1 by brian
clean slate
92
  ~ha_archive()
93
  {
94
  }
1008.3.26 by Stewart Smith
remove handler::table_type() as same information can be retrieved from handler::engine->getName()
95
653 by Brian Aker
More solaris bits
96
  const char *index_type(uint32_t)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
97
  { return "NONE"; }
1 by brian
clean slate
98
  uint64_t table_flags() const
99
  {
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
100
    return (HA_NO_TRANSACTIONS | HA_REC_NOT_IN_SEQ |
1 by brian
clean slate
101
            HA_STATS_RECORDS_IS_EXACT |
1095.3.14 by Brian Aker
Moved file based flag up to engine (from handler). checkLowercaseNames() is now a ember of StorageEngine.
102
            HA_HAS_RECORDS);
1 by brian
clean slate
103
  }
653 by Brian Aker
More solaris bits
104
  uint32_t index_flags(uint32_t, uint32_t, bool) const
1 by brian
clean slate
105
  {
106
    return HA_ONLY_WHOLE_INDEX;
107
  }
653 by Brian Aker
More solaris bits
108
  void get_auto_increment(uint64_t, uint64_t, uint64_t,
109
                          uint64_t *first_value, uint64_t *nb_reserved_values);
482 by Brian Aker
Remove uint.
110
  uint32_t max_supported_keys()          const { return 1; }
111
  uint32_t max_supported_key_length()    const { return sizeof(uint64_t); }
112
  uint32_t max_supported_key_part_length() const { return sizeof(uint64_t); }
1 by brian
clean slate
113
  ha_rows records() { return share->rows_recorded; }
482 by Brian Aker
Remove uint.
114
  int index_init(uint32_t keynr, bool sorted);
481 by Brian Aker
Remove all of uchar.
115
  virtual int index_read(unsigned char * buf, const unsigned char * key,
482 by Brian Aker
Remove uint.
116
			 uint32_t key_len, enum ha_rkey_function find_flag);
117
  virtual int index_read_idx(unsigned char * buf, uint32_t index, const unsigned char * key,
118
			     uint32_t key_len, enum ha_rkey_function find_flag);
481 by Brian Aker
Remove all of uchar.
119
  int index_next(unsigned char * buf);
482 by Brian Aker
Remove uint.
120
  int open(const char *name, int mode, uint32_t test_if_locked);
1 by brian
clean slate
121
  int close(void);
481 by Brian Aker
Remove all of uchar.
122
  int write_row(unsigned char * buf);
123
  int real_write_row(unsigned char *buf, azio_stream *writer);
1 by brian
clean slate
124
  int delete_all_rows();
125
  int rnd_init(bool scan=1);
481 by Brian Aker
Remove all of uchar.
126
  int rnd_next(unsigned char *buf);
127
  int rnd_pos(unsigned char * buf, unsigned char *pos);
128
  int get_row(azio_stream *file_to_read, unsigned char *buf);
129
  int get_row_version2(azio_stream *file_to_read, unsigned char *buf);
130
  int get_row_version3(azio_stream *file_to_read, unsigned char *buf);
1002 by Brian Aker
Refactored out the share to being an object (playing with the structure to
131
  ArchiveShare *get_share(const char *table_name, int *rc);
1 by brian
clean slate
132
  int free_share();
133
  int init_archive_writer();
134
  int init_archive_reader();
135
  bool auto_repair() const { return 1; } // For the moment we just do this
136
  int read_data_header(azio_stream *file_to_read);
481 by Brian Aker
Remove all of uchar.
137
  void position(const unsigned char *record);
1 by brian
clean slate
138
  int info(uint);
139
  void update_create_info(HA_CREATE_INFO *create_info);
520.1.22 by Brian Aker
Second pass of thd cleanup
140
  int optimize(Session* session, HA_CHECK_OPT* check_opt);
141
  int repair(Session* session, HA_CHECK_OPT* check_opt);
1 by brian
clean slate
142
  void start_bulk_insert(ha_rows rows);
143
  int end_bulk_insert();
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
144
  enum row_type get_row_type() const
145
  {
1 by brian
clean slate
146
    return ROW_TYPE_COMPRESSED;
147
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
148
  THR_LOCK_DATA **store_lock(Session *session, THR_LOCK_DATA **to,
1 by brian
clean slate
149
                             enum thr_lock_type lock_type);
150
  bool is_crashed() const;
520.1.22 by Brian Aker
Second pass of thd cleanup
151
  int check(Session* session, HA_CHECK_OPT* check_opt);
152
  bool check_and_repair(Session *session);
481 by Brian Aker
Remove all of uchar.
153
  uint32_t max_row_length(const unsigned char *buf);
1 by brian
clean slate
154
  bool fix_rec_buff(unsigned int length);
481 by Brian Aker
Remove all of uchar.
155
  int unpack_row(azio_stream *file_to_read, unsigned char *record);
156
  unsigned int pack_row(unsigned char *record);
1 by brian
clean slate
157
};
158