anuragp010 commented on code in PR #12213:
URL: https://github.com/apache/ozone/pull/12213#discussion_r4765683901
##########
hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/keys/PutKeyHandler.java:
##########
@@ -106,35 +125,59 @@ protected void execute(OzoneClient client, OzoneAddress
address)
replicationConfig, chunkSize);
} else {
async(dataFile, bucket, keyName, keyMetadata,
- replicationConfig, chunkSize);
+ replicationConfig, chunkSize, storagePolicy);
+ }
+ }
+
+ /**
+ * 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, so that the key
inherits the StoragePolicy of the bucket.
+ *
+ * @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 void async(
File dataFile, OzoneBucket bucket,
String keyName, Map<String, String> keyMetadata,
- ReplicationConfig replicationConfig, int chunkSize)
+ ReplicationConfig replicationConfig, int chunkSize, StoragePolicy
storagePolicy)
throws IOException {
if (isVerbose()) {
out().println("API: async");
}
try (InputStream input = Files.newInputStream(dataFile.toPath());
- OutputStream output = createOrReplaceKey(bucket, keyName,
dataFile.length(), keyMetadata, replicationConfig)) {
+ OutputStream output = createOrReplaceKey(bucket, keyName,
dataFile.length(), keyMetadata, replicationConfig,
+ storagePolicy)) {
IOUtils.copyBytes(input, output, chunkSize);
}
}
private OzoneOutputStream createOrReplaceKey(OzoneBucket bucket, String
keyName,
- long size, Map<String, String> keyMetadata, ReplicationConfig
replicationConfig
- ) throws IOException {
+ long size, Map<String, String> keyMetadata, ReplicationConfig
replicationConfig,
+ StoragePolicy storagePolicy) throws IOException {
if (expectedGeneration != null) {
final long existingGeneration = expectedGeneration;
Preconditions.checkArgument(existingGeneration > 0,
"expectedGeneration must be positive, but was %s",
existingGeneration);
return bucket.rewriteKey(keyName, size, existingGeneration,
replicationConfig, keyMetadata);
}
- return bucket.createKey(keyName, size, replicationConfig, keyMetadata);
+ return bucket.createKey(keyName, CreateKeyOptions.builder()
+ .setSize(size)
+ .setReplicationConfig(replicationConfig)
+ .setMetadata(keyMetadata)
+ .setStoragePolicy(storagePolicy)
Review Comment:
Thanks @ArafatKhan2198 for the review! Yes, good catch. On the current
HDDS-11233 branch the EC write path does not pass the storage type to the
datanodes, so a COLD EC key could be written to a DISK volume. It is fixed by
[HDDS-16678](https://issues.apache.org/jira/browse/HDDS-16678)
(https://github.com/apache/ozone/pull/12179). That change makes EC writes
honour the tier on the SCM and then corresponding storage type on the DN. Since
that PR is open, I would prefer to not add an EC guard here. Happy to hold this
PR until #12179 is merged if you prefer.
--
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]