diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-04-14 18:02:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-14 18:02:40 +0200 |
commit | d8298478feb34ba096ee1452270a92f29f178439 (patch) | |
tree | 4e76f91b43fdcf8e6e2d4b6e44e8fecb226a595e /config-model | |
parent | 93a6738088362485e9b6acdb414ab1aa60ae536f (diff) | |
parent | e4c098e2a56a46b973924d4889e3e8f73ef8f6a3 (diff) |
Merge pull request #12891 from vespa-engine/hmusum/do-not-send-hint-about-files-to-distribute-when-on-hosted
Do not send hint about files to download when on hosted
Diffstat (limited to 'config-model')
8 files changed, 55 insertions, 59 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java b/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java index 13f271ebe9d..87d6554f691 100644 --- a/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java +++ b/config-model/src/main/java/com/yahoo/config/model/test/MockRoot.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Set; @@ -66,7 +67,7 @@ public class MockRoot extends AbstractConfigProducerRoot { super(rootConfigId); hostSystem = new HostSystem(this, "hostsystem", deployState.getProvisioner(), deployState.getDeployLogger()); this.deployState = deployState; - fileDistributor = new FileDistributor(deployState.getFileRegistry(), null); + fileDistributor = new FileDistributor(deployState.getFileRegistry(), List.of(), deployState.isHosted()); } public FileDistributionConfigProducer getFileDistributionConfigProducer() { 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 72c475fb091..75b33e184d9 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 @@ -461,6 +461,7 @@ public abstract class AbstractService extends AbstractConfigProducer<AbstractCon public FileReference sendFile(String relativePath) { return getRoot().getFileDistributor().sendFileToHost(relativePath, getHost()); } + public FileReference sendUri(String uri) { return getRoot().getFileDistributor().sendUriToHost(uri, getHost()); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java index 89cd5c2e735..6f2123f248c 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java @@ -209,7 +209,8 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri /** Creates a mutable model with no services instantiated */ public static VespaModel createIncomplete(DeployState deployState) throws IOException, SAXException { - return new VespaModel(new NullConfigModelRegistry(), deployState, false, new FileDistributor(deployState.getFileRegistry(), null)); + return new VespaModel(new NullConfigModelRegistry(), deployState, false, + new FileDistributor(deployState.getFileRegistry(), List.of(), deployState.isHosted())); } private void validateWrapExceptions() { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminBuilderBase.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminBuilderBase.java index a146e2cd7e7..d2f06da992c 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminBuilderBase.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomAdminBuilderBase.java @@ -71,7 +71,7 @@ public abstract class DomAdminBuilderBase extends VespaDomBuilder.DomConfigProdu Monitoring monitoring = getMonitoring(XML.getChild(adminElement,"monitoring"), deployState.isHosted()); Metrics metrics = new MetricsBuilder(applicationType, predefinedMetricSets) .buildMetrics(XML.getChild(adminElement, "metrics")); - FileDistributionConfigProducer fileDistributionConfigProducer = getFileDistributionConfigProducer(parent); + FileDistributionConfigProducer fileDistributionConfigProducer = getFileDistributionConfigProducer(parent, deployState.isHosted()); Admin admin = new Admin(parent, monitoring, metrics, multitenant, fileDistributionConfigProducer, deployState.isHosted()); admin.setApplicationType(applicationType); @@ -81,8 +81,8 @@ public abstract class DomAdminBuilderBase extends VespaDomBuilder.DomConfigProdu return admin; } - private FileDistributionConfigProducer getFileDistributionConfigProducer(AbstractConfigProducer parent) { - return new FileDistributionConfigProducer(parent, fileRegistry, configServerSpecs); + private FileDistributionConfigProducer getFileDistributionConfigProducer(AbstractConfigProducer parent, boolean isHosted) { + return new FileDistributionConfigProducer(parent, fileRegistry, configServerSpecs, isHosted); } protected abstract void doBuildAdmin(DeployState deployState, Admin admin, Element adminE); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProducer.java b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProducer.java index 9662540e8df..2c6808b5773 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProducer.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProducer.java @@ -20,8 +20,9 @@ public class FileDistributionConfigProducer extends AbstractConfigProducer { private final Map<Host, FileDistributionConfigProvider> fileDistributionConfigProviders = new IdentityHashMap<>(); private final FileDistributor fileDistributor; - public FileDistributionConfigProducer(AbstractConfigProducer ancestor, FileRegistry fileRegistry, List<ConfigServerSpec> configServerSpec) { - this(ancestor, new FileDistributor(fileRegistry, configServerSpec)); + public FileDistributionConfigProducer(AbstractConfigProducer ancestor, FileRegistry fileRegistry, + List<ConfigServerSpec> configServerSpec, boolean isHosted) { + this(ancestor, new FileDistributor(fileRegistry, configServerSpec, isHosted)); } private FileDistributionConfigProducer(AbstractConfigProducer parent, FileDistributor fileDistributor) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java index 576b009c846..5ccf86f9ba8 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java @@ -11,7 +11,10 @@ import com.yahoo.vespa.model.Host; import java.util.*; /** - * Responsible for directing distribution of files to hosts. + * Sends RPC requests to hosts (tenant hosts and config servers) to start download of files. This is used during prepare + * of an application. Services themselves will also request files, the work done in this class is done so that hosts can + * start downloading files before services gets new config that needs these files. This also tries to make sure that + * all config servers (not just the one where the application was deployed) have the files available. * * @author Tony Vaagenes */ @@ -19,61 +22,42 @@ public class FileDistributor { private final FileRegistry fileRegistry; private final List<ConfigServerSpec> configServerSpecs; + private final boolean isHosted; - /** A map from files to the hosts to which that file should be distributed */ + /** A map from file reference to the hosts to which that file reference should be distributed */ private final Map<FileReference, Set<Host>> filesToHosts = new LinkedHashMap<>(); + public FileDistributor(FileRegistry fileRegistry, List<ConfigServerSpec> configServerSpecs, boolean isHosted) { + this.fileRegistry = fileRegistry; + this.configServerSpecs = configServerSpecs; + this.isHosted = isHosted; + } + /** * Adds the given file to the associated application packages' registry of file and marks the file - * for distribution to the given hosts. + * for distribution to the given host. * <b>Note: This class receives ownership of the given collection.</b> * * @return the reference to the file, created by the application package */ - public FileReference sendFileToHosts(String relativePath, Collection<Host> hosts) { - FileReference reference = fileRegistry.addFile(relativePath); - addToFilesToDistribute(reference, hosts); - - return reference; + public FileReference sendFileToHost(String relativePath, Host host) { + return addFileReference(fileRegistry.addFile(relativePath), host); } /** * Adds the given file to the associated application packages' registry of file and marks the file - * for distribution to the given hosts. + * for distribution to the given host. * <b>Note: This class receives ownership of the given collection.</b> * * @return the reference to the file, created by the application package */ - public FileReference sendUriToHosts(String uri, Collection<Host> hosts) { - FileReference reference = fileRegistry.addUri(uri); - if (reference != null) { - addToFilesToDistribute(reference, hosts); - } - - return reference; - } - - /** Same as sendFileToHost(relativePath,Collections.singletonList(host) */ - public FileReference sendFileToHost(String relativePath, Host host) { - return sendFileToHosts(relativePath, Arrays.asList(host)); - } - public FileReference sendUriToHost(String uri, Host host) { - return sendUriToHosts(uri, Arrays.asList(host)); - } - - private void addToFilesToDistribute(FileReference reference, Collection<Host> hosts) { - Set<Host> oldHosts = getHosts(reference); - oldHosts.addAll(hosts); - } - - private Set<Host> getHosts(FileReference reference) { - return filesToHosts.computeIfAbsent(reference, k -> new HashSet<>()); + return addFileReference(fileRegistry.addUri(uri), host); } - public FileDistributor(FileRegistry fileRegistry, List<ConfigServerSpec> configServerSpecs) { - this.fileRegistry = fileRegistry; - this.configServerSpecs = configServerSpecs; + private FileReference addFileReference(FileReference reference, Host host) { + filesToHosts.computeIfAbsent(reference, k -> new HashSet<>()).add(host); + return reference; } /** Returns the files which has been marked for distribution to the given host */ @@ -107,16 +91,20 @@ public class FileDistributor { // should only be called during deploy public void sendDeployedFiles(FileDistribution dbHandler) { String fileSourceHost = fileSourceHost(); - for (Host host : getTargetHosts()) { - if ( ! host.getHostname().equals(fileSourceHost)) { - dbHandler.startDownload(host.getHostname(), ConfigProxy.BASEPORT, filesToSendToHost(host)); - } - } + // Ask other config servers to download, for redundancy - if (configServerSpecs != null) - configServerSpecs.stream() - .filter(configServerSpec -> !configServerSpec.getHostName().equals(fileSourceHost)) - .forEach(spec -> dbHandler.startDownload(spec.getHostName(), spec.getConfigServerPort(), allFilesToSend())); + configServerSpecs.stream() + .filter(spec -> !spec.getHostName().equals(fileSourceHost)) + .forEach(spec -> dbHandler.startDownload(spec.getHostName(), spec.getConfigServerPort(), allFilesToSend())); + + // Skip starting download for application hosts when on hosted, since this is just a hint and requests for files + // will fail until the application is activated (this call is done when preparing an application deployment) + // due to authorization of RPC requests on config servers only considering files belonging to active applications + if (isHosted) return; + + getTargetHosts().stream() + .filter(host -> ! host.getHostname().equals(fileSourceHost)) + .forEach(host -> dbHandler.startDownload(host.getHostname(), ConfigProxy.BASEPORT, filesToSendToHost(host))); } } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterUtils.java b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterUtils.java index db9153fcf23..b1550d90f35 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterUtils.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterUtils.java @@ -60,7 +60,7 @@ public class ContentClusterUtils { public static ContentCluster createCluster(String clusterXml, MockRoot root) { Document doc = XML.getDocument(clusterXml); Admin admin = new Admin(root, new DefaultMonitoring("vespa", 60), new Metrics(), false, - new FileDistributionConfigProducer(root, new MockFileRegistry(), null), + new FileDistributionConfigProducer(root, new MockFileRegistry(), List.of(), false), root.getDeployState().isHosted()); ConfigModelContext context = ConfigModelContext.create(null, root.getDeployState(), null,null, root, null); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/FileDistributorTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/FileDistributorTestCase.java index 131a5344116..55672c5aa16 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/FileDistributorTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/FileDistributorTestCase.java @@ -10,31 +10,34 @@ import org.junit.Test; import java.io.File; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Set; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; /** * @author bratseth */ public class FileDistributorTestCase { + @Test public void fileDistributor() { MockHosts hosts = new MockHosts(); - FileDistributor fileDistributor = new FileDistributor(new MockFileRegistry(), null); + FileDistributor fileDistributor = new FileDistributor(new MockFileRegistry(), List.of(), false); String file1 = "component/path1"; String file2 = "component/path2"; - FileReference ref1 = fileDistributor.sendFileToHosts(file1, Arrays.asList(hosts.host1, hosts.host2)); - FileReference ref2 = fileDistributor.sendFileToHosts(file2, Arrays.asList(hosts.host3)); + FileReference ref1 = fileDistributor.sendFileToHost(file1, hosts.host1); + fileDistributor.sendFileToHost(file1, hosts.host2); // same file reference as above + FileReference ref2 = fileDistributor.sendFileToHost(file2, hosts.host3); assertEquals(new HashSet<>(Arrays.asList(hosts.host1, hosts.host2, hosts.host3)), fileDistributor.getTargetHosts()); - assertTrue( ref1 != null ); - assertTrue( ref2 != null ); + assertNotNull(ref1); + assertNotNull(ref2); MockFileDistribution dbHandler = new MockFileDistribution(); fileDistributor.sendDeployedFiles(dbHandler); @@ -54,4 +57,5 @@ public class FileDistributorTestCase { return null; } } + } |