This is an automated email from the ASF dual-hosted git repository.
devmadhuu pushed a commit to branch HDDS-11233
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/HDDS-11233 by this push:
new f4dcbde0c69 HDDS-17607. Support single node s3 deployment in
S3StorageClassResolver. (#11867)
f4dcbde0c69 is described below
commit f4dcbde0c6967746b72897fa205655bbe0eaf147
Author: Devesh Kumar Singh <[email protected]>
AuthorDate: Wed Nov 4 17:51:37 2026 +0530
HDDS-17607. Support single node s3 deployment in S3StorageClassResolver.
(#11867)
---
.../common/src/main/resources/ozone-default.xml | 2 +
.../hadoop/ozone/s3/S3GatewayConfigKeys.java | 2 +-
.../ozone/s3/util/S3StorageClassResolver.java | 51 +++++++-
.../org/apache/hadoop/ozone/s3/TestGateway.java | 16 +++
.../hadoop/ozone/s3/util/TestS3StorageClass.java | 132 ++++++++++++++++++++-
5 files changed, 198 insertions(+), 5 deletions(-)
diff --git a/hadoop-hdds/common/src/main/resources/ozone-default.xml
b/hadoop-hdds/common/src/main/resources/ozone-default.xml
index df8734846d4..99d01a3b0a5 100644
--- a/hadoop-hdds/common/src/main/resources/ozone-default.xml
+++ b/hadoop-hdds/common/src/main/resources/ozone-default.xml
@@ -2145,7 +2145,9 @@
<description>
When true, a request with x-amz-storage-class STANDARD uses
ozone.replication and
ozone.replication.type, if ozone.replication is set, instead of
RATIS/THREE.
+ Other storage classes and storage policies are unaffected.
The ozone local runtime sets it to true.
+ S3 Gateway reads this setting when it starts. Restart S3 Gateway after
changing it.
</description>
</property>
diff --git
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/S3GatewayConfigKeys.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/S3GatewayConfigKeys.java
index 2f6ab73554f..c30a7bf7834 100644
---
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/S3GatewayConfigKeys.java
+++
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/S3GatewayConfigKeys.java
@@ -104,7 +104,7 @@ public final class S3GatewayConfigKeys {
/**
* Configuration key that makes an explicit {@code x-amz-storage-class:
STANDARD} use the {@code ozone.replication}
- * setting, when set, instead of {@link
org.apache.hadoop.ozone.s3.util.S3StorageType#STANDARD}.
+ * setting, when set, instead of RATIS/THREE.
*/
public static final String
OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY =
"ozone.s3g.standard.storage-class.use-client-default";
diff --git
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3StorageClassResolver.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3StorageClassResolver.java
index 97be25b6d8f..71eae36ba1a 100644
---
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3StorageClassResolver.java
+++
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3StorageClassResolver.java
@@ -17,9 +17,13 @@
package org.apache.hadoop.ozone.s3.util;
+import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_DEFAULT;
+import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY;
import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STORAGE_CLASS_REDUCED_REDUNDANCY_STORAGE_POLICY;
import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STORAGE_CLASS_STANDARD_IA_STORAGE_POLICY;
import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STORAGE_CLASS_STANDARD_STORAGE_POLICY;
+import static
org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_STORAGE_CLASS;
+import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
@@ -32,6 +36,7 @@
import org.apache.hadoop.hdds.client.StoragePolicy;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
/**
* Maps between S3 storage class names and Ozone replication and storage
policy.
@@ -54,9 +59,10 @@ public final class S3StorageClassResolver {
private final S3StorageClassSpec standardSpec;
private final S3StorageClassSpec reducedRedundancySpec;
private final S3StorageClassSpec standardIaSpec;
+ private final boolean standardUsesClientDefault;
/**
- * Resolves gateway storage policy settings once, before the gateway accepts
requests.
+ * Resolves gateway storage class settings once, before the gateway accepts
requests.
*
* @param conf gateway configuration
* @throws IllegalArgumentException if any configured storage policy is not
valid
@@ -68,6 +74,8 @@ public S3StorageClassResolver(ConfigurationSource conf) {
getConfiguredStoragePolicy(conf,
OZONE_S3G_STORAGE_CLASS_REDUCED_REDUNDANCY_STORAGE_POLICY));
standardIaSpec = S3StorageClass.STANDARD_IA.getSpec().withStoragePolicy(
getConfiguredStoragePolicy(conf,
OZONE_S3G_STORAGE_CLASS_STANDARD_IA_STORAGE_POLICY));
+ standardUsesClientDefault =
conf.getBoolean(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
+ OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_DEFAULT);
}
/**
@@ -76,6 +84,8 @@ public S3StorageClassResolver(ConfigurationSource conf) {
* <p>For {@code STANDARD}, {@code REDUCED_REDUNDANCY}, and {@code
STANDARD_IA}, the storage policy comes from the
* class's gateway setting resolved at startup. When the setting is empty,
the spec has no storage policy and the
* write path uses the bucket's policy or the cluster default. Configuration
is not read during request lookup.
+ * The spec retains the class's replication defaults. Use {@link
#resolveReplicationConfig} to also apply the
+ * STANDARD client-default replication setting.
*
* @param s3StorageClass the {@code x-amz-storage-class} header value
* @throws IllegalArgumentException if the storage class is null or unknown
@@ -95,9 +105,46 @@ public S3StorageClassSpec toSpec(String s3StorageClass) {
}
}
+ /**
+ * Resolves replication for a request, including the STANDARD client-default
setting.
+ *
+ * <p>When the setting is enabled and the request specifies STANDARD, a
non-null client replication config is used
+ * unchanged, including its EC layout. The storage-config header and bucket
replication do not override it.
+ * Otherwise, explicit classes use their spec's replication rules. A missing
or empty class header uses client
+ * replication, then bucket replication, or null so the server can apply its
default.
+ * For explicit classes, storage policy is resolved separately through
{@link #toSpec} and is unaffected.
+ *
+ * @param s3StorageClass the x-amz-storage-class header value, or null
+ * @param storageConfigHeader the storage-config header value, or null
+ * @param clientReplicationConfig replication from the gateway's
ozone.replication settings, or null
+ * @param bucketReplicationConfig the bucket's default replication, or null
+ * @return the resolved replication, or null to use the server default
+ * @throws OS3Exception with {@code INVALID_STORAGE_CLASS} if the class is
unknown or its EC layout header is invalid
+ */
+ @Nullable
+ public ReplicationConfig resolveReplicationConfig(@Nullable String
s3StorageClass,
+ @Nullable String storageConfigHeader, @Nullable ReplicationConfig
clientReplicationConfig,
+ @Nullable ReplicationConfig bucketReplicationConfig) {
+ try {
+ if (StringUtils.isEmpty(s3StorageClass)) {
+ return clientReplicationConfig != null ? clientReplicationConfig :
bucketReplicationConfig;
+ }
+ S3StorageClass storageClass =
S3StorageClass.fromS3StorageClass(s3StorageClass);
+ if (standardUsesClientDefault && storageClass == S3StorageClass.STANDARD
&& clientReplicationConfig != null) {
+ return clientReplicationConfig;
+ }
+ return toReplicationConfig(toSpec(s3StorageClass), storageConfigHeader,
bucketReplicationConfig);
+ } catch (IllegalArgumentException e) {
+ throw newError(INVALID_STORAGE_CLASS, s3StorageClass, e);
+ }
+ }
+
/**
* The replication config for a write with the given spec.
*
+ * <p>This conversion does not apply client replication settings. Request
handlers should use
+ * {@link #resolveReplicationConfig} to honor the STANDARD client-default
setting.
+ *
* <p>The spec must supply a supported replication type (RATIS or EC). A
missing type is rejected even when a bucket
* replication config is supplied.
*
@@ -111,7 +158,7 @@ public S3StorageClassSpec toSpec(String s3StorageClass) {
* {@code storageConfigHeader} is not a valid EC layout
*/
@Nonnull
- public static ReplicationConfig toReplicationConfig(S3StorageClassSpec spec,
+ static ReplicationConfig toReplicationConfig(S3StorageClassSpec spec,
@Nullable String storageConfigHeader, @Nullable ReplicationConfig
bucketReplicationConfig) {
ReplicationType type = spec.getReplicationType();
if (type == ReplicationType.EC) {
diff --git
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestGateway.java
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestGateway.java
index a8b6af4cc05..d5ba194d4d5 100644
---
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestGateway.java
+++
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestGateway.java
@@ -18,6 +18,7 @@
package org.apache.hadoop.ozone.s3;
import static org.apache.hadoop.hdds.cli.GenericCli.EXECUTION_ERROR_EXIT_CODE;
+import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY;
import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STORAGE_CLASS_REDUCED_REDUNDANCY_STORAGE_POLICY;
import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STORAGE_CLASS_STANDARD_IA_STORAGE_POLICY;
import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STORAGE_CLASS_STANDARD_STORAGE_POLICY;
@@ -39,8 +40,12 @@
import java.util.logging.Handler;
import java.util.logging.LogManager;
import java.util.logging.Logger;
+import org.apache.hadoop.hdds.client.ECReplicationConfig;
import org.apache.hadoop.hdds.client.OzoneStoragePolicy;
+import org.apache.hadoop.hdds.client.RatisReplicationConfig;
+import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
import org.apache.hadoop.ozone.s3.util.S3StorageClassResolver;
import org.apache.ozone.test.GenericTestUtils.LogCapturer;
import org.junit.jupiter.api.AfterEach;
@@ -121,18 +126,23 @@ public void start() {
@Test
void keepsResolverForTheInitialConfiguration() {
OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setBoolean(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
true);
conf.set(OZONE_S3G_STORAGE_CLASS_STANDARD_STORAGE_POLICY, "HOT");
conf.set(OZONE_S3G_STORAGE_CLASS_REDUCED_REDUNDANCY_STORAGE_POLICY,
"WARM");
conf.set(OZONE_S3G_STORAGE_CLASS_STANDARD_IA_STORAGE_POLICY, "HOT");
OzoneConfigurationHolder.setConfiguration(conf);
S3StorageClassResolver resolver =
OzoneConfigurationHolder.storageClassResolver();
+ conf.setBoolean(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
false);
OzoneConfiguration ignored = new OzoneConfiguration();
ignored.set(OZONE_S3G_STORAGE_CLASS_STANDARD_STORAGE_POLICY, "COLD");
OzoneConfigurationHolder.setConfiguration(ignored);
assertSame(conf, OzoneConfigurationHolder.configuration());
assertSame(resolver, OzoneConfigurationHolder.storageClassResolver());
+ ReplicationConfig clientConfig = new ECReplicationConfig("rs-6-3-512k");
+ assertThat(resolver.resolveReplicationConfig(S3_STORAGE_CLASS_STANDARD,
null, clientConfig, null))
+ .isEqualTo(clientConfig);
assertEquals(OzoneStoragePolicy.HOT,
resolver.toSpec(S3_STORAGE_CLASS_STANDARD).getStoragePolicy());
assertEquals(OzoneStoragePolicy.WARM,
resolver.toSpec(S3_STORAGE_CLASS_REDUCED_REDUNDANCY).getStoragePolicy());
assertEquals(OzoneStoragePolicy.HOT,
resolver.toSpec(S3_STORAGE_CLASS_STANDARD_IA).getStoragePolicy());
@@ -141,6 +151,7 @@ void keepsResolverForTheInitialConfiguration() {
@Test
void resetsResolverWithConfiguration() {
OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setBoolean(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
true);
conf.set(OZONE_S3G_STORAGE_CLASS_STANDARD_STORAGE_POLICY, "HOT");
conf.set(OZONE_S3G_STORAGE_CLASS_STANDARD_IA_STORAGE_POLICY, "HOT");
OzoneConfigurationHolder.setConfiguration(conf);
@@ -157,6 +168,11 @@ void resetsResolverWithConfiguration() {
S3StorageClassResolver resolver =
OzoneConfigurationHolder.storageClassResolver();
assertSame(next, OzoneConfigurationHolder.configuration());
assertNotSame(previous, resolver);
+ ReplicationConfig clientConfig = new ECReplicationConfig("rs-6-3-512k");
+ assertThat(previous.resolveReplicationConfig(S3_STORAGE_CLASS_STANDARD,
null, clientConfig, null))
+ .isEqualTo(clientConfig);
+ assertThat(resolver.resolveReplicationConfig(S3_STORAGE_CLASS_STANDARD,
null, clientConfig, null))
+
.isEqualTo(RatisReplicationConfig.getInstance(ReplicationFactor.THREE));
assertEquals(OzoneStoragePolicy.WARM,
resolver.toSpec(S3_STORAGE_CLASS_STANDARD).getStoragePolicy());
assertEquals(OzoneStoragePolicy.HOT,
previous.toSpec(S3_STORAGE_CLASS_STANDARD_IA).getStoragePolicy());
assertEquals(OzoneStoragePolicy.WARM,
resolver.toSpec(S3_STORAGE_CLASS_STANDARD_IA).getStoragePolicy());
diff --git
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestS3StorageClass.java
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestS3StorageClass.java
index 42c4cff727a..fda73f7fc6a 100644
---
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestS3StorageClass.java
+++
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestS3StorageClass.java
@@ -17,6 +17,7 @@
package org.apache.hadoop.ozone.s3.util;
+import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY;
import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STORAGE_CLASS_REDUCED_REDUNDANCY_STORAGE_POLICY;
import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STORAGE_CLASS_STANDARD_IA_STORAGE_POLICY;
import static
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_STORAGE_CLASS_STANDARD_STORAGE_POLICY;
@@ -25,6 +26,7 @@
import static
org.apache.hadoop.ozone.s3.util.S3Consts.S3_STORAGE_CLASS_REDUCED_REDUNDANCY;
import static
org.apache.hadoop.ozone.s3.util.S3Consts.S3_STORAGE_CLASS_STANDARD;
import static
org.apache.hadoop.ozone.s3.util.S3Consts.S3_STORAGE_CLASS_STANDARD_IA;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -44,9 +46,12 @@
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
+import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.ValueSource;
/** Tests the S3 storage class mapping to Ozone replication and storage
policy. */
class TestS3StorageClass {
@@ -271,8 +276,7 @@ void testForwardReusesPoliciesResolvedAtConstruction() {
}
/**
- * A STANDARD write with a configured storage policy must read back as
STANDARD, so changing the
- * setting never relabels objects.
+ * Without the client replication override, each class round-trips with its
configured storage policy.
*/
@Test
void testConfiguredPolicyRoundTripsToSameClass() {
@@ -329,6 +333,130 @@ void testForwardRatisReplication() {
resolver.toSpec(S3_STORAGE_CLASS_REDUCED_REDUNDANCY), null, null));
}
+ @Test
+ void testStandardClientOverrideDisabledByDefault() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ for (String setting : Arrays.asList(null, "false")) {
+ if (setting != null) {
+ conf.set(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
setting);
+ }
+ S3StorageClassResolver resolver = new S3StorageClassResolver(conf);
+ for (ReplicationConfig clientConfig : REPLICATIONS) {
+
assertThat(resolver.resolveReplicationConfig(S3_STORAGE_CLASS_STANDARD,
"INVALID", clientConfig, EC_6_3))
+ .isEqualTo(RATIS_THREE);
+ }
+ }
+ }
+
+ @Test
+ void testStandardUsesCompleteClientReplicationWhenEnabled() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setBoolean(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
true);
+ S3StorageClassResolver resolver = new S3StorageClassResolver(conf);
+ for (ReplicationConfig clientConfig : REPLICATIONS) {
+ assertThat(resolver.resolveReplicationConfig(S3_STORAGE_CLASS_STANDARD,
null, clientConfig, EC_3_2))
+ .isEqualTo(clientConfig);
+ }
+
+ ReplicationConfig clientConfig = new ECReplicationConfig("rs-6-3-512k");
+ for (String header : Arrays.asList("STANDARD", " STANDARD ")) {
+ for (String layout : Arrays.asList(null, "", "rs-3-2-1024k", "INVALID"))
{
+ assertThat(resolver.resolveReplicationConfig(header, layout,
clientConfig, EC_3_2)).isEqualTo(clientConfig);
+ }
+ }
+ }
+
+ @Test
+ void testStandardWithoutClientReplicationStillUsesRatisThree() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setBoolean(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
true);
+ S3StorageClassResolver resolver = new S3StorageClassResolver(conf);
+ for (ReplicationConfig bucketConfig : Arrays.asList(null, RATIS_ONE,
EC_6_3)) {
+ assertThat(resolver.resolveReplicationConfig(S3_STORAGE_CLASS_STANDARD,
"rs-6-3-512k", null, bucketConfig))
+ .isEqualTo(RATIS_THREE);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testClientOverrideDoesNotChangeOtherClasses(boolean enabled) {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setBoolean(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
enabled);
+ S3StorageClassResolver resolver = new S3StorageClassResolver(conf);
+
assertThat(resolver.resolveReplicationConfig(S3_STORAGE_CLASS_REDUCED_REDUNDANCY,
"INVALID", EC_6_3, EC_3_2))
+ .isEqualTo(RATIS_ONE);
+ assertThat(resolver.resolveReplicationConfig(S3_STORAGE_CLASS_GLACIER,
"INVALID", RATIS_ONE, EC_6_3))
+ .isEqualTo(RATIS_THREE);
+ for (String storageClass : Arrays.asList(S3_STORAGE_CLASS_STANDARD_IA,
S3_STORAGE_CLASS_DEEP_ARCHIVE)) {
+ assertThat(resolver.resolveReplicationConfig(storageClass,
"rs-6-3-512k", RATIS_ONE, EC_3_2))
+ .isEqualTo(new ECReplicationConfig("rs-6-3-512k"));
+ assertThat(resolver.resolveReplicationConfig(storageClass, null,
RATIS_ONE, EC_6_3)).isEqualTo(EC_6_3);
+ assertThat(resolver.resolveReplicationConfig(storageClass, "", EC_3_2,
EC_6_3)).isEqualTo(EC_6_3);
+ assertThat(resolver.resolveReplicationConfig(storageClass, null, EC_6_3,
RATIS_ONE)).isEqualTo(EC_3_2);
+ assertThat(resolver.resolveReplicationConfig(storageClass, null, EC_6_3,
null)).isEqualTo(EC_3_2);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testMissingClassUsesClientThenBucketReplication(boolean enabled) {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setBoolean(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
enabled);
+ S3StorageClassResolver resolver = new S3StorageClassResolver(conf);
+ for (String header : Arrays.asList(null, "")) {
+ for (String layout : Arrays.asList(null, "INVALID")) {
+ assertThat(resolver.resolveReplicationConfig(header, layout,
RATIS_ONE, EC_6_3)).isEqualTo(RATIS_ONE);
+ assertThat(resolver.resolveReplicationConfig(header, layout, EC_6_3,
null)).isEqualTo(EC_6_3);
+ assertThat(resolver.resolveReplicationConfig(header, layout, null,
EC_6_3)).isEqualTo(EC_6_3);
+ assertThat(resolver.resolveReplicationConfig(header, layout, null,
null)).isNull();
+ }
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testRequestMappingRejectsInvalidHeaders(boolean enabled) {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setBoolean(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
enabled);
+ S3StorageClassResolver resolver = new S3StorageClassResolver(conf);
+ for (String header : Arrays.asList("INVALID", "standard", " \t ")) {
+ OS3Exception exception = assertThrows(OS3Exception.class,
+ () -> resolver.resolveReplicationConfig(header, null, EC_6_3,
RATIS_ONE));
+
assertThat(exception.getCode()).isEqualTo(S3ErrorTable.INVALID_STORAGE_CLASS.getCode());
+
assertThat(exception.getHttpCode()).isEqualTo(S3ErrorTable.INVALID_STORAGE_CLASS.getHttpCode());
+ }
+ for (String storageClass : Arrays.asList(S3_STORAGE_CLASS_STANDARD_IA,
S3_STORAGE_CLASS_DEEP_ARCHIVE)) {
+ OS3Exception exception = assertThrows(OS3Exception.class,
+ () -> resolver.resolveReplicationConfig(storageClass, "INVALID",
EC_6_3, EC_3_2));
+
assertThat(exception.getCode()).isEqualTo(S3ErrorTable.INVALID_STORAGE_CLASS.getCode());
+
assertThat(exception.getHttpCode()).isEqualTo(S3ErrorTable.INVALID_STORAGE_CLASS.getHttpCode());
+ }
+ }
+
+ @Test
+ void testClientOverridePreservesStoragePolicyAndReverseMapping() {
+ for (String policy : Arrays.asList("", "HOT", "WARM")) {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(OZONE_S3G_STORAGE_CLASS_STANDARD_STORAGE_POLICY, policy);
+ S3StorageClassSpec defaultSpec = new
S3StorageClassResolver(conf).toSpec(S3_STORAGE_CLASS_STANDARD);
+ conf.setBoolean(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
true);
+ S3StorageClassResolver resolver = new S3StorageClassResolver(conf);
+ S3StorageClassSpec spec = resolver.toSpec(S3_STORAGE_CLASS_STANDARD);
+ assertThat(spec).isEqualTo(defaultSpec);
+
+ ReplicationConfig ec =
resolver.resolveReplicationConfig(S3_STORAGE_CLASS_STANDARD, null, EC_6_3,
RATIS_THREE);
+ assertThat(ec).isEqualTo(EC_6_3);
+ assertThat(S3StorageClassResolver.toS3StorageClass(ec,
spec.getStoragePolicy()))
+ .isEqualTo(S3StorageClass.STANDARD_IA);
+ ReplicationConfig ratis =
resolver.resolveReplicationConfig(S3_STORAGE_CLASS_STANDARD, null, RATIS_ONE,
EC_6_3);
+ assertThat(ratis).isEqualTo(RATIS_ONE);
+ assertThat(S3StorageClassResolver.toS3StorageClass(ratis,
spec.getStoragePolicy()))
+ .isEqualTo(S3StorageClass.REDUCED_REDUNDANCY);
+
assertThat(resolver.toSpec(S3_STORAGE_CLASS_GLACIER).getStoragePolicy()).isEqualTo(OzoneStoragePolicy.COLD);
+
assertThat(resolver.toSpec(S3_STORAGE_CLASS_DEEP_ARCHIVE).getStoragePolicy()).isEqualTo(OzoneStoragePolicy.COLD);
+ }
+ }
+
@Test
void testForwardRejectsMissingReplicationTypeWithBucketDefault() {
S3StorageClassSpec spec = S3StorageClassSpec.newBuilder()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]