~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/blackhole/ha_blackhole.cc

Added code necessary for building plugins dynamically.
Merged in changes from lifeless to allow autoreconf to work.
Touching plugin.ini files now triggers a rebuid - so config/autorun.sh is no
longer required to be run after touching those.
Removed the duplicate plugin names - also removed the issue that getting them
different would silently fail weirdly later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include <drizzled/server_includes.h>
17
17
#include <drizzled/table.h>
 
18
#include <mysys/my_dir.h>
 
19
#include <drizzled/error.h>
 
20
 
18
21
#include "ha_blackhole.h"
19
22
 
20
23
#include <string>
 
24
#include <fstream>
 
25
#include <drizzled/message/table.pb.h>
 
26
#include <google/protobuf/io/zero_copy_stream.h>
 
27
#include <google/protobuf/io/zero_copy_stream_impl.h>
21
28
 
22
29
using namespace std;
 
30
using namespace google;
23
31
 
24
32
static const string engine_name("BLACKHOLE");
25
33
 
 
34
#define BLACKHOLE_EXT ".blk"
26
35
 
27
36
static const char *ha_blackhole_exts[] = {
28
37
  NULL
32
41
{
33
42
public:
34
43
  BlackholeEngine(const string &name_arg)
35
 
   : drizzled::plugin::StorageEngine(name_arg, HTON_FILE_BASED | HTON_CAN_RECREATE) {}
 
44
   : drizzled::plugin::StorageEngine(name_arg, HTON_FILE_BASED | HTON_HAS_DATA_DICTIONARY | HTON_CAN_RECREATE) 
 
45
  {
 
46
    table_definition_ext= BLACKHOLE_EXT;
 
47
  }
 
48
 
36
49
  virtual Cursor *create(TableShare *table,
37
50
                          MEM_ROOT *mem_root)
38
51
  {
43
56
    return ha_blackhole_exts;
44
57
  }
45
58
 
46
 
  int createTableImplementation(Session*, const char *, Table *,
47
 
                                HA_CREATE_INFO *, drizzled::message::Table*);
48
 
 
49
 
  int deleteTableImplementation(Session*, const string table_name); 
 
59
  int doCreateTable(Session*, const char *, Table&,
 
60
                    HA_CREATE_INFO&, drizzled::message::Table&);
 
61
 
 
62
  int doDropTable(Session&, const string table_name); 
 
63
 
 
64
  int doGetTableDefinition(Session& session,
 
65
                           const char* path,
 
66
                           const char *db,
 
67
                           const char *table_name,
 
68
                           const bool is_tmp,
 
69
                           drizzled::message::Table *table_proto);
 
70
 
 
71
  void doGetTableNames(CachedDirectory &directory, string&, set<string>& set_of_names)
 
72
  {
 
73
    CachedDirectory::Entries entries= directory.getEntries();
 
74
 
 
75
    for (CachedDirectory::Entries::iterator entry_iter= entries.begin(); 
 
76
         entry_iter != entries.end(); ++entry_iter)
 
77
    {
 
78
      CachedDirectory::Entry *entry= *entry_iter;
 
79
      string *filename= &entry->filename;
 
80
 
 
81
      assert(filename->size());
 
82
 
 
83
      const char *ext= strchr(filename->c_str(), '.');
 
84
 
 
85
      if (ext == NULL || my_strcasecmp(system_charset_info, ext, BLACKHOLE_EXT) ||
 
86
          is_prefix(filename->c_str(), TMP_FILE_PREFIX))
 
87
      {  }
 
88
      else
 
89
      {
 
90
        char uname[NAME_LEN + 1];
 
91
        uint32_t file_name_len;
 
92
 
 
93
        file_name_len= filename_to_tablename(filename->c_str(), uname, sizeof(uname));
 
94
        // TODO: Remove need for memory copy here
 
95
        uname[file_name_len - sizeof(BLACKHOLE_EXT) + 1]= '\0'; // Subtract ending, place NULL 
 
96
        set_of_names.insert(uname);
 
97
      }
 
98
    }
 
99
  }
50
100
};
51
101
 
52
102
/* Static declarations for shared structures */
85
135
int ha_blackhole::close(void)
86
136
{
87
137
  free_share(share);
88
 
  return(0);
89
 
}
90
 
 
91
 
int BlackholeEngine::createTableImplementation(Session*, const char *path,
92
 
                                               Table *, HA_CREATE_INFO *,
93
 
                                               drizzled::message::Table*)
94
 
{
95
 
  FILE *blackhole_table;
96
 
 
97
 
  /* Create an empty file for the Drizzle core to track whether
98
 
     a blackhole table exists */
99
 
  if ((blackhole_table= fopen(path, "w")) == NULL)
100
 
    return(1);
101
 
 
102
 
  /* This file should never have to be reopened */
103
 
  fclose(blackhole_table);
104
 
 
105
 
  return(0);
106
 
}
107
 
 
108
 
int BlackholeEngine::deleteTableImplementation(Session*, const string path)
109
 
{
110
 
  if (unlink(path.c_str()) != 0)
 
138
  return 0;
 
139
}
 
140
 
 
141
int BlackholeEngine::doCreateTable(Session*, const char *path,
 
142
                                   Table&, HA_CREATE_INFO&,
 
143
                                   drizzled::message::Table& proto)
 
144
{
 
145
  string serialized_proto;
 
146
  string new_path;
 
147
 
 
148
  new_path= path;
 
149
  new_path+= BLACKHOLE_EXT;
 
150
  fstream output(new_path.c_str(), ios::out | ios::binary);
 
151
 
 
152
 
 
153
  if (! output)
 
154
    return 1;
 
155
 
 
156
  if (! proto.SerializeToOstream(&output))
 
157
  {
 
158
    output.close();
 
159
    unlink(new_path.c_str());
 
160
    return 1;
 
161
  }
 
162
 
 
163
  return 0;
 
164
}
 
165
 
 
166
 
 
167
int BlackholeEngine::doDropTable(Session&, const string path)
 
168
{
 
169
  string new_path;
 
170
 
 
171
  new_path= path;
 
172
  new_path+= BLACKHOLE_EXT;
 
173
 
 
174
  if (unlink(new_path.c_str()) != 0)
111
175
  {
112
176
    my_errno= errno;
113
177
    return errno;
114
178
  }
115
 
  return(0);
 
179
 
 
180
  return 0;
 
181
}
 
182
 
 
183
 
 
184
int BlackholeEngine::doGetTableDefinition(Session&,
 
185
                                          const char* path,
 
186
                                          const char *,
 
187
                                          const char *,
 
188
                                          const bool,
 
189
                                          drizzled::message::Table *table_proto)
 
190
{
 
191
  string new_path;
 
192
 
 
193
  new_path= path;
 
194
  new_path+= BLACKHOLE_EXT;
 
195
 
 
196
  int fd= open(new_path.c_str(), O_RDONLY);
 
197
 
 
198
  if (fd == -1)
 
199
  {
 
200
    return -1;
 
201
  }
 
202
 
 
203
  google::protobuf::io::ZeroCopyInputStream* input=
 
204
    new google::protobuf::io::FileInputStream(fd);
 
205
 
 
206
  if (! input)
 
207
    return -1;
 
208
 
 
209
  if (table_proto && ! table_proto->ParseFromZeroCopyStream(input))
 
210
  {
 
211
    close(fd);
 
212
    delete input;
 
213
    return -1;
 
214
  }
 
215
 
 
216
  delete input;
 
217
  return EEXIST;
116
218
}
117
219
 
118
220
const char *ha_blackhole::index_type(uint32_t)
320
422
  return 0;
321
423
}
322
424
 
323
 
drizzle_declare_plugin(blackhole)
 
425
drizzle_declare_plugin
324
426
{
325
427
  "BLACKHOLE",
326
428
  "1.0",