~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/ha_myisam.cc

  • Committer: Stewart Smith
  • Date: 2010-03-15 04:42:26 UTC
  • mto: (1283.38.1)
  • mto: This revision was merged to the branch mainline in revision 1475.
  • Revision ID: stewart@flamingspork.com-20100315044226-q74o953r9h98brm4
basic embedded innodb DATA_DICTIONARY.INNODB_CONFIGURATION test

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include "drizzled/table.h"
35
35
#include "drizzled/field/timestamp.h"
36
36
#include "drizzled/memory/multi_malloc.h"
37
 
#include "drizzled/plugin/daemon.h"
38
37
 
39
38
#include <string>
40
39
#include <sstream>
69
68
 
70
69
class MyisamEngine : public plugin::StorageEngine
71
70
{
72
 
  MyisamEngine();
73
 
  MyisamEngine(const MyisamEngine&);
74
 
  MyisamEngine& operator=(const MyisamEngine&);
75
71
public:
76
 
  explicit MyisamEngine(string name_arg) :
77
 
    plugin::StorageEngine(name_arg,
78
 
                          HTON_HAS_DATA_DICTIONARY |
79
 
                          HTON_CAN_INDEX_BLOBS |
80
 
                          HTON_STATS_RECORDS_IS_EXACT |
81
 
                          HTON_TEMPORARY_ONLY |
82
 
                          HTON_NULL_IN_KEY |
83
 
                          HTON_HAS_RECORDS |
84
 
                          HTON_DUPLICATE_POS |
85
 
                          HTON_AUTO_PART_KEY |
86
 
                          HTON_SKIP_STORE_LOCK |
87
 
                          HTON_FILE_BASED )
88
 
  {
89
 
    pthread_mutex_init(&THR_LOCK_myisam,MY_MUTEX_INIT_FAST);
90
 
  }
91
 
 
92
 
  virtual ~MyisamEngine()
93
 
  { 
94
 
    pthread_mutex_destroy(&THR_LOCK_myisam);
95
 
    end_key_cache(dflt_key_cache, 1);           // Can never fail
96
 
 
97
 
    mi_panic(HA_PANIC_CLOSE);
98
 
  }
 
72
  MyisamEngine(string name_arg)
 
73
   : plugin::StorageEngine(name_arg,
 
74
                                     HTON_HAS_DATA_DICTIONARY |
 
75
                                     HTON_CAN_INDEX_BLOBS |
 
76
                                     HTON_STATS_RECORDS_IS_EXACT |
 
77
                                     HTON_TEMPORARY_ONLY |
 
78
                                     HTON_NULL_IN_KEY |
 
79
                                     HTON_HAS_RECORDS |
 
80
                                     HTON_DUPLICATE_POS |
 
81
                                     HTON_AUTO_PART_KEY |
 
82
                                     HTON_SKIP_STORE_LOCK |
 
83
                                     HTON_FILE_BASED ) {}
 
84
 
 
85
  ~MyisamEngine()
 
86
  { }
99
87
 
100
88
  virtual Cursor *create(TableShare &table,
101
89
                         memory::Root *mem_root)
107
95
    return ha_myisam_exts;
108
96
  }
109
97
 
110
 
  int doCreateTable(Session *,
 
98
  int doCreateTable(Session *, const char *table_name,
111
99
                    Table& table_arg,
112
 
                    drizzled::TableIdentifier &identifier,
113
100
                    message::Table&);
114
101
 
115
 
  int doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to);
 
102
  int doRenameTable(Session*, const char *from, const char *to);
116
103
 
117
 
  int doDropTable(Session&, drizzled::TableIdentifier &identifier);
 
104
  int doDropTable(Session&, const string &table_name);
118
105
 
119
106
  int doGetTableDefinition(Session& session,
120
 
                           drizzled::TableIdentifier &identifier,
121
 
                           message::Table &table_message);
 
107
                           const char* path,
 
108
                           const char *db,
 
109
                           const char *table_name,
 
110
                           const bool is_tmp,
 
111
                           message::Table *table_proto);
122
112
 
123
113
  /* Temp only engine, so do not return values. */
124
114
  void doGetTableNames(CachedDirectory &, string& , set<string>&) { };
135
125
            HA_READ_ORDER |
136
126
            HA_KEYREAD_ONLY);
137
127
  }
138
 
  bool doDoesTableExist(Session& session, TableIdentifier &identifier);
139
128
};
140
129
 
141
 
bool MyisamEngine::doDoesTableExist(Session &session, TableIdentifier &identifier)
142
 
{
143
 
  return session.doesTableMessageExist(identifier);
144
 
}
145
 
 
146
 
int MyisamEngine::doGetTableDefinition(Session &session,
147
 
                                       drizzled::TableIdentifier &identifier,
148
 
                                       message::Table &table_message)
149
 
{
150
 
  if (session.getTableMessage(identifier, table_message))
151
 
    return EEXIST;
152
 
  return ENOENT;
 
130
int MyisamEngine::doGetTableDefinition(Session&,
 
131
                                       const char* path,
 
132
                                       const char *,
 
133
                                       const char *,
 
134
                                       const bool,
 
135
                                       message::Table *table_proto)
 
136
{
 
137
  int error= ENOENT;
 
138
  ProtoCache::iterator iter;
 
139
 
 
140
  pthread_mutex_lock(&proto_cache_mutex);
 
141
  iter= proto_cache.find(path);
 
142
 
 
143
  if (iter!= proto_cache.end())
 
144
  {
 
145
    if (table_proto)
 
146
      table_proto->CopyFrom(((*iter).second));
 
147
    error= EEXIST;
 
148
  }
 
149
  pthread_mutex_unlock(&proto_cache_mutex);
 
150
 
 
151
  return error;
153
152
}
154
153
 
155
154
/* 
676
675
    return(HA_ADMIN_FAILED);
677
676
  }
678
677
 
679
 
  param.db_name=    table->s->getSchemaName();
 
678
  param.db_name=    table->s->db.str;
680
679
  param.table_name= table->alias;
681
680
  param.tmpfile_createflag = O_RDWR | O_TRUNC;
682
681
  param.using_global_keycache = 1;
1224
1223
    stats.block_size= myisam_key_cache_block_size;        /* record block size */
1225
1224
 
1226
1225
    /* Update share */
1227
 
    if (share->tmp_table == message::Table::STANDARD)
 
1226
    if (share->tmp_table == STANDARD_TABLE)
1228
1227
      pthread_mutex_lock(&share->mutex);
1229
1228
    set_prefix(share->keys_in_use, share->keys);
1230
1229
    /*
1278
1277
      memcpy(table->key_info[0].rec_per_key,
1279
1278
             misam_info.rec_per_key,
1280
1279
             sizeof(table->key_info[0].rec_per_key)*share->key_parts);
1281
 
    if (share->tmp_table == message::Table::STANDARD)
 
1280
    if (share->tmp_table == STANDARD_TABLE)
1282
1281
      pthread_mutex_unlock(&share->mutex);
1283
1282
 
1284
1283
   /*
1331
1330
  return mi_delete_all_rows(file);
1332
1331
}
1333
1332
 
1334
 
int MyisamEngine::doDropTable(Session &session,
1335
 
                              drizzled::TableIdentifier &identifier)
 
1333
int MyisamEngine::doDropTable(Session&, const string &table_path)
1336
1334
{
1337
 
  session.removeTableMessage(identifier);
1338
 
 
1339
 
  return mi_delete_table(identifier.getPath().c_str());
 
1335
  ProtoCache::iterator iter;
 
1336
 
 
1337
  pthread_mutex_lock(&proto_cache_mutex);
 
1338
  iter= proto_cache.find(table_path.c_str());
 
1339
 
 
1340
  if (iter!= proto_cache.end())
 
1341
    proto_cache.erase(iter);
 
1342
 
 
1343
  pthread_mutex_unlock(&proto_cache_mutex);
 
1344
 
 
1345
  return mi_delete_table(table_path.c_str());
1340
1346
}
1341
1347
 
1342
1348
 
1348
1354
                                       F_UNLCK : F_EXTRA_LCK));
1349
1355
}
1350
1356
 
1351
 
int MyisamEngine::doCreateTable(Session *session,
 
1357
int MyisamEngine::doCreateTable(Session *, const char *table_name,
1352
1358
                                Table& table_arg,
1353
 
                                drizzled::TableIdentifier &identifier,
1354
1359
                                message::Table& create_proto)
1355
1360
{
1356
1361
  int error;
1382
1387
    create_flags|= HA_PACK_RECORD;
1383
1388
 
1384
1389
  /* TODO: Check that the following internal::fn_format is really needed */
1385
 
  error= mi_create(internal::fn_format(buff, identifier.getPath().c_str(), "", "",
1386
 
                                       MY_UNPACK_FILENAME|MY_APPEND_EXT),
 
1390
  error= mi_create(internal::fn_format(buff, table_name, "", "",
 
1391
                             MY_UNPACK_FILENAME|MY_APPEND_EXT),
1387
1392
                   share->keys, keydef,
1388
1393
                   create_records, recinfo,
1389
1394
                   0, (MI_UNIQUEDEF*) 0,
1390
1395
                   &create_info, create_flags);
1391
1396
  free((unsigned char*) recinfo);
1392
1397
 
1393
 
  session->storeTableMessage(identifier, create_proto);
 
1398
  pthread_mutex_lock(&proto_cache_mutex);
 
1399
  proto_cache.insert(make_pair(table_name, create_proto));
 
1400
  pthread_mutex_unlock(&proto_cache_mutex);
1394
1401
 
1395
1402
  return error;
1396
1403
}
1397
1404
 
1398
1405
 
1399
 
int MyisamEngine::doRenameTable(Session &session, TableIdentifier &from, TableIdentifier &to)
 
1406
int MyisamEngine::doRenameTable(Session*,
 
1407
                                const char *from, const char *to)
1400
1408
{
1401
 
  session.renameTableMessage(from, to);
1402
 
 
1403
 
  return mi_rename(from.getPath().c_str(), to.getPath().c_str());
 
1409
  return mi_rename(from,to);
1404
1410
}
1405
1411
 
1406
1412
 
1492
1498
 
1493
1499
static MyisamEngine *engine= NULL;
1494
1500
 
1495
 
static int myisam_init(plugin::Context &context)
 
1501
static int myisam_init(plugin::Registry &registry)
1496
1502
{
 
1503
  int error;
1497
1504
  engine= new MyisamEngine(engine_name);
1498
 
  context.add(engine);
 
1505
  registry.add(engine);
 
1506
 
 
1507
  pthread_mutex_init(&THR_LOCK_myisam,MY_MUTEX_INIT_FAST);
1499
1508
 
1500
1509
  /* call ha_init_key_cache() on all key caches to init them */
1501
 
  int error= init_key_cache(dflt_key_cache,
1502
 
                            myisam_key_cache_block_size,
1503
 
                            myisam_key_cache_size,
1504
 
                            myisam_key_cache_division_limit, 
1505
 
                            myisam_key_cache_age_threshold);
 
1510
  error= init_key_cache(dflt_key_cache,
 
1511
                        myisam_key_cache_block_size,
 
1512
                        myisam_key_cache_size,
 
1513
                        myisam_key_cache_division_limit, 
 
1514
                        myisam_key_cache_age_threshold);
1506
1515
 
1507
1516
  if (error == 0)
1508
1517
    exit(1); /* Memory Allocation Failure */
1510
1519
  return 0;
1511
1520
}
1512
1521
 
 
1522
static int myisam_deinit(plugin::Registry &registry)
 
1523
{
 
1524
  registry.remove(engine);
 
1525
  delete engine;
 
1526
 
 
1527
  pthread_mutex_destroy(&THR_LOCK_myisam);
 
1528
  end_key_cache(dflt_key_cache, 1);             // Can never fail
 
1529
 
 
1530
  return mi_panic(HA_PANIC_CLOSE);
 
1531
}
1513
1532
 
1514
1533
static void sys_var_key_cache_size_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1515
1534
{
1702
1721
  "Default engine as of MySQL 3.23 with great performance",
1703
1722
  PLUGIN_LICENSE_GPL,
1704
1723
  myisam_init, /* Plugin Init */
 
1724
  myisam_deinit, /* Plugin Deinit */
1705
1725
  sys_variables,           /* system variables */
1706
1726
  NULL                        /* config options                  */
1707
1727
}