Преглед на файлове

TestTTL.CompactionTTL passed

master
马也驰 преди 2 седмици
родител
ревизия
0cefdf5ace
променени са 2 файла, в които са добавени 33 реда и са изтрити 16 реда
  1. +32
    -15
      db/db_impl.cc
  2. +1
    -1
      test/ttl_test.cc

+ 32
- 15
db/db_impl.cc Целия файл

@ -594,6 +594,8 @@ void DBImpl::CompactRange(const Slice* begin, const Slice* end) {
for (int level = 0; level < max_level_with_files; level++) {
TEST_CompactRange(level, begin, end);
}
/// For TTL
TEST_CompactRange(max_level_with_files, begin, end);
}
void DBImpl::TEST_CompactRange(int level, const Slice* begin,
@ -735,21 +737,21 @@ void DBImpl::BackgroundCompaction() {
if (c == nullptr) {
// Nothing to do
} else if (!is_manual && c->IsTrivialMove()) {
// Move file to next level
assert(c->num_input_files(0) == 1);
FileMetaData* f = c->input(0, 0);
c->edit()->RemoveFile(c->level(), f->number);
c->edit()->AddFile(c->level() + 1, f->number, f->file_size, f->smallest,
f->largest);
status = versions_->LogAndApply(c->edit(), &mutex_);
if (!status.ok()) {
RecordBackgroundError(status);
}
VersionSet::LevelSummaryStorage tmp;
Log(options_.info_log, "Moved #%lld to level-%d %lld bytes %s: %s\n",
static_cast<unsigned long long>(f->number), c->level() + 1,
static_cast<unsigned long long>(f->file_size),
status.ToString().c_str(), versions_->LevelSummary(&tmp));
// // Move file to next level
// assert(c->num_input_files(0) == 1);
// FileMetaData* f = c->input(0, 0);
// c->edit()->RemoveFile(c->level(), f->number);
// c->edit()->AddFile(c->level() + 1, f->number, f->file_size, f->smallest,
// f->largest);
// status = versions_->LogAndApply(c->edit(), &mutex_);
// if (!status.ok()) {
// RecordBackgroundError(status);
// }
// VersionSet::LevelSummaryStorage tmp;
// Log(options_.info_log, "Moved #%lld to level-%d %lld bytes %s: %s\n",
// static_cast<unsigned long long>(f->number), c->level() + 1,
// static_cast<unsigned long long>(f->file_size),
// status.ToString().c_str(), versions_->LevelSummary(&tmp));
} else {
CompactionState* compact = new CompactionState(c);
status = DoCompactionWork(compact);
@ -979,6 +981,21 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
drop = true;
}
/// For TTL
Slice value_ddl = input->value();
std::string value = value_ddl.ToString();
size_t pos = value.find_last_of('_');
if (pos != std::string::npos) {
std::string substring = value.substr(pos + 1);
auto ddl = static_cast<uint64_t>(std::stoll(substring));
auto now = std::chrono::system_clock::now();
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
auto microsecondsTimestamp = static_cast<uint64_t>(timestamp);
if (ddl <= microsecondsTimestamp) {
drop = true;
}
}
last_sequence_for_key = ikey.sequence;
}
#if 0

+ 1
- 1
test/ttl_test.cc Целия файл

@ -81,7 +81,7 @@ TEST(TestTTL, ReadTTL) {
TEST(TestTTL, CompactionTTL) {
DB *db;
if(OpenDB("testdb", &db).ok() == false) {
if(OpenDB("testdb_", &db).ok() == false) {
std::cerr << "open db failed" << std::endl;
abort();
}

Зареждане…
Отказ
Запис