~drizzle-trunk/drizzle/development

1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1239.3.28 by Toru Maesaka
Added UNIQUE constraint check for UPDATE queries on VARCHAR key(s) and some tests for it.
4
 *  Copyright (C) 2009 - 2010 Toru Maesaka
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
1239.5.2 by Stewart Smith
fix cpplint warning r.e. header guard for BlitzDB
20
#ifndef PLUGIN_BLITZDB_HA_BLITZ_H
21
#define PLUGIN_BLITZDB_HA_BLITZ_H
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
22
1239.3.18 by Toru Maesaka
Merged Drizzle's Trunk
23
#include "drizzled/session.h"
24
#include "drizzled/cursor.h"
25
#include "drizzled/table.h"
26
#include "drizzled/field.h"
27
#include "drizzled/field/blob.h"
28
#include "drizzled/atomics.h"
29
#include "drizzled/error.h"
30
#include "drizzled/gettext.h"
1239.4.3 by Monty Taylor
Updated for out of tree builds.
31
#include "drizzled/cached_directory.h"
1239.3.121 by Toru Maesaka
Use internal::my_rename instead of std::rename to keep FreeBSD happy.
32
#include "drizzled/internal/my_sys.h"
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
33
#include <tchdb.h>
1239.3.10 by Toru Maesaka
Started hacking on indexing. Prep Work 1.
34
#include <tcbdb.h>
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
35
36
#include <string>
1239.3.102 by Toru Maesaka
Fixed warnings generated in the Build Farm and updated tests to make TC version differences irrelevant.
37
#include <sys/stat.h>
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
38
1239.3.76 by Toru Maesaka
Base work for implementing ha_blitz::records_in_range().
39
#define BLITZ_DATA_EXT         ".bzd"
40
#define BLITZ_INDEX_EXT        ".bzx"
41
#define BLITZ_SYSTEM_EXT       ".bzs"
42
#define BLITZ_LOCK_SLOTS       16
1239.3.100 by Toru Maesaka
Allow NULL to be duplicately inserted into a UNIQUE INDEX. Added some tests for it as well. More patches to come.
43
#define BLITZ_MAX_INDEX        8
1239.3.76 by Toru Maesaka
Base work for implementing ha_blitz::records_in_range().
44
#define BLITZ_MAX_META_LEN     128
45
#define BLITZ_MAX_ROW_STACK    2048
46
#define BLITZ_MAX_KEY_LEN      1024 
1239.3.81 by Toru Maesaka
Added BlitzTree::next_logical_key() for HA_READ_AFTER_KEY search mode. BlitzDB is now HA_READ_RANGE compatible.
47
#define BLITZ_WORST_CASE_RANGE 4
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
48
1239.5.4 by Stewart Smith
cpplint for BlitzDB: Do not use namespace using-directives in headers.
49
const std::string BLITZ_TABLE_PROTO_KEY = "table_definition";
50
const std::string BLITZ_TABLE_PROTO_COMMENT_KEY = "table_definition_comment";
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
51
1239.3.108 by Toru Maesaka
Removed dead function declaration and worked on BlitzCursor object.
52
/* Class Prototype */
53
class BlitzLock;
54
class BlitzData;
55
class BlitzKeyPart;
56
class BlitzCursor;
57
class BlitzTree;
58
class BlitzShare;
59
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
60
/* Multi Reader-Writer lock responsible for controlling concurrency
61
   at the handler level. This class is implemented in blitzlock.cc */
62
class BlitzLock {
63
private:
64
  int scanner_count;
65
  int updater_count;
1239.3.37 by Toru Maesaka
Added a slotted lock mechanism to BlitzLock. This is used to atomically update the index file(s) and the data dictionary with concurrency in mind.
66
  pthread_cond_t condition;
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
67
  pthread_mutex_t mutex;
1239.3.37 by Toru Maesaka
Added a slotted lock mechanism to BlitzLock. This is used to atomically update the index file(s) and the data dictionary with concurrency in mind.
68
  pthread_mutex_t slots[BLITZ_LOCK_SLOTS];
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
69
70
public:
71
  BlitzLock();
72
  ~BlitzLock();
73
1239.3.37 by Toru Maesaka
Added a slotted lock mechanism to BlitzLock. This is used to atomically update the index file(s) and the data dictionary with concurrency in mind.
74
  /* Slotted Lock Mechanism for Concurrently and Atomically
75
     updating the index and data dictionary at the same time. */
76
  uint32_t slot_id(const void *data, size_t len);
77
  int slotted_lock(const uint32_t slot_id);
78
  int slotted_unlock(const uint32_t slot_id);
79
80
  /* Multi Reader-Writer Lock Mechanism. */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
81
  void update_begin();
82
  void update_end();
83
  void scan_begin();
84
  void scan_end();
85
  void scan_update_begin();
86
  void scan_update_end();
87
};
88
1239.3.10 by Toru Maesaka
Started hacking on indexing. Prep Work 1.
89
/* Handler that takes care of all I/O to the data dictionary
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
90
   that holds actual rows. */
91
class BlitzData {
92
private:
1239.3.10 by Toru Maesaka
Started hacking on indexing. Prep Work 1.
93
  TCHDB *data_table;    /* Where the actual row data lives */
94
  TCHDB *system_table;  /* Keeps track of system info */
95
  char *tc_meta_buffer; /* Tokyo Cabinet's Persistent Meta Buffer */
1239.3.6 by Toru Maesaka
Use Drizzle's atomic memory access wrapper to generate hidden row IDs.
96
  drizzled::atomic<uint64_t> current_hidden_row_id;
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
97
98
public:
1239.3.8 by Toru Maesaka
Remove redundant calculation in row packing mechanism.
99
  BlitzData() { current_hidden_row_id = 0; }
100
  ~BlitzData() {}
1239.3.34 by Toru Maesaka
Separated the codebase for Data Dictionary and System Table. TC object is no longer exposed to the handler.
101
  int startup(const char *table_path);
102
  int shutdown(void);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
103
104
  /* DATA DICTIONARY CREATION RELATED */
1239.3.42 by Toru Maesaka
Merged Drizzle's Trunk.
105
  int create_data_table(drizzled::message::Table &proto,
1239.3.88 by Toru Maesaka
Minor cleanup and interface changes to suit the updated Drizzle Storage API.
106
                        drizzled::Table &table,
1627.2.6 by Monty Taylor
Merged in constification of TableIdentifier from Brian.
107
                        const drizzled::TableIdentifier &identifier);
1239.3.88 by Toru Maesaka
Minor cleanup and interface changes to suit the updated Drizzle Storage API.
108
1239.3.34 by Toru Maesaka
Separated the codebase for Data Dictionary and System Table. TC object is no longer exposed to the handler.
109
  int open_data_table(const char *path, const int mode);
110
  int close_data_table(void);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
111
  bool rename_table(const char *from, const char *to);
112
1239.3.10 by Toru Maesaka
Started hacking on indexing. Prep Work 1.
113
  /* DATA DICTIONARY METADATA RELATED */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
114
  uint64_t nrecords(void);
1239.3.19 by Toru Maesaka
Removed all thr_lock related code. Supported primary key based deletion and added a test for it.
115
  uint64_t table_size(void);
1239.3.30 by Toru Maesaka
Added a wrapper to access tc_meta_buffer. Our new policy is to not directly use it.
116
  uint64_t read_meta_row_id(void);
1239.3.31 by Toru Maesaka
Use TC's Meta Buffer for storing auto increment value instead of the system table. Fixed a valgrind warning too.
117
  uint64_t read_meta_autoinc(void);
1239.3.32 by Toru Maesaka
Write the number of keys to TC's Meta Buffer on table creation. Made minor changes to BlitzTree's interface.
118
  uint32_t read_meta_keycount(void);
1239.3.30 by Toru Maesaka
Added a wrapper to access tc_meta_buffer. Our new policy is to not directly use it.
119
  void write_meta_row_id(uint64_t row_id);
1239.3.31 by Toru Maesaka
Use TC's Meta Buffer for storing auto increment value instead of the system table. Fixed a valgrind warning too.
120
  void write_meta_autoinc(uint64_t num);
1239.3.32 by Toru Maesaka
Write the number of keys to TC's Meta Buffer on table creation. Made minor changes to BlitzTree's interface.
121
  void write_meta_keycount(uint32_t nkeys);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
122
123
  /* DATA DICTIONARY READ RELATED*/
124
  char *get_row(const char *key, const size_t klen, int *value_len);
125
  char *next_key_and_row(const char *key, const size_t klen,
126
                         int *next_key_len, const char **value,
1239.3.16 by Toru Maesaka
Added index_init() and index_first() for Primary Keys.
127
                         int *value_len);
128
  char *first_row(int *row_len);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
129
130
  /* DATA DICTIONARY WRITE RELATED */
131
  uint64_t next_hidden_row_id(void);
1239.3.12 by Toru Maesaka
Resolve Primary Key and cleanup BlitzData API. Index Support Prep Work 2.
132
  int write_row(const char *key, const size_t klen,
133
                const unsigned char *row, const size_t rlen);
134
  int write_unique_row(const char *key, const size_t klen,
135
                       const unsigned char *row, const size_t rlen);
1239.3.66 by Toru Maesaka
Started working on completing ha_blitz::delete_row(). Refactored index_read_idx() to suit the new comparator. Index update tests are disabled until ha_blitz::update_row() is completed.
136
  int delete_row(const char *key, const size_t klen);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
137
  bool delete_all_rows(void);
1239.3.34 by Toru Maesaka
Separated the codebase for Data Dictionary and System Table. TC object is no longer exposed to the handler.
138
139
  /* SYSTEM TABLE RELATED */
1239.3.88 by Toru Maesaka
Minor cleanup and interface changes to suit the updated Drizzle Storage API.
140
  int create_system_table(const std::string &path);
141
  int open_system_table(const std::string &path, const int mode);
1239.3.34 by Toru Maesaka
Separated the codebase for Data Dictionary and System Table. TC object is no longer exposed to the handler.
142
  int close_system_table(void);
143
  bool write_table_definition(drizzled::message::Table &proto);
144
  char *get_system_entry(const char *key, const size_t klen, int *vlen);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
145
};
146
1239.3.40 by Toru Maesaka
Extract useful key information from the internal KEY structure at open() and keep it in BlitzDB.
147
/* This class is only used by the BlitzTree object which has a long life
1239.3.112 by Toru Maesaka
Merged Drizzle's Trunk.
148
   span. In general we use the Cursor's local KeyPartInfo array for
1239.3.40 by Toru Maesaka
Extract useful key information from the internal KEY structure at open() and keep it in BlitzDB.
149
   obtaining key information. We create our own array of key information
150
   because there is no guarantee that the pointer to the internal key_info
151
   array will always be alive. */
152
class BlitzKeyPart {
153
public:
154
  BlitzKeyPart() : offset(0), null_pos(0), flag(0), length(0), type(0),
155
                   null_bitmask(0) {}
156
  ~BlitzKeyPart() {}
157
158
  uint32_t offset;      /* Offset of the key in the row */
159
  uint32_t null_pos;    /* Offset of the NULL indicator in the row */
160
  uint16_t flag;
161
  uint16_t length;      /* Length of the key */
162
  uint8_t type;         /* Type of the key */
163
  uint8_t null_bitmask; /* Bitmask to test for NULL */
164
};
165
1239.3.106 by Toru Maesaka
First step in splitting BlitzTree's cursor object.
166
class BlitzCursor {
167
public:
1239.3.108 by Toru Maesaka
Removed dead function declaration and worked on BlitzCursor object.
168
  BlitzCursor() : tree(NULL), cursor(NULL), moved(false),
169
                  active(false) {}
1239.3.106 by Toru Maesaka
First step in splitting BlitzTree's cursor object.
170
  ~BlitzCursor() {}
171
1239.3.108 by Toru Maesaka
Removed dead function declaration and worked on BlitzCursor object.
172
  BlitzTree *tree; /* Tree that this instance works on */
173
  BDBCUR *cursor;  /* Raw cursor to TC */
174
  bool moved;      /* Whether the key was implicitly moved */
175
  bool active;     /* Whether this cursor is active */
1239.3.109 by Toru Maesaka
Still not optimal but the cursor object is now separated between workers. This build survived sysbench's read-only OLTP test.
176
177
  /* B+TREE READ RELATED */
178
  char *first_key(int *key_len);
179
  char *final_key(int *key_len);
180
  char *next_key(int *key_len);
181
  char *prev_key(int *key_ken);
182
  char *next_logical_key(int *key_len);
183
  char *prev_logical_key(int *key_len);
184
185
  char *find_key(const int search_mode, const char *key,
186
                 const int klen, int *rv_len);
187
188
  /* B+TREE UPDATE RELATED */
189
  int delete_position(void);
1239.3.106 by Toru Maesaka
First step in splitting BlitzTree's cursor object.
190
};
191
1239.3.10 by Toru Maesaka
Started hacking on indexing. Prep Work 1.
192
/* Class that reprensents a BTREE index. Takes care of all I/O
1239.3.86 by Toru Maesaka
Merged up to rev:1360. drizzled::TableIdentifier Support.
193
   to the B+Tree index structure */
1239.3.10 by Toru Maesaka
Started hacking on indexing. Prep Work 1.
194
class BlitzTree {
195
private:
196
  TCBDB *btree;
1239.3.38 by Toru Maesaka
More work on indexing component. PK now gets a tree.
197
198
public:
1239.3.110 by Toru Maesaka
Removed old cursor creation/destroy code.
199
  BlitzTree() : length(0), nparts(0), type(0), unique(false) {}
1239.3.38 by Toru Maesaka
More work on indexing component. PK now gets a tree.
200
  ~BlitzTree() {}
201
202
  /* METADATA */
1239.3.40 by Toru Maesaka
Extract useful key information from the internal KEY structure at open() and keep it in BlitzDB.
203
  BlitzKeyPart *parts; /* Array of Key Part(s) */
1239.3.45 by Toru Maesaka
Optimized key generation (much leaner keys). Wrote a workaround for a HA_KEYTYPE_VARTEXT1 bug in Drizzle's Field_varstring. Added tests for a VARCHAR field less than 255 bytes.
204
  int length;          /* Length of the entire key */
1239.3.40 by Toru Maesaka
Extract useful key information from the internal KEY structure at open() and keep it in BlitzDB.
205
  int nparts;          /* Number of parts in this key */
1239.3.54 by Toru Maesaka
Supported secondary index insertion, Added meta information on the B+Tree cursor and some tests.
206
  int type;            /* Type of the key */
1239.3.40 by Toru Maesaka
Extract useful key information from the internal KEY structure at open() and keep it in BlitzDB.
207
  bool unique;         /* Whether this key is unique */
1239.3.10 by Toru Maesaka
Started hacking on indexing. Prep Work 1.
208
209
  /* BTREE INDEX CREATION RELATED */
1239.3.32 by Toru Maesaka
Write the number of keys to TC's Meta Buffer on table creation. Made minor changes to BlitzTree's interface.
210
  int open(const char *path, const int key_num, int mode);
211
  int create(const char *path, const int key_num);
1239.3.35 by Toru Maesaka
Made index file(s) droppable and renamable.
212
  int drop(const char *path, const int key_num);
213
  int rename(const char *from, const char *to, const int key_num);
1239.3.10 by Toru Maesaka
Started hacking on indexing. Prep Work 1.
214
  int close(void);
1239.3.11 by Toru Maesaka
Added appropriate locking for ALTER TABLE and test case for it. Record the number of indexes in BlitzShare.
215
1239.3.61 by Toru Maesaka
Worked on reducing the execution path of row insertion and supported NULL for key values. Added tests for NULL values in full index scan.
216
  /* KEY HANDLING */
1239.3.113 by Toru Maesaka
Improved cursor resource management. TC's cursor allocation only happens once per worker now.
217
  bool create_cursor(BlitzCursor *cursor);
1239.3.106 by Toru Maesaka
First step in splitting BlitzTree's cursor object.
218
  void destroy_cursor(BlitzCursor *cursor);
1239.3.61 by Toru Maesaka
Worked on reducing the execution path of row insertion and supported NULL for key values. Added tests for NULL values in full index scan.
219
1239.3.11 by Toru Maesaka
Added appropriate locking for ALTER TABLE and test case for it. Record the number of indexes in BlitzShare.
220
  /* BTREE INDEX WRITE RELATED */
1239.3.72 by Toru Maesaka
Fixed a critical concurrency bug that would cause inconsistency. Reworked BlitzTree and refactored memory management a little.
221
  int write(const char *key, const size_t klen);
222
  int write_unique(const char *key, const size_t klen);
1239.3.68 by Toru Maesaka
ha_blitz::delete_row() can now delete all index entries. Added basic tests for it as well. More to come.
223
  int delete_key(const char *key, const int klen);
1239.3.38 by Toru Maesaka
More work on indexing component. PK now gets a tree.
224
  int delete_all(void);
1239.3.45 by Toru Maesaka
Optimized key generation (much leaner keys). Wrote a workaround for a HA_KEYTYPE_VARTEXT1 bug in Drizzle's Field_varstring. Added tests for a VARCHAR field less than 255 bytes.
225
1239.3.10 by Toru Maesaka
Started hacking on indexing. Prep Work 1.
226
  /* BTREE METADATA RELATED */
227
  uint64_t records(void); 
228
};
229
1239.3.77 by Toru Maesaka
Isolated key comparison code. It's now a function that can be used anywhere in BlitzDB.
230
/* Callback function for TC's B+Tree key comparison. */
231
extern int blitz_keycmp_cb(const char *a, int alen,
232
                           const char *b, int blen, void *opaque);
233
/* Comparison function for Drizzle types. */
234
extern int packed_key_cmp(BlitzTree *, const char *a, const char *b,
235
                          int *a_real_len, int *b_real_len);
236
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
237
/* Object shared among all worker threads. Try to only add
238
   data that will not be updated at runtime or those that
239
   do not require locking. */
240
class BlitzShare {
241
public:
1239.3.11 by Toru Maesaka
Added appropriate locking for ALTER TABLE and test case for it. Record the number of indexes in BlitzShare.
242
  BlitzShare() : blitz_lock(), use_count(0), nkeys(0) {}
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
243
  ~BlitzShare() {}
244
1239.3.22 by Toru Maesaka
Added Auto Increment support on INSERT and tests for it. Nextup: UPDATE.
245
  drizzled::atomic<uint64_t> auto_increment_value;
246
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
247
  BlitzLock blitz_lock;    /* Handler level lock for BlitzDB */
248
  BlitzData dict;          /* Utility class of BlitzDB */
1239.3.36 by Toru Maesaka
Added code to allocate/deallocate b+tree indexes.
249
  BlitzTree *btrees;       /* Array of BTREE indexes */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
250
  std::string table_name;  /* Name and Length of the table */
251
  uint32_t use_count;      /* Reference counter of this object */
1239.3.11 by Toru Maesaka
Added appropriate locking for ALTER TABLE and test case for it. Record the number of indexes in BlitzShare.
252
  uint32_t nkeys;          /* Number of indexes in this table */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
253
  bool fixed_length_table; /* Whether the table is fixed length */
1239.3.4 by Toru Maesaka
Reworked position() and rnd_pos(). Started reworking update_row() for UPDATES with ORDER BY.
254
  bool primary_key_exists; /* Whether a PK exists in this table */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
255
};
256
1239.3.42 by Toru Maesaka
Merged Drizzle's Trunk.
257
class ha_blitz: public drizzled::Cursor {
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
258
private:
1239.3.42 by Toru Maesaka
Merged Drizzle's Trunk.
259
  BlitzShare *share;            /* Shared object among all threads */
1239.3.113 by Toru Maesaka
Improved cursor resource management. TC's cursor allocation only happens once per worker now.
260
  BlitzCursor *btree_cursor;    /* Array of B+Tree Cursor */
1239.3.42 by Toru Maesaka
Merged Drizzle's Trunk.
261
  drizzled::THR_LOCK_DATA lock; /* Drizzle Lock */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
262
263
  /* THREAD STATE */
1239.3.25 by Toru Maesaka
Obtain memory for key packing from heap instead from the stack. Minor memory handling changes in write_row() and code-cosmetic changes.
264
  bool table_scan;           /* Whether a table scan is occuring */
1239.3.69 by Toru Maesaka
First attempt at completing update_row(). Still needs cleaning and tuning but the flow is there and doesn't break existing tests.
265
  bool table_based;          /* Whether the query involves rnd_xxx() */
1239.3.25 by Toru Maesaka
Obtain memory for key packing from heap instead from the stack. Minor memory handling changes in write_row() and code-cosmetic changes.
266
  bool thread_locked;        /* Whether the thread is locked */
267
  uint32_t sql_command_type; /* Type of SQL command to process */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
268
1239.3.53 by Toru Maesaka
Removed dead variables, shuffled ha_blitz class around and added a 1KB buffer for exclusive use on keeping track of keys.
269
  /* RECORDED KEY IN TABLE OR INDEX READ */
270
  char *held_key;            /* Points to held_key_buf or an allocated key */
271
  char *held_key_buf;        /* Buffer used to copy an unallocated key */
272
  int held_key_len;          /* Length of the key being held */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
273
1239.3.53 by Toru Maesaka
Removed dead variables, shuffled ha_blitz class around and added a 1KB buffer for exclusive use on keeping track of keys.
274
  /* TABLE SCANNER VARIABLES */
1239.3.25 by Toru Maesaka
Obtain memory for key packing from heap instead from the stack. Minor memory handling changes in write_row() and code-cosmetic changes.
275
  char *current_key;         /* Current key in table scan */
276
  const char *current_row;   /* Current row in table scan */
277
  int current_key_len;       /* Length of the current key */
278
  int current_row_len;       /* Length of the current row */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
279
1239.3.72 by Toru Maesaka
Fixed a critical concurrency bug that would cause inconsistency. Reworked BlitzTree and refactored memory management a little.
280
  /* KEY PROCESSING BUFFERS */
281
  char *key_buffer;          /* Key generation buffer */
282
  char *key_merge_buffer;    /* Key Merge buffer for B+Tree */
283
  size_t key_merge_buffer_len;  /* Size of the merge buffer */
284
1239.3.53 by Toru Maesaka
Removed dead variables, shuffled ha_blitz class around and added a 1KB buffer for exclusive use on keeping track of keys.
285
  /* ROW PROCESSING VARIABLES */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
286
  unsigned char pack_buffer[BLITZ_MAX_ROW_STACK]; /* Pack Buffer */
287
  unsigned char *secondary_row_buffer;            /* For big rows */
288
  size_t secondary_row_buffer_size;               /* Reserved buffer size */
1239.3.13 by Toru Maesaka
Added basic index key handling. Started working on PRIMARY KEY support and added tests for it.
289
  int errkey_id;
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
290
291
public:
1239.3.42 by Toru Maesaka
Merged Drizzle's Trunk.
292
  ha_blitz(drizzled::plugin::StorageEngine &engine_arg,
293
           drizzled::TableShare &table_arg);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
294
  ~ha_blitz() {}
295
1239.3.17 by Toru Maesaka
Implemented index_read() and index_read_idx() for PK and added a simple needle in a haystack test.
296
  /* TABLE CONTROL RELATED FUNCTIONS */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
297
  const char **bas_ext() const;
1239.3.17 by Toru Maesaka
Implemented index_read() and index_read_idx() for PK and added a simple needle in a haystack test.
298
  const char *index_type(uint32_t key_num);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
299
  int open(const char *name, int mode, uint32_t open_options);
300
  int close(void);
301
  int info(uint32_t flag);
302
1239.3.16 by Toru Maesaka
Added index_init() and index_first() for Primary Keys.
303
  /* TABLE SCANNER RELATED FUNCTIONS */
1239.3.105 by Toru Maesaka
Merged Drizzle's Trunk.
304
  int doStartTableScan(bool scan);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
305
  int rnd_next(unsigned char *buf);
1239.3.105 by Toru Maesaka
Merged Drizzle's Trunk.
306
  int doEndTableScan(void);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
307
  int rnd_pos(unsigned char *buf, unsigned char *pos);
308
309
  void position(const unsigned char *record);
310
1239.3.16 by Toru Maesaka
Added index_init() and index_first() for Primary Keys.
311
  /* INDEX RELATED FUNCTIONS */
1239.3.105 by Toru Maesaka
Merged Drizzle's Trunk.
312
  int doStartIndexScan(uint32_t key_num, bool sorted);
1239.3.16 by Toru Maesaka
Added index_init() and index_first() for Primary Keys.
313
  int index_first(unsigned char *buf);
1239.3.47 by Toru Maesaka
Implemented forward index scan and basic tests for it. More tests to come.
314
  int index_next(unsigned char *buf);
1239.3.50 by Toru Maesaka
Implemented reverse index scan and added tests for it. Fixed a bug in delete_all_rows().
315
  int index_prev(unsigned char *buf);
316
  int index_last(unsigned char *buf);
1239.3.17 by Toru Maesaka
Implemented index_read() and index_read_idx() for PK and added a simple needle in a haystack test.
317
  int index_read(unsigned char *buf, const unsigned char *key,
1239.3.42 by Toru Maesaka
Merged Drizzle's Trunk.
318
                 uint32_t key_len, enum drizzled::ha_rkey_function find_flag);
1239.3.17 by Toru Maesaka
Implemented index_read() and index_read_idx() for PK and added a simple needle in a haystack test.
319
  int index_read_idx(unsigned char *buf, uint32_t key_num,
320
                     const unsigned char *key, uint32_t key_len,
1239.3.42 by Toru Maesaka
Merged Drizzle's Trunk.
321
                     enum drizzled::ha_rkey_function find_flag);
1239.3.105 by Toru Maesaka
Merged Drizzle's Trunk.
322
  int doEndIndexScan(void);
1239.3.122 by Toru Maesaka
Implemented Cursor::enable_indexes() and Cursor::disable_indexes(). Added a test file it as well.
323
  int enable_indexes(uint32_t mode);  /* For ALTER ... ENABLE KEYS */
324
  int disable_indexes(uint32_t mode); /* For ALTER ... DISABLE KEYS */
1239.3.16 by Toru Maesaka
Added index_init() and index_first() for Primary Keys.
325
1239.3.76 by Toru Maesaka
Base work for implementing ha_blitz::records_in_range().
326
  drizzled::ha_rows records_in_range(uint32_t key_num,
327
                                     drizzled::key_range *min_key,
328
                                     drizzled::key_range *max_key);
329
1239.3.16 by Toru Maesaka
Added index_init() and index_first() for Primary Keys.
330
  /* UPDATE RELATED FUNCTIONS */
1239.3.98 by Toru Maesaka
Merged Trunk.
331
  int doInsertRecord(unsigned char *buf);
332
  int doUpdateRecord(const unsigned char *old_data, unsigned char *new_data);
333
  int doDeleteRecord(const unsigned char *buf);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
334
  int delete_all_rows(void);
1239.3.22 by Toru Maesaka
Added Auto Increment support on INSERT and tests for it. Nextup: UPDATE.
335
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
336
                                  uint64_t nb_desired_values,
337
                                  uint64_t *first_value,
338
                                  uint64_t *nb_reserved_values);
339
  int reset_auto_increment(uint64_t value);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
340
1239.3.29 by Toru Maesaka
Added UNIQUE constraint check on fixed length fields and more tests. Moved get_share() to ha_blitz class.
341
  /* UTILITY FUNCTIONS (BLITZDB SPECIFIC) */
342
  BlitzShare *get_share(const char *table_name);
1239.3.90 by Toru Maesaka
free_share() is now a member of Cursor::ha_blitz.
343
  int free_share(void);
1239.3.29 by Toru Maesaka
Added UNIQUE constraint check on fixed length fields and more tests. Moved get_share() to ha_blitz class.
344
1239.3.28 by Toru Maesaka
Added UNIQUE constraint check for UPDATE queries on VARCHAR key(s) and some tests for it.
345
  /* LOCK RELATED FUNCTIONS (BLITZDB SPECIFIC) */
1239.3.5 by Toru Maesaka
Supported UPDATEs with ORDER BY and added a test for it.
346
  int critical_section_enter();
347
  int critical_section_exit();
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
348
  uint32_t max_row_length(void);
1239.3.28 by Toru Maesaka
Added UNIQUE constraint check for UPDATE queries on VARCHAR key(s) and some tests for it.
349
350
  /* INDEX KEY RELATED FUNCTIONS (BLITZDB SPECIFIC) */
1239.3.39 by Toru Maesaka
Reworked the key packer to support null fields and deleted now a redundant function: pack_index_key_from_row().
351
  size_t make_primary_key(char *pack_to, const unsigned char *row);
352
  size_t make_index_key(char *pack_to, int key_num, const unsigned char *row);
1239.3.47 by Toru Maesaka
Implemented forward index scan and basic tests for it. More tests to come.
353
  size_t btree_key_length(const char *key, const int key_num);
1239.3.23 by Toru Maesaka
Supported VARCHAR to be usable as index key(s). Also added basic tests where VARCHAR is used as PK.
354
  char *native_to_blitz_key(const unsigned char *native_key,
355
                            const int key_num, int *return_key_length);
1239.3.72 by Toru Maesaka
Fixed a critical concurrency bug that would cause inconsistency. Reworked BlitzTree and refactored memory management a little.
356
  char *merge_key(const char *a, const size_t a_len, const char *b,
357
                  const size_t b_len, size_t *merged_len);
1239.3.53 by Toru Maesaka
Removed dead variables, shuffled ha_blitz class around and added a 1KB buffer for exclusive use on keeping track of keys.
358
  void keep_track_of_key(const char *key, const int klen);
1239.3.28 by Toru Maesaka
Added UNIQUE constraint check for UPDATE queries on VARCHAR key(s) and some tests for it.
359
360
  /* ROW RELATED FUNCTIONS (BLITZDB SPECIFIC) */
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
361
  size_t pack_row(unsigned char *row_buffer, unsigned char *row_to_pack);
1239.3.8 by Toru Maesaka
Remove redundant calculation in row packing mechanism.
362
  bool unpack_row(unsigned char *to, const char *from, const size_t from_len);
363
  unsigned char *get_pack_buffer(const size_t size);
1239.3.28 by Toru Maesaka
Added UNIQUE constraint check for UPDATE queries on VARCHAR key(s) and some tests for it.
364
365
  /* COMAPARISON LOGIC (BLITZDB SPECIFIC) */
366
  int compare_rows_for_unique_violation(const unsigned char *old_row,
367
                                        const unsigned char *new_row);
1239.3.1 by Toru Maesaka
Initial import of Project BlitzDB.
368
};
369
1239.5.2 by Stewart Smith
fix cpplint warning r.e. header guard for BlitzDB
370
#endif /* PLUGIN_BLITZDB_HA_BLITZ_H */