From 742d05285f989ac7da41704008ded612ad691f85 Mon Sep 17 00:00:00 2001 From: "wangyi.ywq" Date: Tue, 22 Dec 2020 17:59:16 +0800 Subject: [PATCH] merge ljc --- db/db_impl.cc | 51 +++++++++++++++++++++++++++++++-------- db/db_impl.h | 3 +++ db/db_impl_gc_ttl_test.cc | 26 ++++++++++++++++++++ 3 files changed, 70 insertions(+), 10 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 78a86bee6..5d63fc663 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -100,8 +100,6 @@ #if !defined(_MSC_VER) && !defined(__APPLE__) #include - - #endif #include "utilities/util/valvec.hpp" @@ -112,8 +110,9 @@ #ifdef WITH_TERARK_ZIP #include -#include + #include +#include #endif #ifdef BOOSTLIB @@ -121,7 +120,6 @@ #endif //#include - #ifdef __GNUC__ #pragma GCC diagnostic pop #endif @@ -773,8 +771,41 @@ void DBImpl::StartTimedTasks() { } } } - +void DBImpl::ScheduleGCTTL() { + uint64_t mark_count = 0; + uint64_t marked_count = 0; + uint64_t nowSeconds = env_->NowMicros() / 1000000; + auto should_marked_for_compacted = [](uint64_t ratio_expire_time, + uint64_t scan_gap_expire_time, + uint64_t now) { + return (std::min(ratio_expire_time, scan_gap_expire_time) < now); + }; + ROCKS_LOG_INFO(immutable_db_options_.info_log, "Start ScheduleGCTTL"); + for (auto cfd : *versions_->GetColumnFamilySet()) { + if (cfd->initialized()) { + VersionStorageInfo* vsi = cfd->current()->storage_info(); + for (int l = 0; l < vsi->num_levels(); l++) { + for (auto sst : vsi->LevelFiles(l)) { + if (sst->marked_for_compaction) marked_count++; + if (!sst->marked_for_compaction) + sst->marked_for_compaction = should_marked_for_compacted( + sst->prop.ratio_expire_time, sst->prop.scan_gap_expire_time, + nowSeconds); + if (sst->marked_for_compaction) { + mark_count++; + } + } + } + } + } + ROCKS_LOG_INFO(immutable_db_options_.info_log, "marked for compact SST: %d,%d", + marked_count,mark_count); + if (mark_count > 0) { + MaybeScheduleFlushOrCompaction(); + } +} void DBImpl::DumpStats() { + ScheduleGCTTL(); TEST_SYNC_POINT("DBImpl::DumpStats:1"); #ifndef ROCKSDB_LITE const DBPropertyInfo* cf_property_info = @@ -1259,9 +1290,9 @@ void DBImpl::SchedulePurge() { void DBImpl::BackgroundCallPurge() { mutex_.Lock(); - // We use one single loop to clear both queues so that after existing the loop - // both queues are empty. This is stricter than what is needed, but can make - // it easier for us to reason the correctness. + // We use one single loop to clear both queues so that after existing the + // loop both queues are empty. This is stricter than what is needed, but can + // make it easier for us to reason the correctness. while (!purge_queue_.empty() | !superversion_to_free_queue_.empty() | !logs_to_free_queue_.empty()) { if (!superversion_to_free_queue_.empty()) { @@ -2249,8 +2280,8 @@ Status DBImpl::NewIterators( #endif } else { // Note: no need to consider the special case of - // last_seq_same_as_publish_seq_==false since NewIterators is overridden in - // WritePreparedTxnDB + // last_seq_same_as_publish_seq_==false since NewIterators is overridden + // in WritePreparedTxnDB auto snapshot = read_options.snapshot != nullptr ? read_options.snapshot->GetSequenceNumber() : versions_->LastSequence(); diff --git a/db/db_impl.h b/db/db_impl.h index eabb5f568..815596ed2 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -1151,6 +1151,9 @@ class DBImpl : public DB { // dump rocksdb.stats to LOG void DumpStats(); + // + void ScheduleGCTTL(); + // Return the minimum empty level that could hold the total data in the // input level. Return the input level, if such level could not be found. int FindMinimumEmptyLevelFitting(ColumnFamilyData* cfd, diff --git a/db/db_impl_gc_ttl_test.cc b/db/db_impl_gc_ttl_test.cc index e69de29bb..a8e94caa2 100644 --- a/db/db_impl_gc_ttl_test.cc +++ b/db/db_impl_gc_ttl_test.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2020-present, Bytedance Inc. All rights reserved. +// This source code is licensed under Apache 2.0 License. + +#include "table/block_based_table_builder.h" + +#include "include/rocksdb/ttl_extractor.h" +#include "util/testharness.h" +#include "util/testutil.h" + +namespace rocksdb{ + +class DBImplGCTTL_Test : public testing::Test { + // + + private: + +}; + +TEST_F(DBImplGCTTL_Test,OpenTest) { + +} +} +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file -- GitLab