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

Check membership before transferring leadership #482

Merged

Conversation

anhanhnguyen
Copy link
Contributor

Hi,

During the testing with the current ra library, we noticed that leadership can be transferred to a non-voter member. We think non-voter members should not hold leadership.

Proposed Changes

  • Added a membership check to ensure the target ServerId is a voter member.
  • If the target is not a voter, return a non_voter_member error.

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bug fix (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (correction or otherwise)
  • Cosmetics (whitespace, appearance)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.

  • I have read the CONTRIBUTING.md document
  • I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • All tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in related repositories

Further Comments

If this is a relatively large or complex change, kick off the discussion by
explaining why you chose the solution you did and what alternatives you
considered, etc.

Updated `handle_leader` to include a cluster membership check of target `ServerId` before initiating leader transfer
and return an error if the target server is not a voter.
Copy link
Contributor

@kjnilsson kjnilsson left a comment

Choose a reason for hiding this comment

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

Sounds reasonable. Cheers.

src/ra_server.erl Outdated Show resolved Hide resolved
src/ra_server.erl Outdated Show resolved Hide resolved
case Cluster of
#{ServerId := #{voter_status := #{membership := Membership}}} when Membership =/= voter ->
?DEBUG("~ts: transfer leadership requested but non-voter member ~w", [LogId, ServerId]),
{leader, State, [{reply, {error, non_voter_member}}]};
Copy link
Contributor

Choose a reason for hiding this comment

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

make the error {error, non_voter} please

Copy link
Contributor

Choose a reason for hiding this comment

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

Also please update the type spec fr the transfer_leadership function in the ra module and perhaps the docs also.

Copy link
Contributor Author

@anhanhnguyen anhanhnguyen Dec 6, 2024

Choose a reason for hiding this comment

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

I've updated the docs, but I think the function spec does not require any changes. The {error, non_voter} is already covered under {error, term()} in ra:transfer_leadership/2 function specification.

@kjnilsson kjnilsson added this to the 2.16.0 milestone Dec 5, 2024
@kjnilsson kjnilsson merged commit ca694dc into rabbitmq:main Dec 9, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants