Skip to content

Commit ddca4e3

Browse files
BorysTheDevromange
authored andcommitted
fix: huge TTL in RESTORE cmd is rounded to kMaxExpireDeadlineMs (#4589)
1 parent 3bf4f1f commit ddca4e3

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/server/generic_family.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,17 @@ ::io::Result<size_t> InMemSource::ReadSome(const iovec* v, uint32_t len) {
106106

107107
class RestoreArgs {
108108
private:
109-
static constexpr time_t NO_EXPIRATION = 0;
109+
static constexpr int64_t NO_EXPIRATION = 0;
110110

111-
time_t expiration_ = NO_EXPIRATION;
111+
int64_t expiration_ = NO_EXPIRATION;
112112
bool abs_time_ = false;
113113
bool replace_ = false; // if true, over-ride existing key
114114
bool sticky_ = false;
115115

116116
public:
117117
RestoreArgs() = default;
118118

119-
RestoreArgs(time_t expiration, bool abs_time, bool replace)
119+
RestoreArgs(int64_t expiration, bool abs_time, bool replace)
120120
: expiration_(expiration), abs_time_(abs_time), replace_(replace) {
121121
}
122122

@@ -236,7 +236,7 @@ pair<DbSlice::ItAndUpdater, bool> RdbRestoreValue::Add(string_view key, string_v
236236
if (HasExpiration()) {
237237
int64_t ttl = abs_time_ ? expiration_ - now_msec : expiration_;
238238
if (ttl > kMaxExpireDeadlineMs)
239-
return false;
239+
ttl = kMaxExpireDeadlineMs;
240240

241241
expiration_ = ttl < 0 ? -1 : ttl + now_msec;
242242
}
@@ -326,7 +326,7 @@ class Renamer {
326326
struct SerializedValue {
327327
std::string value;
328328
std::optional<RdbVersion> version;
329-
time_t expire_ts;
329+
int64_t expire_ts;
330330
bool sticky;
331331
};
332332

src/server/string_family_test.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,13 @@ TEST_F(StringFamilyTest, IncrByFloat) {
528528
EXPECT_EQ(resp, "3.566");
529529
}
530530

531+
TEST_F(StringFamilyTest, RestoreHighTTL) {
532+
Run({"SET", "X", "1"});
533+
auto buffer = Run({"DUMP", "X"}).GetBuf();
534+
Run({"DEL", "X"});
535+
EXPECT_EQ(Run({"RESTORE", "X", "5430186761345", ToSV(buffer)}), "OK");
536+
}
537+
531538
TEST_F(StringFamilyTest, SetNx) {
532539
// Make sure that we "screen out" invalid parameters for this command
533540
// this is important as it uses similar path as the "normal" set

0 commit comments

Comments
 (0)