feat: increase expiry period to 8 years.

Related to #923.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2023-03-13 09:44:29 +02:00 committed by Roman Gershman
parent bac9180602
commit a8c1e5cd4a
5 changed files with 12 additions and 6 deletions

View file

@ -11,8 +11,8 @@ Indices (say in GETRANGE and SETRANGE commands) should be signed 32 bit integers
SORT does not take any locale into account.
## Expiry ranges.
Expirations are limited to 4 years. For commands with millisecond precision like PEXPIRE or PSETEX,
expirations greater than 2^27ms are quietly rounded to the nearest second loosing precision of less than 0.001%.
Expirations are limited to 8 years. For commands with millisecond precision like PEXPIRE or PSETEX,
expirations greater than 2^28ms are quietly rounded to the nearest second loosing precision of less than 0.001%.
## Lua
We use lua 5.4.4 that has been released in 2022.

View file

@ -22,7 +22,7 @@ namespace dfly {
enum class ListDir : uint8_t { LEFT, RIGHT };
// Dependent on ExpirePeriod representation of the value.
constexpr int64_t kMaxExpireDeadlineSec = (1u << 27) - 1;
constexpr int64_t kMaxExpireDeadlineSec = (1u << 28) - 1;
using DbIndex = uint16_t;
using ShardId = uint16_t;

View file

@ -30,8 +30,12 @@ class GenericFamilyTest : public BaseFamilyTest {};
TEST_F(GenericFamilyTest, Expire) {
Run({"set", "key", "val"});
auto resp = Run({"expire", "key", "1"});
// sideqik expiry limit
auto resp = Run({"expire", "key", absl::StrCat(5 * 365 * 24 * 3600)});
EXPECT_THAT(resp, IntArg(1));
resp = Run({"expire", "key", "1"});
EXPECT_THAT(resp, IntArg(1));
AdvanceTime(1000);
resp = Run({"get", "key"});

View file

@ -1040,7 +1040,7 @@ void StringFamily::SetExGeneric(bool seconds, CmdArgList args, ConnectionContext
return (*cntx)->SendError(kInvalidIntErr);
}
if (unit_vals < 1) {
if (unit_vals < 1 || unit_vals >= kMaxExpireDeadlineSec) {
ToLower(&args[0]);
return (*cntx)->SendError(InvalidExpireTime(ArgS(args, 0)));
}

View file

@ -362,6 +362,8 @@ TEST_F(StringFamilyTest, SetEx) {
ASSERT_EQ(Run({"setex", "key", "10", "val"}), "OK");
ASSERT_THAT(Run({"ttl", "key"}), IntArg(10));
ASSERT_THAT(Run({"setex", "key", "0", "val"}), ErrArg("invalid expire time"));
ASSERT_EQ(Run({"setex", "key", StrCat(5 * 365 * 24 * 3600), "val"}), "OK");
ASSERT_THAT(Run({"setex", "key", StrCat(1 << 30), "val"}), ErrArg("invalid expire time"));
}
TEST_F(StringFamilyTest, Range) {