Skip to content

Commit

Permalink
fix(transaction): Fix auto journaling in transaction (#4737)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
BagritsevichStepan authored Mar 10, 2025
1 parent 2ff8603 commit 4f70d1b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/server/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down
19 changes: 19 additions & 0 deletions tests/dragonfly/replication_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ async def is_match_rsp(rx):
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)
Expand Down Expand Up @@ -731,6 +735,21 @@ async def check_expire(key):
)
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.
Expand Down

0 comments on commit 4f70d1b

Please sign in to comment.