-
Notifications
You must be signed in to change notification settings - Fork 640
HDDS-16039. Introduce S3StorageClass mapping to OzoneStoragePolicy. #11229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: HDDS-11233
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @devmadhuu.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
| } catch (IllegalArgumentException e) { | ||
| throw new IllegalArgumentException( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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.javain 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWS's
StorageClasshttps://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 differentStorageClassesOzone’s S3
StorageClassescan 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’sStorageClasses.