diff options
author | Jon Bratseth <jonbratseth@yahoo.com> | 2016-07-04 11:12:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-04 11:12:19 +0200 |
commit | 9eda0b4e5cc178e744c0f529b444dc425f282832 (patch) | |
tree | 5acdf44bf6ce48fa64fccc1242ffc35f6b9e477f | |
parent | 1c64210aa00cdc6a462a66b69db4dff664a2242d (diff) | |
parent | 7dd187b4a3c78fc285ec2abc6ff695f2db16ef71 (diff) |
Merge pull request #293 from yahoo/bratseth/only-one-clustercontroller-per-host-3
Bratseth/only one clustercontroller per host 3
7 files changed, 108 insertions, 27 deletions
diff --git a/application/src/main/java/com/yahoo/application/container/Processing.java b/application/src/main/java/com/yahoo/application/container/Processing.java index 1511024364d..085067f707c 100644 --- a/application/src/main/java/com/yahoo/application/container/Processing.java +++ b/application/src/main/java/com/yahoo/application/container/Processing.java @@ -22,6 +22,7 @@ import java.io.IOException; */ @Beta public final class Processing extends ProcessingBase<Request, Response, Processor> { + private final ProcessingHandler handler; Processing(ProcessingHandler handler) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java index 13d85c3a955..187a6222648 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java @@ -114,7 +114,7 @@ public abstract class AbstractService extends AbstractConfigProducer<AbstractCon } if (hostResource == null) { throw new RuntimeException("No host found for service '" + getServiceName() + "'. " + - "The hostalias is probably missing from hosts.xml."); + "The hostalias is probably missing from hosts.xml."); } id = getIndex(hostResource); ports = hostResource.allocateService(this, getInstanceWantedPort(userPort)); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerCluster.java index b82f58fbb40..3847c32dfb2 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerCluster.java @@ -43,7 +43,7 @@ public class ClusterControllerCluster extends AbstractConfigProducer<ContainerCl @Override public void getConfig(ZookeepersConfig.Builder builder) { - final Collection<String> controllerHosts = new ArrayList<>(); + Collection<String> controllerHosts = new ArrayList<>(); for (Container container : containerCluster.getContainers()) { controllerHosts.add(container.getHostName() + ":" + ZK_CLIENT_PORT); } @@ -73,5 +73,6 @@ public class ClusterControllerCluster extends AbstractConfigProducer<ContainerCl } } } + } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java index 8350ac3fc79..295baccaff6 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java @@ -16,6 +16,7 @@ import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol; import com.yahoo.metrics.MetricsmanagerConfig; import com.yahoo.config.model.producer.AbstractConfigProducer; import com.yahoo.vespa.model.HostResource; +import com.yahoo.vespa.model.Service; import com.yahoo.vespa.model.admin.Admin; import com.yahoo.vespa.model.admin.Metric; import com.yahoo.vespa.model.admin.MetricsConsumer; @@ -319,8 +320,8 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri private List<HostResource> drawControllerHosts(int count, StorageGroup rootGroup, Collection<ContainerModel> containers) { List<HostResource> hosts = drawContentHostsRecursively(count, rootGroup); - //if (hosts.size() < count) // supply with containers TODO: Reactivate - // hosts.addAll(drawContainerHosts(count - hosts.size(), containers)); + if (hosts.size() < count) // supply with containers + hosts.addAll(drawContainerHosts(count - hosts.size(), containers, hosts)); if (hosts.size() % 2 == 0) // ZK clusters of even sizes are less available (even in the size=2 case) hosts = hosts.subList(0, hosts.size()-1); return hosts; @@ -333,13 +334,23 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri * This will draw the same nodes each time it is * invoked if cluster names and node indexes are unchanged. */ - private List<HostResource> drawContainerHosts(int count, Collection<ContainerModel> containerClusters) { + private List<HostResource> drawContainerHosts(int count, Collection<ContainerModel> containerClusters, + List<HostResource> usedHosts) { if (containerClusters.isEmpty()) return Collections.emptyList(); - List<HostResource> hosts = new ArrayList<>(); + List<HostResource> allHosts = new ArrayList<>(); for (ContainerCluster cluster : clustersSortedByName(containerClusters)) - hosts.addAll(hostResourcesSortedByIndex(cluster)); - return hosts.subList(0, Math.min(hosts.size(), count)); + allHosts.addAll(hostResourcesSortedByIndex(cluster)); + + // Don't use hosts already selected to be assigned a cluster controllers as part of building this, + // and don't use hosts which already have one. One physical host may have many roles but can only + // have one cluster controller + List<HostResource> hostsWithoutClusterController = allHosts.stream() + .filter(h -> ! hostIsIn(h.getHostName(), usedHosts)) + .filter(h -> ! hostHasClusterController(h.getHostName(), allHosts)) + .collect(Collectors.toList()); + + return hostsWithoutClusterController.subList(0, Math.min(hostsWithoutClusterController.size(), count)); } private List<ContainerCluster> clustersSortedByName(Collection<ContainerModel> containerModels) { @@ -356,6 +367,32 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri .collect(Collectors.toList()); } + /** Returns whether any host having the given hostname has a cluster controller */ + private boolean hostHasClusterController(String hostname, List<HostResource> hosts) { + for (HostResource host : hosts) { + if ( ! host.getHostName().equals(hostname)) continue; + + if (hasClusterController(host)) + return true; + } + return false; + } + + /** Returns whether this host name is in the given list of hosts */ + private boolean hostIsIn(String hostname, List<HostResource> hosts) { + for (HostResource host : hosts) + if (host.getHostName().equals(hostname)) + return true; + return false; + } + + private boolean hasClusterController(HostResource host) { + for (Service service : host.getServices()) + if (service instanceof ClusterControllerContainer) + return true; + return false; + } + /** * Draw <code>count</code> nodes from as many different content groups below this as possible. * This will only achieve maximum spread in the case where the groups are balanced and never on the same diff --git a/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java b/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java index e4f405efb93..1c7940fdc8f 100644 --- a/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java @@ -458,7 +458,7 @@ public class ModelProvisioningTest { ContentCluster cluster = model.getContentClusters().get("bar"); ContainerCluster clusterControllers = cluster.getClusterControllers(); - assertEquals(1, clusterControllers.getContainers().size()); // TODO: Expected 5 with this feature reactivated + assertEquals(5, clusterControllers.getContainers().size()); } public void testClusterControllersAreNotPlacedOnRetiredNodes() { @@ -619,17 +619,63 @@ public class ModelProvisioningTest { " </content>" + "</services>"; - int numberOfHosts = 5; VespaModelTester tester = new VespaModelTester(); - tester.addHosts(numberOfHosts); + tester.addHosts(5); VespaModel model = tester.createModel(services, true); - assertThat(model.getRoot().getHostSystem().getHosts().size(), is(numberOfHosts)); ContentCluster cluster = model.getContentClusters().get("bar"); ContainerCluster clusterControllers = cluster.getClusterControllers(); - assertEquals(1, clusterControllers.getContainers().size()); // TODO: Expected 3 with this feature reactivated + assertEquals(3, clusterControllers.getContainers().size()); } + @Test + public void test2ContentNodesOn2ClustersWithContainerClusterProducesMixedClusterControllerCluster() throws ParseException { + String services = + "<?xml version='1.0' encoding='utf-8' ?>\n" + + "<services>" + + " <container version='1.0' id='container'>" + + " <nodes count='3' flavor='container-node'/>" + + " </container>" + + " <content version='1.0' id='content1'>" + + " <redundancy>2</redundancy>" + + " <documents>" + + " <document type='type1' mode='index'/>" + + " </documents>" + + " <nodes count='2' flavor='content1-node'/>" + + " </content>" + + " <content version='1.0' id='content2'>" + + " <redundancy>2</redundancy>" + + " <documents>" + + " <document type='type1' mode='index'/>" + + " </documents>" + + " <nodes count='2' flavor='content2-node'/>" + + " </content>" + + "</services>"; + + VespaModelTester tester = new VespaModelTester(); + // use different flavors to make the test clearer + tester.addHosts("container-node", 3); + tester.addHosts("content1-node", 2); + tester.addHosts("content2-node", 2); + VespaModel model = tester.createModel(services, true); + + ContentCluster cluster1 = model.getContentClusters().get("content1"); + ContainerCluster clusterControllers1 = cluster1.getClusterControllers(); + assertEquals(3, clusterControllers1.getContainers().size()); + assertEquals("content1-node0", clusterControllers1.getContainers().get(0).getHostName()); + assertEquals("content1-node1", clusterControllers1.getContainers().get(1).getHostName()); + assertEquals("container-node0", clusterControllers1.getContainers().get(2).getHostName()); + + ContentCluster cluster2 = model.getContentClusters().get("content2"); + ContainerCluster clusterControllers2 = cluster2.getClusterControllers(); + assertEquals(3, clusterControllers2.getContainers().size()); + assertEquals("content2-node0", clusterControllers2.getContainers().get(0).getHostName()); + assertEquals("content2-node1", clusterControllers2.getContainers().get(1).getHostName()); + assertEquals("We do not pick the container used to supplement another cluster", + "container-node1", clusterControllers2.getContainers().get(2).getHostName()); + } + + @Test public void testExplicitDedicatedClusterControllers() { String services = "<?xml version='1.0' encoding='utf-8' ?>\n" + diff --git a/container-core/src/main/java/com/yahoo/processing/handler/ProcessingResponse.java b/container-core/src/main/java/com/yahoo/processing/handler/ProcessingResponse.java index 2ce345ad355..d9bbd30a474 100644 --- a/container-core/src/main/java/com/yahoo/processing/handler/ProcessingResponse.java +++ b/container-core/src/main/java/com/yahoo/processing/handler/ProcessingResponse.java @@ -38,7 +38,6 @@ public class ProcessingResponse extends AsyncHttpResponse { private final com.yahoo.processing.Request processingRequest; private final com.yahoo.processing.Response processingResponse; - private final Executor renderingExecutor; private final Execution execution; private final Renderer renderer; @@ -46,24 +45,21 @@ public class ProcessingResponse extends AsyncHttpResponse { private boolean explicitStatusSet = false; @SuppressWarnings("unchecked") - public ProcessingResponse( - int status, - final com.yahoo.processing.Request processingRequest, - final com.yahoo.processing.Response processingResponse, - final Renderer renderer, - final Executor renderingExecutor, final Execution execution) { + public ProcessingResponse(int status, com.yahoo.processing.Request processingRequest, + com.yahoo.processing.Response processingResponse, + Renderer renderer, + Executor renderingExecutor, Execution execution) { super(status); this.processingRequest = processingRequest; this.processingResponse = processingResponse; - this.renderingExecutor = renderingExecutor; this.execution = execution; this.renderer = renderer; } @SuppressWarnings("unchecked") @Override - public void render(final OutputStream stream, final ContentChannel channel, - final CompletionHandler completionHandler) throws IOException { + public void render(OutputStream stream, ContentChannel channel, + CompletionHandler completionHandler) throws IOException { if (renderer instanceof AsynchronousRenderer) { AsynchronousRenderer asyncRenderer = (AsynchronousRenderer)renderer; asyncRenderer.setNetworkWiring(channel, completionHandler); diff --git a/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java b/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java index cc186ea21ee..eeb4a2ef36d 100644 --- a/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java +++ b/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java @@ -93,8 +93,8 @@ public abstract class AsynchronousSectionedRenderer<RESPONSE extends Response> e private static final Logger logger = Logger.getLogger(AsynchronousSectionedRenderer.class.getName()); - // NOTE: Renderers are *prototype objects* - a new instance is created for each rendering by invoking clone - // calling init() and then render(). + // NOTE: Renderers are *prototype objects* - a new instance is created for each rendering by invoking + // clone(), init() and then render(). // Hence any field which is not reinitialized in init() or render() will be *reused* in all rendering operations // across all threads! @@ -110,8 +110,8 @@ public abstract class AsynchronousSectionedRenderer<RESPONSE extends Response> e // This MUST be created in the init() method - see comment above private Object singleThreaded; - // Rendering threads should never block. - // Burst traffic may add work faster than we can complete it, so use an unbounded queue. + // Rendering threads should never block so use one thread per core. + // We should complete any work we have already started so use an unbounded queue. // The executor SHOULD be reused across all instances having the same prototype private final ThreadPoolExecutor renderingExecutor = createExecutor(); private static ThreadPoolExecutor createExecutor() { |