Skip to content

Commit 27c544f

Browse files
committed
Expose GetTtl() API in TTL DB (facebook#13790)
Summary: As title Pull Request resolved: facebook#13790 Test Plan: ``` ./ttl_test --gtest_filter="*TtlTest.ChangeTtlOnOpenDb*" ``` Reviewed By: cbi42 Differential Revision: D78670347 Pulled By: jaykorean fbshipit-source-id: 1b2538d6cd0f2a0fbf397a5d2f677852f97272c4
1 parent 11a61ca commit 27c544f

5 files changed

Lines changed: 27 additions & 0 deletions

File tree

include/rocksdb/utilities/db_ttl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class DBWithTTL : public StackableDB {
6363

6464
virtual void SetTtl(ColumnFamilyHandle* h, int32_t ttl) = 0;
6565

66+
virtual Status GetTtl(ColumnFamilyHandle* h, int32_t* ttl) = 0;
67+
6668
protected:
6769
explicit DBWithTTL(DB* db) : StackableDB(db) {}
6870
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GetTtl() API is now available in TTL DB

utilities/ttl/db_ttl_impl.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,4 +635,22 @@ void DBWithTTLImpl::SetTtl(ColumnFamilyHandle* h, int32_t ttl) {
635635
filter->SetTtl(ttl);
636636
}
637637

638+
Status DBWithTTLImpl::GetTtl(ColumnFamilyHandle* h, int32_t* ttl) {
639+
if (h == nullptr || ttl == nullptr) {
640+
return Status::InvalidArgument(
641+
"column family handle or ttl cannot be null");
642+
}
643+
std::shared_ptr<TtlCompactionFilterFactory> filter;
644+
Options opts;
645+
opts = GetOptions(h);
646+
filter = std::static_pointer_cast<TtlCompactionFilterFactory>(
647+
opts.compaction_filter_factory);
648+
if (!filter) {
649+
return Status::InvalidArgument(
650+
"TTLCompactionFilterFactory is not set for TTLDB");
651+
}
652+
*ttl = filter->GetTtl();
653+
return Status::OK();
654+
}
655+
638656
} // namespace ROCKSDB_NAMESPACE

utilities/ttl/db_ttl_impl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class DBWithTTLImpl : public DBWithTTL {
100100

101101
void SetTtl(ColumnFamilyHandle* h, int32_t ttl) override;
102102

103+
Status GetTtl(ColumnFamilyHandle* h, int32_t* ttl) override;
104+
103105
private:
104106
// remember whether the Close completes or not
105107
bool closed_;
@@ -184,6 +186,7 @@ class TtlCompactionFilterFactory : public CompactionFilterFactory {
184186
std::unique_ptr<CompactionFilter> CreateCompactionFilter(
185187
const CompactionFilter::Context& context) override;
186188
void SetTtl(int32_t ttl) { ttl_ = ttl; }
189+
int32_t GetTtl() { return ttl_; }
187190

188191
const char* Name() const override { return kClassName(); }
189192
static const char* kClassName() { return "TtlCompactionFilterFactory"; }

utilities/ttl/ttl_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,9 @@ TEST_F(TtlTest, ChangeTtlOnOpenDb) {
720720

721721
OpenTtl(1); // T=0:Open the db with ttl = 2
722722
SetTtl(3);
723+
int32_t ttl = 0;
724+
ASSERT_OK(db_ttl_->GetTtl(db_ttl_->DefaultColumnFamily(), &ttl));
725+
ASSERT_EQ(ttl, 3);
723726
PutValues(0, kSampleSize_); // T=0:Insert Set1. Delete at t=2
724727
SleepCompactCheck(2, 0, kSampleSize_, true); // T=2:Set1 should be there
725728
CloseTtl();

0 commit comments

Comments
 (0)