Skip to content
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

test: add test for replication deadlock on replication timeout #3691

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion src/server/replica.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ void Replica::MainReplicationFb() {
}

// Give a lower timeout for connect, because we're
reconnect_count_++;
ec = ConnectAndAuth(absl::GetFlag(FLAGS_master_reconnect_timeout_ms) * 1ms, &cntx_);
if (ec) {
reconnect_count_++;
LOG(WARNING) << "Error connecting to " << server().Description() << " " << ec;
continue;
}
Expand Down
25 changes: 25 additions & 0 deletions tests/dragonfly/replication_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,31 @@ async def test_announce_ip_port(df_factory):
assert port == "1337"


@pytest.mark.asyncio
async def test_replication_timeout_on_full_sync(df_factory: DflyInstanceFactory):
# setting replication_timeout to a very small value to force the replica to timeout
master = df_factory.create(replication_timeout=50, vmodule="replica=2,dflycmd=2")
replica = df_factory.create()

df_factory.start_all([master, replica])

c_master = master.client()
c_replica = replica.client()

await c_master.execute_command("debug", "populate", "200000", "foo", "500")
seeder = SeederV2(key_target=200_000)

seeder_task = asyncio.create_task(seeder.run(c_master, target_deviation=0.1))
await asyncio.sleep(2) # wait for seeder running

await c_replica.execute_command(f"REPLICAOF localhost {master.port}")
await seeder_task
await asyncio.sleep(1)

await assert_replica_reconnections(replica, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am slightly confused with this. How can it ever be 0 if we unconditionally increment it in MainReplFiber

  while (state_mask_.load() & R_ENABLED) {
    // Discard all previous errors and set default error handler.
    cntx_.Reset([this](const GenericError& ge) { this->DefaultErrorHandler(ge); });
    // 1. Connect socket.
    if ((state_mask_.load() & R_TCP_CONNECTED) == 0) {
      ThisFiber::SleepFor(500ms);
      if (is_paused_)
        continue;
      ec = ResolveHostDns();
      if (ec) {
        LOG(ERROR) << "Error resolving dns to " << server().host << " " << ec;
        continue;
      }

      // Give a lower timeout for connect, because we're
      reconnect_count_++;
      ec = ConnectAndAuth(absl::GetFlag(FLAGS_master_reconnect_timeout_ms) * 1ms, &cntx_);
      if (ec) {

What am I missing here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because when starting replication (Replica::Start) we call ConnectAndAuth and than state_mask_.store(R_ENABLED | R_TCP_CONNECTED);
Therefor when entering the while loop at the first time we will not execute this if condition

df_factory.stop_all()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No action needed just remember this is called when the fixture is destroyed. Clients are the ones that usually needed to be closed manually.



async def test_master_stalled_disconnect(df_factory: DflyInstanceFactory):
# disconnect after 1 second of being blocked
master = df_factory.create(replication_timeout=1000)
Expand Down
Loading