greenwich commented on code in PR #12232:
URL: https://github.com/apache/ozone/pull/12232#discussion_r4793631883


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3StorageClassResolver.java:
##########
@@ -76,6 +92,73 @@ public S3StorageClassResolver(ConfigurationSource conf) {
         getConfiguredStoragePolicy(conf, 
OZONE_S3G_STORAGE_CLASS_STANDARD_IA_STORAGE_POLICY));
     standardUsesClientDefault = 
conf.getBoolean(OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_KEY,
         OZONE_S3G_STANDARD_STORAGE_CLASS_USE_CLIENT_DEFAULT_DEFAULT);
+    clientOverride = getConfiguredClientOverride(conf);
+  }
+
+  /**
+   * Resolves a write request's storage class header into replication and 
storage policy, applying the
+   * {@link ClientOverride} mode.
+   *
+   * <p>Without the header, replication comes from client replication, then 
bucket replication, or null so the server
+   * applies its default, and no storage policy is sent, so OM applies the 
bucket policy or the cluster default.
+   * With the header:
+   * <ul>
+   *   <li>{@link ClientOverride#ALLOW}: replication from {@link 
#resolveReplicationConfig} and the storage policy
+   *   from {@link #toSpec}.</li>
+   *   <li>{@link ClientOverride#IGNORE}: the header is validated, then the 
result is the same as without it.</li>
+   *   <li>{@link ClientOverride#REJECT}: as {@code ALLOW}, but the write is 
rejected if its replication differs from
+   *   the replication without the header, when that is known, or if it has a 
storage policy other than the bucket's,
+   *   including on a bucket without one.</li>
+   * </ul>
+   *
+   * @param s3StorageClass the x-amz-storage-class header value, or null
+   * @param storageConfigHeader the storage-config header value, or null
+   * @param clientReplicationConfig replication from the gateway's 
ozone.replication settings, or null
+   * @param bucketReplicationConfig the bucket's default replication, or null
+   * @param bucketStoragePolicy the bucket's storage policy, or null
+   * @throws OS3Exception with {@code INVALID_STORAGE_CLASS} if the class is 
unknown, its EC layout header is invalid,
+   *     or, in {@code REJECT} mode, it conflicts with the bucket
+   */
+  @Nonnull
+  public ResolvedStorageClass resolve(@Nullable String s3StorageClass, 
@Nullable String storageConfigHeader,
+      @Nullable ReplicationConfig clientReplicationConfig, @Nullable 
ReplicationConfig bucketReplicationConfig,
+      @Nullable StoragePolicy bucketStoragePolicy) {
+    ReplicationConfig replicationWithoutHeader =
+        clientReplicationConfig != null ? clientReplicationConfig : 
bucketReplicationConfig;
+    if (StringUtils.isEmpty(s3StorageClass)) {
+      return new ResolvedStorageClass(replicationWithoutHeader, null);
+    }
+    // Validates the class and the storage-config header in every mode.
+    ReplicationConfig replicationConfig = 
resolveReplicationConfig(s3StorageClass, storageConfigHeader,
+        clientReplicationConfig, bucketReplicationConfig);
+    StoragePolicy storagePolicy = toSpec(s3StorageClass).getStoragePolicy();
+    switch (clientOverride) {
+    case IGNORE:
+      return new ResolvedStorageClass(replicationWithoutHeader, null);
+    case REJECT:
+      if (replicationWithoutHeader != null && 
!replicationWithoutHeader.equals(replicationConfig)) {
+        throw newConflictError(s3StorageClass, "replication " + 
replicationConfig,
+            "replication " + replicationWithoutHeader);
+      }
+      if (storagePolicy != null && !storagePolicy.equals(bucketStoragePolicy)) 
{
+        throw newConflictError(s3StorageClass, "storage policy " + 
policyName(storagePolicy),
+            bucketStoragePolicy == null ? "no storage policy" : "storage 
policy " + policyName(bucketStoragePolicy));
+      }
+      return new ResolvedStorageClass(replicationConfig, storagePolicy);
+    default:
+      return new ResolvedStorageClass(replicationConfig, storagePolicy);
+    }
+  }
+
+  private static String policyName(StoragePolicy storagePolicy) {
+    return storagePolicy.getName().toUpperCase(Locale.ROOT);
+  }
+
+  private static OS3Exception newConflictError(String s3StorageClass, String 
requested, String bucketSetting) {
+    OS3Exception ex = newError(INVALID_STORAGE_CLASS, s3StorageClass);
+    ex.setErrorMessage("Storage class " + s3StorageClass + " requests " + 
requested + ", but the bucket uses "
+        + bucketSetting + ". This gateway does not allow the storage class to 
override bucket settings.");

Review Comment:
   What if `ozone.replication` is set on the gateway?
   Probably better wording is "this gateway is configured with replication <>"



-- 
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]

Reply via email to