diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-12-07 15:45:00 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-12-07 15:53:29 +0100 |
commit | b9b0b7d153cde0f6d023d849c8ffdcefb533a277 (patch) | |
tree | d7e029c0fe9d4f7b9fd2f3dbd0dacd4a6f0cc474 /configserver | |
parent | 135ef16d40619bc7fe186b1cdfe825a39b22492d (diff) |
Detach and serve from separate thread.
Diffstat (limited to 'configserver')
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java | 40 | ||||
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/rpc/RpcServer.java | 37 |
2 files changed, 44 insertions, 33 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java index 958f26632ef..90792759d2c 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileServer.java @@ -7,6 +7,9 @@ import com.yahoo.config.FileReference; import com.yahoo.config.model.api.FileDistribution; import com.yahoo.config.subscription.ConfigSourceSet; import com.yahoo.io.IOUtils; +import com.yahoo.jrt.Int32Value; +import com.yahoo.jrt.Request; +import com.yahoo.jrt.StringValue; import com.yahoo.jrt.Supervisor; import com.yahoo.jrt.Transport; import com.yahoo.net.HostName; @@ -33,6 +36,19 @@ public class FileServer { private final ExecutorService executor; private final FileDownloader downloader; + private enum FileApiErrorCodes { + OK(0, "OK"), + NOT_FOUND(1, "Filereference not found"); + private final int code; + private final String description; + FileApiErrorCodes(int code, String description) { + this.code = code; + this.description = description; + } + int getCode() { return code; } + String getDescription() { return description; } + } + public static class ReplayStatus { private final int code; private final String description; @@ -122,6 +138,30 @@ public class FileServer { return new FileReferenceData(reference, file.getName(), type, blob); } + public void serveFile(Request request, Receiver receiver) { + executor.execute(() -> serveFile(request.parameters().get(0).asString(), request, receiver)); + } + private void serveFile(String fileReference, Request request, Receiver receiver) { + FileApiErrorCodes result; + try { + // TODO remove once verified in system tests. + log.info("Received request for reference '" + fileReference + "'"); + result = hasFile(fileReference) + ? FileApiErrorCodes.OK + : FileApiErrorCodes.NOT_FOUND; + if (result == FileApiErrorCodes.OK) { + startFileServing(fileReference, receiver); + } else { + download(new FileReference(fileReference)); + } + } catch (IllegalArgumentException e) { + result = FileApiErrorCodes.NOT_FOUND; + log.warning("Failed serving file reference '" + fileReference + "' with error " + e.toString()); + } + request.returnValues() + .add(new Int32Value(result.getCode())) + .add(new StringValue(result.getDescription())); + } public void download(FileReference fileReference) { downloader.getFile(fileReference); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/RpcServer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/RpcServer.java index 5c50fbfc31b..17368b48e59 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/RpcServer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/RpcServer.java @@ -74,20 +74,9 @@ public class RpcServer implements Runnable, ReloadListener, TenantListener { static final int TRACELEVEL_DEBUG = 9; private static final String THREADPOOL_NAME = "rpcserver worker pool"; private static final long SHUTDOWN_TIMEOUT = 60; - private enum FileApiErrorCodes { - OK(0, "OK"), - NOT_FOUND(1, "Filereference not found"); - private final int code; - private final String description; - FileApiErrorCodes(int code, String description) { - this.code = code; - this.description = description; - } - int getCode() { return code; } - String getDescription() { return description; } - } + private final Supervisor supervisor = new Supervisor(new Transport()); - private Spec spec = null; + private Spec spec; private final boolean useRequestVersion; private final boolean hostedVespa; @@ -455,25 +444,7 @@ public class RpcServer implements Runnable, ReloadListener, TenantListener { @SuppressWarnings("UnusedDeclaration") public final void serveFile(Request request) { - String fileReference = request.parameters().get(0).asString(); - FileApiErrorCodes result; - try { - // TODO remove once verified in system tests. - log.info("Received request for reference '" + fileReference + "'"); - result = fileServer.hasFile(fileReference) - ? FileApiErrorCodes.OK - : FileApiErrorCodes.NOT_FOUND; - if (result == FileApiErrorCodes.OK) { - fileServer.startFileServing(fileReference, new FileReceiver(request.target())); - } else { - fileServer.download(new FileReference(fileReference)); - } - } catch (IllegalArgumentException e) { - result = FileApiErrorCodes.NOT_FOUND; - log.warning("Failed serving file reference '" + fileReference + "' with error " + e.toString()); - } - request.returnValues() - .add(new Int32Value(result.getCode())) - .add(new StringValue(result.getDescription())); + request.detach(); + fileServer.serveFile(request, new FileReceiver(request.target())); } } |