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

Leadership election and Cancellation token in dotnet #10

Open
lawrencegripper opened this issue Jan 4, 2018 · 1 comment
Open

Leadership election and Cancellation token in dotnet #10

lawrencegripper opened this issue Jan 4, 2018 · 1 comment

Comments

@lawrencegripper
Copy link

I was wondering what your thoughts would be on passing a cancellation token to each of the funcs in the .net implementation. This can then be checked, while the code is running, to understand if leadership has been lost.

I took a look at implementing leadership election in dotnetcore a while back using etcd and used this pattern. Full code here, simple example below.

            var election = new ElectionRunner(
                isNowMaster: (cancellationToken) =>{
                    while (!cancellationToken.IsCancellationRequested)
                    {
                        Console.WriteLine("We're Master!!");
                        Task.Delay(TimeSpan.FromSeconds(3)).Wait();
                    }
                },
                isNowSecondary: (cancellationToken) =>{
                    while (!cancellationToken.IsCancellationRequested)
                    {
                        Console.WriteLine("We're secondary");
                        Task.Delay(TimeSpan.FromSeconds(3)).Wait();                        
                    }
                },
                electionTimeoutSec: 15);

I'm unclear on how feasible this is in the Metaparticle code but if there is agreement that it is an worthwhile addition I can investigate further and hopefully create a PR.

@brendandburns
Copy link
Contributor

Under what circumstances would the cancellation be requested? Is this so that as a user that is currently the master, we can request a cancellation of that mastering?

If so, I think that's a great idea, but I think you would pass that to the Election rather than to the isNowMaster function...

I could definitely be missing something here, so please discuss more.

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

No branches or pull requests

2 participants