aboutsummaryrefslogtreecommitdiffhomepage
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
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
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/BUILD1
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/README.md23
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/RemoteOptions.java32
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/SimpleBlobStoreFactory.java59
-rwxr-xr-xsrc/test/shell/bazel/remote_execution_test.sh4
-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
8 files changed, 56 insertions, 122 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/remote/BUILD b/src/main/java/com/google/devtools/build/lib/remote/BUILD
index 62ff0c9ebd..e73289826c 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/remote/BUILD
@@ -34,7 +34,6 @@ java_library(
"//third_party:auth",
"//third_party:gson",
"//third_party:guava",
- "//third_party:hazelcast",
"//third_party:jsr305",
"//third_party:netty",
"//third_party/grpc:grpc-jar",
diff --git a/src/main/java/com/google/devtools/build/lib/remote/README.md b/src/main/java/com/google/devtools/build/lib/remote/README.md
index e8487ec8b1..988039cf3b 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/README.md
+++ b/src/main/java/com/google/devtools/build/lib/remote/README.md
@@ -44,12 +44,12 @@ Bazel currently supports the following digest functions with the remote worker:
### Hazelcast with REST interface
-[Hazelcast](https://hazelcast.org/) is a distributed in-memory cache which can be used by Bazel as a remote cache.
+[Hazelcast](https://hazelcast.org/) is a distributed in-memory cache which can be used by Bazel as a remote cache. You can download the standalone Hazelcast server [here](https://hazelcast.org/download/).
-A simple single-machine setup is to run a single Hazelcast server with REST enabled. The REST endpoint will be `http://localhost:5701/hazelcast/rest/maps/cache`. Run with:
+A simple single-machine setup is to run a single Hazelcast server with REST enabled. The REST endpoint will be `http://localhost:5701/hazelcast/rest/maps/`. Run the Hazelcast server with REST using this command:
```
-java -cp third_party/hazelcast/hazelcast-3.6.4.jar -Dhazelcast.rest.enabled=true com.hazelcast.core.server.StartServer
+java -cp hazelcast-all-3.8.5.jar -Dhazelcast.rest.enabled=true com.hazelcast.core.server.StartServer
```
You can also use Bazel with a Hazelcast cluster - as long as REST is enabled -, and also customize the configuration. Please see the Hazelcast [documentation](http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html) for more details.
@@ -127,7 +127,7 @@ build --strategy=Closure=remote
### Running the sample gRPC cache server
-Bazel currently provides a sample gRPC CAS implementation with a SimpleBlobStore or Hazelcast as caching backend. To use it you need to clone from [Bazel](https://github.com/bazelbuild/bazel) and then build it with:
+Bazel currently provides a sample gRPC CAS implementation with a SimpleBlobStore as caching backend. To use it you need to clone from [Bazel](https://github.com/bazelbuild/bazel) and then build it with:
```
bazel build //src/tools/remote_worker
@@ -138,18 +138,3 @@ The following command will then start the cache server listening on port 8080 us
```
bazel-bin/src/tools/remote_worker/remote_worker --listen_port=8080
```
-
-To connect to a running instance of Hazelcast instead, use:
-
-```
-bazel-bin/src/tools/remote_worker/remote_worker --listen_port=8080 --hazelcast_node=address:port
-```
-
-If you want to change Hazelcast settings to enable distributed memory cache you can provide your own hazelcast.xml with the following command:
-
-```
-bazel-bin/src/tools/remote_worker/remote_worker --jvm_flags=-Dhazelcast.config=/path/to/hz.xml --listen_port 8080
-```
-
-You can copy and edit the [default](https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/resources/hazelcast-default.xml) Hazelcast configuration. Refer to Hazelcast [manual](http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#checking-configuration)
-for more details.
diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteOptions.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteOptions.java
index fdf4c93d5f..7ad4b05b6f 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/RemoteOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteOptions.java
@@ -49,38 +49,6 @@ public final class RemoteOptions extends OptionsBase {
public int restCachePoolSize;
@Option(
- name = "hazelcast_node",
- defaultValue = "null",
- category = "remote",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- help = "A comma separated list of hostnames of hazelcast nodes."
- )
- public String hazelcastNode;
-
- @Option(
- name = "hazelcast_client_config",
- defaultValue = "null",
- category = "remote",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.UNKNOWN},
- help = "A file path to a hazelcast client config XML file."
- )
- public String hazelcastClientConfig;
-
- @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;
-
- @Option(
name = "remote_executor",
defaultValue = "null",
category = "remote",
diff --git a/src/main/java/com/google/devtools/build/lib/remote/SimpleBlobStoreFactory.java b/src/main/java/com/google/devtools/build/lib/remote/SimpleBlobStoreFactory.java
index 1f86270a56..e9ffe2aa5a 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/SimpleBlobStoreFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/SimpleBlobStoreFactory.java
@@ -16,65 +16,21 @@ package com.google.devtools.build.lib.remote;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.google.devtools.build.lib.remote.blobstore.ConcurrentMapBlobStore;
import com.google.devtools.build.lib.remote.blobstore.OnDiskBlobStore;
import com.google.devtools.build.lib.remote.blobstore.RestBlobStore;
import com.google.devtools.build.lib.remote.blobstore.SimpleBlobStore;
import com.google.devtools.build.lib.vfs.Path;
-import com.hazelcast.client.HazelcastClient;
-import com.hazelcast.client.config.ClientConfig;
-import com.hazelcast.client.config.ClientNetworkConfig;
-import com.hazelcast.client.config.XmlClientConfigBuilder;
-import com.hazelcast.config.Config;
-import com.hazelcast.core.Hazelcast;
-import com.hazelcast.core.HazelcastInstance;
import java.io.IOException;
-import java.util.concurrent.ConcurrentMap;
import javax.annotation.Nullable;
/**
* A factory class for providing a {@link SimpleBlobStore} to be used with {@link
- * SimpleBlobStoreActionCache}. Currently implemented with Hazelcast, REST or local.
+ * SimpleBlobStoreActionCache}. Currently implemented with REST or local.
*/
public final class SimpleBlobStoreFactory {
- private static final String HAZELCAST_CACHE_NAME = "hazelcast-build-cache";
-
private SimpleBlobStoreFactory() {}
- /** Construct a {@link SimpleBlobStore} using Hazelcast's version of {@link ConcurrentMap} */
- public static SimpleBlobStore createHazelcast(RemoteOptions options) {
- HazelcastInstance instance;
- if (options.hazelcastClientConfig != null) {
- try {
- ClientConfig config = new XmlClientConfigBuilder(options.hazelcastClientConfig).build();
- instance = HazelcastClient.newHazelcastClient(config);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- } else if (options.hazelcastNode != null) {
- // If --hazelcast_node is specified then create a client instance.
- ClientConfig config = new ClientConfig();
- ClientNetworkConfig net = config.getNetworkConfig();
- net.addAddress(options.hazelcastNode.split(","));
- instance = HazelcastClient.newHazelcastClient(config);
- } else if (options.hazelcastStandaloneListenPort != 0) {
- Config config = new Config();
- config
- .getNetworkConfig()
- .setPort(options.hazelcastStandaloneListenPort)
- .getJoin()
- .getMulticastConfig()
- .setEnabled(false);
- instance = Hazelcast.newHazelcastInstance(config);
- } else {
- // Otherwise create a default instance. This is going to look at
- // -Dhazelcast.config=some-hazelcast.xml for configuration.
- instance = Hazelcast.newHazelcastInstance();
- }
- return new ConcurrentMapBlobStore(instance.<String, byte[]>getMap(HAZELCAST_CACHE_NAME));
- }
-
public static SimpleBlobStore createRest(RemoteOptions options) throws IOException {
return new RestBlobStore(options.remoteRestCache, options.restCachePoolSize);
}
@@ -87,9 +43,6 @@ public final class SimpleBlobStoreFactory {
public static SimpleBlobStore create(RemoteOptions options, @Nullable Path workingDirectory)
throws IOException {
- if (isHazelcastOptions(options)) {
- return createHazelcast(options);
- }
if (isRestUrlOptions(options)) {
return createRest(options);
}
@@ -98,23 +51,17 @@ public final class SimpleBlobStoreFactory {
}
throw new IllegalArgumentException(
"Unrecognized concurrent map RemoteOptions: must specify "
- + "either Hazelcast, Rest URL, or local cache options.");
+ + "either Rest URL, or local cache options.");
}
public static boolean isRemoteCacheOptions(RemoteOptions options) {
- return isHazelcastOptions(options) || isRestUrlOptions(options) || isLocalDiskCache(options);
+ return isRestUrlOptions(options) || isLocalDiskCache(options);
}
public static boolean isLocalDiskCache(RemoteOptions options) {
return options.experimentalLocalDiskCache;
}
- private static boolean isHazelcastOptions(RemoteOptions options) {
- return options.hazelcastNode != null
- || options.hazelcastClientConfig != null
- || options.hazelcastStandaloneListenPort != 0;
- }
-
private static boolean isRestUrlOptions(RemoteOptions options) {
return options.remoteRestCache != null;
}
diff --git a/src/test/shell/bazel/remote_execution_test.sh b/src/test/shell/bazel/remote_execution_test.sh
index c81ce2ed52..2dd63be864 100755
--- a/src/test/shell/bazel/remote_execution_test.sh
+++ b/src/test/shell/bazel/remote_execution_test.sh
@@ -217,9 +217,9 @@ EOF
bazel clean --expunge >& $TEST_log
bazel --host_jvm_args=-Dbazel.DigestFunction=SHA1 build \
--spawn_strategy=remote \
- --remote_rest_cache=http://localhost:${hazelcast_port}/hazelcast/rest/maps/cache \
+ --remote_rest_cache=http://localhost:${hazelcast_port}/hazelcast/rest/maps \
//a:test >& $TEST_log \
- || fail "Failed to build //a:test with remote gRPC cache service"
+ || fail "Failed to build //a:test with remote REST cache service"
diff bazel-bin/a/test ${TEST_TMPDIR}/test_expected \
|| fail "Remote cache generated different result"
# Check that persistent connections are closed after the build. Is there a good cross-platform way
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". */