forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remote: gRPC load balancing. (Part 1)
Defines ConnectionFactory interfaces used to create gRPC connections. This change abstracts away the details of connection creation and allows us applying connection pooling and load balancing without changing client code. PiperOrigin-RevId: 357575236
- Loading branch information
1 parent
97bc48d
commit 97963c5
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/google/devtools/build/lib/remote/grpc/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
load("@rules_java//java:defs.bzl", "java_library") | ||
|
||
package( | ||
default_visibility = ["//src:__subpackages__"], | ||
) | ||
|
||
licenses(["notice"]) | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob(["*"]), | ||
visibility = ["//src:__subpackages__"], | ||
) | ||
|
||
java_library( | ||
name = "grpc", | ||
srcs = glob(["*.java"]), | ||
deps = [ | ||
"//third_party:rxjava3", | ||
"//third_party/grpc:grpc-jar", | ||
], | ||
) |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/google/devtools/build/lib/remote/grpc/Connection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2021 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.remote.grpc; | ||
|
||
import io.grpc.CallOptions; | ||
import io.grpc.ClientCall; | ||
import io.grpc.MethodDescriptor; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A single connection to a server. RPCs are executed within the context of a connection. A {@link | ||
* Connection} object can consist of any number of transport connections. | ||
* | ||
* <p>Connections must be closed to ensure proper resource disposal. | ||
*/ | ||
public interface Connection extends Closeable { | ||
|
||
/** Creates a new {@link ClientCall} for issuing RPC. */ | ||
<ReqT, RespT> ClientCall<ReqT, RespT> call( | ||
MethodDescriptor<ReqT, RespT> method, CallOptions options); | ||
|
||
/** Releases any resources held by the {@link Connection}. */ | ||
@Override | ||
void close() throws IOException; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/google/devtools/build/lib/remote/grpc/ConnectionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2021 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.remote.grpc; | ||
|
||
import io.reactivex.rxjava3.core.Single; | ||
|
||
/** | ||
* A {@link ConnectionFactory} represents a resource factory for connection creation. It may create | ||
* connections by itself, wrap a {@link ConnectionFactory}, or apply connection pooling on top of a | ||
* {@link ConnectionFactory}. | ||
* | ||
* <p>A {@link ConnectionFactory} uses deferred initialization and should initiate connection | ||
* resource allocation after subscription. | ||
* | ||
* <p>Connection creation must be cancellable. Canceling connection creation must release (“close”) | ||
* the connection and all associated resources. | ||
*/ | ||
public interface ConnectionFactory { | ||
/** Creates a new {@link Connection}. */ | ||
Single<? extends Connection> create(); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/google/devtools/build/lib/remote/grpc/ConnectionPool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2021 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.remote.grpc; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A {@link ConnectionFactory} that apply connection pooling. Connections created by {@link | ||
* ConnectionPool} will not be closed by {@link Connection#close()}, use {@link | ||
* ConnectionPool#close()} instead to close all the connections in the pool. | ||
* | ||
* <p>Connections must be closed with {@link Connection#close()} in order to be reused later. | ||
*/ | ||
public interface ConnectionPool extends ConnectionFactory, Closeable { | ||
/** Closes the connection pool and closes all the underlying connections */ | ||
@Override | ||
void close() throws IOException; | ||
} |