Skip to content

Commit c93d149

Browse files
authored
fix: Handle django-cache script so it could run in dragonfly (#6123)
automatically. Also remove legacy flag legacy_saddex_keepttl. Fixes #6119 Signed-off-by: Roman Gershman <roman@dragonflydb.io>
1 parent c5d2c5e commit c93d149

File tree

3 files changed

+20
-53
lines changed

3 files changed

+20
-53
lines changed

src/core/string_set.cc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ extern "C" {
1616

1717
#include "base/logging.h"
1818

19-
ABSL_FLAG(bool, legacy_saddex_keepttl, false,
20-
"If true SADDEX does not update TTL for existing fields");
21-
2219
using namespace std;
2320

2421
namespace dfly {
@@ -93,19 +90,13 @@ unsigned StringSet::AddBatch(absl::Span<std::string_view> span, uint32_t ttl_sec
9390
Prefetch(hash[i]);
9491
}
9592

96-
// update ttl if legacy_saddex_keepttl is off (which is default). This variable is intended for
97-
// SADDEX, but this method is called from SADD as well, where ttl is set to UINT32_MAX value,
98-
// which results in has_ttl being false. This means that ObjUpdateExpireTime is never called from
99-
// SADD code path even when update_ttl is true.
100-
const thread_local bool update_ttl = !absl::GetFlag(FLAGS_legacy_saddex_keepttl);
101-
10293
for (unsigned i = 0; i < count; ++i) {
10394
void* prev = FindInternal(&span[i], hash[i], 1);
10495
if (prev == nullptr) {
10596
++res;
10697
sds field = MakeSetSds(span[i], ttl_sec);
10798
AddUnique(field, has_ttl, hash[i]);
108-
} else if (update_ttl && has_ttl && !keepttl) {
99+
} else if (has_ttl && !keepttl) {
109100
ObjUpdateExpireTime(prev, ttl_sec);
110101
}
111102
}

src/server/multi_test.cc

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,6 @@ TEST_F(MultiTest, ScriptFlagsEmbedded) {
840840
EXPECT_THAT(Run({"eval", s2, "0"}), ErrArg("Invalid flag: this-is-an-error"));
841841
}
842842

843-
// Flaky because of https://github.com/google/sanitizers/issues/1760
844-
#ifndef SANITIZERS
845843
TEST_F(MultiTest, UndeclaredKeyFlag) {
846844
absl::FlagSaver fs; // lua_undeclared_keys_shas changed via CONFIG cmd below
847845

@@ -890,7 +888,6 @@ TEST_F(MultiTest, ScriptBadCommand) {
890888
resp = Run({"eval", s4, "0"});
891889
EXPECT_EQ(resp, "OK");
892890
}
893-
#endif
894891

895892
TEST_F(MultiTest, MultiEvalModeConflict) {
896893
const char* s1 = R"(
@@ -1254,29 +1251,6 @@ TEST_F(MultiTest, EvalShaRo) {
12541251
EXPECT_THAT(resp, ErrArg("Write commands are not allowed from read-only scripts"));
12551252
}
12561253

1257-
TEST_F(MultiTest, ForceAtomicityFlag) {
1258-
absl::FlagSaver fs;
1259-
1260-
const string kHash = "bb855c2ecfa3114d222cb11e0682af6360e9712f";
1261-
const string_view kScript = R"(
1262-
--!df flags=disable-atomicity
1263-
redis.call('get', 'x');
1264-
return "OK";
1265-
)";
1266-
1267-
// EVAL the script works due to disable-atomicity flag
1268-
EXPECT_EQ(Run({"eval", kScript, "0"}), "OK");
1269-
1270-
EXPECT_THAT(Run({"script", "list"}), RespElementsAre(kHash, kScript));
1271-
1272-
// Flush scripts to force re-evaluating of flags
1273-
EXPECT_EQ(Run({"script", "flush"}), "OK");
1274-
1275-
// Now it doesn't work, because we force atomicity
1276-
absl::SetFlag(&FLAGS_lua_force_atomicity_shas, {kHash});
1277-
EXPECT_THAT(Run({"eval", kScript, "0"}), ErrArg("undeclared"));
1278-
}
1279-
12801254
TEST_F(MultiTest, StoredCmdBytesMetric) {
12811255
ASSERT_EQ(GetMetrics().coordinator_stats.stored_cmd_bytes, 0);
12821256

src/server/script_mgr.cc

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,10 @@ ABSL_FLAG(bool, lua_allow_undeclared_auto_correct, false,
3939
"undeclared key.");
4040

4141
ABSL_FLAG(
42-
std::vector<std::string>, lua_undeclared_keys_shas,
43-
std::vector<std::string>({"351130589c64523cb98978dc32c64173a31244f3", // Sidekiq, see #2442
44-
"6ae15ef4678593dc61f991c9953722d67d822776", // Sidekiq, see #2442
45-
"34b1048274c8e50a0cc587a3ed9c383a82bb78c5", // Sidekiq
46-
"b725ca33e5b36f318ab1150b8ac955a3d997c872"}), // Sentry, see #5495
42+
std::vector<std::string>, lua_undeclared_keys_shas, {},
4743
"Comma-separated list of Lua script SHAs which are allowed to access undeclared keys. SHAs are "
4844
"only looked at when loading the script, and new values do not affect already-loaded script.");
4945

50-
ABSL_FLAG(std::vector<std::string>, lua_force_atomicity_shas,
51-
std::vector<std::string>({
52-
"f8133be7f04abd9dfefa83c3b29a9d837cfbda86", // Sidekiq, see #4522
53-
}),
54-
"Comma-separated list of Lua script SHAs which are forced to run in atomic mode, even if "
55-
"the script specifies disable-atomicity.");
56-
5746
namespace dfly {
5847
using namespace std;
5948
using namespace facade;
@@ -272,17 +261,30 @@ io::Result<string, GenericError> ScriptMgr::Insert(string_view body, Interpreter
272261
auto params = params_opt->value_or(default_params_);
273262

274263
if (!params.atomic) {
275-
auto force_atomic_shas = absl::GetFlag(FLAGS_lua_force_atomicity_shas);
276-
if (find(force_atomic_shas.begin(), force_atomic_shas.end(), sha) != force_atomic_shas.end()) {
264+
// override atomicity for a specific buggy script.
265+
constexpr string_view sha_4522 =
266+
"f8133be7f04abd9dfefa83c3b29a9d837cfbda86"sv; // Sidekiq, see #4522
267+
if (sha == sha_4522) {
277268
params.atomic = true;
278269
}
279270
}
280271

281-
auto undeclared_shas = absl::GetFlag(FLAGS_lua_undeclared_keys_shas);
282-
if (find(undeclared_shas.begin(), undeclared_shas.end(), sha) != undeclared_shas.end()) {
272+
const char* kUndeclaredShas[] = {
273+
"351130589c64523cb98978dc32c64173a31244f3", // Sidekiq, see #2442
274+
"6ae15ef4678593dc61f991c9953722d67d822776", // Sidekiq, see #2442
275+
"34b1048274c8e50a0cc587a3ed9c383a82bb78c5", // Sidekiq
276+
"b725ca33e5b36f318ab1150b8ac955a3d997c872", // Sentry, see #5495
277+
"8c4dafdf9b6b7bcf511a0d1ec0518bed9260e16d", // django-ops see #6119
278+
};
279+
280+
if (find(begin(kUndeclaredShas), end(kUndeclaredShas), sha) != end(kUndeclaredShas)) {
283281
params.undeclared_keys = true;
282+
} else {
283+
auto undeclared_shas = absl::GetFlag(FLAGS_lua_undeclared_keys_shas);
284+
if (find(undeclared_shas.begin(), undeclared_shas.end(), sha) != undeclared_shas.end()) {
285+
params.undeclared_keys = true;
286+
}
284287
}
285-
286288
// If the script is atomic, check for possible squashing optimizations.
287289
// For non atomic modes, squashing increases the time locks are held, which
288290
// can decrease throughput with frequently accessed keys.

0 commit comments

Comments
 (0)