~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/ha_myisam.cc

  • Committer: Brian Aker
  • Date: 2010-01-18 19:39:12 UTC
  • mfrom: (1251.2.9 working)
  • Revision ID: brian@gaz-20100118193912-rf7ncdnrhvowyfo6
Merge Jay

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "myisampack.h"
21
21
#include "ha_myisam.h"
22
22
#include "myisam_priv.h"
 
23
#include "drizzled/my_getopt.h"
23
24
#include "drizzled/internal/my_bit.h"
24
25
#include "drizzled/internal/m_string.h"
25
26
#include "drizzled/util/test.h"
27
28
#include "drizzled/errmsg_print.h"
28
29
#include "drizzled/gettext.h"
29
30
#include "drizzled/session.h"
 
31
#include "drizzled/set_var.h"
 
32
#include <drizzled/plugin.h>
30
33
#include "drizzled/plugin/client.h"
31
34
#include "drizzled/table.h"
32
35
#include "drizzled/field/timestamp.h"
39
42
 
40
43
using namespace std;
41
44
 
 
45
extern pthread_mutex_t LOCK_global_system_variables;
42
46
static const string engine_name("MyISAM");
43
47
 
44
48
pthread_mutex_t THR_LOCK_myisam= PTHREAD_MUTEX_INITIALIZER;
45
49
 
46
50
static uint32_t repair_threads;
47
 
static uint32_t block_size;
 
51
static uint32_t myisam_key_cache_block_size;
 
52
static uint32_t myisam_key_cache_size;
 
53
static uint32_t myisam_key_cache_division_limit;
 
54
static uint32_t myisam_key_cache_age_threshold;
48
55
static uint64_t max_sort_file_size;
49
56
static uint64_t sort_buffer_size;
50
57
 
1218
1225
    stats.create_time= misam_info.create_time;
1219
1226
    ref_length= misam_info.reflength;
1220
1227
    share->db_options_in_use= misam_info.options;
1221
 
    stats.block_size= block_size;        /* record block size */
 
1228
    stats.block_size= myisam_key_cache_block_size;        /* record block size */
1222
1229
 
1223
1230
    /* Update share */
1224
1231
    if (share->tmp_table == NO_TMP_TABLE)
1506
1513
 
1507
1514
  /* call ha_init_key_cache() on all key caches to init them */
1508
1515
  error= init_key_cache(dflt_key_cache,
1509
 
                        (uint32_t) dflt_key_cache->param_block_size,
1510
 
                        (uint32_t) dflt_key_cache->param_buff_size,
1511
 
                        dflt_key_cache->param_division_limit, 
1512
 
                        dflt_key_cache->param_age_threshold);
 
1516
                        myisam_key_cache_block_size,
 
1517
                        myisam_key_cache_size,
 
1518
                        myisam_key_cache_division_limit, 
 
1519
                        myisam_key_cache_age_threshold);
1513
1520
 
1514
1521
  if (error == 0)
1515
1522
    exit(1); /* Memory Allocation Failure */
1528
1535
  return mi_panic(HA_PANIC_CLOSE);
1529
1536
}
1530
1537
 
1531
 
static DRIZZLE_SYSVAR_UINT(block_size, block_size,
1532
 
                           PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
1533
 
                           N_("Block size to be used for MyISAM index pages."),
1534
 
                           NULL, NULL, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH, 
1535
 
                           MI_MAX_KEY_BLOCK_LENGTH, 0);
 
1538
static void sys_var_key_cache_size_update(Session *session, drizzle_sys_var *var, void *, const void *save)
 
1539
{
 
1540
  uint32_t tmp= *static_cast<const uint32_t *>(save);
 
1541
  bool error= 0;
 
1542
 
 
1543
        struct my_option option_limits;
 
1544
  plugin_opt_set_limits(&option_limits, var);
 
1545
        option_limits.name= "myisam_key_cache_size";
 
1546
 
 
1547
  if (dflt_key_cache->in_init)
 
1548
    return;
 
1549
 
 
1550
  myisam_key_cache_size= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
 
1551
 
 
1552
  /* If key cache didn't existed initialize it, else resize it */
 
1553
  dflt_key_cache->in_init= 1;
 
1554
 
 
1555
  error= ! resize_key_cache(dflt_key_cache,
 
1556
                                                                                                                myisam_key_cache_block_size,
 
1557
                            myisam_key_cache_size,
 
1558
                            myisam_key_cache_division_limit,
 
1559
                                                                                                          myisam_key_cache_age_threshold);
 
1560
  dflt_key_cache->in_init= 0;
 
1561
}
 
1562
 
 
1563
static void sys_var_key_cache_block_size_update(Session *session, drizzle_sys_var *var, void *, const void *save)
 
1564
{
 
1565
  uint32_t tmp= *static_cast<const uint32_t *>(save);
 
1566
  bool error= 0;
 
1567
 
 
1568
        struct my_option option_limits;
 
1569
  plugin_opt_set_limits(&option_limits, var);
 
1570
        option_limits.name= "myisam_key_cache_block_size";
 
1571
 
 
1572
  if (dflt_key_cache->in_init)
 
1573
    return;
 
1574
 
 
1575
  myisam_key_cache_block_size= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
 
1576
 
 
1577
  dflt_key_cache->in_init= 1;
 
1578
 
 
1579
  error= ! resize_key_cache(dflt_key_cache,
 
1580
                                                                                                                myisam_key_cache_block_size,
 
1581
                            myisam_key_cache_size,
 
1582
                            myisam_key_cache_division_limit,
 
1583
                                                                                                          myisam_key_cache_age_threshold);
 
1584
 
 
1585
  dflt_key_cache->in_init= 0;
 
1586
}
 
1587
 
 
1588
static void sys_var_key_cache_division_limit_update(Session *session, drizzle_sys_var *var, void *, const void *save)
 
1589
{
 
1590
  uint32_t tmp= *static_cast<const uint32_t *>(save);
 
1591
  bool error= 0;
 
1592
 
 
1593
        struct my_option option_limits;
 
1594
  plugin_opt_set_limits(&option_limits, var);
 
1595
        option_limits.name= "myisam_key_cache_division_limit";
 
1596
 
 
1597
  if (dflt_key_cache->in_init)
 
1598
    return;
 
1599
 
 
1600
  myisam_key_cache_division_limit= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
 
1601
 
 
1602
  dflt_key_cache->in_init= 1;
 
1603
 
 
1604
  error= ! resize_key_cache(dflt_key_cache,
 
1605
                                                                                                                myisam_key_cache_block_size,
 
1606
                            myisam_key_cache_size,
 
1607
                            myisam_key_cache_division_limit,
 
1608
                                                                                                          myisam_key_cache_age_threshold);
 
1609
 
 
1610
  dflt_key_cache->in_init= 0;
 
1611
}
 
1612
 
 
1613
static void sys_var_key_cache_age_threshold_update(Session *session, drizzle_sys_var *var, void *, const void *save)
 
1614
{
 
1615
  uint32_t tmp= *static_cast<const uint32_t *>(save);
 
1616
  bool error= 0;
 
1617
 
 
1618
        struct my_option option_limits;
 
1619
  plugin_opt_set_limits(&option_limits, var);
 
1620
        option_limits.name= "myisam_key_cache_age_threshold";
 
1621
 
 
1622
  if (dflt_key_cache->in_init)
 
1623
    return;
 
1624
 
 
1625
  myisam_key_cache_age_threshold= static_cast<uint32_t>(fix_unsigned(session, static_cast<uint64_t>(tmp), &option_limits));
 
1626
 
 
1627
  dflt_key_cache->in_init= 1;
 
1628
 
 
1629
  error= ! resize_key_cache(dflt_key_cache,
 
1630
                                                                                                                myisam_key_cache_block_size,
 
1631
                            myisam_key_cache_size,
 
1632
                            myisam_key_cache_division_limit,
 
1633
                                                                                                          myisam_key_cache_age_threshold);
 
1634
 
 
1635
  dflt_key_cache->in_init= 0;
 
1636
}
 
1637
 
 
1638
static DRIZZLE_SYSVAR_UINT(key_cache_block_size,
 
1639
                            myisam_key_cache_block_size,
 
1640
                            PLUGIN_VAR_RQCMDARG,
 
1641
                            N_("Block size to be used for MyISAM index pages."),
 
1642
                            NULL,
 
1643
                            sys_var_key_cache_block_size_update,
 
1644
                            KEY_CACHE_BLOCK_SIZE,
 
1645
                            512, 
 
1646
                            16 * 1024,
 
1647
                            0);
 
1648
 
 
1649
static DRIZZLE_SYSVAR_UINT(key_cache_age_threshold, myisam_key_cache_age_threshold,
 
1650
                            PLUGIN_VAR_RQCMDARG,
 
1651
                            N_("This characterizes the number of hits a hot block has to be untouched "
 
1652
                            "until it is considered aged enough to be downgraded to a warm block. "
 
1653
                            "This specifies the percentage ratio of that number of hits to the "
 
1654
                            "total number of blocks in key cache"),
 
1655
                            NULL,
 
1656
                            sys_var_key_cache_age_threshold_update,
 
1657
                            300,
 
1658
                            100, 
 
1659
                            UINT32_MAX,
 
1660
                            0);
 
1661
 
 
1662
static DRIZZLE_SYSVAR_UINT(key_cache_division_limit, myisam_key_cache_division_limit,
 
1663
                            PLUGIN_VAR_RQCMDARG,
 
1664
                            N_("The minimum percentage of warm blocks in key cache"),
 
1665
                            NULL,
 
1666
                            sys_var_key_cache_division_limit_update,
 
1667
                            100,
 
1668
                            1, 
 
1669
                            100,
 
1670
                            0);
 
1671
 
 
1672
static DRIZZLE_SYSVAR_UINT(key_cache_size,
 
1673
                            myisam_key_cache_size,
 
1674
                            PLUGIN_VAR_RQCMDARG,
 
1675
                            N_("The size of the buffer used for index blocks for MyISAM tables. "
 
1676
                            "Increase this to get better index handling (for all reads and multiple "
 
1677
                            "writes) to as much as you can afford;"),
 
1678
                            NULL,
 
1679
                            sys_var_key_cache_size_update,
 
1680
                            KEY_CACHE_SIZE,
 
1681
                            1 * 1024 * 1024, 
 
1682
                            UINT32_MAX,
 
1683
                            IO_SIZE);
1536
1684
 
1537
1685
static DRIZZLE_SYSVAR_UINT(repair_threads, repair_threads,
1538
 
                           PLUGIN_VAR_RQCMDARG,
1539
 
                           N_("Number of threads to use when repairing MyISAM tables. The value of "
1540
 
                              "1 disables parallel repair."),
1541
 
                           NULL, NULL, 1, 1, UINT32_MAX, 0);
 
1686
                            PLUGIN_VAR_RQCMDARG,
 
1687
                            N_("Number of threads to use when repairing MyISAM tables. The value of "
 
1688
                            "1 disables parallel repair."),
 
1689
                            NULL, NULL, 1, 1, UINT32_MAX, 0);
1542
1690
 
1543
1691
static DRIZZLE_SYSVAR_ULONGLONG(max_sort_file_size, max_sort_file_size,
1544
1692
                                PLUGIN_VAR_RQCMDARG,
1552
1700
 
1553
1701
extern uint32_t data_pointer_size;
1554
1702
static DRIZZLE_SYSVAR_UINT(data_pointer_size, data_pointer_size,
1555
 
                           PLUGIN_VAR_RQCMDARG,
1556
 
                           N_("Default pointer size to be used for MyISAM tables."),
1557
 
                           NULL, NULL, 6, 2, 7, 0);
 
1703
                            PLUGIN_VAR_RQCMDARG,
 
1704
                            N_("Default pointer size to be used for MyISAM tables."),
 
1705
                            NULL, NULL, 6, 2, 7, 0);
1558
1706
 
1559
1707
static drizzle_sys_var* system_variables[]= {
1560
 
  DRIZZLE_SYSVAR(block_size),
 
1708
  DRIZZLE_SYSVAR(key_cache_block_size),
 
1709
  DRIZZLE_SYSVAR(key_cache_size),
 
1710
  DRIZZLE_SYSVAR(key_cache_division_limit),
 
1711
  DRIZZLE_SYSVAR(key_cache_age_threshold),
1561
1712
  DRIZZLE_SYSVAR(repair_threads),
1562
1713
  DRIZZLE_SYSVAR(max_sort_file_size),
1563
1714
  DRIZZLE_SYSVAR(sort_buffer_size),