提交 7a07afe8 编写于 作者: Z zhangliangkai1992 提交者: Facebook GitHub Bot

DBWithTTLImpl::IsStale overflow when ttl is 15 years (#11279)

Summary:
Fix DBWIthTTLImpl::IsStale overflow

Pull Request resolved: https://github.com/facebook/rocksdb/pull/11279

Reviewed By: cbi42

Differential Revision: D43875039

Pulled By: ajkr

fbshipit-source-id: 3e5feb8c4c4480bf1421b0763ade3d2e459ec028
上级 daeec505
......@@ -451,7 +451,11 @@ bool DBWithTTLImpl::IsStale(const Slice& value, int32_t ttl,
if (!clock->GetCurrentTime(&curtime).ok()) {
return false; // Treat the data as fresh if could not get current time
}
int32_t timestamp_value =
/* int32_t may overflow when timestamp_value + ttl
* for example ttl = 86400 * 365 * 15
* convert timestamp_value to int64_t
*/
int64_t timestamp_value =
DecodeFixed32(value.data() + value.size() - kTSLength);
return (timestamp_value + ttl) < curtime;
}
......
......@@ -635,6 +635,17 @@ TEST_F(TtlTest, MultiGetTest) {
CloseTtl();
}
TEST_F(TtlTest, TtlFiftenYears) {
MakeKVMap(kSampleSize_);
// 15 year will lead int32_t overflow from now
const int kFifteenYearSeconds = 86400 * 365 * 15;
OpenTtl(kFifteenYearSeconds);
PutValues(0, kSampleSize_, true);
// trigger the compaction
SleepCompactCheck(1, 0, kSampleSize_);
CloseTtl();
}
TEST_F(TtlTest, ColumnFamiliesTest) {
DB* db;
Options options;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册