Skip to content

Commit

Permalink
fix(server): Rename confusing flag `replica_reconnect_on_master_resta…
Browse files Browse the repository at this point in the history
…rt` (dragonflydb#3193)

That was a misleading name, as the logic was the exact opposite (oops 🤦)

This PR introduces a new name for the same flag: break_replication_on_master_restart

We're keeping the previous flag for now, to make transition easier. We'll remove it in a later Dragonfly version (>= 1.22)

Fixes dragonflydb#3192
  • Loading branch information
chakaz authored and dranikpg committed Jun 23, 2024
1 parent 5aeb8b2 commit f0064d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/server/replica.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ ABSL_FLAG(int, master_reconnect_timeout_ms, 1000,
"Timeout for re-establishing connection to a replication master");
ABSL_FLAG(bool, replica_partial_sync, true,
"Use partial sync to reconnect when a replica connection is interrupted.");
ABSL_FLAG(bool, replica_reconnect_on_master_restart, false,
"When in replica mode, and master restarts, break replication from master.");
ABSL_FLAG(bool, break_replication_on_master_restart, false,
"When in replica mode, and master restarts, break replication from master to avoid "
"flushing the replica's data.");
ABSL_DECLARE_FLAG(int32_t, port);

// TODO: Remove this flag on release >= 1.22
ABSL_FLAG(bool, replica_reconnect_on_master_restart, false,
"Deprecated - please use --break_replication_on_master_restart.");

namespace dfly {

using namespace std;
Expand Down Expand Up @@ -303,7 +308,8 @@ std::error_code Replica::HandleCapaDflyResp() {
// If we're syncing a different replication ID, drop the saved LSNs.
string_view master_repl_id = ToSV(LastResponseArgs()[0].GetBuf());
if (master_context_.master_repl_id != master_repl_id) {
if (absl::GetFlag(FLAGS_replica_reconnect_on_master_restart) &&
if ((absl::GetFlag(FLAGS_replica_reconnect_on_master_restart) ||
absl::GetFlag(FLAGS_break_replication_on_master_restart)) &&
!master_context_.master_repl_id.empty()) {
LOG(ERROR) << "Encountered different master repl id (" << master_repl_id << " vs "
<< master_context_.master_repl_id << ")";
Expand Down
2 changes: 1 addition & 1 deletion tests/dragonfly/replication_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,7 @@ async def test_replica_reconnect(df_local_factory, break_conn):
# Connect replica to master
master = df_local_factory.create(proactor_threads=1)
replica = df_local_factory.create(
proactor_threads=1, replica_reconnect_on_master_restart=break_conn
proactor_threads=1, break_replication_on_master_restart=break_conn
)
df_local_factory.start_all([master, replica])

Expand Down

0 comments on commit f0064d8

Please sign in to comment.