~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/haildb/haildb_engine.cc

  • Committer: Lee Bieber
  • Date: 2010-12-02 18:54:50 UTC
  • mfrom: (1964.2.5 rip-plugin-sysvar)
  • mto: This revision was merged to the branch mainline in revision 1969.
  • Revision ID: kalebral@gmail.com-20101202185450-502z0lzq624k1cxn
Merge Monty sys_var cleanup for haildb

Show diffs side-by-side

added added

removed removed

Lines of Context:
2827
2827
static bool innobase_create_status_file;
2828
2828
static bool srv_use_sys_malloc;
2829
2829
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_read_io_threads;
2833
 
static unsigned long innobase_write_io_threads;
2834
2830
typedef constrained_check<unsigned int, 1000, 1> autoextend_constraint;
2835
2831
static autoextend_constraint srv_auto_extend_increment;
2836
 
static unsigned long srv_n_spin_wait_rounds;
2837
2832
typedef constrained_check<size_t, SIZE_MAX, 5242880, 1048576> buffer_pool_constraint;
2838
2833
static buffer_pool_constraint innobase_buffer_pool_size;
2839
2834
typedef constrained_check<size_t, SIZE_MAX, 512, 1024> additional_mem_pool_constraint;
2857
2852
static log_buffer_size_constraint innobase_log_buffer_size;
2858
2853
typedef constrained_check<unsigned int, 97, 5> lru_old_blocks_constraint;
2859
2854
static lru_old_blocks_constraint innobase_lru_old_blocks_pct;
 
2855
typedef constrained_check<unsigned int, 99, 0> max_dirty_pages_constraint;
 
2856
static max_dirty_pages_constraint haildb_max_dirty_pages_pct;
 
2857
typedef constrained_check<uint64_t, UINT64_MAX, 0> uint64_constraint;
 
2858
static uint64_constraint haildb_max_purge_lag;
 
2859
static uint64_constraint haildb_sync_spin_loops;
 
2860
typedef constrained_check<uint32_t, UINT32_MAX, 10> open_files_constraint;
 
2861
static open_files_constraint haildb_open_files;
 
2862
typedef constrained_check<unsigned int, 64, 1> io_threads_constraint;
 
2863
static io_threads_constraint haildb_read_io_threads;
 
2864
static io_threads_constraint haildb_write_io_threads;
 
2865
 
 
2866
 
2860
2867
static uint32_t innobase_lru_block_access_recency;
2861
2868
 
2862
 
static long innobase_open_files;
2863
2869
 
2864
2870
 
2865
2871
static int haildb_file_format_name_validate(Session*, set_var *var)
2892
2898
  (void)ret;
2893
2899
}
2894
2900
 
 
2901
static void haildb_status_file_update(Session*, sql_var_t)
 
2902
{
 
2903
  ib_err_t err;
 
2904
 
 
2905
  if (innobase_create_status_file)
 
2906
    err= ib_cfg_set_bool_on("status_file");
 
2907
  else
 
2908
    err= ib_cfg_set_bool_off("status_file");
 
2909
  (void)err;
 
2910
}
 
2911
 
 
2912
 
2895
2913
static int haildb_init(drizzled::module::Context &context)
2896
2914
{
2897
2915
  haildb_system_table_names.insert(std::string("HAILDB_SYS_TABLES"));
2913
2931
  srv_use_sys_malloc= (vm.count("use-internal-malloc")) ? false : true;
2914
2932
 
2915
2933
 
2916
 
  if (vm.count("max-dirty-pages-pct"))
2917
 
  {
2918
 
    if (srv_max_buf_pool_modified_pct > 99)
2919
 
    {
2920
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of max-dirty-pages-pct"));
2921
 
      return 1;
2922
 
    }
2923
 
  }
2924
 
 
2925
 
  if (vm.count("max-purge-lag"))
2926
 
  {
2927
 
    if (srv_max_purge_lag > (unsigned long)~0L)
2928
 
    {
2929
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of max-purge-lag"));
2930
 
      return 1;
2931
 
    }
2932
 
  }
2933
 
 
2934
 
  if (vm.count("open-files"))
2935
 
  {
2936
 
    if (innobase_open_files > LONG_MAX || innobase_open_files < 10L)
2937
 
    {
2938
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of open-files"));
2939
 
      return 1;
2940
 
    }
2941
 
  }
2942
 
 
2943
 
  if (vm.count("read-io-threads"))
2944
 
  {
2945
 
    if (innobase_read_io_threads > 64 || innobase_read_io_threads < 1)
2946
 
    {
2947
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of read-io-threads"));
2948
 
      return 1;
2949
 
    }
2950
 
  }
2951
 
 
2952
 
  if (vm.count("sync-spin-loops"))
2953
 
  {
2954
 
    if (srv_n_spin_wait_rounds > (unsigned long)~0L)
2955
 
    {
2956
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of sync_spin_loops"));
2957
 
      return 1;
2958
 
    }
2959
 
  }
2960
 
 
2961
2934
  ib_err_t err;
2962
2935
 
2963
2936
  err= ib_init();
3019
2992
  if (err != DB_SUCCESS)
3020
2993
    goto haildb_error;
3021
2994
 
3022
 
  err= ib_cfg_set_int("additional_mem_pool_size", static_cast<size_t>(innobase_additional_mem_pool_size));
3023
 
  if (err != DB_SUCCESS)
3024
 
    goto haildb_error;
3025
 
 
3026
 
  err= ib_cfg_set_int("autoextend_increment", static_cast<unsigned int>(srv_auto_extend_increment));
3027
 
  if (err != DB_SUCCESS)
3028
 
    goto haildb_error;
3029
 
 
3030
 
  err= ib_cfg_set_int("buffer_pool_size", static_cast<size_t>(innobase_buffer_pool_size));
3031
 
  if (err != DB_SUCCESS)
3032
 
    goto haildb_error;
3033
 
 
3034
 
  err= ib_cfg_set_int("io_capacity", static_cast<unsigned int>(srv_io_capacity));
 
2995
  err= ib_cfg_set_int("additional_mem_pool_size", innobase_additional_mem_pool_size.get());
 
2996
  if (err != DB_SUCCESS)
 
2997
    goto haildb_error;
 
2998
 
 
2999
  err= ib_cfg_set_int("autoextend_increment", srv_auto_extend_increment.get());
 
3000
  if (err != DB_SUCCESS)
 
3001
    goto haildb_error;
 
3002
 
 
3003
  err= ib_cfg_set_int("buffer_pool_size", innobase_buffer_pool_size.get());
 
3004
  if (err != DB_SUCCESS)
 
3005
    goto haildb_error;
 
3006
 
 
3007
  err= ib_cfg_set_int("io_capacity", srv_io_capacity.get());
3035
3008
  if (err != DB_SUCCESS)
3036
3009
    goto haildb_error;
3037
3010
 
3044
3017
    goto haildb_error;
3045
3018
 
3046
3019
  err= ib_cfg_set_int("flush_log_at_trx_commit",
3047
 
                      static_cast<uint16_t>(srv_flush_log_at_trx_commit));
 
3020
                      srv_flush_log_at_trx_commit.get());
3048
3021
  if (err != DB_SUCCESS)
3049
3022
    goto haildb_error;
3050
3023
 
3057
3030
  }
3058
3031
 
3059
3032
  err= ib_cfg_set_int("force_recovery",
3060
 
                      static_cast<uint16_t>(innobase_force_recovery));
 
3033
                      innobase_force_recovery.get());
3061
3034
  if (err != DB_SUCCESS)
3062
3035
    goto haildb_error;
3063
3036
 
3065
3038
  if (err != DB_SUCCESS)
3066
3039
    goto haildb_error;
3067
3040
 
3068
 
  err= ib_cfg_set_int("log_file_size", static_cast<int64_t>(haildb_log_file_size));
3069
 
  if (err != DB_SUCCESS)
3070
 
    goto haildb_error;
3071
 
 
3072
 
  err= ib_cfg_set_int("log_buffer_size", static_cast<long>(innobase_log_buffer_size));
3073
 
  if (err != DB_SUCCESS)
3074
 
    goto haildb_error;
3075
 
 
3076
 
  err= ib_cfg_set_int("log_files_in_group", static_cast<unsigned int>(haildb_log_files_in_group));
 
3041
  err= ib_cfg_set_int("log_file_size", haildb_log_file_size.get());
 
3042
  if (err != DB_SUCCESS)
 
3043
    goto haildb_error;
 
3044
 
 
3045
  err= ib_cfg_set_int("log_buffer_size", innobase_log_buffer_size.get());
 
3046
  if (err != DB_SUCCESS)
 
3047
    goto haildb_error;
 
3048
 
 
3049
  err= ib_cfg_set_int("log_files_in_group", haildb_log_files_in_group.get());
3077
3050
  if (err != DB_SUCCESS)
3078
3051
    goto haildb_error;
3079
3052
 
3081
3054
  if (err != DB_SUCCESS)
3082
3055
    goto haildb_error;
3083
3056
 
3084
 
  err= ib_cfg_set_int("lock_wait_timeout", static_cast<unsigned int>(innobase_lock_wait_timeout));
3085
 
  if (err != DB_SUCCESS)
3086
 
    goto haildb_error;
3087
 
 
3088
 
  err= ib_cfg_set_int("max_dirty_pages_pct", srv_max_buf_pool_modified_pct);
3089
 
  if (err != DB_SUCCESS)
3090
 
    goto haildb_error;
3091
 
 
3092
 
  err= ib_cfg_set_int("max_purge_lag", srv_max_purge_lag);
3093
 
  if (err != DB_SUCCESS)
3094
 
    goto haildb_error;
3095
 
 
3096
 
  err= ib_cfg_set_int("open_files", innobase_open_files);
3097
 
  if (err != DB_SUCCESS)
3098
 
    goto haildb_error;
3099
 
 
3100
 
  err= ib_cfg_set_int("read_io_threads", innobase_read_io_threads);
3101
 
  if (err != DB_SUCCESS)
3102
 
    goto haildb_error;
3103
 
 
3104
 
  err= ib_cfg_set_int("write_io_threads", innobase_write_io_threads);
3105
 
  if (err != DB_SUCCESS)
3106
 
    goto haildb_error;
3107
 
 
3108
 
  err= ib_cfg_set_int("sync_spin_loops", srv_n_spin_wait_rounds);
 
3057
  err= ib_cfg_set_int("lock_wait_timeout", innobase_lock_wait_timeout.get());
 
3058
  if (err != DB_SUCCESS)
 
3059
    goto haildb_error;
 
3060
 
 
3061
  err= ib_cfg_set_int("max_dirty_pages_pct", haildb_max_dirty_pages_pct.get());
 
3062
  if (err != DB_SUCCESS)
 
3063
    goto haildb_error;
 
3064
 
 
3065
  err= ib_cfg_set_int("max_purge_lag", haildb_max_purge_lag.get());
 
3066
  if (err != DB_SUCCESS)
 
3067
    goto haildb_error;
 
3068
 
 
3069
  err= ib_cfg_set_int("open_files", haildb_open_files.get());
 
3070
  if (err != DB_SUCCESS)
 
3071
    goto haildb_error;
 
3072
 
 
3073
  err= ib_cfg_set_int("read_io_threads", haildb_read_io_threads.get());
 
3074
  if (err != DB_SUCCESS)
 
3075
    goto haildb_error;
 
3076
 
 
3077
  err= ib_cfg_set_int("write_io_threads", haildb_write_io_threads.get());
 
3078
  if (err != DB_SUCCESS)
 
3079
    goto haildb_error;
 
3080
 
 
3081
  err= ib_cfg_set_int("sync_spin_loops", haildb_sync_spin_loops.get());
3109
3082
  if (err != DB_SUCCESS)
3110
3083
    goto haildb_error;
3111
3084
 
3144
3117
  context.registerVariable(new sys_var_constrained_value_readonly<uint16_t>("fast_shutdown", innobase_fast_shutdown));
3145
3118
  context.registerVariable(new sys_var_bool_ptr_readonly("file_per_table",
3146
3119
                                                         &srv_file_per_table));
 
3120
  context.registerVariable(new sys_var_bool_ptr_readonly("rollback_on_timeout",
 
3121
                                                         &innobase_rollback_on_timeout));
 
3122
  context.registerVariable(new sys_var_bool_ptr_readonly("print_verbose_log",
 
3123
                                                         &innobase_print_verbose_log));
 
3124
  context.registerVariable(new sys_var_bool_ptr("status_file",
 
3125
                                                &innobase_create_status_file,
 
3126
                                                haildb_status_file_update));
 
3127
  context.registerVariable(new sys_var_bool_ptr_readonly("use_sys_malloc",
 
3128
                                                         &srv_use_sys_malloc));
3147
3129
  context.registerVariable(new sys_var_std_string("file_format",
3148
3130
                                                  innobase_file_format_name,
3149
3131
                                                  haildb_file_format_name_validate));
3161
3143
  context.registerVariable(new sys_var_uint32_t_ptr("lru_block_access_recency",
3162
3144
                                                    &innobase_lru_block_access_recency,
3163
3145
                                                    haildb_lru_block_access_recency_update));
 
3146
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("max_dirty_pages_pct", haildb_max_dirty_pages_pct));
 
3147
  context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("max_purge_lag", haildb_max_purge_lag));
 
3148
  context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("sync_spin_loops", haildb_sync_spin_loops));
 
3149
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("open_files", haildb_open_files));
 
3150
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("read_io_threads", haildb_read_io_threads));
 
3151
  context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("write_io_threads", haildb_write_io_threads));
3164
3152
 
3165
3153
  haildb_datadict_dump_func_initialize(context);
3166
3154
  config_table_function_initialize(context);
3179
3167
  ib_err_t err;
3180
3168
  ib_shutdown_t shutdown_flag= IB_SHUTDOWN_NORMAL;
3181
3169
 
3182
 
  if (static_cast<unsigned int>(innobase_fast_shutdown) == 1)
 
3170
  if (innobase_fast_shutdown.get() == 1)
3183
3171
    shutdown_flag= IB_SHUTDOWN_NO_IBUFMERGE_PURGE;
3184
 
  else if (static_cast<unsigned int>(innobase_fast_shutdown) == 2)
 
3172
  else if (innobase_fast_shutdown.get() == 2)
3185
3173
    shutdown_flag= IB_SHUTDOWN_NO_BUFPOOL_FLUSH;
3186
3174
 
3187
3175
  err= ib_shutdown(shutdown_flag);
3194
3182
}
3195
3183
 
3196
3184
 
3197
 
static void haildb_status_file_update(Session*, drizzle_sys_var*,
3198
 
                                      void *,
3199
 
                                      const void *save)
3200
 
 
3201
 
{
3202
 
  bool status_file_enabled;
3203
 
  ib_err_t err;
3204
 
 
3205
 
  status_file_enabled= *static_cast<const bool*>(save);
3206
 
 
3207
 
 
3208
 
  if (status_file_enabled)
3209
 
    err= ib_cfg_set_bool_on("status_file");
3210
 
  else
3211
 
    err= ib_cfg_set_bool_off("status_file");
3212
 
 
3213
 
  if (err == DB_SUCCESS)
3214
 
    innobase_create_status_file= status_file_enabled;
3215
 
}
3216
 
 
3217
 
 
3218
 
static DRIZZLE_SYSVAR_ULONG(max_dirty_pages_pct, srv_max_buf_pool_modified_pct,
3219
 
  PLUGIN_VAR_RQCMDARG,
3220
 
  "Percentage of dirty pages allowed in bufferpool.",
3221
 
  NULL, NULL, 75, 0, 99, 0);
3222
 
 
3223
 
static DRIZZLE_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag,
3224
 
  PLUGIN_VAR_RQCMDARG,
3225
 
  "Desired maximum length of the purge queue (0 = no limit)",
3226
 
  NULL, NULL, 0, 0, ~0L, 0);
3227
 
 
3228
 
static DRIZZLE_SYSVAR_BOOL(rollback_on_timeout, innobase_rollback_on_timeout,
3229
 
  PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
3230
 
  "Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)",
3231
 
  NULL, NULL, false);
3232
 
 
3233
 
static DRIZZLE_SYSVAR_LONG(open_files, innobase_open_files,
3234
 
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3235
 
  "How many files at the maximum HailDB keeps open at the same time.",
3236
 
  NULL, NULL, 300L, 10L, LONG_MAX, 0);
3237
 
 
3238
 
static DRIZZLE_SYSVAR_ULONG(read_io_threads, innobase_read_io_threads,
3239
 
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3240
 
  "Number of background read I/O threads in HailDB.",
3241
 
  NULL, NULL, 4, 1, 64, 0);
3242
 
 
3243
 
static DRIZZLE_SYSVAR_ULONG(write_io_threads, innobase_write_io_threads,
3244
 
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
3245
 
  "Number of background write I/O threads in HailDB.",
3246
 
  NULL, NULL, 4, 1, 64, 0);
3247
 
 
3248
 
static DRIZZLE_SYSVAR_BOOL(print_verbose_log, innobase_print_verbose_log,
3249
 
  PLUGIN_VAR_NOCMDARG,
3250
 
  "Disable if you want to reduce the number of messages written to the log (default: enabled).",
3251
 
  NULL, NULL, true);
3252
 
 
3253
 
static DRIZZLE_SYSVAR_BOOL(status_file, innobase_create_status_file,
3254
 
  PLUGIN_VAR_OPCMDARG,
3255
 
  "Enable SHOW HAILDB STATUS output in the log",
3256
 
  NULL, haildb_status_file_update, false);
3257
 
 
3258
 
static DRIZZLE_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds,
3259
 
  PLUGIN_VAR_RQCMDARG,
3260
 
  "Count of spin-loop rounds in HailDB mutexes (30 by default)",
3261
 
  NULL, NULL, 30L, 0L, ~0L, 0);
3262
 
 
3263
 
static DRIZZLE_SYSVAR_BOOL(use_sys_malloc, srv_use_sys_malloc,
3264
 
  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
3265
 
  "Use OS memory allocator instead of HailDB's internal memory allocator",
3266
 
  NULL, NULL, true);
3267
 
 
3268
3185
static void init_options(drizzled::module::option_context &context)
3269
3186
{
3270
3187
  context("disable-adaptive-hash-index",
3333
3250
          po::value<uint32_t>(&innobase_lru_block_access_recency)->default_value(0),
3334
3251
          N_("Milliseconds between accesses to a block at which it is made young. 0=disabled (Advanced users)"));
3335
3252
  context("max-dirty-pages-pct",
3336
 
          po::value<unsigned long>(&srv_max_buf_pool_modified_pct)->default_value(75),
 
3253
          po::value<max_dirty_pages_constraint>(&haildb_max_dirty_pages_pct)->default_value(75),
3337
3254
          N_("Percentage of dirty pages allowed in bufferpool."));
3338
3255
  context("max-purge-lag",
3339
 
          po::value<unsigned long>(&srv_max_purge_lag)->default_value(0),
 
3256
          po::value<uint64_constraint>(&haildb_max_purge_lag)->default_value(0),
3340
3257
          N_("Desired maximum length of the purge queue (0 = no limit)"));
3341
3258
  context("rollback-on-timeout",
3342
3259
          po::value<bool>(&innobase_rollback_on_timeout)->default_value(false)->zero_tokens(),
3343
3260
          N_("Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)"));
3344
3261
  context("open-files",
3345
 
          po::value<long>(&innobase_open_files)->default_value(300),
 
3262
          po::value<open_files_constraint>(&haildb_open_files)->default_value(300),
3346
3263
          N_("How many files at the maximum HailDB keeps open at the same time."));
3347
3264
  context("read-io-threads",
3348
 
          po::value<unsigned long>(&innobase_read_io_threads)->default_value(4),
 
3265
          po::value<io_threads_constraint>(&haildb_read_io_threads)->default_value(4),
3349
3266
          N_("Number of background read I/O threads in HailDB."));
3350
3267
  context("write-io-threads",
3351
 
          po::value<unsigned long>(&innobase_write_io_threads)->default_value(4),
 
3268
          po::value<io_threads_constraint>(&haildb_write_io_threads)->default_value(4),
3352
3269
          N_("Number of background write I/O threads in HailDB."));
3353
3270
  context("disable-print-verbose-log",
3354
3271
          N_("Disable if you want to reduce the number of messages written to the log (default: enabled)."));
3356
3273
          po::value<bool>(&innobase_create_status_file)->default_value(false)->zero_tokens(),
3357
3274
          N_("Enable SHOW HAILDB STATUS output in the log"));
3358
3275
  context("sync-spin-loops",
3359
 
          po::value<unsigned long>(&srv_n_spin_wait_rounds)->default_value(30L),
 
3276
          po::value<uint64_constraint>(&haildb_sync_spin_loops)->default_value(30L),
3360
3277
          N_("Count of spin-loop rounds in HailDB mutexes (30 by default)"));
3361
3278
  context("use-internal-malloc",
3362
3279
          N_("Use HailDB's internal memory allocator instead of the OS memory allocator"));
3363
3280
}
3364
3281
 
3365
 
static drizzle_sys_var* innobase_system_variables[]= {
3366
 
  DRIZZLE_SYSVAR(max_dirty_pages_pct),
3367
 
  DRIZZLE_SYSVAR(max_purge_lag),
3368
 
  DRIZZLE_SYSVAR(open_files),
3369
 
  DRIZZLE_SYSVAR(read_io_threads),
3370
 
  DRIZZLE_SYSVAR(rollback_on_timeout),
3371
 
  DRIZZLE_SYSVAR(write_io_threads),
3372
 
  DRIZZLE_SYSVAR(print_verbose_log),
3373
 
  DRIZZLE_SYSVAR(status_file),
3374
 
  DRIZZLE_SYSVAR(sync_spin_loops),
3375
 
  DRIZZLE_SYSVAR(use_sys_malloc),
3376
 
  NULL
3377
 
};
3378
 
 
3379
3282
DRIZZLE_DECLARE_PLUGIN
3380
3283
{
3381
3284
  DRIZZLE_VERSION_ID,
3385
3288
  "Transactional Storage Engine using the HailDB Library",
3386
3289
  PLUGIN_LICENSE_GPL,
3387
3290
  haildb_init,     /* Plugin Init */
3388
 
  innobase_system_variables, /* system variables */
 
3291
  NULL, /* system variables */
3389
3292
  init_options                /* config options   */
3390
3293
}
3391
3294
DRIZZLE_DECLARE_PLUGIN_END;