adoroszlai commented on a change in pull request #2430:
URL: https://github.com/apache/ozone/pull/2430#discussion_r675093653



##########
File path: 
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/client/TestReplicationConfig.java
##########
@@ -27,6 +29,23 @@
  */
 public class TestReplicationConfig {
 
+  @Test
+  public void testGetDefaultShouldCreateReplicationConfigFromConf() {
+    OzoneConfiguration conf = new OzoneConfiguration();
+    ReplicationConfig replicationConfig = ReplicationConfig.getDefault(conf);
+    Assert.assertEquals(
+        org.apache.hadoop.hdds.client.ReplicationType.RATIS.name(),
+        replicationConfig.getReplicationType().name());
+    Assert.assertEquals(3, replicationConfig.getRequiredNodes());
+    conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE, "STAND_ALONE");
+    conf.set(OzoneConfigKeys.OZONE_REPLICATION, "1");
+    replicationConfig = ReplicationConfig.getDefault(conf);
+    Assert.assertEquals(
+        org.apache.hadoop.hdds.client.ReplicationType.STAND_ALONE.name(),
+        replicationConfig.getReplicationType().name());
+    Assert.assertEquals(1, replicationConfig.getRequiredNodes());

Review comment:
       Nit: Can you please split to a separate test case?  The first part 
checks default config while the second part checks custom values.

##########
File path: 
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfig.java
##########
@@ -63,7 +64,14 @@ static ReplicationConfig fromTypeAndFactor(
   }
 
   static ReplicationConfig getDefault(ConfigurationSource config) {
-    return new RatisReplicationConfig(HddsProtos.ReplicationFactor.THREE);
+    String replication = config.get(OzoneConfigKeys.OZONE_REPLICATION);
+    String replType = config.get(OzoneConfigKeys.OZONE_REPLICATION_TYPE);
+    ReplicationConfig replicationConfig = null;
+    if (replication != null && replType != null) {
+      replicationConfig = ReplicationConfig
+          .fromTypeAndString(ReplicationType.valueOf(replType), replication);
+    }

Review comment:
       Instead of returning `null`, I think we should fall back to defaults 
(defined in `OzoneConfigKeys` for each key).
   
   ```suggestion
       String replication = config.get(OzoneConfigKeys.OZONE_REPLICATION,
           OzoneConfigKeys.OZONE_REPLICATION_DEFAULT);
       String replType = config.get(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
           OzoneConfigKeys.OZONE_REPLICATION_TYPE_DEFAULT);
       return ReplicationConfig.fromTypeAndString(
           ReplicationType.valueOf(replType), replication);
   ```




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