Skip to content

Commit 49f02a6

Browse files
authored
Update grpc-java and various other dependencies; add some more javadoc (#31)
- grpc-java 1.30.0 - netty 4.1.48.Final (to match grpc-java netty dep version) - netty-tcnative 2.0.30 - protobuf 3.12.2 - guava 29.0-jre - Switch to use org.apache.tomcat:annotations-api:6.0.53 Also includes work around for race condition leak when using blocking RPCs in latest versions of grpc-java.
1 parent af2329d commit 49f02a6

7 files changed

Lines changed: 201 additions & 52 deletions

File tree

build-env/install-etcd.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Fail on any error
44
set -e
55

6-
ETCD_VERSION=v3.3.18
6+
ETCD_VERSION=v3.3.22
77

88
INSTALL_DIR="${1:-$HOME/etcd}"
99

pom.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@
5555
</distributionManagement>
5656

5757
<properties>
58-
<grpc-version>1.26.0</grpc-version>
59-
<netty-version>4.1.42.Final</netty-version>
60-
<netty-tcnative-version>2.0.26.Final</netty-tcnative-version>
61-
<protoc-version>3.11.0</protoc-version>
58+
<grpc-version>1.30.0</grpc-version>
59+
<netty-version>4.1.48.Final</netty-version>
60+
<netty-tcnative-version>2.0.30.Final</netty-tcnative-version>
61+
<protobuf-version>3.12.2</protobuf-version>
6262
<gson-version>2.8.6</gson-version>
6363
<slf4j-version>1.7.30</slf4j-version>
6464
<junit-version>4.13</junit-version>
65-
<guava-version>28.2-jre</guava-version>
66-
<annotation-version>1.3.2</annotation-version>
65+
<guava-version>29.0-jre</guava-version>
66+
<annotation-version>6.0.53</annotation-version>
6767

6868
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6969
</properties>
@@ -129,8 +129,8 @@
129129
gRPC stubs. "provided" scope is sufficient since this
130130
annotation only has source retention. -->
131131
<dependency>
132-
<groupId>javax.annotation</groupId>
133-
<artifactId>javax.annotation-api</artifactId>
132+
<groupId>org.apache.tomcat</groupId>
133+
<artifactId>annotations-api</artifactId>
134134
<version>${annotation-version}</version>
135135
<scope>provided</scope>
136136
</dependency>
@@ -163,7 +163,7 @@
163163
<artifactId>protobuf-maven-plugin</artifactId>
164164
<version>0.6.1</version>
165165
<configuration>
166-
<protocArtifact>com.google.protobuf:protoc:${protoc-version}:exe:${os.detected.classifier}</protocArtifact>
166+
<protocArtifact>com.google.protobuf:protoc:${protobuf-version}:exe:${os.detected.classifier}</protocArtifact>
167167
<pluginId>grpc-java</pluginId>
168168
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc-version}:exe:${os.detected.classifier}</pluginArtifact>
169169
</configuration>

src/main/java/com/ibm/etcd/client/EtcdClient.java

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import javax.net.ssl.TrustManagerFactory;
4242

4343
import com.google.common.annotations.VisibleForTesting;
44+
import com.google.common.base.Preconditions;
4445
import com.google.common.base.Predicate;
4546
import com.google.common.base.Predicates;
4647
import com.google.common.collect.ImmutableSet;
@@ -64,6 +65,7 @@
6465

6566
import io.grpc.CallCredentials;
6667
import io.grpc.CallOptions;
68+
import io.grpc.Deadline;
6769
import io.grpc.ManagedChannel;
6870
import io.grpc.Metadata;
6971
import io.grpc.Metadata.Key;
@@ -82,6 +84,7 @@
8284
import io.netty.channel.epoll.EpollSocketChannel;
8385
import io.netty.channel.nio.NioEventLoopGroup;
8486
import io.netty.channel.socket.nio.NioSocketChannel;
87+
import io.netty.handler.ssl.SslContext;
8588
import io.netty.handler.ssl.SslContextBuilder;
8689
import io.netty.util.concurrent.FastThreadLocalThread;
8790

@@ -131,18 +134,34 @@ public static class Builder {
131134
this.chanBuilder = chanBuilder;
132135
}
133136

137+
/**
138+
* Set etcd credentials to use from {@link ByteString}s
139+
*
140+
* @param name
141+
* @param password
142+
*/
134143
public Builder withCredentials(ByteString name, ByteString password) {
135144
this.name = name;
136145
this.password = password;
137146
return this;
138147
}
139148

149+
/**
150+
* Set etcd credentials to use from {@link String}s as UTF-8.
151+
*
152+
* @param name
153+
* @param password
154+
*/
140155
public Builder withCredentials(String name, String password) {
141156
this.name = ByteString.copyFromUtf8(name);
142157
this.password = ByteString.copyFromUtf8(password);
143158
return this;
144159
}
145160

161+
/**
162+
* Attempt authentication immediately rather than if/when required.
163+
* Applies only if etcd credentials have been provided.
164+
*/
146165
public Builder withImmediateAuth() {
147166
preemptAuth = true;
148167
return this;
@@ -156,16 +175,41 @@ public Builder withThreadCount(int threads) {
156175
return this;
157176
}
158177

178+
/**
179+
* Control whether all RPC requests are sent via the underlying
180+
* IO event loop. This helps to limit overall memory use due to
181+
* internal thread-local buffer pooling.
182+
* <p>
183+
* Default is <code>true</code>
184+
*
185+
* @param sendViaEventLoop
186+
*/
159187
public Builder sendViaEventLoop(boolean sendViaEventLoop) {
160188
this.sendViaEventLoop = sendViaEventLoop;
161189
return this;
162190
}
163191

192+
/**
193+
* Provide executor to use for user call-backs. A default
194+
* client-scoped executor will be used if not set.
195+
*
196+
* @param executor
197+
*/
164198
public Builder withUserExecutor(Executor executor) {
165199
this.executor = executor;
166200
return this;
167201
}
168202

203+
/**
204+
* Provide a default timeout to use for requests made by this client.
205+
* This timeout value is used per-attempt, unlike {@link Deadline}s
206+
* used per-call which also cover any/all retry attempts.
207+
*
208+
* The default for this default is 10 seconds
209+
*
210+
* @param value
211+
* @param unit
212+
*/
169213
public Builder withDefaultTimeout(long value, TimeUnit unit) {
170214
this.defaultTimeoutMs = TimeUnit.MILLISECONDS.convert(value, unit);
171215
return this;
@@ -176,43 +220,80 @@ private SslContextBuilder sslBuilder() {
176220
: (sslContextBuilder = GrpcSslContexts.forClient());
177221
}
178222

223+
/**
224+
* Disable TLS - to connect to insecure servers in development contexts
225+
*/
179226
public Builder withPlainText() {
180227
chanBuilder.usePlaintext();
181228
return this;
182229
}
183230

231+
/**
232+
* Provide CA certificate to use for TLS connection
233+
*
234+
* @param certSource
235+
* @throws IOException if there is an error reading from the provided {@link ByteSource}
236+
* @throws SSLException
237+
*/
184238
public Builder withCaCert(ByteSource certSource) throws IOException, SSLException {
185239
try (InputStream cert = certSource.openStream()) {
186240
chanBuilder.sslContext(sslBuilder().trustManager(cert).build());
187241
}
188242
return this;
189243
}
190244

245+
/**
246+
* Provide custom {@link TrustManagerFactory} to use for this
247+
* client's TLS connection.
248+
*
249+
* @param tmf
250+
* @throws SSLException
251+
*/
191252
public Builder withTrustManager(TrustManagerFactory tmf) throws SSLException {
192253
chanBuilder.sslContext(sslBuilder().trustManager(tmf).build());
193254
return this;
194255
}
195256

257+
/**
258+
* Configure the netty {@link SslContext} to be used by this client.
259+
* The provided {@link Consumer} should make updates to the passed
260+
* {@link SslContextBuilder} as needed, but should not call build().
261+
*
262+
* @param contextBuilder
263+
* @throws SSLException
264+
*/
196265
public Builder withTlsConfig(Consumer<SslContextBuilder> contextBuilder) throws SSLException {
197266
SslContextBuilder sslBuilder = sslBuilder();
198267
contextBuilder.accept(sslBuilder);
199268
chanBuilder.sslContext(sslBuilder.build());
200269
return this;
201270
}
202271

272+
/**
273+
* Set the session timeout in seconds - this corresponds to the TTL of the
274+
* session lease, see {@link EtcdClient#getSessionLease()}.
275+
*
276+
* @param timeoutSecs
277+
*/
203278
public Builder withSessionTimeoutSecs(int timeoutSecs) {
204-
if (timeoutSecs < 1) {
205-
throw new IllegalArgumentException("invalid session timeout: " + timeoutSecs);
206-
}
279+
Preconditions.checkArgument(timeoutSecs < 1, "invalid session timeout: %s", timeoutSecs);
207280
this.sessTimeoutSecs = timeoutSecs;
208281
return this;
209282
}
210283

284+
/**
285+
* Set the maximum inbound message size in bytes
286+
*
287+
* @param sizeInBytes
288+
*/
211289
public Builder withMaxInboundMessageSize(int sizeInBytes) {
212290
chanBuilder.maxInboundMessageSize(sizeInBytes);
213291
return this;
214292
}
215293

294+
/**
295+
* @return the built {@link EtcdClient} instance
296+
*/
216297
public EtcdClient build() {
217298
return new EtcdClient(chanBuilder, defaultTimeoutMs, name, password,
218299
preemptAuth, threads, executor, sendViaEventLoop, sessTimeoutSecs);
@@ -223,18 +304,34 @@ private static int defaultThreadCount() {
223304
return Math.min(6, Runtime.getRuntime().availableProcessors());
224305
}
225306

307+
/**
308+
*
309+
* @param host
310+
* @param port
311+
* @return
312+
*/
226313
public static Builder forEndpoint(String host, int port) {
227314
String target = GrpcUtil.authorityFromHostAndPort(host, port);
228315
return new Builder(NettyChannelBuilder.forTarget(target));
229316
}
230317

318+
/**
319+
*
320+
* @param endpoints
321+
* @return
322+
*/
231323
public static Builder forEndpoints(List<String> endpoints) {
232324
NettyChannelBuilder ncb = NettyChannelBuilder
233325
.forTarget(StaticEtcdNameResolverFactory.ETCD)
234326
.nameResolverFactory(new StaticEtcdNameResolverFactory(endpoints));
235327
return new Builder(ncb);
236328
}
237329

330+
/**
331+
*
332+
* @param endpoints
333+
* @return
334+
*/
238335
public static Builder forEndpoints(String endpoints) {
239336
return forEndpoints(Arrays.asList(endpoints.split(",")));
240337
}

src/main/java/com/ibm/etcd/client/FluentRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public final ListenableFuture<RespT> async() {
100100
}
101101
@Override
102102
public final RespT sync() {
103-
return GrpcClient.waitFor(this::async);
103+
return client.waitForCall(this::async);
104104
}
105105
}
106106
}

0 commit comments

Comments
 (0)