aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/remote_worker
diff options
context:
space:
mode:
authorGravatar Alpha Lam <alpha.lam.ts@gmail.com>2017-10-30 08:53:27 -0400
committerGravatar John Cater <jcater@google.com>2017-10-30 10:42:07 -0400
commitab8e513ed537c67f6032911cb6e089c10f46def1 (patch)
tree42b507324932d5a90d16b20fb031e815523a6bd0 /src/tools/remote_worker
parent7a3f1048e3c8f8fce57c3d873824511f15cb4aa0 (diff)
Remove hazelcast dependency from Bazel
This change removes Bazel's dependency on Hazelcast. This will help to reduce size of the Bazel binary and simplify the usage of remote cache. However Hazelcast library is still kept in the repository and still being used by remote_worker. It is useful as a REST server to allow integration testing with the remote rest cache functionality. Change-Id: Ia21b970cedaec84bc6c13e839509d838acb5756f PiperOrigin-RevId: 173880600
Diffstat (limited to 'src/tools/remote_worker')
-rw-r--r--src/tools/remote_worker/README.md6
-rw-r--r--src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorker.java41
-rw-r--r--src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorkerOptions.java12
3 files changed, 47 insertions, 12 deletions
diff --git a/src/tools/remote_worker/README.md b/src/tools/remote_worker/README.md
index 32c912a0ab..e779576fdf 100644
--- a/src/tools/remote_worker/README.md
+++ b/src/tools/remote_worker/README.md
@@ -40,9 +40,3 @@ As you can see, the specific behavior of the sandbox can be tuned via the flags
no network connectivity except for its own "localhost". Note that due to a Linux kernel issue this
might result in a loss of performance if you run many actions in parallel. For long running tests
it probably won't matter much, though.
-
-## Hazelcast caching
-
-You can also use a Hazelcast server for the distributed cache as follows:
-Suppose your Hazelcast server is listening on address:port. Then, run the
-remote worker with --hazelcast_node=address:port.
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 79278945e7..2cff8f860e 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
@@ -49,6 +49,9 @@ import com.google.devtools.remoteexecution.v1test.ActionResult;
import com.google.devtools.remoteexecution.v1test.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase;
import com.google.devtools.remoteexecution.v1test.ExecutionGrpc.ExecutionImplBase;
import com.google.watcher.v1.WatcherGrpc.WatcherImplBase;
+import com.hazelcast.config.Config;
+import com.hazelcast.core.Hazelcast;
+import com.hazelcast.core.HazelcastInstance;
import io.grpc.Server;
import io.grpc.ServerInterceptor;
import io.grpc.ServerInterceptors;
@@ -171,6 +174,23 @@ public final class RemoteWorker {
});
}
+ /**
+ * Construct a {@link SimpleBlobStore} using Hazelcast's version of {@link ConcurrentMap}. This
+ * will start a standalone Hazelcast server in the same JVM. There will also be a REST server
+ * started for accessing the maps.
+ */
+ private static SimpleBlobStore createHazelcast(RemoteWorkerOptions options) {
+ Config config = new Config();
+ config
+ .getNetworkConfig()
+ .setPort(options.hazelcastStandaloneListenPort)
+ .getJoin()
+ .getMulticastConfig()
+ .setEnabled(false);
+ HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
+ return new ConcurrentMapBlobStore(instance.<String, byte[]>getMap("cache"));
+ }
+
public static void main(String[] args) throws Exception {
OptionsParser parser =
OptionsParser.newOptionsParser(RemoteOptions.class, RemoteWorkerOptions.class);
@@ -216,12 +236,21 @@ public final class RemoteWorker {
return;
}
- SimpleBlobStore blobStore =
- usingRemoteCache
- ? SimpleBlobStoreFactory.create(remoteOptions, null)
- : remoteWorkerOptions.casPath != null
- ? new OnDiskBlobStore(fs.getPath(remoteWorkerOptions.casPath))
- : new ConcurrentMapBlobStore(new ConcurrentHashMap<String, byte[]>());
+ // The instance of SimpleBlobStore used is based on these criteria in order:
+ // 1. If remote cache or local disk cache is specified then use it first.
+ // 2. Otherwise start a standalone Hazelcast instance and use it as the blob store. This also
+ // creates a REST server for testing.
+ // 3. Finally use a ConcurrentMap to back the blob store.
+ final SimpleBlobStore blobStore;
+ if (usingRemoteCache) {
+ blobStore = SimpleBlobStoreFactory.create(remoteOptions, null);
+ } else if (remoteWorkerOptions.casPath != null) {
+ blobStore = new OnDiskBlobStore(fs.getPath(remoteWorkerOptions.casPath));
+ } else if (remoteWorkerOptions.hazelcastStandaloneListenPort != 0) {
+ blobStore = createHazelcast(remoteWorkerOptions);
+ } else {
+ blobStore = new ConcurrentMapBlobStore(new ConcurrentHashMap<String, byte[]>());
+ }
RemoteWorker worker =
new RemoteWorker(
diff --git a/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorkerOptions.java b/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorkerOptions.java
index bfcdf5de6d..9dee83a349 100644
--- a/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorkerOptions.java
+++ b/src/tools/remote_worker/src/main/java/com/google/devtools/build/remote/RemoteWorkerOptions.java
@@ -134,6 +134,18 @@ public class RemoteWorkerOptions extends OptionsBase {
)
public int jobs;
+ @Option(
+ name = "hazelcast_standalone_listen_port",
+ defaultValue = "0",
+ category = "build_worker",
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ help =
+ "Runs an embedded hazelcast server that listens to this port. The server does not join"
+ + " any cluster. This is useful for testing."
+ )
+ public int hazelcastStandaloneListenPort;
+
private static final int MAX_JOBS = 16384;
/** Converter for jobs: [0, MAX_JOBS] or "auto". */