Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public final class S3Consts {
/** Request header carrying the list of object attributes to return. */
public static final String OBJECT_ATTRIBUTES_HEADER = "x-amz-object-attributes";

// S3 storage class values passed via the `x-amz-storage-class` request header.
public static final String S3_STORAGE_CLASS_STANDARD = "STANDARD";
public static final String S3_STORAGE_CLASS_STANDARD_IA = "STANDARD_IA";
public static final String S3_STORAGE_CLASS_GLACIER = "GLACIER";

Comment on lines +134 to +138

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.

I don't know whether u are aware or not but S3StorageType.java in the S3 Gateway has similar enums means: “this S3 storage class string picks how many copies / EC layout the object gets” (STANDARD → 3-way Ratis, STANDARD_IA → EC, etc.). Almost all upload/download code uses that today.

This PR adds S3StorageClass, which means: “this string picks Hot / Warm / Cold (which disk tier).”

Those are two different ideas with similar names. That will confuse people and cause wrong imports later.

We should look into these and check how they both can be used independently.

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.

AWS's StorageClass https://aws.amazon.com/s3/storage-classes does not explicitly specify the replica types or storage media types for each StorageClass; instead, it defines concepts such as durability, SLA, zones, and latency , etc for different StorageClasses

Ozone’s S3 StorageClasses can have custom definitions; users can specify the storage medium (storage policy) and replica type through S3 StorageClass parameter, which does not conflict with AWS S3’s StorageClasses.

//Never Constructed
private S3Consts() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.hdds.client.OzoneStoragePolicy.COLD;
import static org.apache.hadoop.hdds.client.OzoneStoragePolicy.HOT;
import static org.apache.hadoop.hdds.client.OzoneStoragePolicy.WARM;
import static org.apache.hadoop.ozone.s3.util.S3Consts.S3_STORAGE_CLASS_GLACIER;
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 org.apache.hadoop.hdds.client.OzoneStoragePolicy;
import org.apache.hadoop.hdds.client.StoragePolicy;

/**
* Maps S3 storage class values to Ozone StoragePolicy.
*/
public enum S3StorageClass {

STANDARD(S3_STORAGE_CLASS_STANDARD, HOT),
STANDARD_IA(S3_STORAGE_CLASS_STANDARD_IA, WARM),
GLACIER(S3_STORAGE_CLASS_GLACIER, COLD);

private final String s3StorageClass;
private final StoragePolicy storagePolicy;

S3StorageClass(String s3StorageClass, StoragePolicy storagePolicy) {
this.s3StorageClass = s3StorageClass;
this.storagePolicy = storagePolicy;
}

public StoragePolicy getStoragePolicy() {
return storagePolicy;
}

public String getS3StorageClass() {
return s3StorageClass;
}

/**
* Look up the S3StorageClass matching an S3 storage-class header value.
*
* @param s3StorageClass the S3 storage class name (case-insensitive).
* @return the matching S3StorageClass.
* @throws IllegalArgumentException if the value is null or does not map to
* a supported storage class.
*/
public static S3StorageClass fromS3StorageClass(String s3StorageClass) {
if (s3StorageClass == null) {
throw new IllegalArgumentException("Not supported s3StorageClass: null");
}
try {
return S3StorageClass.valueOf(s3StorageClass.toUpperCase());

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.

Thanks @devmadhuu.
I wonder would Locale.ROOT be safer here? toUpperCase() uses the JVM's default locale.
For example, under Turkish locale, "standard_ia" becomes "STANDARD_İA", which does not match the enum constant.
The Java documentation recommends Locale.ROOT for locale-independent strings such as protocol keys.

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.

+1

} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(

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.

IllegalArgumentException is fine for a util with no callers yet but PutObject must map unknown classes to OS3Exception / InvalidStorageClass, not a 500.

"Not supported s3StorageClass: " + s3StorageClass);
}
}

/**
* Look up the S3StorageClass matching an Ozone StoragePolicy.
*
* @param storagePolicy the Ozone StoragePolicy.
* @return the matching S3StorageClass.
* @throws IllegalArgumentException if the policy is null or does not map to
* a supported storage class.
*/
public static S3StorageClass fromStoragePolicy(StoragePolicy storagePolicy) {
if (!(storagePolicy instanceof OzoneStoragePolicy)) {
throw new IllegalArgumentException(
"Not supported storagePolicy: " + storagePolicy);
}
switch ((OzoneStoragePolicy) storagePolicy) {
case HOT:
return STANDARD;
case WARM:
return STANDARD_IA;
case COLD:
return GLACIER;
default:
throw new IllegalArgumentException(
"Not supported storagePolicy: " + storagePolicy);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.util.S3Consts.S3_STORAGE_CLASS_GLACIER;
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.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.apache.hadoop.hdds.client.OzoneStoragePolicy;
import org.junit.jupiter.api.Test;

/** Test the S3 storage-class ↔ Ozone StoragePolicy mapping. */
class TestS3StorageClass {

@Test
void testFromS3StorageClass() {
// S3 storage-class string → S3StorageClass
assertEquals(S3StorageClass.STANDARD,
S3StorageClass.fromS3StorageClass(S3_STORAGE_CLASS_STANDARD));
assertEquals(S3StorageClass.STANDARD_IA,
S3StorageClass.fromS3StorageClass(S3_STORAGE_CLASS_STANDARD_IA));
assertEquals(S3StorageClass.GLACIER,
S3StorageClass.fromS3StorageClass(S3_STORAGE_CLASS_GLACIER));
assertThrows(IllegalArgumentException.class,
() -> S3StorageClass.fromS3StorageClass("INVALID"));
assertThrows(IllegalArgumentException.class,
() -> S3StorageClass.fromS3StorageClass(null));
}

@Test
void testFromStoragePolicy() {
// OzoneStoragePolicy → S3StorageClass
assertEquals(S3StorageClass.STANDARD,
S3StorageClass.fromStoragePolicy(OzoneStoragePolicy.HOT));
assertEquals(S3StorageClass.STANDARD_IA,
S3StorageClass.fromStoragePolicy(OzoneStoragePolicy.WARM));
assertEquals(S3StorageClass.GLACIER,
S3StorageClass.fromStoragePolicy(OzoneStoragePolicy.COLD));
assertThrows(IllegalArgumentException.class,
() -> S3StorageClass.fromStoragePolicy(null));
}

@Test
void testMappingConsistency() {
for (S3StorageClass s3StorageClass : S3StorageClass.values()) {
assertEquals(s3StorageClass,
S3StorageClass.fromS3StorageClass(s3StorageClass.getS3StorageClass()));
assertEquals(s3StorageClass,
S3StorageClass.fromStoragePolicy(s3StorageClass.getStoragePolicy()));
}
}
}
Loading