Skip to content

Commit a98badf

Browse files
author
Lei Jin
committed
print table options
Summary: Add a virtual function in table factory that will print table options Test Plan: make release Reviewers: igor, yhchiang, sdong Reviewed By: sdong Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D22149
1 parent 66f62e5 commit a98badf

11 files changed

+203
-41
lines changed

db/simple_table_db_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,10 @@ class SimpleTableFactory: public TableFactory {
559559
virtual Status SanitizeDBOptions(DBOptions* db_opts) const override {
560560
return Status::OK();
561561
}
562+
563+
virtual std::string GetPrintableTableOptions() const override {
564+
return std::string();
565+
}
562566
};
563567

564568
Status SimpleTableFactory::NewTableReader(

include/rocksdb/table.h

+47-41
Original file line numberDiff line numberDiff line change
@@ -166,47 +166,49 @@ struct PlainTablePropertyNames {
166166
const uint32_t kPlainTableVariableLength = 0;
167167

168168
struct PlainTableOptions {
169-
// @user_key_len: plain table has optimization for fix-sized keys, which can be
170-
// specified via user_key_len. Alternatively, you can pass
171-
// `kPlainTableVariableLength` if your keys have variable
172-
// lengths.
173-
uint32_t user_key_len = kPlainTableVariableLength;
174-
175-
// @bloom_bits_per_key: the number of bits used for bloom filer per prefix. You
176-
// may disable it by passing a zero.
177-
int bloom_bits_per_key = 10;
178-
179-
// @hash_table_ratio: the desired utilization of the hash table used for prefix
180-
// hashing. hash_table_ratio = number of prefixes / #buckets
181-
// in the hash table
182-
double hash_table_ratio = 0.75;
183-
184-
// @index_sparseness: inside each prefix, need to build one index record for how
185-
// many keys for binary search inside each hash bucket.
186-
// For encoding type kPrefix, the value will be used when
187-
// writing to determine an interval to rewrite the full key.
188-
// It will also be used as a suggestion and satisfied when
189-
// possible.
190-
size_t index_sparseness = 16;
191-
192-
// @huge_page_tlb_size: if <=0, allocate hash indexes and blooms from malloc.
193-
// Otherwise from huge page TLB. The user needs to reserve
194-
// huge pages for it to be allocated, like:
195-
// sysctl -w vm.nr_hugepages=20
196-
// See linux doc Documentation/vm/hugetlbpage.txt
197-
size_t huge_page_tlb_size = 0;
198-
199-
// @encoding_type: how to encode the keys. See enum EncodingType above for
200-
// the choices. The value will determine how to encode keys
201-
// when writing to a new SST file. This value will be stored
202-
// inside the SST file which will be used when reading from the
203-
// file, which makes it possible for users to choose different
204-
// encoding type when reopening a DB. Files with different
205-
// encoding types can co-exist in the same DB and can be read.
206-
EncodingType encoding_type = kPlain;
207-
208-
// @full_scan_mode: mode for reading the whole file one record by one without
209-
// using the index.
169+
// @user_key_len: plain table has optimization for fix-sized keys, which can
170+
// be specified via user_key_len. Alternatively, you can pass
171+
// `kPlainTableVariableLength` if your keys have variable
172+
// lengths.
173+
uint32_t user_key_len = kPlainTableVariableLength;
174+
175+
// @bloom_bits_per_key: the number of bits used for bloom filer per prefix.
176+
// You may disable it by passing a zero.
177+
int bloom_bits_per_key = 10;
178+
179+
// @hash_table_ratio: the desired utilization of the hash table used for
180+
// prefix hashing.
181+
// hash_table_ratio = number of prefixes / #buckets in the
182+
// hash table
183+
double hash_table_ratio = 0.75;
184+
185+
// @index_sparseness: inside each prefix, need to build one index record for
186+
// how many keys for binary search inside each hash bucket.
187+
// For encoding type kPrefix, the value will be used when
188+
// writing to determine an interval to rewrite the full
189+
// key. It will also be used as a suggestion and satisfied
190+
// when possible.
191+
size_t index_sparseness = 16;
192+
193+
// @huge_page_tlb_size: if <=0, allocate hash indexes and blooms from malloc.
194+
// Otherwise from huge page TLB. The user needs to
195+
// reserve huge pages for it to be allocated, like:
196+
// sysctl -w vm.nr_hugepages=20
197+
// See linux doc Documentation/vm/hugetlbpage.txt
198+
size_t huge_page_tlb_size = 0;
199+
200+
// @encoding_type: how to encode the keys. See enum EncodingType above for
201+
// the choices. The value will determine how to encode keys
202+
// when writing to a new SST file. This value will be stored
203+
// inside the SST file which will be used when reading from
204+
// the file, which makes it possible for users to choose
205+
// different encoding type when reopening a DB. Files with
206+
// different encoding types can co-exist in the same DB and
207+
// can be read.
208+
EncodingType encoding_type = kPlain;
209+
210+
// @full_scan_mode: mode for reading the whole file one record by one without
211+
// using the index.
210212
bool full_scan_mode = false;
211213

212214
// @store_index_in_file: compute plain table index and bloom filter during
@@ -299,6 +301,10 @@ class TableFactory {
299301
// If the function cannot find a way to sanitize the input DB Options,
300302
// a non-ok Status will be returned.
301303
virtual Status SanitizeDBOptions(DBOptions* db_opts) const = 0;
304+
305+
// Return a string that contains printable format of table configurations.
306+
// RocksDB prints configurations at DB Open().
307+
virtual std::string GetPrintableTableOptions() const = 0;
302308
};
303309

304310
#ifndef ROCKSDB_LITE

table/adaptive_table_factory.cc

+33
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,39 @@ TableBuilder* AdaptiveTableFactory::NewTableBuilder(
7070
file, compression_type);
7171
}
7272

73+
std::string AdaptiveTableFactory::GetPrintableTableOptions() const {
74+
std::string ret;
75+
ret.reserve(20000);
76+
const int kBufferSize = 200;
77+
char buffer[kBufferSize];
78+
79+
if (!table_factory_to_write_) {
80+
snprintf(buffer, kBufferSize, " write factory (%s) options:\n%s\n",
81+
table_factory_to_write_->Name(),
82+
table_factory_to_write_->GetPrintableTableOptions().c_str());
83+
ret.append(buffer);
84+
}
85+
if (!plain_table_factory_) {
86+
snprintf(buffer, kBufferSize, " %s options:\n%s\n",
87+
plain_table_factory_->Name(),
88+
plain_table_factory_->GetPrintableTableOptions().c_str());
89+
ret.append(buffer);
90+
}
91+
if (!block_based_table_factory_) {
92+
snprintf(buffer, kBufferSize, " %s options:\n%s\n",
93+
block_based_table_factory_->Name(),
94+
block_based_table_factory_->GetPrintableTableOptions().c_str());
95+
ret.append(buffer);
96+
}
97+
if (!cuckoo_table_factory_) {
98+
snprintf(buffer, kBufferSize, " %s options:\n%s\n",
99+
cuckoo_table_factory_->Name(),
100+
cuckoo_table_factory_->GetPrintableTableOptions().c_str());
101+
ret.append(buffer);
102+
}
103+
return ret;
104+
}
105+
73106
extern TableFactory* NewAdaptiveTableFactory(
74107
std::shared_ptr<TableFactory> table_factory_to_write,
75108
std::shared_ptr<TableFactory> block_based_table_factory,

table/adaptive_table_factory.h

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#ifndef ROCKSDB_LITE
88

9+
#include <string>
910
#include "rocksdb/options.h"
1011
#include "rocksdb/table.h"
1112

@@ -50,6 +51,7 @@ class AdaptiveTableFactory : public TableFactory {
5051
return Status::OK();
5152
}
5253

54+
std::string GetPrintableTableOptions() const override;
5355

5456
private:
5557
std::shared_ptr<TableFactory> table_factory_to_write_;

table/block_based_table_factory.cc

+60
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,66 @@ TableBuilder* BlockBasedTableFactory::NewTableBuilder(
6464
return table_builder;
6565
}
6666

67+
std::string BlockBasedTableFactory::GetPrintableTableOptions() const {
68+
std::string ret;
69+
ret.reserve(20000);
70+
const int kBufferSize = 200;
71+
char buffer[kBufferSize];
72+
73+
snprintf(buffer, kBufferSize, " flush_block_policy_factory: %s (%p)\n",
74+
table_options_.flush_block_policy_factory->Name(),
75+
table_options_.flush_block_policy_factory.get());
76+
ret.append(buffer);
77+
snprintf(buffer, kBufferSize, " cache_index_and_filter_blocks: %d\n",
78+
table_options_.cache_index_and_filter_blocks);
79+
ret.append(buffer);
80+
snprintf(buffer, kBufferSize, " index_type: %d\n",
81+
table_options_.index_type);
82+
ret.append(buffer);
83+
snprintf(buffer, kBufferSize, " hash_index_allow_collision: %d\n",
84+
table_options_.hash_index_allow_collision);
85+
ret.append(buffer);
86+
snprintf(buffer, kBufferSize, " checksum: %d\n",
87+
table_options_.checksum);
88+
ret.append(buffer);
89+
snprintf(buffer, kBufferSize, " no_block_cache: %d\n",
90+
table_options_.no_block_cache);
91+
ret.append(buffer);
92+
snprintf(buffer, kBufferSize, " block_cache: %p\n",
93+
table_options_.block_cache.get());
94+
ret.append(buffer);
95+
if (table_options_.block_cache) {
96+
snprintf(buffer, kBufferSize, " block_cache_size: %zd\n",
97+
table_options_.block_cache->GetCapacity());
98+
ret.append(buffer);
99+
}
100+
snprintf(buffer, kBufferSize, " block_cache_compressed: %p\n",
101+
table_options_.block_cache_compressed.get());
102+
ret.append(buffer);
103+
if (table_options_.block_cache_compressed) {
104+
snprintf(buffer, kBufferSize, " block_cache_compressed_size: %zd\n",
105+
table_options_.block_cache_compressed->GetCapacity());
106+
ret.append(buffer);
107+
}
108+
snprintf(buffer, kBufferSize, " block_size: %zd\n",
109+
table_options_.block_size);
110+
ret.append(buffer);
111+
snprintf(buffer, kBufferSize, " block_size_deviation: %d\n",
112+
table_options_.block_size_deviation);
113+
ret.append(buffer);
114+
snprintf(buffer, kBufferSize, " block_restart_interval: %d\n",
115+
table_options_.block_restart_interval);
116+
ret.append(buffer);
117+
snprintf(buffer, kBufferSize, " filter_policy: %s\n",
118+
table_options_.filter_policy == nullptr ?
119+
"nullptr" : table_options_.filter_policy->Name());
120+
ret.append(buffer);
121+
snprintf(buffer, kBufferSize, " whole_key_filtering: %d\n",
122+
table_options_.whole_key_filtering);
123+
ret.append(buffer);
124+
return ret;
125+
}
126+
67127
TableFactory* NewBlockBasedTableFactory(
68128
const BlockBasedTableOptions& table_options) {
69129
return new BlockBasedTableFactory(table_options);

table/block_based_table_factory.h

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class BlockBasedTableFactory : public TableFactory {
4949
return Status::OK();
5050
}
5151

52+
std::string GetPrintableTableOptions() const override;
53+
5254
private:
5355
BlockBasedTableOptions table_options_;
5456
};

table/cuckoo_table_factory.cc

+15
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ TableBuilder* CuckooTableFactory::NewTableBuilder(
5151
max_search_depth_, GetSliceMurmurHash);
5252
}
5353

54+
std::string CuckooTableFactory::GetPrintableTableOptions() const {
55+
std::string ret;
56+
ret.reserve(2000);
57+
const int kBufferSize = 200;
58+
char buffer[kBufferSize];
59+
60+
snprintf(buffer, kBufferSize, " hash_table_ratio: %lf\n",
61+
hash_table_ratio_);
62+
ret.append(buffer);
63+
snprintf(buffer, kBufferSize, " max_search_depth: %u\n",
64+
max_search_depth_);
65+
ret.append(buffer);
66+
return ret;
67+
}
68+
5469
TableFactory* NewCuckooTableFactory(double hash_table_ratio,
5570
uint32_t max_search_depth) {
5671
return new CuckooTableFactory(hash_table_ratio, max_search_depth);

table/cuckoo_table_factory.h

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#pragma once
77
#ifndef ROCKSDB_LITE
88

9+
#include <string>
910
#include "rocksdb/table.h"
1011

1112
namespace rocksdb {
@@ -45,6 +46,8 @@ class CuckooTableFactory : public TableFactory {
4546
return Status::OK();
4647
}
4748

49+
std::string GetPrintableTableOptions() const override;
50+
4851
private:
4952
const double hash_table_ratio_;
5053
const uint32_t max_search_depth_;

table/plain_table_factory.cc

+33
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,39 @@ TableBuilder* PlainTableFactory::NewTableBuilder(
3535
store_index_in_file_);
3636
}
3737

38+
std::string PlainTableFactory::GetPrintableTableOptions() const {
39+
std::string ret;
40+
ret.reserve(20000);
41+
const int kBufferSize = 200;
42+
char buffer[kBufferSize];
43+
44+
snprintf(buffer, kBufferSize, " user_key_len: %u\n",
45+
user_key_len_);
46+
ret.append(buffer);
47+
snprintf(buffer, kBufferSize, " bloom_bits_per_key: %d\n",
48+
bloom_bits_per_key_);
49+
ret.append(buffer);
50+
snprintf(buffer, kBufferSize, " hash_table_ratio: %lf\n",
51+
hash_table_ratio_);
52+
ret.append(buffer);
53+
snprintf(buffer, kBufferSize, " index_sparseness: %zd\n",
54+
index_sparseness_);
55+
ret.append(buffer);
56+
snprintf(buffer, kBufferSize, " huge_page_tlb_size: %zd\n",
57+
huge_page_tlb_size_);
58+
ret.append(buffer);
59+
snprintf(buffer, kBufferSize, " encoding_type: %d\n",
60+
encoding_type_);
61+
ret.append(buffer);
62+
snprintf(buffer, kBufferSize, " full_scan_mode: %d\n",
63+
full_scan_mode_);
64+
ret.append(buffer);
65+
snprintf(buffer, kBufferSize, " store_index_in_file: %d\n",
66+
store_index_in_file_);
67+
ret.append(buffer);
68+
return ret;
69+
}
70+
3871
extern TableFactory* NewPlainTableFactory(const PlainTableOptions& options) {
3972
return new PlainTableFactory(options);
4073
}

table/plain_table_factory.h

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ class PlainTableFactory : public TableFactory {
164164
CompressionType compression_type) const
165165
override;
166166

167+
std::string GetPrintableTableOptions() const override;
168+
167169
static const char kValueTypeSeqId0 = 0xFF;
168170

169171
// Sanitizes the specified DB Options.

util/options.cc

+2
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ void ColumnFamilyOptions::Dump(Logger* log) const {
305305
compaction_filter_factory_v2->Name());
306306
Log(log, " Options.memtable_factory: %s", memtable_factory->Name());
307307
Log(log, " Options.table_factory: %s", table_factory->Name());
308+
Log(log, " table_factory options: %s",
309+
table_factory->GetPrintableTableOptions().c_str());
308310
Log(log, " Options.write_buffer_size: %zd", write_buffer_size);
309311
Log(log, " Options.max_write_buffer_number: %d", max_write_buffer_number);
310312
if (!compression_per_level.empty()) {

0 commit comments

Comments
 (0)