~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/haildb/haildb_engine.cc

  • Committer: Brian Aker
  • Date: 2010-12-18 10:14:05 UTC
  • mfrom: (2008.1.3 clean)
  • Revision ID: brian@tangent.org-20101218101405-qjbse29shi9coklg
Merge of user identifier work

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
#include <drizzled/error.h>
77
77
#include "drizzled/internal/my_pthread.h"
78
78
#include <drizzled/plugin/transactional_storage_engine.h>
 
79
#include <drizzled/plugin/error_message.h>
79
80
 
80
81
#include <fcntl.h>
 
82
#include <stdarg.h>
81
83
 
82
84
#include <string>
83
85
#include <boost/algorithm/string.hpp>
352
354
  isolation_level= tx_isolation_to_ib_trx_level((enum_tx_isolation)session_tx_isolation(session));
353
355
  *transaction= ib_trx_begin(isolation_level);
354
356
 
355
 
  return 0;
 
357
  return *transaction == NULL;
356
358
}
357
359
 
358
360
void HailDBEngine::doStartStatement(Session *session)
488
490
    nr++;
489
491
  }
490
492
  ib_tuple_delete(tuple);
 
493
  tuple= NULL;
491
494
  err= ib_cursor_reset(cursor);
492
495
  assert(err == DB_SUCCESS);
493
496
  return nr;
818
821
int HailDBCursor::open(const char *name, int, uint32_t)
819
822
{
820
823
  const char* haildb_table_name= table_path_to_haildb_name(name);
821
 
  ib_err_t err= ib_cursor_open_table(haildb_table_name, NULL, &cursor);
 
824
  ib_err_t err= ib_table_get_id(haildb_table_name, &table_id);
822
825
  bool has_hidden_primary_key= false;
823
826
  ib_id_t idx_id;
824
827
 
825
828
  if (err != DB_SUCCESS)
826
829
    return ib_err_t_to_drizzle_error(err);
827
830
 
 
831
  err= ib_cursor_open_table_using_id(table_id, NULL, &cursor);
 
832
  cursor_is_sec_index= false;
 
833
 
 
834
  if (err != DB_SUCCESS)
 
835
    return ib_err_t_to_drizzle_error(err);
 
836
 
828
837
  err= ib_index_get_id(haildb_table_name, "HIDDEN_PRIMARY", &idx_id);
829
838
 
830
839
  if (err == DB_SUCCESS)
1776
1785
  return("BTREE");
1777
1786
}
1778
1787
 
1779
 
static ib_err_t write_row_to_haildb_tuple(Field **fields, ib_tpl_t tuple)
 
1788
static ib_err_t write_row_to_haildb_tuple(const unsigned char* buf,
 
1789
                                          Field **fields, ib_tpl_t tuple)
1780
1790
{
1781
1791
  int colnr= 0;
1782
1792
  ib_err_t err= DB_ERROR;
 
1793
  ptrdiff_t row_offset= buf - (*fields)->getTable()->getInsertRecord();
1783
1794
 
1784
1795
  for (Field **field= fields; *field; field++, colnr++)
1785
1796
  {
 
1797
    (**field).move_field_offset(row_offset);
 
1798
 
1786
1799
    if (! (**field).isWriteSet() && (**field).is_null())
 
1800
    {
 
1801
      (**field).move_field_offset(-row_offset);
1787
1802
      continue;
 
1803
    }
1788
1804
 
1789
1805
    if ((**field).is_null())
1790
1806
    {
1791
1807
      err= ib_col_set_value(tuple, colnr, NULL, IB_SQL_NULL);
1792
1808
      assert(err == DB_SUCCESS);
 
1809
      (**field).move_field_offset(-row_offset);
1793
1810
      continue;
1794
1811
    }
1795
1812
 
1801
1818
      */
1802
1819
      String str;
1803
1820
      (**field).setReadSet();
1804
 
      (**field).val_str(&str);
 
1821
      (**field).val_str_internal(&str);
1805
1822
      err= ib_col_set_value(tuple, colnr, str.ptr(), str.length());
1806
1823
    }
1807
1824
    else if ((**field).type() == DRIZZLE_TYPE_ENUM)
1827
1844
    }
1828
1845
 
1829
1846
    assert (err == DB_SUCCESS);
 
1847
 
 
1848
    (**field).move_field_offset(-row_offset);
1830
1849
  }
1831
1850
 
1832
1851
  return err;
1875
1894
 
1876
1895
  tuple= ib_clust_read_tuple_create(cursor);
1877
1896
 
1878
 
  ib_cursor_attach_trx(cursor, transaction);
 
1897
  if (cursor_is_sec_index)
 
1898
  {
 
1899
    err= ib_cursor_close(cursor);
 
1900
    assert(err == DB_SUCCESS);
 
1901
 
 
1902
    err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
 
1903
 
 
1904
    if (err != DB_SUCCESS)
 
1905
      return ib_err_t_to_drizzle_error(err);
 
1906
 
 
1907
    cursor_is_sec_index= false;
 
1908
  }
 
1909
  else
 
1910
  {
 
1911
    ib_cursor_attach_trx(cursor, transaction);
 
1912
  }
1879
1913
 
1880
1914
  err= ib_cursor_first(cursor);
1881
1915
  if (current_session->lex->sql_command == SQLCOM_CREATE_TABLE
1934
1968
 
1935
1969
  }
1936
1970
 
1937
 
  write_row_to_haildb_tuple(getTable()->getFields(), tuple);
 
1971
  write_row_to_haildb_tuple(record, getTable()->getFields(), tuple);
1938
1972
 
1939
1973
  if (share->has_hidden_primary_key)
1940
1974
  {
1967
2001
      err= ib_cursor_first(cursor);
1968
2002
      assert(err == DB_SUCCESS || err == DB_END_OF_INDEX);
1969
2003
 
1970
 
      write_row_to_haildb_tuple(getTable()->getFields(), tuple);
 
2004
      write_row_to_haildb_tuple(record, getTable()->getFields(), tuple);
1971
2005
 
1972
2006
      err= ib_cursor_insert_row(cursor, tuple);
1973
2007
      assert(err==DB_SUCCESS); // probably be nice and process errors
1980
2014
 
1981
2015
  tuple= ib_tuple_clear(tuple);
1982
2016
  ib_tuple_delete(tuple);
 
2017
  tuple= NULL;
1983
2018
  err= ib_cursor_reset(cursor);
1984
2019
 
1985
2020
  return ret;
1986
2021
}
1987
2022
 
1988
 
int HailDBCursor::doUpdateRecord(const unsigned char *,
1989
 
                                         unsigned char *)
 
2023
int HailDBCursor::doUpdateRecord(const unsigned char *old_data,
 
2024
                                 unsigned char *new_data)
1990
2025
{
1991
2026
  ib_tpl_t update_tuple;
1992
2027
  ib_err_t err;
 
2028
  bool created_tuple= false;
1993
2029
 
1994
2030
  update_tuple= ib_clust_read_tuple_create(cursor);
1995
2031
 
 
2032
  if (tuple == NULL)
 
2033
  {
 
2034
    ib_trx_t transaction= *get_trx(getTable()->in_use);
 
2035
 
 
2036
    if (cursor_is_sec_index)
 
2037
    {
 
2038
      err= ib_cursor_close(cursor);
 
2039
      assert(err == DB_SUCCESS);
 
2040
 
 
2041
      err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
 
2042
 
 
2043
      if (err != DB_SUCCESS)
 
2044
        return ib_err_t_to_drizzle_error(err);
 
2045
      cursor_is_sec_index= false;
 
2046
    }
 
2047
    else
 
2048
    {
 
2049
      ib_cursor_attach_trx(cursor, transaction);
 
2050
    }
 
2051
 
 
2052
    store_key_value_from_haildb(getTable()->key_info + getTable()->getShare()->getPrimaryKey(),
 
2053
                                  ref, ref_length, old_data);
 
2054
 
 
2055
    ib_tpl_t search_tuple= ib_clust_search_tuple_create(cursor);
 
2056
 
 
2057
    fill_ib_search_tpl_from_drizzle_key(search_tuple,
 
2058
                                        getTable()->key_info + 0,
 
2059
                                        ref, ref_length);
 
2060
 
 
2061
    err= ib_cursor_set_lock_mode(cursor, IB_LOCK_X);
 
2062
    assert(err == DB_SUCCESS);
 
2063
 
 
2064
    int res;
 
2065
    err= ib_cursor_moveto(cursor, search_tuple, IB_CUR_GE, &res);
 
2066
    assert(err == DB_SUCCESS);
 
2067
 
 
2068
    tuple= ib_clust_read_tuple_create(cursor);
 
2069
 
 
2070
    err= ib_cursor_read_row(cursor, tuple);
 
2071
    assert(err == DB_SUCCESS);// FIXME
 
2072
 
 
2073
    created_tuple= true;
 
2074
  }
 
2075
 
1996
2076
  err= ib_tuple_copy(update_tuple, tuple);
1997
2077
  assert(err == DB_SUCCESS);
1998
2078
 
1999
 
  write_row_to_haildb_tuple(getTable()->getFields(), update_tuple);
 
2079
  write_row_to_haildb_tuple(new_data, getTable()->getFields(), update_tuple);
2000
2080
 
2001
2081
  err= ib_cursor_update_row(cursor, tuple, update_tuple);
2002
2082
 
2003
2083
  ib_tuple_delete(update_tuple);
2004
2084
 
 
2085
  if (created_tuple)
 
2086
  {
 
2087
    ib_err_t ib_err= ib_cursor_reset(cursor); //fixme check error
 
2088
    assert(ib_err == DB_SUCCESS);
 
2089
    tuple= ib_tuple_clear(tuple);
 
2090
    ib_tuple_delete(tuple);
 
2091
    tuple= NULL;
 
2092
  }
 
2093
 
2005
2094
  advance_cursor= true;
2006
2095
 
2007
 
  if (err == DB_SUCCESS)
2008
 
    return 0;
2009
 
  else if (err == DB_DUPLICATE_KEY)
2010
 
    return HA_ERR_FOUND_DUPP_KEY;
2011
 
  else
2012
 
    return -1;
 
2096
  return ib_err_t_to_drizzle_error(err);
2013
2097
}
2014
2098
 
2015
2099
int HailDBCursor::doDeleteRecord(const unsigned char *)
2016
2100
{
2017
2101
  ib_err_t err;
2018
2102
 
 
2103
  assert(ib_cursor_is_positioned(cursor) == IB_TRUE);
2019
2104
  err= ib_cursor_delete_row(cursor);
2020
 
  if (err != DB_SUCCESS)
2021
 
    return -1; // FIXME
2022
2105
 
2023
2106
  advance_cursor= true;
2024
 
  return 0;
 
2107
 
 
2108
  return ib_err_t_to_drizzle_error(err);
2025
2109
}
2026
2110
 
2027
2111
int HailDBCursor::delete_all_rows(void)
2028
2112
{
2029
2113
  /* I *think* ib_truncate is non-transactional....
2030
2114
     so only support TRUNCATE and not DELETE FROM t;
2031
 
     (this is what ha_haildb does)
 
2115
     (this is what ha_innodb does)
2032
2116
  */
2033
2117
  if (session_sql_command(getTable()->in_use) != SQLCOM_TRUNCATE)
2034
2118
    return HA_ERR_WRONG_COMMAND;
2038
2122
 
2039
2123
  ib_trx_t transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ);
2040
2124
 
2041
 
  ib_cursor_attach_trx(cursor, transaction);
 
2125
  if (cursor_is_sec_index)
 
2126
  {
 
2127
    err= ib_cursor_close(cursor);
 
2128
    assert(err == DB_SUCCESS);
 
2129
 
 
2130
    err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
 
2131
 
 
2132
    if (err != DB_SUCCESS)
 
2133
      return ib_err_t_to_drizzle_error(err);
 
2134
    cursor_is_sec_index= false;
 
2135
  }
 
2136
  else
 
2137
  {
 
2138
    ib_cursor_attach_trx(cursor, transaction);
 
2139
  }
2042
2140
 
2043
2141
  err= ib_schema_lock_exclusive(transaction);
2044
2142
  if (err != DB_SUCCESS)
2074
2172
  ib_schema_unlock(transaction);
2075
2173
  ib_err_t rollback_err= ib_trx_rollback(transaction);
2076
2174
  assert(rollback_err == DB_SUCCESS);
2077
 
  return err;
 
2175
  return ib_err_t_to_drizzle_error(err);
2078
2176
}
2079
2177
 
2080
2178
int HailDBCursor::doStartTableScan(bool)
2081
2179
{
2082
 
  ib_err_t err;
 
2180
  ib_err_t err= DB_SUCCESS;
2083
2181
  ib_trx_t transaction;
2084
2182
 
2085
2183
  if (in_table_scan)
2090
2188
 
2091
2189
  assert(transaction != NULL);
2092
2190
 
2093
 
  ib_cursor_attach_trx(cursor, transaction);
 
2191
  if (cursor_is_sec_index)
 
2192
  {
 
2193
    err= ib_cursor_close(cursor);
 
2194
    assert(err == DB_SUCCESS);
 
2195
 
 
2196
    err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
 
2197
    cursor_is_sec_index= false;
 
2198
  }
 
2199
  else
 
2200
  {
 
2201
    ib_cursor_attach_trx(cursor, transaction);
 
2202
  }
 
2203
 
 
2204
  if (err != DB_SUCCESS)
 
2205
    return ib_err_t_to_drizzle_error(err);
2094
2206
 
2095
2207
  err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2096
2208
  assert(err == DB_SUCCESS); // FIXME
2118
2230
 
2119
2231
  err= ib_cursor_read_row(cursor, tuple);
2120
2232
 
2121
 
  if (err != DB_SUCCESS) // FIXME
 
2233
  if (err == DB_RECORD_NOT_FOUND)
2122
2234
    return HA_ERR_END_OF_FILE;
 
2235
  if (err != DB_SUCCESS)
 
2236
    return ib_err_t_to_drizzle_error(err);
2123
2237
 
2124
2238
  int colnr= 0;
2125
2239
 
2130
2244
  for (Field **field= table->getFields() ; *field ; field++, colnr++)
2131
2245
  {
2132
2246
    if (! (**field).isReadSet())
2133
 
      continue;
 
2247
      (**field).setReadSet(); /* Fucking broken API screws us royally. */
2134
2248
 
2135
2249
    (**field).move_field_offset(row_offset);
2136
2250
 
2140
2254
    if (length == IB_SQL_NULL)
2141
2255
    {
2142
2256
      (**field).set_null();
 
2257
      (**field).move_field_offset(-row_offset);
2143
2258
      continue;
2144
2259
    }
2145
2260
    else
2183
2298
 
2184
2299
    (**field).move_field_offset(-row_offset);
2185
2300
 
 
2301
    if (err != DB_SUCCESS)
 
2302
      return ib_err_t_to_drizzle_error(err);
2186
2303
  }
2187
2304
 
2188
2305
  if (has_hidden_primary_key)
2190
2307
    err= ib_tuple_read_u64(tuple, colnr, hidden_pkey);
2191
2308
  }
2192
2309
 
2193
 
  return 0;
 
2310
  return ib_err_t_to_drizzle_error(err);
2194
2311
}
2195
2312
 
2196
2313
int HailDBCursor::rnd_next(unsigned char *buf)
2202
2319
    return previous_error;
2203
2320
 
2204
2321
  if (advance_cursor)
 
2322
  {
2205
2323
    err= ib_cursor_next(cursor);
 
2324
    if (err != DB_SUCCESS)
 
2325
      return ib_err_t_to_drizzle_error(err);
 
2326
  }
2206
2327
 
2207
2328
  tuple= ib_tuple_clear(tuple);
2208
2329
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2218
2339
  ib_err_t err;
2219
2340
 
2220
2341
  ib_tuple_delete(tuple);
 
2342
  tuple= NULL;
2221
2343
  err= ib_cursor_reset(cursor);
2222
2344
  assert(err == DB_SUCCESS);
2223
2345
  in_table_scan= false;
2224
2346
  previous_error= 0;
2225
 
  return 0;
 
2347
  return ib_err_t_to_drizzle_error(err);
2226
2348
}
2227
2349
 
2228
2350
int HailDBCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
2236
2358
  {
2237
2359
    err= ib_col_set_value(search_tuple, 0,
2238
2360
                          ((uint64_t*)(pos)), sizeof(uint64_t));
 
2361
    if (err != DB_SUCCESS)
 
2362
      return ib_err_t_to_drizzle_error(err);
2239
2363
  }
2240
2364
  else
2241
2365
  {
2251
2375
  }
2252
2376
 
2253
2377
  err= ib_cursor_moveto(cursor, search_tuple, IB_CUR_GE, &res);
2254
 
  assert(err == DB_SUCCESS);
 
2378
  if (err != DB_SUCCESS)
 
2379
    return ib_err_t_to_drizzle_error(err);
2255
2380
 
2256
2381
  assert(res==0);
2257
2382
  if (res != 0)
2300
2425
      }
2301
2426
 
2302
2427
      String str;
2303
 
      field->val_str(&str);
 
2428
      field->val_str_internal(&str);
2304
2429
 
2305
2430
      *ref++= (char)(str.length() & 0x000000ff);
2306
2431
      *ref++= (char)((str.length()>>8) & 0x000000ff);
2379
2504
 
2380
2505
  if (flag & HA_STATUS_AUTO)
2381
2506
    stats.auto_increment_value= 1;
 
2507
 
 
2508
  if (flag & HA_STATUS_ERRKEY) {
 
2509
    const char *err_table_name;
 
2510
    const char *err_index_name;
 
2511
 
 
2512
    ib_trx_t transaction= *get_trx(getTable()->in_use);
 
2513
 
 
2514
    err= ib_get_duplicate_key(transaction, &err_table_name, &err_index_name);
 
2515
 
 
2516
    errkey= -1;
 
2517
 
 
2518
    for (unsigned int i = 0; i < getTable()->getShare()->keys; i++)
 
2519
    {
 
2520
      if (strcmp(err_index_name, getTable()->key_info[i].name) == 0)
 
2521
      {
 
2522
        errkey= i;
 
2523
        break;
 
2524
      }
 
2525
    }
 
2526
 
 
2527
  }
 
2528
 
2382
2529
  return(0);
2383
2530
}
2384
2531
 
2385
2532
int HailDBCursor::doStartIndexScan(uint32_t keynr, bool)
2386
2533
{
 
2534
  ib_err_t err;
2387
2535
  ib_trx_t transaction= *get_trx(getTable()->in_use);
2388
2536
 
2389
2537
  active_index= keynr;
2390
2538
 
2391
 
  ib_cursor_attach_trx(cursor, transaction);
2392
 
 
2393
2539
  if (active_index == 0 && ! share->has_hidden_primary_key)
2394
2540
  {
 
2541
    if (cursor_is_sec_index)
 
2542
    {
 
2543
      err= ib_cursor_close(cursor);
 
2544
      assert(err == DB_SUCCESS);
 
2545
 
 
2546
      err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
 
2547
 
 
2548
      if (err != DB_SUCCESS)
 
2549
        return ib_err_t_to_drizzle_error(err);
 
2550
 
 
2551
    }
 
2552
    else
 
2553
    {
 
2554
      ib_cursor_attach_trx(cursor, transaction);
 
2555
    }
 
2556
 
 
2557
    cursor_is_sec_index= false;
2395
2558
    tuple= ib_clust_read_tuple_create(cursor);
2396
2559
  }
2397
2560
  else
2398
2561
  {
2399
 
    ib_err_t err;
2400
2562
    ib_id_t index_id;
2401
2563
    err= ib_index_get_id(table_path_to_haildb_name(getShare()->getPath()),
2402
2564
                         getShare()->getKeyInfo(keynr).name,
2403
2565
                         &index_id);
2404
2566
    if (err != DB_SUCCESS)
2405
 
      return -1;
 
2567
      return ib_err_t_to_drizzle_error(err);
2406
2568
 
2407
2569
    err= ib_cursor_close(cursor);
2408
2570
    assert(err == DB_SUCCESS);
 
2571
 
2409
2572
    err= ib_cursor_open_index_using_id(index_id, transaction, &cursor);
2410
2573
 
2411
2574
    if (err != DB_SUCCESS)
2412
 
      return -1;
 
2575
      return ib_err_t_to_drizzle_error(err);
 
2576
 
 
2577
    cursor_is_sec_index= true;
2413
2578
 
2414
2579
    tuple= ib_clust_read_tuple_create(cursor);
2415
2580
    ib_cursor_set_cluster_access(cursor);
2416
2581
  }
2417
2582
 
2418
 
  ib_err_t err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
 
2583
  err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2419
2584
  assert(err == DB_SUCCESS);
2420
2585
 
2421
2586
  advance_cursor= false;
2681
2846
      if (err == DB_END_OF_INDEX)
2682
2847
        return HA_ERR_END_OF_FILE;
2683
2848
      else
2684
 
        return -1; // FIXME
 
2849
        return ib_err_t_to_drizzle_error(err);
2685
2850
    }
2686
2851
  }
2687
2852
 
2827
2992
static bool innobase_create_status_file;
2828
2993
static bool srv_use_sys_malloc;
2829
2994
static string innobase_file_format_name;
2830
 
static unsigned long srv_max_buf_pool_modified_pct;
2831
 
static unsigned long srv_max_purge_lag;
2832
 
static unsigned long innobase_lru_old_blocks_pct;
2833
 
static unsigned long innobase_lru_block_access_recency;
2834
 
static unsigned long innobase_read_io_threads;
2835
 
static unsigned long innobase_write_io_threads;
2836
2995
typedef constrained_check<unsigned int, 1000, 1> autoextend_constraint;
2837
2996
static autoextend_constraint srv_auto_extend_increment;
2838
 
static unsigned long innobase_lock_wait_timeout;
2839
 
static unsigned long srv_n_spin_wait_rounds;
2840
2997
typedef constrained_check<size_t, SIZE_MAX, 5242880, 1048576> buffer_pool_constraint;
2841
2998
static buffer_pool_constraint innobase_buffer_pool_size;
2842
2999
typedef constrained_check<size_t, SIZE_MAX, 512, 1024> additional_mem_pool_constraint;
2843
3000
static additional_mem_pool_constraint innobase_additional_mem_pool_size;
2844
3001
static bool  innobase_use_checksums= true;
2845
3002
typedef constrained_check<unsigned int, UINT_MAX, 100> io_capacity_constraint;
2846
 
typedef constrained_check<uint16_t, 2, 0> trinary_constraint;
 
3003
typedef constrained_check<uint32_t, 2, 0> trinary_constraint;
2847
3004
static trinary_constraint innobase_fast_shutdown;
2848
3005
static trinary_constraint srv_flush_log_at_trx_commit;
2849
 
typedef constrained_check<uint16_t, 6, 0> force_recovery_constraint;
 
3006
typedef constrained_check<uint32_t, 6, 0> force_recovery_constraint;
2850
3007
static force_recovery_constraint innobase_force_recovery;
 
3008
typedef constrained_check<int64_t, INT64_MAX, 1024*1024, 1024*1024> log_file_constraint;
 
3009
static log_file_constraint haildb_log_file_size;
 
3010
 
2851
3011
static io_capacity_constraint srv_io_capacity;
2852
 
 
2853
 
static long innobase_open_files;
2854
 
static long innobase_log_buffer_size;
2855
 
static char  default_haildb_data_file_path[]= "ibdata1:10M:autoextend";
2856
 
static char* haildb_data_file_path= NULL;
2857
 
 
2858
 
static int64_t haildb_log_file_size;
2859
 
static int64_t haildb_log_files_in_group;
 
3012
typedef constrained_check<unsigned int, 100, 2> log_files_in_group_constraint;
 
3013
static log_files_in_group_constraint haildb_log_files_in_group;
 
3014
typedef constrained_check<unsigned int, 1024*1024*1024, 1> lock_wait_constraint;
 
3015
static lock_wait_constraint innobase_lock_wait_timeout;
 
3016
typedef constrained_check<long, LONG_MAX, 256*1024, 1024> log_buffer_size_constraint;
 
3017
static log_buffer_size_constraint innobase_log_buffer_size;
 
3018
typedef constrained_check<unsigned int, 97, 5> lru_old_blocks_constraint;
 
3019
static lru_old_blocks_constraint innobase_lru_old_blocks_pct;
 
3020
typedef constrained_check<unsigned int, 99, 0> max_dirty_pages_constraint;
 
3021
static max_dirty_pages_constraint haildb_max_dirty_pages_pct;
 
3022
static uint64_constraint haildb_max_purge_lag;
 
3023
static uint64_constraint haildb_sync_spin_loops;
 
3024
typedef constrained_check<uint32_t, UINT32_MAX, 10> open_files_constraint;
 
3025
static open_files_constraint haildb_open_files;
 
3026
typedef constrained_check<unsigned int, 64, 1> io_threads_constraint;
 
3027
static io_threads_constraint haildb_read_io_threads;
 
3028
static io_threads_constraint haildb_write_io_threads;
 
3029
 
 
3030
 
 
3031
static uint32_t innobase_lru_block_access_recency;
 
3032
 
 
3033
 
2860
3034
 
2861
3035
static int haildb_file_format_name_validate(Session*, set_var *var)
2862
3036
{
2876
3050
    return 1;
2877
3051
}
2878
3052
 
 
3053
static void haildb_lru_old_blocks_pct_update(Session*, sql_var_t)
 
3054
{
 
3055
  int ret= ib_cfg_set_int("lru_old_blocks_pct", static_cast<uint32_t>(innobase_lru_old_blocks_pct));
 
3056
  (void)ret;
 
3057
}
 
3058
 
 
3059
static void haildb_lru_block_access_recency_update(Session*, sql_var_t)
 
3060
{
 
3061
  int ret= ib_cfg_set_int("lru_block_access_recency", static_cast<uint32_t>(innobase_lru_block_access_recency));
 
3062
  (void)ret;
 
3063
}
 
3064
 
 
3065
static void haildb_status_file_update(Session*, sql_var_t)
 
3066
{
 
3067
  ib_err_t err;
 
3068
 
 
3069
  if (innobase_create_status_file)
 
3070
    err= ib_cfg_set_bool_on("status_file");
 
3071
  else
 
3072
    err= ib_cfg_set_bool_off("status_file");
 
3073
  (void)err;
 
3074
}
 
3075
 
 
3076
extern "C" int haildb_errmsg_callback(ib_msg_stream_t, const char *fmt, ...);
 
3077
namespace drizzled
 
3078
{
 
3079
extern bool volatile shutdown_in_progress;
 
3080
}
 
3081
 
 
3082
extern "C" int haildb_errmsg_callback(ib_msg_stream_t, const char *fmt, ...)
 
3083
{
 
3084
  bool r= false;
 
3085
  va_list args;
 
3086
  va_start(args, fmt);
 
3087
  if (! shutdown_in_progress)
 
3088
    r= plugin::ErrorMessage::vprintf(NULL, ERRMSG_LVL_WARN, fmt, args);
 
3089
  else
 
3090
    vfprintf(stderr, fmt, args);
 
3091
  va_end(args);
 
3092
 
 
3093
  return (! r==true);
 
3094
}
 
3095
 
2879
3096
static int haildb_init(drizzled::module::Context &context)
2880
3097
{
2881
3098
  haildb_system_table_names.insert(std::string("HAILDB_SYS_TABLES"));
2896
3113
  innobase_print_verbose_log= (vm.count("disable-print-verbose-log")) ? false : true;
2897
3114
  srv_use_sys_malloc= (vm.count("use-internal-malloc")) ? false : true;
2898
3115
 
2899
 
  if (vm.count("log-file-size"))
2900
 
  {
2901
 
    if (haildb_log_file_size > INT64_MAX || haildb_log_file_size < 1*1024*1024L)
2902
 
    {
2903
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-file-size"));
2904
 
      return 1;
2905
 
    }
2906
 
    haildb_log_file_size/= 1024*1024L;
2907
 
    haildb_log_file_size*= 1024*1024L;
2908
 
  }
2909
 
 
2910
 
  if (vm.count("log-files-in-group"))
2911
 
  {
2912
 
    if (haildb_log_files_in_group > 100 || haildb_log_files_in_group < 2)
2913
 
    {
2914
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-files-in-group"));
2915
 
      return 1;
2916
 
    }
2917
 
  }
2918
 
 
2919
 
  if (vm.count("lock-wait-timeout"))
2920
 
  {
2921
 
    if (innobase_lock_wait_timeout > 1024*1024*1024 || innobase_lock_wait_timeout < 1)
2922
 
    {
2923
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lock-wait-timeout"));
2924
 
      return 1;
2925
 
    }
2926
 
  }
2927
 
 
2928
 
  if (vm.count("log-buffer-size"))
2929
 
  {
2930
 
    if (innobase_log_buffer_size > LONG_MAX || innobase_log_buffer_size < 256*1024L)
2931
 
    {
2932
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-buffer-size"));
2933
 
      return 1;
2934
 
    }
2935
 
    innobase_log_buffer_size/= 1024;
2936
 
    innobase_log_buffer_size*= 1024;
2937
 
  }
2938
 
 
2939
 
  if (vm.count("lru-old-blocks-pct"))
2940
 
  {
2941
 
    if (innobase_lru_old_blocks_pct > 95 || innobase_lru_old_blocks_pct < 5)
2942
 
    {
2943
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lru-old-blocks-pct"));
2944
 
      return 1;
2945
 
    }
2946
 
  }
2947
 
 
2948
 
  if (vm.count("lru-block-access-recency"))
2949
 
  {
2950
 
    if (innobase_lru_block_access_recency > ULONG_MAX)
2951
 
    {
2952
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lru-block-access-recency"));
2953
 
      return 1;
2954
 
    }
2955
 
  }
2956
 
 
2957
 
  if (vm.count("max-dirty-pages-pct"))
2958
 
  {
2959
 
    if (srv_max_buf_pool_modified_pct > 99)
2960
 
    {
2961
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of max-dirty-pages-pct"));
2962
 
      return 1;
2963
 
    }
2964
 
  }
2965
 
 
2966
 
  if (vm.count("max-purge-lag"))
2967
 
  {
2968
 
    if (srv_max_purge_lag > (unsigned long)~0L)
2969
 
    {
2970
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of max-purge-lag"));
2971
 
      return 1;
2972
 
    }
2973
 
  }
2974
 
 
2975
 
  if (vm.count("open-files"))
2976
 
  {
2977
 
    if (innobase_open_files > LONG_MAX || innobase_open_files < 10L)
2978
 
    {
2979
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of open-files"));
2980
 
      return 1;
2981
 
    }
2982
 
  }
2983
 
 
2984
 
  if (vm.count("read-io-threads"))
2985
 
  {
2986
 
    if (innobase_read_io_threads > 64 || innobase_read_io_threads < 1)
2987
 
    {
2988
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of read-io-threads"));
2989
 
      return 1;
2990
 
    }
2991
 
  }
2992
 
 
2993
 
  if (vm.count("sync-spin-loops"))
2994
 
  {
2995
 
    if (srv_n_spin_wait_rounds > (unsigned long)~0L)
2996
 
    {
2997
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of sync_spin_loops"));
2998
 
      return 1;
2999
 
    }
3000
 
  }
3001
 
 
3002
 
  if (vm.count("data-file-path"))
3003
 
  {
3004
 
    haildb_data_file_path= const_cast<char *>(vm["data-file-path"].as<string>().c_str());
3005
 
  }
3006
3116
 
3007
3117
  ib_err_t err;
3008
3118
 
3010
3120
  if (err != DB_SUCCESS)
3011
3121
    goto haildb_error;
3012
3122
 
 
3123
  ib_logger_set(haildb_errmsg_callback, NULL);
3013
3124
 
3014
 
  if (vm.count("data-home-dir"))
 
3125
  if (not vm["data-home-dir"].as<string>().empty())
3015
3126
  {
3016
3127
    err= ib_cfg_set_text("data_home_dir", vm["data-home-dir"].as<string>().c_str());
3017
3128
    if (err != DB_SUCCESS)
3025
3136
      goto haildb_error;
3026
3137
  }
3027
3138
 
3028
 
  if (haildb_data_file_path == NULL)
3029
 
    haildb_data_file_path= default_haildb_data_file_path;
3030
 
 
3031
3139
  if (innobase_print_verbose_log)
3032
3140
    err= ib_cfg_set_bool_on("print_verbose_log");
3033
3141
  else
3068
3176
  if (err != DB_SUCCESS)
3069
3177
    goto haildb_error;
3070
3178
 
3071
 
  err= ib_cfg_set_int("additional_mem_pool_size", static_cast<size_t>(innobase_additional_mem_pool_size));
3072
 
  if (err != DB_SUCCESS)
3073
 
    goto haildb_error;
3074
 
 
3075
 
  err= ib_cfg_set_int("autoextend_increment", static_cast<unsigned int>(srv_auto_extend_increment));
3076
 
  if (err != DB_SUCCESS)
3077
 
    goto haildb_error;
3078
 
 
3079
 
  err= ib_cfg_set_int("buffer_pool_size", static_cast<size_t>(innobase_buffer_pool_size));
3080
 
  if (err != DB_SUCCESS)
3081
 
    goto haildb_error;
3082
 
 
3083
 
  err= ib_cfg_set_int("io_capacity", static_cast<unsigned int>(srv_io_capacity));
 
3179
  err= ib_cfg_set_int("additional_mem_pool_size", innobase_additional_mem_pool_size.get());
 
3180
  if (err != DB_SUCCESS)
 
3181
    goto haildb_error;
 
3182
 
 
3183
  err= ib_cfg_set_int("autoextend_increment", srv_auto_extend_increment.get());
 
3184
  if (err != DB_SUCCESS)
 
3185
    goto haildb_error;
 
3186
 
 
3187
  err= ib_cfg_set_int("buffer_pool_size", innobase_buffer_pool_size.get());
 
3188
  if (err != DB_SUCCESS)
 
3189
    goto haildb_error;
 
3190
 
 
3191
  err= ib_cfg_set_int("io_capacity", srv_io_capacity.get());
3084
3192
  if (err != DB_SUCCESS)
3085
3193
    goto haildb_error;
3086
3194
 
3093
3201
    goto haildb_error;
3094
3202
 
3095
3203
  err= ib_cfg_set_int("flush_log_at_trx_commit",
3096
 
                      static_cast<uint16_t>(srv_flush_log_at_trx_commit));
 
3204
                      srv_flush_log_at_trx_commit.get());
3097
3205
  if (err != DB_SUCCESS)
3098
3206
    goto haildb_error;
3099
3207
 
3106
3214
  }
3107
3215
 
3108
3216
  err= ib_cfg_set_int("force_recovery",
3109
 
                      static_cast<uint16_t>(innobase_force_recovery));
3110
 
  if (err != DB_SUCCESS)
3111
 
    goto haildb_error;
3112
 
 
3113
 
  err= ib_cfg_set_text("data_file_path", haildb_data_file_path);
3114
 
  if (err != DB_SUCCESS)
3115
 
    goto haildb_error;
3116
 
 
3117
 
  err= ib_cfg_set_int("log_file_size", haildb_log_file_size);
3118
 
  if (err != DB_SUCCESS)
3119
 
    goto haildb_error;
3120
 
 
3121
 
  err= ib_cfg_set_int("log_buffer_size", innobase_log_buffer_size);
3122
 
  if (err != DB_SUCCESS)
3123
 
    goto haildb_error;
3124
 
 
3125
 
  err= ib_cfg_set_int("log_files_in_group", haildb_log_files_in_group);
 
3217
                      innobase_force_recovery.get());
 
3218
  if (err != DB_SUCCESS)
 
3219
    goto haildb_error;
 
3220
 
 
3221
  err= ib_cfg_set_text("data_file_path", vm["data-file-path"].as<string>().c_str());
 
3222
  if (err != DB_SUCCESS)
 
3223
    goto haildb_error;
 
3224
 
 
3225
  err= ib_cfg_set_int("log_file_size", haildb_log_file_size.get());
 
3226
  if (err != DB_SUCCESS)
 
3227
    goto haildb_error;
 
3228
 
 
3229
  err= ib_cfg_set_int("log_buffer_size", innobase_log_buffer_size.get());
 
3230
  if (err != DB_SUCCESS)
 
3231
    goto haildb_error;
 
3232
 
 
3233
  err= ib_cfg_set_int("log_files_in_group", haildb_log_files_in_group.get());
3126
3234
  if (err != DB_SUCCESS)
3127
3235
    goto haildb_error;
3128
3236
 
3130
3238
  if (err != DB_SUCCESS)
3131
3239
    goto haildb_error;
3132
3240
 
3133
 
  err= ib_cfg_set_int("lock_wait_timeout", innobase_lock_wait_timeout);
3134
 
  if (err != DB_SUCCESS)
3135
 
    goto haildb_error;
3136
 
 
3137
 
  err= ib_cfg_set_int("max_dirty_pages_pct", srv_max_buf_pool_modified_pct);
3138
 
  if (err != DB_SUCCESS)
3139
 
    goto haildb_error;
3140
 
 
3141
 
  err= ib_cfg_set_int("max_purge_lag", srv_max_purge_lag);
3142
 
  if (err != DB_SUCCESS)
3143
 
    goto haildb_error;
3144
 
 
3145
 
  err= ib_cfg_set_int("open_files", innobase_open_files);
3146
 
  if (err != DB_SUCCESS)
3147
 
    goto haildb_error;
3148
 
 
3149
 
  err= ib_cfg_set_int("read_io_threads", innobase_read_io_threads);
3150
 
  if (err != DB_SUCCESS)
3151
 
    goto haildb_error;
3152
 
 
3153
 
  err= ib_cfg_set_int("write_io_threads", innobase_write_io_threads);
3154
 
  if (err != DB_SUCCESS)
3155
 
    goto haildb_error;
3156
 
 
3157
 
  err= ib_cfg_set_int("sync_spin_loops", srv_n_spin_wait_rounds);
 
3241
  err= ib_cfg_set_int("lock_wait_timeout", innobase_lock_wait_timeout.get());
 
3242
  if (err != DB_SUCCESS)
 
3243
    goto haildb_error;
 
3244
 
 
3245
  err= ib_cfg_set_int("max_dirty_pages_pct", haildb_max_dirty_pages_pct.get());
 
3246
  if (err != DB_SUCCESS)
 
3247
    goto haildb_error;
 
3248
 
 
3249
  err= ib_cfg_set_int("max_purge_lag", haildb_max_purge_lag.get());
 
3250
  if (err != DB_SUCCESS)
 
3251
    goto haildb_error;
 
3252
 
 
3253
  err= ib_cfg_set_int("open_files", haildb_open_files.get());
 
3254
  if (err != DB_SUCCESS)
 
3255
    goto haildb_error;
 
3256
 
 
3257
  err= ib_cfg_set_int("read_io_threads", haildb_read_io_threads.get());
 
3258
  if (err != DB_SUCCESS)
 
3259
    goto haildb_error;
 
3260
 
 
3261
  err= ib_cfg_set_int("write_io_threads", haildb_write_io_threads.get());
 
3262
  if (err != DB_SUCCESS)
 
3263
    goto haildb_error;
 
3264
 
 
3265
  err= ib_cfg_set_int("sync_spin_loops", haildb_sync_spin_loops.get());
3158
3266
  if (err != DB_SUCCESS)
3159
3267
    goto haildb_error;
3160
3268
 
3185
3293
                                                         &innobase_use_checksums));
3186
3294
  context.registerVariable(new sys_var_bool_ptr_readonly("doublewrite",
3187
3295
                                                         &innobase_use_doublewrite));
 
3296
  context.registerVariable(new sys_var_const_string_val("data_file_path",
 
3297
                                                vm["data-file-path"].as<string>()));
3188
3298
  context.registerVariable(new sys_var_const_string_val("data_home_dir",
3189
 
                                                vm.count("data-home-dir") ?  vm["data-home-dir"].as<string>() : ""));
 
3299
                                                vm["data-home-dir"].as<string>()));
3190
3300
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("io_capacity", srv_io_capacity));
3191
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint16_t>("fast_shutdown", innobase_fast_shutdown));
 
3301
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("fast_shutdown", innobase_fast_shutdown));
3192
3302
  context.registerVariable(new sys_var_bool_ptr_readonly("file_per_table",
3193
3303
                                                         &srv_file_per_table));
3194
 
  context.registerVariable(new sys_var_std_string("file-format",
 
3304
  context.registerVariable(new sys_var_bool_ptr_readonly("rollback_on_timeout",
 
3305
                                                         &innobase_rollback_on_timeout));
 
3306
  context.registerVariable(new sys_var_bool_ptr_readonly("print_verbose_log",
 
3307
                                                         &innobase_print_verbose_log));
 
3308
  context.registerVariable(new sys_var_bool_ptr("status_file",
 
3309
                                                &innobase_create_status_file,
 
3310
                                                haildb_status_file_update));
 
3311
  context.registerVariable(new sys_var_bool_ptr_readonly("use_sys_malloc",
 
3312
                                                         &srv_use_sys_malloc));
 
3313
  context.registerVariable(new sys_var_std_string("file_format",
3195
3314
                                                  innobase_file_format_name,
3196
3315
                                                  haildb_file_format_name_validate));
3197
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint16_t>("flush_log_at_trx_commit", srv_flush_log_at_trx_commit));
 
3316
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("flush_log_at_trx_commit", srv_flush_log_at_trx_commit));
3198
3317
  context.registerVariable(new sys_var_const_string_val("flush_method",
3199
3318
                                                vm.count("flush-method") ?  vm["flush-method"].as<string>() : ""));
3200
 
  context.registerVariable(new sys_var_constrained_value_readonly<uint16_t>("force_recovery", innobase_force_recovery));
 
3319
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("force_recovery", innobase_force_recovery));
3201
3320
  context.registerVariable(new sys_var_const_string_val("log_group_home_dir",
3202
3321
                                                vm.count("log-group-home-dir") ?  vm["log-group-home-dir"].as<string>() : ""));
 
3322
  context.registerVariable(new sys_var_constrained_value<int64_t>("log_file_size", haildb_log_file_size));
 
3323
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("log_files_in_group", haildb_log_files_in_group));
 
3324
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("lock_wait_timeout", innobase_lock_wait_timeout));
 
3325
  context.registerVariable(new sys_var_constrained_value_readonly<long>("log_buffer_size", innobase_log_buffer_size));
 
3326
  context.registerVariable(new sys_var_constrained_value<unsigned int>("lru_old_blocks_pct", innobase_lru_old_blocks_pct, haildb_lru_old_blocks_pct_update));
 
3327
  context.registerVariable(new sys_var_uint32_t_ptr("lru_block_access_recency",
 
3328
                                                    &innobase_lru_block_access_recency,
 
3329
                                                    haildb_lru_block_access_recency_update));
 
3330
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("max_dirty_pages_pct", haildb_max_dirty_pages_pct));
 
3331
  context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("max_purge_lag", haildb_max_purge_lag));
 
3332
  context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("sync_spin_loops", haildb_sync_spin_loops));
 
3333
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("open_files", haildb_open_files));
 
3334
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("read_io_threads", haildb_read_io_threads));
 
3335
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("write_io_threads", haildb_write_io_threads));
3203
3336
 
3204
3337
  haildb_datadict_dump_func_initialize(context);
3205
3338
  config_table_function_initialize(context);
3218
3351
  ib_err_t err;
3219
3352
  ib_shutdown_t shutdown_flag= IB_SHUTDOWN_NORMAL;
3220
3353
 
3221
 
  if (static_cast<unsigned int>(innobase_fast_shutdown) == 1)
 
3354
  if (innobase_fast_shutdown.get() == 1)
3222
3355
    shutdown_flag= IB_SHUTDOWN_NO_IBUFMERGE_PURGE;
3223
 
  else if (static_cast<unsigned int>(innobase_fast_shutdown) == 2)
 
3356
  else if (innobase_fast_shutdown.get() == 2)
3224
3357
    shutdown_flag= IB_SHUTDOWN_NO_BUFPOOL_FLUSH;
3225
3358
 
3226
3359
  err= ib_shutdown(shutdown_flag);
3233
3366
}
3234
3367
 
3235
3368
 
3236
 
static void haildb_lru_old_blocks_pct_update(Session*, drizzle_sys_var*,
3237
 
                                             void *,
3238
 
                                             const void *save)
3239
 
 
3240
 
{
3241
 
  unsigned long pct;
3242
 
 
3243
 
  pct= *static_cast<const unsigned long*>(save);
3244
 
 
3245
 
  ib_err_t err= ib_cfg_set_int("lru_old_blocks_pct", pct);
3246
 
  if (err == DB_SUCCESS)
3247
 
    innobase_lru_old_blocks_pct= pct;
3248
 
}
3249
 
 
3250
 
static void haildb_lru_block_access_recency_update(Session*, drizzle_sys_var*,
3251
 
                                                   void *,
3252
 
                                                   const void *save)
3253
 
 
3254
 
{
3255
 
  unsigned long ms;
3256
 
 
3257
 
  ms= *static_cast<const unsigned long*>(save);
3258
 
 
3259
 
  ib_err_t err= ib_cfg_set_int("lru_block_access_recency", ms);
3260
 
 
3261
 
  if (err == DB_SUCCESS)
3262
 
    innobase_lru_block_access_recency= ms;
3263
 
}
3264
 
 
3265
 
static void haildb_status_file_update(Session*, drizzle_sys_var*,
3266
 
                                      void *,
3267
 
                                      const void *save)
3268
 
 
3269
 
{
3270
 
  bool status_file_enabled;
3271
 
  ib_err_t err;
3272
 
 
3273
 
  status_file_enabled= *static_cast<const bool*>(save);
3274
 
 
3275
 
 
3276
 
  if (status_file_enabled)
3277
 
    err= ib_cfg_set_bool_on("status_file");
3278
 
  else
3279
 
    err= ib_cfg_set_bool_off("status_file");
3280
 
 
3281
 
  if (err == DB_SUCCESS)
3282
 
    innobase_create_status_file= status_file_enabled;
3283
 
}
3284
 
 
3285
 
static DRIZZLE_SYSVAR_STR(data_file_path, haildb_data_file_path,
3286
 
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3287
 
  "Path to individual files and their sizes.",
3288
 
  NULL, NULL, NULL);
3289
 
 
3290
 
static DRIZZLE_SYSVAR_LONGLONG(log_file_size, haildb_log_file_size,
3291
 
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3292
 
  "Size of each log file in a log group.",
3293
 
  NULL, NULL, 20*1024*1024L, 1*1024*1024L, INT64_MAX, 1024*1024L);
3294
 
 
3295
 
static DRIZZLE_SYSVAR_LONGLONG(log_files_in_group, haildb_log_files_in_group,
3296
 
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3297
 
  "Number of log files in the log group. HailDB writes to the files in a circular fashion. Value 3 is recommended here.",
3298
 
  NULL, NULL, 2, 2, 100, 0);
3299
 
 
3300
 
static DRIZZLE_SYSVAR_ULONG(lock_wait_timeout, innobase_lock_wait_timeout,
3301
 
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3302
 
  "Timeout in seconds an HailDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout.",
3303
 
  NULL, NULL, 5, 1, 1024 * 1024 * 1024, 0);
3304
 
 
3305
 
static DRIZZLE_SYSVAR_LONG(log_buffer_size, innobase_log_buffer_size,
3306
 
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3307
 
  "The size of the buffer which HailDB uses to write log to the log files on disk.",
3308
 
  NULL, NULL, 8*1024*1024L, 256*1024L, LONG_MAX, 1024);
3309
 
 
3310
 
static DRIZZLE_SYSVAR_ULONG(lru_old_blocks_pct, innobase_lru_old_blocks_pct,
3311
 
  PLUGIN_VAR_RQCMDARG,
3312
 
  "Sets the point in the LRU list from where all pages are classified as "
3313
 
  "old (Advanced users)",
3314
 
  NULL,
3315
 
  haildb_lru_old_blocks_pct_update, 37, 5, 95, 0);
3316
 
 
3317
 
static DRIZZLE_SYSVAR_ULONG(lru_block_access_recency, innobase_lru_block_access_recency,
3318
 
  PLUGIN_VAR_RQCMDARG,
3319
 
  "Milliseconds between accesses to a block at which it is made young. "
3320
 
  "0=disabled (Advanced users)",
3321
 
  NULL,
3322
 
  haildb_lru_block_access_recency_update, 0, 0, ULONG_MAX, 0);
3323
 
 
3324
 
 
3325
 
static DRIZZLE_SYSVAR_ULONG(max_dirty_pages_pct, srv_max_buf_pool_modified_pct,
3326
 
  PLUGIN_VAR_RQCMDARG,
3327
 
  "Percentage of dirty pages allowed in bufferpool.",
3328
 
  NULL, NULL, 75, 0, 99, 0);
3329
 
 
3330
 
static DRIZZLE_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag,
3331
 
  PLUGIN_VAR_RQCMDARG,
3332
 
  "Desired maximum length of the purge queue (0 = no limit)",
3333
 
  NULL, NULL, 0, 0, ~0L, 0);
3334
 
 
3335
 
static DRIZZLE_SYSVAR_BOOL(rollback_on_timeout, innobase_rollback_on_timeout,
3336
 
  PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
3337
 
  "Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)",
3338
 
  NULL, NULL, false);
3339
 
 
3340
 
static DRIZZLE_SYSVAR_LONG(open_files, innobase_open_files,
3341
 
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3342
 
  "How many files at the maximum HailDB keeps open at the same time.",
3343
 
  NULL, NULL, 300L, 10L, LONG_MAX, 0);
3344
 
 
3345
 
static DRIZZLE_SYSVAR_ULONG(read_io_threads, innobase_read_io_threads,
3346
 
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3347
 
  "Number of background read I/O threads in HailDB.",
3348
 
  NULL, NULL, 4, 1, 64, 0);
3349
 
 
3350
 
static DRIZZLE_SYSVAR_ULONG(write_io_threads, innobase_write_io_threads,
3351
 
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3352
 
  "Number of background write I/O threads in HailDB.",
3353
 
  NULL, NULL, 4, 1, 64, 0);
3354
 
 
3355
 
static DRIZZLE_SYSVAR_BOOL(print_verbose_log, innobase_print_verbose_log,
3356
 
  PLUGIN_VAR_NOCMDARG,
3357
 
  "Disable if you want to reduce the number of messages written to the log (default: enabled).",
3358
 
  NULL, NULL, true);
3359
 
 
3360
 
static DRIZZLE_SYSVAR_BOOL(status_file, innobase_create_status_file,
3361
 
  PLUGIN_VAR_OPCMDARG,
3362
 
  "Enable SHOW HAILDB STATUS output in the log",
3363
 
  NULL, haildb_status_file_update, false);
3364
 
 
3365
 
static DRIZZLE_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds,
3366
 
  PLUGIN_VAR_RQCMDARG,
3367
 
  "Count of spin-loop rounds in HailDB mutexes (30 by default)",
3368
 
  NULL, NULL, 30L, 0L, ~0L, 0);
3369
 
 
3370
 
static DRIZZLE_SYSVAR_BOOL(use_sys_malloc, srv_use_sys_malloc,
3371
 
  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
3372
 
  "Use OS memory allocator instead of HailDB's internal memory allocator",
3373
 
  NULL, NULL, true);
3374
 
 
3375
3369
static void init_options(drizzled::module::option_context &context)
3376
3370
{
3377
3371
  context("disable-adaptive-hash-index",
3388
3382
          po::value<buffer_pool_constraint>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
3389
3383
          N_("The size of the memory buffer HailDB uses to cache data and indexes of its tables."));
3390
3384
  context("data-home-dir",
3391
 
          po::value<string>(),
 
3385
          po::value<string>()->default_value(""),
3392
3386
          N_("The common part for HailDB table spaces."));
3393
3387
  context("disable-checksums",
3394
3388
          N_("Disable HailDB checksums validation (enabled by default)."));
3416
3410
          po::value<force_recovery_constraint>(&innobase_force_recovery)->default_value(0),
3417
3411
          N_("Helps to save your data in case the disk image of the database becomes corrupt."));
3418
3412
  context("data-file-path",
3419
 
          po::value<string>(),
 
3413
          po::value<string>()->default_value("ibdata1:10M:autoextend"),
3420
3414
          N_("Path to individual files and their sizes."));
3421
3415
  context("log-group-home-dir",
3422
3416
          po::value<string>(),
3423
3417
          N_("Path to HailDB log files."));
3424
3418
  context("log-file-size",
3425
 
          po::value<int64_t>(&haildb_log_file_size)->default_value(20*1024*1024L),
 
3419
          po::value<log_file_constraint>(&haildb_log_file_size)->default_value(20*1024*1024L),
3426
3420
          N_("Size of each log file in a log group."));
3427
3421
  context("haildb-log-files-in-group",
3428
 
          po::value<int64_t>(&haildb_log_files_in_group)->default_value(2),
 
3422
          po::value<log_files_in_group_constraint>(&haildb_log_files_in_group)->default_value(2),
3429
3423
          N_("Number of log files in the log group. HailDB writes to the files in a circular fashion. Value 3 is recommended here."));
3430
3424
  context("lock-wait-timeout",
3431
 
          po::value<unsigned long>(&innobase_lock_wait_timeout)->default_value(5),
 
3425
          po::value<lock_wait_constraint>(&innobase_lock_wait_timeout)->default_value(5),
3432
3426
          N_("Timeout in seconds an HailDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout."));
3433
3427
  context("log-buffer-size",
3434
 
        po::value<long>(&innobase_log_buffer_size)->default_value(8*1024*1024L),
 
3428
        po::value<log_buffer_size_constraint>(&innobase_log_buffer_size)->default_value(8*1024*1024L),
3435
3429
        N_("The size of the buffer which HailDB uses to write log to the log files on disk."));
3436
3430
  context("lru-old-blocks-pct",
3437
 
          po::value<unsigned long>(&innobase_lru_old_blocks_pct)->default_value(37),
 
3431
          po::value<lru_old_blocks_constraint>(&innobase_lru_old_blocks_pct)->default_value(37),
3438
3432
          N_("Sets the point in the LRU list from where all pages are classified as old (Advanced users)"));
3439
3433
  context("lru-block-access-recency",
3440
 
          po::value<unsigned long>(&innobase_lru_block_access_recency)->default_value(0),
 
3434
          po::value<uint32_t>(&innobase_lru_block_access_recency)->default_value(0),
3441
3435
          N_("Milliseconds between accesses to a block at which it is made young. 0=disabled (Advanced users)"));
3442
3436
  context("max-dirty-pages-pct",
3443
 
          po::value<unsigned long>(&srv_max_buf_pool_modified_pct)->default_value(75),
 
3437
          po::value<max_dirty_pages_constraint>(&haildb_max_dirty_pages_pct)->default_value(75),
3444
3438
          N_("Percentage of dirty pages allowed in bufferpool."));
3445
3439
  context("max-purge-lag",
3446
 
          po::value<unsigned long>(&srv_max_purge_lag)->default_value(0),
 
3440
          po::value<uint64_constraint>(&haildb_max_purge_lag)->default_value(0),
3447
3441
          N_("Desired maximum length of the purge queue (0 = no limit)"));
3448
3442
  context("rollback-on-timeout",
3449
3443
          po::value<bool>(&innobase_rollback_on_timeout)->default_value(false)->zero_tokens(),
3450
3444
          N_("Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)"));
3451
3445
  context("open-files",
3452
 
          po::value<long>(&innobase_open_files)->default_value(300),
 
3446
          po::value<open_files_constraint>(&haildb_open_files)->default_value(300),
3453
3447
          N_("How many files at the maximum HailDB keeps open at the same time."));
3454
3448
  context("read-io-threads",
3455
 
          po::value<unsigned long>(&innobase_read_io_threads)->default_value(4),
 
3449
          po::value<io_threads_constraint>(&haildb_read_io_threads)->default_value(4),
3456
3450
          N_("Number of background read I/O threads in HailDB."));
3457
3451
  context("write-io-threads",
3458
 
          po::value<unsigned long>(&innobase_write_io_threads)->default_value(4),
 
3452
          po::value<io_threads_constraint>(&haildb_write_io_threads)->default_value(4),
3459
3453
          N_("Number of background write I/O threads in HailDB."));
3460
3454
  context("disable-print-verbose-log",
3461
3455
          N_("Disable if you want to reduce the number of messages written to the log (default: enabled)."));
3463
3457
          po::value<bool>(&innobase_create_status_file)->default_value(false)->zero_tokens(),
3464
3458
          N_("Enable SHOW HAILDB STATUS output in the log"));
3465
3459
  context("sync-spin-loops",
3466
 
          po::value<unsigned long>(&srv_n_spin_wait_rounds)->default_value(30L),
 
3460
          po::value<uint64_constraint>(&haildb_sync_spin_loops)->default_value(30L),
3467
3461
          N_("Count of spin-loop rounds in HailDB mutexes (30 by default)"));
3468
3462
  context("use-internal-malloc",
3469
3463
          N_("Use HailDB's internal memory allocator instead of the OS memory allocator"));
3470
3464
}
3471
3465
 
3472
 
static drizzle_sys_var* innobase_system_variables[]= {
3473
 
  DRIZZLE_SYSVAR(data_file_path),
3474
 
  DRIZZLE_SYSVAR(lock_wait_timeout),
3475
 
  DRIZZLE_SYSVAR(log_file_size),
3476
 
  DRIZZLE_SYSVAR(log_files_in_group),
3477
 
  DRIZZLE_SYSVAR(log_buffer_size),
3478
 
  DRIZZLE_SYSVAR(lru_old_blocks_pct),
3479
 
  DRIZZLE_SYSVAR(lru_block_access_recency),
3480
 
  DRIZZLE_SYSVAR(max_dirty_pages_pct),
3481
 
  DRIZZLE_SYSVAR(max_purge_lag),
3482
 
  DRIZZLE_SYSVAR(open_files),
3483
 
  DRIZZLE_SYSVAR(read_io_threads),
3484
 
  DRIZZLE_SYSVAR(rollback_on_timeout),
3485
 
  DRIZZLE_SYSVAR(write_io_threads),
3486
 
  DRIZZLE_SYSVAR(print_verbose_log),
3487
 
  DRIZZLE_SYSVAR(status_file),
3488
 
  DRIZZLE_SYSVAR(sync_spin_loops),
3489
 
  DRIZZLE_SYSVAR(use_sys_malloc),
3490
 
  NULL
3491
 
};
3492
 
 
3493
3466
DRIZZLE_DECLARE_PLUGIN
3494
3467
{
3495
3468
  DRIZZLE_VERSION_ID,
3499
3472
  "Transactional Storage Engine using the HailDB Library",
3500
3473
  PLUGIN_LICENSE_GPL,
3501
3474
  haildb_init,     /* Plugin Init */
3502
 
  innobase_system_variables, /* system variables */
 
3475
  NULL, /* system variables */
3503
3476
  init_options                /* config options   */
3504
3477
}
3505
3478
DRIZZLE_DECLARE_PLUGIN_END;