public void stop() throws Exception { for (LeaderService leaderService : _leaderServiceList) { leaderService.stopAsync(); leaderService.awaitTerminated(); } }
Future<Void> startAsync() { _leaderService.startAsync(); return _startedFuture; }
Future<Void> stopAsync() { _leaderService.stopAsync(); return _terminatedFuture; }
PartitionLeader(int partition) { _partition = partition; String leaderPath = ZKPaths.makePath(_basePath, String.format(LEADER_PATH_PATTERN, partition)); _leaderService = new LeaderService(_curator, leaderPath, _instanceId, _serviceName, _reacquireDelay, _delayUnit, this::leadershipAcquired); _leaderService.addListener(new Service.Listener() { @Override public void running() { _startedFuture.set(null); } @Override public void terminated(Service.State from) { _terminatedFuture.set(null); } }, MoreExecutors.sameThreadExecutor()); }
boolean hasLeadership() { if (!_leaderService.isRunning() || !_leaderService.hasLeadership()) { return false; } // It's possible we technically have leadership but are in the process of giving it up because we already // are leading the maximum number of partitions. Verify that this isn't a rejected service. Service delegateService = _leaderService.getCurrentDelegateService().orNull(); return delegateService == null || !(delegateService instanceof RelinquishService); }
@Override public LeaderService get() { LeaderService service = new LeaderService( curator, "/leader/table-maintenance", self.toString(), "Leader-TableMaintenance-" + scope, 1, TimeUnit.MINUTES, maintenanceServiceFactory); ServiceFailureListener.listenTo(service, metricRegistry); dropwizardTask.register(scope.toLowerCase() + "-maintenance", service); return service; } };
public void start() throws Exception { _leaderServiceList = getLeaderServices(_timestampCache, _curator, _self, _cqlSessionForHintsPollerMap, _clusterHintsPoller, _dropwizardTask, _metricRegistry); for (LeaderService leaderService : _leaderServiceList) { leaderService.startAsync(); leaderService.awaitRunning(); } }
boolean relinquishLeadership() { if (hasLeadership()) { // Release leadership by stopping the delegate service, but do not stop the leadership service itself Service delegateService = _leaderService.getCurrentDelegateService().orNull(); if (delegateService != null) { _log.info("Relinquishing leadership of partition {} for {}", _partition, _serviceName); delegateService.stopAsync(); } return true; } else { return false; } }
public void register(final String name, final LeaderService leaderService) { _selectorMap.put(name, leaderService); // Unregister automatically to avoid memory leaks. leaderService.addListener(new AbstractServiceListener() { @Override public void terminated(Service.State from) { unregister(name, leaderService); } @Override public void failed(Service.State from, Throwable failure) { unregister(name, leaderService); } }, MoreExecutors.sameThreadExecutor()); }
private String getLeaderId(LeaderService leaderService) { try { return leaderService.getLeader().getId(); } catch (Exception e) { return "<unknown>"; } } }
PartitionLeader(int partition) { _partition = partition; String leaderPath = ZKPaths.makePath(_basePath, String.format(LEADER_PATH_PATTERN, partition)); _leaderService = new LeaderService(_curator, leaderPath, _instanceId, _serviceName, _reacquireDelay, _delayUnit, this::leadershipAcquired); _leaderService.addListener(new Service.Listener() { @Override public void running() { _startedFuture.set(null); } @Override public void terminated(Service.State from) { _terminatedFuture.set(null); } }, MoreExecutors.sameThreadExecutor()); }
boolean hasLeadership() { if (!_leaderService.isRunning() || !_leaderService.hasLeadership()) { return false; } // It's possible we technically have leadership but are in the process of giving it up because we already // are leading the maximum number of partitions. Verify that this isn't a rejected service. Service delegateService = _leaderService.getCurrentDelegateService().orNull(); return delegateService == null || !(delegateService instanceof RelinquishService); }
@Override public LeaderService get() { LeaderService service = new LeaderService( curator, "/leader/table-maintenance", self.toString(), "Leader-TableMaintenance-" + scope, 1, TimeUnit.MINUTES, maintenanceServiceFactory); ServiceFailureListener.listenTo(service, metricRegistry); dropwizardTask.register(scope.toLowerCase() + "-maintenance", service); return service; } };
public void stop() throws Exception { for (LeaderService leaderService : _leaderServiceList) { leaderService.stopAsync(); leaderService.awaitTerminated(); } }
public void start() throws Exception { _leaderServiceList = getLeaderServices(_timestampCache, _curator, _self, _cqlSessionForHintsPollerMap, _clusterHintsPoller, _dropwizardTask, _metricRegistry); for (LeaderService leaderService : _leaderServiceList) { leaderService.startAsync(); leaderService.awaitRunning(); } }
boolean relinquishLeadership() { if (hasLeadership()) { // Release leadership by stopping the delegate service, but do not stop the leadership service itself Service delegateService = _leaderService.getCurrentDelegateService().orNull(); if (delegateService != null) { _log.info("Relinquishing leadership of partition {} for {}", _partition, _serviceName); delegateService.stopAsync(); } return true; } else { return false; } }
Future<Void> startAsync() { _leaderService.startAsync(); return _startedFuture; }
Future<Void> stopAsync() { _leaderService.stopAsync(); return _terminatedFuture; }
public void register(final String name, final LeaderService leaderService) { _selectorMap.put(name, leaderService); // Unregister automatically to avoid memory leaks. leaderService.addListener(new AbstractServiceListener() { @Override public void terminated(Service.State from) { unregister(name, leaderService); } @Override public void failed(Service.State from, Throwable failure) { unregister(name, leaderService); } }, MoreExecutors.sameThreadExecutor()); }
private String getLeaderId(LeaderService leaderService) { try { return leaderService.getLeader().getId(); } catch (Exception e) { return "<unknown>"; } } }