Skip to content

Commit

Permalink
Fix stale log index when there is an snapshot but no log in disk
Browse files Browse the repository at this point in the history
  • Loading branch information
JackyWoo committed Jun 15, 2024
1 parent b5ec8d1 commit ddb4563
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Service/NuRaftStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ NuRaftStateMachine::NuRaftStateMachine(
{
LOG_INFO(log, "No previous last commit idx found, skip replaying logs.");
}
else if (previous_last_commit_id < last_committed_idx)
else if (previous_last_commit_id <= last_committed_idx)
{
LOG_WARNING(
log,
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/test_snapshots/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_state_after_restart(started_cluster, node):
finally:
close_zk_clients([node_zk, node_zk2])


@pytest.mark.parametrize(
'node',
[
Expand Down Expand Up @@ -115,3 +116,28 @@ def test_ephemeral_after_restart(started_cluster, node):
assert list(sorted(existing_children)) == list(sorted(node_zk2.get_children("/test_ephemeral_after_restart")))
finally:
close_zk_clients([node_zk, node_zk2])


@pytest.mark.parametrize(
'node',
[
cluster.add_instance('node5', main_configs=['configs/enable_keeper.xml'], with_zookeeper=True, stay_alive=True),
cluster.add_instance('node6', main_configs=['configs/enable_async_snapshot_keeper.xml'], with_zookeeper=True, stay_alive=True)
]
)
def test_restart_with_no_log(started_cluster, node):
node_zk = node_zk2 = None
try:
node_zk = node.get_fake_zk()
node_zk.create("/test_restart_with_no_log", b"somevalue")

node.send_4lw_cmd(cmd="csnp")
time.sleep(1) # wait for snapshot to be taken

node.restart_raftkeeper(kill=True)
node.wait_for_join_cluster()

node_zk2 = node.get_fake_zk()
assert node_zk2.exists("/test_restart_with_no_log")
finally:
close_zk_clients([node_zk, node_zk2])

0 comments on commit ddb4563

Please sign in to comment.