Skip to content

Conversation

@swamirishi
Copy link
Contributor

@swamirishi swamirishi commented Jun 13, 2024

What changes were proposed in this pull request?

Setting ClientVersion in the ContainerCommandRequestProto object in XceiverGrpcClient send method, to ensure client version is always set on the request object.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-11013

How was this patch tested?

Existing Unit test, no functional change.

…ion in one centralised function

Change-Id: I540e518819db3ebfec1aca5b3a31d1b5ba5fee41
Change-Id: Id5abeebc078d39d15d516cf804dcdaaa3ed2467c

Change-Id: Ic5a87d9e696a462cfe92ff35a0068dfeba97541c
Copy link
Contributor

@hemantk-12 hemantk-12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @swamirishi for the patch. In general, change looks good to me. Left a comment about one change in ClientVersion.

nit: I don't think it is a good idea to provide a helper function on top of builder. I guess you have done it this way to make the version mandatory field and ContainerCommandRequestProto.newBuilder() is generated by protobuf.

Change-Id: I8936e48570d75052a32c40a9aee751628b753585
@swamirishi swamirishi requested a review from hemantk-12 June 14, 2024 00:56
@swamirishi
Copy link
Contributor Author

swamirishi commented Jun 14, 2024

Thanks @swamirishi for the patch. In general, change looks good to me. Left a comment about one change in ClientVersion.

nit: I don't think it is a good idea to provide a helper function on top of builder. I guess you have done it this way to make the version mandatory field and ContainerCommandRequestProto.newBuilder() is generated by protobuf.

Yeah I wanted to mandate client versions are being set to the latest value on all the request. I don't think there is a programatic way of doing this in protobuf. From what I know we can only set a constant value in proto file. Moreover server side and client side handling is going to be different in this patch. #6779

@swamirishi
Copy link
Contributor Author

We can deprecate this method call, when we would stop supporting older clients on the server side.

Copy link
Contributor

@hemantk-12 hemantk-12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM+1.

Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @swamirishi for extracting this.

There are two leftover calls to newBuilder in ContainerProtocolCalls (echo and readContainerFromAllNodes) and two in TestHddsDispatcher (newPutSmallFile and getWriteChunkRequest0).

@adoroszlai adoroszlai changed the title HDDS-11013. Refactor Container service request to set the client version in one centralised function HDDS-11013. Centralise ContainerCommandRequestProto.Builder creation to ensure version is set Jun 14, 2024
Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @swamirishi for the patch.

One question: instead of replacing all the calls, how about setting version in sendCommand(Async)? That would simplify this change a whole lot. It would also avoid potential problems caused by accidentally using the plain builder instead of the one created by the central functions. This should be done in both client classes.

Comment on lines 112 to 116
public static ContainerCommandRequestProto.Builder getContainerCommandRequestProtoBuilder(
ContainerCommandRequestProto req, int version) {
return (req == null ?
ContainerCommandRequestProto.newBuilder() : ContainerCommandRequestProto.newBuilder(req)).setVersion(version);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

req may already have version set. newBuilder(req) preserves that in the builder, but setVersion overwrites it. This is a problem if called via getContainerCommandRequestProtoBuilder(req), without explicit version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would have to build an object again there. Is it something we should do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that is the case we should just send a builder than sending the request object. That is also one viable change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or we can just add a validation check and throw an exception if the version is not set.


ContainerCommandRequestProto finalPayload =
ContainerCommandRequestProto.newBuilder(request)
ContainerCommandRequestProto finalPayload = getContainerCommandRequestProtoBuilder(request)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also set version conditionally here.

@adoroszlai adoroszlai changed the title HDDS-11013. Centralise ContainerCommandRequestProto.Builder creation to ensure version is set HDDS-11013. Ensure version is always set in ContainerCommandRequestProto Jun 14, 2024
Change-Id: I24026f8f2863c1b0501c781452c269a09a7c3b7c
Change-Id: I510d453b900c945814c4d665dfcee5aa14ab0476
Change-Id: I5524a82d0c77a9c01a9034cb4cd0cd2ae577b3f8
Change-Id: Icca0406b6cd1cf9edb8bd0dc350a537a397737a3
@swamirishi swamirishi requested a review from adoroszlai June 14, 2024 22:24
Change-Id: Ie101e536af7728528036a042437ff23896c3f34e
@swamirishi swamirishi marked this pull request as draft June 14, 2024 22:32
@swamirishi swamirishi requested a review from hemantk-12 June 14, 2024 23:56
@swamirishi swamirishi marked this pull request as ready for review June 14, 2024 23:56
Copy link
Contributor

@hemantk-12 hemantk-12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

List<DatanodeDetails> datanodeList = pipeline.getNodes();
HashMap<DatanodeDetails, CompletableFuture<ContainerCommandResponseProto>>
futureHashMap = new HashMap<>();
ContainerCommandRequestProto.Builder builder = ContainerCommandRequestProto.newBuilder(request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: create a helper function something likegetVersionRequest() and reuse it in other places.

Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @swamirishi for updating the patch. I think it's much simpler now. Only few nits picked.

Comment on lines 282 to 285
if (!request.hasVersion()) {
builder.setVersion(ClientVersion.CURRENT.toProtoValue());
}
ContainerCommandRequestProto finalRequest = builder.build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we only conditionally need to create newBuilder() and then build().

return TracingUtil.executeInNewSpan(spanName,
() -> {
ContainerCommandRequestProto finalPayload =
ContainerCommandRequestProto.Builder finalPayload =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: finalPayload can be renamed to builder.

try (Scope ignored = GlobalTracer.get().activateSpan(span)) {

ContainerCommandRequestProto finalPayload =
ContainerCommandRequestProto.Builder finalPayload =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: finalPayload can be renamed to builder.

public XceiverClientReply sendCommandAsync(
ContainerCommandRequestProto request
) {
final ContainerCommandRequestProto.Builder finalRequest = ContainerCommandRequestProto.newBuilder(request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: finalRequest can be renamed to builder.

Comment on lines 235 to 239
final ContainerCommandRequestProto.Builder finalRequest = ContainerCommandRequestProto.newBuilder(request);
if (!request.hasVersion()) {
finalRequest.setVersion(ClientVersion.CURRENT.toProtoValue());
}
request = finalRequest.build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we only conditionally need to create newBuilder() and then build().

final Builder builder =
ContainerCommandRequestProto.newBuilder()
ClientVersion clientVersion, ContainerProtos.Type cmdType, int replicaIndex) {
final Builder builder = ContainerCommandRequestProto.newBuilder().setVersion(clientVersion.toProtoValue())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
final Builder builder = ContainerCommandRequestProto.newBuilder().setVersion(clientVersion.toProtoValue())
final Builder builder = ContainerCommandRequestProto.newBuilder()
.setVersion(clientVersion.toProtoValue())

Change-Id: If914929863aba7e7123f3daf73e682e1416967b1
Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @swamirishi for updating the patch, LGTM.

@swamirishi swamirishi merged commit 81bc179 into apache:master Jun 17, 2024
@swamirishi
Copy link
Contributor Author

Thank your for the review @hemantk-12 @adoroszlai

xichen01 pushed a commit to xichen01/ozone that referenced this pull request Jul 17, 2024
xichen01 pushed a commit to xichen01/ozone that referenced this pull request Jul 17, 2024
xichen01 pushed a commit to xichen01/ozone that referenced this pull request Jul 18, 2024
xichen01 pushed a commit to xichen01/ozone that referenced this pull request Jul 18, 2024
ptlrs pushed a commit to ptlrs/ozone that referenced this pull request Mar 8, 2025
…andRequestProto (apache#6812)

(cherry picked from commit 81bc179)
Change-Id: I1a11a59f7d245578ff233a29c9b120974c5a413d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants