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

Make cluster meet reliable under link failures #461

Open
wants to merge 3 commits into
base: unstable
Choose a base branch
from

Conversation

srgsanky
Copy link

@srgsanky srgsanky commented May 8, 2024

When there is a link failure while an ongoing MEET request is sent the sending node stops sending anymore MEET and starts sending PINGs. Since every node responds to PINGs from unknown nodes with a PONG, the receiving node never adds the sending node. But the sending node adds the receiving node when it sees a PONG. This can lead to asymmetry in cluster membership. This changes makes the sender keep sending MEET until it sees a PONG, avoiding the asymmetry.

When there is a link failure while an ongoing MEET request is sent the
sending node stops sending anymore MEET and starts sending PINGs. Since
every node responds to PINGs from unknown nodes with a PONG, the
receiving node never adds the sending node. But the sending node adds
the receiving node when it sees a PONG. This can lead to asymmetry in
cluster membership. This changes makes the sender keep sending MEET
until it sees a PONG, avoiding the asymmetry.
@srgsanky
Copy link
Author

srgsanky commented May 8, 2024

Posting this for initial comments. I can migrate the test based on the new framework once #442 is merged.

Copy link

codecov bot commented May 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.94%. Comparing base (d52c8f3) to head (2ff9879).

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable     #461      +/-   ##
============================================
+ Coverage     69.83%   69.94%   +0.11%     
============================================
  Files           109      109              
  Lines         61801    61808       +7     
============================================
+ Hits          43158    43234      +76     
+ Misses        18643    18574      -69     
Files Coverage Δ
src/cluster_legacy.c 86.50% <100.00%> (+0.28%) ⬆️
src/debug.c 53.60% <100.00%> (+0.13%) ⬆️

... and 14 files with indirect coverage changes

@srgsanky
Copy link
Author

srgsanky commented May 8, 2024

@madolson @hpatro @PingXie can one of you help review this change?

src/cluster_legacy.c Outdated Show resolved Hide resolved
* normal PING packets. */
node->flags &= ~CLUSTER_NODE_MEET;

/* NOTE: We cannot clear the MEET flag from the node until we get a response
Copy link
Member

Choose a reason for hiding this comment

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

This makes sense to me, but I thought we briefly discussed just only sending the meet once, and on reconnect just not sending another meet. The previously logic was "We'll only send a single meet", I'm wondering if there was any logic somewhere that relied on that behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we getting into the territory that CLUSTER MEET should only be sent when it was generated by the user/admin?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

Copy link
Author

Choose a reason for hiding this comment

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

The initial MEET is still triggered by an admin/user command.

    /* We can clear the flag after the first packet is sent.
     * If we'll never receive a PONG, we'll never send new packets
     * to this node. Instead after the PONG is received and we
     * are no longer in meet/handshake status, we want to send
     * normal PING packets. */

The previous code comment above doesn't restrict the MEET to be sent exactly once. I can't think of any scenario where sending multiple MEETs will break - this is similar to when an admin sends MEET multiple times. We send MEET only when the connection is established in clusterLinkConnectHandler, so we still limit sending MEET when connection is newly setup and not in every cluster cron run.

Copy link
Member

Choose a reason for hiding this comment

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

this is similar to when an admin sends MEET multiple times

I believe the cluster deduplicate multiple identical requests to the same IP/port.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, is there a worst case scenario where the node which was intended to connect to earlier has changed and we send the MEET command to the wrong node with this change?

Copy link
Member

Choose a reason for hiding this comment

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

I can't think of any. I went through the code and it seems okay to get a double MEET. My ask is can we update the test to also cause this edge case. I believe we can drop the pong messages on the source node, kill the connection, and trigger a second meet message.

Copy link
Author

Choose a reason for hiding this comment

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

In the test case I am using multiple MEETs to make sure we don't stop dropping the link early.

    wait_for_condition 1000 50 {
        [CI $b cluster_stats_messages_meet_received] >= 3
    } else {
      fail "Cluster node $a never sent multiple MEETs to $b"
    }

Copy link
Member

Choose a reason for hiding this comment

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

B isn't processing these right? It's just immediately dropping the first three and not processing them, it only ever processes the 4th one once correct?

* normal PING packets. */
node->flags &= ~CLUSTER_NODE_MEET;

/* NOTE: We cannot clear the MEET flag from the node until we get a response
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we getting into the territory that CLUSTER MEET should only be sent when it was generated by the user/admin?

Comment on lines +2030 to +2031
int cluster_close_link_on_packet_drop; /* Debug config that goes along with cluster_drop_packet_filter.
When set, the link is closed on packet drop. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any alternative you thought of for testing without introducing this particular flag?

Copy link
Author

Choose a reason for hiding this comment

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

In order to test this, the target node has to close the physical connection and not just simply drop the packet. Simply dropping the packet is not a valid scenario in production as we use TCP and we expect reliable transmission.

The only other approach that I can think of is to use iptables to drop packets while the connection is setup. I couldn't find examples in tcl tests that use iptables. Do you have a better approach in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

In the cluster tests for failover, we use SIGPAUSE to stop node. (There's some TCL helper function for it, like proc pause_process I think.) Then, it doesn't respond to any network traffic. SIGCONT is used to wake it up again.

Copy link
Author

Choose a reason for hiding this comment

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

SIGPAUSE and SIGCONT may not reproduce the scenario that this PR is fixing. We want the connect to be established successfully so that the sender sends the MEET message. The connection has to be torn down before the MEET is received by the receiver. This makes it tricky.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK

@hpatro
Copy link
Contributor

hpatro commented May 13, 2024

I think it's worth investing on this redis/redis#11095 to avoid this issue altogether.

@srgsanky
Copy link
Author

I think it's worth investing on this redis/redis#11095 to avoid this issue altogether.

Thanks, I wasn't aware of this linked issue. IMO these two issues can be solved independently. The linked issue tries to make the admin experience better for MEET command where as this PR tries to address a specific gap in MEET implementation.

  • With SYNC MEET, we will have to make changes to admin client timeout. This timeout can possible trickle up the stack in a control plane implementation.
  • If we choose to attempt handshake for a longer period of time, we either have to filter out nodes in handshake in cluster nodes output for a non-admin client or make the clients filter out the nodes with this new flag. This can require a client side change to avoid connecting to a node in handshake, experiencing availability issues.

The problem addressed in this PR (asymmetric cluster membership) can happen with SYNC MEET as well due to link failures. So, it is worth solving it. The handshake nodes will still be removed after the handshake timeout (same as node_timeout of 15s). Wdyt?

@madolson
Copy link
Member

The problem addressed in this PR (asymmetric cluster membership) can happen with SYNC MEET as well due to link failures. So, it is worth solving it. The handshake nodes will still be removed after the handshake timeout (same as node_timeout of 15s). Wdyt?

Yeah, I still believe this a problem even with the #11095.

@zuiderkwast
Copy link
Contributor

Awesome material for our next release which will be full of cluster improvements. Is it worth mentioning in release notes?

Btw @srgsanky you need to commit with -s. See the instructions on the DCO CI job's details page.

@madolson madolson added the release-notes This issue should get a line item in the release notes label May 13, 2024
@madolson
Copy link
Member

Awesome material for our next release which will be full of cluster improvements. Is it worth mentioning in release notes?

I would also be inclined to backport it.

@srgsanky
Copy link
Author

Awesome material for our next release which will be full of cluster improvements. Is it worth mentioning in release notes?

Btw @srgsanky you need to commit with -s. See the instructions on the DCO CI job's details page.

When I tried to merge the new changes into my fork, I ended up with a merge commit

* 2ff9879fa (HEAD -> unstable, origin/unstable, origin/HEAD) Moved test under unit and addressed other comments
*   b826ef77a Merge branch 'valkey-io:unstable' into unstable
|\
| * d52c8f30e Include stddef in zmalloc.h (#516)
| * dcc9fd4fe Resolve numtests counter error (#514)
...
| * 315b7573c Update server function's name to valkey (#456)
* | 49a884c06 Make cluster meet reliable under link failures
|/
* 4e944cede Migrate kvstore.c unit tests to new test framework. (#446)

I want to signoff just 49a884c, but the rebase is adding a signoff to all commits 315b757..d52c8f3 which are not made by me.

Do you have any recommendation to fix this?

As an alternate option, I can start fresh and add a new commit from the tip of unstable. I am not sure if I will be able to reuse this PR.

@srgsanky srgsanky force-pushed the unstable branch 2 times, most recently from d8aa71c to 2ff9879 Compare May 19, 2024 21:22
@zuiderkwast
Copy link
Contributor

I believe it's possible to undo a merge by git reset --hard 49a884c06 (the commit before the merge commit), then rebase to add the --signoff, then do git merge unstable again. The commit you added after merge commit can be cherry-picked after all this. Just remember the commit id.

If nothing works, then it's always possible to start from scratch with a new branch and cherry-pick all your commits into it. Then you can rename the branches and force-push to this PR's branch.

@madolson
Copy link
Member

@srgsanky The commit missing the DCO is just the top one. You should just be able to do git commit -s --amend with a no-op and force push over what you have.

Copy link
Member

@madolson madolson left a comment

Choose a reason for hiding this comment

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

Just some minor nitpicks around the tests, it overall LGTM.

Comment on lines +5 to +10
tags {tls:skip external:skip cluster} {

set base_conf [list cluster-enabled yes]
start_multiple_servers 2 [list overrides $base_conf] {

test "Cluster nodes are reachable" {
Copy link
Member

Choose a reason for hiding this comment

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

Some tests have this indentation since we wanted to preserve git history, when we ported them from the old to new framework. For new tests, they should ideally be indented. Maybe we should just format them at this point, since we are already losing so much history.

Comment on lines +30 to +36
set b 0
set a 1

test "Cluster nodes haven't met each other" {
assert {[llength [get_cluster_nodes $a]] == 1}
assert {[llength [get_cluster_nodes $b]] == 1}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
set b 0
set a 1
test "Cluster nodes haven't met each other" {
assert {[llength [get_cluster_nodes $a]] == 1}
assert {[llength [get_cluster_nodes $b]] == 1}
}
test "Cluster nodes haven't met each other" {
assert {[llength [get_cluster_nodes 1]] == 1}
assert {[llength [get_cluster_nodes 0]] == 1}
}

If you much prefer a and b, I'm okay with, but it seems just as useful to just call them 0 and 1 to me.


set b_port [srv 0 port]

R $a CLUSTER MEET 127.0.0.1 $b_port
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
R $a CLUSTER MEET 127.0.0.1 $b_port
R 1 CLUSTER MEET 127.0.0.1 [srv 0 port]

Similar to previous point about avoiding renaming the nodes a and b.

@@ -44,6 +44,7 @@ test "Cluster nodes hard reset" {
R $id config set repl-diskless-load disabled
R $id config set cluster-announce-hostname ""
R $id DEBUG DROP-CLUSTER-PACKET-FILTER -1
R $id DEBUG CLOSE-CLUSTER-LINK-ON-PACKET-DROP 0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
R $id DEBUG CLOSE-CLUSTER-LINK-ON-PACKET-DROP 0

I assume this is no longer needed now that the tests were moved?

wait_for_condition 1000 50 {
[CI $b cluster_stats_messages_meet_received] >= 3
} else {
fail "Cluster node $a never sent multiple MEETs to $b"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fail "Cluster node $a never sent multiple MEETs to $b"
fail "Cluster node $a never sent multiple MEETs to $b"

We should figure out a linter for TCL.

* normal PING packets. */
node->flags &= ~CLUSTER_NODE_MEET;

/* NOTE: We cannot clear the MEET flag from the node until we get a response
Copy link
Member

Choose a reason for hiding this comment

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

B isn't processing these right? It's just immediately dropping the first three and not processing them, it only ever processes the 4th one once correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes This issue should get a line item in the release notes
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants