Skip to content

Commit 09da82f

Browse files
Jonah CohenGunnar Kudrjavets
authored andcommitted
Add sysvar for specifying file containing column family configs.
1 parent 26311dc commit 09da82f

File tree

5 files changed

+190
-309
lines changed

5 files changed

+190
-309
lines changed

storage/rocksdb/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ IF(ROCKSDB_OK)
4949
rdb_locks.cc rdb_locks.h
5050
rdb_rowmods.cc rdb_rowmods.h
5151
rdb_applyiter.cc rdb_applyiter.h
52-
rdb_cf_option.cc rdb_cf_option.h
52+
rdb_cf_options.cc rdb_cf_options.h
5353
rdb_cf_manager.cc rdb_cf_manager.h)
5454

5555
MYSQL_ADD_PLUGIN(rocksdb_se ${ROCKSDB_SOURCES} STORAGE_ENGINE STATIC_ONLY MANDATORY LINK_LIBRARIES ${LINK_DIR} snappy bz2)

storage/rocksdb/ha_rocksdb.cc

Lines changed: 23 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "rdb_locks.h"
3232
#include "rdb_rowmods.h"
3333

34-
#include "rdb_cf_option.h"
34+
#include "rdb_cf_options.h"
3535
#include "rdb_cf_manager.h"
3636

3737
#include "rocksdb/table.h"
@@ -54,15 +54,11 @@ void key_copy(uchar *to_key, uchar *from_record, KEY *key_info,
5454
// Parameters and settings
5555
///////////////////////////////////////////////////////////
5656
extern const longlong ROCKSDB_WRITE_BUFFER_SIZE_DEFAULT;
57-
extern const int ROCKSDB_TARGET_FILE_SIZE_BASE_DEFAULT;
58-
static char * rocksdb_write_buffer_size_str;
59-
Numeric_cf_option write_buffer_size_map;
60-
61-
static char * rocksdb_target_file_size_base_str;
62-
Numeric_cf_option target_file_size_base_map;
6357

6458
static char * rocksdb_db_options;
6559
static char * rocksdb_default_cf_options;
60+
static char * rocksdb_cf_options_file;
61+
Cf_options rocksdb_cf_options_map;
6662

6763
///////////////////////////////////////////////////////////
6864
// Globals
@@ -95,64 +91,10 @@ mysql_mutex_t rocksdb_mutex;
9591
//////////////////////////////////////////////////////////////////////////////
9692

9793
static int
98-
rocksdb_write_buffer_size_validate(THD* thd,
99-
struct st_mysql_sys_var* var,
100-
void* save,
101-
struct st_mysql_value* value)
102-
{
103-
/* The option is read-only, it should never be updated */
104-
DBUG_ASSERT(0);
105-
return 1;
106-
#if 0
107-
const char* param_str;
108-
char buff[STRING_BUFFER_USUAL_SIZE];
109-
int len= sizeof(buff);
110-
111-
param_str= value->val_str(value, buff, &len);
112-
if (param_str != NULL)
113-
{
114-
if (parse_multi_number(param_str, &write_buffer_size_map))
115-
{
116-
save= (void*)1;
117-
return 1;
118-
}
119-
}
120-
save= NULL;
121-
return 0;
122-
#endif
123-
}
124-
125-
126-
static void
127-
rocksdb_write_buffer_size_update(THD* thd,
94+
rocksdb_cf_options_file_validate(THD* thd,
12895
struct st_mysql_sys_var* var,
129-
void* var_ptr,
130-
const void* save)
131-
{
132-
/* The option is read-only, it should never be updated */
133-
DBUG_ASSERT(0);
134-
}
135-
136-
137-
static bool rocksdb_parse_write_buffer_size_arg()
138-
{
139-
write_buffer_size_map.default_val= ROCKSDB_WRITE_BUFFER_SIZE_DEFAULT;
140-
if (parse_per_cf_numeric(rocksdb_write_buffer_size_str, &write_buffer_size_map))
141-
{
142-
sql_print_error("RocksDB: Invalid value for rocksdb_write_buffer_size: %s",
143-
rocksdb_write_buffer_size_str);
144-
return true;
145-
}
146-
else
147-
return false;
148-
}
149-
150-
151-
static int
152-
rocksdb_target_file_size_base_validate(THD* thd,
153-
struct st_mysql_sys_var* var,
154-
void* save,
155-
struct st_mysql_value* value)
96+
void* save,
97+
struct st_mysql_value* value)
15698
{
15799
/* The option is read-only, it should never be updated */
158100
DBUG_ASSERT(0);
@@ -161,30 +103,15 @@ rocksdb_target_file_size_base_validate(THD* thd,
161103

162104

163105
static void
164-
rocksdb_target_file_size_base_update(THD* thd,
165-
struct st_mysql_sys_var* var,
166-
void* var_ptr,
167-
const void* save)
106+
rocksdb_cf_options_file_update(THD* thd,
107+
struct st_mysql_sys_var* var,
108+
void* var_ptr,
109+
const void* save)
168110
{
169111
/* The option is read-only, it should never be updated */
170112
DBUG_ASSERT(0);
171113
}
172114

173-
174-
static bool rocksdb_parse_target_file_size_base_arg()
175-
{
176-
target_file_size_base_map.default_val= ROCKSDB_TARGET_FILE_SIZE_BASE_DEFAULT;
177-
if (parse_per_cf_numeric(rocksdb_target_file_size_base_str,
178-
&target_file_size_base_map))
179-
{
180-
sql_print_error("RocksDB: Invalid value for rocksdb_target_file_size_base: %s",
181-
rocksdb_target_file_size_base_str);
182-
return true;
183-
}
184-
else
185-
return false;
186-
}
187-
188115
//////////////////////////////////////////////////////////////////////////////
189116
// Options definitions
190117
//////////////////////////////////////////////////////////////////////////////
@@ -215,13 +142,6 @@ static MYSQL_SYSVAR_LONGLONG(block_cache_size, rocksdb_block_cache_size,
215142
NULL, NULL, /* RocksDB's default is 8 MB: */ 8*1024*1024L,
216143
/* min */ 1024L, /* max */ LONGLONG_MAX, /* Block size */1024L);
217144

218-
static MYSQL_SYSVAR_STR(write_buffer_size, rocksdb_write_buffer_size_str,
219-
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
220-
"options.write_buffer_size for RocksDB (Can also be set per-column family)",
221-
rocksdb_write_buffer_size_validate,
222-
rocksdb_write_buffer_size_update, "4194304" /* default is 4 MB for default CF */);
223-
const longlong ROCKSDB_WRITE_BUFFER_SIZE_DEFAULT=4194304;
224-
225145
static MYSQL_SYSVAR_STR(db_options, rocksdb_db_options,
226146
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
227147
"db options for RocksDB",
@@ -232,23 +152,13 @@ static MYSQL_SYSVAR_STR(default_cf_options, rocksdb_default_cf_options,
232152
"default cf options for RocksDB",
233153
NULL, NULL, "");
234154

235-
static MYSQL_SYSVAR_STR(target_file_size_base,
236-
rocksdb_target_file_size_base_str,
155+
static MYSQL_SYSVAR_STR(cf_options_file, rocksdb_cf_options_file,
237156
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
238-
"options.target_file_size_base for RocksDB (Can also be set per-column family)",
239-
rocksdb_target_file_size_base_validate,
240-
rocksdb_target_file_size_base_update,
241-
"2097152" /* default is 2 MB for default CF */);
242-
const int ROCKSDB_TARGET_FILE_SIZE_BASE_DEFAULT=2097152;
243-
244-
#if 0
245-
static MYSQL_SYSVAR_INT(target_file_size_base,
246-
rocksdb_target_file_size_base,
247-
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
248-
"options.target_file_size_base for RocksDB",
249-
NULL, NULL, /* RocksDB's default is 2 MB: */ 2*1024*1024L,
250-
/* min */ 1024L, /* max */ INT_MAX, /* Block size */1024L);
251-
#endif
157+
"path to cnf file with cf options for RocksDB",
158+
rocksdb_cf_options_file_validate,
159+
rocksdb_cf_options_file_update, "");
160+
161+
const longlong ROCKSDB_WRITE_BUFFER_SIZE_DEFAULT=4194304;
252162

253163
static struct st_mysql_sys_var* rocksdb_system_variables[]= {
254164
MYSQL_SYSVAR(lock_wait_timeout),
@@ -257,10 +167,9 @@ static struct st_mysql_sys_var* rocksdb_system_variables[]= {
257167
MYSQL_SYSVAR(bulk_load_size),
258168

259169
MYSQL_SYSVAR(block_cache_size),
260-
MYSQL_SYSVAR(write_buffer_size),
261170
MYSQL_SYSVAR(db_options),
262171
MYSQL_SYSVAR(default_cf_options),
263-
MYSQL_SYSVAR(target_file_size_base),
172+
MYSQL_SYSVAR(cf_options_file),
264173

265174
NULL
266175
};
@@ -651,12 +560,7 @@ static bool rocksdb_show_status(handlerton* hton,
651560

652561
void get_cf_options(const std::string &cf_name, rocksdb::ColumnFamilyOptions *opts)
653562
{
654-
*opts= default_cf_opts;
655-
int tfsb= target_file_size_base_map.get_val(cf_name.c_str());
656-
size_t wbs= write_buffer_size_map.get_val(cf_name.c_str());
657-
658-
opts->write_buffer_size= wbs;
659-
opts->target_file_size_base= tfsb;
563+
rocksdb_cf_options_map.Get(cf_name, opts);
660564
}
661565

662566
/*
@@ -671,13 +575,6 @@ static int rocksdb_init_func(void *p)
671575
init_rocksdb_psi_keys();
672576
#endif
673577

674-
/* Parse command-line option values */
675-
if (rocksdb_parse_write_buffer_size_arg() ||
676-
rocksdb_parse_target_file_size_base_arg())
677-
{
678-
DBUG_RETURN(1);
679-
}
680-
681578
rocksdb_hton= (handlerton *)p;
682579
mysql_mutex_init(ex_key_mutex_example, &rocksdb_mutex, MY_MUTEX_INIT_FAST);
683580
(void) my_hash_init(&rocksdb_open_tables,system_charset_info,32,0,0,
@@ -746,8 +643,7 @@ static int rocksdb_init_func(void *p)
746643

747644
default_cf_opts.comparator= &rocksdb_pk_comparator;
748645

749-
default_cf_opts.write_buffer_size= write_buffer_size_map.get_default_val();
750-
default_cf_opts.target_file_size_base= target_file_size_base_map.get_default_val();
646+
default_cf_opts.write_buffer_size = ROCKSDB_WRITE_BUFFER_SIZE_DEFAULT;
751647

752648
rocksdb::BlockBasedTableOptions table_options;
753649
table_options.block_cache = rocksdb::NewLRUCache(rocksdb_block_cache_size);
@@ -760,10 +656,10 @@ static int rocksdb_init_func(void *p)
760656
DBUG_RETURN(1);
761657
}
762658

763-
if (!rocksdb::GetColumnFamilyOptionsFromString(
764-
default_cf_opts,
765-
std::string(rocksdb_default_cf_options),
766-
&default_cf_opts)) {
659+
if (!rocksdb_cf_options_map.SetDefault(
660+
std::string(rocksdb_default_cf_options)) ||
661+
!rocksdb_cf_options_map.ParseConfigFile(
662+
std::string(rocksdb_cf_options_file))) {
767663
DBUG_RETURN(1);
768664
}
769665

0 commit comments

Comments
 (0)