1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
1 |
/*
|
2 |
Copyright (C) 2010 Stewart Smith
|
|
3 |
||
4 |
This program is free software; you can redistribute it and/or
|
|
5 |
modify it under the terms of the GNU General Public License
|
|
6 |
as published by the Free Software Foundation; either version 2
|
|
7 |
of the License, or (at your option) any later version.
|
|
8 |
||
9 |
This program is distributed in the hope that it will be useful,
|
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
GNU General Public License for more details.
|
|
13 |
||
14 |
You should have received a copy of the GNU General Public License
|
|
15 |
along with this program; if not, write to the Free Software
|
|
16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17 |
*/
|
|
18 |
||
19 |
#include "config.h" |
|
20 |
#include <drizzled/table.h> |
|
21 |
#include <drizzled/error.h> |
|
22 |
#include "drizzled/internal/my_pthread.h" |
|
23 |
||
24 |
#include "tableprototester.h" |
|
25 |
||
26 |
#include <fcntl.h> |
|
27 |
||
28 |
#include <string> |
|
29 |
#include <map> |
|
30 |
#include <fstream> |
|
31 |
#include <drizzled/message/table.pb.h> |
|
32 |
#include "drizzled/internal/m_string.h" |
|
33 |
||
34 |
#include "drizzled/global_charset_info.h" |
|
35 |
||
36 |
||
37 |
using namespace std; |
|
38 |
using namespace google; |
|
1273.2.35
by Stewart Smith
add t1 test (missing engine) to TableProtoTester. Fix up proper error reporting. |
39 |
using namespace drizzled; |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
40 |
|
41 |
#define TABLEPROTOTESTER_EXT ".TBT"
|
|
42 |
||
43 |
static const char *TableProtoTesterCursor_exts[] = { |
|
44 |
NULL
|
|
45 |
};
|
|
46 |
||
47 |
class TableProtoTesterEngine : public drizzled::plugin::StorageEngine |
|
48 |
{
|
|
49 |
public: |
|
50 |
TableProtoTesterEngine(const string &name_arg) |
|
51 |
: drizzled::plugin::StorageEngine(name_arg, |
|
52 |
HTON_NULL_IN_KEY | |
|
53 |
HTON_CAN_INDEX_BLOBS | |
|
54 |
HTON_SKIP_STORE_LOCK | |
|
1414
by Brian Aker
Remove dead type. |
55 |
HTON_AUTO_PART_KEY) |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
56 |
{
|
57 |
table_definition_ext= TABLEPROTOTESTER_EXT; |
|
58 |
}
|
|
59 |
||
60 |
virtual Cursor *create(TableShare &table, |
|
61 |
drizzled::memory::Root *mem_root) |
|
62 |
{
|
|
63 |
return new (mem_root) TableProtoTesterCursor(*this, table); |
|
64 |
}
|
|
65 |
||
66 |
const char **bas_ext() const { |
|
67 |
return TableProtoTesterCursor_exts; |
|
68 |
}
|
|
69 |
||
1413
by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference. |
70 |
int doCreateTable(Session&, |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
71 |
Table&, |
1358.1.2
by Brian Aker
Long pass through the system to use more of TableIdentifiers. |
72 |
drizzled::TableIdentifier &identifier, |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
73 |
drizzled::message::Table&); |
74 |
||
1358.1.3
by Brian Aker
doDropTable() now only uses identifier. |
75 |
int doDropTable(Session&, drizzled::TableIdentifier &identifier); |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
76 |
|
1413
by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference. |
77 |
int doGetTableDefinition(Session &session, |
1358.1.2
by Brian Aker
Long pass through the system to use more of TableIdentifiers. |
78 |
drizzled::TableIdentifier &identifier, |
1354.1.1
by Brian Aker
Modify ptr to reference. |
79 |
drizzled::message::Table &table_proto); |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
80 |
|
81 |
void doGetTableNames(drizzled::CachedDirectory &directory, |
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
82 |
SchemaIdentifier &, |
83 |
set<string>& set_of_names) |
|
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
84 |
{
|
85 |
(void)directory; |
|
1273.2.35
by Stewart Smith
add t1 test (missing engine) to TableProtoTester. Fix up proper error reporting. |
86 |
set_of_names.insert("t1"); |
87 |
||
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
88 |
}
|
89 |
||
90 |
/* The following defines can be increased if necessary */
|
|
91 |
uint32_t max_supported_keys() const { return 64; } |
|
92 |
uint32_t max_supported_key_length() const { return 1000; } |
|
93 |
uint32_t max_supported_key_part_length() const { return 1000; } |
|
94 |
||
95 |
uint32_t index_flags(enum ha_key_alg) const |
|
96 |
{
|
|
97 |
return (HA_READ_NEXT | |
|
98 |
HA_READ_PREV | |
|
99 |
HA_READ_RANGE | |
|
100 |
HA_READ_ORDER | |
|
101 |
HA_KEYREAD_ONLY); |
|
102 |
}
|
|
103 |
||
1413
by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference. |
104 |
bool doDoesTableExist(Session &session, TableIdentifier &identifier); |
1389
by Brian Aker
Large reord in ALTER TABLE for RENAME. |
105 |
|
1413
by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference. |
106 |
int doRenameTable(Session&, TableIdentifier&, TableIdentifier&) |
1389
by Brian Aker
Large reord in ALTER TABLE for RENAME. |
107 |
{
|
108 |
return EPERM; |
|
109 |
}
|
|
1429.1.3
by Brian Aker
Merge in work for fetching a list of table identifiers. |
110 |
|
111 |
void doGetTableIdentifiers(drizzled::CachedDirectory &directory, |
|
112 |
drizzled::SchemaIdentifier &schema_identifier, |
|
113 |
drizzled::TableIdentifiers &set_of_identifiers); |
|
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
114 |
};
|
115 |
||
1429.1.3
by Brian Aker
Merge in work for fetching a list of table identifiers. |
116 |
void TableProtoTesterEngine::doGetTableIdentifiers(drizzled::CachedDirectory&, |
117 |
drizzled::SchemaIdentifier &schema_identifier, |
|
118 |
drizzled::TableIdentifiers &set_of_identifiers) |
|
119 |
{
|
|
1579.3.6
by Stewart Smith
add a too_many_enum_options table to tableprototester. It seems as if we don't get a corruption warning/error if an engine presents a table with > 2^16 enum options (anything over 2^16 is not representable in 2 bytes of storage, so is invalid). |
120 |
if (schema_identifier.compare("test")) |
121 |
{
|
|
122 |
set_of_identifiers.push_back(TableIdentifier(schema_identifier, "t1")); |
|
123 |
set_of_identifiers.push_back(TableIdentifier(schema_identifier, "too_many_enum_values")); |
|
124 |
}
|
|
1429.1.3
by Brian Aker
Merge in work for fetching a list of table identifiers. |
125 |
}
|
1358.1.1
by Brian Aker
Fixes regression in performance from Exists patch. |
126 |
|
127 |
bool TableProtoTesterEngine::doDoesTableExist(Session&, TableIdentifier &identifier) |
|
128 |
{
|
|
1358.1.9
by Brian Aker
Update for std::string |
129 |
if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0) |
1358.1.1
by Brian Aker
Fixes regression in performance from Exists patch. |
130 |
return true; |
1579.3.6
by Stewart Smith
add a too_many_enum_options table to tableprototester. It seems as if we don't get a corruption warning/error if an engine presents a table with > 2^16 enum options (anything over 2^16 is not representable in 2 bytes of storage, so is invalid). |
131 |
if (strcmp(identifier.getPath().c_str(), "./test/too_many_enum_values") == 0) |
132 |
return true; |
|
1358.1.1
by Brian Aker
Fixes regression in performance from Exists patch. |
133 |
|
134 |
return false; |
|
135 |
}
|
|
136 |
||
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
137 |
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg, |
1358.1.1
by Brian Aker
Fixes regression in performance from Exists patch. |
138 |
TableShare &table_arg) : |
139 |
Cursor(engine_arg, table_arg) |
|
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
140 |
{ } |
141 |
||
142 |
int TableProtoTesterCursor::open(const char *, int, uint32_t) |
|
143 |
{
|
|
1358.1.1
by Brian Aker
Fixes regression in performance from Exists patch. |
144 |
return 0; |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
145 |
}
|
146 |
||
147 |
int TableProtoTesterCursor::close(void) |
|
148 |
{
|
|
149 |
return 0; |
|
150 |
}
|
|
151 |
||
1413
by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference. |
152 |
int TableProtoTesterEngine::doCreateTable(Session&, |
1358.1.1
by Brian Aker
Fixes regression in performance from Exists patch. |
153 |
Table&, |
1413
by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference. |
154 |
drizzled::TableIdentifier&, |
1358.1.1
by Brian Aker
Fixes regression in performance from Exists patch. |
155 |
drizzled::message::Table&) |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
156 |
{
|
157 |
return EEXIST; |
|
158 |
}
|
|
159 |
||
160 |
||
1358.1.3
by Brian Aker
doDropTable() now only uses identifier. |
161 |
int TableProtoTesterEngine::doDropTable(Session&, drizzled::TableIdentifier&) |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
162 |
{
|
163 |
return EPERM; |
|
164 |
}
|
|
165 |
||
1354.1.1
by Brian Aker
Modify ptr to reference. |
166 |
static void fill_table1(message::Table &table) |
1273.2.35
by Stewart Smith
add t1 test (missing engine) to TableProtoTester. Fix up proper error reporting. |
167 |
{
|
168 |
message::Table::Field *field; |
|
169 |
message::Table::TableOptions *tableopts; |
|
170 |
||
1354.1.1
by Brian Aker
Modify ptr to reference. |
171 |
table.set_name("t1"); |
172 |
table.set_type(message::Table::INTERNAL); |
|
1273.2.35
by Stewart Smith
add t1 test (missing engine) to TableProtoTester. Fix up proper error reporting. |
173 |
|
1354.1.1
by Brian Aker
Modify ptr to reference. |
174 |
tableopts= table.mutable_options(); |
1273.2.35
by Stewart Smith
add t1 test (missing engine) to TableProtoTester. Fix up proper error reporting. |
175 |
tableopts->set_comment("Table without a StorageEngine message"); |
176 |
||
177 |
{
|
|
1354.1.1
by Brian Aker
Modify ptr to reference. |
178 |
field= table.add_field(); |
1273.2.35
by Stewart Smith
add t1 test (missing engine) to TableProtoTester. Fix up proper error reporting. |
179 |
field->set_name("number"); |
180 |
field->set_type(message::Table::Field::INTEGER); |
|
181 |
}
|
|
182 |
||
183 |
}
|
|
1579.3.6
by Stewart Smith
add a too_many_enum_options table to tableprototester. It seems as if we don't get a corruption warning/error if an engine presents a table with > 2^16 enum options (anything over 2^16 is not representable in 2 bytes of storage, so is invalid). |
184 |
|
185 |
static void fill_table_too_many_enum_values(message::Table &table) |
|
186 |
{
|
|
187 |
message::Table::Field *field; |
|
188 |
message::Table::TableOptions *tableopts; |
|
189 |
||
190 |
table.set_schema("test"); |
|
191 |
table.set_name("too_many_enum_values"); |
|
192 |
table.set_type(message::Table::STANDARD); |
|
193 |
table.mutable_engine()->set_name("tableprototester"); |
|
194 |
table.set_creation_timestamp(0); |
|
195 |
table.set_update_timestamp(0); |
|
196 |
||
197 |
||
198 |
tableopts= table.mutable_options(); |
|
199 |
tableopts->set_comment("Table with too many enum options"); |
|
200 |
||
201 |
{
|
|
202 |
field= table.add_field(); |
|
203 |
field->set_name("many_values"); |
|
204 |
field->set_type(message::Table::Field::ENUM); |
|
205 |
||
206 |
message::Table::Field::EnumerationValues *field_options= field->mutable_enumeration_values(); |
|
207 |
for(int i=0; i<70000; i++) |
|
208 |
{
|
|
209 |
char enum_value[100]; |
|
210 |
snprintf(enum_value, sizeof(enum_value), "a%d", i); |
|
211 |
field_options->add_field_value(enum_value); |
|
212 |
}
|
|
213 |
}
|
|
214 |
||
215 |
}
|
|
216 |
||
217 |
||
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
218 |
int TableProtoTesterEngine::doGetTableDefinition(Session&, |
1358.1.7
by Brian Aker
Remove interface bits around caller for internal lookup of create table. |
219 |
drizzled::TableIdentifier &identifier, |
1358.1.3
by Brian Aker
doDropTable() now only uses identifier. |
220 |
drizzled::message::Table &table_proto) |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
221 |
{
|
1358.1.9
by Brian Aker
Update for std::string |
222 |
if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0) |
1273.2.35
by Stewart Smith
add t1 test (missing engine) to TableProtoTester. Fix up proper error reporting. |
223 |
{
|
1354.1.1
by Brian Aker
Modify ptr to reference. |
224 |
fill_table1(table_proto); |
1273.2.35
by Stewart Smith
add t1 test (missing engine) to TableProtoTester. Fix up proper error reporting. |
225 |
return EEXIST; |
226 |
}
|
|
1579.3.6
by Stewart Smith
add a too_many_enum_options table to tableprototester. It seems as if we don't get a corruption warning/error if an engine presents a table with > 2^16 enum options (anything over 2^16 is not representable in 2 bytes of storage, so is invalid). |
227 |
else if (strcmp(identifier.getPath().c_str(), "./test/too_many_enum_values")==0) |
228 |
{
|
|
229 |
fill_table_too_many_enum_values(table_proto); |
|
230 |
return EEXIST; |
|
231 |
}
|
|
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
232 |
return ENOENT; |
233 |
}
|
|
234 |
||
235 |
const char *TableProtoTesterCursor::index_type(uint32_t) |
|
236 |
{
|
|
237 |
return("BTREE"); |
|
238 |
}
|
|
239 |
||
1491.1.10
by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan |
240 |
int TableProtoTesterCursor::doInsertRecord(unsigned char *) |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
241 |
{
|
242 |
return(table->next_number_field ? update_auto_increment() : 0); |
|
243 |
}
|
|
244 |
||
1491.1.10
by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan |
245 |
int TableProtoTesterCursor::doStartTableScan(bool) |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
246 |
{
|
247 |
return(0); |
|
248 |
}
|
|
249 |
||
250 |
||
251 |
int TableProtoTesterCursor::rnd_next(unsigned char *) |
|
252 |
{
|
|
253 |
return(HA_ERR_END_OF_FILE); |
|
254 |
}
|
|
255 |
||
256 |
||
257 |
int TableProtoTesterCursor::rnd_pos(unsigned char *, unsigned char *) |
|
258 |
{
|
|
259 |
assert(0); |
|
260 |
return(0); |
|
261 |
}
|
|
262 |
||
263 |
||
264 |
void TableProtoTesterCursor::position(const unsigned char *) |
|
265 |
{
|
|
266 |
assert(0); |
|
267 |
return; |
|
268 |
}
|
|
269 |
||
270 |
||
271 |
int TableProtoTesterCursor::info(uint32_t flag) |
|
272 |
{
|
|
273 |
memset(&stats, 0, sizeof(stats)); |
|
274 |
if (flag & HA_STATUS_AUTO) |
|
275 |
stats.auto_increment_value= 1; |
|
276 |
return(0); |
|
277 |
}
|
|
278 |
||
279 |
||
280 |
int TableProtoTesterCursor::index_read_map(unsigned char *, const unsigned char *, |
|
281 |
key_part_map, enum ha_rkey_function) |
|
282 |
{
|
|
283 |
return(HA_ERR_END_OF_FILE); |
|
284 |
}
|
|
285 |
||
286 |
||
287 |
int TableProtoTesterCursor::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *, |
|
288 |
key_part_map, enum ha_rkey_function) |
|
289 |
{
|
|
290 |
return(HA_ERR_END_OF_FILE); |
|
291 |
}
|
|
292 |
||
293 |
||
294 |
int TableProtoTesterCursor::index_read_last_map(unsigned char *, const unsigned char *, key_part_map) |
|
295 |
{
|
|
296 |
return(HA_ERR_END_OF_FILE); |
|
297 |
}
|
|
298 |
||
299 |
||
300 |
int TableProtoTesterCursor::index_next(unsigned char *) |
|
301 |
{
|
|
302 |
return(HA_ERR_END_OF_FILE); |
|
303 |
}
|
|
304 |
||
305 |
||
306 |
int TableProtoTesterCursor::index_prev(unsigned char *) |
|
307 |
{
|
|
308 |
return(HA_ERR_END_OF_FILE); |
|
309 |
}
|
|
310 |
||
311 |
||
312 |
int TableProtoTesterCursor::index_first(unsigned char *) |
|
313 |
{
|
|
314 |
return(HA_ERR_END_OF_FILE); |
|
315 |
}
|
|
316 |
||
317 |
||
318 |
int TableProtoTesterCursor::index_last(unsigned char *) |
|
319 |
{
|
|
320 |
return(HA_ERR_END_OF_FILE); |
|
321 |
}
|
|
322 |
||
323 |
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL; |
|
324 |
||
1530.2.6
by Monty Taylor
Moved plugin::Context to module::Context. |
325 |
static int tableprototester_init(drizzled::module::Context &context) |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
326 |
{
|
327 |
||
328 |
tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER"); |
|
1324.2.2
by Monty Taylor
Use the plugin::Context everywhere. |
329 |
context.add(tableprototester_engine); |
1273.2.34
by Stewart Smith
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :( |
330 |
|
331 |
return 0; |
|
332 |
}
|
|
333 |
||
334 |
DRIZZLE_DECLARE_PLUGIN
|
|
335 |
{
|
|
336 |
DRIZZLE_VERSION_ID, |
|
337 |
"TABLEPROTOTESTER", |
|
338 |
"1.0", |
|
339 |
"Stewart Smith", |
|
340 |
"Used to test rest of server with various table proto messages", |
|
341 |
PLUGIN_LICENSE_GPL, |
|
342 |
tableprototester_init, /* Plugin Init */ |
|
343 |
NULL, /* system variables */ |
|
344 |
NULL /* config options */ |
|
345 |
}
|
|
346 |
DRIZZLE_DECLARE_PLUGIN_END; |