This is an automated email from the ASF dual-hosted git repository.

devmadhuu pushed a commit to branch HDDS-11233
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/HDDS-11233 by this push:
     new eb6f89fddd7 HDDS-17528. Make CreateBucket and SetBucketProperty ZDU 
compliant (#12080)
eb6f89fddd7 is described below

commit eb6f89fddd7b1625b257707b7cb57e92de0299f0
Author: Anurag Parvatikar <[email protected]>
AuthorDate: Wed Nov 25 10:50:18 2026 +0530

    HDDS-17528. Make CreateBucket and SetBucketProperty ZDU compliant (#12080)
---
 .../apache/hadoop/ozone/client/rpc/RpcClient.java  |  15 ++-
 .../hadoop/ozone/client/rpc/TestRpcClient.java     | 129 ++++++++++++++++++---
 .../ozone/om/TestOMStoragePolicyUpgrade.java       |  53 +++++++++
 3 files changed, 180 insertions(+), 17 deletions(-)

diff --git 
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
 
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
index 486e95a5f89..5a8b71dde3e 100644
--- 
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
+++ 
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
@@ -638,6 +638,9 @@ public void createBucket(
             + " not support Erasure Coded replication.");
       }
     }
+    if (bucketArgs.getStoragePolicy() != null || 
bucketArgs.getAllowFallbackStoragePolicy() != null) {
+      checkStoragePolicySupported();
+    }
 
     final String owner;
     // If S3 auth exists, set owner name to the short user name derived from 
the
@@ -1252,6 +1255,7 @@ public void setBucketStoragePolicy(
     verifyVolumeName(volumeName);
     verifyBucketName(bucketName);
     Objects.requireNonNull(storagePolicy, "storagePolicy == null");
+    checkStoragePolicySupported();
     OmBucketArgs.Builder builder = OmBucketArgs.newBuilder();
     builder.setVolumeName(volumeName)
         .setBucketName(bucketName)
@@ -1264,6 +1268,7 @@ public void setBucketStoragePolicy(OmBucketArgs args) 
throws IOException {
     Objects.requireNonNull(args, "args == null");
     verifyVolumeName(args.getVolumeName());
     verifyBucketName(args.getBucketName());
+    checkStoragePolicySupported();
     ozoneManagerClient.setBucketProperty(args);
   }
 
@@ -1571,6 +1576,12 @@ private void checkIfNoneMatchETagSupport() throws 
IOException {
     }
   }
 
+  private void checkStoragePolicySupported() throws IOException {
+    if (!OzoneManagerVersion.STORAGE_POLICY_SUPPORT.isSupportedBy(omVersion)) {
+      throw new IOException("OzoneManager does not support storage policy");
+    }
+  }
+
   private OmKeyArgs.Builder createWriteKeyArgsBuilder(String volumeName,
       String bucketName, String keyName, long size,
       ReplicationConfig replicationConfig, Map<String, String> metadata,
@@ -2249,8 +2260,8 @@ public OmMultipartInfo initiateMultipartUpload(String 
volumeName,
       }
     }
 
-    if (storagePolicy != null && 
!OzoneManagerVersion.STORAGE_POLICY_SUPPORT.isSupportedBy(omVersion)) {
-      throw new IOException("OzoneManager does not support storage policy");
+    if (storagePolicy != null) {
+      checkStoragePolicySupported();
     }
 
     OmKeyArgs keyArgs = new OmKeyArgs.Builder()
diff --git 
a/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
 
b/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
index 425d2d6ebb0..1b95cc4bf9c 100644
--- 
a/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
+++ 
b/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
@@ -44,6 +44,7 @@
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
 import java.util.function.Supplier;
 import java.util.stream.Stream;
 import org.apache.commons.lang3.reflect.FieldUtils;
@@ -64,6 +65,7 @@
 import org.apache.hadoop.ozone.client.protocol.MultipartUploadOptions;
 import org.apache.hadoop.ozone.om.exceptions.OMException;
 import org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes;
+import org.apache.hadoop.ozone.om.helpers.OmBucketArgs;
 import org.apache.hadoop.ozone.om.helpers.OmKeyArgs;
 import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
 import org.apache.hadoop.ozone.om.helpers.S3VolumeContext;
@@ -840,21 +842,8 @@ public void 
testInitiateMultipartUploadRejectsNullOptions() throws IOException {
   public void 
testInitiateMultipartUploadWithStoragePolicyRequiresSupportedOmVersion(OzoneManagerVersion
 version)
       throws IOException {
     List<KeyArgs> requests = new ArrayList<>();
-    OmTransport transport = new MockOmTransport() {
-      @Override
-      public OMResponse submitRequest(OMRequest request) throws IOException {
-        if (request.getCmdType() == Type.ServiceList) {
-          return 
OMResponse.newBuilder().setCmdType(Type.ServiceList).setStatus(Status.OK).setSuccess(true)
-              
.setServiceListResponse(ServiceListResponse.newBuilder().addServiceInfo(om(version).getProtobuf()))
-              .build();
-        }
-        if (request.getCmdType() == Type.InitiateMultiPartUpload) {
-          
requests.add(request.getInitiateMultiPartUploadRequest().getKeyArgs());
-          throw new IOException("captured");
-        }
-        return super.submitRequest(request);
-      }
-    };
+    OmTransport transport = transportWithOmVersion(version, 
Type.InitiateMultiPartUpload,
+        request -> 
requests.add(request.getInitiateMultiPartUploadRequest().getKeyArgs()));
     RpcClient client = createRpcClient(transport);
     try {
       ReplicationConfig replication = 
RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE);
@@ -879,6 +868,116 @@ public OMResponse submitRequest(OMRequest request) throws 
IOException {
     }
   }
 
+  /**
+   * A storage policy field is sent only to an OM that supports it, and a 
request without one is never rejected.
+   */
+  @ParameterizedTest
+  @EnumSource(value = OzoneManagerVersion.class, mode = 
EnumSource.Mode.EXCLUDE, names = "UNKNOWN_VERSION")
+  public void 
testCreateBucketWithStoragePolicyRequiresSupportedOmVersion(OzoneManagerVersion 
version)
+      throws IOException {
+    List<BucketInfo> requests = new ArrayList<>();
+    OmTransport transport = transportWithOmVersion(version, Type.CreateBucket,
+        request -> 
requests.add(request.getCreateBucketRequest().getBucketInfo()));
+    RpcClient client = createRpcClient(transport);
+    try {
+      IOException withoutPolicyError = assertThrows(IOException.class, () -> 
client.createBucket(
+          "vol", "bucket", BucketArgs.newBuilder().build()));
+      IOException withPolicyError = assertThrows(IOException.class, () -> 
client.createBucket(
+          "vol", "bucket", 
BucketArgs.newBuilder().setStoragePolicy(OzoneStoragePolicy.COLD).build()));
+      IOException withFallbackError = assertThrows(IOException.class, () -> 
client.createBucket(
+          "vol", "bucket", 
BucketArgs.newBuilder().setAllowFallbackStoragePolicy(false).build()));
+
+      assertThat(withoutPolicyError).hasMessage("captured");
+      assertThat(requests.get(0).hasStoragePolicy()).isFalse();
+      assertThat(requests.get(0).hasAllowFallbackStoragePolicy()).isFalse();
+      if (OzoneManagerVersion.STORAGE_POLICY_SUPPORT.isSupportedBy(version)) {
+        assertThat(withPolicyError).hasMessage("captured");
+        assertThat(withFallbackError).hasMessage("captured");
+        assertThat(requests).hasSize(3);
+        
assertThat(requests.get(1).getStoragePolicy()).isEqualTo(OzoneStoragePolicy.toProto(OzoneStoragePolicy.COLD));
+        assertThat(requests.get(2).hasAllowFallbackStoragePolicy()).isTrue();
+        assertThat(requests.get(2).getAllowFallbackStoragePolicy()).isFalse();
+      } else {
+        assertThat(withPolicyError).hasMessage("OzoneManager does not support 
storage policy");
+        assertThat(withFallbackError).hasMessage("OzoneManager does not 
support storage policy");
+        assertThat(requests).hasSize(1);
+      }
+    } finally {
+      client.close();
+    }
+  }
+
+  /**
+   * Setting a storage policy needs an OM that supports it, whatever the 
arguments are. This includes
+   * arguments that carry no storage policy field, since the method is a 
public storage policy API.
+   */
+  @ParameterizedTest
+  @EnumSource(value = OzoneManagerVersion.class, mode = 
EnumSource.Mode.EXCLUDE, names = "UNKNOWN_VERSION")
+  public void 
testSetBucketStoragePolicyRequiresSupportedOmVersion(OzoneManagerVersion 
version)
+      throws IOException {
+    List<OzoneManagerProtocolProtos.BucketArgs> requests = new ArrayList<>();
+    OmTransport transport = transportWithOmVersion(version, 
Type.SetBucketProperty,
+        request -> 
requests.add(request.getSetBucketPropertyRequest().getBucketArgs()));
+    RpcClient client = createRpcClient(transport);
+    try {
+      IOException withPolicyError = assertThrows(IOException.class, () -> 
client.setBucketStoragePolicy(
+          "vol", "bucket", OzoneStoragePolicy.COLD));
+      IOException withFallbackError = assertThrows(IOException.class, () -> 
client.setBucketStoragePolicy(
+          
OmBucketArgs.newBuilder().setVolumeName("vol").setBucketName("bucket")
+              .setAllowFallbackStoragePolicy(true).build()));
+      IOException withUnsetError = assertThrows(IOException.class, () -> 
client.setBucketStoragePolicy(
+          
OmBucketArgs.newBuilder().setVolumeName("vol").setBucketName("bucket")
+              .setUnsetStoragePolicy(true).build()));
+      IOException withEmptyArgsError = assertThrows(IOException.class, () -> 
client.setBucketStoragePolicy(
+          
OmBucketArgs.newBuilder().setVolumeName("vol").setBucketName("bucket").build()));
+
+      if (OzoneManagerVersion.STORAGE_POLICY_SUPPORT.isSupportedBy(version)) {
+        assertThat(withPolicyError).hasMessage("captured");
+        assertThat(withFallbackError).hasMessage("captured");
+        assertThat(withUnsetError).hasMessage("captured");
+        assertThat(withEmptyArgsError).hasMessage("captured");
+        assertThat(requests).hasSize(4);
+        
assertThat(requests.get(0).getStoragePolicy()).isEqualTo(OzoneStoragePolicy.toProto(OzoneStoragePolicy.COLD));
+        assertThat(requests.get(1).getAllowFallbackStoragePolicy()).isTrue();
+        assertThat(requests.get(2).getUnsetStoragePolicy()).isTrue();
+        assertThat(requests.get(3).hasStoragePolicy()).isFalse();
+        assertThat(requests.get(3).hasAllowFallbackStoragePolicy()).isFalse();
+        assertThat(requests.get(3).hasUnsetStoragePolicy()).isFalse();
+      } else {
+        assertThat(withPolicyError).hasMessage("OzoneManager does not support 
storage policy");
+        assertThat(withFallbackError).hasMessage("OzoneManager does not 
support storage policy");
+        assertThat(withUnsetError).hasMessage("OzoneManager does not support 
storage policy");
+        assertThat(withEmptyArgsError).hasMessage("OzoneManager does not 
support storage policy");
+        assertThat(requests).isEmpty();
+      }
+    } finally {
+      client.close();
+    }
+  }
+
+  /**
+   * A transport whose OM reports the given version. A request of the captured 
type is passed to the captor and then
+   * fails with "captured", so that a test sees what the client sent without a 
real OM.
+   */
+  private static OmTransport transportWithOmVersion(
+      OzoneManagerVersion version, Type capturedType, Consumer<OMRequest> 
captor) {
+    return new MockOmTransport() {
+      @Override
+      public OMResponse submitRequest(OMRequest request) throws IOException {
+        if (request.getCmdType() == Type.ServiceList) {
+          return 
OMResponse.newBuilder().setCmdType(Type.ServiceList).setStatus(Status.OK).setSuccess(true)
+              
.setServiceListResponse(ServiceListResponse.newBuilder().addServiceInfo(om(version).getProtobuf()))
+              .build();
+        }
+        if (request.getCmdType() == capturedType) {
+          captor.accept(request);
+          throw new IOException("captured");
+        }
+        return super.submitRequest(request);
+      }
+    };
+  }
+
   private static ServiceInfo om(OzoneManagerVersion version) {
     return new ServiceInfo.Builder()
         .setNodeType(HddsProtos.NodeType.OM)
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMStoragePolicyUpgrade.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMStoragePolicyUpgrade.java
index afa02a9d2e8..44bb955d806 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMStoragePolicyUpgrade.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMStoragePolicyUpgrade.java
@@ -19,14 +19,23 @@
 
 import static 
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_OM_DEFAULT_STORAGE_POLICY_KEY;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
+import java.io.IOException;
 import java.util.UUID;
 import org.apache.hadoop.hdds.client.OzoneStoragePolicy;
 import org.apache.hadoop.hdds.client.StoragePolicy;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.utils.IOUtils;
 import org.apache.hadoop.ozone.OzoneManagerVersion;
+import org.apache.hadoop.ozone.client.BucketArgs;
+import org.apache.hadoop.ozone.client.OzoneBucket;
+import org.apache.hadoop.ozone.client.OzoneClient;
+import org.apache.hadoop.ozone.client.OzoneVolume;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
 import org.apache.hadoop.ozone.om.helpers.OmBucketArgs;
 import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -87,6 +96,22 @@ private void preFinalizationChecks() throws Exception {
     assertRejected(() -> setStoragePolicy(OzoneStoragePolicy.HOT, true, null));
     assertRejected(() -> setStoragePolicy(null, null, true));
 
+    // Through the client API, RpcClient refuses to send storage policy fields 
to an OM below
+    // STORAGE_POLICY_SUPPORT. It fails on the client, so the OM never sees 
the request.
+    OzoneVolume volume = getClient().getObjectStore().getVolume(VOLUME_NAME);
+    String clientRejected = "buck-" + UUID.randomUUID();
+    assertClientRejected(() -> volume.createBucket(clientRejected,
+        
BucketArgs.newBuilder().setStoragePolicy(OzoneStoragePolicy.HOT).build()));
+    assertClientRejected(() -> volume.createBucket(clientRejected,
+        BucketArgs.newBuilder().setAllowFallbackStoragePolicy(true).build()));
+    assertThatThrownBy(() -> getOmClient().getBucketInfo(VOLUME_NAME, 
clientRejected))
+        .isInstanceOfSatisfying(OMException.class, ex -> 
assertThat(ex.getResult())
+            .isEqualTo(OMException.ResultCodes.BUCKET_NOT_FOUND));
+    OzoneBucket bucket = volume.getBucket(bucketName);
+    assertClientRejected(() -> 
bucket.setStoragePolicy(OzoneStoragePolicy.HOT));
+    assertClientRejected(() -> bucket.setStoragePolicyProperty(null, null, 
true));
+    assertThat(getOmClient().getBucketInfo(VOLUME_NAME, 
bucketName).getStoragePolicy()).isNull();
+
     // Controls: the gate must not reject requests that carry no storage 
policy field
     createBucket(null, null);
     // The client API must not add a policy field on its own, or the gate 
rejects this request.
@@ -125,6 +150,34 @@ private void postFinalizationChecks() throws Exception {
     setStoragePolicy(null, null, true);
     assertThat(getOmClient().getBucketInfo(VOLUME_NAME, bucketName)
         .getStoragePolicy()).isNull();
+
+    // A client connected after finalization sees the new OM version and may 
send storage policy fields.
+    // The client used before finalization cached the old OM version, so it 
cannot be reused here.
+    OzoneClient postFinalizeClient = getCluster().newClient();
+    try {
+      OzoneVolume volume = 
postFinalizeClient.getObjectStore().getVolume(VOLUME_NAME);
+      String clientCreated = "buck-" + UUID.randomUUID();
+      volume.createBucket(clientCreated, BucketArgs.newBuilder()
+          .setStoragePolicy(OzoneStoragePolicy.HOT)
+          .setAllowFallbackStoragePolicy(false)
+          .build());
+      OmBucketInfo clientCreatedInfo = 
getOmClient().getBucketInfo(VOLUME_NAME, clientCreated);
+      
assertThat(clientCreatedInfo.getStoragePolicy()).isEqualTo(OzoneStoragePolicy.HOT);
+      assertThat(clientCreatedInfo.getAllowFallbackStoragePolicy()).isFalse();
+
+      volume.getBucket(bucketName).setStoragePolicy(OzoneStoragePolicy.COLD);
+      assertThat(getOmClient().getBucketInfo(VOLUME_NAME, bucketName)
+          .getStoragePolicy()).isEqualTo(OzoneStoragePolicy.COLD);
+    } finally {
+      IOUtils.closeQuietly(postFinalizeClient);
+    }
+  }
+
+  private void assertClientRejected(ThrowingCallable call) {
+    assertThatThrownBy(call)
+        .isInstanceOf(IOException.class)
+        .isNotInstanceOf(OMException.class)
+        .hasMessage("OzoneManager does not support storage policy");
   }
 
   private void setStoragePolicy(StoragePolicy storagePolicy,


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to