Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Or Friedmann committed Apr 2, 2023
1 parent d692714 commit 9460180
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 65 deletions.
2 changes: 1 addition & 1 deletion db_stress_tool/db_stress_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ void StressTest::OperateDb(ThreadState* thread) {
read_opts.adaptive_readahead = FLAGS_adaptive_readahead;
read_opts.readahead_size = FLAGS_readahead_size;
if (gflags::GetCommandLineFlagInfoOrDie("ttl").is_default &&
FLAGS_skip_expired_data) {
FLAGS_skip_expired_data && FLAGS_ttl < 1) {
auto error_msg =
IOStatus::InvalidArgument("skip_expired_data must be set with ttl");
}
Expand Down
4 changes: 4 additions & 0 deletions gmock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Makefile:171: Warning: Compiling in debug mode. Don't use the resulting binary in production
Makefile:171: Warning: Compiling in debug mode. Don't use the resulting binary in production
/usr/bin/ar: creating libspeedb_test_debug.a
/usr/bin/ar: creating libspeedb_debug.a
Binary file added mono_crash.mem.51841.1.blob
Binary file not shown.
17 changes: 11 additions & 6 deletions utilities/ttl/db_ttl_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ Status DBWithTTLImpl::SanityCheckTimestamp(const Slice& str) {
}

// Checks if the string is stale or not according to TTl provided
// Generic IsStale implementation
bool DBWithTTLImpl::IsStale(const Slice& value, int32_t ttl,
SystemClock* clock) {
if (ttl <= 0) { // Data is fresh if TTL is non-positive
Expand All @@ -457,13 +458,16 @@ bool DBWithTTLImpl::IsStale(const Slice& value, int32_t ttl,
}

// IsStale for strict ttl
bool DBWithTTLImpl::IsStale(const Slice& value,
ColumnFamilyHandle* column_family,
const ReadOptions& options) {
bool DBWithTTLImpl::IsStaleStrictTtl(const Slice& value,
ColumnFamilyHandle* column_family,
const ReadOptions& options) {
Options opts = GetOptions(column_family);
auto filter = std::static_pointer_cast<TtlCompactionFilterFactory>(
opts.compaction_filter_factory);
int32_t ttl = filter->GetTtl();
if (ttl <= 0) {
return false;
}
if (options.snapshot == nullptr) {
SystemClock* clock = (opts.env == nullptr)
? SystemClock::Default().get()
Expand Down Expand Up @@ -520,7 +524,7 @@ Status DBWithTTLImpl::Get(const ReadOptions& options,
return st;
}
if (options.skip_expired_data) {
if (IsStale(*value, column_family, options)) {
if (IsStaleStrictTtl(*value, column_family, options)) {
return Status::NotFound();
}
}
Expand All @@ -540,10 +544,11 @@ std::vector<Status> DBWithTTLImpl::MultiGet(
if (!statuses[i].ok()) {
continue;
}
// check if the key has been expired if is_stale == true it's expired
// re-check if the key expired for each key requested by the multiget
bool is_stale = false;
if (options.skip_expired_data) {
is_stale = false;
if (IsStale((*values)[i], column_family[i], options)) {
if (IsStaleStrictTtl((*values)[i], column_family[i], options)) {
statuses[i] = Status::NotFound();
is_stale = true;
}
Expand Down
4 changes: 2 additions & 2 deletions utilities/ttl/db_ttl_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class DBWithTTLImpl : public DBWithTTL {
static bool IsStale(const Slice& value, int32_t ttl, SystemClock* clock);

// IsStale for strict ttl
bool IsStale(const Slice& value, ColumnFamilyHandle* column_family,
const ReadOptions& options);
bool IsStaleStrictTtl(const Slice& value, ColumnFamilyHandle* column_family,
const ReadOptions& options);

static Status AppendTS(const Slice& val, std::string* val_with_ts,
SystemClock* clock);
Expand Down
Loading

0 comments on commit 9460180

Please sign in to comment.