Skip to content

Commit e3809ba

Browse files
committed
Tweak the LevelDB options a bit.
1 parent bb550ab commit e3809ba

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

configure.ac

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ PKG_CHECK_MODULES([json_c], [json-c])
2727

2828
# Checks for header files.
2929
AC_HEADER_RESOLV
30-
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])
30+
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/socket.h sys/time.h unistd.h leveldb/filter_policy.h])
3131
AC_CHECK_HEADER([event2/event.h],,
3232
[AC_MSG_ERROR([libevent headers could not be found])])
3333
AC_CHECK_HEADER([gflags/gflags.h],,
@@ -36,6 +36,8 @@ AC_CHECK_HEADER([glog/logging.h],,
3636
[AC_MSG_ERROR([glog headers could not be found])])
3737
AC_CHECK_HEADER([google/protobuf/message.h],,
3838
[AC_MSG_ERROR([protobuf headers could not be found])])
39+
AC_CHECK_HEADER([leveldb/db.h],,
40+
[AC_MSG_ERROR([leveldb headers could not be found])])
3941
AC_CHECK_HEADER([ldns/ldns.h],, [missing_ldns=yes])
4042

4143
# Check for working GTest/GMock.

cpp/log/leveldb_db-inl.h

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
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

1822
namespace {
1923

@@ -29,6 +33,20 @@ const char kTreeHeadPrefix[] = "sth-";
2933
const 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+
3250
std::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

4866
template <class Logged>
4967
LevelDB<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

cpp/log/leveldb_db.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#ifndef CERTIFICATE_LEVELDB_DB_H
22
#define CERTIFICATE_LEVELDB_DB_H
33

4+
#include "config.h"
5+
46
#include <leveldb/db.h>
7+
#ifdef HAVE_LEVELDB_FILTER_POLICY_H
8+
#include <leveldb/filter_policy.h>
9+
#endif
510
#include <map>
611
#include <memory>
712
#include <mutex>
@@ -63,6 +68,11 @@ class LevelDB : public Database<Logged> {
6368
void InsertEntryMapping(int64_t sequence_number, const std::string& hash);
6469

6570
mutable std::mutex lock_;
71+
#ifdef HAVE_LEVELDB_FILTER_POLICY_H
72+
// filter_policy_ must be valid for at least as long as db_ is, so
73+
// keep this order.
74+
const std::unique_ptr<const leveldb::FilterPolicy> filter_policy_;
75+
#endif
6676
std::unique_ptr<leveldb::DB> db_;
6777

6878
int64_t contiguous_size_;

0 commit comments

Comments
 (0)