@Override public HostDomain getHostDomain(Domain domain) { // TODO: this should be done with a map and caching try { for (HostDomain hostDomain : getAssignedDomains()) { if (hostDomain.getDomain().equals(domain)) { return hostDomain; } } } catch (IOException e) { throw new RuntimeException(e); } return null; }
public PartitionUpdateTask(HostDomain hostDomain, HostDomainPartition partition, PartitionUpdateTaskStatisticsAggregator partitionUpdateTaskStatisticsAggregator, List<Throwable> encounteredThrowables, DiskPartitionAssignment assignment) { this.hostDomain = hostDomain; this.encounteredThrowables = encounteredThrowables; this.domain = hostDomain.getDomain(); this.partition = partition; this.assignment = assignment; this.partitionUpdateTaskStatisticsAggregator = partitionUpdateTaskStatisticsAggregator; // Register itself in the aggregator partitionUpdateTaskStatisticsAggregator.register(this); }
public String getName() { return hostDomain.getDomain().getName(); }
private void garbageCollectHostDomains(Host host) throws IOException { // Delete deletable domains and partitions for (HostDomain hostDomain : host.getAssignedDomains()) { // Host domain does not contain anymore partitions. Delete it LOG.info("Host Domain " + hostDomain + " is assigned " + hostDomain.getPartitions().size() + " partitions."); if (hostDomain.getPartitions().size() == 0) { LOG.info("Garbage collecting Host Domain " + hostDomain + " as it is not used anymore."); host.removeDomain(hostDomain.getDomain()); } } }
DomainAccessor(HostDomain hostDomain, PartitionAccessor[] partitionAccessors, Partitioner partitioner, int getTimerAggregatorWindow) throws IOException { this.hostDomain = hostDomain; this.partitionAccessors = partitionAccessors; this.partitioner = partitioner; this.getRequestsTimerAggregator = new HankTimerEventAggregator("GET " + hostDomain.getDomain().getName(), getTimerAggregatorWindow); }
@Override public int compareTo(HostDomain hostDomain) { return getDomain().compareTo(hostDomain.getDomain()); }
@Override public void runCore() throws IOException { Map<Domain, RuntimeStatisticsAggregator> runtimeStatisticsAggregators = new HashMap<Domain, RuntimeStatisticsAggregator>(); // Compute aggregate partition runtime statistics for (DomainAccessor domainAccessor : domainAccessors) { if (domainAccessor != null) { runtimeStatisticsAggregators.put(domainAccessor.getHostDomain().getDomain(), domainAccessor.getRuntimeStatistics()); } } // Set statistics Hosts.setRuntimeStatistics(host, runtimeStatisticsAggregators); }
private void deletePartition(HostDomain hostDomain, HostDomainPartition partition) throws IOException { LOG.info("Deleting Domain " + hostDomain.getDomain().getName() + " partition " + partition.getPartitionNumber()); Deleter deleter = hostDomain.getDomain().getStorageEngine().getDeleter(assignment, partition.getPartitionNumber()); deleter.delete(); hostDomain.removePartition(partition.getPartitionNumber()); }
StorageEngine storageEngine = hostDomain.getDomain().getStorageEngine();
public static Map<Domain, Map<Integer, Set<Host>>> domainToPartitionToHostsServing(RingGroup ringGroup, HostReplicaStatus config) throws IOException { Map<Domain, Map<Integer, Set<Host>>> result = new HashMap<>(); // Compute num replicas fully serving for all partitions for (Ring ring : ringGroup.getRings()) { for (Host h : ring.getHosts()) { if (isFullyServing(h, false, config)) { for (HostDomain hostDomain : h.getAssignedDomains()) { Domain domain = hostDomain.getDomain(); for (HostDomainPartition partition : hostDomain.getPartitions()) { if (!partition.isDeletable() && partition.getCurrentDomainVersion() != null) { int partitionNumber = partition.getPartitionNumber(); Map<Integer, Set<Host>> partitionToNumFullyServing = result.get(domain); if (partitionToNumFullyServing == null) { partitionToNumFullyServing = new HashMap<Integer, Set<Host>>(); result.put(domain, partitionToNumFullyServing); } if (!partitionToNumFullyServing.containsKey(partitionNumber)) { partitionToNumFullyServing.put(partitionNumber, new HashSet<Host>()); } partitionToNumFullyServing.get(partitionNumber).add(h); } } } } } } return result; }
public HankResponse get(ByteBuffer key, ReaderResult result) throws IOException { HankTimer timer = getRequestsTimerAggregator.getTimer(); try { int partition = partitioner.partition(key, partitionAccessors.length); PartitionAccessor partitionAccessor = partitionAccessors[partition]; if (partitionAccessor == null) { LOG.error("Failed to perform get because of an Exception: wrong host for domain: " + hostDomain.getDomain().getName() + ", partition: " + partition + ", key: " + BytesUtils.bytesToHexString(key) + ", response: " + WRONG_HOST); return WRONG_HOST; } return partitionAccessor.get(key, result); } finally { getRequestsTimerAggregator.add(timer); } }
private ArrayList<PartitionUpdateTask> buildPartitionUpdateTasks( PartitionUpdateTaskStatisticsAggregator partitionUpdateTaskStatisticsAggregator, List<Throwable> encounteredThrowables) throws IOException { ArrayList<PartitionUpdateTask> partitionUpdateTasks = new ArrayList<PartitionUpdateTask>(); for (HostDomain hostDomain : host.getAssignedDomains()) { StorageEngine engine = hostDomain.getDomain().getStorageEngine(); DiskPartitionAssignment assignments = engine.getDataDirectoryPerPartition(configurator, getPartitionNumbers(hostDomain.getPartitions())); for (HostDomainPartition partition : hostDomain.getPartitions()) { partitionUpdateTasks.add( new PartitionUpdateTask( hostDomain, partition, partitionUpdateTaskStatisticsAggregator, encounteredThrowables, assignments)); } } // Sort update tasks per partition id, so that we update domains concurrently but in order of partition number Collections.sort(partitionUpdateTasks); return partitionUpdateTasks; }
Domain domain = hostDomain.getDomain(); if (domain == null) { throw new IOException(String.format("Could not load Domain from HostDomain %s", hostDomain.toString()));
public static ServingStatusAggregator computeServingStatusAggregator(Host host, DomainGroup domainGroup) throws IOException { ServingStatusAggregator result = new ServingStatusAggregator(); for (HostDomain hostDomain : host.getAssignedDomains()) { DomainAndVersion domainVersion = domainGroup.getDomainVersion(hostDomain.getDomain()); // Ignore domains that are not relevant if (domainVersion != null) { for (HostDomainPartition partition : hostDomain.getPartitions()) { // Ignore deletable partitions if (!partition.isDeletable()) { // Check if partition is served and up to date boolean servedAndUpToDate = host.getState() == HostState.SERVING && partition.getCurrentDomainVersion() != null && partition.getCurrentDomainVersion().equals(domainVersion.getVersionNumber()); // Aggregate counts result.add(hostDomain.getDomain(), partition.getPartitionNumber(), servedAndUpToDate); } } } } return result; }
if (!domains.contains(hostDomain.getDomain())) { for (HostDomainPartition partition : hostDomain.getPartitions()) { if (!partition.isDeletable()) {
private boolean isInUse(Domain domain) throws IOException { String domainName = domain.getName(); for (RingGroup rg : coordinator.getRingGroups()) { for (Ring ring : rg.getRings()) { for (Host host : ring.getHosts()) { for (HostDomain hostDomain : host.getAssignedDomains()) { if(hostDomain.getDomain().getName().equals(domainName)){ return true; } } } } DomainGroup dg = rg.getDomainGroup(); for (Domain dgd : dg.getDomains()) { if(dgd.getName().equals(domainName)){ return true; } } } return false; }
if (!domains.contains(hostDomain.getDomain())) { for (HostDomainPartition partition : hostDomain.getPartitions()) { if (!partition.isDeletable()) {
@Test public void testDomains() throws Exception { final ZkHost host = ZkHost.create(getZk(), coordinator, getRoot(), ADDRESS, null, Collections.emptyList()); assertEquals(0, host.getAssignedDomains().size()); host.addDomain(d0); WaitUntil.orDie(() -> { try { return !host.getAssignedDomains().isEmpty(); } catch (IOException e) { throw new RuntimeException(e); } }); HostDomain hostDomain = (HostDomain) host.getAssignedDomains().toArray()[0]; assertEquals(0, hostDomain.getDomain().getId()); assertEquals(0, host.getHostDomain(d0).getDomain().getId()); }