diff options
author | Lukacs Berki <lberki@google.com> | 2017-02-07 09:23:36 +0000 |
---|---|---|
committer | Kristina Chodorow <kchodorow@google.com> | 2017-02-07 18:26:50 +0000 |
commit | 75392053de95cecf544d3f9b473a01288de6ee43 (patch) | |
tree | 40ac3b7854a0112c9b458bec3a3cb1b2bd0c8756 /src/main/java/com/google/devtools/build/lib/server | |
parent | 90cdca8d2715a698630e13b6d2e71b44d76abf82 (diff) |
Reinstate IdleServerTasks that accidentally got disabled with the switch from AF_UNIX to gRPC.
Do not reinstate the checks whether the server should terminate itself, though, because we apparently get along pretty well without those.
--
PiperOrigin-RevId: 146760481
MOS_MIGRATED_REVID=146760481
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/server')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java | 30 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/server/RPCServer.java | 4 |
2 files changed, 29 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java b/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java index fe68b910ad..e1f888d521 100644 --- a/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java +++ b/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java @@ -116,6 +116,9 @@ public class GrpcServerImpl implements RPCServer { thread = Thread.currentThread(); id = UUID.randomUUID().toString(); synchronized (runningCommands) { + if (runningCommands.isEmpty()) { + busy(); + } runningCommands.put(id, this); runningCommands.notify(); } @@ -127,6 +130,9 @@ public class GrpcServerImpl implements RPCServer { public void close() { synchronized (runningCommands) { runningCommands.remove(id); + if (runningCommands.isEmpty()) { + idle(); + } runningCommands.notify(); } @@ -142,8 +148,9 @@ public class GrpcServerImpl implements RPCServer { public static class Factory implements RPCServer.Factory { @Override public RPCServer create(CommandExecutor commandExecutor, Clock clock, int port, - Path serverDirectory, int maxIdleSeconds) throws IOException { - return new GrpcServerImpl(commandExecutor, clock, port, serverDirectory, maxIdleSeconds); + Path workspace, Path serverDirectory, int maxIdleSeconds) throws IOException { + return new GrpcServerImpl( + commandExecutor, clock, port, workspace, serverDirectory, maxIdleSeconds); } } @@ -499,6 +506,7 @@ public class GrpcServerImpl implements RPCServer { private final ExecutorService commandExecutorPool; private final Clock clock; private final Path serverDirectory; + private final Path workspace; private final String requestCookie; private final String responseCookie; private final AtomicLong interruptCounter = new AtomicLong(0); @@ -508,11 +516,12 @@ public class GrpcServerImpl implements RPCServer { private final String pidInFile; private Server server; + private IdleServerTasks idleServerTasks; private final int port; boolean serving; public GrpcServerImpl(CommandExecutor commandExecutor, Clock clock, int port, - Path serverDirectory, int maxIdleSeconds) throws IOException { + Path workspace, Path serverDirectory, int maxIdleSeconds) throws IOException { // server.pid was written in the C++ launcher after fork() but before exec() . // The client only accesses the pid file after connecting to the socket // which ensures that it gets the correct pid value. @@ -523,6 +532,7 @@ public class GrpcServerImpl implements RPCServer { this.commandExecutor = commandExecutor; this.clock = clock; this.serverDirectory = serverDirectory; + this.workspace = workspace; this.port = port; this.maxIdleSeconds = maxIdleSeconds; this.serving = false; @@ -541,6 +551,20 @@ public class GrpcServerImpl implements RPCServer { pidFileWatcherThread = new PidFileWatcherThread(); pidFileWatcherThread.start(); + idleServerTasks = new IdleServerTasks(workspace); + idleServerTasks.idle(); + } + + private void idle() { + Preconditions.checkState(idleServerTasks == null); + idleServerTasks = new IdleServerTasks(workspace); + idleServerTasks.idle(); + } + + private void busy() { + Preconditions.checkState(idleServerTasks != null); + idleServerTasks.busy(); + idleServerTasks = null; } private static String generateCookie(SecureRandom random, int byteCount) { diff --git a/src/main/java/com/google/devtools/build/lib/server/RPCServer.java b/src/main/java/com/google/devtools/build/lib/server/RPCServer.java index 449bb9761f..d7aba84a41 100644 --- a/src/main/java/com/google/devtools/build/lib/server/RPCServer.java +++ b/src/main/java/com/google/devtools/build/lib/server/RPCServer.java @@ -28,8 +28,8 @@ public interface RPCServer { * Present so that we don't need to invoke a constructor with multiple arguments by reflection. */ interface Factory { - RPCServer create(CommandExecutor commandExecutor, Clock clock, int port, Path serverDirectory, - int maxIdleSeconds) throws IOException; + RPCServer create(CommandExecutor commandExecutor, Clock clock, int port, + Path workspace, Path serverDirectory, int maxIdleSeconds) throws IOException; } /** |