You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/10/18 15:49:08 UTC

[GitHub] [ozone] neils-dev commented on a diff in pull request #3658: HDDS-6983. Snapshot Chain - list of snapshots per snapshottable bucket

neils-dev commented on code in PR #3658:
URL: https://github.com/apache/ozone/pull/3658#discussion_r998420127


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestSnapshotChain.java:
##########
@@ -0,0 +1,305 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+package org.apache.hadoop.ozone.om;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
+import org.apache.hadoop.util.Time;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.UUID;
+
+import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_DB_DIRS;
+
+/**
+ * Tests SnapshotChain that stores in chronological order
+ * Ozone object storage snapshots.  There exist two types
+ * of chains provided by the SnapshotChainManager
+ * i.) path based snapshots - a list of snapshots taken for a given bucket
+ * ii.) global snapshots - a list of every snapshot taken in chrono order
+ */
+public class TestSnapshotChain {
+  private OMMetadataManager omMetadataManager;
+  private Map<String, SnapshotInfo> sinfos;
+  private SnapshotChainManager chainManager;
+
+  @Rule
+  public TemporaryFolder folder = new TemporaryFolder();
+
+  @Before
+  public void setup() throws Exception {
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.set(OZONE_OM_DB_DIRS,
+        folder.getRoot().getAbsolutePath());
+    omMetadataManager = new OmMetadataManagerImpl(conf);
+    sinfos = new HashMap<>();
+    chainManager = new SnapshotChainManager(omMetadataManager);
+  }
+
+  private SnapshotInfo createSnapshotInfo(String volName,
+                                          String bucketName,
+                                          String snapshotName,
+                                          String snapshotID,
+                                          String pathPrevID,
+                                          String globalPrevID) {
+    return new SnapshotInfo.Builder()
+        .setSnapshotID(snapshotID)
+        .setName(snapshotName)
+        .setVolumeName(volName)
+        .setBucketName(bucketName)
+        .setSnapshotStatus(SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE)
+        .setCreationTime(Time.now())
+        .setDeletionTime(-1L)
+        .setPathPreviousSnapshotID(pathPrevID)
+        .setGlobalPreviousSnapshotID(globalPrevID)
+        .setSnapshotPath(String.join("/", volName, bucketName))
+        .setCheckpointDir("checkpoint.testdir")
+        .build();
+  }
+
+  private void deleteSnapshot(String snapshotID) throws IOException {
+    SnapshotInfo sinfo = null;
+    final String snapshotPath = "vol1/bucket1";
+    // reset the next snapshotInfo.globalPreviousSnapshotID
+    // to the previous in the entry to be deleted.
+    if (chainManager.hasNextGlobalSnapshot(snapshotID)) {
+      sinfo = sinfos
+              .get(chainManager.nextGlobalSnapshot(snapshotID));

Review Comment:
   Thanks for checking the `deleteSnapshot `in the` TestSnapshotChain` @sadanand48 .  I've updated the `deleteSnapshot` private test method so it updates the` sinfos` for deleted snapshots by both updating the adjacent snapshot info pointers to point to the right snapshots in the chain _and also_ to append the deleted snapshot to the test `sinfos` data-structure for the tests.  With this, tests that would test inserting 2 of 3 snapshots, deleting a snapshot and adding a snapshot should work without issues as well as the implemented `testDeleteSnapshot()` method without having to manually update the test `sinfos` structure within the test.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org