private void assertIsLeader() throws Exception { if (!isLeader()) { NimbusInfo leaderAddress = leaderElector.getLeader(); throw new RuntimeException("not a leader, current leader is " + leaderAddress); } }
private boolean isLeader() throws Exception { return leaderElector.isLeader(); }
leaderElector.addToLeaderLockQueue(); this.blobStore.startSyncBlobs();
blobListers.cleanup(); blobStore.shutdown(); leaderElector.close(); assignmentsDistributer.close(); ITopologyActionNotifierPlugin actionNotifier = nimbusTopologyActionNotifier;
@Override public NimbusSummary getLeader() throws AuthorizationException, TException { getLeaderCalls.mark(); checkAuthorization(null, null, "getClusterInfo"); List<NimbusSummary> nimbuses = stormClusterState.nimbuses(); NimbusInfo leader = leaderElector.getLeader(); for (NimbusSummary nimbusSummary : nimbuses) { if (leader.getHost().equals(nimbusSummary.get_host()) && leader.getPort() == nimbusSummary.get_port()) { nimbusSummary.set_uptime_secs(Time.deltaSecs(nimbusSummary.get_uptime_secs())); nimbusSummary.set_isLeader(true); return nimbusSummary; } } return null; }
private void blobSync() throws Exception { if ("distributed".equals(conf.get(Config.STORM_CLUSTER_MODE))) { if (!this.leaderElector.isLeader()) { IStormClusterState state = stormClusterState; NimbusInfo nimbusInfo = this.nimbusInfo; BlobStore store = this; Set<String> allKeys = new HashSet<>(); for (Iterator<String> it = store.listKeys(); it.hasNext();) { allKeys.add(it.next()); } Set<String> zkKeys = new HashSet<>(state.blobstore(() -> { try { this.blobSync(); } catch (Exception e) { throw new RuntimeException(e); } })); LOG.debug("blob-sync blob-store-keys {} zookeeper-keys {}", allKeys, zkKeys); LocalFsBlobStoreSynchronizer sync = new LocalFsBlobStoreSynchronizer(store, conf); sync.setNimbusInfo(nimbusInfo); sync.setBlobStoreKeySet(allKeys); sync.setZookeeperKeySet(zkKeys); sync.setZkClient(zkClient); sync.syncBlobs(); } //else not leader (NOOP) } //else local (NOOP) }
NimbusInfo leader = leaderElector.getLeader(); for (NimbusSummary nimbusSummary : nimbuses) { nimbusSummary.set_uptime_secs(Time.deltaSecs(nimbusSummary.get_uptime_secs()));