1414#include " monitoring/latency.h"
1515#include " util/util.h"
1616
17+ DEFINE_int32 (leveldb_max_open_files, 0 ,
18+ " number of open files that can be used by leveldb" );
19+ DEFINE_int32 (leveldb_bloom_filter_bits_per_key, 0 ,
20+ " number of open files that can be used by leveldb" );
1721
1822namespace {
1923
@@ -29,6 +33,20 @@ const char kTreeHeadPrefix[] = "sth-";
2933const char kMetaPrefix [] = " meta-" ;
3034
3135
36+ #ifdef HAVE_LEVELDB_FILTER_POLICY_H
37+ std::unique_ptr<const leveldb::FilterPolicy> BuildFilterPolicy () {
38+ std::unique_ptr<const leveldb::FilterPolicy> retval;
39+
40+ if (FLAGS_leveldb_bloom_filter_bits_per_key > 0 ) {
41+ retval.reset (CHECK_NOTNULL (leveldb::NewBloomFilterPolicy (
42+ FLAGS_leveldb_bloom_filter_bits_per_key)));
43+ }
44+
45+ return retval;
46+ }
47+ #endif
48+
49+
3250std::string FormatSequenceNumber (const int64_t seq) {
3351 return std::to_string (seq);
3452}
@@ -47,11 +65,25 @@ const size_t LevelDB<Logged>::kTimestampBytesIndexed = 6;
4765
4866template <class Logged >
4967LevelDB<Logged>::LevelDB(const std::string& dbfile)
50- : contiguous_size_(0 ), latest_tree_timestamp_(0 ) {
68+ :
69+ #ifdef HAVE_LEVELDB_FILTER_POLICY_H
70+ filter_policy_ (BuildFilterPolicy()),
71+ #endif
72+ contiguous_size_ (0 ),
73+ latest_tree_timestamp_(0 ) {
5174 LOG (INFO) << " Opening " << dbfile;
5275 cert_trans::ScopedLatency latency (latency_by_op_ms.GetScopedLatency (" open" ));
5376 leveldb::Options options;
5477 options.create_if_missing = true ;
78+ if (FLAGS_leveldb_max_open_files > 0 ) {
79+ options.max_open_files = FLAGS_leveldb_max_open_files;
80+ }
81+ #ifdef HAVE_LEVELDB_FILTER_POLICY_H
82+ options.filter_policy = filter_policy_.get ();
83+ #else
84+ CHECK_EQ (FLAGS_leveldb_bloom_filter_bits_per_key, 0 )
85+ << " this version of leveldb does not have bloom filter support" ;
86+ #endif
5587 leveldb::DB* db;
5688 leveldb::Status status (leveldb::DB::Open (options, dbfile, &db));
5789 CHECK (status.ok ()) << status.ToString ();
@@ -286,8 +318,9 @@ void LevelDB<Logged>::BuildIndex() {
286318 // this should not be necessarily, but just to be sure...
287319 std::lock_guard<std::mutex> lock (lock_);
288320
289- std::unique_ptr<leveldb::Iterator> it (
290- db_->NewIterator (leveldb::ReadOptions ()));
321+ leveldb::ReadOptions options;
322+ options.fill_cache = false ;
323+ std::unique_ptr<leveldb::Iterator> it (db_->NewIterator (options));
291324 CHECK (it);
292325 it->Seek (kEntryPrefix );
293326
0 commit comments