This is an automated email from the ASF dual-hosted git repository.

amaliujia pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 61516a11707 HDDS-17567. Add ChainedReplicationConfig for V3 pipelines. 
(#11869)
61516a11707 is described below

commit 61516a117078e067af280d557c4e2b3b41d88448
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Mon Nov 2 22:01:31 2026 -0800

    HDDS-17567. Add ChainedReplicationConfig for V3 pipelines. (#11869)
---
 .../hdds/client/ChainedReplicationConfig.java      |  45 +++++++++
 .../hadoop/hdds/client/NCopyReplicationConfig.java | 108 +++++++++++++++++++++
 .../hadoop/hdds/client/RatisReplicationConfig.java |  97 ++----------------
 .../hadoop/hdds/client/ReplicationConfig.java      |  34 +++----
 .../hadoop/hdds/client/ReplicationFactor.java      |  30 +++---
 .../apache/hadoop/hdds/client/ReplicationType.java |  33 +++----
 .../org/apache/hadoop/ozone/OzoneConfigKeys.java   |   8 +-
 7 files changed, 206 insertions(+), 149 deletions(-)

diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ChainedReplicationConfig.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ChainedReplicationConfig.java
new file mode 100644
index 00000000000..f718939d3e9
--- /dev/null
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ChainedReplicationConfig.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdds.client;
+
+import java.util.Map;
+import net.jcip.annotations.Immutable;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
+
+/**
+ * {@link ReplicationConfig} for {@link ReplicationType#CHAINED}.
+ */
+@Immutable
+public final class ChainedReplicationConfig extends NCopyReplicationConfig {
+  private static final Map<ReplicationFactor, ChainedReplicationConfig> 
CONFIGS = newMap(ChainedReplicationConfig::new);
+
+  /** @return the config with the given factor. */
+  public static ChainedReplicationConfig getInstance(ReplicationFactor factor) 
{
+    return CONFIGS.get(factor);
+  }
+
+  private ChainedReplicationConfig(ReplicationFactor factor) {
+    super(ReplicationType.CHAINED, factor);
+  }
+
+  public static boolean hasFactor(ReplicationConfig config, ReplicationFactor 
factor) {
+    return config instanceof ChainedReplicationConfig
+        && ((ChainedReplicationConfig) config).getReplicationFactor() == 
factor;
+  }
+}
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/NCopyReplicationConfig.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/NCopyReplicationConfig.java
new file mode 100644
index 00000000000..5a037c8f182
--- /dev/null
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/NCopyReplicationConfig.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdds.client;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+import net.jcip.annotations.Immutable;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
+
+/**
+ * {@link ReplicationConfig} for a {@link ReplicationType}.
+ */
+@Immutable
+abstract class NCopyReplicationConfig implements ReplicatedReplicationConfig {
+  private final ReplicationType type;
+  /** The number of copies. */
+  private final ReplicationFactor factor;
+  private final String name;
+
+  NCopyReplicationConfig(ReplicationType type, ReplicationFactor factor) {
+    this.type = Objects.requireNonNull(type, "type == null");
+    this.factor = Objects.requireNonNull(factor, "factor == null");
+    this.name = type + "/" + factor;
+  }
+
+  @Override
+  @JsonProperty("replicationType")
+  public final ReplicationType getReplicationType() {
+    return type;
+  }
+
+  @Override
+  public ReplicationFactor getReplicationFactor() {
+    return factor;
+  }
+
+  @Override
+  public int getRequiredNodes() {
+    return factor.getNumber();
+  }
+
+  @Override
+  @JsonIgnore
+  public String getReplication() {
+    return factor.name();
+  }
+
+  @Override
+  public final boolean equals(Object obj) {
+    if (this == obj) {
+      return true;
+    } else if (obj == null || obj.getClass() != this.getClass()) {
+      return false;
+    }
+    final ReplicatedReplicationConfig that = (ReplicatedReplicationConfig) obj;
+    return this.getReplicationFactor() == that.getReplicationFactor();
+  }
+
+  @Override
+  public final int hashCode() {
+    return Objects.hash(factor);
+  }
+
+  @Override
+  public final String toString() {
+    return name;
+  }
+
+  @Override
+  public final String configFormat() {
+    return name;
+  }
+
+  @Override
+  public int getMinimumNodes() {
+    return 1;
+  }
+
+  static <C extends NCopyReplicationConfig> Map<ReplicationFactor, C> newMap(
+      Function<ReplicationFactor, C> constructor) {
+    final EnumMap<ReplicationFactor, C> map = new 
EnumMap<>(ReplicationFactor.class);
+    for (ReplicationFactor f : ReplicationFactor.values()) {
+      map.put(f, constructor.apply(f));
+    }
+    return Collections.unmodifiableMap(map);
+  }
+}
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/RatisReplicationConfig.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/RatisReplicationConfig.java
index 468580c3cc3..82bd28f6a7d 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/RatisReplicationConfig.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/RatisReplicationConfig.java
@@ -17,54 +17,25 @@
 
 package org.apache.hadoop.hdds.client;
 
-import static 
org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.ONE;
-import static 
org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.THREE;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.Objects;
+import java.util.Map;
 import net.jcip.annotations.Immutable;
 import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
 import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
 
 /**
- * Replication configuration for Ratis replication.
+ * {@link ReplicationConfig} for {@link ReplicationType#RATIS}.
  */
 @Immutable
-public final class RatisReplicationConfig
-    implements ReplicatedReplicationConfig {
-
-  private final ReplicationFactor replicationFactor;
-  private static final ReplicationType REPLICATION_TYPE = 
ReplicationType.RATIS;
-
-  private static final RatisReplicationConfig RATIS_ONE_CONFIG =
-      new RatisReplicationConfig(ONE);
-
-  private static final RatisReplicationConfig RATIS_THREE_CONFIG =
-      new RatisReplicationConfig(THREE);
+public final class RatisReplicationConfig extends NCopyReplicationConfig {
+  private static final Map<ReplicationFactor, RatisReplicationConfig> CONFIGS 
= newMap(RatisReplicationConfig::new);
 
-  /**
-   * Get an instance of Ratis Replication Config with the requested factor.
-   * The same static instance will be returned for all requests for the same
-   * factor.
-   * @param factor Replication Factor requested
-   * @return RatisReplicationConfig object of the requested factor
-   */
+  /** @return the conf with the given factor. */
   public static RatisReplicationConfig getInstance(ReplicationFactor factor) {
-    if (factor == ONE) {
-      return RATIS_ONE_CONFIG;
-    } else if (factor == THREE) {
-      return RATIS_THREE_CONFIG;
-    }
-    return new RatisReplicationConfig(factor);
+    return CONFIGS.get(factor);
   }
 
-  /**
-   * Use the static getInstance method rather than the private constructor.
-   * @param replicationFactor
-   */
   private RatisReplicationConfig(ReplicationFactor replicationFactor) {
-    this.replicationFactor = replicationFactor;
+    super(ReplicationType.RATIS, replicationFactor);
   }
 
   public static boolean hasFactor(ReplicationConfig replicationConfig,
@@ -75,58 +46,4 @@ public static boolean hasFactor(ReplicationConfig 
replicationConfig,
     }
     return false;
   }
-
-  @Override
-  @JsonProperty("replicationType")
-  public ReplicationType getReplicationType() {
-    return REPLICATION_TYPE;
-  }
-
-  @Override
-  public int getRequiredNodes() {
-    return replicationFactor.getNumber();
-  }
-
-  @Override
-  public ReplicationFactor getReplicationFactor() {
-    return replicationFactor;
-  }
-
-  @Override
-  @JsonIgnore
-  public String getReplication() {
-    return String.valueOf(replicationFactor);
-  }
-
-  @Override
-  public boolean equals(Object o) {
-    if (this == o) {
-      return true;
-    }
-    if (o == null || getClass() != o.getClass()) {
-      return false;
-    }
-    RatisReplicationConfig that = (RatisReplicationConfig) o;
-    return replicationFactor == that.replicationFactor;
-  }
-
-  @Override
-  public int hashCode() {
-    return Objects.hash(replicationFactor);
-  }
-
-  @Override
-  public String toString() {
-    return REPLICATION_TYPE.name() + "/" + replicationFactor;
-  }
-
-  @Override
-  public String configFormat() {
-    return toString();
-  }
-
-  @Override
-  public int getMinimumNodes() {
-    return 1;
-  }
 }
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfig.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfig.java
index 20ddf555bcd..88ce5e3203f 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfig.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfig.java
@@ -20,9 +20,8 @@
 import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION;
 import static 
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION_DEFAULT;
 import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION_TYPE;
-import static 
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION_TYPE_DEFAULT;
+import static 
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION_TYPE_DEFAULT_TYPE;
 
-import java.util.Objects;
 import org.apache.hadoop.hdds.conf.ConfigurationSource;
 import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
 
@@ -44,6 +43,8 @@ static ReplicationConfig fromProtoTypeAndFactor(
     switch (type) {
     case RATIS:
       return RatisReplicationConfig.getInstance(factor);
+    case CHAINED:
+      return ChainedReplicationConfig.getInstance(factor);
     case STAND_ALONE:
       return StandaloneReplicationConfig.getInstance(factor);
     default:
@@ -62,15 +63,11 @@ static ReplicationConfig fromTypeAndFactor(
       org.apache.hadoop.hdds.client.ReplicationType type,
       org.apache.hadoop.hdds.client.ReplicationFactor factor
   ) {
-    return fromProtoTypeAndFactor(
-        HddsProtos.ReplicationType.valueOf(type.name()),
-        HddsProtos.ReplicationFactor.valueOf(factor.name()));
+    return fromProtoTypeAndFactor(type.toProto(), factor.toProto());
   }
 
   static ReplicationConfig getDefault(ConfigurationSource config) {
-    String replication =
-        config.get(OZONE_REPLICATION, OZONE_REPLICATION_DEFAULT);
-    return parse(null, replication, config);
+    return parse(null, null, config);
   }
 
   static ReplicationConfig resolve(ReplicationConfig replicationConfig,
@@ -98,6 +95,7 @@ static ReplicationConfig fromProto(
     case EC:
       return new ECReplicationConfig(ecConfig);
     case RATIS:
+    case CHAINED:
     case STAND_ALONE:
       return fromProtoTypeAndFactor(type, factor);
     default:
@@ -149,26 +147,23 @@ static ReplicationConfig adjustReplication(
    * @param type the ReplicationType to parse from the replication string
    * @param replication the replication String that for example contains the
    *                    replication factor for RATIS replication.
-   * @param config the current Ozone configuration to apply validation on the
-   *               parsed object.
+   * @param conf the current Ozone configuration to apply validation on the 
parsed object.
    * @return a validated ReplicationConfig object that is allowed based on the
    *         system's configuration.
    * @throws IllegalArgumentException if the parsed ReplicationConfig is not
    *         allowed by the ozone.replication.allowed-configs property, or
    *         if the give replication type or replication can not be parsed.
-   * @throws NullPointerException if the ReplicationConfig was not created
-   *         for the type.
    */
-  static ReplicationConfig parse(ReplicationType type, String replication,
-      ConfigurationSource config) {
+  static ReplicationConfig parse(ReplicationType type, String replication, 
ConfigurationSource conf) {
     if (type == null) {
-      type = ReplicationType.valueOf(
-          config.get(OZONE_REPLICATION_TYPE, OZONE_REPLICATION_TYPE_DEFAULT));
+      final String confValue = conf.get(OZONE_REPLICATION_TYPE);
+      type = confValue != null ? ReplicationType.valueOf(confValue) : 
OZONE_REPLICATION_TYPE_DEFAULT_TYPE;
+    }
+    if (replication == null) {
+      replication = conf.get(OZONE_REPLICATION, OZONE_REPLICATION_DEFAULT);
     }
-    replication = Objects.toString(replication,
-        config.get(OZONE_REPLICATION, OZONE_REPLICATION_DEFAULT));
 
-    return parseWithoutFallback(type, replication, config);
+    return parseWithoutFallback(type, replication, conf);
   }
 
   static ReplicationConfig parseWithoutFallback(ReplicationType type,
@@ -186,6 +181,7 @@ static ReplicationConfig 
parseWithoutFallback(ReplicationType type,
     ReplicationConfig replicationConfig;
     switch (type) {
     case RATIS:
+    case CHAINED:
     case STAND_ALONE:
       ReplicationFactor factor;
       try {
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationFactor.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationFactor.java
index 9f47cc2fd26..3578a0d207a 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationFactor.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationFactor.java
@@ -23,8 +23,16 @@
  * The replication factor to be used while writing key into ozone.
  */
 public enum ReplicationFactor {
-  ONE,
-  THREE;
+  ONE(1, HddsProtos.ReplicationFactor.ONE),
+  THREE(3, HddsProtos.ReplicationFactor.THREE);
+
+  private final int value;
+  private final HddsProtos.ReplicationFactor proto;
+
+  ReplicationFactor(int value, HddsProtos.ReplicationFactor proto) {
+    this.value = value;
+    this.proto = proto;
+  }
 
   /**
    * Returns enum value corresponding to the int value.
@@ -66,25 +74,11 @@ public static HddsProtos.ReplicationFactor toProto(
   }
 
   public HddsProtos.ReplicationFactor toProto() {
-    switch (this) {
-    case ONE:
-      return HddsProtos.ReplicationFactor.ONE;
-    case THREE:
-      return HddsProtos.ReplicationFactor.THREE;
-    default:
-      throw new IllegalStateException("Unexpected enum value: " + this);
-    }
+    return proto;
   }
 
   /** @return the number of replication(s). */
   public int getValue() {
-    switch (this) {
-    case ONE:
-      return 1;
-    case THREE:
-      return 3;
-    default:
-      throw new IllegalStateException("Unexpected enum value: " + this);
-    }
+    return value;
   }
 }
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationType.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationType.java
index d1247b24b54..0c23beaf816 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationType.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationType.java
@@ -23,11 +23,20 @@
  * The replication type to be used while writing key into ozone.
  */
 public enum ReplicationType {
-  RATIS,
-  STAND_ALONE,
-  @Deprecated
-  CHAINED,
-  EC;
+  RATIS(HddsProtos.ReplicationType.RATIS),
+  STAND_ALONE(HddsProtos.ReplicationType.STAND_ALONE),
+  CHAINED(HddsProtos.ReplicationType.CHAINED),
+  EC(HddsProtos.ReplicationType.EC);
+
+  private final HddsProtos.ReplicationType proto;
+
+  ReplicationType(HddsProtos.ReplicationType proto) {
+    this.proto = proto;
+  }
+
+  public HddsProtos.ReplicationType toProto() {
+    return proto;
+  }
 
   public static ReplicationType fromProto(
       HddsProtos.ReplicationType replicationType) {
@@ -54,18 +63,6 @@ public static HddsProtos.ReplicationType toProto(
     if (replicationType == null) {
       return null;
     }
-    switch (replicationType) {
-    case RATIS:
-      return HddsProtos.ReplicationType.RATIS;
-    case STAND_ALONE:
-      return HddsProtos.ReplicationType.STAND_ALONE;
-    case CHAINED:
-      return HddsProtos.ReplicationType.CHAINED;
-    case EC:
-      return HddsProtos.ReplicationType.EC;
-    default:
-      throw new IllegalArgumentException(
-          "Unsupported replication type: " + replicationType);
-    }
+    return replicationType.toProto();
   }
 }
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java
index a6fcb792eea..0627c776fed 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java
@@ -250,12 +250,12 @@ public final class OzoneConfigKeys {
   public static final int OZONE_CLIENT_CONNECTION_TIMEOUT_DEFAULT = 5000;
 
   public static final String OZONE_REPLICATION = "ozone.replication";
-  public static final String OZONE_REPLICATION_DEFAULT =
-      ReplicationFactor.THREE.toString();
+  public static final ReplicationFactor OZONE_REPLICATION_DEFAULT_FACTOR = 
ReplicationFactor.THREE;
+  public static final String OZONE_REPLICATION_DEFAULT = 
OZONE_REPLICATION_DEFAULT_FACTOR.name();
 
   public static final String OZONE_REPLICATION_TYPE = "ozone.replication.type";
-  public static final String OZONE_REPLICATION_TYPE_DEFAULT =
-      ReplicationType.RATIS.toString();
+  public static final ReplicationType OZONE_REPLICATION_TYPE_DEFAULT_TYPE = 
ReplicationType.RATIS;
+  public static final String OZONE_REPLICATION_TYPE_DEFAULT = 
OZONE_REPLICATION_TYPE_DEFAULT_TYPE.name();
 
   /**
    * Configuration property to configure the cache size of client list calls.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to