public static boolean isUpToDate(Ring ring, DomainGroup domainGroup) throws IOException { for (Host host : ring.getHosts()) { if (!Hosts.isUpToDate(host, domainGroup)) { return false; } } return true; }
private void doAddHost(HttpServletRequest req, HttpServletResponse resp) throws IOException { String rgName = req.getParameter("rgName"); int ringNum = Integer.parseInt(req.getParameter("ringNum")); String hostname = req.getParameter("hostname").trim(); int portNum = Integer.parseInt(req.getParameter("port")); String flagsStr = req.getParameter("hostFlags"); coordinator.getRingGroup(rgName).getRing(ringNum).addHost( new PartitionServerAddress(hostname, portNum), Hosts.splitHostFlags(flagsStr)); resp.sendRedirect("/ring.jsp?g=" + rgName + "&n=" + ringNum); }
public static boolean isUpToDateOrMoreRecent(Host host, Collection<DomainAndVersion> domainVersions) throws IOException { if (!allPartitionsUpToDate(host, domainVersions, true)) { return false; } if (isAssignedDeletablePartition(host)) { return false; } return true; }
for (Host host : ring.getHostsSorted()) { if (ringGroupConductorMode != RingGroupConductorMode.PROACTIVE || Hosts.isOnline(host)) {
ThreeNestedMap<Domain, Integer, String, Long> domainPartitionBucketCounts) throws IOException { boolean isAssigned = partitionAssigner.isAssigned(host); boolean isUpToDate = Hosts.isUpToDate(host, domainGroup); boolean isFullyServing = PartitionUtils.isFullyServing(host, true, status); if (Hosts.isServing(host) && isAssigned && isUpToDate) { LOG.info("Host " + host.getAddress() + " is serving, assigned, and up-to-date. Do nothing."); return; if (Hosts.isIdle(host) && Hosts.isServable(host) && status == LiveReplicaStatus.UNDER_REPLICATED) { LOG.info("Host " + host.getAddress() + " is idle, servable, and not enough replicas are fully serving. Serve."); Hosts.enqueueCommandIfNotPresent(host, HostCommand.SERVE_DATA); return; if (Hosts.isIdle(host) && isAssigned && isUpToDate) { LOG.info("Host " + host.getAddress() + " is idle, assigned and up-to-date. Serve."); Hosts.enqueueCommandIfNotPresent(host, HostCommand.SERVE_DATA); return; if (Hosts.isIdle(host) && isAssigned && !isUpToDate && (status.isFullyReplicated() || !Hosts.isServable(host))) { Hosts.enqueueCommandIfNotPresent(host, HostCommand.EXECUTE_UPDATE); return; Hosts.enqueueCommandIfNotPresent(host, HostCommand.GO_TO_IDLE); removeFromReplicasFullyServing(domainToPartitionToHostsFullyServing, host); return;
public static Map<Host, Map<String, FilesystemStatisticsAggregator>> computeFilesystemStatistics(Ring ring) throws IOException { Map<Host, Map<String, FilesystemStatisticsAggregator>> result = new HashMap<Host, Map<String, FilesystemStatisticsAggregator>>(); for (Host host : ring.getHosts()) { result.put(host, Hosts.computeFilesystemStatistics(host)); } return result; }
public static FilesystemStatisticsAggregator computeFilesystemStatisticsForHost(Map<Host, Map<String, FilesystemStatisticsAggregator>> filesystemStatistics, Host host) { if (filesystemStatistics.containsKey(host)) { return Hosts.computeFilesystemStatisticsForHost(filesystemStatistics.get(host)); } else { return new FilesystemStatisticsAggregator(); } }
public static Map<Host, Map<Domain, RuntimeStatisticsAggregator>> computeRuntimeStatistics(Coordinator coordinator, Ring ring) throws IOException { Map<Host, Map<Domain, RuntimeStatisticsAggregator>> result = new HashMap<Host, Map<Domain, RuntimeStatisticsAggregator>>(); for (Host host : ring.getHosts()) { result.put(host, Hosts.computeRuntimeStatistics(coordinator, host)); } return result; }
protected HostData getHostData(Host host) throws IOException { HostData data = new HostData(); data.address = host.getAddress(); data.isOnline = Hosts.isOnline(host); data.state = host.getState(); data.statisticsString = host.getStatistic(Hosts.RUNTIME_STATISTICS_KEY); data.statisticsJson = getRuntimeStatsString(host); return data; }
if (Hosts.isOnline(host)) { throw new RuntimeException("Could not start a partition server for host " + host + " since it is already online.");
@Override protected void action(HttpServletRequest req, HttpServletResponse resp) throws IOException { String domainName = req.getParameter("name"); int numParts = Integer.parseInt(req.getParameter("numParts")); String storageEngineFactoryName = req.getParameter("storageEngineFactorySelect"); if (storageEngineFactoryName.equals("__other__")) { storageEngineFactoryName = req.getParameter("storageEngineFactoryName"); } String storageEngineOptions = req.getParameter("storageEngineOptions"); final String requiredHostFlags = req.getParameter("requiredHostFlags"); String partitionerName = req.getParameter("partitionerSelect"); if (partitionerName.equals("__other__")) { partitionerName = req.getParameter("partitionerOther"); } DomainController.this.coordinator.addDomain(domainName, numParts, storageEngineFactoryName, storageEngineOptions, partitionerName, Hosts.splitHostFlags(requiredHostFlags)); redirect("/domains.jsp", resp); } });
public static boolean isUpToDate(Ring ring, DomainGroup domainGroup, Domain domain) throws IOException { for (Host host : ring.getHosts()) { if (!Hosts.isUpToDate(host, domainGroup, domain)) { return false; } } return true; }
public static boolean isUpToDate(Host host, DomainGroup domainGroup) throws IOException { if (domainGroup == null || domainGroup.getDomainVersions() == null) { return false; } if (!allPartitionsUpToDate(host, domainGroup.getDomainVersions(), false)) { return false; } if (isAssignedDeletablePartition(host)) { return false; } return true; }
@Test public void testSetState() throws Exception { ZkHost host = ZkHost.create(getZk(), coordinator, getRoot(), ADDRESS, null, Collections.emptyList()); assertEquals(HostState.OFFLINE, host.getState()); assertFalse(Hosts.isOnline(host)); host.setState(HostState.IDLE); waitUntilHost(HostState.IDLE, host); assertEquals(HostState.IDLE, host.getState()); assertTrue(Hosts.isOnline(host)); host.setState(HostState.OFFLINE); waitUntilHost(HostState.OFFLINE, host); assertEquals(HostState.OFFLINE, host.getState()); assertFalse(Hosts.isOnline(host)); host.close(); }
@Override public List<String> getRequiredHostFlags() { String requiredHostFlagsStr = metadata.get().get_required_host_flags(); if (requiredHostFlagsStr == null) { return Collections.emptyList(); } else { return Hosts.splitHostFlags(requiredHostFlagsStr); } }
public static boolean isServingOnlyUpToDate(RingGroup ringGroup) throws IOException { DomainGroup domainGroup = ringGroup.getDomainGroup(); for (Ring ring : ringGroup.getRings()) { for (Host host : ring.getHosts()) { if (host.getState() == HostState.SERVING && !Hosts.isUpToDate(host, domainGroup)) { return false; } } } return true; }
@Test public void testCreateAndLoad() throws Exception { final ZkHost host = ZkHost.create(getZk(), coordinator, getRoot(), ADDRESS, null, Collections.emptyList()); assertEquals(ADDRESS, host.getAddress()); assertEquals(0, host.getCommandQueue().size()); assertNull(host.getCurrentCommand()); assertEquals(HostState.OFFLINE, host.getState()); assertFalse(Hosts.isOnline(host)); host.setEphemeralStatistic("a", "A"); host.setEphemeralStatistic("b", "B"); WaitUntil.orDie(() -> { try { return "A".equals(host.getStatistic("a")) && "B".equals(host.getStatistic("b")); } catch (IOException e) { throw new RuntimeException(e); } }); assertEquals("A", host.getStatistic("a")); assertEquals("B", host.getStatistic("b")); assertNull(host.getStatistic("c")); host.setAddress(OTHER_ADDRESS); WaitUntil.orDie(() -> host.getAddress().equals(OTHER_ADDRESS)); assertEquals(OTHER_ADDRESS, host.getAddress()); }
@Override public List<String> getFlags() throws IOException { String flags = metadata.get().get_flags(); return flags == null ? null : Hosts.splitHostFlags(flags); }
private void doUpdateDomain(HttpServletRequest req, HttpServletResponse resp) throws IOException { final String domainName = req.getParameter("name"); final String partitionerClassName = req.getParameter("partitionerClassName"); final String requiredHostFlags = req.getParameter("requiredHostFlags"); final String storageEngineFactoryClassName = req.getParameter("storageEngineFactoryClassName"); final String storageEngineOptions = req.getParameter("storageEngineOptions"); final Domain domain = coordinator.getDomain(domainName); if (domain == null) { throw new IOException("Could not get Domain '" + domainName + "' from Configurator."); } else { coordinator.updateDomain(domainName, domain.getNumParts(), storageEngineFactoryClassName, storageEngineOptions, partitionerClassName, Hosts.splitHostFlags(requiredHostFlags)); } resp.sendRedirect("/domains.jsp"); } }
private void doUpdate(HttpServletRequest req, HttpServletResponse resp) throws IOException { RingGroup rg = coordinator.getRingGroup(req.getParameter("g")); Ring r = rg.getRing(Integer.parseInt(req.getParameter("n"))); Host h = r.getHostByAddress(PartitionServerAddress.parse(URLEnc.decode(req.getParameter("h")))); h.setFlags(Hosts.splitHostFlags(req.getParameter("hostFlags"))); PartitionServerAddress address = PartitionServerAddress.parse(req.getParameter("hostAddress")); if (!h.getAddress().equals(address)) { h.setAddress(address); // Redirect to Ring (host address has changed) resp.sendRedirect("/ring.jsp?g=" + rg.getName() + "&n=" + r.getRingNumber()); } else { redirectBack(resp, rg, r, h); } }