chungen0126 commented on code in PR #8399:
URL: https://github.com/apache/ozone/pull/8399#discussion_r2092748278


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3Utils.java:
##########
@@ -63,64 +64,44 @@ private S3Utils() {
    *
    * @param s3StorageTypeHeader        - s3 user passed storage type
    *                                   header.
-   * @param clientConfiguredReplConfig - Client side configured replication
-   *                                   config.
    * @param bucketReplConfig           - server side bucket default replication
    *                                   config.
+   * @param clientConfiguredReplConfig - Client side configured replication
+   *                                   config.
    * @return client resolved replication config.
    */
   public static ReplicationConfig resolveS3ClientSideReplicationConfig(
-      String s3StorageTypeHeader, ReplicationConfig clientConfiguredReplConfig,
+      String s3StorageTypeHeader, String s3StorageConfigHeader,
+      ReplicationConfig clientConfiguredReplConfig,
       ReplicationConfig bucketReplConfig)
       throws OS3Exception {
-    ReplicationConfig clientDeterminedReplConfig = null;
 
-    // Let's map the user provided s3 storage type header to ozone s3 storage
-    // type.
-    S3StorageType s3StorageType = null;
-    if (s3StorageTypeHeader != null && !s3StorageTypeHeader.equals("")) {
-      s3StorageType = toS3StorageType(s3StorageTypeHeader);
+    // If user provided s3 storage type header is not null then map it
+    // to ozone replication config
+    if (!StringUtils.isEmpty(s3StorageTypeHeader)) {
+      return toReplicationConfig(s3StorageTypeHeader, s3StorageConfigHeader);
     }
 
-    boolean isECBucket = bucketReplConfig != null && bucketReplConfig
-        .getReplicationType() == HddsProtos.ReplicationType.EC;
-
-    // if bucket replication config configured with EC, we will give high
-    // preference to server side bucket defaults.
-    // Why we give high preference to EC is, there is no way for file system
-    // interfaces to pass EC replication. So, if one configures EC at bucket,
-    // we consider EC to take preference. in short, keys created from file
-    // system under EC bucket will always be EC'd.
-    if (isECBucket) {
-      // if bucket is EC, don't bother client provided configs, let's pass
-      // bucket config.
-      clientDeterminedReplConfig = bucketReplConfig;
-    } else {
-      // Let's validate the client side available replication configs.
-      boolean isUserPassedReplicationInSupportedList =
-          s3StorageType != null && (s3StorageType.getFactor()
-              .getValue() == ReplicationFactor.ONE.getValue() || s3StorageType
-              .getFactor().getValue() == ReplicationFactor.THREE.getValue());
-      if (isUserPassedReplicationInSupportedList) {
-        clientDeterminedReplConfig = ReplicationConfig.fromProtoTypeAndFactor(
-            ReplicationType.toProto(s3StorageType.getType()),
-            ReplicationFactor.toProto(s3StorageType.getFactor()));
-      } else {
-        // API passed replication number is not in supported replication list.
-        // So, let's use whatever available in client side configured.
-        // By default it will be null, so server will use server defaults.
-        clientDeterminedReplConfig = clientConfiguredReplConfig;
-      }
-    }
-    return clientDeterminedReplConfig;
+    // If client configured replication config is null then default to bucket 
replication
+    // otherwise default to server side default replication config.
+    return (clientConfiguredReplConfig != null) ?
+        clientConfiguredReplConfig : bucketReplConfig;
   }
 
-  public static S3StorageType toS3StorageType(String storageType)
+  public static ReplicationConfig toReplicationConfig(String s3StorageType, 
String s3StorageConfig)
       throws OS3Exception {
     try {
-      return S3StorageType.valueOf(storageType);
+      if (S3StorageType.STANDARD_IA.name().equals(s3StorageType)) {

Review Comment:
   Suggest doing valueOf() first, then check the enum makes the logic clearer.
   ```
   try {
         S3StorageType storageType = S3StorageType.valueOf(s3StorageType);
         if (S3StorageType.STANDARD_IA.equals(storageType)) {
           return (!StringUtils.isEmpty(s3StorageConfig)) ? new 
ECReplicationConfig(s3StorageConfig) :
               new 
ECReplicationConfig(S3StorageType.STANDARD_IA.getEcReplicationString());
         } else {
           return ReplicationConfig.fromProtoTypeAndFactor(
               ReplicationType.toProto(storageType.getType()),
               ReplicationFactor.toProto(storageType.getFactor()));
         }
   ```



-- 
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]

Reply via email to