~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2005 MySQL AB
2
3
  This program is free software; you can redistribute it and/or modify
4
  it under the terms of the GNU General Public License as published by
5
  the Free Software Foundation; version 2 of the License.
6
7
  This program is distributed in the hope that it will be useful,
8
  but WITHOUT ANY WARRANTY; without even the implied warranty of
9
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
  GNU General Public License for more details.
11
12
  You should have received a copy of the GNU General Public License
13
  along with this program; if not, write to the Free Software
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
16
#include "config.h"
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
17
#include <drizzled/table.h>
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
18
#include <drizzled/error.h>
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
19
#include "drizzled/internal/my_pthread.h"
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
20
1 by brian
clean slate
21
#include "ha_blackhole.h"
22
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
23
#include <fcntl.h>
24
960.2.41 by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method.
25
#include <string>
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
26
#include <map>
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
27
#include <fstream>
28
#include <drizzled/message/table.pb.h>
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
29
#include "drizzled/internal/m_string.h"
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
30
#include <google/protobuf/io/zero_copy_stream.h>
31
#include <google/protobuf/io/zero_copy_stream_impl.h>
1241.9.28 by Monty Taylor
Removed global_charset_info.h from server_includes.h
32
#include "drizzled/global_charset_info.h"
33
960.2.41 by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method.
34
35
using namespace std;
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
36
using namespace google;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
37
using namespace drizzled;
960.2.41 by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method.
38
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
39
#define BLACKHOLE_EXT ".blk"
1039.3.1 by Stewart Smith
move bas_ext to StorageEngine instead of handler
40
1324.2.3 by Monty Taylor
Remove plugin deinit.
41
static pthread_mutex_t blackhole_mutex;
42
43
1039.3.1 by Stewart Smith
move bas_ext to StorageEngine instead of handler
44
static const char *ha_blackhole_exts[] = {
1723.4.1 by LinuxJedi
Fix blackhole engine alter table not renaming file correctly
45
  BLACKHOLE_EXT,
1039.3.1 by Stewart Smith
move bas_ext to StorageEngine instead of handler
46
  NULL
47
};
48
1130.1.4 by Monty Taylor
Moved StorageEngine into plugin namespace.
49
class BlackholeEngine : public drizzled::plugin::StorageEngine
1 by brian
clean slate
50
{
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
51
  typedef map<string, BlackholeShare*> BlackholeMap;
52
  BlackholeMap blackhole_open_tables;
53
960.2.41 by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method.
54
public:
964.1.4 by Monty Taylor
Moved flags into private area.
55
  BlackholeEngine(const string &name_arg)
1461.1.1 by Stewart Smith
remove HTON_FILE_BASED: it's unused now.
56
   : drizzled::plugin::StorageEngine(name_arg,
1233.1.3 by Brian Aker
Move more of the flags up to engine flags.
57
                                     HTON_NULL_IN_KEY |
58
                                     HTON_CAN_INDEX_BLOBS |
1236.1.2 by Brian Aker
Updating blackhole to skip store_lock. I've added a test to make sure that
59
                                     HTON_SKIP_STORE_LOCK |
1414 by Brian Aker
Remove dead type.
60
                                     HTON_AUTO_PART_KEY),
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
61
    blackhole_open_tables()
1183.1.27 by Brian Aker
Fix issue where there are too many files in data directory. We now only
62
  {
63
    table_definition_ext= BLACKHOLE_EXT;
64
  }
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
65
1324.2.3 by Monty Taylor
Remove plugin deinit.
66
  virtual ~BlackholeEngine()
67
  {
68
    pthread_mutex_destroy(&blackhole_mutex);
69
  }
70
1680.6.1 by Brian Aker
Remove call for using special new for a cursor.
71
  virtual Cursor *create(TableShare &table)
960.2.29 by Monty Taylor
Updated blackhole.
72
  {
1680.6.1 by Brian Aker
Remove call for using special new for a cursor.
73
    return new ha_blackhole(*this, table);
960.2.29 by Monty Taylor
Updated blackhole.
74
  }
1039.3.1 by Stewart Smith
move bas_ext to StorageEngine instead of handler
75
76
  const char **bas_ext() const {
77
    return ha_blackhole_exts;
78
  }
1039.3.3 by Stewart Smith
Move handler::create to StorageEngine::create_table
79
1413 by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference.
80
  int doCreateTable(Session&,
1222.1.7 by Brian Aker
Remove HA_CREATE_INFO from createTable()
81
                    Table&,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
82
                    const drizzled::TableIdentifier &identifier,
1222.1.7 by Brian Aker
Remove HA_CREATE_INFO from createTable()
83
                    drizzled::message::Table&);
1103.5.2 by Toru Maesaka
Added tests for BLACKHOLE and also code to create and delete a empty file. This is so that the core can track if a table exists or not. This is required for proper implementation of DROP TABLE and otherwise the test suite will reject it
84
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
85
  int doDropTable(Session&, const drizzled::TableIdentifier &identifier);
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
86
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
87
  BlackholeShare *findOpenTable(const string table_name);
88
  void addOpenTable(const string &table_name, BlackholeShare *);
89
  void deleteOpenTable(const string &table_name);
90
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
91
  int doGetTableDefinition(Session& session,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
92
                           const drizzled::TableIdentifier &identifier,
1354.1.1 by Brian Aker
Modify ptr to reference.
93
                           drizzled::message::Table &table_message);
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
94
1241.9.44 by Monty Taylor
Made magic with cached_directory.
95
  void doGetTableNames(drizzled::CachedDirectory &directory,
1642 by Brian Aker
This adds const to SchemaIdentifier.
96
		       const SchemaIdentifier &,
1415 by Brian Aker
Mass overhaul to use schema_identifier.
97
                       set<string>& set_of_names)
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
98
  {
1241.9.44 by Monty Taylor
Made magic with cached_directory.
99
    drizzled::CachedDirectory::Entries entries= directory.getEntries();
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
100
1241.9.44 by Monty Taylor
Made magic with cached_directory.
101
    for (drizzled::CachedDirectory::Entries::iterator entry_iter= entries.begin();
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
102
         entry_iter != entries.end(); ++entry_iter)
103
    {
1241.9.44 by Monty Taylor
Made magic with cached_directory.
104
      drizzled::CachedDirectory::Entry *entry= *entry_iter;
1259.3.4 by Monty Taylor
Just a little bit of a cleanup.
105
      const string *filename= &entry->filename;
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
106
107
      assert(filename->size());
108
109
      const char *ext= strchr(filename->c_str(), '.');
110
111
      if (ext == NULL || my_strcasecmp(system_charset_info, ext, BLACKHOLE_EXT) ||
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
112
         (filename->compare(0, strlen(TMP_FILE_PREFIX), TMP_FILE_PREFIX) == 0))
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
113
      {  }
114
      else
115
      {
116
        char uname[NAME_LEN + 1];
117
        uint32_t file_name_len;
118
1601 by Brian Aker
Move functions to class methods.
119
        file_name_len= TableIdentifier::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
120
        // TODO: Remove need for memory copy here
1233.1.9 by Brian Aker
Move max key stuff up to engine.
121
        uname[file_name_len - sizeof(BLACKHOLE_EXT) + 1]= '\0'; // Subtract ending, place NULL
1183.1.13 by Brian Aker
Fix pass by reference for directory object
122
        set_of_names.insert(uname);
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
123
      }
124
    }
125
  }
1233.1.9 by Brian Aker
Move max key stuff up to engine.
126
127
  /* The following defines can be increased if necessary */
128
  uint32_t max_supported_keys()          const { return BLACKHOLE_MAX_KEY; }
129
  uint32_t max_supported_key_length()    const { return BLACKHOLE_MAX_KEY_LENGTH; }
130
  uint32_t max_supported_key_part_length() const { return BLACKHOLE_MAX_KEY_LENGTH; }
1235.1.13 by Brian Aker
Next pass through interface to move index flag bits up to engine.
131
132
  uint32_t index_flags(enum  ha_key_alg) const
133
  {
134
    return (HA_READ_NEXT |
135
            HA_READ_PREV |
136
            HA_READ_RANGE |
137
            HA_READ_ORDER |
138
            HA_KEYREAD_ONLY);
139
  }
140
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
141
  bool doDoesTableExist(Session& session, const drizzled::TableIdentifier &identifier);
142
  int doRenameTable(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.
143
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
1642 by Brian Aker
This adds const to SchemaIdentifier.
144
                             const drizzled::SchemaIdentifier &schema_identifier,
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
145
                             drizzled::TableIdentifiers &set_of_identifiers);
960.2.29 by Monty Taylor
Updated blackhole.
146
};
1 by brian
clean slate
147
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
148
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
149
void BlackholeEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
1642 by Brian Aker
This adds const to SchemaIdentifier.
150
                                            const drizzled::SchemaIdentifier &schema_identifier,
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
151
                                            drizzled::TableIdentifiers &set_of_identifiers)
152
{
153
  drizzled::CachedDirectory::Entries entries= directory.getEntries();
154
155
  for (drizzled::CachedDirectory::Entries::iterator entry_iter= entries.begin();
156
       entry_iter != entries.end(); ++entry_iter)
157
  {
158
    drizzled::CachedDirectory::Entry *entry= *entry_iter;
159
    const string *filename= &entry->filename;
160
161
    assert(filename->size());
162
163
    const char *ext= strchr(filename->c_str(), '.');
164
165
    if (ext == NULL || my_strcasecmp(system_charset_info, ext, BLACKHOLE_EXT) ||
166
        (filename->compare(0, strlen(TMP_FILE_PREFIX), TMP_FILE_PREFIX) == 0))
167
    {  }
168
    else
169
    {
170
      char uname[NAME_LEN + 1];
171
      uint32_t file_name_len;
172
1601 by Brian Aker
Move functions to class methods.
173
      file_name_len= TableIdentifier::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
174
      // TODO: Remove need for memory copy here
175
      uname[file_name_len - sizeof(BLACKHOLE_EXT) + 1]= '\0'; // Subtract ending, place NULL
176
177
      set_of_identifiers.push_back(TableIdentifier(schema_identifier, uname));
178
    }
179
  }
180
}
181
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
182
int BlackholeEngine::doRenameTable(Session&, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to)
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
183
{
184
  int error= 0;
185
186
  for (const char **ext= bas_ext(); *ext ; ext++)
187
  {
1390 by Brian Aker
Update interface to use Identifiers directly.
188
    if (rename_file_ext(from.getPath().c_str(), to.getPath().c_str(), *ext))
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
189
    {
190
      if ((error=errno) != ENOENT)
191
        break;
192
      error= 0;
193
    }
194
  }
195
  return error;
196
}
197
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
198
BlackholeShare *BlackholeEngine::findOpenTable(const string table_name)
199
{
200
  BlackholeMap::iterator find_iter=
201
    blackhole_open_tables.find(table_name);
202
203
  if (find_iter != blackhole_open_tables.end())
204
    return (*find_iter).second;
205
  else
206
    return NULL;
207
}
208
209
void BlackholeEngine::addOpenTable(const string &table_name, BlackholeShare *share)
210
{
211
  blackhole_open_tables[table_name]= share;
212
}
213
214
void BlackholeEngine::deleteOpenTable(const string &table_name)
215
{
216
  blackhole_open_tables.erase(table_name);
217
}
218
219
1 by brian
clean slate
220
221
/*****************************************************************************
222
** BLACKHOLE tables
223
*****************************************************************************/
224
1208.3.2 by brian
Update for Cursor renaming.
225
ha_blackhole::ha_blackhole(drizzled::plugin::StorageEngine &engine_arg,
226
                           TableShare &table_arg)
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
227
  :Cursor(engine_arg, table_arg), share(NULL)
1208.3.2 by brian
Update for Cursor renaming.
228
{ }
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
229
653 by Brian Aker
More solaris bits
230
int ha_blackhole::open(const char *name, int, uint32_t)
1 by brian
clean slate
231
{
232
  if (!(share= get_share(name)))
51.3.8 by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines
233
    return(HA_ERR_OUT_OF_MEM);
1 by brian
clean slate
234
1689.2.13 by Brian Aker
More encapsulation of thr_lock
235
  lock.init(&share->lock);
236
  return 0;
1 by brian
clean slate
237
}
238
239
int ha_blackhole::close(void)
240
{
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
241
  free_share();
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
242
  return 0;
1 by brian
clean slate
243
}
244
1413 by Brian Aker
doCreateTable() was still taking a pointer instead of a session reference.
245
int BlackholeEngine::doCreateTable(Session&,
1222.1.7 by Brian Aker
Remove HA_CREATE_INFO from createTable()
246
                                   Table&,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
247
                                   const drizzled::TableIdentifier &identifier,
1183.1.18 by Brian Aker
Fixed references to doCreateTable()
248
                                   drizzled::message::Table& proto)
1 by brian
clean slate
249
{
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
250
  string serialized_proto;
251
  string new_path;
252
1358.1.6 by Brian Aker
Remove old calls for path.
253
  new_path= identifier.getPath();
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
254
  new_path+= BLACKHOLE_EXT;
1183.1.19 by Brian Aker
Three cleanups from build test.
255
  fstream output(new_path.c_str(), ios::out | ios::binary);
256
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
257
258
  if (! output)
259
    return 1;
260
1183.1.18 by Brian Aker
Fixed references to doCreateTable()
261
  if (! proto.SerializeToOstream(&output))
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
262
  {
263
    output.close();
264
    unlink(new_path.c_str());
265
    return 1;
266
  }
267
268
  return 0;
1103.5.2 by Toru Maesaka
Added tests for BLACKHOLE and also code to create and delete a empty file. This is so that the core can track if a table exists or not. This is required for proper implementation of DROP TABLE and otherwise the test suite will reject it
269
}
270
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
271
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
272
int BlackholeEngine::doDropTable(Session&,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
273
                                 const drizzled::TableIdentifier &identifier)
1103.5.2 by Toru Maesaka
Added tests for BLACKHOLE and also code to create and delete a empty file. This is so that the core can track if a table exists or not. This is required for proper implementation of DROP TABLE and otherwise the test suite will reject it
274
{
1358.1.3 by Brian Aker
doDropTable() now only uses identifier.
275
  string new_path(identifier.getPath());
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
276
277
  new_path+= BLACKHOLE_EXT;
278
1213 by Brian Aker
Fixes startup failures when temporary tables were left behind in a crash.
279
  int error= unlink(new_path.c_str());
280
281
  if (error != 0)
1103.5.3 by Toru Maesaka
Fix the curly brace in BLACKHOLE to follow the coding standard
282
  {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
283
    error= errno= errno;
1103.5.2 by Toru Maesaka
Added tests for BLACKHOLE and also code to create and delete a empty file. This is so that the core can track if a table exists or not. This is required for proper implementation of DROP TABLE and otherwise the test suite will reject it
284
  }
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
285
1213 by Brian Aker
Fixes startup failures when temporary tables were left behind in a crash.
286
  return error;
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
287
}
288
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
289
1358.1.1 by Brian Aker
Fixes regression in performance from Exists patch.
290
bool BlackholeEngine::doDoesTableExist(Session&,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
291
                                       const drizzled::TableIdentifier &identifier)
1358.1.1 by Brian Aker
Fixes regression in performance from Exists patch.
292
{
293
  string proto_path(identifier.getPath());
294
  proto_path.append(BLACKHOLE_EXT);
295
296
  if (access(proto_path.c_str(), F_OK))
297
  {
298
    return false;
299
  }
300
301
  return true;
302
}
303
304
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
305
int BlackholeEngine::doGetTableDefinition(Session&,
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
306
                                          const drizzled::TableIdentifier &identifier,
1354.1.1 by Brian Aker
Modify ptr to reference.
307
                                          drizzled::message::Table &table_proto)
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
308
{
309
  string new_path;
310
1358.1.7 by Brian Aker
Remove interface bits around caller for internal lookup of create table.
311
  new_path= identifier.getPath();
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
312
  new_path+= BLACKHOLE_EXT;
313
314
  int fd= open(new_path.c_str(), O_RDONLY);
315
316
  if (fd == -1)
317
  {
1217.1.4 by Brian Aker
Cleanup of return errors from engines (still... a better job could be done).
318
    return errno;
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
319
  }
320
321
  google::protobuf::io::ZeroCopyInputStream* input=
322
    new google::protobuf::io::FileInputStream(fd);
323
1354.1.1 by Brian Aker
Modify ptr to reference.
324
  if (not input)
1217.1.4 by Brian Aker
Cleanup of return errors from engines (still... a better job could be done).
325
    return HA_ERR_CRASHED_ON_USAGE;
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
326
1354.1.1 by Brian Aker
Modify ptr to reference.
327
  if (not table_proto.ParseFromZeroCopyStream(input))
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
328
  {
329
    close(fd);
1183.1.28 by Brian Aker
Memory leak fixed in blackhole
330
    delete input;
1354.1.1 by Brian Aker
Modify ptr to reference.
331
    if (not table_proto.IsInitialized())
1273.2.26 by Stewart Smith
correctly throw a ER_CORRUPT_TABLE_DEFINITION error message from BlackholeEngine if reading table proto message fails. Modify storage_engine.cc code so that errors are reported back to the user correctly.
332
    {
333
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
1354.1.1 by Brian Aker
Modify ptr to reference.
334
               table_proto.InitializationErrorString().c_str());
1273.2.26 by Stewart Smith
correctly throw a ER_CORRUPT_TABLE_DEFINITION error message from BlackholeEngine if reading table proto message fails. Modify storage_engine.cc code so that errors are reported back to the user correctly.
335
      return ER_CORRUPT_TABLE_DEFINITION;
336
    }
337
1217.1.4 by Brian Aker
Cleanup of return errors from engines (still... a better job could be done).
338
    return HA_ERR_CRASHED_ON_USAGE;
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
339
  }
340
1183.1.28 by Brian Aker
Memory leak fixed in blackhole
341
  delete input;
1354.1.1 by Brian Aker
Modify ptr to reference.
342
1183.1.10 by Brian Aker
Update blackhole engine to handle its own dictionary
343
  return EEXIST;
1 by brian
clean slate
344
}
345
653 by Brian Aker
More solaris bits
346
const char *ha_blackhole::index_type(uint32_t)
1 by brian
clean slate
347
{
249 by Brian Aker
Random key cleanup (it is a friday...)
348
  return("BTREE");
1 by brian
clean slate
349
}
350
1491.1.2 by Jay Pipes
Cursor::write_row() -> Cursor::doInsertRecord(). Cursor::ha_write_row() -> Cursor::insertRecord()
351
int ha_blackhole::doInsertRecord(unsigned char *)
1 by brian
clean slate
352
{
51.3.8 by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines
353
  return(table->next_number_field ? update_auto_increment() : 0);
1 by brian
clean slate
354
}
355
1491.1.10 by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan
356
int ha_blackhole::doStartTableScan(bool)
1 by brian
clean slate
357
{
51.3.8 by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines
358
  return(0);
1 by brian
clean slate
359
}
360
361
653 by Brian Aker
More solaris bits
362
int ha_blackhole::rnd_next(unsigned char *)
1 by brian
clean slate
363
{
51.3.8 by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines
364
  return(HA_ERR_END_OF_FILE);
1 by brian
clean slate
365
}
366
367
653 by Brian Aker
More solaris bits
368
int ha_blackhole::rnd_pos(unsigned char *, unsigned char *)
1 by brian
clean slate
369
{
51.3.8 by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines
370
  assert(0);
371
  return(0);
1 by brian
clean slate
372
}
373
374
653 by Brian Aker
More solaris bits
375
void ha_blackhole::position(const unsigned char *)
1 by brian
clean slate
376
{
51.3.8 by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines
377
  assert(0);
378
  return;
1 by brian
clean slate
379
}
380
381
482 by Brian Aker
Remove uint.
382
int ha_blackhole::info(uint32_t flag)
1 by brian
clean slate
383
{
212.6.9 by Mats Kindahl
Removing extreneous explicit casts for blackhole storage engine.
384
  memset(&stats, 0, sizeof(stats));
1 by brian
clean slate
385
  if (flag & HA_STATUS_AUTO)
386
    stats.auto_increment_value= 1;
51.3.8 by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines
387
  return(0);
1 by brian
clean slate
388
}
389
390
653 by Brian Aker
More solaris bits
391
int ha_blackhole::index_read_map(unsigned char *, const unsigned char *,
392
                                 key_part_map, enum ha_rkey_function)
393
{
394
  return(HA_ERR_END_OF_FILE);
395
}
396
397
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
398
int ha_blackhole::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *,
653 by Brian Aker
More solaris bits
399
                                     key_part_map, enum ha_rkey_function)
400
{
401
  return(HA_ERR_END_OF_FILE);
402
}
403
404
405
int ha_blackhole::index_read_last_map(unsigned char *, const unsigned char *, key_part_map)
406
{
407
  return(HA_ERR_END_OF_FILE);
408
}
409
410
411
int ha_blackhole::index_next(unsigned char *)
412
{
413
  return(HA_ERR_END_OF_FILE);
414
}
415
416
417
int ha_blackhole::index_prev(unsigned char *)
418
{
419
  return(HA_ERR_END_OF_FILE);
420
}
421
422
423
int ha_blackhole::index_first(unsigned char *)
424
{
425
  return(HA_ERR_END_OF_FILE);
426
}
427
428
429
int ha_blackhole::index_last(unsigned char *)
1 by brian
clean slate
430
{
51.3.8 by Jay Pipes
Removed DBUG from CSV and Blackhole storage engines
431
  return(HA_ERR_END_OF_FILE);
1 by brian
clean slate
432
}
433
434
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
435
BlackholeShare *ha_blackhole::get_share(const char *table_name)
1 by brian
clean slate
436
{
437
  pthread_mutex_lock(&blackhole_mutex);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
438
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
439
  BlackholeEngine *a_engine= static_cast<BlackholeEngine *>(engine);
440
  share= a_engine->findOpenTable(table_name);
441
442
  if (share == NULL)
1 by brian
clean slate
443
  {
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
444
    share= new (nothrow) BlackholeShare(table_name);
445
    if (share == NULL)
1 by brian
clean slate
446
    {
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
447
      pthread_mutex_unlock(&blackhole_mutex);      
448
      return NULL;
1 by brian
clean slate
449
    }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
450
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
451
    a_engine->addOpenTable(share->table_name, share);
1 by brian
clean slate
452
  }
453
  share->use_count++;
454
  pthread_mutex_unlock(&blackhole_mutex);
455
  return share;
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
456
1 by brian
clean slate
457
}
458
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
459
void ha_blackhole::free_share()
1 by brian
clean slate
460
{
461
  pthread_mutex_lock(&blackhole_mutex);
462
  if (!--share->use_count)
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
463
  {
464
    BlackholeEngine *a_engine= static_cast<BlackholeEngine *>(engine);
465
    a_engine->deleteOpenTable(share->table_name);
466
    delete share;
467
  }
1 by brian
clean slate
468
  pthread_mutex_unlock(&blackhole_mutex);
469
}
470
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
471
BlackholeShare::BlackholeShare(const string table_name_arg)
472
  : use_count(0), table_name(table_name_arg)
473
{
474
  thr_lock_init(&lock);
475
}
476
477
BlackholeShare::~BlackholeShare()
478
{
1689.2.11 by Brian Aker
Encapsulate more of the thr lock.
479
  lock.deinit();
1240.2.3 by Monty Taylor
Fixed blackhole crashses on Spare - made Blackhole follow the pattern of CSV and Archive.
480
}
481
1 by brian
clean slate
482
1130.1.4 by Monty Taylor
Moved StorageEngine into plugin namespace.
483
static drizzled::plugin::StorageEngine *blackhole_engine= NULL;
971.1.51 by Monty Taylor
New-style plugin registration now works.
484
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
485
static int blackhole_init(drizzled::module::Context &context)
1 by brian
clean slate
486
{
971.1.51 by Monty Taylor
New-style plugin registration now works.
487
1192.5.9 by Monty Taylor
Made blackhole dynamic
488
  blackhole_engine= new BlackholeEngine("BLACKHOLE");
1324.2.2 by Monty Taylor
Use the plugin::Context everywhere.
489
  context.add(blackhole_engine);
971.1.51 by Monty Taylor
New-style plugin registration now works.
490
  
398.1.10 by Monty Taylor
Actually removed VOID() this time.
491
  pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST);
1 by brian
clean slate
492
493
  return 0;
494
}
495
496
1228.1.5 by Monty Taylor
Merged in some naming things.
497
DRIZZLE_DECLARE_PLUGIN
1 by brian
clean slate
498
{
1241.10.2 by Monty Taylor
Added support for embedding the drizzle version number in the plugin file.
499
  DRIZZLE_VERSION_ID,
1 by brian
clean slate
500
  "BLACKHOLE",
177.4.3 by mark
ripped out more plugin ABI and API version checking, and plugin versions are now strings
501
  "1.0",
1 by brian
clean slate
502
  "MySQL AB",
503
  "/dev/null storage engine (anything you write to it disappears)",
504
  PLUGIN_LICENSE_GPL,
1103.5.1 by Toru Maesaka
Updated Blackhole to work with the current SE interface
505
  blackhole_init,     /* Plugin Init */
506
  NULL,               /* system variables */
507
  NULL                /* config options   */
1 by brian
clean slate
508
}
1228.1.5 by Monty Taylor
Merged in some naming things.
509
DRIZZLE_DECLARE_PLUGIN_END;