drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
wiredtiger_drizzle.h
1
2/* Header for the the WiredTiger Cursor */
3
4#pragma once
5
6#include <drizzled/cursor.h>
7#include <drizzled/errmsg_print.h>
8#include <drizzled/plugin/storage_engine.h>
9#include <drizzled/plugin/transactional_storage_engine.h>
10#include <drizzled/session.h>
11#include <drizzled/thr_lock.h>
12#include <wiredtiger.h>
13#include <boost/dynamic_bitset.hpp>
14#include <drizzled/identifier/table.h>
15
16#define WT_UNUSED(a) (void)(a)
17
18using namespace drizzled;
19using namespace std;
20
22
23static const char *wiredtiger_exts[] = {
24 NULL
25};
26typedef unsigned char *WIREDTIGER_PTR;
27
28class WiredTigerTableShare
29{
30public:
31WiredTigerTableShare(drizzled::identifier::Table _table_identifier):
32 use_count(0), table_identifier(_table_identifier) {}
33
34 // the following are protected by wt_share_mutex
36 int64_t use_count;
37 drizzled::atomic<uint64_t> auto_increment_value;
38
39 /* the table_identifier is read-only, created in constructor and then never
40 changes.
41 Where we're going, we don't need no stinking mutex. */
42 drizzled::identifier::Table table_identifier;
43};
44
45
46class WiredTigerEngine : public plugin::TransactionalStorageEngine
47{
48public:
49 explicit WiredTigerEngine(string name_arg) :
50 plugin::TransactionalStorageEngine(name_arg,
51 HTON_ALTER_NOT_SUPPORTED |
52 HTON_FAST_KEY_READ |
53 HTON_HAS_RECORDS |
54 HTON_NO_BLOBS |
55 HTON_NULL_IN_KEY |
56 /*HTON_STATS_RECORDS_IS_EXACT |*/
57 HTON_TEMPORARY_NOT_SUPPORTED)
58 {
59 }
60
61 virtual ~WiredTigerEngine()
62 {
63 conn->close(conn, NULL);
64 }
65
66 virtual Cursor *create(Table &table);
67
68 const char **bas_ext() const
69 {
70 return wiredtiger_exts;
71 }
72
73 drizzled::message::Table::Index::IndexType default_index_type() const
74 {
75 return drizzled::message::Table::Index::BTREE;
76 }
77
78 bool validateCreateTableOption(const std::string &key,
79 const std::string &state);
80
81 int doCreateTable(Session &session,
82 Table &table_arg,
83 const identifier::Table &identifier,
84 const message::Table &create_proto);
85
86 int doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to);
87
88 int doDropTable(Session&, const identifier::Table &identifier);
89
90 int doGetTableDefinition(Session& session,
91 const identifier::Table &identifier,
92 message::Table &table_message);
93
94 uint32_t max_supported_keys() const { return MAX_KEY; }
95 uint32_t max_supported_key_part_length() const { return MAX_KEY_LENGTH; }
96
97 uint32_t index_flags(drizzled::message::Table::Index::IndexType) const
98 {
99 errmsg_printf(error::INSPECT, "WiredTigerEngine::index_flags\n");
100 return (HA_READ_NEXT |
101 HA_READ_PREV |
102 HA_READ_ORDER |
103 /*HA_READ_RANGE |*/
104 HA_KEYREAD_ONLY);
105 }
106
107 bool doDoesTableExist(Session& session, const identifier::Table &identifier);
108 void doGetTableIdentifiers(CachedDirectory &directory,
109 const identifier::Schema &schema_identifier,
110 identifier::table::vector &set_of_identifiers);
111
112 virtual int startTransaction(Session *, start_transaction_option_t)
113 {
114 /* The kernel notifies every transactional engine on BEGIN; the base
115 class would register this engine as a transaction resource, making
116 every commit count a WiredTiger commit (doubling Handler_commit)
117 even for transactions that never touch a WiredTiger table.
118 Registration and the WiredTiger-side begin instead happen on first
119 use, via doStartStatement(). */
120 return 0;
121 }
122
123 int doStartTransaction(Session *session, start_transaction_option_t options);
124
125 virtual void doStartStatement(Session *session);
126
127 virtual void doEndStatement(Session *session)
128 {
129 errmsg_printf(error::INSPECT, "WiredTigerEngine::doEndStatement\n");
130 WT_UNUSED(session);
131 }
132
133 int doSetSavepoint(Session *, NamedSavepoint &)
134 {
135 errmsg_printf(error::INSPECT, "WiredTigerEngine::doSetSavepoint\n");
136 return (0);
137 }
138
139 int doRollbackToSavepoint(Session *, NamedSavepoint &)
140 {
141 errmsg_printf(error::INSPECT, "WiredTigerEngine::doRollbackSavepoint\n");
142 return (0);
143 }
144
145 int doReleaseSavepoint(Session *, NamedSavepoint &)
146 {
147 errmsg_printf(error::INSPECT, "WiredTigerEngine::doReleaseSavepoint\n");
148 return (0);
149 }
150
151 int doCommit(Session *, bool /* normal_transaction */);
152
153 int doRollback(Session *, bool /* normal_transaction */);
154
155 void closeConnection(Session &session);
156
157 WT_CONNECTION *conn;
158 WT_SESSION *eng_session; /* for schema operations */
159
160 WiredTigerTableShare *findOpenTable(const identifier::Table &identifier);
161 void addOpenTable(const identifier::Table &, WiredTigerTableShare *);
162 void deleteOpenTable(const identifier::Table &);
163
164 int checkpoint(const std::string &config);
165
166private:
167 int getTableURI(const drizzled::identifier::Table &, string &);
168 int readTableProto(const identifier::Table &, message::Table &);
169 typedef std::map<std::string, WiredTigerTableShare*> WTShareMap;
170 WTShareMap wt_shares;
171};
172
173
174class WiredTigerCursor : public drizzled::Cursor
175{
176 /* number of records changed since last statistics update */
177 uint32_t records_changed;
178 uint32_t key_stat_version;
179 bool internal_table;
180public:
181 WiredTigerCursor(drizzled::plugin::StorageEngine &engine, drizzled::Table &table);
182 ~WiredTigerCursor() {}
183 Cursor *clone(drizzled::memory::Root *mem_root);
184
185 const char *index_type(uint32_t inx);
186
187 /*********************************************************************/
192 double scan_time()
193 {
194 /* Since MySQL seems to favor table scans too much over index
195 searches, we pretend that a sequential read takes the same time
196 as a random disk read, that is, we do not divide the following
197 by 10, which would be physically realistic. */
198 errmsg_printf(error::INSPECT, "WiredTigerCursor::scan_time\n");
199 return (double) (stats.records+stats.deleted) / 20.0+10;
200 }
201
202 /******************************************************************/
206 double read_time(uint32_t, uint32_t,
207 drizzled::ha_rows rows)
208 {
209 errmsg_printf(error::INSPECT, "WiredTigerCursor::read_time\n");
210 return (double) rows / 20.0+1;
211 }
212
213 int doOpen(const drizzled::identifier::Table &identifier, int mode, uint32_t test_if_locked);
214 int close(void);
215 void set_keys_for_scanning(void);
216 int doInsertRecord(unsigned char * buf);
217 int doUpdateRecord(const unsigned char * old_data, unsigned char * new_data);
218 int doDeleteRecord(const unsigned char * buf);
219 virtual void get_auto_increment(uint64_t offset, uint64_t increment,
220 uint64_t nb_desired_values,
221 uint64_t *first_value,
222 uint64_t *nb_reserved_values);
223
224 int index_read(unsigned char *buf,
225 const unsigned char *key_ptr,
226 uint32_t key_len,
227 drizzled::ha_rkey_function find_flag);
228
229 int index_next(unsigned char * buf);
230 int index_prev(unsigned char * buf);
231 int index_first(unsigned char * buf);
232 int index_last(unsigned char * buf);
233 int doStartTableScan(bool scan);
234 int rnd_next(unsigned char *buf);
235 int rnd_pos(unsigned char * buf, unsigned char *pos);
236 void position(const unsigned char *record);
237 int info(uint);
238 int extra(enum drizzled::ha_extra_function operation);
239 int reset();
240 int delete_all_rows(void);
241 int disable_indexes(uint32_t mode);
242 int enable_indexes(uint32_t mode);
243 int indexes_are_disabled(void);
244 int doStartIndexScan(uint32_t idx, bool);
245 int doEndIndexScan();
246
247 drizzled::ha_rows records_in_range(uint32_t inx,
248 drizzled::key_range *min_key,
249 drizzled::key_range *max_key);
250 void drop_table();
251
252 int cmp_ref(const unsigned char *ref1, const unsigned char *ref2);
253 int reset_auto_increment(uint64_t value)
254 {
255 errmsg_printf(error::INSPECT, "WiredTigerCursor::reset_auto_increment\n");
256 WT_UNUSED(value);
257 return 0;
258 }
259
261 THR_LOCK_DATA **store_lock(Session *,THR_LOCK_DATA **, thr_lock_type );
262
263 /* Only ever accessed by WiredTigerStorageEngine. */
264 uint64_t getInitialAutoIncrementValue();
265
266private:
267
268 int wt_pack_from_index_buf(WT_ITEM *kBuf,
269 const drizzled::KeyInfo *key_info,
270 const unsigned char *key_ptr,
271 uint32_t key_len);
272
273 void reopen_cursor_if_needed();
274 int open_table_cursor();
275
276 static int getFieldEncoding(Field *field, char * const type);
277 int packField(Field *, WT_PACK_STREAM *, ptrdiff_t);
278 int packIndex(const char *, WT_ITEM *, key_range *, KeyInfo *);
279 int packRecord(WT_ITEM *, WT_ITEM *, const unsigned char *);
280 int recordPacker(WT_PACK_STREAM *, WT_PACK_STREAM *, unsigned char *,
281 size_t *, size_t *, bool);
282 int unpackRecord(WT_ITEM *, WT_ITEM *, unsigned char *);
283 int unpackField(Field *, WT_PACK_STREAM *, ptrdiff_t);
284
285 int setupKeyFields(uint32_t, bool);
286 int setupTableURI(const drizzled::identifier::Table &);
287 void update_key_stats();
288 WT_SESSION *wt_session;
289 WT_CURSOR *wt_cursor;
290 // Buffers for temporary packing and unpacking.
291 WT_ITEM key_buf;
292 WT_ITEM value_buf;
293 WT_ITEM null_buf;
294 // Cached information about which fields form the key
295 std::vector<int32_t> *key_fields;
296 std::vector<int32_t> *index_key_fields;
297 std::vector<int32_t> *index_value_fields;
298 string table_uri;
300
302 int free_share();
303// Drizzle defines values up to 32 for this flag, use higher ranges for some
304// WiredTiger specific flags.
305#define WT_WRITE_CAN_REPLACE 0x10000
306 uint32_t opt_flag; /* Flags defined in drizzled/base.h, set by extra API */
307
308};
309
310WT_SESSION *get_wt_session(Session &session);
THR_LOCK_DATA ** store_lock(Session *, THR_LOCK_DATA **, thr_lock_type)
double read_time(uint32_t, uint32_t, drizzled::ha_rows rows)
int reset_auto_increment(uint64_t value)
drizzled::ha_rows records_in_range(uint32_t inx, drizzled::key_range *min_key, drizzled::key_range *max_key)
int doStartIndexScan(uint32_t idx, bool)
int doStartTableScan(bool scan)
static INNOBASE_SHARE * get_share(const char *table_name)
Convert from decimal to binary representation.
Definition common_fwd.h:215
TODO: Rename this file - func.h is stupid.
STL namespace.