SaketaChalamchala commented on code in PR #11229: URL: https://github.com/apache/ozone/pull/11229#discussion_r4342436875
########## hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3StorageClassResolver.java: ########## @@ -0,0 +1,187 @@ +/* + * 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.ozone.s3.util; + +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_STORAGE_POLICY; + +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; +import java.util.Locale; +import org.apache.commons.lang3.StringUtils; +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.client.StoragePolicy; +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType; + +/** + * Maps between S3 storage class names and Ozone replication and storage policy. + * + * <p>The two directions are deliberately not symmetric: + * <ul> + * <li><b>Forward</b> (request header to Ozone) is strict. An unknown name is the client's mistake + * and is rejected.</li> + * <li><b>Reverse</b> (stored key to response header) never fails. It describes data that already + * exists, so every combination of replication and storage policy maps to some class. + * Replication decides the class, and only a COLD storage policy changes it.</li> + * </ul> + */ +public final class S3StorageClassResolver { + + /** EC layout used when neither the request nor the bucket specifies one. */ + private static final ECReplicationConfig DEFAULT_EC_REPLICATION_CONFIG = + new ECReplicationConfig(3, 2); + + private S3StorageClassResolver() { + } + + /** + * Forward mapping: the spec for a write that requests the given storage class. + * + * <p>For {@code STANDARD} and {@code REDUCED_REDUNDANCY}, the storage policy comes from the + * class's gateway setting. When the setting is empty, the spec has no storage policy and the + * write inherits the bucket's. + * + * @param s3StorageClass the {@code x-amz-storage-class} header value + * @param conf gateway configuration + * @throws IllegalArgumentException if the storage class is unknown, or its configured storage + * policy is not valid + */ + @Nonnull + public static S3StorageClassSpec toSpec(String s3StorageClass, ConfigurationSource conf) { + S3StorageClass storageClass = S3StorageClass.fromS3StorageClass(s3StorageClass); + S3StorageClassSpec spec = storageClass.getSpec(); + switch (storageClass) { + case STANDARD: + return spec.withStoragePolicy( + getConfiguredStoragePolicy(conf, OZONE_S3G_STORAGE_CLASS_STANDARD_STORAGE_POLICY)); Review Comment: The storage policy fall back to bucket config or server default if `OZONE_S3G_STORAGE_CLASS_STANDARD_STORAGE_POLICY` is not set is missing here. -- 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]
