fix(server): Correctly set expiration from Lua scripts (#2080)

We used to set `time_now_ms_` only in the non-squashed execution path.

Fixes #2034
This commit is contained in:
Shahar Mike 2023-10-27 13:13:47 +03:00 committed by GitHub
parent 474ea5137a
commit 502efd80b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View file

@ -1685,16 +1685,17 @@ void Service::EvalInternal(CmdArgList args, const EvalArgs& eval_args, Interpret
});
++ServerState::tlocal()->stats.eval_shardlocal_coordination_cnt;
boost::intrusive_ptr<Transaction> stub_tx = new Transaction{tx, *sid};
cntx->transaction = stub_tx.get();
tx->PrepareMultiForScheduleSingleHop(*sid, tx->GetDbIndex(), args);
tx->ScheduleSingleHop([&](Transaction*, EngineShard*) {
boost::intrusive_ptr<Transaction> stub_tx = new Transaction{tx, *sid};
cntx->transaction = stub_tx.get();
result = interpreter->RunFunction(eval_args.sha, &error);
cntx->transaction = tx;
return OpStatus::OK;
});
cntx->transaction = tx;
if (*sid != ServerState::tlocal()->thread_index()) {
VLOG(1) << "Migrating connection " << cntx->conn() << " from " << ProactorBase::GetIndex()
<< " to " << *sid;

View file

@ -876,6 +876,19 @@ TEST_F(MultiTest, TestLockedKeys) {
EXPECT_FALSE(service_->IsLocked(0, "key2"));
}
TEST_F(MultiTest, EvalExpiration) {
// Make sure expiration is correctly set even from Lua scripts
if (auto config = absl::GetFlag(FLAGS_default_lua_flags); config != "") {
GTEST_SKIP() << "Skipped Eval test because default_lua_flags is set";
return;
}
absl::FlagSaver fs;
absl::SetFlag(&FLAGS_multi_exec_mode, Transaction::LOCK_AHEAD);
Run({"eval", "redis.call('set', 'x', 0, 'ex', 5, 'nx')", "1", "x"});
EXPECT_LE(CheckedInt({"pttl", "x"}), 5000);
}
class MultiEvalTest : public BaseFamilyTest {
protected:
MultiEvalTest() : BaseFamilyTest() {