Skip to content

Commit 8723bc0

Browse files
committed
fix: prohibit read commands during takeover
1 parent 267d5ab commit 8723bc0

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/server/main_service.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,10 @@ std::optional<ErrorReply> Service::VerifyCommandState(const CommandId* cid, CmdA
10571057
allowed_by_state = false;
10581058
break;
10591059
case GlobalState::TAKEN_OVER:
1060-
allowed_by_state = !cid->IsWriteOnly();
1060+
// Only Admin commands are allowed
1061+
// we prohibit even read commands, because read commands running in pipeline can take a while
1062+
// to send all data to a client which leads to fail in takeover
1063+
allowed_by_state = dfly_cntx.conn()->IsPrivileged();
10611064
break;
10621065
default:
10631066
break;

tests/dragonfly/replication_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,9 +1187,9 @@ async def test_take_over_counters(df_factory, master_threads, replica_threads):
11871187
c2 = replica2.client()
11881188
c3 = replica3.client()
11891189

1190-
await c1.execute_command(f"REPLICAOF localhost {master.port}")
1191-
await c2.execute_command(f"REPLICAOF localhost {master.port}")
1192-
await c3.execute_command(f"REPLICAOF localhost {master.port}")
1190+
await c1.execute_command(f"REPLICAOF localhost {master.admin_port}")
1191+
await c2.execute_command(f"REPLICAOF localhost {master.admin_port}")
1192+
await c3.execute_command(f"REPLICAOF localhost {master.admin_port}")
11931193

11941194
await wait_available_async(c1)
11951195

@@ -1293,7 +1293,7 @@ async def test_take_over_read_commands(df_factory, master_threads, replica_threa
12931293
await c_master.execute_command("SET foo bar")
12941294

12951295
c_replica = replica.client()
1296-
await c_replica.execute_command(f"REPLICAOF localhost {master.port}")
1296+
await c_replica.execute_command(f"REPLICAOF localhost {master.admin_port}")
12971297
await wait_available_async(c_replica)
12981298

12991299
async def prompt():
@@ -1329,7 +1329,7 @@ async def test_take_over_timeout(df_factory, df_seeder_factory):
13291329

13301330
logging.debug(f"PORTS ARE: {master.port} {replica.port}")
13311331

1332-
await c_replica.execute_command(f"REPLICAOF localhost {master.port}")
1332+
await c_replica.execute_command(f"REPLICAOF localhost {master.admin_port}")
13331333
await wait_available_async(c_replica)
13341334

13351335
fill_task = asyncio.create_task(seeder.run(target_ops=3000))
@@ -1517,7 +1517,7 @@ async def test_replicaof_flag(df_factory):
15171517

15181518
replica = df_factory.create(
15191519
proactor_threads=2,
1520-
replicaof=f"localhost:{master.port}", # start to replicate master
1520+
replicaof=f"localhost:{master.admin_port}", # start to replicate master
15211521
)
15221522

15231523
# set up replica. check that it is replicating

0 commit comments

Comments
 (0)