~drizzle-trunk/drizzle/development

1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
1
/* Copyright (C) 2003 MySQL AB
2
   Copyright (C) 2010 Brian Aker
3
4
  This program is free software; you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation; version 2 of the License.
7
8
  This program is distributed in the hope that it will be useful,
9
  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
  GNU General Public License for more details.
12
13
  You should have received a copy of the GNU General Public License
14
  along with this program; if not, write to the Free Software
15
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
16
17
#include "drizzled/field.h"
18
#include "drizzled/field/blob.h"
19
#include "drizzled/field/timestamp.h"
20
#include "plugin/myisam/myisam.h"
21
#include "drizzled/table.h"
22
#include "drizzled/session.h"
23
#include <drizzled/thr_lock.h>
24
#include <drizzled/my_hash.h>
25
#include <drizzled/cursor.h>
26
27
#include <fcntl.h>
28
#include <inttypes.h>
29
#include <string>
30
#include <sys/stat.h>
31
#include <unistd.h>
32
#include <zlib.h>
33
1685.2.8 by Brian Aker
Fix possible issue with case.
34
#include <boost/unordered_map.hpp>
35
#include "drizzled/util/string.h"
36
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
37
#include "azio.h"
38
#include "plugin/archive/ha_archive.h"
39
40
41
42
#include <cstdio>
43
#include <string>
44
#include <map>
45
46
#ifndef PLUGIN_ARCHIVE_ARCHIVE_ENGINE_H
47
#define PLUGIN_ARCHIVE_ARCHIVE_ENGINE_H
48
49
/* The file extension */
50
#define ARZ ".arz"               // The data file
51
#define ARN ".ARN"               // Files used during an optimize call
52
53
/*
54
  We just implement one additional file extension.
55
*/
56
static const char *ha_archive_exts[] = {
57
  ARZ,
58
  NULL
59
};
60
61
62
class ArchiveEngine : public drizzled::plugin::StorageEngine
63
{
1685.2.8 by Brian Aker
Fix possible issue with case.
64
  typedef boost::unordered_map<std::string, ArchiveShare *, drizzled::util::insensitive_hash, drizzled::util::insensitive_equal_to> ArchiveMap;
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
65
  ArchiveMap archive_open_tables;
66
1685.2.7 by Brian Aker
Encapsulate global lock.
67
  /* Variables for archive share methods */
68
  pthread_mutex_t _mutex;
69
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
70
public:
1358.1.1 by Brian Aker
Fixes regression in performance from Exists patch.
71
  ArchiveEngine() :
72
    drizzled::plugin::StorageEngine("ARCHIVE",
73
                                    drizzled::HTON_STATS_RECORDS_IS_EXACT |
1414 by Brian Aker
Remove dead type.
74
                                    drizzled::HTON_HAS_RECORDS),
1358.1.1 by Brian Aker
Fixes regression in performance from Exists patch.
75
    archive_open_tables()
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
76
  {
1685.2.7 by Brian Aker
Encapsulate global lock.
77
    pthread_mutex_init(&_mutex, NULL);
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
78
    table_definition_ext= ARZ;
79
  }
1685.2.7 by Brian Aker
Encapsulate global lock.
80
  ~ArchiveEngine()
81
  {
82
    pthread_mutex_destroy(&_mutex);
83
  }
84
85
  pthread_mutex_t &mutex()
86
  {
87
    return _mutex;
88
  }
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
89
1680.6.1 by Brian Aker
Remove call for using special new for a cursor.
90
  virtual drizzled::Cursor *create(drizzled::TableShare &table)
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
91
  {
1680.6.1 by Brian Aker
Remove call for using special new for a cursor.
92
    return new ha_archive(*this, table);
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
93
  }
94
95
  const char **bas_ext() const {
96
    return ha_archive_exts;
97
  }
98
1413 by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference.
99
  int doCreateTable(drizzled::Session &session,
100
                    drizzled::Table &table_arg,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
101
                    const drizzled::TableIdentifier &identifier,
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
102
                    drizzled::message::Table& proto);
103
104
  int doGetTableDefinition(drizzled::Session& session,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
105
                           const drizzled::TableIdentifier &identifier,
1354.1.1 by Brian Aker
Modify ptr to reference.
106
                           drizzled::message::Table &table_message);
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
107
1642 by Brian Aker
This adds const to SchemaIdentifier.
108
  void doGetTableNames(drizzled::CachedDirectory &directory, const drizzled::SchemaIdentifier&, std::set<std::string>& set_of_names);
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
109
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
110
  int doDropTable(drizzled::Session&, const drizzled::TableIdentifier &identifier);
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
111
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
112
  ArchiveShare *findOpenTable(const std::string table_name);
113
  void addOpenTable(const std::string &table_name, ArchiveShare *);
114
  void deleteOpenTable(const std::string &table_name);
115
116
  uint32_t max_supported_keys()          const { return 1; }
117
  uint32_t max_supported_key_length()    const { return sizeof(uint64_t); }
118
  uint32_t max_supported_key_part_length() const { return sizeof(uint64_t); }
119
120
  uint32_t index_flags(enum  drizzled::ha_key_alg) const
121
  {
122
    return HA_ONLY_WHOLE_INDEX;
123
  }
1358.1.1 by Brian Aker
Fixes regression in performance from Exists patch.
124
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
125
  bool doDoesTableExist(drizzled::Session&, const drizzled::TableIdentifier &identifier);
126
  int doRenameTable(drizzled::Session&, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
127
128
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
1642 by Brian Aker
This adds const to SchemaIdentifier.
129
                             const drizzled::SchemaIdentifier &schema_identifier,
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
130
                             drizzled::TableIdentifiers &set_of_identifiers);
1286.1.4 by Brian Aker
Style change in Archive. Split a few files out.
131
};
132
133
#endif /* PLUGIN_ARCHIVE_ARCHIVE_ENGINE_H */