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"
35
#include "drizzled/field/timestamp.h"
34
36
#include "drizzled/memory/multi_malloc.h"
35
37
#include "drizzled/plugin/daemon.h"
37
#include <drizzled/plugin/storage_engine.h>
39
39
#include <boost/algorithm/string.hpp>
40
#include <boost/scoped_ptr.hpp>
45
44
#include <algorithm>
47
#include <boost/program_options.hpp>
48
#include <drizzled/module/option_map.h>
50
namespace po= boost::program_options;
52
46
using namespace std;
53
47
using namespace drizzled;
49
extern pthread_mutex_t LOCK_global_system_variables;
55
50
static const string engine_name("MyISAM");
57
boost::mutex THR_LOCK_myisam;
52
pthread_mutex_t THR_LOCK_myisam= PTHREAD_MUTEX_INITIALIZER;
59
static uint32_t myisam_key_cache_block_size= KEY_CACHE_BLOCK_SIZE;
54
static uint32_t repair_threads;
55
static uint32_t myisam_key_cache_block_size;
60
56
static uint32_t myisam_key_cache_size;
61
57
static uint32_t myisam_key_cache_division_limit;
62
58
static uint32_t myisam_key_cache_age_threshold;
63
59
static uint64_t max_sort_file_size;
64
typedef constrained_check<size_t, SIZE_MAX, 1024, 1024> sort_buffer_constraint;
65
static sort_buffer_constraint sort_buffer_size;
67
void st_mi_isam_share::setKeyCache()
69
(void)init_key_cache(&key_cache,
70
myisam_key_cache_block_size,
71
myisam_key_cache_size,
72
myisam_key_cache_division_limit,
73
myisam_key_cache_age_threshold);
60
static uint64_t sort_buffer_size;
76
62
/*****************************************************************************
1496
1487
return (uint)file->state->checksum;
1490
static MyisamEngine *engine= NULL;
1499
1492
static int myisam_init(module::Context &context)
1501
context.add(new MyisamEngine(engine_name));
1502
context.registerVariable(new sys_var_constrained_value<size_t>("sort-buffer-size",
1504
context.registerVariable(new sys_var_uint64_t_ptr("max_sort_file_size",
1505
&max_sort_file_size,
1506
context.getOptions()["max-sort-file-size"].as<uint64_t>()));
1494
engine= new MyisamEngine(engine_name);
1495
context.add(engine);
1497
/* call ha_init_key_cache() on all key caches to init them */
1498
int error= init_key_cache(dflt_key_cache,
1499
myisam_key_cache_block_size,
1500
myisam_key_cache_size,
1501
myisam_key_cache_division_limit,
1502
myisam_key_cache_age_threshold);
1505
exit(1); /* Memory Allocation Failure */
1512
static void init_options(drizzled::module::option_context &context)
1514
context("max-sort-file-size",
1515
po::value<uint64_t>(&max_sort_file_size)->default_value(INT32_MAX),
1516
_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."));
1517
context("sort-buffer-size",
1518
po::value<sort_buffer_constraint>(&sort_buffer_size)->default_value(8192*1024),
1519
_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."));
1511
static void sys_var_key_cache_size_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1513
uint32_t tmp= *static_cast<const uint32_t *>(save);
1516
struct option option_limits;
1517
plugin_opt_set_limits(&option_limits, var);
1518
option_limits.name= "myisam_key_cache_size";
1520
if (dflt_key_cache->in_init)
1523
myisam_key_cache_size= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1525
/* If key cache didn't existed initialize it, else resize it */
1526
dflt_key_cache->in_init= 1;
1528
error= ! resize_key_cache(dflt_key_cache,
1529
myisam_key_cache_block_size,
1530
myisam_key_cache_size,
1531
myisam_key_cache_division_limit,
1532
myisam_key_cache_age_threshold);
1533
dflt_key_cache->in_init= 0;
1536
static void sys_var_key_cache_block_size_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1538
uint32_t tmp= *static_cast<const uint32_t *>(save);
1541
struct option option_limits;
1542
plugin_opt_set_limits(&option_limits, var);
1543
option_limits.name= "myisam_key_cache_block_size";
1545
if (dflt_key_cache->in_init)
1548
myisam_key_cache_block_size= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1550
dflt_key_cache->in_init= 1;
1552
error= ! resize_key_cache(dflt_key_cache,
1553
myisam_key_cache_block_size,
1554
myisam_key_cache_size,
1555
myisam_key_cache_division_limit,
1556
myisam_key_cache_age_threshold);
1558
dflt_key_cache->in_init= 0;
1561
static void sys_var_key_cache_division_limit_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1563
uint32_t tmp= *static_cast<const uint32_t *>(save);
1566
struct option option_limits;
1567
plugin_opt_set_limits(&option_limits, var);
1568
option_limits.name= "myisam_key_cache_division_limit";
1570
if (dflt_key_cache->in_init)
1573
myisam_key_cache_division_limit= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1575
dflt_key_cache->in_init= 1;
1577
error= ! resize_key_cache(dflt_key_cache,
1578
myisam_key_cache_block_size,
1579
myisam_key_cache_size,
1580
myisam_key_cache_division_limit,
1581
myisam_key_cache_age_threshold);
1583
dflt_key_cache->in_init= 0;
1586
static void sys_var_key_cache_age_threshold_update(Session *session, drizzle_sys_var *var, void *, const void *save)
1588
uint32_t tmp= *static_cast<const uint32_t *>(save);
1591
struct option option_limits;
1592
plugin_opt_set_limits(&option_limits, var);
1593
option_limits.name= "myisam_key_cache_age_threshold";
1595
if (dflt_key_cache->in_init)
1598
myisam_key_cache_age_threshold= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
1600
dflt_key_cache->in_init= 1;
1602
error= ! resize_key_cache(dflt_key_cache,
1603
myisam_key_cache_block_size,
1604
myisam_key_cache_size,
1605
myisam_key_cache_division_limit,
1606
myisam_key_cache_age_threshold);
1608
dflt_key_cache->in_init= 0;
1611
static DRIZZLE_SYSVAR_UINT(key_cache_block_size,
1612
myisam_key_cache_block_size,
1613
PLUGIN_VAR_RQCMDARG,
1614
N_("Block size to be used for MyISAM index pages."),
1616
sys_var_key_cache_block_size_update,
1617
KEY_CACHE_BLOCK_SIZE,
1622
static DRIZZLE_SYSVAR_UINT(key_cache_age_threshold, myisam_key_cache_age_threshold,
1623
PLUGIN_VAR_RQCMDARG,
1624
N_("This characterizes the number of hits a hot block has to be untouched "
1625
"until it is considered aged enough to be downgraded to a warm block. "
1626
"This specifies the percentage ratio of that number of hits to the "
1627
"total number of blocks in key cache"),
1629
sys_var_key_cache_age_threshold_update,
1635
static DRIZZLE_SYSVAR_UINT(key_cache_division_limit, myisam_key_cache_division_limit,
1636
PLUGIN_VAR_RQCMDARG,
1637
N_("The minimum percentage of warm blocks in key cache"),
1639
sys_var_key_cache_division_limit_update,
1645
static DRIZZLE_SYSVAR_UINT(key_cache_size,
1646
myisam_key_cache_size,
1647
PLUGIN_VAR_RQCMDARG,
1648
N_("The size of the buffer used for index blocks for MyISAM tables. "
1649
"Increase this to get better index handling (for all reads and multiple "
1650
"writes) to as much as you can afford;"),
1652
sys_var_key_cache_size_update,
1658
static DRIZZLE_SYSVAR_UINT(repair_threads, repair_threads,
1659
PLUGIN_VAR_RQCMDARG,
1660
N_("Number of threads to use when repairing MyISAM tables. The value of "
1661
"1 disables parallel repair."),
1662
NULL, NULL, 1, 1, UINT32_MAX, 0);
1664
static DRIZZLE_SYSVAR_ULONGLONG(max_sort_file_size, max_sort_file_size,
1665
PLUGIN_VAR_RQCMDARG,
1666
N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."),
1667
NULL, NULL, INT32_MAX, 0, UINT64_MAX, 0);
1669
static DRIZZLE_SYSVAR_ULONGLONG(sort_buffer_size, sort_buffer_size,
1670
PLUGIN_VAR_RQCMDARG,
1671
N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."),
1672
NULL, NULL, 8192*1024, 1024, SIZE_MAX, 0);
1674
extern uint32_t data_pointer_size;
1675
static DRIZZLE_SYSVAR_UINT(data_pointer_size, data_pointer_size,
1676
PLUGIN_VAR_RQCMDARG,
1677
N_("Default pointer size to be used for MyISAM tables."),
1678
NULL, NULL, 6, 2, 7, 0);
1680
static drizzle_sys_var* sys_variables[]= {
1681
DRIZZLE_SYSVAR(key_cache_block_size),
1682
DRIZZLE_SYSVAR(key_cache_size),
1683
DRIZZLE_SYSVAR(key_cache_division_limit),
1684
DRIZZLE_SYSVAR(key_cache_age_threshold),
1685
DRIZZLE_SYSVAR(repair_threads),
1686
DRIZZLE_SYSVAR(max_sort_file_size),
1687
DRIZZLE_SYSVAR(sort_buffer_size),
1688
DRIZZLE_SYSVAR(data_pointer_size),
1523
1693
DRIZZLE_DECLARE_PLUGIN
1525
1695
DRIZZLE_VERSION_ID,
1529
1699
"Default engine as of MySQL 3.23 with great performance",
1530
1700
PLUGIN_LICENSE_GPL,
1531
1701
myisam_init, /* Plugin Init */
1533
init_options /* config options */
1702
sys_variables, /* system variables */
1703
NULL /* config options */
1535
1705
DRIZZLE_DECLARE_PLUGIN_END;