28
28
#include "drizzled/errmsg_print.h"
29
29
#include "drizzled/gettext.h"
30
30
#include "drizzled/session.h"
31
#include "drizzled/set_var.h"
32
#include <drizzled/plugin.h>
31
#include "drizzled/plugin.h"
33
32
#include "drizzled/plugin/client.h"
34
33
#include "drizzled/table.h"
35
#include "drizzled/field/timestamp.h"
36
34
#include "drizzled/memory/multi_malloc.h"
37
35
#include "drizzled/plugin/daemon.h"
37
#include <boost/algorithm/string.hpp>
38
#include <boost/scoped_ptr.hpp>
42
43
#include <algorithm>
45
#include <boost/program_options.hpp>
46
#include <drizzled/module/option_map.h>
48
namespace po= boost::program_options;
44
50
using namespace std;
45
51
using namespace drizzled;
47
extern pthread_mutex_t LOCK_global_system_variables;
48
53
static const string engine_name("MyISAM");
50
pthread_mutex_t THR_LOCK_myisam= PTHREAD_MUTEX_INITIALIZER;
55
boost::mutex THR_LOCK_myisam;
52
static uint32_t repair_threads;
53
static uint32_t myisam_key_cache_block_size;
57
static uint32_t myisam_key_cache_block_size= KEY_CACHE_BLOCK_SIZE;
54
58
static uint32_t myisam_key_cache_size;
55
59
static uint32_t myisam_key_cache_division_limit;
56
60
static uint32_t myisam_key_cache_age_threshold;
57
61
static uint64_t max_sort_file_size;
58
static uint64_t sort_buffer_size;
62
typedef constrained_check<size_t, SIZE_MAX, 1024, 1024> sort_buffer_constraint;
63
static sort_buffer_constraint sort_buffer_size;
65
void st_mi_isam_share::setKeyCache()
67
(void)init_key_cache(&key_cache,
68
myisam_key_cache_block_size,
69
myisam_key_cache_size,
70
myisam_key_cache_division_limit,
71
myisam_key_cache_age_threshold);
60
74
/*****************************************************************************
135
140
HA_KEYREAD_ONLY);
137
bool doDoesTableExist(Session& session, TableIdentifier &identifier);
142
bool doDoesTableExist(Session& session, const identifier::Table &identifier);
139
144
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
140
drizzled::SchemaIdentifier &schema_identifier,
141
drizzled::TableIdentifiers &set_of_identifiers);
145
const drizzled::identifier::Schema &schema_identifier,
146
drizzled::identifier::Table::vector &set_of_identifiers);
147
bool validateCreateTableOption(const std::string &key, const std::string &state)
150
if (boost::iequals(key, "ROW_FORMAT"))
144
159
void MyisamEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
145
drizzled::SchemaIdentifier&,
146
drizzled::TableIdentifiers&)
160
const drizzled::identifier::Schema&,
161
drizzled::identifier::Table::vector&)
150
bool MyisamEngine::doDoesTableExist(Session &session, TableIdentifier &identifier)
165
bool MyisamEngine::doDoesTableExist(Session &session, const identifier::Table &identifier)
152
return session.doesTableMessageExist(identifier);
167
return session.getMessageCache().doesTableMessageExist(identifier);
155
170
int MyisamEngine::doGetTableDefinition(Session &session,
156
drizzled::TableIdentifier &identifier,
171
const identifier::Table &identifier,
157
172
message::Table &table_message)
159
if (session.getTableMessage(identifier, table_message))
174
if (session.getMessageCache().getTableMessage(identifier, table_message))
201
216
uint32_t i, j, recpos, minpos, fieldpos, temp_length, length;
202
217
enum ha_base_keytype type= HA_KEYTYPE_BINARY;
203
218
unsigned char *record;
205
219
MI_KEYDEF *keydef;
206
220
MI_COLUMNDEF *recinfo, *recinfo_pos;
207
221
HA_KEYSEG *keyseg;
208
TableShare *share= table_arg->s;
222
TableShare *share= table_arg->getMutableShare();
209
223
uint32_t options= share->db_options_in_use;
210
224
if (!(memory::multi_malloc(false,
211
recinfo_out, (share->fields * 2 + 2) * sizeof(MI_COLUMNDEF),
212
keydef_out, share->keys * sizeof(MI_KEYDEF),
213
&keyseg, (share->key_parts + share->keys) * sizeof(HA_KEYSEG),
225
recinfo_out, (share->sizeFields() * 2 + 2) * sizeof(MI_COLUMNDEF),
226
keydef_out, share->sizeKeys() * sizeof(MI_KEYDEF),
227
&keyseg, (share->key_parts + share->sizeKeys()) * sizeof(HA_KEYSEG),
215
229
return(HA_ERR_OUT_OF_MEM);
216
230
keydef= *keydef_out;
217
231
recinfo= *recinfo_out;
218
pos= table_arg->key_info;
219
for (i= 0; i < share->keys; i++, pos++)
232
for (i= 0; i < share->sizeKeys(); i++)
234
KeyInfo *pos= &table_arg->key_info[i];
221
235
keydef[i].flag= ((uint16_t) pos->flags & (HA_NOSAME));
222
236
keydef[i].key_alg= HA_KEY_ALG_BTREE;
223
237
keydef[i].block_length= pos->block_size;
1499
1494
return (uint)file->state->checksum;
1502
static MyisamEngine *engine= NULL;
1504
static int myisam_init(plugin::Context &context)
1506
engine= new MyisamEngine(engine_name);
1507
context.add(engine);
1509
/* call ha_init_key_cache() on all key caches to init them */
1510
int 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);
1517
exit(1); /* Memory Allocation Failure */
1497
static int myisam_init(module::Context &context)
1499
context.add(new MyisamEngine(engine_name));
1500
context.registerVariable(new sys_var_constrained_value<size_t>("sort-buffer-size",
1502
context.registerVariable(new sys_var_uint64_t_ptr("max_sort_file_size",
1503
&max_sort_file_size,
1504
context.getOptions()["max-sort-file-size"].as<uint64_t>()));
1523
static void sys_var_key_cache_size_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1525
uint32_t tmp= *static_cast<const uint32_t *>(save);
1528
struct option option_limits;
1529
plugin_opt_set_limits(&option_limits, var);
1530
option_limits.name= "myisam_key_cache_size";
1532
if (dflt_key_cache->in_init)
1535
myisam_key_cache_size= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1537
/* If key cache didn't existed initialize it, else resize it */
1538
dflt_key_cache->in_init= 1;
1540
error= ! resize_key_cache(dflt_key_cache,
1541
myisam_key_cache_block_size,
1542
myisam_key_cache_size,
1543
myisam_key_cache_division_limit,
1544
myisam_key_cache_age_threshold);
1545
dflt_key_cache->in_init= 0;
1548
static void sys_var_key_cache_block_size_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1550
uint32_t tmp= *static_cast<const uint32_t *>(save);
1553
struct option option_limits;
1554
plugin_opt_set_limits(&option_limits, var);
1555
option_limits.name= "myisam_key_cache_block_size";
1557
if (dflt_key_cache->in_init)
1560
myisam_key_cache_block_size= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1562
dflt_key_cache->in_init= 1;
1564
error= ! resize_key_cache(dflt_key_cache,
1565
myisam_key_cache_block_size,
1566
myisam_key_cache_size,
1567
myisam_key_cache_division_limit,
1568
myisam_key_cache_age_threshold);
1570
dflt_key_cache->in_init= 0;
1573
static void sys_var_key_cache_division_limit_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1575
uint32_t tmp= *static_cast<const uint32_t *>(save);
1578
struct option option_limits;
1579
plugin_opt_set_limits(&option_limits, var);
1580
option_limits.name= "myisam_key_cache_division_limit";
1582
if (dflt_key_cache->in_init)
1585
myisam_key_cache_division_limit= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1587
dflt_key_cache->in_init= 1;
1589
error= ! resize_key_cache(dflt_key_cache,
1590
myisam_key_cache_block_size,
1591
myisam_key_cache_size,
1592
myisam_key_cache_division_limit,
1593
myisam_key_cache_age_threshold);
1595
dflt_key_cache->in_init= 0;
1598
static void sys_var_key_cache_age_threshold_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1600
uint32_t tmp= *static_cast<const uint32_t *>(save);
1603
struct option option_limits;
1604
plugin_opt_set_limits(&option_limits, var);
1605
option_limits.name= "myisam_key_cache_age_threshold";
1607
if (dflt_key_cache->in_init)
1610
myisam_key_cache_age_threshold= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1612
dflt_key_cache->in_init= 1;
1614
error= ! resize_key_cache(dflt_key_cache,
1615
myisam_key_cache_block_size,
1616
myisam_key_cache_size,
1617
myisam_key_cache_division_limit,
1618
myisam_key_cache_age_threshold);
1620
dflt_key_cache->in_init= 0;
1623
static DRIZZLE_SYSVAR_UINT(key_cache_block_size,
1624
myisam_key_cache_block_size,
1625
PLUGIN_VAR_RQCMDARG,
1626
N_("Block size to be used for MyISAM index pages."),
1628
sys_var_key_cache_block_size_update,
1629
KEY_CACHE_BLOCK_SIZE,
1634
static DRIZZLE_SYSVAR_UINT(key_cache_age_threshold, myisam_key_cache_age_threshold,
1635
PLUGIN_VAR_RQCMDARG,
1636
N_("This characterizes the number of hits a hot block has to be untouched "
1637
"until it is considered aged enough to be downgraded to a warm block. "
1638
"This specifies the percentage ratio of that number of hits to the "
1639
"total number of blocks in key cache"),
1641
sys_var_key_cache_age_threshold_update,
1647
static DRIZZLE_SYSVAR_UINT(key_cache_division_limit, myisam_key_cache_division_limit,
1648
PLUGIN_VAR_RQCMDARG,
1649
N_("The minimum percentage of warm blocks in key cache"),
1651
sys_var_key_cache_division_limit_update,
1657
static DRIZZLE_SYSVAR_UINT(key_cache_size,
1658
myisam_key_cache_size,
1659
PLUGIN_VAR_RQCMDARG,
1660
N_("The size of the buffer used for index blocks for MyISAM tables. "
1661
"Increase this to get better index handling (for all reads and multiple "
1662
"writes) to as much as you can afford;"),
1664
sys_var_key_cache_size_update,
1670
static DRIZZLE_SYSVAR_UINT(repair_threads, repair_threads,
1671
PLUGIN_VAR_RQCMDARG,
1672
N_("Number of threads to use when repairing MyISAM tables. The value of "
1673
"1 disables parallel repair."),
1674
NULL, NULL, 1, 1, UINT32_MAX, 0);
1676
static DRIZZLE_SYSVAR_ULONGLONG(max_sort_file_size, max_sort_file_size,
1677
PLUGIN_VAR_RQCMDARG,
1678
N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."),
1679
NULL, NULL, INT32_MAX, 0, UINT64_MAX, 0);
1681
static DRIZZLE_SYSVAR_ULONGLONG(sort_buffer_size, sort_buffer_size,
1682
PLUGIN_VAR_RQCMDARG,
1683
N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."),
1684
NULL, NULL, 8192*1024, 1024, SIZE_MAX, 0);
1686
extern uint32_t data_pointer_size;
1687
static DRIZZLE_SYSVAR_UINT(data_pointer_size, data_pointer_size,
1688
PLUGIN_VAR_RQCMDARG,
1689
N_("Default pointer size to be used for MyISAM tables."),
1690
NULL, NULL, 6, 2, 7, 0);
1692
static drizzle_sys_var* sys_variables[]= {
1693
DRIZZLE_SYSVAR(key_cache_block_size),
1694
DRIZZLE_SYSVAR(key_cache_size),
1695
DRIZZLE_SYSVAR(key_cache_division_limit),
1696
DRIZZLE_SYSVAR(key_cache_age_threshold),
1697
DRIZZLE_SYSVAR(repair_threads),
1698
DRIZZLE_SYSVAR(max_sort_file_size),
1699
DRIZZLE_SYSVAR(sort_buffer_size),
1700
DRIZZLE_SYSVAR(data_pointer_size),
1510
static void init_options(drizzled::module::option_context &context)
1512
context("max-sort-file-size",
1513
po::value<uint64_t>(&max_sort_file_size)->default_value(INT32_MAX),
1514
_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."));
1515
context("sort-buffer-size",
1516
po::value<sort_buffer_constraint>(&sort_buffer_size)->default_value(8192*1024),
1517
_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."));
1705
1521
DRIZZLE_DECLARE_PLUGIN
1707
1523
DRIZZLE_VERSION_ID,
1711
1527
"Default engine as of MySQL 3.23 with great performance",
1712
1528
PLUGIN_LICENSE_GPL,
1713
1529
myisam_init, /* Plugin Init */
1714
sys_variables, /* system variables */
1715
NULL /* config options */
1531
init_options /* config options */
1717
1533
DRIZZLE_DECLARE_PLUGIN_END;