Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError;
import static org.apache.hadoop.ozone.s3.util.S3Consts.AWS_TAG_PREFIX;
import static org.apache.hadoop.ozone.s3.util.S3Consts.CUSTOM_METADATA_HEADER_PREFIX;
import static org.apache.hadoop.ozone.s3.util.S3Consts.STORAGE_CONFIG_HEADER;
import static org.apache.hadoop.ozone.s3.util.S3Consts.TAG_HEADER;
import static org.apache.hadoop.ozone.s3.util.S3Consts.TAG_KEY_LENGTH_LIMIT;
import static org.apache.hadoop.ozone.s3.util.S3Consts.TAG_NUM_LIMIT;
Expand Down Expand Up @@ -97,7 +98,7 @@ public abstract class EndpointBase implements Auditor {
private ContainerRequestContext context;

private Set<String> excludeMetadataFields =
new HashSet<>(Arrays.asList(OzoneConsts.GDPR_FLAG));
new HashSet<>(Arrays.asList(OzoneConsts.GDPR_FLAG, STORAGE_CONFIG_HEADER));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this mean

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We store any x-amz-meta-key=value for an object in KeyArgs.metadata (or ex., Etag). ^^This will exclude storing EC storage config in the metadata because it will be available in replication config. We only want to use this header to determine EC replication config when client uses STANDARD_IA storage class.

private static final Logger LOG =
LoggerFactory.getLogger(EndpointBase.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_DATASTREAM_AUTO_THRESHOLD_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION;
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.audit.AuditLogger.PerformanceStringBuilder;
import static org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_CLIENT_BUFFER_SIZE_DEFAULT;
import static org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_CLIENT_BUFFER_SIZE_KEY;
Expand All @@ -49,12 +48,14 @@
import static org.apache.hadoop.ozone.s3.util.S3Consts.COPY_SOURCE_IF_MODIFIED_SINCE;
import static org.apache.hadoop.ozone.s3.util.S3Consts.COPY_SOURCE_IF_UNMODIFIED_SINCE;
import static org.apache.hadoop.ozone.s3.util.S3Consts.CUSTOM_METADATA_COPY_DIRECTIVE_HEADER;
import static org.apache.hadoop.ozone.s3.util.S3Consts.CUSTOM_METADATA_HEADER_PREFIX;
import static org.apache.hadoop.ozone.s3.util.S3Consts.CopyDirective;
import static org.apache.hadoop.ozone.s3.util.S3Consts.DECODED_CONTENT_LENGTH_HEADER;
import static org.apache.hadoop.ozone.s3.util.S3Consts.MP_PARTS_COUNT;
import static org.apache.hadoop.ozone.s3.util.S3Consts.RANGE_HEADER;
import static org.apache.hadoop.ozone.s3.util.S3Consts.RANGE_HEADER_SUPPORTED_UNIT;
import static org.apache.hadoop.ozone.s3.util.S3Consts.STORAGE_CLASS_HEADER;
import static org.apache.hadoop.ozone.s3.util.S3Consts.STORAGE_CONFIG_HEADER;
import static org.apache.hadoop.ozone.s3.util.S3Consts.TAG_COUNT_HEADER;
import static org.apache.hadoop.ozone.s3.util.S3Consts.TAG_DIRECTIVE_HEADER;
import static org.apache.hadoop.ozone.s3.util.S3Utils.urlDecode;
Expand Down Expand Up @@ -230,7 +231,7 @@ public Response put(
boolean auditSuccess = true;
PerformanceStringBuilder perf = new PerformanceStringBuilder();

String copyHeader = null, storageType = null;
String copyHeader = null, storageType = null, storageConfig = null;
DigestInputStream digestInputStream = null;
try {
if (aclMarker != null) {
Expand All @@ -256,12 +257,13 @@ public Response put(

copyHeader = headers.getHeaderString(COPY_SOURCE_HEADER);
storageType = headers.getHeaderString(STORAGE_CLASS_HEADER);
storageConfig = headers.getHeaderString(CUSTOM_METADATA_HEADER_PREFIX + STORAGE_CONFIG_HEADER);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious: how will a client add the header to the request? is it supported by s3 cli or hadoop aws cloud connector?

i wonder where we add this information in the developer doc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All s3 clients should support it. They would just need to add the "x-amz-metadata-storage-class=" to their requests.
This is demonstrated in the acceptance test with AWS cli which does the above underneath.

boolean storageTypeDefault = StringUtils.isEmpty(storageType);

// Normal put object
OzoneBucket bucket = volume.getBucket(bucketName);
ReplicationConfig replicationConfig =
getReplicationConfig(bucket, storageType);
getReplicationConfig(bucket, storageType, storageConfig);

boolean enableEC = false;
if ((replicationConfig != null &&
Expand Down Expand Up @@ -812,14 +814,15 @@ public Response initializeMultipartUpload(
try {
OzoneBucket ozoneBucket = getBucket(bucket);
String storageType = headers.getHeaderString(STORAGE_CLASS_HEADER);
String storageConfig = headers.getHeaderString(CUSTOM_METADATA_HEADER_PREFIX + STORAGE_CONFIG_HEADER);

Map<String, String> customMetadata =
getCustomMetadataFromHeaders(headers.getRequestHeaders());

Map<String, String> tags = getTaggingFromHeaders(headers);

ReplicationConfig replicationConfig =
getReplicationConfig(ozoneBucket, storageType);
getReplicationConfig(ozoneBucket, storageType, storageConfig);

OmMultipartInfo multipartInfo =
ozoneBucket.initiateMultipartUpload(key, replicationConfig, customMetadata, tags);
Expand Down Expand Up @@ -852,21 +855,20 @@ public Response initializeMultipartUpload(
}

private ReplicationConfig getReplicationConfig(OzoneBucket ozoneBucket,
String storageType) throws OS3Exception {
if (StringUtils.isEmpty(storageType)) {
S3StorageType defaultStorageType = S3StorageType.getDefault(ozoneConfiguration);
storageType = (defaultStorageType != null ? defaultStorageType.toString() : null);
}
String storageType, String storageConfig) throws OS3Exception {

ReplicationConfig clientConfiguredReplicationConfig = null;
ReplicationType replicationType = ReplicationType.valueOf(
ozoneConfiguration.get(OZONE_REPLICATION_TYPE));
String replication = ozoneConfiguration.get(OZONE_REPLICATION);

if (replication != null) {
clientConfiguredReplicationConfig = ReplicationConfig.parse(
ReplicationType.valueOf(ozoneConfiguration
.get(OZONE_REPLICATION_TYPE, OZONE_REPLICATION_TYPE_DEFAULT)),
replication, ozoneConfiguration);
clientConfiguredReplicationConfig =
(replicationType == ReplicationType.EC) ?
new ECReplicationConfig(replication) : ReplicationConfig.parse(
replicationType, replication, ozoneConfiguration);
}
return S3Utils.resolveS3ClientSideReplicationConfig(storageType,
return S3Utils.resolveS3ClientSideReplicationConfig(storageType, storageConfig,
clientConfiguredReplicationConfig, ozoneBucket.getReplicationConfig());
}

Expand Down Expand Up @@ -969,9 +971,10 @@ private Response createMultipartKey(OzoneVolume volume, String bucket,

copyHeader = headers.getHeaderString(COPY_SOURCE_HEADER);
String storageType = headers.getHeaderString(STORAGE_CLASS_HEADER);
String storageConfig = headers.getHeaderString(CUSTOM_METADATA_HEADER_PREFIX + STORAGE_CONFIG_HEADER);
final OzoneBucket ozoneBucket = volume.getBucket(bucket);
ReplicationConfig replicationConfig =
getReplicationConfig(ozoneBucket, storageType);
getReplicationConfig(ozoneBucket, storageType, storageConfig);

boolean enableEC = false;
if ((replicationConfig != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ public final class S3ErrorTable {
HTTP_FORBIDDEN
);

public static final OS3Exception INVALID_STORAGE_CLASS = new OS3Exception(
"InvalidStorageClass", "The storage class that you specified is not valid. " +
"Check that storage class is supported and if using STANDARD_IA check that " +
"storage config is a valid EC replication string.",
HTTP_BAD_REQUEST);

private static Function<Exception, OS3Exception> generateInternalError =
e -> new OS3Exception("InternalError", e.getMessage(), HTTP_INTERNAL_ERROR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public final class S3Consts {
// Constants related to custom metadata
public static final String CUSTOM_METADATA_HEADER_PREFIX = "x-amz-meta-";
public static final String CUSTOM_METADATA_COPY_DIRECTIVE_HEADER = "x-amz-metadata-directive";
public static final String STORAGE_CONFIG_HEADER = "storage-config";

public static final String DECODED_CONTENT_LENGTH_HEADER =
"x-amz-decoded-content-length";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,29 @@
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationFactor;
import org.apache.hadoop.hdds.client.ReplicationType;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.ozone.OzoneConfigKeys;

/**
* Maps S3 storage class values to Ozone replication values.
*/

public enum S3StorageType {

REDUCED_REDUNDANCY(ReplicationType.RATIS, ReplicationFactor.ONE),
STANDARD(ReplicationType.RATIS, ReplicationFactor.THREE);
REDUCED_REDUNDANCY(ReplicationType.RATIS, ReplicationFactor.ONE, null),
STANDARD(ReplicationType.RATIS, ReplicationFactor.THREE, null),
STANDARD_IA(ReplicationType.EC, null, ECReplicationConfig.EcCodec.RS + "-3-2-1024k");

private final ReplicationType type;
private final ReplicationFactor factor;
private final String ecReplicationString;

S3StorageType(
ReplicationType type,
ReplicationFactor factor) {
ReplicationFactor factor,
String ecReplicationString) {
Comment thread
adoroszlai marked this conversation as resolved.
Outdated
this.type = type;
this.factor = factor;
this.ecReplicationString = ecReplicationString;
}

public ReplicationFactor getFactor() {
Expand All @@ -52,33 +54,13 @@ public ReplicationType getType() {
return type;
}

/**
* Get default S3StorageType for a new key to be uploaded.
* This should align to the ozone cluster configuration.
* @param config OzoneConfiguration
* @return S3StorageType which wraps ozone replication type and factor
*/
public static S3StorageType getDefault(ConfigurationSource config) {
String replicationString = config.get(OzoneConfigKeys.OZONE_REPLICATION);
ReplicationFactor configFactor;
if (replicationString == null) {
// if no config is set then let server take decision
return null;
}
try {
configFactor = ReplicationFactor.valueOf(
Integer.parseInt(replicationString));
} catch (NumberFormatException ex) {
// conservatively defaults to STANDARD on wrong config value
return STANDARD;
}
return configFactor == ReplicationFactor.ONE
? REDUCED_REDUNDANCY : STANDARD;
public String getEcReplicationString() {
return ecReplicationString;
}

public static S3StorageType fromReplicationConfig(ReplicationConfig config) {
if (config instanceof ECReplicationConfig) {
return S3StorageType.STANDARD;
return STANDARD_IA;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map EC type to STANDARD_IA.

@SaketaChalamchala SaketaChalamchala May 14, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done here. STANDARD_IA is mapped to EC/RS-3-2-1024k by default.

}
if (config.getReplicationType() == HddsProtos.ReplicationType.STAND_ALONE ||
config.getRequiredNodes() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.hadoop.ozone.s3.util;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_ARGUMENT;
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_STORAGE_CLASS;
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError;
import static org.apache.hadoop.ozone.s3.util.S3Consts.STREAMING_AWS4_ECDSA_P256_SHA256_PAYLOAD;
import static org.apache.hadoop.ozone.s3.util.S3Consts.STREAMING_AWS4_ECDSA_P256_SHA256_PAYLOAD_TRAILER;
Expand All @@ -32,10 +32,11 @@
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hdds.client.ECReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationFactor;
import org.apache.hadoop.hdds.client.ReplicationType;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.ozone.s3.exception.OS3Exception;

/**
Expand Down Expand Up @@ -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 storageType, String storageConfig)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no test

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests for toReplicationConfig() are covered by testing resolveS3ClientSideReplicationConfig in TestS3Utils.java

throws OS3Exception {
try {
return S3StorageType.valueOf(storageType);
if (S3StorageType.STANDARD_IA.name().equals(storageType)) {
return (!StringUtils.isEmpty(storageConfig)) ? new ECReplicationConfig(storageConfig) :
new ECReplicationConfig(S3StorageType.STANDARD_IA.getEcReplicationString());
} else {
S3StorageType s3StorageType = S3StorageType.valueOf(storageType);
return ReplicationConfig.fromProtoTypeAndFactor(
ReplicationType.toProto(s3StorageType.getType()),
ReplicationFactor.toProto(s3StorageType.getFactor()));
}
} catch (IllegalArgumentException ex) {
throw newError(INVALID_ARGUMENT, storageType, ex);
throw newError(INVALID_STORAGE_CLASS, storageType, ex);
}
}

Expand Down
Loading