|
43 | 43 |
|
44 | 44 | /* MySQL includes */ |
45 | 45 | #include <mysql/components/services/log_builtins.h> |
| 46 | +#include <mysql/psi/mysql_file.h> |
46 | 47 | #include <mysql/psi/mysql_table.h> |
47 | 48 | #include <mysql/thread_pool_priv.h> |
48 | 49 | #include <mysys_err.h> |
@@ -724,6 +725,7 @@ static unsigned long // NOLINT(runtime/int) |
724 | 725 | static ulong rocksdb_info_log_level; |
725 | 726 | static char *rocksdb_wal_dir; |
726 | 727 | static char *rocksdb_persistent_cache_path; |
| 728 | +static char *rocksdb_wsenv_path; |
727 | 729 | static ulong rocksdb_index_type; |
728 | 730 | static uint32_t rocksdb_flush_log_at_trx_commit; |
729 | 731 | static uint32_t rocksdb_debug_optimizer_n_rows; |
@@ -1596,6 +1598,10 @@ static MYSQL_SYSVAR_ULONG( |
1596 | 1598 | nullptr, nullptr, rocksdb_persistent_cache_size_mb, |
1597 | 1599 | /* min */ 0L, /* max */ ULONG_MAX, 0); |
1598 | 1600 |
|
| 1601 | +static MYSQL_SYSVAR_STR(wsenv_path, rocksdb_wsenv_path, |
| 1602 | + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, |
| 1603 | + "Path for RocksDB WSEnv", nullptr, nullptr, ""); |
| 1604 | + |
1599 | 1605 | static MYSQL_SYSVAR_STR(fault_injection_options, |
1600 | 1606 | opt_rocksdb_fault_injection_options, |
1601 | 1607 | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, |
@@ -2496,6 +2502,7 @@ static struct SYS_VAR *rocksdb_system_variables[] = { |
2496 | 2502 | MYSQL_SYSVAR(persistent_cache_path), |
2497 | 2503 | MYSQL_SYSVAR(persistent_cache_size_mb), |
2498 | 2504 | MYSQL_SYSVAR(fault_injection_options), |
| 2505 | + MYSQL_SYSVAR(wsenv_path), |
2499 | 2506 | MYSQL_SYSVAR(delete_obsolete_files_period_micros), |
2500 | 2507 | MYSQL_SYSVAR(max_background_jobs), |
2501 | 2508 | MYSQL_SYSVAR(max_background_flushes), |
@@ -3998,7 +4005,8 @@ class Rdb_transaction_impl : public Rdb_transaction { |
3998 | 4005 | tx_opts.write_batch_flush_threshold = |
3999 | 4006 | THDVAR(m_thd, write_batch_flush_threshold); |
4000 | 4007 |
|
4001 | | - write_opts.sync = (rocksdb_flush_log_at_trx_commit == FLUSH_LOG_SYNC); |
| 4008 | + write_opts.sync = (rocksdb_flush_log_at_trx_commit == FLUSH_LOG_SYNC) && |
| 4009 | + rdb_sync_wal_supported(); |
4002 | 4010 | write_opts.disableWAL = THDVAR(m_thd, write_disable_wal); |
4003 | 4011 | write_opts.ignore_missing_column_families = |
4004 | 4012 | THDVAR(m_thd, write_ignore_missing_column_families); |
@@ -4291,7 +4299,8 @@ class Rdb_writebatch_impl : public Rdb_transaction { |
4291 | 4299 |
|
4292 | 4300 | void start_tx() override { |
4293 | 4301 | reset(); |
4294 | | - write_opts.sync = (rocksdb_flush_log_at_trx_commit == FLUSH_LOG_SYNC); |
| 4302 | + write_opts.sync = (rocksdb_flush_log_at_trx_commit == FLUSH_LOG_SYNC) && |
| 4303 | + rdb_sync_wal_supported(); |
4295 | 4304 | write_opts.disableWAL = THDVAR(m_thd, write_disable_wal); |
4296 | 4305 | write_opts.ignore_missing_column_families = |
4297 | 4306 | THDVAR(m_thd, write_ignore_missing_column_families); |
@@ -4566,14 +4575,17 @@ static bool rocksdb_flush_wal(handlerton *const hton MY_ATTRIBUTE((__unused__)), |
4566 | 4575 | if ((!binlog_group_flush && !rocksdb_db_options->allow_mmap_writes) || |
4567 | 4576 | rocksdb_flush_log_at_trx_commit != FLUSH_LOG_NEVER) { |
4568 | 4577 | rocksdb_wal_group_syncs++; |
4569 | | - s = rdb->FlushWAL(!binlog_group_flush || |
4570 | | - rocksdb_flush_log_at_trx_commit == FLUSH_LOG_SYNC); |
| 4578 | + bool sync = rdb_sync_wal_supported() && |
| 4579 | + (!binlog_group_flush || |
| 4580 | + rocksdb_flush_log_at_trx_commit == FLUSH_LOG_SYNC); |
| 4581 | + s = rdb->FlushWAL(sync); |
4571 | 4582 | } |
4572 | 4583 |
|
4573 | 4584 | if (!s.ok()) { |
4574 | 4585 | rdb_log_status_error(s); |
4575 | 4586 | return HA_EXIT_FAILURE; |
4576 | 4587 | } |
| 4588 | + |
4577 | 4589 | return HA_EXIT_SUCCESS; |
4578 | 4590 | } |
4579 | 4591 |
|
@@ -5929,6 +5941,23 @@ static rocksdb::Status check_rocksdb_options_compatibility( |
5929 | 5941 |
|
5930 | 5942 | static uint rocksdb_partition_flags() { return (HA_CANNOT_PARTITION_FK); } |
5931 | 5943 |
|
| 5944 | +bool rdb_has_wsenv() { |
| 5945 | +#if FB_HAVE_WSENV |
| 5946 | + return rocksdb_wsenv_path != nullptr && *rocksdb_wsenv_path; |
| 5947 | +#else |
| 5948 | + return false; |
| 5949 | +#endif |
| 5950 | +} |
| 5951 | + |
| 5952 | +bool rdb_sync_wal_supported() { |
| 5953 | +#if FB_HAVE_WSENV |
| 5954 | + // wsenv doesn't support SyncWAL=true yet |
| 5955 | + return !rdb_has_wsenv(); |
| 5956 | +#else |
| 5957 | + return true; |
| 5958 | +#endif |
| 5959 | +} |
| 5960 | + |
5932 | 5961 | /* |
5933 | 5962 | Storage Engine initialization function, invoked when plugin is loaded. |
5934 | 5963 | */ |
@@ -5965,6 +5994,33 @@ static int rocksdb_init_internal(void *const p) { |
5965 | 5994 | DBUG_RETURN(HA_EXIT_FAILURE); |
5966 | 5995 | }); |
5967 | 5996 |
|
| 5997 | +#ifdef FB_HAVE_WSENV |
| 5998 | + // Initialize WSEnv with rocksdb_ws_env_path |
| 5999 | + if (rdb_has_wsenv()) { |
| 6000 | + // NO_LINT_DEBUG |
| 6001 | + sql_print_information( |
| 6002 | + "RocksDB: Initializing WSEnvironment: rocksdb_wsenv_path = %s", |
| 6003 | + rocksdb_wsenv_path); |
| 6004 | + |
| 6005 | + RegisterCustomObjectsSimple(); |
| 6006 | + rocksdb::Env *ws_env = nullptr; |
| 6007 | + auto s = rocksdb::Env::LoadEnv(rocksdb_wsenv_path, &ws_env); |
| 6008 | + if (s.ok()) { |
| 6009 | + rocksdb_db_options->env = ws_env; |
| 6010 | + } else { |
| 6011 | + rdb_log_status_error(s, "Can't initialize WSEnvironment"); |
| 6012 | + DBUG_RETURN(HA_EXIT_FAILURE); |
| 6013 | + } |
| 6014 | + } |
| 6015 | +#else |
| 6016 | + if (rocksdb_wsenv_path != nullptr && *rocksdb_wsenv_path) { |
| 6017 | + // We've turned on WSEnv in the wrong build |
| 6018 | + // NO_LINT_DEBUG |
| 6019 | + sql_print_error("RocksDB: WSEnvironment not supported. "); |
| 6020 | + DBUG_RETURN(HA_EXIT_FAILURE); |
| 6021 | + } |
| 6022 | +#endif |
| 6023 | + |
5968 | 6024 | if (opt_rocksdb_fault_injection_options != nullptr && |
5969 | 6025 | *opt_rocksdb_fault_injection_options != '\0') { |
5970 | 6026 | bool retryable = false; |
@@ -14773,7 +14829,8 @@ void Rdb_background_thread::run() { |
14773 | 14829 | // background thread. |
14774 | 14830 | if (rdb && (rocksdb_flush_log_at_trx_commit != FLUSH_LOG_SYNC) && |
14775 | 14831 | !rocksdb_db_options->allow_mmap_writes) { |
14776 | | - const rocksdb::Status s = rdb->FlushWAL(true); |
| 14832 | + bool sync = rdb_sync_wal_supported(); |
| 14833 | + const rocksdb::Status s = rdb->FlushWAL(sync); |
14777 | 14834 | if (!s.ok()) { |
14778 | 14835 | rdb_handle_io_error(s, RDB_IO_ERROR_BG_THREAD); |
14779 | 14836 | } |
|
0 commit comments