public void dropSegment(String from, String segmentName, final LoadPeonCallback callback) { try { final DruidServer fromServer = serverInventoryView.getInventoryValue(from); if (fromServer == null) { throw new IAE("Unable to find server [%s]", from); } final DataSegment segment = fromServer.getSegment(segmentName); if (segment == null) { throw new IAE("Unable to find segment [%s] on server [%s]", segmentName, from); } final LoadQueuePeon dropPeon = loadManagementPeons.get(from); if (dropPeon == null) { throw new IAE("LoadQueuePeon hasn't been created yet for path [%s]", from); } if (!dropPeon.getSegmentsToDrop().contains(segment)) { dropPeon.dropSegment(segment, callback); } } catch (Exception e) { log.makeAlert(e, "Exception dropping segment %s", segmentName).emit(); callback.execute(); } }
private void stopBeingLeader() { synchronized (lock) { try { log.info("I am no longer the leader..."); for (String server : loadManagementPeons.keySet()) { LoadQueuePeon peon = loadManagementPeons.remove(server); peon.stop(); } loadManagementPeons.clear(); serviceAnnouncer.unannounce(self); serverInventoryView.stop(); databaseRuleManager.stop(); databaseSegmentManager.stop(); leader = false; } catch (Exception e) { log.makeAlert(e, "Unable to stopBeingLeader").emit(); } } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ServerHolder that = (ServerHolder) o; if (peon != null ? !peon.equals(that.peon) : that.peon != null) { return false; } if (server != null ? !server.equals(that.server) : that.server != null) { return false; } return true; }
public void moveSegment( String from, String to, String segmentName, final LoadPeonCallback callback) { try { final DruidServer fromServer = serverInventoryView.getInventoryValue(from); if (fromServer == null) { throw new IAE("Unable to find server [%s]", from); } final DruidServer toServer = serverInventoryView.getInventoryValue(to); if (toServer == null) { throw new IAE("Unable to find server [%s]", to); } if (to.equalsIgnoreCase(from)) { throw new IAE( "Redundant command to move segment [%s] from [%s] to [%s]", segmentName, from, to); } final DataSegment segment = fromServer.getSegment(segmentName); if (segment == null) { throw new IAE("Unable to find segment [%s] on server [%s]", segmentName, from); } final LoadQueuePeon loadPeon = loadManagementPeons.get(to); if (loadPeon == null) { throw new IAE("LoadQueuePeon hasn't been created yet for path [%s]", to); } final LoadQueuePeon dropPeon = loadManagementPeons.get(from); if (dropPeon == null) { throw new IAE("LoadQueuePeon hasn't been created yet for path [%s]", from); } final ServerHolder toHolder = new ServerHolder(toServer, loadPeon); if (toHolder.getAvailableSize() < segment.getSize()) { throw new IAE( "Not enough capacity on server [%s] for segment [%s]. Required: %,d, available: %,d.", to, segment, segment.getSize(), toHolder.getAvailableSize()); } final String toLoadQueueSegPath = ZKPaths.makePath(ZKPaths.makePath(zkPaths.getLoadQueuePath(), to), segmentName); final String toServedSegPath = ZKPaths.makePath( ZKPaths.makePath( serverInventoryView.getInventoryManagerConfig().getInventoryPath(), to), segmentName); loadPeon.loadSegment( segment, new LoadPeonCallback() { @Override protected void execute() { try { if (curator.checkExists().forPath(toServedSegPath) != null && curator.checkExists().forPath(toLoadQueueSegPath) == null && !dropPeon.getSegmentsToDrop().contains(segment)) { dropPeon.dropSegment(segment, callback); } else if (callback != null) { callback.execute(); } } catch (Exception e) { throw Throwables.propagate(e); } } }); } catch (Exception e) { log.makeAlert(e, "Exception moving segment %s", segmentName).emit(); callback.execute(); } }
public boolean isLoadingSegment(DataSegment segment) { return peon.getSegmentsToLoad().contains(segment); }
public Long getLoadQueueSize() { return peon.getLoadQueueSize(); }
@Override public int hashCode() { int result = server != null ? server.hashCode() : 0; result = 31 * result + (peon != null ? peon.hashCode() : 0); return result; }