duongkame commented on code in PR #4363:
URL: https://github.com/apache/ozone/pull/4363#discussion_r1129886385
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/GrpcContainerUploader.java:
##########
@@ -53,18 +55,32 @@ public GrpcContainerUploader(
public OutputStream startUpload(long containerId, DatanodeDetails target,
CompletableFuture<Void> callback, CopyContainerCompression compression)
throws IOException {
- GrpcReplicationClient client =
- new GrpcReplicationClient(target.getIpAddress(),
- target.getPort(Port.Name.REPLICATION).getValue(),
- securityConfig, certClient, compression);
- StreamObserver<SendContainerRequest> requestStream = client.upload(
- new SendContainerResponseStreamObserver(containerId, target,
callback));
- return new SendContainerOutputStream(requestStream, containerId,
- GrpcReplicationService.BUFFER_SIZE, compression);
+ GrpcReplicationClient client = null;
Review Comment:
Should the code around creating `client` and uploading be refactored to be
done in one place, e.g. in `PushReplicator.replicate`.
```
try (GrpcReplicationClient client = grpcContainerUploader.createClient()) {
try (OutputStream output : client.upload(....)) {
source.copyData(containerID, output, compression);
...
}
}
```
That way we wouldn't need to care about passing `client` around and closing
it in multiple places.
That's just a suggestion to simplify the model. Looks like in this PR you
already take good care of closing resources.
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/GrpcContainerUploader.java:
##########
@@ -53,18 +55,32 @@ public GrpcContainerUploader(
public OutputStream startUpload(long containerId, DatanodeDetails target,
CompletableFuture<Void> callback, CopyContainerCompression compression)
throws IOException {
- GrpcReplicationClient client =
- new GrpcReplicationClient(target.getIpAddress(),
- target.getPort(Port.Name.REPLICATION).getValue(),
- securityConfig, certClient, compression);
- StreamObserver<SendContainerRequest> requestStream = client.upload(
- new SendContainerResponseStreamObserver(containerId, target,
callback));
- return new SendContainerOutputStream(requestStream, containerId,
- GrpcReplicationService.BUFFER_SIZE, compression);
+ GrpcReplicationClient client = null;
+ try {
+ client = createReplicationClient(target, compression);
+ StreamObserver<SendContainerRequest> requestStream = client.upload(
+ new SendContainerResponseStreamObserver(containerId, target,
+ callback));
+ return new SendContainerOutputStream(client, requestStream, containerId,
Review Comment:
nit: should `client.upload` return `SendContainerOutputStream` directly?
Looks like there's no need to expose the details of StreamObserver to outside.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]