Skip to content

chore: allow replicaof in cluster mode when state is TAKEN_OVER #5618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/server/server_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3395,9 +3395,11 @@ void ServerFamily::ReplicaOfInternal(CmdArgList args, Transaction* tx, SinkReply
last_master_data = replica_->Stop();
StopAllClusterReplicas();

// First, switch into the loading state
if (auto new_state = service_.SwitchState(GlobalState::ACTIVE, GlobalState::LOADING);
new_state != GlobalState::LOADING) {
const GlobalState gstate = ServerState::tlocal()->gstate();
if (gstate == GlobalState::TAKEN_OVER) {
service_.SwitchState(GlobalState::TAKEN_OVER, GlobalState::LOADING);
} else if (auto new_state = service_.SwitchState(GlobalState::ACTIVE, GlobalState::LOADING);
new_state != GlobalState::LOADING) {
LOG(WARNING) << new_state << " in progress, ignored";
builder->SendError("Invalid state");
return;
Expand Down
11 changes: 11 additions & 0 deletions tests/dragonfly/cluster_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3421,3 +3421,14 @@ async def test_replica_takeover_moved(

assert await r1.client.execute_command("GET X") == "2"
assert await m2.client.execute_command("GET FOOX") == "1"

await r1.client.execute_command("flushall")
assert await r1.client.dbsize() == 0
await r1.client.execute_command("SET newk foo")
# Now bring back m1 as a replica of r1
nodes.append(m1)
r1.replicas = [m1]
await push_config(json.dumps(generate_config(master_nodes)), [node.client for node in nodes])
await m1.client.execute_command(f"replicaof localhost {r1.instance.port}")
await check_all_replicas_finished([m1.client], r1.client)
assert await m1.client.execute_command("GET newk") == "foo"
Loading