2019-04-18 17:51:19 +00:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
#include "utilities/ttl/db_ttl_impl.h"
|
|
|
|
|
2014-04-22 18:27:33 +00:00
|
|
|
#include "db/write_batch_internal.h"
|
2019-05-30 03:44:08 +00:00
|
|
|
#include "file/filename.h"
|
2021-09-29 11:01:57 +00:00
|
|
|
#include "logging/logging.h"
|
2015-07-15 21:51:51 +00:00
|
|
|
#include "rocksdb/convenience.h"
|
2014-04-29 03:34:20 +00:00
|
|
|
#include "rocksdb/env.h"
|
|
|
|
#include "rocksdb/iterator.h"
|
2021-03-15 11:32:24 +00:00
|
|
|
#include "rocksdb/system_clock.h"
|
2015-07-15 21:51:51 +00:00
|
|
|
#include "rocksdb/utilities/db_ttl.h"
|
2021-08-06 15:26:23 +00:00
|
|
|
#include "rocksdb/utilities/object_registry.h"
|
|
|
|
#include "rocksdb/utilities/options_type.h"
|
2015-07-15 21:51:51 +00:00
|
|
|
#include "util/coding.h"
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2021-08-06 15:26:23 +00:00
|
|
|
static std::unordered_map<std::string, OptionTypeInfo> ttl_merge_op_type_info =
|
2023-11-11 00:57:17 +00:00
|
|
|
{{"user_operator", OptionTypeInfo::AsCustomSharedPtr<MergeOperator>(
|
|
|
|
0, OptionVerificationType::kByNameAllowNull,
|
|
|
|
OptionTypeFlags::kNone)}};
|
2021-08-06 15:26:23 +00:00
|
|
|
|
|
|
|
TtlMergeOperator::TtlMergeOperator(
|
|
|
|
const std::shared_ptr<MergeOperator>& merge_op, SystemClock* clock)
|
|
|
|
: user_merge_op_(merge_op), clock_(clock) {
|
|
|
|
RegisterOptions("TtlMergeOptions", &user_merge_op_, &ttl_merge_op_type_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TtlMergeOperator::FullMergeV2(const MergeOperationInput& merge_in,
|
|
|
|
MergeOperationOutput* merge_out) const {
|
|
|
|
const uint32_t ts_len = DBWithTTLImpl::kTSLength;
|
|
|
|
if (merge_in.existing_value && merge_in.existing_value->size() < ts_len) {
|
|
|
|
ROCKS_LOG_ERROR(merge_in.logger,
|
|
|
|
"Error: Could not remove timestamp from existing value.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract time-stamp from each operand to be passed to user_merge_op_
|
|
|
|
std::vector<Slice> operands_without_ts;
|
|
|
|
for (const auto& operand : merge_in.operand_list) {
|
|
|
|
if (operand.size() < ts_len) {
|
|
|
|
ROCKS_LOG_ERROR(merge_in.logger,
|
|
|
|
"Error: Could not remove timestamp from operand value.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
operands_without_ts.push_back(operand);
|
|
|
|
operands_without_ts.back().remove_suffix(ts_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the user merge operator (store result in *new_value)
|
|
|
|
bool good = true;
|
|
|
|
MergeOperationOutput user_merge_out(merge_out->new_value,
|
|
|
|
merge_out->existing_operand);
|
|
|
|
if (merge_in.existing_value) {
|
|
|
|
Slice existing_value_without_ts(merge_in.existing_value->data(),
|
|
|
|
merge_in.existing_value->size() - ts_len);
|
|
|
|
good = user_merge_op_->FullMergeV2(
|
|
|
|
MergeOperationInput(merge_in.key, &existing_value_without_ts,
|
|
|
|
operands_without_ts, merge_in.logger),
|
|
|
|
&user_merge_out);
|
|
|
|
} else {
|
|
|
|
good = user_merge_op_->FullMergeV2(
|
|
|
|
MergeOperationInput(merge_in.key, nullptr, operands_without_ts,
|
|
|
|
merge_in.logger),
|
|
|
|
&user_merge_out);
|
|
|
|
}
|
Add API to limit blast radius of merge operator failure (#11092)
Summary:
Prior to this PR, `FullMergeV2()` can only return `false` to indicate failure, which causes any operation invoking it to fail. During a compaction, such a failure causes the compaction to fail and causes the DB to irreversibly enter read-only mode. Some users asked for a way to allow the merge operator to fail without such widespread damage.
To limit the blast radius of merge operator failures, this PR introduces the `MergeOperationOutput::op_failure_scope` API. When unpopulated (`kDefault`) or set to `kTryMerge`, the merge operator failure handling is the same as before. When set to `kMustMerge`, merge operator failure still causes failure to operations that must merge (`Get()`, iterator, `MultiGet()`, etc.). However, under `kMustMerge`, flushes/compactions can survive merge operator failures by outputting the unmerged input operands.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11092
Reviewed By: siying
Differential Revision: D42525673
Pulled By: ajkr
fbshipit-source-id: 951dc3bf190f86347dccf3381be967565cda52ee
2023-01-20 22:40:30 +00:00
|
|
|
merge_out->op_failure_scope = user_merge_out.op_failure_scope;
|
2021-08-06 15:26:23 +00:00
|
|
|
|
|
|
|
// Return false if the user merge operator returned false
|
|
|
|
if (!good) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (merge_out->existing_operand.data()) {
|
|
|
|
merge_out->new_value.assign(merge_out->existing_operand.data(),
|
|
|
|
merge_out->existing_operand.size());
|
|
|
|
merge_out->existing_operand = Slice(nullptr, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Augment the *new_value with the ttl time-stamp
|
|
|
|
int64_t curtime;
|
|
|
|
if (!clock_->GetCurrentTime(&curtime).ok()) {
|
|
|
|
ROCKS_LOG_ERROR(
|
|
|
|
merge_in.logger,
|
|
|
|
"Error: Could not get current time to be attached internally "
|
|
|
|
"to the new value.");
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
char ts_string[ts_len];
|
|
|
|
EncodeFixed32(ts_string, (int32_t)curtime);
|
|
|
|
merge_out->new_value.append(ts_string, ts_len);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TtlMergeOperator::PartialMergeMulti(const Slice& key,
|
|
|
|
const std::deque<Slice>& operand_list,
|
|
|
|
std::string* new_value,
|
|
|
|
Logger* logger) const {
|
|
|
|
const uint32_t ts_len = DBWithTTLImpl::kTSLength;
|
|
|
|
std::deque<Slice> operands_without_ts;
|
|
|
|
|
|
|
|
for (const auto& operand : operand_list) {
|
|
|
|
if (operand.size() < ts_len) {
|
|
|
|
ROCKS_LOG_ERROR(logger, "Error: Could not remove timestamp from value.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-03-04 18:08:32 +00:00
|
|
|
operands_without_ts.emplace_back(operand.data(), operand.size() - ts_len);
|
2021-08-06 15:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the user partial-merge operator (store result in *new_value)
|
|
|
|
assert(new_value);
|
|
|
|
if (!user_merge_op_->PartialMergeMulti(key, operands_without_ts, new_value,
|
|
|
|
logger)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Augment the *new_value with the ttl time-stamp
|
|
|
|
int64_t curtime;
|
|
|
|
if (!clock_->GetCurrentTime(&curtime).ok()) {
|
|
|
|
ROCKS_LOG_ERROR(
|
|
|
|
logger,
|
|
|
|
"Error: Could not get current time to be attached internally "
|
|
|
|
"to the new value.");
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
char ts_string[ts_len];
|
|
|
|
EncodeFixed32(ts_string, (int32_t)curtime);
|
|
|
|
new_value->append(ts_string, ts_len);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status TtlMergeOperator::PrepareOptions(const ConfigOptions& config_options) {
|
|
|
|
if (clock_ == nullptr) {
|
|
|
|
clock_ = config_options.env->GetSystemClock().get();
|
|
|
|
}
|
|
|
|
return MergeOperator::PrepareOptions(config_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status TtlMergeOperator::ValidateOptions(
|
|
|
|
const DBOptions& db_opts, const ColumnFamilyOptions& cf_opts) const {
|
|
|
|
if (user_merge_op_ == nullptr) {
|
|
|
|
return Status::InvalidArgument(
|
|
|
|
"UserMergeOperator required by TtlMergeOperator");
|
|
|
|
} else if (clock_ == nullptr) {
|
|
|
|
return Status::InvalidArgument("SystemClock required by TtlMergeOperator");
|
|
|
|
} else {
|
|
|
|
return MergeOperator::ValidateOptions(db_opts, cf_opts);
|
|
|
|
}
|
|
|
|
}
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
|
2014-05-02 14:13:51 +00:00
|
|
|
void DBWithTTLImpl::SanitizeOptions(int32_t ttl, ColumnFamilyOptions* options,
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock) {
|
2013-12-07 00:10:43 +00:00
|
|
|
if (options->compaction_filter) {
|
|
|
|
options->compaction_filter =
|
2021-03-15 11:32:24 +00:00
|
|
|
new TtlCompactionFilter(ttl, clock, options->compaction_filter);
|
2013-08-13 17:56:20 +00:00
|
|
|
} else {
|
2013-12-07 00:10:43 +00:00
|
|
|
options->compaction_filter_factory =
|
|
|
|
std::shared_ptr<CompactionFilterFactory>(new TtlCompactionFilterFactory(
|
2021-03-15 11:32:24 +00:00
|
|
|
ttl, clock, options->compaction_filter_factory));
|
2013-08-13 17:56:20 +00:00
|
|
|
}
|
2013-08-03 07:40:22 +00:00
|
|
|
|
2013-12-07 00:10:43 +00:00
|
|
|
if (options->merge_operator) {
|
|
|
|
options->merge_operator.reset(
|
2021-03-15 11:32:24 +00:00
|
|
|
new TtlMergeOperator(options->merge_operator, clock));
|
2013-05-10 21:19:47 +00:00
|
|
|
}
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 15:26:23 +00:00
|
|
|
static std::unordered_map<std::string, OptionTypeInfo> ttl_type_info = {
|
|
|
|
{"ttl", {0, OptionType::kInt32T}},
|
|
|
|
};
|
|
|
|
|
|
|
|
static std::unordered_map<std::string, OptionTypeInfo> ttl_cff_type_info = {
|
|
|
|
{"user_filter_factory",
|
|
|
|
OptionTypeInfo::AsCustomSharedPtr<CompactionFilterFactory>(
|
|
|
|
0, OptionVerificationType::kByNameAllowFromNull,
|
|
|
|
OptionTypeFlags::kNone)}};
|
|
|
|
static std::unordered_map<std::string, OptionTypeInfo> user_cf_type_info = {
|
|
|
|
{"user_filter",
|
|
|
|
OptionTypeInfo::AsCustomRawPtr<const CompactionFilter>(
|
|
|
|
0, OptionVerificationType::kByName, OptionTypeFlags::kAllowNull)}};
|
|
|
|
|
|
|
|
TtlCompactionFilter::TtlCompactionFilter(
|
|
|
|
int32_t ttl, SystemClock* clock, const CompactionFilter* _user_comp_filter,
|
|
|
|
std::unique_ptr<const CompactionFilter> _user_comp_filter_from_factory)
|
|
|
|
: LayeredCompactionFilterBase(_user_comp_filter,
|
|
|
|
std::move(_user_comp_filter_from_factory)),
|
|
|
|
ttl_(ttl),
|
|
|
|
clock_(clock) {
|
|
|
|
RegisterOptions("TTL", &ttl_, &ttl_type_info);
|
|
|
|
RegisterOptions("UserFilter", &user_comp_filter_, &user_cf_type_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TtlCompactionFilter::Filter(int level, const Slice& key,
|
|
|
|
const Slice& old_val, std::string* new_val,
|
|
|
|
bool* value_changed) const {
|
|
|
|
if (DBWithTTLImpl::IsStale(old_val, ttl_, clock_)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (user_comp_filter() == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
assert(old_val.size() >= DBWithTTLImpl::kTSLength);
|
|
|
|
Slice old_val_without_ts(old_val.data(),
|
|
|
|
old_val.size() - DBWithTTLImpl::kTSLength);
|
|
|
|
if (user_comp_filter()->Filter(level, key, old_val_without_ts, new_val,
|
|
|
|
value_changed)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (*value_changed) {
|
|
|
|
new_val->append(old_val.data() + old_val.size() - DBWithTTLImpl::kTSLength,
|
|
|
|
DBWithTTLImpl::kTSLength);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status TtlCompactionFilter::PrepareOptions(
|
|
|
|
const ConfigOptions& config_options) {
|
|
|
|
if (clock_ == nullptr) {
|
|
|
|
clock_ = config_options.env->GetSystemClock().get();
|
|
|
|
}
|
|
|
|
return LayeredCompactionFilterBase::PrepareOptions(config_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status TtlCompactionFilter::ValidateOptions(
|
|
|
|
const DBOptions& db_opts, const ColumnFamilyOptions& cf_opts) const {
|
|
|
|
if (clock_ == nullptr) {
|
|
|
|
return Status::InvalidArgument(
|
|
|
|
"SystemClock required by TtlCompactionFilter");
|
|
|
|
} else {
|
|
|
|
return LayeredCompactionFilterBase::ValidateOptions(db_opts, cf_opts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TtlCompactionFilterFactory::TtlCompactionFilterFactory(
|
|
|
|
int32_t ttl, SystemClock* clock,
|
|
|
|
std::shared_ptr<CompactionFilterFactory> comp_filter_factory)
|
|
|
|
: ttl_(ttl), clock_(clock), user_comp_filter_factory_(comp_filter_factory) {
|
|
|
|
RegisterOptions("UserOptions", &user_comp_filter_factory_,
|
|
|
|
&ttl_cff_type_info);
|
|
|
|
RegisterOptions("TTL", &ttl_, &ttl_type_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CompactionFilter>
|
|
|
|
TtlCompactionFilterFactory::CreateCompactionFilter(
|
|
|
|
const CompactionFilter::Context& context) {
|
|
|
|
std::unique_ptr<const CompactionFilter> user_comp_filter_from_factory =
|
|
|
|
nullptr;
|
|
|
|
if (user_comp_filter_factory_) {
|
|
|
|
user_comp_filter_from_factory =
|
|
|
|
user_comp_filter_factory_->CreateCompactionFilter(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::unique_ptr<TtlCompactionFilter>(new TtlCompactionFilter(
|
|
|
|
ttl_, clock_, nullptr, std::move(user_comp_filter_from_factory)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Status TtlCompactionFilterFactory::PrepareOptions(
|
|
|
|
const ConfigOptions& config_options) {
|
|
|
|
if (clock_ == nullptr) {
|
|
|
|
clock_ = config_options.env->GetSystemClock().get();
|
|
|
|
}
|
|
|
|
return CompactionFilterFactory::PrepareOptions(config_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status TtlCompactionFilterFactory::ValidateOptions(
|
|
|
|
const DBOptions& db_opts, const ColumnFamilyOptions& cf_opts) const {
|
|
|
|
if (clock_ == nullptr) {
|
|
|
|
return Status::InvalidArgument(
|
|
|
|
"SystemClock required by TtlCompactionFilterFactory");
|
|
|
|
} else {
|
|
|
|
return CompactionFilterFactory::ValidateOptions(db_opts, cf_opts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int RegisterTtlObjects(ObjectLibrary& library, const std::string& /*arg*/) {
|
2022-01-11 14:32:42 +00:00
|
|
|
library.AddFactory<MergeOperator>(
|
2021-08-06 15:26:23 +00:00
|
|
|
TtlMergeOperator::kClassName(),
|
|
|
|
[](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard,
|
|
|
|
std::string* /* errmsg */) {
|
|
|
|
guard->reset(new TtlMergeOperator(nullptr, nullptr));
|
|
|
|
return guard->get();
|
|
|
|
});
|
2022-01-11 14:32:42 +00:00
|
|
|
library.AddFactory<CompactionFilterFactory>(
|
2021-08-06 15:26:23 +00:00
|
|
|
TtlCompactionFilterFactory::kClassName(),
|
|
|
|
[](const std::string& /*uri*/,
|
|
|
|
std::unique_ptr<CompactionFilterFactory>* guard,
|
|
|
|
std::string* /* errmsg */) {
|
|
|
|
guard->reset(new TtlCompactionFilterFactory(0, nullptr, nullptr));
|
|
|
|
return guard->get();
|
|
|
|
});
|
2022-01-11 14:32:42 +00:00
|
|
|
library.AddFactory<CompactionFilter>(
|
2021-08-06 15:26:23 +00:00
|
|
|
TtlCompactionFilter::kClassName(),
|
|
|
|
[](const std::string& /*uri*/,
|
|
|
|
std::unique_ptr<CompactionFilter>* /*guard*/,
|
|
|
|
std::string* /* errmsg */) {
|
|
|
|
return new TtlCompactionFilter(0, nullptr, nullptr);
|
|
|
|
});
|
|
|
|
size_t num_types;
|
|
|
|
return static_cast<int>(library.GetFactoryCount(&num_types));
|
|
|
|
}
|
2014-04-29 03:34:20 +00:00
|
|
|
// Open the db inside DBWithTTLImpl because options needs pointer to its ttl
|
2019-06-20 20:04:13 +00:00
|
|
|
DBWithTTLImpl::DBWithTTLImpl(DB* db) : DBWithTTL(db), closed_(false) {}
|
2014-04-29 03:34:20 +00:00
|
|
|
|
2015-05-05 23:54:47 +00:00
|
|
|
DBWithTTLImpl::~DBWithTTLImpl() {
|
2019-06-20 20:04:13 +00:00
|
|
|
if (!closed_) {
|
2020-12-22 23:08:17 +00:00
|
|
|
Close().PermitUncheckedError();
|
2019-06-20 20:04:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DBWithTTLImpl::Close() {
|
|
|
|
Status ret = Status::OK();
|
|
|
|
if (!closed_) {
|
|
|
|
Options default_options = GetOptions();
|
|
|
|
// Need to stop background compaction before getting rid of the filter
|
|
|
|
CancelAllBackgroundWork(db_, /* wait = */ true);
|
|
|
|
ret = db_->Close();
|
|
|
|
delete default_options.compaction_filter;
|
|
|
|
closed_ = true;
|
|
|
|
}
|
|
|
|
return ret;
|
2015-05-05 23:54:47 +00:00
|
|
|
}
|
2013-12-07 00:10:43 +00:00
|
|
|
|
2021-08-06 15:26:23 +00:00
|
|
|
void DBWithTTLImpl::RegisterTtlClasses() {
|
|
|
|
static std::once_flag once;
|
|
|
|
std::call_once(once, [&]() {
|
|
|
|
ObjectRegistry::Default()->AddLibrary("TTL", RegisterTtlObjects, "");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
Status DBWithTTL::Open(const Options& options, const std::string& dbname,
|
|
|
|
DBWithTTL** dbptr, int32_t ttl, bool read_only) {
|
2014-04-22 18:27:33 +00:00
|
|
|
DBOptions db_options(options);
|
|
|
|
ColumnFamilyOptions cf_options(options);
|
|
|
|
std::vector<ColumnFamilyDescriptor> column_families;
|
2024-03-04 18:08:32 +00:00
|
|
|
column_families.emplace_back(kDefaultColumnFamilyName, cf_options);
|
2014-04-22 18:27:33 +00:00
|
|
|
std::vector<ColumnFamilyHandle*> handles;
|
2014-04-29 03:34:20 +00:00
|
|
|
Status s = DBWithTTL::Open(db_options, dbname, column_families, &handles,
|
|
|
|
dbptr, {ttl}, read_only);
|
2014-04-22 18:27:33 +00:00
|
|
|
if (s.ok()) {
|
|
|
|
assert(handles.size() == 1);
|
|
|
|
// i can delete the handle since DBImpl is always holding a reference to
|
|
|
|
// default column family
|
|
|
|
delete handles[0];
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
Status DBWithTTL::Open(
|
2014-04-22 18:27:33 +00:00
|
|
|
const DBOptions& db_options, const std::string& dbname,
|
|
|
|
const std::vector<ColumnFamilyDescriptor>& column_families,
|
2014-04-29 03:34:20 +00:00
|
|
|
std::vector<ColumnFamilyHandle*>* handles, DBWithTTL** dbptr,
|
2020-08-24 23:22:50 +00:00
|
|
|
const std::vector<int32_t>& ttls, bool read_only) {
|
2021-08-06 15:26:23 +00:00
|
|
|
DBWithTTLImpl::RegisterTtlClasses();
|
2014-04-22 18:27:33 +00:00
|
|
|
if (ttls.size() != column_families.size()) {
|
|
|
|
return Status::InvalidArgument(
|
|
|
|
"ttls size has to be the same as number of column families");
|
|
|
|
}
|
|
|
|
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock = (db_options.env == nullptr)
|
|
|
|
? SystemClock::Default().get()
|
|
|
|
: db_options.env->GetSystemClock().get();
|
|
|
|
|
2014-04-22 18:27:33 +00:00
|
|
|
std::vector<ColumnFamilyDescriptor> column_families_sanitized =
|
|
|
|
column_families;
|
|
|
|
for (size_t i = 0; i < column_families_sanitized.size(); ++i) {
|
2014-05-02 14:13:51 +00:00
|
|
|
DBWithTTLImpl::SanitizeOptions(
|
2021-03-15 11:32:24 +00:00
|
|
|
ttls[i], &column_families_sanitized[i].options, clock);
|
2014-04-22 18:27:33 +00:00
|
|
|
}
|
2013-12-07 00:10:43 +00:00
|
|
|
DB* db;
|
|
|
|
|
2014-04-22 18:27:33 +00:00
|
|
|
Status st;
|
2013-12-07 00:10:43 +00:00
|
|
|
if (read_only) {
|
2014-04-22 18:27:33 +00:00
|
|
|
st = DB::OpenForReadOnly(db_options, dbname, column_families_sanitized,
|
|
|
|
handles, &db);
|
2013-12-07 00:10:43 +00:00
|
|
|
} else {
|
2014-04-22 18:27:33 +00:00
|
|
|
st = DB::Open(db_options, dbname, column_families_sanitized, handles, &db);
|
2013-12-07 00:10:43 +00:00
|
|
|
}
|
|
|
|
if (st.ok()) {
|
2014-04-29 03:34:20 +00:00
|
|
|
*dbptr = new DBWithTTLImpl(db);
|
2013-12-07 00:10:43 +00:00
|
|
|
} else {
|
2014-04-22 18:27:33 +00:00
|
|
|
*dbptr = nullptr;
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
}
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
Status DBWithTTLImpl::CreateColumnFamilyWithTtl(
|
|
|
|
const ColumnFamilyOptions& options, const std::string& column_family_name,
|
|
|
|
ColumnFamilyHandle** handle, int ttl) {
|
2021-08-06 15:26:23 +00:00
|
|
|
RegisterTtlClasses();
|
2014-04-29 03:34:20 +00:00
|
|
|
ColumnFamilyOptions sanitized_options = options;
|
2021-03-15 11:32:24 +00:00
|
|
|
DBWithTTLImpl::SanitizeOptions(ttl, &sanitized_options,
|
|
|
|
GetEnv()->GetSystemClock().get());
|
2014-04-29 03:34:20 +00:00
|
|
|
|
|
|
|
return DBWithTTL::CreateColumnFamily(sanitized_options, column_family_name,
|
|
|
|
handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DBWithTTLImpl::CreateColumnFamily(const ColumnFamilyOptions& options,
|
|
|
|
const std::string& column_family_name,
|
|
|
|
ColumnFamilyHandle** handle) {
|
|
|
|
return CreateColumnFamilyWithTtl(options, column_family_name, handle, 0);
|
|
|
|
}
|
|
|
|
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
// Appends the current timestamp to the string.
|
|
|
|
// Returns false if could not get the current_time, true if append succeeds
|
2014-05-02 14:13:51 +00:00
|
|
|
Status DBWithTTLImpl::AppendTS(const Slice& val, std::string* val_with_ts,
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock) {
|
2014-04-29 03:34:20 +00:00
|
|
|
val_with_ts->reserve(kTSLength + val.size());
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
char ts_string[kTSLength];
|
2013-11-19 04:56:21 +00:00
|
|
|
int64_t curtime;
|
2021-03-15 11:32:24 +00:00
|
|
|
Status st = clock->GetCurrentTime(&curtime);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
if (!st.ok()) {
|
|
|
|
return st;
|
|
|
|
}
|
2013-11-19 04:56:21 +00:00
|
|
|
EncodeFixed32(ts_string, (int32_t)curtime);
|
2014-04-29 03:34:20 +00:00
|
|
|
val_with_ts->append(val.data(), val.size());
|
|
|
|
val_with_ts->append(ts_string, kTSLength);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2013-05-10 00:33:27 +00:00
|
|
|
// Returns corruption if the length of the string is lesser than timestamp, or
|
|
|
|
// timestamp refers to a time lesser than ttl-feature release time
|
2014-04-29 03:34:20 +00:00
|
|
|
Status DBWithTTLImpl::SanityCheckTimestamp(const Slice& str) {
|
2013-08-03 07:40:22 +00:00
|
|
|
if (str.size() < kTSLength) {
|
2013-05-10 00:33:27 +00:00
|
|
|
return Status::Corruption("Error: value's length less than timestamp's\n");
|
|
|
|
}
|
|
|
|
// Checks that TS is not lesser than kMinTimestamp
|
|
|
|
// Gaurds against corruption & normal database opened incorrectly in ttl mode
|
2014-04-29 03:34:20 +00:00
|
|
|
int32_t timestamp_value = DecodeFixed32(str.data() + str.size() - kTSLength);
|
|
|
|
if (timestamp_value < kMinTimestamp) {
|
2013-05-10 00:33:27 +00:00
|
|
|
return Status::Corruption("Error: Timestamp < ttl feature release time!\n");
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
// Checks if the string is stale or not according to TTl provided
|
2021-03-15 11:32:24 +00:00
|
|
|
bool DBWithTTLImpl::IsStale(const Slice& value, int32_t ttl,
|
|
|
|
SystemClock* clock) {
|
2014-04-29 03:34:20 +00:00
|
|
|
if (ttl <= 0) { // Data is fresh if TTL is non-positive
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-11-19 04:56:21 +00:00
|
|
|
int64_t curtime;
|
2021-03-15 11:32:24 +00:00
|
|
|
if (!clock->GetCurrentTime(&curtime).ok()) {
|
2014-04-29 03:34:20 +00:00
|
|
|
return false; // Treat the data as fresh if could not get current time
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
}
|
2023-03-09 21:11:25 +00:00
|
|
|
/* int32_t may overflow when timestamp_value + ttl
|
|
|
|
* for example ttl = 86400 * 365 * 15
|
|
|
|
* convert timestamp_value to int64_t
|
|
|
|
*/
|
|
|
|
int64_t timestamp_value =
|
2014-04-29 03:34:20 +00:00
|
|
|
DecodeFixed32(value.data() + value.size() - kTSLength);
|
2013-08-03 07:40:22 +00:00
|
|
|
return (timestamp_value + ttl) < curtime;
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
}
|
|
|
|
|
2017-03-13 18:44:50 +00:00
|
|
|
// Strips the TS from the end of the slice
|
|
|
|
Status DBWithTTLImpl::StripTS(PinnableSlice* pinnable_val) {
|
|
|
|
if (pinnable_val->size() < kTSLength) {
|
|
|
|
return Status::Corruption("Bad timestamp in key-value");
|
|
|
|
}
|
|
|
|
// Erasing characters which hold the TS
|
|
|
|
pinnable_val->remove_suffix(kTSLength);
|
2020-12-22 23:08:17 +00:00
|
|
|
return Status::OK();
|
2017-03-13 18:44:50 +00:00
|
|
|
}
|
|
|
|
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
// Strips the TS from the end of the string
|
2014-04-29 03:34:20 +00:00
|
|
|
Status DBWithTTLImpl::StripTS(std::string* str) {
|
2013-08-03 07:40:22 +00:00
|
|
|
if (str->length() < kTSLength) {
|
|
|
|
return Status::Corruption("Bad timestamp in key-value");
|
|
|
|
}
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
// Erasing characters which hold the TS
|
|
|
|
str->erase(str->length() - kTSLength, kTSLength);
|
2020-12-22 23:08:17 +00:00
|
|
|
return Status::OK();
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
}
|
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
Status DBWithTTLImpl::Put(const WriteOptions& options,
|
|
|
|
ColumnFamilyHandle* column_family, const Slice& key,
|
|
|
|
const Slice& val) {
|
2013-07-22 23:49:55 +00:00
|
|
|
WriteBatch batch;
|
2020-12-22 23:08:17 +00:00
|
|
|
Status st = batch.Put(column_family, key, val);
|
2020-12-23 07:44:44 +00:00
|
|
|
if (st.ok()) {
|
|
|
|
st = Write(options, &batch);
|
2020-12-22 23:08:17 +00:00
|
|
|
}
|
2020-12-23 07:44:44 +00:00
|
|
|
return st;
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
}
|
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
Status DBWithTTLImpl::Get(const ReadOptions& options,
|
|
|
|
ColumnFamilyHandle* column_family, const Slice& key,
|
2024-02-16 17:21:06 +00:00
|
|
|
PinnableSlice* value, std::string* timestamp) {
|
|
|
|
if (timestamp) {
|
|
|
|
return Status::NotSupported(
|
|
|
|
"Get() that returns timestamp is not supported");
|
|
|
|
}
|
2017-01-08 22:08:51 +00:00
|
|
|
Status st = db_->Get(options, column_family, key, value);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
if (!st.ok()) {
|
|
|
|
return st;
|
|
|
|
}
|
2017-01-08 22:08:51 +00:00
|
|
|
st = SanityCheckTimestamp(*value);
|
2013-05-10 00:33:27 +00:00
|
|
|
if (!st.ok()) {
|
|
|
|
return st;
|
|
|
|
}
|
2017-01-08 22:08:51 +00:00
|
|
|
return StripTS(value);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 17:21:06 +00:00
|
|
|
void DBWithTTLImpl::MultiGet(const ReadOptions& options, const size_t num_keys,
|
|
|
|
ColumnFamilyHandle** column_families,
|
|
|
|
const Slice* keys, PinnableSlice* values,
|
|
|
|
std::string* timestamps, Status* statuses,
|
|
|
|
const bool /*sorted_input*/) {
|
|
|
|
if (timestamps) {
|
|
|
|
for (size_t i = 0; i < num_keys; ++i) {
|
|
|
|
statuses[i] = Status::NotSupported(
|
|
|
|
"MultiGet() returning timestamps not implemented.");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
db_->MultiGet(options, num_keys, column_families, keys, values, timestamps,
|
|
|
|
statuses);
|
|
|
|
for (size_t i = 0; i < num_keys; ++i) {
|
2014-12-20 11:46:37 +00:00
|
|
|
if (!statuses[i].ok()) {
|
|
|
|
continue;
|
|
|
|
}
|
2024-02-16 17:21:06 +00:00
|
|
|
PinnableSlice tmp_val = std::move(values[i]);
|
|
|
|
values[i].PinSelf(tmp_val);
|
|
|
|
assert(!values[i].IsPinned());
|
|
|
|
statuses[i] = SanityCheckTimestamp(values[i]);
|
2014-12-20 11:46:37 +00:00
|
|
|
if (!statuses[i].ok()) {
|
|
|
|
continue;
|
|
|
|
}
|
2024-02-16 17:21:06 +00:00
|
|
|
statuses[i] = StripTS(&values[i]);
|
2014-12-20 11:46:37 +00:00
|
|
|
}
|
2013-06-05 18:22:38 +00:00
|
|
|
}
|
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
bool DBWithTTLImpl::KeyMayExist(const ReadOptions& options,
|
|
|
|
ColumnFamilyHandle* column_family,
|
|
|
|
const Slice& key, std::string* value,
|
|
|
|
bool* value_found) {
|
2014-04-22 18:27:33 +00:00
|
|
|
bool ret = db_->KeyMayExist(options, column_family, key, value, value_found);
|
2013-08-24 00:36:00 +00:00
|
|
|
if (ret && value != nullptr && value_found != nullptr && *value_found) {
|
|
|
|
if (!SanityCheckTimestamp(*value).ok() || !StripTS(value).ok()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2013-07-06 01:49:18 +00:00
|
|
|
}
|
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
Status DBWithTTLImpl::Merge(const WriteOptions& options,
|
|
|
|
ColumnFamilyHandle* column_family, const Slice& key,
|
|
|
|
const Slice& value) {
|
2013-07-22 23:49:55 +00:00
|
|
|
WriteBatch batch;
|
2020-12-22 23:08:17 +00:00
|
|
|
Status st = batch.Merge(column_family, key, value);
|
2020-12-23 07:44:44 +00:00
|
|
|
if (st.ok()) {
|
|
|
|
st = Write(options, &batch);
|
2020-12-22 23:08:17 +00:00
|
|
|
}
|
2020-12-23 07:44:44 +00:00
|
|
|
return st;
|
2013-03-21 22:59:47 +00:00
|
|
|
}
|
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
Status DBWithTTLImpl::Write(const WriteOptions& opts, WriteBatch* updates) {
|
2013-05-15 22:00:57 +00:00
|
|
|
class Handler : public WriteBatch::Handler {
|
|
|
|
public:
|
2021-03-15 11:32:24 +00:00
|
|
|
explicit Handler(SystemClock* clock) : clock_(clock) {}
|
2013-05-15 22:00:57 +00:00
|
|
|
WriteBatch updates_ttl;
|
2019-02-14 21:52:47 +00:00
|
|
|
Status PutCF(uint32_t column_family_id, const Slice& key,
|
|
|
|
const Slice& value) override {
|
2013-05-15 22:00:57 +00:00
|
|
|
std::string value_with_ts;
|
2021-03-15 11:32:24 +00:00
|
|
|
Status st = AppendTS(value, &value_with_ts, clock_);
|
2013-05-15 22:00:57 +00:00
|
|
|
if (!st.ok()) {
|
2020-12-22 23:08:17 +00:00
|
|
|
return st;
|
2013-05-15 22:00:57 +00:00
|
|
|
}
|
2020-12-22 23:08:17 +00:00
|
|
|
return WriteBatchInternal::Put(&updates_ttl, column_family_id, key,
|
|
|
|
value_with_ts);
|
2013-05-15 22:00:57 +00:00
|
|
|
}
|
2019-02-14 21:52:47 +00:00
|
|
|
Status MergeCF(uint32_t column_family_id, const Slice& key,
|
|
|
|
const Slice& value) override {
|
2013-07-22 23:49:55 +00:00
|
|
|
std::string value_with_ts;
|
2021-03-15 11:32:24 +00:00
|
|
|
Status st = AppendTS(value, &value_with_ts, clock_);
|
2013-07-22 23:49:55 +00:00
|
|
|
if (!st.ok()) {
|
2020-12-22 23:08:17 +00:00
|
|
|
return st;
|
2013-07-22 23:49:55 +00:00
|
|
|
}
|
2020-12-22 23:08:17 +00:00
|
|
|
return WriteBatchInternal::Merge(&updates_ttl, column_family_id, key,
|
|
|
|
value_with_ts);
|
2013-05-15 22:00:57 +00:00
|
|
|
}
|
2019-02-14 21:52:47 +00:00
|
|
|
Status DeleteCF(uint32_t column_family_id, const Slice& key) override {
|
2020-12-22 23:08:17 +00:00
|
|
|
return WriteBatchInternal::Delete(&updates_ttl, column_family_id, key);
|
2013-05-15 22:00:57 +00:00
|
|
|
}
|
2021-06-17 22:59:53 +00:00
|
|
|
Status DeleteRangeCF(uint32_t column_family_id, const Slice& begin_key,
|
|
|
|
const Slice& end_key) override {
|
|
|
|
return WriteBatchInternal::DeleteRange(&updates_ttl, column_family_id,
|
|
|
|
begin_key, end_key);
|
|
|
|
}
|
2019-02-14 21:52:47 +00:00
|
|
|
void LogData(const Slice& blob) override { updates_ttl.PutLogData(blob); }
|
2014-05-02 14:13:51 +00:00
|
|
|
|
|
|
|
private:
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock_;
|
2013-05-15 22:00:57 +00:00
|
|
|
};
|
2021-03-15 11:32:24 +00:00
|
|
|
Handler handler(GetEnv()->GetSystemClock().get());
|
2020-12-22 23:08:17 +00:00
|
|
|
Status st = updates->Iterate(&handler);
|
|
|
|
if (!st.ok()) {
|
|
|
|
return st;
|
2013-05-15 22:00:57 +00:00
|
|
|
} else {
|
|
|
|
return db_->Write(opts, &(handler.updates_ttl));
|
|
|
|
}
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
}
|
|
|
|
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
Iterator* DBWithTTLImpl::NewIterator(const ReadOptions& _read_options,
|
2014-04-29 03:34:20 +00:00
|
|
|
ColumnFamilyHandle* column_family) {
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
if (_read_options.io_activity != Env::IOActivity::kUnknown &&
|
|
|
|
_read_options.io_activity != Env::IOActivity::kDBIterator) {
|
2023-04-21 16:07:18 +00:00
|
|
|
return NewErrorIterator(Status::InvalidArgument(
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
"Can only call NewIterator with `ReadOptions::io_activity` is "
|
|
|
|
"`Env::IOActivity::kUnknown` or `Env::IOActivity::kDBIterator`"));
|
2023-04-21 16:07:18 +00:00
|
|
|
}
|
Group rocksdb.sst.read.micros stat by different user read IOActivity + misc (#11444)
Summary:
**Context/Summary:**
- Similar to https://github.com/facebook/rocksdb/pull/11288 but for user read such as `Get(), MultiGet(), DBIterator::XXX(), Verify(File)Checksum()`.
- For this, I refactored some user-facing `MultiGet` calls in `TransactionBase` and various types of `DB` so that it does not call a user-facing `Get()` but `GetImpl()` for passing the `ReadOptions::io_activity` check (see PR conversation)
- New user read stats breakdown are guarded by `kExceptDetailedTimers` since measurement shows they have 4-5% regression to the upstream/main.
- Misc
- More refactoring: with https://github.com/facebook/rocksdb/pull/11288, we complete passing `ReadOptions/IOOptions` to FS level. So we can now replace the previously [added](https://github.com/facebook/rocksdb/pull/9424) `rate_limiter_priority` parameter in `RandomAccessFileReader`'s `Read/MultiRead/Prefetch()` with `IOOptions::rate_limiter_priority`
- Also, `ReadAsync()` call time is measured in `SST_READ_MICRO` now
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11444
Test Plan:
- CI fake db crash/stress test
- Microbenchmarking
**Build** `make clean && ROCKSDB_NO_FBCODE=1 DEBUG_LEVEL=0 make -jN db_basic_bench`
- google benchmark version: https://github.com/google/benchmark/commit/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd
- db_basic_bench_base: upstream
- db_basic_bench_pr: db_basic_bench_base + this PR
- asyncread_db_basic_bench_base: upstream + [db basic bench patch for IteratorNext](https://github.com/facebook/rocksdb/compare/main...hx235:rocksdb:micro_bench_async_read)
- asyncread_db_basic_bench_pr: asyncread_db_basic_bench_base + this PR
**Test**
Get
```
TEST_TMPDIR=/dev/shm ./db_basic_bench_{null_stat|base|pr} --benchmark_filter=DBGet/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/negative_query:0/enable_filter:0/mmap:1/threads:1 --benchmark_repetitions=1000
```
Result
```
Coming soon
```
AsyncRead
```
TEST_TMPDIR=/dev/shm ./asyncread_db_basic_bench_{base|pr} --benchmark_filter=IteratorNext/comp_style:0/max_data:134217728/per_key_size:256/enable_statistics:1/async_io:1/include_detailed_timers:0 --benchmark_repetitions=1000 > syncread_db_basic_bench_{base|pr}.out
```
Result
```
Base:
1956,1956,1968,1977,1979,1986,1988,1988,1988,1990,1991,1991,1993,1993,1993,1993,1994,1996,1997,1997,1997,1998,1999,2001,2001,2002,2004,2007,2007,2008,
PR (2.3% regression, due to measuring `SST_READ_MICRO` that wasn't measured before):
1993,2014,2016,2022,2024,2027,2027,2028,2028,2030,2031,2031,2032,2032,2038,2039,2042,2044,2044,2047,2047,2047,2048,2049,2050,2052,2052,2052,2053,2053,
```
Reviewed By: ajkr
Differential Revision: D45918925
Pulled By: hx235
fbshipit-source-id: 58a54560d9ebeb3a59b6d807639692614dad058a
2023-08-09 00:26:50 +00:00
|
|
|
ReadOptions read_options(_read_options);
|
|
|
|
if (read_options.io_activity == Env::IOActivity::kUnknown) {
|
|
|
|
read_options.io_activity = Env::IOActivity::kDBIterator;
|
|
|
|
}
|
|
|
|
return new TtlIterator(db_->NewIterator(read_options, column_family));
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 20:33:13 +00:00
|
|
|
}
|
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
void DBWithTTLImpl::SetTtl(ColumnFamilyHandle* h, int32_t ttl) {
|
2018-01-18 18:41:26 +00:00
|
|
|
std::shared_ptr<TtlCompactionFilterFactory> filter;
|
|
|
|
Options opts;
|
|
|
|
opts = GetOptions(h);
|
|
|
|
filter = std::static_pointer_cast<TtlCompactionFilterFactory>(
|
2022-10-24 23:38:09 +00:00
|
|
|
opts.compaction_filter_factory);
|
2024-03-04 18:08:32 +00:00
|
|
|
if (!filter) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-18 18:41:26 +00:00
|
|
|
filter->SetTtl(ttl);
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|