adoroszlai commented on code in PR #9696:
URL: https://github.com/apache/ozone/pull/9696#discussion_r3049713990
##########
hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/OmMetadataGenerator.java:
##########
@@ -464,4 +527,47 @@ enum Operation {
INFO_VOLUME,
MIXED,
}
+
+ private List<String> getOMFollowerNodeIds(OzoneClient ozoneClient) throws
IOException {
+ List<OMRoleInfo> omRoleInfos = ozoneClient.getProxy().getOmRoleInfos();
+ String leaderOMNodeId = null;
+ List<String> followerOMNodeIds = new ArrayList<>();
+ for (OMRoleInfo omRoleInfo : omRoleInfos) {
+ if (omRoleInfo.getServerRole().equals("LEADER")) {
+ if (leaderOMNodeId != null) {
+ // This situation should be rare
+ throw new IllegalStateException("There are more than one leader
detected, please retry again");
+ }
+ leaderOMNodeId = omRoleInfo.getNodeId();
+ } else if (omRoleInfo.getServerRole().equals("FOLLOWER")) {
+ followerOMNodeIds.add(omRoleInfo.getNodeId());
+ }
+ }
+ if (followerOMNodeIds.isEmpty()) {
+ throw new IllegalArgumentException("There is no follower in the OM
service, please retry again");
+ }
+ return followerOMNodeIds;
+ }
+
+ private void changeInitialProxyForFollowerRead(OzoneClient ozoneClient,
String omNodeId) {
+ OzoneManagerProtocolClientSideTranslatorPB ozoneManagerClient =
+ (OzoneManagerProtocolClientSideTranslatorPB)
+ ozoneClient.getProxy().getOzoneManagerClient();
+
+ OmTransport transport = ozoneManagerClient.getTransport();
+
+ if (transport instanceof Hadoop3OmTransport) {
+ Hadoop3OmTransport hadoop3OmTransport =
+ (Hadoop3OmTransport) ozoneManagerClient.getTransport();
Review Comment:
```suggestion
(Hadoop3OmTransport) transport;
```
##########
hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/OmMetadataGenerator.java:
##########
@@ -134,15 +143,28 @@ public class OmMetadataGenerator extends
BaseFreonGenerator
)
private String omServiceID;
+ @Option(
+ names = "--clients",
+ description = "The number of Ozone clients used. If zero or less, " +
+ "will fallback to 1",
Review Comment:
nit: I don't think we need to describe invalid input handling in the
description
##########
hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/OmMetadataGenerator.java:
##########
@@ -165,18 +187,43 @@ public Void call() throws Exception {
OzoneConfiguration conf = createOzoneConfiguration();
replicationConfig = replication.fromParamsOrConfig(conf);
- try (OzoneClient rpcClient = createOzoneClient(omServiceID, conf)) {
- ensureVolumeAndBucketExist(rpcClient, volumeName, bucketName);
- ozoneManagerClient = createOmClient(conf, omServiceID);
- bucket = rpcClient.getObjectStore().getVolume(volumeName)
- .getBucket(bucketName);
+ if (clientsNo <= 0) {
+ clientsNo = 1;
+ }
+
+ try (OzoneClient ozClient = createOzoneClient(omServiceID, conf)) {
+ ensureVolumeAndBucketExist(ozClient, volumeName, bucketName);
+
+ ozoneClients = new OzoneClient[clientsNo];
+ List<String> followerOMNodeIds = null;
+ int currentFollowerAffinityIndex = 0;
+ if (enableFollowerAffinity) {
+ followerOMNodeIds = getOMFollowerNodeIds(ozClient);
+ }
+ for (int i = 0; i < clientsNo; i++) {
+ OzoneClient ozoneClient = createOzoneClient(omServiceID, conf);
+ if (enableFollowerAffinity) {
+ // Point the client proxy to the followers in a round-robin fashion
+ // This balances the read loads on the OM followers
+ String followerNodeId =
followerOMNodeIds.get(currentFollowerAffinityIndex);
+ changeInitialProxyForFollowerRead(ozoneClient, followerNodeId);
+ currentFollowerAffinityIndex = (currentFollowerAffinityIndex + 1) %
followerOMNodeIds.size();
+ LOG.debug("Connected OzoneClient-{} to OM follower {}", i + 1,
followerNodeId);
+ }
+ ozoneClients[i] = ozoneClient;
+ }
runTests(this::applyOperation);
} finally {
- if (ozoneManagerClient != null) {
- ozoneManagerClient.close();
- omKeyArgsBuilder.remove();
+ if (ozoneClients != null) {
+ for (OzoneClient ozoneClient : ozoneClients) {
+ if (ozoneClient != null) {
+ ozoneClient.close();
+ }
+ }
}
Review Comment:
nit: can simplify
```java
IOUtils.closeQuietly(ozoneClients);
```
--
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]