fix(transaction): Fix auto journaling in transaction (#4737)

* fix(transaction): Fix auto journaling in transaction

Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>

* refactor: address comments

Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>

---------

Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>
This commit is contained in:
Stepan Bagritsevich 2025-03-10 17:04:58 +01:00 committed by GitHub
parent 2ff8603492
commit 4f70d1bdbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View file

@ -499,6 +499,7 @@ void Transaction::MultiSwitchCmd(const CommandId* cid) {
kv_fp_.clear();
cid_ = cid;
re_enabled_auto_journal_ = false;
cb_ptr_ = nullptr;
for (auto& sd : shard_data_) {

View file

@ -589,6 +589,10 @@ async def test_rewrites(df_factory):
async def skip_cmd():
await is_match_rsp(r".*")
async def skip_cmds(n):
for _ in range(n):
await skip_cmd()
async def check(cmd, rx):
await c_master.execute_command(cmd)
match = await is_match_rsp(rx)
@ -731,6 +735,21 @@ async def test_rewrites(df_factory):
)
await check_expire("renamekey")
# Test autojournaling in the multi-mode
await c_master.execute_command("XADD k-stream * field value")
await c_master.execute_command("SADD k-one-element-set value1 value2")
sha = await c_master.script_load(
"redis.call('XTRIM', KEYS[1], 'MINID', '0'); return redis.call('SPOP', KEYS[2]);"
)
await skip_cmds(3)
# The first call to XTRIM triggers autojournaling.
# The SPOP command is executed with CO::NO_AUTOJOURNALING.
# This test ensures that the SPOP command is still properly replicated
await check_list_ooo(
f"EVALSHA {sha} 2 k-stream k-one-element-set",
[r"XTRIM k-stream MINID 0", r"SREM k-one-element-set value[12]"],
)
"""
Test automatic replication of expiry.