You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@helix.apache.org by Dave Peterson <da...@box.com> on 2018/02/05 04:42:30 UTC

Re: callback for controller becoming master

Currently we have a pair of controller nodes, a master and a slave for
failover.
These are separate from the nodes that handle client requests.  When a
config
file change occurs, we restart the controllers sequentially, to force them
to see
the changed config, and add or delete resources as necessary.

In the current implementation, the logic executing at controller startup
that
reads the config file is surrounded by an "if" so that it executes only if
it is
master.  So when the slave restarts, it comes back up as a slave, and
doesn't
load the config.  Likewise, when the master restarts, the slave becomes
master,
but doesn't reload the config, since that is done only at startup.  And the
former
master comes back up as a slave so it doesn't load the config either.  One
way
to fix things would be to add code that reads the config when a controller
becomes master, although we are not sure how much we like that solution.  We
need to think more about it and consider alternatives.  But knowing that
there is
a mechanism for executing a callback on becoming master is
useful information, just so we know what is possible.

Dave



On Sat, Jan 27, 2018 at 10:27 AM, kishore g <g....@gmail.com> wrote:

> Yes, You can add a ControllerChangeListener on the HelixManager. Can you
> describe the scenario where you plan to use this?
>
> MyControllerChangeLister implements ControllerChangeListener {
>
>   onControllerChange(NotificationContext context) {
>
>   HelixDataAccessor accessor = changeContext.getManager().
> getHelixDataAccessor();
>
>    // double check if this controller is the leader
>    Builder keyBuilder = accessor.keyBuilder();
>    LiveInstance leader = accessor.getProperty(
> keyBuilder.controllerLeader());
>    if (leader == null) {
>     //No leader
>    } else {
>      String leaderInstanceName = leader.getInstanceName();
>    }
>   }
> }
>
> On Fri, Jan 26, 2018 at 2:56 PM, Dave Peterson <da...@box.com>
> wrote:
>
>> Does the Helix API provide a way to register a callback that gets called
>> when a Helix controller becomes master?
>>
>> Thanks,
>> Dave
>>
>>
>