28
28
#include "drizzled/errmsg_print.h"
29
29
#include "drizzled/gettext.h"
30
30
#include "drizzled/session.h"
31
#include "drizzled/plugin.h"
31
#include "drizzled/set_var.h"
32
#include <drizzled/plugin.h>
32
33
#include "drizzled/plugin/client.h"
33
34
#include "drizzled/table.h"
34
35
#include "drizzled/field/timestamp.h"
35
36
#include "drizzled/memory/multi_malloc.h"
36
37
#include "drizzled/plugin/daemon.h"
38
#include <boost/algorithm/string.hpp>
39
#include <boost/scoped_ptr.hpp>
44
42
#include <algorithm>
46
#include <boost/program_options.hpp>
47
#include <drizzled/module/option_map.h>
49
namespace po= boost::program_options;
51
44
using namespace std;
52
45
using namespace drizzled;
47
extern pthread_mutex_t LOCK_global_system_variables;
54
48
static const string engine_name("MyISAM");
56
boost::mutex THR_LOCK_myisam;
50
pthread_mutex_t THR_LOCK_myisam= PTHREAD_MUTEX_INITIALIZER;
58
static uint32_t myisam_key_cache_block_size= KEY_CACHE_BLOCK_SIZE;
52
static uint32_t repair_threads;
53
static uint32_t myisam_key_cache_block_size;
59
54
static uint32_t myisam_key_cache_size;
60
55
static uint32_t myisam_key_cache_division_limit;
61
56
static uint32_t myisam_key_cache_age_threshold;
62
57
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;
66
void st_mi_isam_share::setKeyCache()
68
(void)init_key_cache(&key_cache,
69
myisam_key_cache_block_size,
70
myisam_key_cache_size,
71
myisam_key_cache_division_limit,
72
myisam_key_cache_age_threshold);
58
static uint64_t sort_buffer_size;
75
60
/*****************************************************************************
141
134
HA_KEYREAD_ONLY);
143
bool doDoesTableExist(Session& session, const TableIdentifier &identifier);
136
bool doDoesTableExist(Session& session, TableIdentifier &identifier);
145
138
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
146
const drizzled::SchemaIdentifier &schema_identifier,
147
drizzled::TableIdentifier::vector &set_of_identifiers);
148
bool validateCreateTableOption(const std::string &key, const std::string &state)
151
if (boost::iequals(key, "ROW_FORMAT"))
139
drizzled::SchemaIdentifier &schema_identifier,
140
drizzled::TableIdentifiers &set_of_identifiers);
160
143
void MyisamEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
161
const drizzled::SchemaIdentifier&,
162
drizzled::TableIdentifier::vector&)
144
drizzled::SchemaIdentifier&,
145
drizzled::TableIdentifiers&)
166
bool MyisamEngine::doDoesTableExist(Session &session, const TableIdentifier &identifier)
149
bool MyisamEngine::doDoesTableExist(Session &session, TableIdentifier &identifier)
168
return session.getMessageCache().doesTableMessageExist(identifier);
151
return session.doesTableMessageExist(identifier);
171
154
int MyisamEngine::doGetTableDefinition(Session &session,
172
const TableIdentifier &identifier,
155
drizzled::TableIdentifier &identifier,
173
156
message::Table &table_message)
175
if (session.getMessageCache().getTableMessage(identifier, table_message))
158
if (session.getTableMessage(identifier, table_message))
1487
1498
return (uint)file->state->checksum;
1490
static int myisam_init(module::Context &context)
1492
context.add(new MyisamEngine(engine_name));
1493
context.registerVariable(new sys_var_constrained_value<size_t>("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>()));
1501
static MyisamEngine *engine= NULL;
1503
static int myisam_init(plugin::Context &context)
1505
engine= new MyisamEngine(engine_name);
1506
context.add(engine);
1508
/* call ha_init_key_cache() on all key caches to init them */
1509
int error= init_key_cache(dflt_key_cache,
1510
myisam_key_cache_block_size,
1511
myisam_key_cache_size,
1512
myisam_key_cache_division_limit,
1513
myisam_key_cache_age_threshold);
1516
exit(1); /* Memory Allocation Failure */
1503
static void init_options(drizzled::module::option_context &context)
1505
context("max-sort-file-size",
1506
po::value<uint64_t>(&max_sort_file_size)->default_value(INT32_MAX),
1507
N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."));
1508
context("sort-buffer-size",
1509
po::value<sort_buffer_constraint>(&sort_buffer_size)->default_value(8192*1024),
1510
N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."));
1522
static void sys_var_key_cache_size_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1524
uint32_t tmp= *static_cast<const uint32_t *>(save);
1527
struct option option_limits;
1528
plugin_opt_set_limits(&option_limits, var);
1529
option_limits.name= "myisam_key_cache_size";
1531
if (dflt_key_cache->in_init)
1534
myisam_key_cache_size= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1536
/* If key cache didn't existed initialize it, else resize it */
1537
dflt_key_cache->in_init= 1;
1539
error= ! resize_key_cache(dflt_key_cache,
1540
myisam_key_cache_block_size,
1541
myisam_key_cache_size,
1542
myisam_key_cache_division_limit,
1543
myisam_key_cache_age_threshold);
1544
dflt_key_cache->in_init= 0;
1547
static void sys_var_key_cache_block_size_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1549
uint32_t tmp= *static_cast<const uint32_t *>(save);
1552
struct option option_limits;
1553
plugin_opt_set_limits(&option_limits, var);
1554
option_limits.name= "myisam_key_cache_block_size";
1556
if (dflt_key_cache->in_init)
1559
myisam_key_cache_block_size= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1561
dflt_key_cache->in_init= 1;
1563
error= ! resize_key_cache(dflt_key_cache,
1564
myisam_key_cache_block_size,
1565
myisam_key_cache_size,
1566
myisam_key_cache_division_limit,
1567
myisam_key_cache_age_threshold);
1569
dflt_key_cache->in_init= 0;
1572
static void sys_var_key_cache_division_limit_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1574
uint32_t tmp= *static_cast<const uint32_t *>(save);
1577
struct option option_limits;
1578
plugin_opt_set_limits(&option_limits, var);
1579
option_limits.name= "myisam_key_cache_division_limit";
1581
if (dflt_key_cache->in_init)
1584
myisam_key_cache_division_limit= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1586
dflt_key_cache->in_init= 1;
1588
error= ! resize_key_cache(dflt_key_cache,
1589
myisam_key_cache_block_size,
1590
myisam_key_cache_size,
1591
myisam_key_cache_division_limit,
1592
myisam_key_cache_age_threshold);
1594
dflt_key_cache->in_init= 0;
1597
static void sys_var_key_cache_age_threshold_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1599
uint32_t tmp= *static_cast<const uint32_t *>(save);
1602
struct option option_limits;
1603
plugin_opt_set_limits(&option_limits, var);
1604
option_limits.name= "myisam_key_cache_age_threshold";
1606
if (dflt_key_cache->in_init)
1609
myisam_key_cache_age_threshold= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1611
dflt_key_cache->in_init= 1;
1613
error= ! resize_key_cache(dflt_key_cache,
1614
myisam_key_cache_block_size,
1615
myisam_key_cache_size,
1616
myisam_key_cache_division_limit,
1617
myisam_key_cache_age_threshold);
1619
dflt_key_cache->in_init= 0;
1622
static DRIZZLE_SYSVAR_UINT(key_cache_block_size,
1623
myisam_key_cache_block_size,
1624
PLUGIN_VAR_RQCMDARG,
1625
N_("Block size to be used for MyISAM index pages."),
1627
sys_var_key_cache_block_size_update,
1628
KEY_CACHE_BLOCK_SIZE,
1633
static DRIZZLE_SYSVAR_UINT(key_cache_age_threshold, myisam_key_cache_age_threshold,
1634
PLUGIN_VAR_RQCMDARG,
1635
N_("This characterizes the number of hits a hot block has to be untouched "
1636
"until it is considered aged enough to be downgraded to a warm block. "
1637
"This specifies the percentage ratio of that number of hits to the "
1638
"total number of blocks in key cache"),
1640
sys_var_key_cache_age_threshold_update,
1646
static DRIZZLE_SYSVAR_UINT(key_cache_division_limit, myisam_key_cache_division_limit,
1647
PLUGIN_VAR_RQCMDARG,
1648
N_("The minimum percentage of warm blocks in key cache"),
1650
sys_var_key_cache_division_limit_update,
1656
static DRIZZLE_SYSVAR_UINT(key_cache_size,
1657
myisam_key_cache_size,
1658
PLUGIN_VAR_RQCMDARG,
1659
N_("The size of the buffer used for index blocks for MyISAM tables. "
1660
"Increase this to get better index handling (for all reads and multiple "
1661
"writes) to as much as you can afford;"),
1663
sys_var_key_cache_size_update,
1669
static DRIZZLE_SYSVAR_UINT(repair_threads, repair_threads,
1670
PLUGIN_VAR_RQCMDARG,
1671
N_("Number of threads to use when repairing MyISAM tables. The value of "
1672
"1 disables parallel repair."),
1673
NULL, NULL, 1, 1, UINT32_MAX, 0);
1675
static DRIZZLE_SYSVAR_ULONGLONG(max_sort_file_size, max_sort_file_size,
1676
PLUGIN_VAR_RQCMDARG,
1677
N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."),
1678
NULL, NULL, INT32_MAX, 0, UINT64_MAX, 0);
1680
static DRIZZLE_SYSVAR_ULONGLONG(sort_buffer_size, sort_buffer_size,
1681
PLUGIN_VAR_RQCMDARG,
1682
N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."),
1683
NULL, NULL, 8192*1024, 1024, SIZE_MAX, 0);
1685
extern uint32_t data_pointer_size;
1686
static DRIZZLE_SYSVAR_UINT(data_pointer_size, data_pointer_size,
1687
PLUGIN_VAR_RQCMDARG,
1688
N_("Default pointer size to be used for MyISAM tables."),
1689
NULL, NULL, 6, 2, 7, 0);
1691
static drizzle_sys_var* sys_variables[]= {
1692
DRIZZLE_SYSVAR(key_cache_block_size),
1693
DRIZZLE_SYSVAR(key_cache_size),
1694
DRIZZLE_SYSVAR(key_cache_division_limit),
1695
DRIZZLE_SYSVAR(key_cache_age_threshold),
1696
DRIZZLE_SYSVAR(repair_threads),
1697
DRIZZLE_SYSVAR(max_sort_file_size),
1698
DRIZZLE_SYSVAR(sort_buffer_size),
1699
DRIZZLE_SYSVAR(data_pointer_size),
1514
1704
DRIZZLE_DECLARE_PLUGIN
1516
1706
DRIZZLE_VERSION_ID,
1520
1710
"Default engine as of MySQL 3.23 with great performance",
1521
1711
PLUGIN_LICENSE_GPL,
1522
1712
myisam_init, /* Plugin Init */
1523
NULL, /* system variables */
1524
init_options /* config options */
1713
sys_variables, /* system variables */
1714
NULL /* config options */
1526
1716
DRIZZLE_DECLARE_PLUGIN_END;