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
#include "drizzled/plugin/daemon.h"
38
#include <boost/algorithm/string.hpp>
39
#include <boost/scoped_ptr.hpp>
44
41
#include <algorithm>
46
#include <boost/program_options.hpp>
47
#include <drizzled/module/option_map.h>
49
namespace po= boost::program_options;
51
43
using namespace std;
52
44
using namespace drizzled;
46
extern pthread_mutex_t LOCK_global_system_variables;
54
47
static const string engine_name("MyISAM");
56
boost::mutex THR_LOCK_myisam;
49
pthread_mutex_t THR_LOCK_myisam= PTHREAD_MUTEX_INITIALIZER;
58
static uint32_t myisam_key_cache_block_size= KEY_CACHE_BLOCK_SIZE;
51
static uint32_t repair_threads;
52
static uint32_t myisam_key_cache_block_size;
59
53
static uint32_t myisam_key_cache_size;
60
54
static uint32_t myisam_key_cache_division_limit;
61
55
static uint32_t myisam_key_cache_age_threshold;
62
56
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);
57
static uint64_t sort_buffer_size;
75
59
/*****************************************************************************
85
69
class MyisamEngine : public plugin::StorageEngine
88
MyisamEngine(const MyisamEngine&);
89
MyisamEngine& operator=(const MyisamEngine&);
91
explicit MyisamEngine(string name_arg) :
92
plugin::StorageEngine(name_arg,
93
HTON_CAN_INDEX_BLOBS |
94
HTON_STATS_RECORDS_IS_EXACT |
100
HTON_SKIP_STORE_LOCK)
104
virtual ~MyisamEngine()
106
mi_panic(HA_PANIC_CLOSE);
109
virtual Cursor *create(Table &table)
111
return new ha_myisam(*this, table);
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 |
82
HTON_SKIP_STORE_LOCK |
88
virtual Cursor *create(TableShare &table,
89
memory::Root *mem_root)
91
return new (mem_root) ha_myisam(*this, table);
114
94
const char **bas_ext() const {
115
95
return ha_myisam_exts;
118
int doCreateTable(Session&,
98
int doCreateTable(Session *,
120
const TableIdentifier &identifier,
100
drizzled::TableIdentifier &identifier,
121
101
message::Table&);
123
int doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to);
103
int doRenameTable(Session*, const char *from, const char *to);
125
int doDropTable(Session&, const TableIdentifier &identifier);
105
int doDropTable(Session&, drizzled::TableIdentifier &identifier);
127
107
int doGetTableDefinition(Session& session,
128
const TableIdentifier &identifier,
108
drizzled::TableIdentifier &identifier,
129
109
message::Table &table_message);
111
/* Temp only engine, so do not return values. */
112
void doGetTableNames(CachedDirectory &, string& , set<string>&) { };
131
114
uint32_t max_supported_keys() const { return MI_MAX_KEY; }
132
115
uint32_t max_supported_key_length() const { return MI_MAX_KEY_LENGTH; }
133
116
uint32_t max_supported_key_part_length() const { return MI_MAX_KEY_LENGTH; }
141
124
HA_KEYREAD_ONLY);
143
bool doDoesTableExist(Session& session, const TableIdentifier &identifier);
145
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"))
126
bool doDoesTableExist(Session& session, TableIdentifier &identifier);
160
void MyisamEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
161
const drizzled::SchemaIdentifier&,
162
drizzled::TableIdentifier::vector&)
166
bool MyisamEngine::doDoesTableExist(Session &session, const TableIdentifier &identifier)
168
return session.getMessageCache().doesTableMessageExist(identifier);
171
int MyisamEngine::doGetTableDefinition(Session &session,
172
const TableIdentifier &identifier,
173
message::Table &table_message)
175
if (session.getMessageCache().getTableMessage(identifier, table_message))
129
bool MyisamEngine::doDoesTableExist(Session&, TableIdentifier &identifier)
131
ProtoCache::iterator iter;
133
pthread_mutex_lock(&proto_cache_mutex);
134
iter= proto_cache.find(identifier.getPath());
136
if (iter != proto_cache.end())
140
pthread_mutex_unlock(&proto_cache_mutex);
145
int MyisamEngine::doGetTableDefinition(Session&,
146
drizzled::TableIdentifier &identifier,
147
message::Table &table_proto)
150
ProtoCache::iterator iter;
152
pthread_mutex_lock(&proto_cache_mutex);
153
iter= proto_cache.find(identifier.getPath());
155
if (iter != proto_cache.end())
157
table_proto.CopyFrom(((*iter).second));
160
pthread_mutex_unlock(&proto_cache_mutex);
1487
1509
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>()));
1512
static MyisamEngine *engine= NULL;
1514
static int myisam_init(plugin::Registry ®istry)
1517
engine= new MyisamEngine(engine_name);
1518
registry.add(engine);
1520
pthread_mutex_init(&THR_LOCK_myisam,MY_MUTEX_INIT_FAST);
1522
/* call ha_init_key_cache() on all key caches to init them */
1523
error= init_key_cache(dflt_key_cache,
1524
myisam_key_cache_block_size,
1525
myisam_key_cache_size,
1526
myisam_key_cache_division_limit,
1527
myisam_key_cache_age_threshold);
1530
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."));
1535
static int myisam_deinit(plugin::Registry ®istry)
1537
registry.remove(engine);
1540
pthread_mutex_destroy(&THR_LOCK_myisam);
1541
end_key_cache(dflt_key_cache, 1); // Can never fail
1543
return mi_panic(HA_PANIC_CLOSE);
1546
static void sys_var_key_cache_size_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1548
uint32_t tmp= *static_cast<const uint32_t *>(save);
1551
struct my_option option_limits;
1552
plugin_opt_set_limits(&option_limits, var);
1553
option_limits.name= "myisam_key_cache_size";
1555
if (dflt_key_cache->in_init)
1558
myisam_key_cache_size= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1560
/* If key cache didn't existed initialize it, else resize it */
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);
1568
dflt_key_cache->in_init= 0;
1571
static void sys_var_key_cache_block_size_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1573
uint32_t tmp= *static_cast<const uint32_t *>(save);
1576
struct my_option option_limits;
1577
plugin_opt_set_limits(&option_limits, var);
1578
option_limits.name= "myisam_key_cache_block_size";
1580
if (dflt_key_cache->in_init)
1583
myisam_key_cache_block_size= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1585
dflt_key_cache->in_init= 1;
1587
error= ! resize_key_cache(dflt_key_cache,
1588
myisam_key_cache_block_size,
1589
myisam_key_cache_size,
1590
myisam_key_cache_division_limit,
1591
myisam_key_cache_age_threshold);
1593
dflt_key_cache->in_init= 0;
1596
static void sys_var_key_cache_division_limit_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1598
uint32_t tmp= *static_cast<const uint32_t *>(save);
1601
struct my_option option_limits;
1602
plugin_opt_set_limits(&option_limits, var);
1603
option_limits.name= "myisam_key_cache_division_limit";
1605
if (dflt_key_cache->in_init)
1608
myisam_key_cache_division_limit= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1610
dflt_key_cache->in_init= 1;
1612
error= ! resize_key_cache(dflt_key_cache,
1613
myisam_key_cache_block_size,
1614
myisam_key_cache_size,
1615
myisam_key_cache_division_limit,
1616
myisam_key_cache_age_threshold);
1618
dflt_key_cache->in_init= 0;
1621
static void sys_var_key_cache_age_threshold_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1623
uint32_t tmp= *static_cast<const uint32_t *>(save);
1626
struct my_option option_limits;
1627
plugin_opt_set_limits(&option_limits, var);
1628
option_limits.name= "myisam_key_cache_age_threshold";
1630
if (dflt_key_cache->in_init)
1633
myisam_key_cache_age_threshold= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1635
dflt_key_cache->in_init= 1;
1637
error= ! resize_key_cache(dflt_key_cache,
1638
myisam_key_cache_block_size,
1639
myisam_key_cache_size,
1640
myisam_key_cache_division_limit,
1641
myisam_key_cache_age_threshold);
1643
dflt_key_cache->in_init= 0;
1646
static DRIZZLE_SYSVAR_UINT(key_cache_block_size,
1647
myisam_key_cache_block_size,
1648
PLUGIN_VAR_RQCMDARG,
1649
N_("Block size to be used for MyISAM index pages."),
1651
sys_var_key_cache_block_size_update,
1652
KEY_CACHE_BLOCK_SIZE,
1657
static DRIZZLE_SYSVAR_UINT(key_cache_age_threshold, myisam_key_cache_age_threshold,
1658
PLUGIN_VAR_RQCMDARG,
1659
N_("This characterizes the number of hits a hot block has to be untouched "
1660
"until it is considered aged enough to be downgraded to a warm block. "
1661
"This specifies the percentage ratio of that number of hits to the "
1662
"total number of blocks in key cache"),
1664
sys_var_key_cache_age_threshold_update,
1670
static DRIZZLE_SYSVAR_UINT(key_cache_division_limit, myisam_key_cache_division_limit,
1671
PLUGIN_VAR_RQCMDARG,
1672
N_("The minimum percentage of warm blocks in key cache"),
1674
sys_var_key_cache_division_limit_update,
1680
static DRIZZLE_SYSVAR_UINT(key_cache_size,
1681
myisam_key_cache_size,
1682
PLUGIN_VAR_RQCMDARG,
1683
N_("The size of the buffer used for index blocks for MyISAM tables. "
1684
"Increase this to get better index handling (for all reads and multiple "
1685
"writes) to as much as you can afford;"),
1687
sys_var_key_cache_size_update,
1693
static DRIZZLE_SYSVAR_UINT(repair_threads, repair_threads,
1694
PLUGIN_VAR_RQCMDARG,
1695
N_("Number of threads to use when repairing MyISAM tables. The value of "
1696
"1 disables parallel repair."),
1697
NULL, NULL, 1, 1, UINT32_MAX, 0);
1699
static DRIZZLE_SYSVAR_ULONGLONG(max_sort_file_size, max_sort_file_size,
1700
PLUGIN_VAR_RQCMDARG,
1701
N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."),
1702
NULL, NULL, INT32_MAX, 0, UINT64_MAX, 0);
1704
static DRIZZLE_SYSVAR_ULONGLONG(sort_buffer_size, sort_buffer_size,
1705
PLUGIN_VAR_RQCMDARG,
1706
N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."),
1707
NULL, NULL, 8192*1024, 1024, SIZE_MAX, 0);
1709
extern uint32_t data_pointer_size;
1710
static DRIZZLE_SYSVAR_UINT(data_pointer_size, data_pointer_size,
1711
PLUGIN_VAR_RQCMDARG,
1712
N_("Default pointer size to be used for MyISAM tables."),
1713
NULL, NULL, 6, 2, 7, 0);
1715
static drizzle_sys_var* sys_variables[]= {
1716
DRIZZLE_SYSVAR(key_cache_block_size),
1717
DRIZZLE_SYSVAR(key_cache_size),
1718
DRIZZLE_SYSVAR(key_cache_division_limit),
1719
DRIZZLE_SYSVAR(key_cache_age_threshold),
1720
DRIZZLE_SYSVAR(repair_threads),
1721
DRIZZLE_SYSVAR(max_sort_file_size),
1722
DRIZZLE_SYSVAR(sort_buffer_size),
1723
DRIZZLE_SYSVAR(data_pointer_size),
1514
1728
DRIZZLE_DECLARE_PLUGIN
1516
1730
DRIZZLE_VERSION_ID,
1520
1734
"Default engine as of MySQL 3.23 with great performance",
1521
1735
PLUGIN_LICENSE_GPL,
1522
1736
myisam_init, /* Plugin Init */
1523
NULL, /* system variables */
1524
init_options /* config options */
1737
myisam_deinit, /* Plugin Deinit */
1738
sys_variables, /* system variables */
1739
NULL /* config options */
1526
1741
DRIZZLE_DECLARE_PLUGIN_END;