Skip to content

Commit 239ac9d

Browse files
committed
avoid very large compactions; fix build on Linux
1 parent 3c8be10 commit 239ac9d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

build_detect_platform

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ case `uname -s` in
2727
Linux)
2828
PLATFORM=OS_LINUX
2929
echo "PLATFORM_CFLAGS=-pthread -DOS_LINUX" >> build_config.mk
30-
echo "PLATFORM_LDFLAGS=-lpthread" >> build_config.mk
30+
echo "PLATFORM_LDFLAGS=-pthread" >> build_config.mk
3131
;;
3232
SunOS)
3333
PLATFORM=OS_SOLARIS

db/version_set.cc

+14-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ static const int kTargetFileSize = 2 * 1048576;
2626
// stop building a single file in a level->level+1 compaction.
2727
static const int64_t kMaxGrandParentOverlapBytes = 10 * kTargetFileSize;
2828

29+
// Maximum number of bytes in all compacted files. We avoid expanding
30+
// the lower level file set of a compaction if it would make the
31+
// total compaction cover more than this many bytes.
32+
static const int64_t kExpandedCompactionByteSizeLimit = 25 * kTargetFileSize;
33+
2934
static double MaxBytesForLevel(int level) {
3035
// Note: the result for level zero is not really used since we set
3136
// the level-0 compaction threshold based on number of files.
@@ -1223,20 +1228,26 @@ void VersionSet::SetupOtherInputs(Compaction* c) {
12231228
if (!c->inputs_[1].empty()) {
12241229
std::vector<FileMetaData*> expanded0;
12251230
current_->GetOverlappingInputs(level, &all_start, &all_limit, &expanded0);
1226-
if (expanded0.size() > c->inputs_[0].size()) {
1231+
const int64_t inputs0_size = TotalFileSize(c->inputs_[0]);
1232+
const int64_t inputs1_size = TotalFileSize(c->inputs_[1]);
1233+
const int64_t expanded0_size = TotalFileSize(expanded0);
1234+
if (expanded0.size() > c->inputs_[0].size() &&
1235+
inputs1_size + expanded0_size < kExpandedCompactionByteSizeLimit) {
12271236
InternalKey new_start, new_limit;
12281237
GetRange(expanded0, &new_start, &new_limit);
12291238
std::vector<FileMetaData*> expanded1;
12301239
current_->GetOverlappingInputs(level+1, &new_start, &new_limit,
12311240
&expanded1);
12321241
if (expanded1.size() == c->inputs_[1].size()) {
12331242
Log(options_->info_log,
1234-
"Expanding@%d %d+%d to %d+%d\n",
1243+
"Expanding@%d %d+%d (%ld+%ld bytes) to %d+%d (%ld+%ld bytes)\n",
12351244
level,
12361245
int(c->inputs_[0].size()),
12371246
int(c->inputs_[1].size()),
1247+
long(inputs0_size), long(inputs1_size),
12381248
int(expanded0.size()),
1239-
int(expanded1.size()));
1249+
int(expanded1.size()),
1250+
long(expanded0_size), long(inputs1_size));
12401251
smallest = new_start;
12411252
largest = new_limit;
12421253
c->inputs_[0] = expanded0;

0 commit comments

Comments
 (0)