~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/blackhole/ha_blackhole.cc

  • Committer: Brian Aker
  • Date: 2010-10-20 20:26:18 UTC
  • mfrom: (1859.2.13 refactor)
  • Revision ID: brian@tangent.org-20101020202618-9222n39lm329urv5
Merge for Brian 

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
#include "config.h"
17
 
 
 
17
#include <drizzled/table.h>
18
18
#include <drizzled/error.h>
19
 
#include <drizzled/global_charset_info.h>
20
 
#include <drizzled/internal/m_string.h>
21
 
#include <drizzled/internal/my_pthread.h>
22
 
#include <drizzled/message/table.h>
23
 
#include <drizzled/plugin/storage_engine.h>
24
 
#include <drizzled/table.h>
25
 
 
 
19
#include "drizzled/internal/my_pthread.h"
26
20
 
27
21
#include "ha_blackhole.h"
28
22
 
29
23
#include <fcntl.h>
30
24
 
 
25
#include <string>
 
26
#include <map>
31
27
#include <fstream>
32
 
#include <map>
33
 
#include <string>
34
 
 
 
28
#include <drizzled/message/table.pb.h>
 
29
#include "drizzled/internal/m_string.h"
35
30
#include <google/protobuf/io/zero_copy_stream.h>
36
31
#include <google/protobuf/io/zero_copy_stream_impl.h>
 
32
#include "drizzled/global_charset_info.h"
37
33
 
38
34
 
39
35
using namespace std;
52
48
 
53
49
class BlackholeEngine : public drizzled::plugin::StorageEngine
54
50
{
55
 
  typedef std::map<std::string, BlackholeShare*> BlackholeMap;
 
51
  typedef map<string, BlackholeShare*> BlackholeMap;
56
52
  BlackholeMap blackhole_open_tables;
57
53
 
58
54
public:
72
68
    pthread_mutex_destroy(&blackhole_mutex);
73
69
  }
74
70
 
75
 
  virtual Cursor *create(Table &table)
 
71
  virtual Cursor *create(TableShare &table)
76
72
  {
77
73
    return new ha_blackhole(*this, table);
78
74
  }
83
79
 
84
80
  int doCreateTable(Session&,
85
81
                    Table&,
86
 
                    const drizzled::identifier::Table &identifier,
 
82
                    const drizzled::TableIdentifier &identifier,
87
83
                    drizzled::message::Table&);
88
84
 
89
 
  int doDropTable(Session&, const drizzled::identifier::Table &identifier);
 
85
  int doDropTable(Session&, const drizzled::TableIdentifier &identifier);
90
86
 
91
87
  BlackholeShare *findOpenTable(const string table_name);
92
88
  void addOpenTable(const string &table_name, BlackholeShare *);
93
89
  void deleteOpenTable(const string &table_name);
94
90
 
95
91
  int doGetTableDefinition(Session& session,
96
 
                           const drizzled::identifier::Table &identifier,
 
92
                           const drizzled::TableIdentifier &identifier,
97
93
                           drizzled::message::Table &table_message);
98
94
 
99
95
  /* The following defines can be increased if necessary */
110
106
            HA_KEYREAD_ONLY);
111
107
  }
112
108
 
113
 
  bool doDoesTableExist(Session& session, const drizzled::identifier::Table &identifier);
114
 
  int doRenameTable(Session&, const drizzled::identifier::Table &from, const drizzled::identifier::Table &to);
 
109
  bool doDoesTableExist(Session& session, const drizzled::TableIdentifier &identifier);
 
110
  int doRenameTable(Session&, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
115
111
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
116
 
                             const drizzled::identifier::Schema &schema_identifier,
117
 
                             drizzled::identifier::Table::vector &set_of_identifiers);
 
112
                             const drizzled::SchemaIdentifier &schema_identifier,
 
113
                             drizzled::TableIdentifiers &set_of_identifiers);
118
114
};
119
115
 
120
116
 
121
117
void BlackholeEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
122
 
                                            const drizzled::identifier::Schema &schema_identifier,
123
 
                                            drizzled::identifier::Table::vector &set_of_identifiers)
 
118
                                            const drizzled::SchemaIdentifier &schema_identifier,
 
119
                                            drizzled::TableIdentifiers &set_of_identifiers)
124
120
{
125
121
  drizzled::CachedDirectory::Entries entries= directory.getEntries();
126
122
 
142
138
      char uname[NAME_LEN + 1];
143
139
      uint32_t file_name_len;
144
140
 
145
 
      file_name_len= identifier::Table::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
 
141
      file_name_len= TableIdentifier::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
146
142
      // TODO: Remove need for memory copy here
147
143
      uname[file_name_len - sizeof(BLACKHOLE_EXT) + 1]= '\0'; // Subtract ending, place NULL
148
144
 
149
 
      set_of_identifiers.push_back(identifier::Table(schema_identifier, uname));
 
145
      set_of_identifiers.push_back(TableIdentifier(schema_identifier, uname));
150
146
    }
151
147
  }
152
148
}
153
149
 
154
 
int BlackholeEngine::doRenameTable(Session&, const drizzled::identifier::Table &from, const drizzled::identifier::Table &to)
 
150
int BlackholeEngine::doRenameTable(Session&, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to)
155
151
{
156
152
  int error= 0;
157
153
 
195
191
*****************************************************************************/
196
192
 
197
193
ha_blackhole::ha_blackhole(drizzled::plugin::StorageEngine &engine_arg,
198
 
                           Table &table_arg)
 
194
                           TableShare &table_arg)
199
195
  :Cursor(engine_arg, table_arg), share(NULL)
200
196
{ }
201
197
 
216
212
 
217
213
int BlackholeEngine::doCreateTable(Session&,
218
214
                                   Table&,
219
 
                                   const drizzled::identifier::Table &identifier,
 
215
                                   const drizzled::TableIdentifier &identifier,
220
216
                                   drizzled::message::Table& proto)
221
217
{
222
218
  string serialized_proto;
242
238
 
243
239
 
244
240
int BlackholeEngine::doDropTable(Session&,
245
 
                                 const drizzled::identifier::Table &identifier)
 
241
                                 const drizzled::TableIdentifier &identifier)
246
242
{
247
243
  string new_path(identifier.getPath());
248
244
 
260
256
 
261
257
 
262
258
bool BlackholeEngine::doDoesTableExist(Session&,
263
 
                                       const drizzled::identifier::Table &identifier)
 
259
                                       const drizzled::TableIdentifier &identifier)
264
260
{
265
261
  string proto_path(identifier.getPath());
266
262
  proto_path.append(BLACKHOLE_EXT);
275
271
 
276
272
 
277
273
int BlackholeEngine::doGetTableDefinition(Session&,
278
 
                                          const drizzled::identifier::Table &identifier,
 
274
                                          const drizzled::TableIdentifier &identifier,
279
275
                                          drizzled::message::Table &table_proto)
280
276
{
281
277
  string new_path;
303
299
    if (not table_proto.IsInitialized())
304
300
    {
305
301
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
306
 
               table_proto.name().empty() ? " " : table_proto.name().c_str(),
307
302
               table_proto.InitializationErrorString().c_str());
308
 
 
309
303
      return ER_CORRUPT_TABLE_DEFINITION;
310
304
    }
311
305
 
324
318
 
325
319
int ha_blackhole::doInsertRecord(unsigned char *)
326
320
{
327
 
  return(getTable()->next_number_field ? update_auto_increment() : 0);
 
321
  return(table->next_number_field ? update_auto_increment() : 0);
328
322
}
329
323
 
330
324
int ha_blackhole::doStartTableScan(bool)
410
404
{
411
405
  pthread_mutex_lock(&blackhole_mutex);
412
406
 
413
 
  BlackholeEngine *a_engine= static_cast<BlackholeEngine *>(getEngine());
 
407
  BlackholeEngine *a_engine= static_cast<BlackholeEngine *>(engine);
414
408
  share= a_engine->findOpenTable(table_name);
415
409
 
416
410
  if (share == NULL)
435
429
  pthread_mutex_lock(&blackhole_mutex);
436
430
  if (!--share->use_count)
437
431
  {
438
 
    BlackholeEngine *a_engine= static_cast<BlackholeEngine *>(getEngine());
 
432
    BlackholeEngine *a_engine= static_cast<BlackholeEngine *>(engine);
439
433
    a_engine->deleteOpenTable(share->table_name);
440
434
    delete share;
441
435
  }
477
471
  "/dev/null storage engine (anything you write to it disappears)",
478
472
  PLUGIN_LICENSE_GPL,
479
473
  blackhole_init,     /* Plugin Init */
480
 
  NULL,               /* depends */
 
474
  NULL,               /* system variables */
481
475
  NULL                /* config options   */
482
476
}
483
477
DRIZZLE_DECLARE_PLUGIN_END;