szetszwo commented on code in PR #9796:
URL: https://github.com/apache/ozone/pull/9796#discussion_r2848931904
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/ha/HadoopRpcOMFollowerReadFailoverProxyProvider.java:
##########
@@ -213,7 +228,26 @@ public Object invoke(Object proxy, final Method method,
final Object[] args)
return method.invoke(this, args);
}
OMRequest omRequest = parseOMRequest(args);
- if (useFollowerRead && OmUtils.shouldSendToFollower(omRequest)) {
+
+ // Apply default consistency hint once, before any routing decision.
+ // In the future, we will support per-request hints which allows client
(e.g. S3 clients)
+ // to specify a custom request header (e.g. x-ozone-read-consistency) as
a consistency hint
+ // for read requests.
+ boolean isFollowerReadEligible = useFollowerRead &&
OmUtils.shouldSendToFollower(omRequest);
+ if (!omRequest.hasReadConsistencyHint()) {
+ ReadConsistencyProto defaultReadConsistency = isFollowerReadEligible
+ ? followerReadConsistencyType : leaderReadConsistencyType;
+ if (defaultReadConsistency != null &&
+ defaultReadConsistency !=
ReadConsistencyProto.UNKNOWN_READ_CONSISTENCY) {
+ omRequest = omRequest.toBuilder()
+ .setReadConsistencyHint(ReadConsistencyHint.newBuilder()
+ .setReadConsistency(defaultReadConsistency).build())
+ .build();
Review Comment:
Change them to followerReadConsistencyType and leaderReadConsistencyType to
ReadConsistencyHint. So it does not need to build again and again.
```java
{
....
this.followerReadConsistencyType =
getReadConsistencyHint(followerReadConsistencyType);
this.leaderReadConsistencyType =
getReadConsistencyHint(leaderReadConsistencyType);
}
static ReadConsistencyHint getReadConsistencyHint(ReadConsistencyProto
type) {
return type == ReadConsistencyProto.UNKNOWN_READ_CONSISTENCY ? null
: ReadConsistencyHint.newBuilder().setReadConsistency(type).build();
}
```
```java
if (!omRequest.hasReadConsistencyHint()) {
final ReadConsistencyHint defaultReadConsistency =
isFollowerReadEligible
? followerReadConsistencyType : leaderReadConsistencyType;
if (defaultReadConsistency != null) {
omRequest = omRequest.toBuilder()
.setReadConsistencyHint(defaultReadConsistency)
.build();
args[1] = omRequest;
}
}
```
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/ha/HadoopRpcOMFollowerReadFailoverProxyProvider.java:
##########
@@ -213,7 +228,26 @@ public Object invoke(Object proxy, final Method method,
final Object[] args)
return method.invoke(this, args);
}
OMRequest omRequest = parseOMRequest(args);
- if (useFollowerRead && OmUtils.shouldSendToFollower(omRequest)) {
+
+ // Apply default consistency hint once, before any routing decision.
+ // In the future, we will support per-request hints which allows client
(e.g. S3 clients)
+ // to specify a custom request header (e.g. x-ozone-read-consistency) as
a consistency hint
+ // for read requests.
+ boolean isFollowerReadEligible = useFollowerRead &&
OmUtils.shouldSendToFollower(omRequest);
+ if (!omRequest.hasReadConsistencyHint()) {
+ ReadConsistencyProto defaultReadConsistency = isFollowerReadEligible
+ ? followerReadConsistencyType : leaderReadConsistencyType;
+ if (defaultReadConsistency != null &&
+ defaultReadConsistency !=
ReadConsistencyProto.UNKNOWN_READ_CONSISTENCY) {
+ omRequest = omRequest.toBuilder()
+ .setReadConsistencyHint(ReadConsistencyHint.newBuilder()
+ .setReadConsistency(defaultReadConsistency).build())
+ .build();
Review Comment:
Change them to followerReadConsistencyType and leaderReadConsistencyType to
ReadConsistencyHint. So it does not need to build again and again.
```java
{
....
this.followerReadConsistencyType =
getReadConsistencyHint(followerReadConsistencyType);
this.leaderReadConsistencyType =
getReadConsistencyHint(leaderReadConsistencyType);
}
static ReadConsistencyHint getReadConsistencyHint(ReadConsistencyProto
type) {
return type == ReadConsistencyProto.UNKNOWN_READ_CONSISTENCY ? null
: ReadConsistencyHint.newBuilder().setReadConsistency(type).build();
}
```
```java
if (!omRequest.hasReadConsistencyHint()) {
final ReadConsistencyHint defaultReadConsistency =
isFollowerReadEligible
? followerReadConsistencyType : leaderReadConsistencyType;
if (defaultReadConsistency != null) {
omRequest = omRequest.toBuilder()
.setReadConsistencyHint(defaultReadConsistency)
.build();
args[1] = omRequest;
}
}
```
--
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]