~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/ha_myisam.cc

  • Committer: Stewart Smith
  • Date: 2010-11-03 03:30:27 UTC
  • mto: (1902.1.1 build) (1910.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1903.
  • Revision ID: stewart@flamingspork.com-20101103033027-lskb6gxwwforfz71
fix docs warning: underline/overline too short for replace.rst

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include "drizzled/plugin/daemon.h"
37
37
 
38
38
#include <boost/algorithm/string.hpp>
39
 
#include <boost/scoped_ptr.hpp>
40
39
 
41
40
#include <string>
42
41
#include <sstream>
43
42
#include <map>
44
43
#include <algorithm>
45
 
#include <memory>
46
44
#include <boost/program_options.hpp>
47
45
#include <drizzled/module/option_map.h>
48
46
 
60
58
static uint32_t myisam_key_cache_division_limit;
61
59
static uint32_t myisam_key_cache_age_threshold;
62
60
static uint64_t max_sort_file_size;
63
 
typedef constrained_check<size_t, SIZE_MAX, 1024, 1024> sort_buffer_constraint;
64
 
static sort_buffer_constraint sort_buffer_size;
 
61
static uint64_t sort_buffer_size;
65
62
 
66
63
void st_mi_isam_share::setKeyCache()
67
64
{
144
141
 
145
142
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
146
143
                             const drizzled::SchemaIdentifier &schema_identifier,
147
 
                             drizzled::TableIdentifier::vector &set_of_identifiers);
 
144
                             drizzled::TableIdentifiers &set_of_identifiers);
148
145
  bool validateCreateTableOption(const std::string &key, const std::string &state)
149
146
  {
150
147
    (void)state;
159
156
 
160
157
void MyisamEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
161
158
                                         const drizzled::SchemaIdentifier&,
162
 
                                         drizzled::TableIdentifier::vector&)
 
159
                                         drizzled::TableIdentifiers&)
163
160
{
164
161
}
165
162
 
166
163
bool MyisamEngine::doDoesTableExist(Session &session, const TableIdentifier &identifier)
167
164
{
168
 
  return session.getMessageCache().doesTableMessageExist(identifier);
 
165
  return session.doesTableMessageExist(identifier);
169
166
}
170
167
 
171
168
int MyisamEngine::doGetTableDefinition(Session &session,
172
169
                                       const TableIdentifier &identifier,
173
170
                                       message::Table &table_message)
174
171
{
175
 
  if (session.getMessageCache().getTableMessage(identifier, table_message))
 
172
  if (session.getTableMessage(identifier, table_message))
176
173
    return EEXIST;
177
174
  return ENOENT;
178
175
}
479
476
volatile int *killed_ptr(MI_CHECK *param)
480
477
{
481
478
  /* In theory Unsafe conversion, but should be ok for now */
482
 
  return (int*) (((Session *)(param->session))->getKilledPtr());
 
479
  return (int*) &(((Session *)(param->session))->killed);
483
480
}
484
481
 
485
482
void mi_check_print_error(MI_CHECK *param, const char *fmt,...)
703
700
  param.using_global_keycache = 1;
704
701
  param.session= session;
705
702
  param.out_flag= 0;
706
 
  param.sort_buffer_length= static_cast<size_t>(sort_buffer_size);
 
703
  param.sort_buffer_length= (size_t)sort_buffer_size;
707
704
  strcpy(fixed_name,file->filename);
708
705
 
709
706
  // Don't lock tables if we have used LOCK Table
905
902
  else if (mode == HA_KEY_SWITCH_NONUNIQ_SAVE)
906
903
  {
907
904
    Session *session= getTable()->in_use;
908
 
    boost::scoped_ptr<MI_CHECK> param_ap(new MI_CHECK);
909
 
    MI_CHECK &param= *param_ap.get();
 
905
    MI_CHECK param;
910
906
    const char *save_proc_info= session->get_proc_info();
911
907
    session->set_proc_info("Creating index");
912
908
    myisamchk_init(&param);
914
910
    param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK |
915
911
                     T_CREATE_MISSING_KEYS);
916
912
    param.myf_rw&= ~MY_WAIT_IF_FULL;
917
 
    param.sort_buffer_length=  static_cast<size_t>(sort_buffer_size);
 
913
    param.sort_buffer_length=  (size_t)sort_buffer_size;
918
914
    param.stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL;
919
915
    if ((error= (repair(session,param,0) != HA_ADMIN_OK)) && param.retry_repair)
920
916
    {
1331
1327
int MyisamEngine::doDropTable(Session &session,
1332
1328
                              const TableIdentifier &identifier)
1333
1329
{
1334
 
  session.getMessageCache().removeTableMessage(identifier);
 
1330
  session.removeTableMessage(identifier);
1335
1331
 
1336
1332
  return mi_delete_table(identifier.getPath().c_str());
1337
1333
}
1387
1383
                   &create_info, create_flags);
1388
1384
  free((unsigned char*) recinfo);
1389
1385
 
1390
 
  session.getMessageCache().storeTableMessage(identifier, create_proto);
 
1386
  session.storeTableMessage(identifier, create_proto);
1391
1387
 
1392
1388
  return error;
1393
1389
}
1395
1391
 
1396
1392
int MyisamEngine::doRenameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
1397
1393
{
1398
 
  session.getMessageCache().renameTableMessage(from, to);
 
1394
  session.renameTableMessage(from, to);
1399
1395
 
1400
1396
  return mi_rename(from.getPath().c_str(), to.getPath().c_str());
1401
1397
}
1487
1483
  return (uint)file->state->checksum;
1488
1484
}
1489
1485
 
 
1486
static MyisamEngine *engine= NULL;
 
1487
 
1490
1488
static int myisam_init(module::Context &context)
1491
1489
1492
 
  context.add(new MyisamEngine(engine_name));
1493
 
  context.registerVariable(new sys_var_constrained_value<size_t>("sort-buffer-size",
1494
 
                                                                 sort_buffer_size));
1495
 
  context.registerVariable(new sys_var_uint64_t_ptr("max_sort_file_size",
1496
 
                                                    &max_sort_file_size,
1497
 
                                                    context.getOptions()["max-sort-file-size"].as<uint64_t>()));
 
1490
  const module::option_map &vm= context.getOptions();
 
1491
 
 
1492
  if (vm.count("max-sort-file-size"))
 
1493
  {
 
1494
    if (max_sort_file_size > UINT64_MAX)
 
1495
    {
 
1496
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for max-sort-file-size\n"));
 
1497
      exit(-1);
 
1498
    }
 
1499
  }
 
1500
 
 
1501
  if (vm.count("sort-buffer-size"))
 
1502
  {
 
1503
    if (sort_buffer_size < 1024 || sort_buffer_size > SIZE_MAX)
 
1504
    {
 
1505
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for sort-buffer-size\n"));
 
1506
      exit(-1);
 
1507
    }
 
1508
  }
 
1509
 
 
1510
  engine= new MyisamEngine(engine_name);
 
1511
  context.add(engine);
1498
1512
 
1499
1513
  return 0;
1500
1514
}
1501
1515
 
1502
1516
 
 
1517
static DRIZZLE_SYSVAR_ULONGLONG(max_sort_file_size, max_sort_file_size,
 
1518
                                PLUGIN_VAR_RQCMDARG,
 
1519
                                N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."),
 
1520
                                NULL, NULL, INT32_MAX, 0, UINT64_MAX, 0);
 
1521
 
 
1522
static DRIZZLE_SYSVAR_ULONGLONG(sort_buffer_size, sort_buffer_size,
 
1523
                                PLUGIN_VAR_RQCMDARG,
 
1524
                                N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."),
 
1525
                                NULL, NULL, 8192*1024, 1024, SIZE_MAX, 0);
 
1526
 
1503
1527
static void init_options(drizzled::module::option_context &context)
1504
1528
{
1505
1529
  context("max-sort-file-size",
1506
1530
          po::value<uint64_t>(&max_sort_file_size)->default_value(INT32_MAX),
1507
1531
          N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."));
1508
1532
  context("sort-buffer-size",
1509
 
          po::value<sort_buffer_constraint>(&sort_buffer_size)->default_value(8192*1024),
 
1533
          po::value<uint64_t>(&sort_buffer_size)->default_value(8192*1024),
1510
1534
          N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."));
1511
1535
}
1512
1536
 
 
1537
static drizzle_sys_var* sys_variables[]= {
 
1538
  DRIZZLE_SYSVAR(max_sort_file_size),
 
1539
  DRIZZLE_SYSVAR(sort_buffer_size),
 
1540
  NULL
 
1541
};
 
1542
 
1513
1543
 
1514
1544
DRIZZLE_DECLARE_PLUGIN
1515
1545
{
1520
1550
  "Default engine as of MySQL 3.23 with great performance",
1521
1551
  PLUGIN_LICENSE_GPL,
1522
1552
  myisam_init, /* Plugin Init */
1523
 
  NULL,           /* system variables */
 
1553
  sys_variables,           /* system variables */
1524
1554
  init_options                        /* config options                  */
1525
1555
}
1526
1556
DRIZZLE_DECLARE_PLUGIN_END;