You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@curator.apache.org by Henrik Nordvik <he...@gmail.com> on 2013/08/28 16:44:55 UTC

LeaderSelector Executor

Hi,

The LeaderSelector has a constructor which takes in ThreadFactory and
Executor as parameters. The "default" constructor uses
MoreExecutors.sameThreadExecutor().
I tried using my own ThreadPool with multiple threads, because I thought
that was they way of using multiple leaders.
When I did that, to my surprise, it started multiple leaders per path.
After reading the code it makes sense, it only guarantees that you are the
leader when submitting the thread to the executor.

It seems to me like using anything other than sameThreadExecutor makes
little sense.
When would you want to use it?


Example snippet:
    LeaderSelectorListener listener = new MyLeaderSelectorListener("1");
    ExecutorService executorPool = Executors.newFixedThreadPool(20);
    LeaderSelector leaderSelector = new LeaderSelector(client, path,
threadFactory, executorPool, listener);
    leaderSelector.autoRequeue();
    leaderSelector.start();
    // MyLeaderSelectorListener.takeLeadership is called multiple times
here, even though it is in a sleep-loop.


--
Henrik Nordvik

Re: LeaderSelector Executor

Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
This looks very broken to me. Please open an issue for this.

-Jordan

On Aug 28, 2013, at 7:44 AM, Henrik Nordvik <he...@gmail.com> wrote:

> Hi,
> 
> The LeaderSelector has a constructor which takes in ThreadFactory and Executor as parameters. The "default" constructor uses MoreExecutors.sameThreadExecutor().
> I tried using my own ThreadPool with multiple threads, because I thought that was they way of using multiple leaders. 
> When I did that, to my surprise, it started multiple leaders per path. After reading the code it makes sense, it only guarantees that you are the leader when submitting the thread to the executor.
> 
> It seems to me like using anything other than sameThreadExecutor makes little sense.
> When would you want to use it?
> 
> 
> Example snippet:
>     LeaderSelectorListener listener = new MyLeaderSelectorListener("1");
>     ExecutorService executorPool = Executors.newFixedThreadPool(20);
>     LeaderSelector leaderSelector = new LeaderSelector(client, path, threadFactory, executorPool, listener);
>     leaderSelector.autoRequeue();
>     leaderSelector.start();
>     // MyLeaderSelectorListener.takeLeadership is called multiple times here, even though it is in a sleep-loop.
> 
> 
> --
> Henrik Nordvik