hemantk-12 commented on code in PR #4634:
URL: https://github.com/apache/ozone/pull/4634#discussion_r1181906455


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerRequestHandler.java:
##########
@@ -1218,8 +1219,18 @@ private GetS3VolumeContextResponse getS3VolumeContext()
     return impl.getS3VolumeContext().getProtobuf();
   }
 
+  @DisallowedUntilLayoutVersion(SNAPSHOT_SUPPORT)
   private SnapshotDiffResponse snapshotDiff(
       SnapshotDiffRequest snapshotDiffRequest) throws IOException {
+        if (!getOzoneManager().getVersionManager()
+        .isAllowed(SNAPSHOT_SUPPORT)) {
+          throw new OMException(
+                  "cannot be invoked before finalization.",
+                  OMException.ResultCodes.
+                    NOT_SUPPORTED_OPERATION_PRIOR_FINALIZATION)
+                  ;
+        }
+

Review Comment:
   nit:
   1. You can extract out this code to some validation function and reuse at  
other places like. May be add it to 
[OmSnapshotUtils](https://github.com/apache/ozone/blob/06433c0da953d885ce39e439e0c2ddc8d96af6f6/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotUtils.java#L41)
   2. nit: indentation is bit off. Please configure your intelliJ with Ozone 
style: 
https://www.jetbrains.com/help/idea/configuring-code-style.html#import-code-style



##########
hadoop-ozone/dist/src/main/smoketest/upgrade/snapshot.robot:
##########
@@ -0,0 +1,74 @@
+# 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.
+
+*** Settings ***
+Documentation       Smoketest ozone cluster startup
+Library             OperatingSystem
+Library             BuiltIn
+Resource            ../commonlib.robot
+Resource            ../s3/commonawslib.robot
+Test Timeout        5 minutes
+
+*** Variables ***
+
+
+*** Test Cases ***
+Create snapshot
+    [Tags]     snapshot-support
+    ${output} =         Execute                ozone sh volume create vol
+                        Should not contain     ${output}       Failed
+    ${output} =         Execute                ozone sh bucket create 
/vol/bucket2
+                        Should not contain     ${output}       Failed
+    ${output} =         Execute                ozone sh snapshot create 
/vol/bucket2 snapshot1
+                        Should not contain     ${output}       Failed
+                        Execute and checkrc    echo "key created using Ozone 
Shell" > /tmp/sourcekey    0
+                        Execute                ozone sh key put 
/vol/bucket2/key1 /tmp/sourcekey
+                        Execute                ozone sh snapshot create 
/vol/bucket2 snapshot2
+
+Create snapshot in non-supported ozone version
+    [Tags]     snapshot-non-support
+    ${output} =         Execute and checkrc    ozone sh bucket create 
/vol/bucket2     255
+
+List snapshot
+    [Tags]     snapshot-support
+    ${output} =         Execute           ozone sh snapshot ls /vol/bucket2
+                        Should contain    ${output}       snapshot1
+                        Should contain    ${output}       snapshot2
+                        Should contain    ${output}       SNAPSHOT_ACTIVE
+
+List snapshot in non-supported ozone version
+    [Tags]     snapshot-non-support
+    ${output} =         Execute and checkrc       ozone sh snapshot ls 
/vol/bucket2    255
+
+Snapshot Diff
+    [Tags]     snapshot-support
+    ${output} =         Execute           ozone sh snapshot snapshotDiff 
/vol/bucket2 snapshot1 snapshot2

Review Comment:
   You have to call snapDiff twice. Similar to: 
https://github.com/apache/ozone/blob/428fe1de25c5598856c4e0414d758607e07b8f7e/hadoop-ozone/dist/src/main/smoketest/snapshot/snapshot-sh.robot#L50-L54



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java:
##########
@@ -193,6 +198,67 @@ private void init() throws Exception {
 
     // stop the deletion services so that keys can still be read
     keyManager.stop();
+    preFinalizationChecks();
+    finalizeOMUpgrade();
+  }
+
+  private static void expectFailurePreFinalization
+      (LambdaTestUtils.VoidCallable eval)
+      throws Exception {
+    LambdaTestUtils.intercept(OMException.class,
+        "cannot be invoked before finalization.", eval);
+  }
+
+  private static void preFinalizationChecks()
+      throws Exception {
+    // None of the snapshot APIs is usable before the upgrade finalization step
+    expectFailurePreFinalization(() ->
+        store.createSnapshot(volumeName, bucketName,
+          UUID.randomUUID().toString()));
+
+    expectFailurePreFinalization(() ->
+        store.listSnapshot(volumeName, bucketName));
+    expectFailurePreFinalization(() ->
+        store.snapshotDiff(volumeName, bucketName,
+          UUID.randomUUID().toString(),
+          UUID.randomUUID().toString(),
+          "", 1000, false));
+    expectFailurePreFinalization(() ->
+        store.deleteSnapshot(volumeName, bucketName,
+          UUID.randomUUID().toString()));
+  }
+
+  /**
+   * Trigger OM upgrade finalization from the client and block until completion
+   * (status FINALIZATION_DONE).
+   */
+  private static void finalizeOMUpgrade()
+      throws IOException, InterruptedException, TimeoutException {
+
+    // Trigger OM upgrade finalization. Ref: FinalizeUpgradeSubCommand#call
+    final OzoneManagerProtocol omclient = 
+        client.getObjectStore()
+        .getClientProxy().getOzoneManagerClient();
+    final String upgradeClientID = "Test-Upgrade-Client-" + UUID.randomUUID();
+    UpgradeFinalizer.StatusAndMessages finalizationResponse =
+        omclient.finalizeUpgrade(upgradeClientID);
+
+    // The status should transition as soon as the client call above returns
+    Assert.assertTrue(isStarting(finalizationResponse.status()));
+    // Wait for the finalization to be marked as done.
+    // 10s timeout should be plenty.
+    GenericTestUtils.waitFor(() -> {

Review Comment:
   nit: [Awaitility](https://github.com/awaitility/awaitility) might be better 
to use.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotCreateRequest.java:
##########
@@ -87,7 +89,16 @@ public OMSnapshotCreateRequest(OMRequest omRequest) {
   }
 
   @Override
+  @DisallowedUntilLayoutVersion(SNAPSHOT_SUPPORT)
   public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
+    if (!ozoneManager.getVersionManager()
+            .isAllowed(SNAPSHOT_SUPPORT)) {
+      throw new OMException(
+              "cannot be invoked before finalization.",

Review Comment:
   ```suggestion
                 "Cannot be invoked before finalization.",
   ```



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java:
##########
@@ -193,6 +198,67 @@ private void init() throws Exception {
 
     // stop the deletion services so that keys can still be read
     keyManager.stop();
+    preFinalizationChecks();
+    finalizeOMUpgrade();
+  }
+
+  private static void expectFailurePreFinalization
+      (LambdaTestUtils.VoidCallable eval)
+      throws Exception {
+    LambdaTestUtils.intercept(OMException.class,

Review Comment:
   You can directly use `Assert.assertThrows` instread of `LambdaTestUtils`.



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