@Test public void testLeadControllerManager() { LeadControllerManager leadControllerManager = new LeadControllerManager(_helixManager, _controllerMetrics); String tableName = "testTable"; int expectedPartitionIndex = LeadControllerUtils.getPartitionIdForTable(tableName); String partitionName = LeadControllerUtils.generatePartitionName(expectedPartitionIndex); becomeHelixLeader(false); leadControllerManager.onHelixControllerChange(); Assert.assertFalse(leadControllerManager.isLeaderForTable(tableName)); enableResourceConfig(true); leadControllerManager.onResourceConfigChange(); Assert.assertFalse(leadControllerManager.isLeaderForTable(tableName)); Assert.assertTrue(LeadControllerUtils.isLeadControllerResourceEnabled(_helixManager)); leadControllerManager.addPartitionLeader(partitionName); Assert.assertTrue(leadControllerManager.isLeaderForTable(tableName)); leadControllerManager.removePartitionLeader(partitionName); Assert.assertFalse(leadControllerManager.isLeaderForTable(tableName)); enableResourceConfig(false); leadControllerManager.onResourceConfigChange(); Assert.assertFalse(LeadControllerUtils.isLeadControllerResourceEnabled(_helixManager)); Assert.assertFalse(leadControllerManager.isLeaderForTable(tableName)); leadControllerManager.addPartitionLeader(partitionName); Assert.assertFalse(leadControllerManager.isLeaderForTable(tableName)); becomeHelixLeader(true); leadControllerManager.onHelixControllerChange(); Assert.assertTrue(leadControllerManager.isLeaderForTable(tableName)); }
public LeadControllerManager(HelixManager helixParticipantManager, ControllerMetrics controllerMetrics) { _helixManager = helixParticipantManager; _controllerMetrics = controllerMetrics; _instanceId = helixParticipantManager.getInstanceName(); _leadForPartitions = ConcurrentHashMap.newKeySet(); _controllerLeadershipFetchingThread = new Thread("ControllerLeadershipFetchingThread") { @Override public void run() { while (true) { try { synchronized (LeadControllerManager.this) { if (_isShuttingDown) { return; } if (isHelixLeader()) { if (!_amIHelixLeader) { _amIHelixLeader = true; LOGGER.warn("Becoming leader without getting Helix change callback"); _controllerMetrics .addMeteredGlobalValue(ControllerMeter.CONTROLLER_LEADERSHIP_CHANGE_WITHOUT_CALLBACK, 1L); } _controllerMetrics.setValueOfGlobalGauge(ControllerGauge.PINOT_CONTROLLER_LEADER, 1L); } else { if (_amIHelixLeader) { _amIHelixLeader = false; LOGGER.warn("Losing leadership without getting Helix change callback"); _controllerMetrics .addMeteredGlobalValue(ControllerMeter.CONTROLLER_LEADERSHIP_CHANGE_WITHOUT_CALLBACK, 1L); } _controllerMetrics.setValueOfGlobalGauge(ControllerGauge.PINOT_CONTROLLER_LEADER, 0L); } LeadControllerManager.this.wait(CONTROLLER_LEADERSHIP_FETCH_INTERVAL_MS); } } catch (Exception e) { LOGGER.error("Caught exception within controller leadership fetching thread", e); } } } }; }
LeadControllerManager { public LeadControllerManager(HelixManager helixParticipantManager, ControllerMetrics controllerMetrics) { _helixManager = helixParticipantManager; _controllerMetrics = controllerMetrics; _instanceId = helixParticipantManager.getInstanceName(); _leadForPartitions = ConcurrentHashMap.newKeySet(); _controllerLeadershipFetchingThread = new Thread("ControllerLeadershipFetchingThread") { @Override public void run() { while (true) { try { synchronized (LeadControllerManager.this) { if (_isShuttingDown) { return; } if (isHelixLeader()) { if (!_amIHelixLeader) { _amIHelixLeader = true; LOGGER.warn("Becoming leader without getting Helix change callback"); _controllerMetrics .addMeteredGlobalValue(ControllerMeter.CONTROLLER_LEADERSHIP_CHANGE_WITHOUT_CALLBACK, 1L); } _controllerMetrics.setValueOfGlobalGauge(ControllerGauge.PINOT_CONTROLLER_LEADER, 1L); } else { if (_amIHelixLeader) { _amIHelixLeader = false; LOGGER.warn("Losing leadership without getting Helix change callback"); _controllerMetrics .addMeteredGlobalValue(ControllerMeter.CONTROLLER_LEADERSHIP_CHANGE_WITHOUT_CALLBACK, 1L); } _controllerMetrics.setValueOfGlobalGauge(ControllerGauge.PINOT_CONTROLLER_LEADER, 0L); } LeadControllerManager.this.wait(CONTROLLER_LEADERSHIP_FETCH_INTERVAL_MS); } } catch (Exception e) { LOGGER.error("Caught exception within controller leadership fetching thread", e); } } } }; } }
LeadControllerManager { public LeadControllerManager(HelixManager helixParticipantManager, ControllerMetrics controllerMetrics) { _helixManager = helixParticipantManager; _controllerMetrics = controllerMetrics; _instanceId = helixParticipantManager.getInstanceName(); _leadForPartitions = ConcurrentHashMap.newKeySet(); _controllerLeadershipFetchingThread = new Thread("ControllerLeadershipFetchingThread") { @Override public void run() { while (true) { try { synchronized (LeadControllerManager.this) { if (_isShuttingDown) { return; } if (isHelixLeader()) { if (!_amIHelixLeader) { _amIHelixLeader = true; LOGGER.warn("Becoming leader without getting Helix change callback"); _controllerMetrics .addMeteredGlobalValue(ControllerMeter.CONTROLLER_LEADERSHIP_CHANGE_WITHOUT_CALLBACK, 1L); } _controllerMetrics.setValueOfGlobalGauge(ControllerGauge.PINOT_CONTROLLER_LEADER, 1L); } else { if (_amIHelixLeader) { _amIHelixLeader = false; LOGGER.warn("Losing leadership without getting Helix change callback"); _controllerMetrics .addMeteredGlobalValue(ControllerMeter.CONTROLLER_LEADERSHIP_CHANGE_WITHOUT_CALLBACK, 1L); } _controllerMetrics.setValueOfGlobalGauge(ControllerGauge.PINOT_CONTROLLER_LEADER, 0L); } LeadControllerManager.this.wait(CONTROLLER_LEADERSHIP_FETCH_INTERVAL_MS); } } catch (Exception e) { LOGGER.error("Caught exception within controller leadership fetching thread", e); } } } }; } LeadControllerManager(HelixManager helixParticipantManager, ControllerMetrics controllerMetrics); }
LeadControllerManager { public LeadControllerManager(HelixManager helixParticipantManager, ControllerMetrics controllerMetrics) { _helixManager = helixParticipantManager; _controllerMetrics = controllerMetrics; _instanceId = helixParticipantManager.getInstanceName(); _leadForPartitions = ConcurrentHashMap.newKeySet(); _controllerLeadershipFetchingThread = new Thread("ControllerLeadershipFetchingThread") { @Override public void run() { while (true) { try { synchronized (LeadControllerManager.this) { if (_isShuttingDown) { return; } if (isHelixLeader()) { if (!_amIHelixLeader) { _amIHelixLeader = true; LOGGER.warn("Becoming leader without getting Helix change callback"); _controllerMetrics .addMeteredGlobalValue(ControllerMeter.CONTROLLER_LEADERSHIP_CHANGE_WITHOUT_CALLBACK, 1L); } _controllerMetrics.setValueOfGlobalGauge(ControllerGauge.PINOT_CONTROLLER_LEADER, 1L); } else { if (_amIHelixLeader) { _amIHelixLeader = false; LOGGER.warn("Losing leadership without getting Helix change callback"); _controllerMetrics .addMeteredGlobalValue(ControllerMeter.CONTROLLER_LEADERSHIP_CHANGE_WITHOUT_CALLBACK, 1L); } _controllerMetrics.setValueOfGlobalGauge(ControllerGauge.PINOT_CONTROLLER_LEADER, 0L); } LeadControllerManager.this.wait(CONTROLLER_LEADERSHIP_FETCH_INTERVAL_MS); } } catch (Exception e) { LOGGER.error("Caught exception within controller leadership fetching thread", e); } } } }; } LeadControllerManager(HelixManager helixParticipantManager, ControllerMetrics controllerMetrics); boolean isLeaderForTable(String tableName); synchronized void addPartitionLeader(String partitionName); synchronized void removePartitionLeader(String partitionName); synchronized void start(); void stop(); }
LeadControllerManager { public LeadControllerManager(HelixManager helixParticipantManager, ControllerMetrics controllerMetrics) { _helixManager = helixParticipantManager; _controllerMetrics = controllerMetrics; _instanceId = helixParticipantManager.getInstanceName(); _leadForPartitions = ConcurrentHashMap.newKeySet(); _controllerLeadershipFetchingThread = new Thread("ControllerLeadershipFetchingThread") { @Override public void run() { while (true) { try { synchronized (LeadControllerManager.this) { if (_isShuttingDown) { return; } if (isHelixLeader()) { if (!_amIHelixLeader) { _amIHelixLeader = true; LOGGER.warn("Becoming leader without getting Helix change callback"); _controllerMetrics .addMeteredGlobalValue(ControllerMeter.CONTROLLER_LEADERSHIP_CHANGE_WITHOUT_CALLBACK, 1L); } _controllerMetrics.setValueOfGlobalGauge(ControllerGauge.PINOT_CONTROLLER_LEADER, 1L); } else { if (_amIHelixLeader) { _amIHelixLeader = false; LOGGER.warn("Losing leadership without getting Helix change callback"); _controllerMetrics .addMeteredGlobalValue(ControllerMeter.CONTROLLER_LEADERSHIP_CHANGE_WITHOUT_CALLBACK, 1L); } _controllerMetrics.setValueOfGlobalGauge(ControllerGauge.PINOT_CONTROLLER_LEADER, 0L); } LeadControllerManager.this.wait(CONTROLLER_LEADERSHIP_FETCH_INTERVAL_MS); } } catch (Exception e) { LOGGER.error("Caught exception within controller leadership fetching thread", e); } } } }; } LeadControllerManager(HelixManager helixParticipantManager, ControllerMetrics controllerMetrics); boolean isLeaderForTable(String tableName); synchronized void addPartitionLeader(String partitionName); synchronized void removePartitionLeader(String partitionName); synchronized void start(); void stop();  }