Skip to content

Commit

Permalink
Merge branch 'master' into performance
Browse files Browse the repository at this point in the history
Conflicts:
	Makefile
	db/db_impl.cc
	db/db_test.cc
	db/memtable_list.cc
	db/memtable_list.h
	table/block_based_table_reader.cc
	table/table_test.cc
	util/cache.cc
	util/coding.cc
  • Loading branch information
liukai committed Jan 28, 2014
2 parents b20486f + 9dc2941 commit a5e220f
Show file tree
Hide file tree
Showing 48 changed files with 1,642 additions and 537 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,12 @@ endif # PLATFORM_SHARED_EXT
all: $(LIBRARY) $(PROGRAMS)

.PHONY: blackbox_crash_test check clean coverage crash_test ldb_tests \
release tags valgrind_check whitebox_crash_test format
release tags valgrind_check whitebox_crash_test format shared_lib

# Will also generate shared libraries.
release:
$(MAKE) clean
OPT="-DNDEBUG -O2" $(MAKE) all -j32
OPT="-DNDEBUG -O2" $(MAKE) $(SHARED) -j32

coverage:
$(MAKE) clean
Expand Down Expand Up @@ -200,6 +199,8 @@ tags:
format:
build_tools/format-diff.sh

shared_lib: $(SHARED)

# ---------------------------------------------------------------------------
# Unit tests and tools
# ---------------------------------------------------------------------------
Expand Down
34 changes: 22 additions & 12 deletions db/compaction_picker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#include "db/compaction_picker.h"

#include <limits>
#include "util/statistics.h"

namespace rocksdb {
Expand All @@ -22,6 +24,21 @@ uint64_t TotalFileSize(const std::vector<FileMetaData*>& files) {
return sum;
}

// Multiple two operands. If they overflow, return op1.
uint64_t MultiplyCheckOverflow(uint64_t op1, int op2) {
if (op1 == 0) {
return 0;
}
if (op2 <= 0) {
return op1;
}
uint64_t casted_op2 = (uint64_t) op2;
if (std::numeric_limits<uint64_t>::max() / op1 < casted_op2) {
return op1;
}
return op1 * casted_op2;
}

} // anonymous namespace

CompactionPicker::CompactionPicker(const Options* options,
Expand All @@ -30,15 +47,7 @@ CompactionPicker::CompactionPicker(const Options* options,
options_(options),
num_levels_(options->num_levels),
icmp_(icmp) {
Init();
}

void CompactionPicker::ReduceNumberOfLevels(int new_levels) {
num_levels_ = new_levels;
Init();
}

void CompactionPicker::Init() {
max_file_size_.reset(new uint64_t[NumberLevels()]);
level_max_bytes_.reset(new uint64_t[NumberLevels()]);
int target_file_size_multiplier = options_->target_file_size_multiplier;
Expand All @@ -48,10 +57,11 @@ void CompactionPicker::Init() {
max_file_size_[i] = ULLONG_MAX;
level_max_bytes_[i] = options_->max_bytes_for_level_base;
} else if (i > 1) {
max_file_size_[i] = max_file_size_[i - 1] * target_file_size_multiplier;
level_max_bytes_[i] =
level_max_bytes_[i - 1] * max_bytes_multiplier *
options_->max_bytes_for_level_multiplier_additional[i - 1];
max_file_size_[i] = MultiplyCheckOverflow(max_file_size_[i - 1],
target_file_size_multiplier);
level_max_bytes_[i] = MultiplyCheckOverflow(
MultiplyCheckOverflow(level_max_bytes_[i - 1], max_bytes_multiplier),
options_->max_bytes_for_level_multiplier_additional[i - 1]);
} else {
max_file_size_[i] = options_->target_file_size_base;
level_max_bytes_[i] = options_->max_bytes_for_level_base;
Expand Down
5 changes: 0 additions & 5 deletions db/compaction_picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ class CompactionPicker {
CompactionPicker(const Options* options, const InternalKeyComparator* icmp);
virtual ~CompactionPicker();

// See VersionSet::ReduceNumberOfLevels()
void ReduceNumberOfLevels(int new_levels);

// Pick level and inputs for a new compaction.
// Returns nullptr if there is no compaction to be done.
// Otherwise returns a pointer to a heap-allocated object that
Expand Down Expand Up @@ -120,8 +117,6 @@ class CompactionPicker {

const Options* const options_;
private:
void Init();

int num_levels_;

const InternalKeyComparator* const icmp_;
Expand Down
2 changes: 2 additions & 0 deletions db/db_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "rocksdb/env.h"
#include "rocksdb/memtablerep.h"
#include "rocksdb/write_batch.h"
#include "rocksdb/slice.h"
#include "rocksdb/slice_transform.h"
#include "rocksdb/statistics.h"
#include "rocksdb/perf_context.h"
#include "port/port.h"
Expand Down
Loading

0 comments on commit a5e220f

Please sign in to comment.