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;
23
using namespace drizzled;
38
27
First, if you want to understand storage engines you should look at
105
94
/* Variables for archive share methods */
106
95
pthread_mutex_t archive_mutex= PTHREAD_MUTEX_INITIALIZER;
108
static unsigned int global_version;
110
/* The file extension */
111
#define ARZ ".arz" // The data file
112
#define ARN ".ARN" // Files used during an optimize call
116
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);
119
104
Number of rows that will force a bulk insert.
126
111
#define ARCHIVE_ROW_HEADER_SIZE 4
129
We just implement one additional file extension.
131
static const char *ha_archive_exts[] = {
136
class ArchiveEngine : public drizzled::plugin::StorageEngine
138
typedef std::map<string, ArchiveShare*> ArchiveMap;
139
ArchiveMap archive_open_tables;
142
ArchiveEngine(const string &name_arg)
143
: drizzled::plugin::StorageEngine(name_arg,
145
HTON_STATS_RECORDS_IS_EXACT |
147
HTON_HAS_DATA_DICTIONARY),
148
archive_open_tables()
150
table_definition_ext= ARZ;
153
virtual Cursor *create(TableShare &table,
154
drizzled::memory::Root *mem_root)
156
return new (mem_root) ha_archive(*this, table);
159
const char **bas_ext() const {
160
return ha_archive_exts;
163
int doCreateTable(Session *session, const char *table_name,
165
drizzled::message::Table& proto);
167
int doGetTableDefinition(Session& session,
170
const char *table_name,
172
drizzled::message::Table *table_proto);
174
void doGetTableNames(drizzled::CachedDirectory &directory, string& , set<string>& set_of_names);
176
int doDropTable(Session&, const string table_path);
177
ArchiveShare *findOpenTable(const string table_name);
178
void addOpenTable(const string &table_name, ArchiveShare *);
179
void deleteOpenTable(const string &table_name);
181
uint32_t max_supported_keys() const { return 1; }
182
uint32_t max_supported_key_length() const { return sizeof(uint64_t); }
183
uint32_t max_supported_key_part_length() const { return sizeof(uint64_t); }
185
uint32_t index_flags(enum ha_key_alg) const
187
return HA_ONLY_WHOLE_INDEX;
191
113
ArchiveShare *ArchiveEngine::findOpenTable(const string table_name)
193
115
ArchiveMap::iterator find_iter=
310
static ArchiveEngine *archive_engine= NULL;
313
Initialize the archive Cursor.
324
static int archive_db_init(drizzled::plugin::Registry ®istry)
327
pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST);
328
archive_engine= new ArchiveEngine("ARCHIVE");
329
registry.add(archive_engine);
331
/* When the engine starts up set the first version */
338
Release the archive Cursor.
348
static int archive_db_done(drizzled::plugin::Registry ®istry)
350
registry.remove(archive_engine);
351
delete archive_engine;
353
pthread_mutex_destroy(&archive_mutex);
359
233
ha_archive::ha_archive(drizzled::plugin::StorageEngine &engine_arg,
360
234
TableShare &table_arg)
364
238
buffer.set((char *)byte_buffer, IO_SIZE, system_charset_info);
366
240
/* The size of the offset value we will use for position() */
367
ref_length= sizeof(my_off_t);
241
ref_length= sizeof(internal::my_off_t);
368
242
archive_reader_open= false;
396
270
memset(&archive_write, 0, sizeof(azio_stream)); /* Archive file we are working with */
397
271
table_name.append(name);
398
fn_format(data_file_name, table_name.c_str(), "",
272
internal::fn_format(data_file_name, table_name.c_str(), "",
399
273
ARZ, MY_REPLACE_EXT | MY_UNPACK_FILENAME);
401
275
We will use this lock for rows.
692
566
We reuse name_buff since it is available.
694
fn_format(name_buff, table_name, "", ARZ,
568
internal::fn_format(name_buff, table_name, "", ARZ,
695
569
MY_REPLACE_EXT | MY_UNPACK_FILENAME);
1085
959
void ha_archive::position(const unsigned char *)
1087
my_store_ptr(ref, ref_length, current_position);
961
internal::my_store_ptr(ref, ref_length, current_position);
1099
973
int ha_archive::rnd_pos(unsigned char * buf, unsigned char *pos)
1101
975
ha_statistic_increment(&SSV::ha_read_rnd_next_count);
1102
current_position= (my_off_t)my_get_ptr(pos, ref_length);
976
current_position= (internal::my_off_t)internal::my_get_ptr(pos, ref_length);
1103
977
if (azseek(&archive, (size_t)current_position, SEEK_SET) == (size_t)(-1L))
1104
978
return(HA_ERR_CRASHED_ON_USAGE);
1105
979
return(get_row(&archive, buf));
1149
1023
azread_frm(&archive, proto_string);
1151
1025
/* Lets create a file to contain the new data */
1152
fn_format(writer_filename, share->table_name.c_str(), "", ARN,
1026
internal::fn_format(writer_filename, share->table_name.c_str(), "", ARN,
1153
1027
MY_REPLACE_EXT | MY_UNPACK_FILENAME);
1155
1029
if (!(azopen(&writer, writer_filename, O_CREAT|O_RDWR, AZ_METHOD_BLOCK)))
1232
1106
azclose(&archive);
1234
1108
// make the file we just wrote be our data file
1235
rc = my_rename(writer_filename,share->data_file_name,MYF(0));
1109
rc = internal::my_rename(writer_filename,share->data_file_name,MYF(0));
1237
1111
free(proto_string);
1451
1325
free((char*) r);
1455
static DRIZZLE_SYSVAR_BOOL(aio, archive_use_aio,
1456
PLUGIN_VAR_NOCMDOPT,
1457
"Whether or not to use asynchronous IO.",
1460
static drizzle_sys_var* archive_system_variables[]= {
1461
DRIZZLE_SYSVAR(aio),
1465
DRIZZLE_DECLARE_PLUGIN
1470
"Brian Aker, MySQL AB",
1471
"Archive storage engine",
1473
archive_db_init, /* Plugin Init */
1474
archive_db_done, /* Plugin Deinit */
1475
NULL, /* status variables */
1476
archive_system_variables, /* system variables */
1477
NULL /* config options */
1479
DRIZZLE_DECLARE_PLUGIN_END;