diff options
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/remote/ConcurrentMapActionCache.java (renamed from src/main/java/com/google/devtools/build/lib/remote/MemcacheActionCache.java) | 19 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/remote/MemcacheWorkExecutor.java | 32 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java | 6 | ||||
-rw-r--r-- | src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java | 8 |
4 files changed, 28 insertions, 37 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/remote/MemcacheActionCache.java b/src/main/java/com/google/devtools/build/lib/remote/ConcurrentMapActionCache.java index 8d29bea68a..e867a77411 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/MemcacheActionCache.java +++ b/src/main/java/com/google/devtools/build/lib/remote/ConcurrentMapActionCache.java @@ -23,7 +23,6 @@ import com.google.devtools.build.lib.remote.RemoteProtocol.FileEntry; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.vfs.Path; import com.google.protobuf.ByteString; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -32,23 +31,19 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.Semaphore; /** - * A RemoteActionCache implementation that uses memcache as a distributed storage - * for files and action output. The memcache is accessed by the {@link ConcurrentMap} - * interface. + * A RemoteActionCache implementation that uses a concurrent map as a distributed storage for files + * and action output. * - * The thread satefy is guaranteed by the underlying memcache client. + * <p>The thread safety is guaranteed by the underlying map. */ @ThreadSafe -public final class MemcacheActionCache implements RemoteActionCache { +public final class ConcurrentMapActionCache implements RemoteActionCache { private final Path execRoot; private final ConcurrentMap<String, byte[]> cache; private static final int MAX_MEMORY_KBYTES = 512 * 1024; private final Semaphore uploadMemoryAvailable = new Semaphore(MAX_MEMORY_KBYTES, true); - /** - * Construct an action cache using JCache API. - */ - public MemcacheActionCache( + public ConcurrentMapActionCache( Path execRoot, RemoteOptions options, ConcurrentMap<String, byte[]> cache) { this.execRoot = execRoot; this.cache = cache; @@ -147,9 +142,7 @@ public final class MemcacheActionCache implements RemoteActionCache { cache.put(key, actionOutput.build().toByteArray()); } - /** - * Add the file to action output cache entry. Put the file to cache if necessary. - */ + /** Add the file to action output cache entry. Put the file to cache if necessary. */ private void addToActionOutput(Path file, String execPathString, CacheEntry.Builder actionOutput) throws IOException { if (file.isDirectory()) { diff --git a/src/main/java/com/google/devtools/build/lib/remote/MemcacheWorkExecutor.java b/src/main/java/com/google/devtools/build/lib/remote/MemcacheWorkExecutor.java index a2948bad84..7f87803dde 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/MemcacheWorkExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/remote/MemcacheWorkExecutor.java @@ -29,10 +29,8 @@ import com.google.devtools.build.lib.shell.CommandException; import com.google.devtools.build.lib.shell.CommandResult; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; - import io.grpc.ManagedChannel; import io.grpc.netty.NettyChannelBuilder; - import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -42,16 +40,16 @@ import java.util.Collection; import java.util.List; /** - * Implementation of {@link RemoteWorkExecutor} that uses MemcacheActionCache and gRPC for + * Implementation of {@link RemoteWorkExecutor} that uses ConcurrentMapActionCache and gRPC for * communicating the work, inputs and outputs. */ @ThreadSafe public class MemcacheWorkExecutor implements RemoteWorkExecutor { /** - * A cache used to store the input and output files as well as the build status - * of the remote work. + * A cache used to store the input and output files as well as the build status of the remote + * work. */ - protected final MemcacheActionCache cache; + protected final ConcurrentMapActionCache cache; /** Execution root for running this work locally. */ private final Path execRoot; @@ -62,20 +60,20 @@ public class MemcacheWorkExecutor implements RemoteWorkExecutor { private static final int MAX_WORK_SIZE_BYTES = 1024 * 1024 * 512; /** - * This constructor is used when this class is used in a client. - * It requires a host address and port to connect to a remote service. + * This constructor is used when this class is used in a client. It requires a host address and + * port to connect to a remote service. */ - private MemcacheWorkExecutor(MemcacheActionCache cache, String host, int port) { + private MemcacheWorkExecutor(ConcurrentMapActionCache cache, String host, int port) { this.cache = cache; this.execRoot = null; this.channel = NettyChannelBuilder.forAddress(host, port).usePlaintext(true).build(); } /** - * This constructor is used when this class is used in the remote worker. - * A path to the execution root is needed for executing work locally. + * This constructor is used when this class is used in the remote worker. A path to the execution + * root is needed for executing work locally. */ - private MemcacheWorkExecutor(MemcacheActionCache cache, Path execRoot) { + private MemcacheWorkExecutor(ConcurrentMapActionCache cache, Path execRoot) { this.cache = cache; this.execRoot = execRoot; this.channel = null; @@ -83,24 +81,26 @@ public class MemcacheWorkExecutor implements RemoteWorkExecutor { /** * Create an instance of MemcacheWorkExecutor that talks to a remote server. - * @param cache An instance of MemcacheActionCache. + * + * @param cache An instance of ConcurrentMapActionCache. * @param host Hostname of the server to connect to. * @param port Port of the server to connect to. * @return An instance of MemcacheWorkExecutor that talks to a remote server. */ public static MemcacheWorkExecutor createRemoteWorkExecutor( - MemcacheActionCache cache, String host, int port) { + ConcurrentMapActionCache cache, String host, int port) { return new MemcacheWorkExecutor(cache, host, port); } /** * Create an instance of MemcacheWorkExecutor that runs locally. - * @param cache An instance of MemcacheActionCache. + * + * @param cache An instance of ConcurrentMapActionCache. * @param execRoot Path of the execution root where work is executed. * @return An instance of MemcacheWorkExecutor tthat runs locally in the execution root. */ public static MemcacheWorkExecutor createLocalWorkExecutor( - MemcacheActionCache cache, Path execRoot) { + ConcurrentMapActionCache cache, Path execRoot) { return new MemcacheWorkExecutor(cache, execRoot); } diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java index c55a788720..ffe27f5d94 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java @@ -61,19 +61,19 @@ public final class RemoteModule extends BlazeModule { buildRequest = event.getRequest(); RemoteOptions options = buildRequest.getOptions(RemoteOptions.class); - MemcacheActionCache cache = null; + ConcurrentMapActionCache cache = null; // Don't provide the remote spawn unless at least action cache is initialized. if (actionCache == null) { if (options.hazelcastNode != null || options.hazelcastClientConfig != null) { cache = - new MemcacheActionCache( + new ConcurrentMapActionCache( this.env.getDirectories().getExecRoot(), options, HazelcastCacheFactory.create(options)); } else if (options.restCacheUrl != null) { cache = - new MemcacheActionCache( + new ConcurrentMapActionCache( this.env.getDirectories().getExecRoot(), options, RestUrlCacheFactory.create(options)); diff --git a/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java b/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java index 250aedbfb2..2bf5c39f46 100644 --- a/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java +++ b/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java @@ -14,8 +14,8 @@ package com.google.devtools.build.remote; +import com.google.devtools.build.lib.remote.ConcurrentMapActionCache; import com.google.devtools.build.lib.remote.HazelcastCacheFactory; -import com.google.devtools.build.lib.remote.MemcacheActionCache; import com.google.devtools.build.lib.remote.MemcacheWorkExecutor; import com.google.devtools.build.lib.remote.RemoteOptions; import com.google.devtools.build.lib.remote.RemoteProtocol.RemoteWorkRequest; @@ -29,11 +29,9 @@ import com.google.devtools.build.lib.vfs.JavaIoFileSystem; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.UnixFileSystem; import com.google.devtools.common.options.OptionsParser; - import io.grpc.Server; import io.grpc.ServerBuilder; import io.grpc.stub.StreamObserver; - import java.io.IOException; import java.io.PrintWriter; import java.util.Collections; @@ -71,8 +69,8 @@ public class RemoteWorker implements RemoteWorkGrpc.RemoteWork { Path tempRoot = workPath.getRelative("build-" + UUID.randomUUID().toString()); try { FileSystemUtils.createDirectoryAndParents(tempRoot); - final MemcacheActionCache actionCache = - new MemcacheActionCache(tempRoot, remoteOptions, cache); + final ConcurrentMapActionCache actionCache = + new ConcurrentMapActionCache(tempRoot, remoteOptions, cache); final MemcacheWorkExecutor workExecutor = MemcacheWorkExecutor.createLocalWorkExecutor(actionCache, tempRoot); if (LOG_FINER) { |