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

Send :name_conflict message to losing process when registries merge #118

Merged
merged 5 commits into from
May 17, 2019

Conversation

arjan
Copy link
Contributor

@arjan arjan commented May 16, 2019

When 2 clustered registries register the same name at exactly the same time, it will seem like name registration succeeds for both registries. The function returns {:ok, pid} for both of these calls.

However, due to the eventual consistent nature of the CRDT, a conflict resolution will take place, and the CRDT will pick one of the two processes as the "winner" of the name. The losing process will then receive a message to indicate that it has lost the name registration. The message looks like this:

{:name_conflict, {name, value}, registry_name, winning_pid}

@derekkraan
Copy link
Owner

derekkraan commented May 17, 2019

Thanks, this looks great!

I was thinking about this last night, maybe it would be better to send an exit signal with the reason. Then it's still a message that processes can respond to, but the default behaviour (exiting vs ignoring) is perhaps better.

What do you think?

@derekkraan
Copy link
Owner

Consider: Elixir.Registry (and Horde.Registry) links your process to itself, so if the registry goes down, you get an exit signal. Also, it's common to write {:ok, pid} = Horde.Registry.register(...) in the init/1 callback of your process, and also just let it crash if that fails. (At least, this is what I do).

@arjan
Copy link
Contributor Author

arjan commented May 17, 2019

Yes so to catch this signal you then need to be trapping exits. I think that's fine. I'll fix this, hold on

@derekkraan
Copy link
Owner

Yes, this is looking great. Thanks!

@derekkraan derekkraan merged commit 1a3db65 into derekkraan:master May 17, 2019
@arjan arjan deleted the name-conflict-messages branch May 17, 2019 08:40
derekkraan added a commit that referenced this pull request May 21, 2019
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