Skip to content

Commit 3844001

Browse files
author
Lei Jin
committed
move block based table related options BlockBasedTableOptions
Summary: I will move compression related options in a separate diff since this diff is already pretty lengthy. I guess I will also need to change JNI accordingly :( Test Plan: make all check Reviewers: yhchiang, igor, sdong Reviewed By: igor Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D21915
1 parent 17b54ae commit 3844001

36 files changed

+465
-442
lines changed

HISTORY.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
* Statistics APIs now take uint32_t as type instead of Tickers. Also make two access functions getTickerCount and histogramData const
2121
* Add DB property rocksdb.estimate-num-keys, estimated number of live keys in DB.
2222
* Add DB::GetIntProperty(), which returns DB properties that are integer as uint64_t.
23+
* The Prefix Extractor used with V2 compaction filters is now passed user key to SliceTransform::Transform instead of unparsed RocksDB key.
24+
* Move BlockBasedTable related options to BlockBasedTableOptions from Options. Change corresponding JNI interface. Options affected include:
25+
no_block_cache, block_cache, block_cache_compressed, block_size, block_size_deviation, block_restart_interval, filter_policy, whole_key_filtering. filter_policy is changed to shared_ptr from a raw pointer.
26+
* Remove deprecated options: disable_seek_compaction and db_stats_log_interval
2327

2428
## 3.3.0 (7/10/2014)
2529
### New Features

db/c.cc

+70-50
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ using rocksdb::MergeOperator;
5555
using rocksdb::NewBloomFilterPolicy;
5656
using rocksdb::NewLRUCache;
5757
using rocksdb::Options;
58+
using rocksdb::BlockBasedTableOptions;
5859
using rocksdb::RandomAccessFile;
5960
using rocksdb::Range;
6061
using rocksdb::ReadOptions;
@@ -81,6 +82,7 @@ struct rocksdb_fifo_compaction_options_t { CompactionOptionsFIFO rep; };
8182
struct rocksdb_readoptions_t { ReadOptions rep; };
8283
struct rocksdb_writeoptions_t { WriteOptions rep; };
8384
struct rocksdb_options_t { Options rep; };
85+
struct rocksdb_block_based_table_options_t { BlockBasedTableOptions rep; };
8486
struct rocksdb_seqfile_t { SequentialFile* rep; };
8587
struct rocksdb_randomfile_t { RandomAccessFile* rep; };
8688
struct rocksdb_writablefile_t { WritableFile* rep; };
@@ -1053,6 +1055,74 @@ const char* rocksdb_writebatch_data(rocksdb_writebatch_t* b, size_t* size) {
10531055
return b->rep.Data().c_str();
10541056
}
10551057

1058+
rocksdb_block_based_table_options_t*
1059+
rocksdb_block_based_options_create() {
1060+
return new rocksdb_block_based_table_options_t;
1061+
}
1062+
1063+
void rocksdb_block_based_options_destroy(
1064+
rocksdb_block_based_table_options_t* options) {
1065+
delete options;
1066+
}
1067+
1068+
void rocksdb_block_based_options_set_block_size(
1069+
rocksdb_block_based_table_options_t* options, size_t block_size) {
1070+
options->rep.block_size = block_size;
1071+
}
1072+
1073+
void rocksdb_block_based_options_set_block_size_deviation(
1074+
rocksdb_block_based_table_options_t* options, int block_size_deviation) {
1075+
options->rep.block_size_deviation = block_size_deviation;
1076+
}
1077+
1078+
void rocksdb_block_based_options_set_block_restart_interval(
1079+
rocksdb_block_based_table_options_t* options, int block_restart_interval) {
1080+
options->rep.block_restart_interval = block_restart_interval;
1081+
}
1082+
1083+
void rocksdb_block_based_options_set_filter_policy(
1084+
rocksdb_block_based_table_options_t* options,
1085+
rocksdb_filterpolicy_t* filter_policy) {
1086+
options->rep.filter_policy.reset(filter_policy);
1087+
}
1088+
1089+
void rocksdb_block_based_options_set_no_block_cache(
1090+
rocksdb_block_based_table_options_t* options,
1091+
unsigned char no_block_cache) {
1092+
options->rep.no_block_cache = no_block_cache;
1093+
}
1094+
1095+
void rocksdb_block_based_options_set_block_cache(
1096+
rocksdb_block_based_table_options_t* options,
1097+
rocksdb_cache_t* block_cache) {
1098+
if (block_cache) {
1099+
options->rep.block_cache = block_cache->rep;
1100+
}
1101+
}
1102+
1103+
void rocksdb_block_based_options_set_block_cache_compressed(
1104+
rocksdb_block_based_table_options_t* options,
1105+
rocksdb_cache_t* block_cache_compressed) {
1106+
if (block_cache_compressed) {
1107+
options->rep.block_cache_compressed = block_cache_compressed->rep;
1108+
}
1109+
}
1110+
1111+
void rocksdb_block_based_options_set_whole_key_filtering(
1112+
rocksdb_block_based_table_options_t* options, unsigned char v) {
1113+
options->rep.whole_key_filtering = v;
1114+
}
1115+
1116+
void rocksdb_options_set_block_based_table_factory(
1117+
rocksdb_options_t *opt,
1118+
rocksdb_block_based_table_options_t* table_options) {
1119+
if (table_options) {
1120+
opt->rep.table_factory.reset(
1121+
rocksdb::NewBlockBasedTableFactory(table_options->rep));
1122+
}
1123+
}
1124+
1125+
10561126
rocksdb_options_t* rocksdb_options_create() {
10571127
return new rocksdb_options_t;
10581128
}
@@ -1111,12 +1181,6 @@ void rocksdb_options_set_compaction_filter_factory_v2(
11111181
opt->rep.compaction_filter_factory_v2 = std::shared_ptr<CompactionFilterFactoryV2>(compaction_filter_factory_v2);
11121182
}
11131183

1114-
void rocksdb_options_set_filter_policy(
1115-
rocksdb_options_t* opt,
1116-
rocksdb_filterpolicy_t* policy) {
1117-
opt->rep.filter_policy = policy;
1118-
}
1119-
11201184
void rocksdb_options_set_create_if_missing(
11211185
rocksdb_options_t* opt, unsigned char v) {
11221186
opt->rep.create_if_missing = v;
@@ -1160,26 +1224,6 @@ void rocksdb_options_set_max_open_files(rocksdb_options_t* opt, int n) {
11601224
opt->rep.max_open_files = n;
11611225
}
11621226

1163-
void rocksdb_options_set_cache(rocksdb_options_t* opt, rocksdb_cache_t* c) {
1164-
if (c) {
1165-
opt->rep.block_cache = c->rep;
1166-
}
1167-
}
1168-
1169-
void rocksdb_options_set_cache_compressed(rocksdb_options_t* opt, rocksdb_cache_t* c) {
1170-
if (c) {
1171-
opt->rep.block_cache_compressed = c->rep;
1172-
}
1173-
}
1174-
1175-
void rocksdb_options_set_block_size(rocksdb_options_t* opt, size_t s) {
1176-
opt->rep.block_size = s;
1177-
}
1178-
1179-
void rocksdb_options_set_block_restart_interval(rocksdb_options_t* opt, int n) {
1180-
opt->rep.block_restart_interval = n;
1181-
}
1182-
11831227
void rocksdb_options_set_target_file_size_base(
11841228
rocksdb_options_t* opt, uint64_t n) {
11851229
opt->rep.target_file_size_base = n;
@@ -1272,11 +1316,6 @@ void rocksdb_options_set_prefix_extractor(
12721316
opt->rep.prefix_extractor.reset(prefix_extractor);
12731317
}
12741318

1275-
void rocksdb_options_set_whole_key_filtering(
1276-
rocksdb_options_t* opt, unsigned char v) {
1277-
opt->rep.whole_key_filtering = v;
1278-
}
1279-
12801319
void rocksdb_options_set_disable_data_sync(
12811320
rocksdb_options_t* opt, int disable_data_sync) {
12821321
opt->rep.disableDataSync = disable_data_sync;
@@ -1287,11 +1326,6 @@ void rocksdb_options_set_use_fsync(
12871326
opt->rep.use_fsync = use_fsync;
12881327
}
12891328

1290-
void rocksdb_options_set_db_stats_log_interval(
1291-
rocksdb_options_t* opt, int db_stats_log_interval) {
1292-
opt->rep.db_stats_log_interval = db_stats_log_interval;
1293-
}
1294-
12951329
void rocksdb_options_set_db_log_dir(
12961330
rocksdb_options_t* opt, const char* db_log_dir) {
12971331
opt->rep.db_log_dir = db_log_dir;
@@ -1351,11 +1385,6 @@ void rocksdb_options_set_stats_dump_period_sec(
13511385
opt->rep.stats_dump_period_sec = v;
13521386
}
13531387

1354-
void rocksdb_options_set_block_size_deviation(
1355-
rocksdb_options_t* opt, int v) {
1356-
opt->rep.block_size_deviation = v;
1357-
}
1358-
13591388
void rocksdb_options_set_advise_random_on_open(
13601389
rocksdb_options_t* opt, unsigned char v) {
13611390
opt->rep.advise_random_on_open = v;
@@ -1450,11 +1479,6 @@ void rocksdb_options_set_max_manifest_file_size(
14501479
opt->rep.max_manifest_file_size = v;
14511480
}
14521481

1453-
void rocksdb_options_set_no_block_cache(
1454-
rocksdb_options_t* opt, unsigned char v) {
1455-
opt->rep.no_block_cache = v;
1456-
}
1457-
14581482
void rocksdb_options_set_table_cache_numshardbits(
14591483
rocksdb_options_t* opt, int v) {
14601484
opt->rep.table_cache_numshardbits = v;
@@ -1474,10 +1498,6 @@ void rocksdb_options_set_disable_auto_compactions(rocksdb_options_t* opt, int di
14741498
opt->rep.disable_auto_compactions = disable;
14751499
}
14761500

1477-
void rocksdb_options_set_disable_seek_compaction(rocksdb_options_t* opt, int disable) {
1478-
opt->rep.disable_seek_compaction = disable;
1479-
}
1480-
14811501
void rocksdb_options_set_delete_obsolete_files_period_micros(
14821502
rocksdb_options_t* opt, uint64_t v) {
14831503
opt->rep.delete_obsolete_files_period_micros = v;

db/c_test.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ int main(int argc, char** argv) {
335335
rocksdb_cache_t* cache;
336336
rocksdb_env_t* env;
337337
rocksdb_options_t* options;
338+
rocksdb_block_based_table_options_t* table_options;
338339
rocksdb_readoptions_t* roptions;
339340
rocksdb_writeoptions_t* woptions;
340341
char* err = NULL;
@@ -353,14 +354,15 @@ int main(int argc, char** argv) {
353354
options = rocksdb_options_create();
354355
rocksdb_options_set_comparator(options, cmp);
355356
rocksdb_options_set_error_if_exists(options, 1);
356-
rocksdb_options_set_cache(options, cache);
357357
rocksdb_options_set_env(options, env);
358358
rocksdb_options_set_info_log(options, NULL);
359359
rocksdb_options_set_write_buffer_size(options, 100000);
360360
rocksdb_options_set_paranoid_checks(options, 1);
361361
rocksdb_options_set_max_open_files(options, 10);
362-
rocksdb_options_set_block_size(options, 1024);
363-
rocksdb_options_set_block_restart_interval(options, 8);
362+
table_options = rocksdb_block_based_options_create();
363+
rocksdb_block_based_options_set_block_cache(table_options, cache);
364+
rocksdb_options_set_block_based_table_factory(options, table_options);
365+
364366
rocksdb_options_set_compression(options, rocksdb_no_compression);
365367
rocksdb_options_set_compression_options(options, -14, -1, 0);
366368
int compression_levels[] = {rocksdb_no_compression, rocksdb_no_compression,
@@ -540,10 +542,13 @@ int main(int argc, char** argv) {
540542
policy = rocksdb_filterpolicy_create_bloom(10);
541543
}
542544

545+
table_options = rocksdb_block_based_options_create();
546+
rocksdb_block_based_options_set_filter_policy(table_options, policy);
547+
543548
// Create new database
544549
rocksdb_close(db);
545550
rocksdb_destroy_db(options, dbname, &err);
546-
rocksdb_options_set_filter_policy(options, policy);
551+
rocksdb_options_set_block_based_table_factory(options, table_options);
547552
db = rocksdb_open(options, dbname, &err);
548553
CheckNoError(err);
549554
rocksdb_put(db, woptions, "foo", 3, "foovalue", 8, &err);
@@ -565,8 +570,9 @@ int main(int argc, char** argv) {
565570
CheckGet(db, roptions, "foo", "foovalue");
566571
CheckGet(db, roptions, "bar", "barvalue");
567572
}
568-
rocksdb_options_set_filter_policy(options, NULL);
569-
rocksdb_filterpolicy_destroy(policy);
573+
// Reset the policy
574+
rocksdb_block_based_options_set_filter_policy(table_options, NULL);
575+
rocksdb_options_set_block_based_table_factory(options, table_options);
570576
}
571577

572578
StartPhase("compaction_filter");
@@ -757,9 +763,7 @@ int main(int argc, char** argv) {
757763
StartPhase("prefix");
758764
{
759765
// Create new database
760-
rocksdb_filterpolicy_t* policy = rocksdb_filterpolicy_create_bloom(10);
761766
rocksdb_options_set_allow_mmap_reads(options, 1);
762-
rocksdb_options_set_filter_policy(options, policy);
763767
rocksdb_options_set_prefix_extractor(options, rocksdb_slicetransform_create_fixed_prefix(3));
764768
rocksdb_options_set_hash_skip_list_rep(options, 5000, 4, 4);
765769
rocksdb_options_set_plain_table_factory(options, 4, 10, 0.75, 16);
@@ -796,13 +800,13 @@ int main(int argc, char** argv) {
796800
rocksdb_iter_get_error(iter, &err);
797801
CheckNoError(err);
798802
rocksdb_iter_destroy(iter);
799-
rocksdb_filterpolicy_destroy(policy);
800803
}
801804

802805

803806
StartPhase("cleanup");
804807
rocksdb_close(db);
805808
rocksdb_options_destroy(options);
809+
rocksdb_block_based_options_destroy(table_options);
806810
rocksdb_readoptions_destroy(roptions);
807811
rocksdb_writeoptions_destroy(woptions);
808812
rocksdb_cache_destroy(cache);

db/column_family.cc

+1-11
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ ColumnFamilyHandleImpl::~ColumnFamilyHandleImpl() {
5050
uint32_t ColumnFamilyHandleImpl::GetID() const { return cfd()->GetID(); }
5151

5252
ColumnFamilyOptions SanitizeOptions(const InternalKeyComparator* icmp,
53-
const InternalFilterPolicy* ipolicy,
5453
const ColumnFamilyOptions& src) {
5554
ColumnFamilyOptions result = src;
5655
result.comparator = icmp;
57-
result.filter_policy = (src.filter_policy != nullptr) ? ipolicy : nullptr;
5856
#ifdef OS_MACOSX
5957
// TODO(icanadi) make write_buffer_size uint64_t instead of size_t
6058
ClipToRange(&result.write_buffer_size, ((size_t)64) << 10, ((size_t)1) << 30);
@@ -70,13 +68,7 @@ ColumnFamilyOptions SanitizeOptions(const InternalKeyComparator* icmp,
7068
result.min_write_buffer_number_to_merge =
7169
std::min(result.min_write_buffer_number_to_merge,
7270
result.max_write_buffer_number - 1);
73-
if (result.block_cache == nullptr && !result.no_block_cache) {
74-
result.block_cache = NewLRUCache(8 << 20);
75-
}
7671
result.compression_per_level = src.compression_per_level;
77-
if (result.block_size_deviation < 0 || result.block_size_deviation > 100) {
78-
result.block_size_deviation = 0;
79-
}
8072
if (result.max_mem_compaction_level >= result.num_levels) {
8173
result.max_mem_compaction_level = result.num_levels - 1;
8274
}
@@ -195,9 +187,7 @@ ColumnFamilyData::ColumnFamilyData(uint32_t id, const std::string& name,
195187
refs_(0),
196188
dropped_(false),
197189
internal_comparator_(options.comparator),
198-
internal_filter_policy_(options.filter_policy),
199-
options_(*db_options, SanitizeOptions(&internal_comparator_,
200-
&internal_filter_policy_, options)),
190+
options_(*db_options, SanitizeOptions(&internal_comparator_, options)),
201191
mem_(nullptr),
202192
imm_(options_.min_write_buffer_number_to_merge),
203193
super_version_(nullptr),

db/column_family.h

-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ struct SuperVersion {
113113
};
114114

115115
extern ColumnFamilyOptions SanitizeOptions(const InternalKeyComparator* icmp,
116-
const InternalFilterPolicy* ipolicy,
117116
const ColumnFamilyOptions& src);
118117

119118
class ColumnFamilySet;
@@ -272,7 +271,6 @@ class ColumnFamilyData {
272271
bool dropped_; // true if client dropped it
273272

274273
const InternalKeyComparator internal_comparator_;
275-
const InternalFilterPolicy internal_filter_policy_;
276274

277275
Options const options_;
278276

db/column_family_test.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,10 @@ TEST(ColumnFamilyTest, DifferentCompactionStyles) {
746746
default_cf.num_levels = 3;
747747
default_cf.write_buffer_size = 64 << 10; // 64KB
748748
default_cf.target_file_size_base = 30 << 10;
749-
default_cf.filter_policy = nullptr;
750-
default_cf.no_block_cache = true;
751749
default_cf.source_compaction_factor = 100;
750+
BlockBasedTableOptions table_options;
751+
table_options.no_block_cache = true;
752+
default_cf.table_factory.reset(NewBlockBasedTableFactory(table_options));
752753

753754
one.compaction_style = kCompactionStyleUniversal;
754755
// trigger compaction if there are >= 4 files

db/corruption_test.cc

+7-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class CorruptionTest {
4545

4646
db_ = nullptr;
4747
options_.create_if_missing = true;
48-
options_.block_size_deviation = 0; // make unit test pass for now
48+
BlockBasedTableOptions table_options;
49+
table_options.block_size_deviation = 0; // make unit test pass for now
50+
options_.table_factory.reset(NewBlockBasedTableFactory(table_options));
4951
Reopen();
5052
options_.create_if_missing = false;
5153
}
@@ -60,9 +62,11 @@ class CorruptionTest {
6062
db_ = nullptr;
6163
Options opt = (options ? *options : options_);
6264
opt.env = &env_;
63-
opt.block_cache = tiny_cache_;
64-
opt.block_size_deviation = 0;
6565
opt.arena_block_size = 4096;
66+
BlockBasedTableOptions table_options;
67+
table_options.block_cache = tiny_cache_;
68+
table_options.block_size_deviation = 0;
69+
opt.table_factory.reset(NewBlockBasedTableFactory(table_options));
6670
return DB::Open(opt, dbname_, &db_);
6771
}
6872

0 commit comments

Comments
 (0)