Skip to content

Commit e86d7df

Browse files
committed
Merge branch 'master' into columnfamilies
2 parents e816838 + b9ce156 commit e86d7df

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

db/db_impl.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
28272827
compact->CleanupBatchBuffer();
28282828
compact->CleanupMergedBuffer();
28292829
compact->cur_prefix_ = kNullString;
2830+
bool prefix_initialized = false;
28302831

28312832
int64_t imm_micros = 0; // Micros spent doing imm_ compactions
28322833
ColumnFamilyData* cfd = compact->compaction->column_family_data();
@@ -2903,8 +2904,9 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
29032904
const SliceTransform* transformer =
29042905
cfd->options()->compaction_filter_factory_v2->GetPrefixExtractor();
29052906
std::string key_prefix = transformer->Transform(key).ToString();
2906-
if (compact->cur_prefix_ == kNullString) {
2907+
if (!prefix_initialized) {
29072908
compact->cur_prefix_ = key_prefix;
2909+
prefix_initialized = true;
29082910
}
29092911
if (!ParseInternalKey(key, &ikey)) {
29102912
// log error

db/db_test.cc

+50
Original file line numberDiff line numberDiff line change
@@ -3969,6 +3969,56 @@ TEST(DBTest, CompactionFilterV2WithValueChange) {
39693969
}
39703970
}
39713971

3972+
TEST(DBTest, CompactionFilterV2NULLPrefix) {
3973+
Options options = CurrentOptions();
3974+
options.num_levels = 3;
3975+
options.max_mem_compaction_level = 0;
3976+
auto prefix_extractor = NewFixedPrefixTransform(8);
3977+
options.compaction_filter_factory_v2 =
3978+
std::make_shared<ChangeFilterFactoryV2>(prefix_extractor);
3979+
// In a testing environment, we can only flush the application
3980+
// compaction filter buffer using universal compaction
3981+
option_config_ = kUniversalCompaction;
3982+
options.compaction_style = (rocksdb::CompactionStyle)1;
3983+
Reopen(&options);
3984+
3985+
// Write 100K+1 keys, these are written to a few files
3986+
// in L0. We do this so that the current snapshot points
3987+
// to the 100001 key.The compaction filter is not invoked
3988+
// on keys that are visible via a snapshot because we
3989+
// anyways cannot delete it.
3990+
const std::string value(10, 'x');
3991+
char first_key[100];
3992+
snprintf(first_key, sizeof(first_key), "%s0000%010d", "NULL", 1);
3993+
Put(first_key, value);
3994+
for (int i = 1; i < 100000; i++) {
3995+
char key[100];
3996+
snprintf(key, sizeof(key), "%08d%010d", i, i);
3997+
Put(key, value);
3998+
}
3999+
4000+
char last_key[100];
4001+
snprintf(last_key, sizeof(last_key), "%s0000%010d", "NULL", 2);
4002+
Put(last_key, value);
4003+
4004+
// push all files to lower levels
4005+
dbfull()->TEST_FlushMemTable();
4006+
dbfull()->TEST_CompactRange(0, nullptr, nullptr);
4007+
4008+
// verify that all keys now have the new value that
4009+
// was set by the compaction process.
4010+
std::string newvalue = Get(first_key);
4011+
ASSERT_EQ(newvalue.compare(NEW_VALUE), 0);
4012+
newvalue = Get(last_key);
4013+
ASSERT_EQ(newvalue.compare(NEW_VALUE), 0);
4014+
for (int i = 1; i < 100000; i++) {
4015+
char key[100];
4016+
snprintf(key, sizeof(key), "%08d%010d", i, i);
4017+
std::string newvalue = Get(key);
4018+
ASSERT_EQ(newvalue.compare(NEW_VALUE), 0);
4019+
}
4020+
}
4021+
39724022
TEST(DBTest, SparseMerge) {
39734023
do {
39744024
Options options = CurrentOptions();

db/merge_operator.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ bool MergeOperator::PartialMergeMulti(const Slice& key,
1818
const std::deque<Slice>& operand_list,
1919
std::string* new_value,
2020
Logger* logger) const {
21+
assert(operand_list.size() >= 2);
2122
// Simply loop through the operands
2223
std::string temp_value;
23-
Slice temp_slice;
24-
for (const auto& operand : operand_list) {
24+
Slice temp_slice(operand_list[0]);
25+
26+
for (int i = 1; i < operand_list.size(); ++i) {
27+
auto& operand = operand_list[i];
2528
if (!PartialMerge(key, temp_slice, operand, &temp_value, logger)) {
2629
return false;
2730
}

util/env_posix.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ class PosixEnv : public Env {
13631363
EnvOptions OptimizeForLogWrite(const EnvOptions& env_options) const {
13641364
EnvOptions optimized = env_options;
13651365
optimized.use_mmap_writes = false;
1366-
optimized.fallocate_with_keep_size = true;
1366+
optimized.fallocate_with_keep_size = false;
13671367
return optimized;
13681368
}
13691369

0 commit comments

Comments
 (0)