-
Notifications
You must be signed in to change notification settings - Fork 640
HDDS-15881. Support setting storagePolicy via SetBucketProperty #11232
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,8 @@ | |||||||||||
| import java.io.IOException; | ||||||||||||
| import org.apache.hadoop.hdds.client.DefaultReplicationConfig; | ||||||||||||
| import org.apache.hadoop.hdds.client.OzoneQuota; | ||||||||||||
| import org.apache.hadoop.hdds.client.OzoneStoragePolicy; | ||||||||||||
| import org.apache.hadoop.hdds.client.StoragePolicy; | ||||||||||||
| import org.apache.hadoop.ozone.OzoneConsts; | ||||||||||||
| import org.apache.hadoop.ozone.client.BucketArgs; | ||||||||||||
| import org.apache.hadoop.ozone.client.OzoneBucket; | ||||||||||||
|
|
@@ -67,6 +69,19 @@ public class CreateBucketHandler extends BucketHandler { | |||||||||||
| @CommandLine.Mixin | ||||||||||||
| private SetSpaceQuotaOptions quotaOptions; | ||||||||||||
|
|
||||||||||||
| @Option(names = {"--storage-policy", "-s"}, | ||||||||||||
| description = "Bucket StoragePolicy. Allowed values: HOT, WARM, COLD, null. Default: WARM.", | ||||||||||||
| defaultValue = "WARM") | ||||||||||||
|
Comment on lines
+73
to
+74
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. Use the
Suggested change
|
||||||||||||
| private String storagePolicyStr; | ||||||||||||
|
|
||||||||||||
| @Option(names = {"--allow-fallback-storage-policy", "-a"}, | ||||||||||||
| description = "When true, allocation may fall back to the StoragePolicy's " + | ||||||||||||
| "fallback tier if the creation tier is unavailable. Default: true.", | ||||||||||||
| defaultValue = "true") | ||||||||||||
| private String allowFallBackStoragePolicyStr; | ||||||||||||
|
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. Can we use
Suggested change
Use the |
||||||||||||
|
|
||||||||||||
| private static final String NULL_STORAGE_POLICY = "null"; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Executes create bucket. | ||||||||||||
| */ | ||||||||||||
|
|
@@ -78,8 +93,14 @@ public void execute(OzoneClient client, OzoneAddress address) | |||||||||||
| ownerName = UserGroupInformation.getCurrentUser().getShortUserName(); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| StoragePolicy storagePolicy = parseStoragePolicy(storagePolicyStr); | ||||||||||||
| Boolean allowFallBackStoragePolicy = | ||||||||||||
| Boolean.valueOf(allowFallBackStoragePolicyStr); | ||||||||||||
|
|
||||||||||||
| BucketArgs.Builder bb = | ||||||||||||
| new BucketArgs.Builder() | ||||||||||||
| .setStoragePolicy(storagePolicy) | ||||||||||||
| .setAllowFallbackStoragePolicy(allowFallBackStoragePolicy) | ||||||||||||
| .setVersioning(false).setOwner(ownerName); | ||||||||||||
| if (allowedBucketLayout != null) { | ||||||||||||
| bb.setBucketLayout(allowedBucketLayout); | ||||||||||||
|
|
@@ -127,6 +148,28 @@ public void execute(OzoneClient client, OzoneAddress address) | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Parse a user-supplied {@code --storage-policy} value into a | ||||||||||||
| * {@link StoragePolicy}. Returns {@code null} when the caller passed | ||||||||||||
| * "null" (any case) or an empty value, to leave the bucket without an | ||||||||||||
| * explicit StoragePolicy (the server defaults it to WARM on create). | ||||||||||||
| * | ||||||||||||
| * @throws IllegalArgumentException if the value is not one of HOT, WARM, | ||||||||||||
| * COLD, or "null". | ||||||||||||
| */ | ||||||||||||
| private static StoragePolicy parseStoragePolicy(String value) { | ||||||||||||
| if (Strings.isNullOrEmpty(value) | ||||||||||||
| || NULL_STORAGE_POLICY.equalsIgnoreCase(value)) { | ||||||||||||
| return null; | ||||||||||||
| } | ||||||||||||
| try { | ||||||||||||
| return OzoneStoragePolicy.valueOf(value.toUpperCase()); | ||||||||||||
| } catch (IllegalArgumentException e) { | ||||||||||||
| throw new IllegalArgumentException("Invalid storage policy: " + value | ||||||||||||
| + ". Allowed String values are: HOT, WARM, COLD, or null."); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private static class LayoutConverter implements CommandLine.ITypeConverter<BucketLayout> { | ||||||||||||
| @Override | ||||||||||||
| public BucketLayout convert(String value) { | ||||||||||||
|
|
||||||||||||
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.
nit: Let’s use
unsetas it reads better thanunSet.