17
18
#include "config.h"
18
#include "drizzled/field.h"
19
#include "drizzled/field/blob.h"
20
#include "drizzled/field/timestamp.h"
21
#include "plugin/myisam/myisam.h"
22
#include "drizzled/table.h"
23
#include "drizzled/session.h"
25
#include "ha_archive.h"
20
#include "plugin/archive/archive_engine.h"
35
22
using namespace std;
36
23
using namespace drizzled;
39
27
First, if you want to understand storage engines you should look at
40
28
ha_example.cc and ha_example.h.
106
94
/* Variables for archive share methods */
107
95
pthread_mutex_t archive_mutex= PTHREAD_MUTEX_INITIALIZER;
109
static unsigned int global_version;
111
/* The file extension */
112
#define ARZ ".arz" // The data file
113
#define ARN ".ARN" // Files used during an optimize call
117
static bool archive_use_aio= false;
97
/* When the engine starts up set the first version */
98
static uint64_t global_version= 1;
100
// We use this to find out the state of the archive aio option.
101
extern bool archive_aio_state(void);
120
104
Number of rows that will force a bulk insert.
127
111
#define ARCHIVE_ROW_HEADER_SIZE 4
130
We just implement one additional file extension.
132
static const char *ha_archive_exts[] = {
137
class ArchiveEngine : public drizzled::plugin::StorageEngine
139
typedef std::map<string, ArchiveShare*> ArchiveMap;
140
ArchiveMap archive_open_tables;
143
ArchiveEngine(const string &name_arg)
144
: drizzled::plugin::StorageEngine(name_arg,
146
HTON_STATS_RECORDS_IS_EXACT |
148
HTON_HAS_DATA_DICTIONARY),
149
archive_open_tables()
151
table_definition_ext= ARZ;
154
virtual Cursor *create(TableShare &table,
155
drizzled::memory::Root *mem_root)
157
return new (mem_root) ha_archive(*this, table);
160
const char **bas_ext() const {
161
return ha_archive_exts;
164
int doCreateTable(Session *session, const char *table_name,
166
drizzled::message::Table& proto);
168
int doGetTableDefinition(Session& session,
171
const char *table_name,
173
drizzled::message::Table *table_proto);
175
void doGetTableNames(drizzled::CachedDirectory &directory, string& , set<string>& set_of_names);
177
int doDropTable(Session&, const string table_path);
178
ArchiveShare *findOpenTable(const string table_name);
179
void addOpenTable(const string &table_name, ArchiveShare *);
180
void deleteOpenTable(const string &table_name);
182
uint32_t max_supported_keys() const { return 1; }
183
uint32_t max_supported_key_length() const { return sizeof(uint64_t); }
184
uint32_t max_supported_key_part_length() const { return sizeof(uint64_t); }
186
uint32_t index_flags(enum ha_key_alg) const
188
return HA_ONLY_WHOLE_INDEX;
192
113
ArchiveShare *ArchiveEngine::findOpenTable(const string table_name)
194
115
ArchiveMap::iterator find_iter=
311
static ArchiveEngine *archive_engine= NULL;
314
Initialize the archive Cursor.
325
static int archive_db_init(drizzled::plugin::Registry ®istry)
328
pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST);
329
archive_engine= new ArchiveEngine("ARCHIVE");
330
registry.add(archive_engine);
332
/* When the engine starts up set the first version */
339
Release the archive Cursor.
349
static int archive_db_done(drizzled::plugin::Registry ®istry)
351
registry.remove(archive_engine);
352
delete archive_engine;
354
pthread_mutex_destroy(&archive_mutex);
360
233
ha_archive::ha_archive(drizzled::plugin::StorageEngine &engine_arg,
361
234
TableShare &table_arg)
1452
1325
free((char*) r);
1456
static DRIZZLE_SYSVAR_BOOL(aio, archive_use_aio,
1457
PLUGIN_VAR_NOCMDOPT,
1458
"Whether or not to use asynchronous IO.",
1461
static drizzle_sys_var* archive_system_variables[]= {
1462
DRIZZLE_SYSVAR(aio),
1466
DRIZZLE_DECLARE_PLUGIN
1471
"Brian Aker, MySQL AB",
1472
"Archive storage engine",
1474
archive_db_init, /* Plugin Init */
1475
archive_db_done, /* Plugin Deinit */
1476
NULL, /* status variables */
1477
archive_system_variables, /* system variables */
1478
NULL /* config options */
1480
DRIZZLE_DECLARE_PLUGIN_END;