2019
1982
ret= HA_ERR_FOUND_DUPP_KEY;
2021
1984
else if (err != DB_SUCCESS)
2022
ret= ib_err_t_to_drizzle_error(getTable()->getSession(), err);
1985
ret= ib_err_t_to_drizzle_error(err);
2024
1987
tuple= ib_tuple_clear(tuple);
2025
1988
ib_tuple_delete(tuple);
2027
1989
err= ib_cursor_reset(cursor);
2032
int HailDBCursor::doUpdateRecord(const unsigned char *old_data,
2033
unsigned char *new_data)
1994
int HailDBCursor::doUpdateRecord(const unsigned char *,
2035
1997
ib_tpl_t update_tuple;
2037
bool created_tuple= false;
2039
2000
update_tuple= ib_clust_read_tuple_create(cursor);
2043
ib_trx_t transaction= *get_trx(getTable()->in_use);
2045
if (cursor_is_sec_index)
2047
err= ib_cursor_close(cursor);
2048
assert(err == DB_SUCCESS);
2050
err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2052
if (err != DB_SUCCESS)
2053
return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2054
cursor_is_sec_index= false;
2058
ib_cursor_attach_trx(cursor, transaction);
2061
store_key_value_from_haildb(getTable()->key_info + getTable()->getShare()->getPrimaryKey(),
2062
ref, ref_length, old_data);
2064
ib_tpl_t search_tuple= ib_clust_search_tuple_create(cursor);
2066
fill_ib_search_tpl_from_drizzle_key(search_tuple,
2067
getTable()->key_info + 0,
2070
err= ib_cursor_set_lock_mode(cursor, IB_LOCK_X);
2071
assert(err == DB_SUCCESS);
2074
err= ib_cursor_moveto(cursor, search_tuple, IB_CUR_GE, &res);
2075
assert(err == DB_SUCCESS);
2077
tuple= ib_clust_read_tuple_create(cursor);
2079
err= ib_cursor_read_row(cursor, tuple);
2080
assert(err == DB_SUCCESS);// FIXME
2082
created_tuple= true;
2085
2002
err= ib_tuple_copy(update_tuple, tuple);
2086
2003
assert(err == DB_SUCCESS);
2088
write_row_to_haildb_tuple(new_data, getTable()->getFields(), update_tuple);
2005
write_row_to_haildb_tuple(table->getFields(), update_tuple);
2090
2007
err= ib_cursor_update_row(cursor, tuple, update_tuple);
2092
2009
ib_tuple_delete(update_tuple);
2096
ib_err_t ib_err= ib_cursor_reset(cursor); //fixme check error
2097
assert(ib_err == DB_SUCCESS);
2098
tuple= ib_tuple_clear(tuple);
2099
ib_tuple_delete(tuple);
2103
2011
advance_cursor= true;
2105
return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2013
if (err == DB_SUCCESS)
2015
else if (err == DB_DUPLICATE_KEY)
2016
return HA_ERR_FOUND_DUPP_KEY;
2108
2021
int HailDBCursor::doDeleteRecord(const unsigned char *)
2112
assert(ib_cursor_is_positioned(cursor) == IB_TRUE);
2113
2025
err= ib_cursor_delete_row(cursor);
2026
if (err != DB_SUCCESS)
2115
2029
advance_cursor= true;
2117
return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2120
2033
int HailDBCursor::delete_all_rows(void)
2122
2035
/* I *think* ib_truncate is non-transactional....
2123
2036
so only support TRUNCATE and not DELETE FROM t;
2124
(this is what ha_innodb does)
2037
(this is what ha_haildb does)
2126
if (getTable()->in_use->getSqlCommand() != SQLCOM_TRUNCATE)
2039
if (session_sql_command(table->in_use) != SQLCOM_TRUNCATE)
2127
2040
return HA_ERR_WRONG_COMMAND;
2479
2354
double HailDBCursor::scan_time()
2481
ib_table_stats_t table_stats;
2484
err= ib_get_table_statistics(cursor, &table_stats, sizeof(table_stats));
2486
/* Approximate I/O seeks for full table scan */
2487
return (double) (table_stats.stat_clustered_index_size / 16384);
2490
2359
int HailDBCursor::info(uint32_t flag)
2492
ib_table_stats_t table_stats;
2495
if (flag & HA_STATUS_VARIABLE)
2497
err= ib_get_table_statistics(cursor, &table_stats, sizeof(table_stats));
2499
stats.records= table_stats.stat_n_rows;
2501
if (table_stats.stat_n_rows < 2)
2505
stats.data_file_length= table_stats.stat_clustered_index_size;
2506
stats.index_file_length= table_stats.stat_sum_of_other_index_sizes;
2508
stats.mean_rec_length= stats.data_file_length / stats.records;
2511
2363
if (flag & HA_STATUS_AUTO)
2512
2364
stats.auto_increment_value= 1;
2514
if (flag & HA_STATUS_ERRKEY) {
2515
const char *err_table_name;
2516
const char *err_index_name;
2518
ib_trx_t transaction= *get_trx(getTable()->in_use);
2520
err= ib_get_duplicate_key(transaction, &err_table_name, &err_index_name);
2524
for (unsigned int i = 0; i < getTable()->getShare()->keys; i++)
2526
if (strcmp(err_index_name, getTable()->key_info[i].name) == 0)
2535
if (flag & HA_STATUS_CONST)
2537
for (unsigned int i = 0; i < getTable()->getShare()->sizeKeys(); i++)
2539
const char* index_name= getTable()->key_info[i].name;
2542
ha_rows rec_per_key;
2544
err= ib_get_index_stat_n_diff_key_vals(cursor, index_name,
2547
if (err != DB_SUCCESS)
2548
return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2550
for (unsigned int j=0; j < getTable()->key_info[i].key_parts; j++)
2552
if (n_diff[j+1] == 0)
2553
rec_per_key= stats.records;
2555
rec_per_key= stats.records / n_diff[j+1];
2557
/* We import this heuristic from ha_innodb, which says
2558
that MySQL favours table scans too much over index searches,
2559
so we pretend our index selectivity is 2 times better. */
2561
rec_per_key= rec_per_key / 2;
2563
if (rec_per_key == 0)
2566
getTable()->key_info[i].rec_per_key[j]=
2567
rec_per_key >= ~(ulong) 0 ? ~(ulong) 0 :
2568
(ulong) rec_per_key;
2578
2368
int HailDBCursor::doStartIndexScan(uint32_t keynr, bool)
2581
ib_trx_t transaction= *get_trx(getTable()->in_use);
2370
ib_trx_t transaction= *get_trx(table->in_use);
2583
2372
active_index= keynr;
2374
ib_cursor_attach_trx(cursor, transaction);
2585
2376
if (active_index == 0 && ! share->has_hidden_primary_key)
2587
if (cursor_is_sec_index)
2589
err= ib_cursor_close(cursor);
2590
assert(err == DB_SUCCESS);
2592
err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2594
if (err != DB_SUCCESS)
2595
return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2600
ib_cursor_attach_trx(cursor, transaction);
2603
cursor_is_sec_index= false;
2604
2378
tuple= ib_clust_read_tuple_create(cursor);
2608
2383
ib_id_t index_id;
2609
err= ib_index_get_id(table_path_to_haildb_name(getShare()->getPath()),
2610
getShare()->getKeyInfo(keynr).name,
2384
err= ib_index_get_id(table_path_to_haildb_name(table_share->getPath()),
2385
table_share->getKeyInfo(keynr).name,
2612
2387
if (err != DB_SUCCESS)
2613
return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2615
2390
err= ib_cursor_close(cursor);
2616
2391
assert(err == DB_SUCCESS);
2618
2392
err= ib_cursor_open_index_using_id(index_id, transaction, &cursor);
2620
2394
if (err != DB_SUCCESS)
2621
return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2623
cursor_is_sec_index= true;
2625
2397
tuple= ib_clust_read_tuple_create(cursor);
2626
2398
ib_cursor_set_cluster_access(cursor);
2629
err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2401
ib_err_t err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2630
2402
assert(err == DB_SUCCESS);
2632
2404
advance_cursor= false;
3051
2814
static bool innobase_rollback_on_timeout;
3052
2815
static bool innobase_create_status_file;
3053
2816
static bool srv_use_sys_malloc;
3054
static string innobase_file_format_name;
3055
typedef constrained_check<unsigned int, 1000, 1> autoextend_constraint;
3056
static autoextend_constraint srv_auto_extend_increment;
3057
typedef constrained_check<size_t, SIZE_MAX, 5242880, 1048576> buffer_pool_constraint;
3058
static buffer_pool_constraint innobase_buffer_pool_size;
3059
typedef constrained_check<size_t, SIZE_MAX, 512, 1024> additional_mem_pool_constraint;
3060
static additional_mem_pool_constraint innobase_additional_mem_pool_size;
3061
static bool innobase_use_checksums= true;
3062
typedef constrained_check<unsigned int, UINT_MAX, 100> io_capacity_constraint;
3063
typedef constrained_check<uint32_t, 2, 0> trinary_constraint;
3064
static trinary_constraint innobase_fast_shutdown;
3065
static trinary_constraint srv_flush_log_at_trx_commit;
3066
typedef constrained_check<uint32_t, 6, 0> force_recovery_constraint;
3067
static force_recovery_constraint innobase_force_recovery;
3068
typedef constrained_check<int64_t, INT64_MAX, 1024*1024, 1024*1024> log_file_constraint;
3069
static log_file_constraint haildb_log_file_size;
3071
static io_capacity_constraint srv_io_capacity;
3072
typedef constrained_check<unsigned int, 100, 2> log_files_in_group_constraint;
3073
static log_files_in_group_constraint haildb_log_files_in_group;
3074
typedef constrained_check<unsigned int, 1024*1024*1024, 1> lock_wait_constraint;
3075
static lock_wait_constraint innobase_lock_wait_timeout;
3076
typedef constrained_check<long, LONG_MAX, 256*1024, 1024> log_buffer_size_constraint;
3077
static log_buffer_size_constraint innobase_log_buffer_size;
3078
typedef constrained_check<unsigned int, 97, 5> lru_old_blocks_constraint;
3079
static lru_old_blocks_constraint innobase_lru_old_blocks_pct;
3080
typedef constrained_check<unsigned int, 99, 0> max_dirty_pages_constraint;
3081
static max_dirty_pages_constraint haildb_max_dirty_pages_pct;
3082
static uint64_constraint haildb_max_purge_lag;
3083
static uint64_constraint haildb_sync_spin_loops;
3084
typedef constrained_check<uint32_t, UINT32_MAX, 10> open_files_constraint;
3085
static open_files_constraint haildb_open_files;
3086
typedef constrained_check<unsigned int, 64, 1> io_threads_constraint;
3087
static io_threads_constraint haildb_read_io_threads;
3088
static io_threads_constraint haildb_write_io_threads;
3091
static uint32_t innobase_lru_block_access_recency;
3095
static int haildb_file_format_name_validate(Session*, set_var *var)
3098
const char *format= var->value->str_value.ptr();
3102
ib_err_t err= ib_cfg_set_text("file_format", format);
3104
if (err == DB_SUCCESS)
3106
innobase_file_format_name= format;
3113
static void haildb_lru_old_blocks_pct_update(Session*, sql_var_t)
3115
int ret= ib_cfg_set_int("lru_old_blocks_pct", static_cast<uint32_t>(innobase_lru_old_blocks_pct));
3119
static void haildb_lru_block_access_recency_update(Session*, sql_var_t)
3121
int ret= ib_cfg_set_int("lru_block_access_recency", static_cast<uint32_t>(innobase_lru_block_access_recency));
3125
static void haildb_status_file_update(Session*, sql_var_t)
3129
if (innobase_create_status_file)
3130
err= ib_cfg_set_bool_on("status_file");
3132
err= ib_cfg_set_bool_off("status_file");
3136
extern "C" int haildb_errmsg_callback(ib_msg_stream_t, const char *fmt, ...);
3139
extern bool volatile shutdown_in_progress;
3142
extern "C" int haildb_errmsg_callback(ib_msg_stream_t, const char *fmt, ...)
3146
va_start(args, fmt);
3147
if (not shutdown_in_progress)
3149
r= plugin::ErrorMessage::vprintf(error::WARN, fmt, args);
3153
vfprintf(stderr, fmt, args);
2817
static char* innobase_file_format_name = const_cast<char *>("Barracuda");
2818
static char* innobase_unix_file_flush_method = NULL;
2819
static unsigned long srv_flush_log_at_trx_commit;
2820
static unsigned long srv_max_buf_pool_modified_pct;
2821
static unsigned long srv_max_purge_lag;
2822
static unsigned long innobase_lru_old_blocks_pct;
2823
static unsigned long innobase_lru_block_access_recency;
2824
static unsigned long innobase_read_io_threads;
2825
static unsigned long innobase_write_io_threads;
2826
static unsigned int srv_auto_extend_increment;
2827
static unsigned long innobase_lock_wait_timeout;
2828
static unsigned long srv_n_spin_wait_rounds;
2829
static int64_t innobase_buffer_pool_size;
2830
static long innobase_open_files;
2831
static long innobase_additional_mem_pool_size;
2832
static long innobase_force_recovery;
2833
static long innobase_log_buffer_size;
2834
static char default_haildb_data_file_path[]= "ibdata1:10M:autoextend";
2835
static char* haildb_data_file_path= NULL;
2837
static int64_t haildb_log_file_size;
2838
static int64_t haildb_log_files_in_group;
3160
2840
static int haildb_init(drizzled::module::Context &context)
3177
2857
innobase_print_verbose_log= (vm.count("disable-print-verbose-log")) ? false : true;
3178
2858
srv_use_sys_malloc= (vm.count("use-internal-malloc")) ? false : true;
2860
if (vm.count("additional-mem-pool-size"))
2862
if (innobase_additional_mem_pool_size > LONG_MAX || innobase_additional_mem_pool_size < 512*1024L)
2864
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of additional-mem-pool-size"));
2867
innobase_additional_mem_pool_size/= 1024;
2868
innobase_additional_mem_pool_size*= 1024;
2871
if (vm.count("autoextend-increment"))
2873
if (srv_auto_extend_increment > 1000L || srv_auto_extend_increment < 1L)
2875
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of autoextend-increment"));
2880
if (vm.count("buffer-pool-size"))
2882
if (innobase_buffer_pool_size > INT64_MAX || innobase_buffer_pool_size < 5*1024*1024L)
2884
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of buffer-pool-size"));
2887
innobase_buffer_pool_size/= 1024*1024L;
2888
innobase_buffer_pool_size*= 1024*1024L;
2891
if (vm.count("io-capacity"))
2893
if (srv_io_capacity > (unsigned long)~0L || srv_io_capacity < 100)
2895
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of io-capacity"));
2900
if (vm.count("fast-shutdown"))
2902
if (innobase_fast_shutdown > 2)
2904
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of fast-shutdown"));
2909
if (vm.count("flush-log-at-trx-commit"))
2911
if (srv_flush_log_at_trx_commit > 2)
2913
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of flush-log-at-trx-commit"));
2918
if (vm.count("force-recovery"))
2920
if (innobase_force_recovery > 6)
2922
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of force-recovery"));
2927
if (vm.count("log-file-size"))
2929
if (haildb_log_file_size > INT64_MAX || haildb_log_file_size < 1*1024*1024L)
2931
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-file-size"));
2934
haildb_log_file_size/= 1024*1024L;
2935
haildb_log_file_size*= 1024*1024L;
2938
if (vm.count("log-files-in-group"))
2940
if (haildb_log_files_in_group > 100 || haildb_log_files_in_group < 2)
2942
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-files-in-group"));
2947
if (vm.count("lock-wait-timeout"))
2949
if (innobase_lock_wait_timeout > 1024*1024*1024 || innobase_lock_wait_timeout < 1)
2951
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lock-wait-timeout"));
2956
if (vm.count("log-buffer-size"))
2958
if (innobase_log_buffer_size > LONG_MAX || innobase_log_buffer_size < 256*1024L)
2960
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of log-buffer-size"));
2963
innobase_log_buffer_size/= 1024;
2964
innobase_log_buffer_size*= 1024;
2967
if (vm.count("lru-old-blocks-pct"))
2969
if (innobase_lru_old_blocks_pct > 95 || innobase_lru_old_blocks_pct < 5)
2971
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lru-old-blocks-pct"));
2976
if (vm.count("lru-block-access-recency"))
2978
if (innobase_lru_block_access_recency > ULONG_MAX)
2980
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of lru-block-access-recency"));
2985
if (vm.count("max-dirty-pages-pct"))
2987
if (srv_max_buf_pool_modified_pct > 99)
2989
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of max-dirty-pages-pct"));
2994
if (vm.count("max-purge-lag"))
2996
if (srv_max_purge_lag > (unsigned long)~0L)
2998
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of max-purge-lag"));
3003
if (vm.count("open-files"))
3005
if (innobase_open_files > LONG_MAX || innobase_open_files < 10L)
3007
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of open-files"));
3012
if (vm.count("read-io-threads"))
3014
if (innobase_read_io_threads > 64 || innobase_read_io_threads < 1)
3016
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of read-io-threads"));
3021
if (vm.count("sync-spin-loops"))
3023
if (srv_n_spin_wait_rounds > (unsigned long)~0L)
3025
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of sync_spin_loops"));
3030
if (vm.count("data-home-dir"))
3032
innobase_data_home_dir= const_cast<char *>(vm["data-home-dir"].as<string>().c_str());
3035
if (vm.count("file-format"))
3037
innobase_file_format_name= const_cast<char *>(vm["file-format"].as<string>().c_str());
3040
if (vm.count("log-group-home-dir"))
3042
innobase_log_group_home_dir= const_cast<char *>(vm["log-group-home-dir"].as<string>().c_str());
3045
if (vm.count("flush-method"))
3047
innobase_unix_file_flush_method= const_cast<char *>(vm["flush-method"].as<string>().c_str());
3050
if (vm.count("data-file-path"))
3052
haildb_data_file_path= const_cast<char *>(vm["data-file-path"].as<string>().c_str());
3347
3219
haildb_engine= new HailDBEngine("InnoDB");
3348
3220
context.add(haildb_engine);
3349
context.registerVariable(new sys_var_bool_ptr_readonly("adaptive_hash_index",
3350
&innobase_adaptive_hash_index));
3351
context.registerVariable(new sys_var_bool_ptr_readonly("adaptive_flushing",
3352
&srv_adaptive_flushing));
3353
context.registerVariable(new sys_var_constrained_value_readonly<size_t>("additional_mem_pool_size",innobase_additional_mem_pool_size));
3354
context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("autoextend_increment", srv_auto_extend_increment));
3355
context.registerVariable(new sys_var_constrained_value_readonly<size_t>("buffer_pool_size", innobase_buffer_pool_size));
3356
context.registerVariable(new sys_var_bool_ptr_readonly("checksums",
3357
&innobase_use_checksums));
3358
context.registerVariable(new sys_var_bool_ptr_readonly("doublewrite",
3359
&innobase_use_doublewrite));
3360
context.registerVariable(new sys_var_const_string_val("data_file_path",
3361
vm["data-file-path"].as<string>()));
3362
context.registerVariable(new sys_var_const_string_val("data_home_dir",
3363
vm["data-home-dir"].as<string>()));
3364
context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("io_capacity", srv_io_capacity));
3365
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("fast_shutdown", innobase_fast_shutdown));
3366
context.registerVariable(new sys_var_bool_ptr_readonly("file_per_table",
3367
&srv_file_per_table));
3368
context.registerVariable(new sys_var_bool_ptr_readonly("rollback_on_timeout",
3369
&innobase_rollback_on_timeout));
3370
context.registerVariable(new sys_var_bool_ptr_readonly("print_verbose_log",
3371
&innobase_print_verbose_log));
3372
context.registerVariable(new sys_var_bool_ptr("status_file",
3373
&innobase_create_status_file,
3374
haildb_status_file_update));
3375
context.registerVariable(new sys_var_bool_ptr_readonly("use_sys_malloc",
3376
&srv_use_sys_malloc));
3377
context.registerVariable(new sys_var_std_string("file_format",
3378
innobase_file_format_name,
3379
haildb_file_format_name_validate));
3380
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("flush_log_at_trx_commit", srv_flush_log_at_trx_commit));
3381
context.registerVariable(new sys_var_const_string_val("flush_method",
3382
vm.count("flush-method") ? vm["flush-method"].as<string>() : ""));
3383
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("force_recovery", innobase_force_recovery));
3384
context.registerVariable(new sys_var_const_string_val("log_group_home_dir",
3385
vm.count("log-group-home-dir") ? vm["log-group-home-dir"].as<string>() : ""));
3386
context.registerVariable(new sys_var_constrained_value<int64_t>("log_file_size", haildb_log_file_size));
3387
context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("log_files_in_group", haildb_log_files_in_group));
3388
context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("lock_wait_timeout", innobase_lock_wait_timeout));
3389
context.registerVariable(new sys_var_constrained_value_readonly<long>("log_buffer_size", innobase_log_buffer_size));
3390
context.registerVariable(new sys_var_constrained_value<unsigned int>("lru_old_blocks_pct", innobase_lru_old_blocks_pct, haildb_lru_old_blocks_pct_update));
3391
context.registerVariable(new sys_var_uint32_t_ptr("lru_block_access_recency",
3392
&innobase_lru_block_access_recency,
3393
haildb_lru_block_access_recency_update));
3394
context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("max_dirty_pages_pct", haildb_max_dirty_pages_pct));
3395
context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("max_purge_lag", haildb_max_purge_lag));
3396
context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("sync_spin_loops", haildb_sync_spin_loops));
3397
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("open_files", haildb_open_files));
3398
context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("read_io_threads", haildb_read_io_threads));
3399
context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("write_io_threads", haildb_write_io_threads));
3222
haildb_version_func_initialize(context);
3401
3223
haildb_datadict_dump_func_initialize(context);
3402
3224
config_table_function_initialize(context);
3403
3225
status_table_function_initialize(context);
3254
static char haildb_file_format_name_storage[100];
3256
static int haildb_file_format_name_validate(Session*, drizzle_sys_var*,
3258
drizzle_value *value)
3262
int len= sizeof(buff);
3263
const char *format= value->val_str(value, buff, &len);
3265
*static_cast<const char**>(save)= NULL;
3270
err= ib_cfg_set_text("file_format", format);
3272
if (err == DB_SUCCESS)
3274
strncpy(haildb_file_format_name_storage, format, sizeof(haildb_file_format_name_storage));;
3275
haildb_file_format_name_storage[sizeof(haildb_file_format_name_storage)-1]= 0;
3277
*static_cast<const char**>(save)= haildb_file_format_name_storage;
3284
static void haildb_file_format_name_update(Session*, drizzle_sys_var*,
3291
assert(var_ptr != NULL);
3292
assert(save != NULL);
3294
format= *static_cast<const char*const*>(save);
3296
/* Format is already set in validate */
3297
memmove(haildb_file_format_name_storage, format, sizeof(haildb_file_format_name_storage));;
3298
haildb_file_format_name_storage[sizeof(haildb_file_format_name_storage)-1]= 0;
3300
*static_cast<const char**>(var_ptr)= haildb_file_format_name_storage;
3303
static void haildb_lru_old_blocks_pct_update(Session*, drizzle_sys_var*,
3310
pct= *static_cast<const unsigned long*>(save);
3312
ib_err_t err= ib_cfg_set_int("lru_old_blocks_pct", pct);
3313
if (err == DB_SUCCESS)
3314
innobase_lru_old_blocks_pct= pct;
3317
static void haildb_lru_block_access_recency_update(Session*, drizzle_sys_var*,
3324
ms= *static_cast<const unsigned long*>(save);
3326
ib_err_t err= ib_cfg_set_int("lru_block_access_recency", ms);
3328
if (err == DB_SUCCESS)
3329
innobase_lru_block_access_recency= ms;
3332
static void haildb_status_file_update(Session*, drizzle_sys_var*,
3337
bool status_file_enabled;
3340
status_file_enabled= *static_cast<const bool*>(save);
3343
if (status_file_enabled)
3344
err= ib_cfg_set_bool_on("status_file");
3346
err= ib_cfg_set_bool_off("status_file");
3348
if (err == DB_SUCCESS)
3349
innobase_create_status_file= status_file_enabled;
3352
static DRIZZLE_SYSVAR_BOOL(adaptive_hash_index, innobase_adaptive_hash_index,
3353
PLUGIN_VAR_NOCMDARG,
3354
"Enable HailDB adaptive hash index (enabled by default). ",
3357
static DRIZZLE_SYSVAR_BOOL(adaptive_flushing, srv_adaptive_flushing,
3358
PLUGIN_VAR_NOCMDARG,
3359
"Attempt flushing dirty pages to avoid IO bursts at checkpoints.",
3362
static DRIZZLE_SYSVAR_LONG(additional_mem_pool_size, innobase_additional_mem_pool_size,
3363
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3364
"Size of a memory pool HailDB uses to store data dictionary information and other internal data structures.",
3365
NULL, NULL, 8*1024*1024L, 512*1024L, LONG_MAX, 1024);
3367
static DRIZZLE_SYSVAR_UINT(autoextend_increment, srv_auto_extend_increment,
3368
PLUGIN_VAR_RQCMDARG,
3369
"Data file autoextend increment in megabytes",
3370
NULL, NULL, 8L, 1L, 1000L, 0);
3372
static DRIZZLE_SYSVAR_LONGLONG(buffer_pool_size, innobase_buffer_pool_size,
3373
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3374
"The size of the memory buffer HailDB uses to cache data and indexes of its tables.",
3375
NULL, NULL, 128*1024*1024L, 5*1024*1024L, INT64_MAX, 1024*1024L);
3377
static DRIZZLE_SYSVAR_BOOL(checksums, innobase_use_checksums,
3378
PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
3379
"Enable HailDB checksums validation (enabled by default). "
3380
"Disable with --skip-haildb-checksums.",
3383
static DRIZZLE_SYSVAR_STR(data_home_dir, innobase_data_home_dir,
3384
PLUGIN_VAR_READONLY,
3385
"The common part for HailDB table spaces.",
3388
static DRIZZLE_SYSVAR_BOOL(doublewrite, innobase_use_doublewrite,
3389
PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
3390
"Enable HailDB doublewrite buffer (enabled by default). "
3391
"Disable with --skip-haildb-doublewrite.",
3394
static DRIZZLE_SYSVAR_ULONG(io_capacity, srv_io_capacity,
3395
PLUGIN_VAR_RQCMDARG,
3396
"Number of IOPs the server can do. Tunes the background IO rate",
3397
NULL, NULL, 200, 100, ~0L, 0);
3399
static DRIZZLE_SYSVAR_ULONG(fast_shutdown, innobase_fast_shutdown,
3400
PLUGIN_VAR_OPCMDARG,
3401
"Speeds up the shutdown process of the HailDB storage engine. Possible "
3402
"values are 0, 1 (faster)"
3403
" or 2 (fastest - crash-like)"
3405
NULL, NULL, 1, 0, 2, 0);
3407
static DRIZZLE_SYSVAR_BOOL(file_per_table, srv_file_per_table,
3408
PLUGIN_VAR_NOCMDARG,
3409
"Stores each HailDB table to an .ibd file in the database dir.",
3412
static DRIZZLE_SYSVAR_STR(file_format, innobase_file_format_name,
3413
PLUGIN_VAR_RQCMDARG,
3414
"File format to use for new tables in .ibd files.",
3415
haildb_file_format_name_validate,
3416
haildb_file_format_name_update, "Barracuda");
3418
static DRIZZLE_SYSVAR_ULONG(flush_log_at_trx_commit, srv_flush_log_at_trx_commit,
3419
PLUGIN_VAR_OPCMDARG,
3420
"Set to 0 (write and flush once per second),"
3421
" 1 (write and flush at each commit)"
3422
" or 2 (write at commit, flush once per second).",
3423
NULL, NULL, 1, 0, 2, 0);
3425
static DRIZZLE_SYSVAR_STR(flush_method, innobase_unix_file_flush_method,
3426
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3427
"With which method to flush data.", NULL, NULL, NULL);
3429
static DRIZZLE_SYSVAR_LONG(force_recovery, innobase_force_recovery,
3430
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3431
"Helps to save your data in case the disk image of the database becomes corrupt.",
3432
NULL, NULL, 0, 0, 6, 0);
3434
static DRIZZLE_SYSVAR_STR(data_file_path, haildb_data_file_path,
3435
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3436
"Path to individual files and their sizes.",
3439
static DRIZZLE_SYSVAR_STR(log_group_home_dir, innobase_log_group_home_dir,
3440
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3441
"Path to HailDB log files.", NULL, NULL, NULL);
3443
static DRIZZLE_SYSVAR_LONGLONG(log_file_size, haildb_log_file_size,
3444
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3445
"Size of each log file in a log group.",
3446
NULL, NULL, 20*1024*1024L, 1*1024*1024L, INT64_MAX, 1024*1024L);
3448
static DRIZZLE_SYSVAR_LONGLONG(log_files_in_group, haildb_log_files_in_group,
3449
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3450
"Number of log files in the log group. HailDB writes to the files in a circular fashion. Value 3 is recommended here.",
3451
NULL, NULL, 2, 2, 100, 0);
3453
static DRIZZLE_SYSVAR_ULONG(lock_wait_timeout, innobase_lock_wait_timeout,
3454
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3455
"Timeout in seconds an HailDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout.",
3456
NULL, NULL, 5, 1, 1024 * 1024 * 1024, 0);
3458
static DRIZZLE_SYSVAR_LONG(log_buffer_size, innobase_log_buffer_size,
3459
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3460
"The size of the buffer which HailDB uses to write log to the log files on disk.",
3461
NULL, NULL, 8*1024*1024L, 256*1024L, LONG_MAX, 1024);
3463
static DRIZZLE_SYSVAR_ULONG(lru_old_blocks_pct, innobase_lru_old_blocks_pct,
3464
PLUGIN_VAR_RQCMDARG,
3465
"Sets the point in the LRU list from where all pages are classified as "
3466
"old (Advanced users)",
3468
haildb_lru_old_blocks_pct_update, 37, 5, 95, 0);
3470
static DRIZZLE_SYSVAR_ULONG(lru_block_access_recency, innobase_lru_block_access_recency,
3471
PLUGIN_VAR_RQCMDARG,
3472
"Milliseconds between accesses to a block at which it is made young. "
3473
"0=disabled (Advanced users)",
3475
haildb_lru_block_access_recency_update, 0, 0, ULONG_MAX, 0);
3478
static DRIZZLE_SYSVAR_ULONG(max_dirty_pages_pct, srv_max_buf_pool_modified_pct,
3479
PLUGIN_VAR_RQCMDARG,
3480
"Percentage of dirty pages allowed in bufferpool.",
3481
NULL, NULL, 75, 0, 99, 0);
3483
static DRIZZLE_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag,
3484
PLUGIN_VAR_RQCMDARG,
3485
"Desired maximum length of the purge queue (0 = no limit)",
3486
NULL, NULL, 0, 0, ~0L, 0);
3488
static DRIZZLE_SYSVAR_BOOL(rollback_on_timeout, innobase_rollback_on_timeout,
3489
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
3490
"Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)",
3493
static DRIZZLE_SYSVAR_LONG(open_files, innobase_open_files,
3494
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3495
"How many files at the maximum HailDB keeps open at the same time.",
3496
NULL, NULL, 300L, 10L, LONG_MAX, 0);
3498
static DRIZZLE_SYSVAR_ULONG(read_io_threads, innobase_read_io_threads,
3499
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3500
"Number of background read I/O threads in HailDB.",
3501
NULL, NULL, 4, 1, 64, 0);
3503
static DRIZZLE_SYSVAR_ULONG(write_io_threads, innobase_write_io_threads,
3504
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3505
"Number of background write I/O threads in HailDB.",
3506
NULL, NULL, 4, 1, 64, 0);
3508
static DRIZZLE_SYSVAR_BOOL(print_verbose_log, innobase_print_verbose_log,
3509
PLUGIN_VAR_NOCMDARG,
3510
"Disable if you want to reduce the number of messages written to the log (default: enabled).",
3513
static DRIZZLE_SYSVAR_BOOL(status_file, innobase_create_status_file,
3514
PLUGIN_VAR_OPCMDARG,
3515
"Enable SHOW HAILDB STATUS output in the log",
3516
NULL, haildb_status_file_update, false);
3518
static DRIZZLE_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds,
3519
PLUGIN_VAR_RQCMDARG,
3520
"Count of spin-loop rounds in HailDB mutexes (30 by default)",
3521
NULL, NULL, 30L, 0L, ~0L, 0);
3523
static DRIZZLE_SYSVAR_BOOL(use_sys_malloc, srv_use_sys_malloc,
3524
PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
3525
"Use OS memory allocator instead of HailDB's internal memory allocator",
3433
3528
static void init_options(drizzled::module::option_context &context)
3437
3532
context("disable-adaptive-flushing",
3438
3533
N_("Do not attempt to flush dirty pages to avoid IO bursts at checkpoints."));
3439
3534
context("additional-mem-pool-size",
3440
po::value<additional_mem_pool_constraint>(&innobase_additional_mem_pool_size)->default_value(8*1024*1024L),
3535
po::value<long>(&innobase_additional_mem_pool_size)->default_value(8*1024*1024L),
3441
3536
N_("Size of a memory pool HailDB uses to store data dictionary information and other internal data structures."));
3442
3537
context("autoextend-increment",
3443
po::value<autoextend_constraint>(&srv_auto_extend_increment)->default_value(8),
3538
po::value<unsigned int>(&srv_auto_extend_increment)->default_value(8L),
3444
3539
N_("Data file autoextend increment in megabytes"));
3445
3540
context("buffer-pool-size",
3446
po::value<buffer_pool_constraint>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
3541
po::value<int64_t>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
3447
3542
N_("The size of the memory buffer HailDB uses to cache data and indexes of its tables."));
3448
3543
context("data-home-dir",
3449
po::value<string>()->default_value(""),
3544
po::value<string>(),
3450
3545
N_("The common part for HailDB table spaces."));
3451
3546
context("disable-checksums",
3452
3547
N_("Disable HailDB checksums validation (enabled by default)."));
3453
3548
context("disable-doublewrite",
3454
3549
N_("Disable HailDB doublewrite buffer (enabled by default)."));
3455
3550
context("io-capacity",
3456
po::value<io_capacity_constraint>(&srv_io_capacity)->default_value(200),
3551
po::value<unsigned long>(&srv_io_capacity)->default_value(200),
3457
3552
N_("Number of IOPs the server can do. Tunes the background IO rate"));
3458
3553
context("fast-shutdown",
3459
po::value<trinary_constraint>(&innobase_fast_shutdown)->default_value(1),
3554
po::value<unsigned long>(&innobase_fast_shutdown)->default_value(1),
3460
3555
N_("Speeds up the shutdown process of the HailDB storage engine. Possible values are 0, 1 (faster) or 2 (fastest - crash-like)."));
3461
3556
context("file-per-table",
3462
3557
po::value<bool>(&srv_file_per_table)->default_value(false)->zero_tokens(),
3463
3558
N_("Stores each HailDB table to an .ibd file in the database dir."));
3464
3559
context("file-format",
3465
po::value<string>(&innobase_file_format_name)->default_value("Barracuda"),
3560
po::value<string>(),
3466
3561
N_("File format to use for new tables in .ibd files."));
3467
3562
context("flush-log-at-trx-commit",
3468
po::value<trinary_constraint>(&srv_flush_log_at_trx_commit)->default_value(1),
3563
po::value<unsigned long>(&srv_flush_log_at_trx_commit)->default_value(1),
3469
3564
N_("Set to 0 (write and flush once per second),1 (write and flush at each commit) or 2 (write at commit, flush once per second)."));
3470
3565
context("flush-method",
3471
3566
po::value<string>(),
3472
3567
N_("With which method to flush data."));
3473
3568
context("force-recovery",
3474
po::value<force_recovery_constraint>(&innobase_force_recovery)->default_value(0),
3569
po::value<long>(&innobase_force_recovery)->default_value(0),
3475
3570
N_("Helps to save your data in case the disk image of the database becomes corrupt."));
3476
3571
context("data-file-path",
3477
po::value<string>()->default_value("ibdata1:10M:autoextend"),
3572
po::value<string>(),
3573
N_("Path to individual files and their sizes."));
3574
context("log-group-home-dir",
3575
po::value<string>(),
3478
3576
N_("Path to individual files and their sizes."));
3479
3577
context("log-group-home-dir",
3480
3578
po::value<string>(),
3481
3579
N_("Path to HailDB log files."));
3482
3580
context("log-file-size",
3483
po::value<log_file_constraint>(&haildb_log_file_size)->default_value(20*1024*1024L),
3581
po::value<int64_t>(&haildb_log_file_size)->default_value(20*1024*1024L),
3484
3582
N_("Size of each log file in a log group."));
3485
3583
context("haildb-log-files-in-group",
3486
po::value<log_files_in_group_constraint>(&haildb_log_files_in_group)->default_value(2),
3584
po::value<int64_t>(&haildb_log_files_in_group)->default_value(2),
3487
3585
N_("Number of log files in the log group. HailDB writes to the files in a circular fashion. Value 3 is recommended here."));
3488
3586
context("lock-wait-timeout",
3489
po::value<lock_wait_constraint>(&innobase_lock_wait_timeout)->default_value(5),
3587
po::value<unsigned long>(&innobase_lock_wait_timeout)->default_value(5),
3490
3588
N_("Timeout in seconds an HailDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout."));
3491
3589
context("log-buffer-size",
3492
po::value<log_buffer_size_constraint>(&innobase_log_buffer_size)->default_value(8*1024*1024L),
3590
po::value<long>(&innobase_log_buffer_size)->default_value(8*1024*1024L),
3493
3591
N_("The size of the buffer which HailDB uses to write log to the log files on disk."));
3494
3592
context("lru-old-blocks-pct",
3495
po::value<lru_old_blocks_constraint>(&innobase_lru_old_blocks_pct)->default_value(37),
3593
po::value<unsigned long>(&innobase_lru_old_blocks_pct)->default_value(37),
3496
3594
N_("Sets the point in the LRU list from where all pages are classified as old (Advanced users)"));
3497
3595
context("lru-block-access-recency",
3498
po::value<uint32_t>(&innobase_lru_block_access_recency)->default_value(0),
3596
po::value<unsigned long>(&innobase_lru_block_access_recency)->default_value(0),
3499
3597
N_("Milliseconds between accesses to a block at which it is made young. 0=disabled (Advanced users)"));
3500
3598
context("max-dirty-pages-pct",
3501
po::value<max_dirty_pages_constraint>(&haildb_max_dirty_pages_pct)->default_value(75),
3599
po::value<unsigned long>(&srv_max_buf_pool_modified_pct)->default_value(75),
3502
3600
N_("Percentage of dirty pages allowed in bufferpool."));
3503
3601
context("max-purge-lag",
3504
po::value<uint64_constraint>(&haildb_max_purge_lag)->default_value(0),
3602
po::value<unsigned long>(&srv_max_purge_lag)->default_value(0),
3505
3603
N_("Desired maximum length of the purge queue (0 = no limit)"));
3506
3604
context("rollback-on-timeout",
3507
3605
po::value<bool>(&innobase_rollback_on_timeout)->default_value(false)->zero_tokens(),
3508
3606
N_("Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)"));
3509
3607
context("open-files",
3510
po::value<open_files_constraint>(&haildb_open_files)->default_value(300),
3608
po::value<long>(&innobase_open_files)->default_value(300),
3511
3609
N_("How many files at the maximum HailDB keeps open at the same time."));
3512
3610
context("read-io-threads",
3513
po::value<io_threads_constraint>(&haildb_read_io_threads)->default_value(4),
3611
po::value<unsigned long>(&innobase_read_io_threads)->default_value(4),
3514
3612
N_("Number of background read I/O threads in HailDB."));
3515
3613
context("write-io-threads",
3516
po::value<io_threads_constraint>(&haildb_write_io_threads)->default_value(4),
3614
po::value<unsigned long>(&innobase_write_io_threads)->default_value(4),
3517
3615
N_("Number of background write I/O threads in HailDB."));
3518
3616
context("disable-print-verbose-log",
3519
3617
N_("Disable if you want to reduce the number of messages written to the log (default: enabled)."));
3521
3619
po::value<bool>(&innobase_create_status_file)->default_value(false)->zero_tokens(),
3522
3620
N_("Enable SHOW HAILDB STATUS output in the log"));
3523
3621
context("sync-spin-loops",
3524
po::value<uint64_constraint>(&haildb_sync_spin_loops)->default_value(30L),
3622
po::value<unsigned long>(&srv_n_spin_wait_rounds)->default_value(30L),
3525
3623
N_("Count of spin-loop rounds in HailDB mutexes (30 by default)"));
3526
3624
context("use-internal-malloc",
3527
3625
N_("Use HailDB's internal memory allocator instead of the OS memory allocator"));
3628
static drizzle_sys_var* innobase_system_variables[]= {
3629
DRIZZLE_SYSVAR(adaptive_hash_index),
3630
DRIZZLE_SYSVAR(adaptive_flushing),
3631
DRIZZLE_SYSVAR(additional_mem_pool_size),
3632
DRIZZLE_SYSVAR(autoextend_increment),
3633
DRIZZLE_SYSVAR(buffer_pool_size),
3634
DRIZZLE_SYSVAR(checksums),
3635
DRIZZLE_SYSVAR(data_home_dir),
3636
DRIZZLE_SYSVAR(doublewrite),
3637
DRIZZLE_SYSVAR(io_capacity),
3638
DRIZZLE_SYSVAR(fast_shutdown),
3639
DRIZZLE_SYSVAR(file_per_table),
3640
DRIZZLE_SYSVAR(file_format),
3641
DRIZZLE_SYSVAR(flush_log_at_trx_commit),
3642
DRIZZLE_SYSVAR(flush_method),
3643
DRIZZLE_SYSVAR(force_recovery),
3644
DRIZZLE_SYSVAR(log_group_home_dir),
3645
DRIZZLE_SYSVAR(data_file_path),
3646
DRIZZLE_SYSVAR(lock_wait_timeout),
3647
DRIZZLE_SYSVAR(log_file_size),
3648
DRIZZLE_SYSVAR(log_files_in_group),
3649
DRIZZLE_SYSVAR(log_buffer_size),
3650
DRIZZLE_SYSVAR(lru_old_blocks_pct),
3651
DRIZZLE_SYSVAR(lru_block_access_recency),
3652
DRIZZLE_SYSVAR(max_dirty_pages_pct),
3653
DRIZZLE_SYSVAR(max_purge_lag),
3654
DRIZZLE_SYSVAR(open_files),
3655
DRIZZLE_SYSVAR(read_io_threads),
3656
DRIZZLE_SYSVAR(rollback_on_timeout),
3657
DRIZZLE_SYSVAR(write_io_threads),
3658
DRIZZLE_SYSVAR(print_verbose_log),
3659
DRIZZLE_SYSVAR(status_file),
3660
DRIZZLE_SYSVAR(sync_spin_loops),
3661
DRIZZLE_SYSVAR(use_sys_malloc),
3530
3665
DRIZZLE_DECLARE_PLUGIN
3532
3667
DRIZZLE_VERSION_ID,