~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/ha_archive.cc

  • Committer: Brian Aker
  • Date: 2010-02-10 18:04:24 UTC
  • mfrom: (1286.1.5 build)
  • Revision ID: brian@gaz-20100210180424-03ypoyifmlc2lgcp
Merge of Brian/Padraig

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 2003 MySQL AB
 
2
   Copyright (C) 2010 Brian Aker
2
3
 
3
4
  This program is free software; you can redistribute it and/or modify
4
5
  it under the terms of the GNU General Public License as published by
15
16
 
16
17
 
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"
24
 
 
25
 
#include "ha_archive.h"
26
 
 
27
 
#include <unistd.h>
28
 
#include <fcntl.h>
29
 
#include <sys/stat.h>
30
 
 
31
 
#include <cstdio>
32
 
#include <string>
33
 
#include <map>
 
19
 
 
20
#include "plugin/archive/archive_engine.h"
34
21
 
35
22
using namespace std;
36
23
using namespace drizzled;
37
24
 
 
25
 
38
26
/*
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;
108
96
 
109
 
static unsigned int global_version;
110
 
 
111
 
/* The file extension */
112
 
#define ARZ ".arz"               // The data file
113
 
#define ARN ".ARN"               // Files used during an optimize call
114
 
 
115
 
 
116
 
 
117
 
static bool archive_use_aio= false;
 
97
/* When the engine starts up set the first version */
 
98
static uint64_t global_version= 1;
 
99
 
 
100
// We use this to find out the state of the archive aio option.
 
101
extern bool archive_aio_state(void);
118
102
 
119
103
/*
120
104
  Number of rows that will force a bulk insert.
126
110
*/
127
111
#define ARCHIVE_ROW_HEADER_SIZE 4
128
112
 
129
 
/*
130
 
  We just implement one additional file extension.
131
 
*/
132
 
static const char *ha_archive_exts[] = {
133
 
  ARZ,
134
 
  NULL
135
 
};
136
 
 
137
 
class ArchiveEngine : public drizzled::plugin::StorageEngine
138
 
{
139
 
  typedef std::map<string, ArchiveShare*> ArchiveMap;
140
 
  ArchiveMap archive_open_tables;
141
 
 
142
 
public:
143
 
  ArchiveEngine(const string &name_arg)
144
 
   : drizzled::plugin::StorageEngine(name_arg,
145
 
                                     HTON_FILE_BASED |
146
 
                                     HTON_STATS_RECORDS_IS_EXACT |
147
 
                                     HTON_HAS_RECORDS |
148
 
                                     HTON_HAS_DATA_DICTIONARY),
149
 
     archive_open_tables()
150
 
  {
151
 
    table_definition_ext= ARZ;
152
 
  }
153
 
 
154
 
  virtual Cursor *create(TableShare &table,
155
 
                         drizzled::memory::Root *mem_root)
156
 
  {
157
 
    return new (mem_root) ha_archive(*this, table);
158
 
  }
159
 
 
160
 
  const char **bas_ext() const {
161
 
    return ha_archive_exts;
162
 
  }
163
 
 
164
 
  int doCreateTable(Session *session, const char *table_name,
165
 
                    Table& table_arg,
166
 
                    drizzled::message::Table& proto);
167
 
 
168
 
  int doGetTableDefinition(Session& session,
169
 
                           const char* path,
170
 
                           const char *db,
171
 
                           const char *table_name,
172
 
                           const bool is_tmp,
173
 
                           drizzled::message::Table *table_proto);
174
 
 
175
 
  void doGetTableNames(drizzled::CachedDirectory &directory, string& , set<string>& set_of_names);
176
 
 
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);
181
 
 
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); }
185
 
 
186
 
  uint32_t index_flags(enum  ha_key_alg) const
187
 
  {
188
 
    return HA_ONLY_WHOLE_INDEX;
189
 
  }
190
 
};
191
 
 
192
113
ArchiveShare *ArchiveEngine::findOpenTable(const string table_name)
193
114
{
194
115
  ArchiveMap::iterator find_iter=
308
229
  return error;
309
230
}
310
231
 
311
 
static ArchiveEngine *archive_engine= NULL;
312
 
 
313
 
/*
314
 
  Initialize the archive Cursor.
315
 
 
316
 
  SYNOPSIS
317
 
    archive_db_init()
318
 
    void *
319
 
 
320
 
  RETURN
321
 
    false       OK
322
 
    true        Error
323
 
*/
324
 
 
325
 
static int archive_db_init(drizzled::plugin::Registry &registry)
326
 
{
327
 
 
328
 
  pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST);
329
 
  archive_engine= new ArchiveEngine("ARCHIVE");
330
 
  registry.add(archive_engine);
331
 
 
332
 
  /* When the engine starts up set the first version */
333
 
  global_version= 1;
334
 
 
335
 
  return false;
336
 
}
337
 
 
338
 
/*
339
 
  Release the archive Cursor.
340
 
 
341
 
  SYNOPSIS
342
 
    archive_db_done()
343
 
    void
344
 
 
345
 
  RETURN
346
 
    false       OK
347
 
*/
348
 
 
349
 
static int archive_db_done(drizzled::plugin::Registry &registry)
350
 
{
351
 
  registry.remove(archive_engine);
352
 
  delete archive_engine;
353
 
 
354
 
  pthread_mutex_destroy(&archive_mutex);
355
 
 
356
 
  return 0;
357
 
}
358
 
 
359
232
 
360
233
ha_archive::ha_archive(drizzled::plugin::StorageEngine &engine_arg,
361
234
                       TableShare &table_arg)
545
418
  {
546
419
    az_method method;
547
420
 
548
 
    switch (archive_use_aio)
 
421
    switch (archive_aio_state())
549
422
    {
550
423
    case false:
551
424
      method= AZ_METHOD_BLOCK;
1452
1325
  free((char*) r);
1453
1326
  return;
1454
1327
}
1455
 
 
1456
 
static DRIZZLE_SYSVAR_BOOL(aio, archive_use_aio,
1457
 
  PLUGIN_VAR_NOCMDOPT,
1458
 
  "Whether or not to use asynchronous IO.",
1459
 
  NULL, NULL, true);
1460
 
 
1461
 
static drizzle_sys_var* archive_system_variables[]= {
1462
 
  DRIZZLE_SYSVAR(aio),
1463
 
  NULL
1464
 
};
1465
 
 
1466
 
DRIZZLE_DECLARE_PLUGIN
1467
 
{
1468
 
  DRIZZLE_VERSION_ID,
1469
 
  "ARCHIVE",
1470
 
  "3.5",
1471
 
  "Brian Aker, MySQL AB",
1472
 
  "Archive storage engine",
1473
 
  PLUGIN_LICENSE_GPL,
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                  */
1479
 
}
1480
 
DRIZZLE_DECLARE_PLUGIN_END;
1481