smengcl commented on code in PR #4571: URL: https://github.com/apache/ozone/pull/4571#discussion_r1198424282
########## hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestSnapshotDeletingService.java: ########## @@ -0,0 +1,485 @@ +/* + * 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. + * + */ + +package org.apache.hadoop.fs.ozone; + +import org.apache.hadoop.hdds.client.ReplicationFactor; +import org.apache.hadoop.hdds.client.ReplicationType; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.utils.IOUtils; +import org.apache.hadoop.hdds.utils.db.Table; +import org.apache.hadoop.ozone.MiniOzoneCluster; +import org.apache.hadoop.ozone.TestDataUtil; +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.om.OMConfigKeys; +import org.apache.hadoop.ozone.om.OmMetadataManagerImpl; +import org.apache.hadoop.ozone.om.OmSnapshot; +import org.apache.hadoop.ozone.om.OzoneManager; +import org.apache.hadoop.ozone.om.helpers.BucketLayout; +import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.SnapshotInfo; +import org.apache.hadoop.ozone.om.service.SnapshotDeletingService; +import org.apache.ozone.test.GenericTestUtils; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_ENABLED; +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_INTERVAL; +import static org.apache.hadoop.ozone.om.OmSnapshotManager.getSnapshotPrefix; +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DELETING_SERVICE_INTERVAL; +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DELETING_SERVICE_TIMEOUT; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * Test Snapshot Deleting Service. + */ +public class TestSnapshotDeletingService { + + private static final Logger LOG = + LoggerFactory.getLogger(TestSnapshotDeletingService.class); + private static boolean omRatisEnabled = true; + private static final String CONTENT = "testContent"; + + private MiniOzoneCluster cluster; + private OzoneManager om; + private OzoneBucket bucket1; + private OzoneClient client; + private static final String VOLUME_NAME = "vol1"; + private static final String BUCKET_NAME_ONE = "bucket1"; + private static final String BUCKET_NAME_TWO = "bucket2"; + + @BeforeEach + public void setup() throws Exception { + OzoneConfiguration conf = new OzoneConfiguration(); + conf.setTimeDuration(OZONE_SNAPSHOT_DELETING_SERVICE_INTERVAL, + 100, TimeUnit.MILLISECONDS); + conf.setTimeDuration(OZONE_SNAPSHOT_DELETING_SERVICE_TIMEOUT, + 10000, TimeUnit.MILLISECONDS); + conf.setInt(OMConfigKeys.OZONE_DIR_DELETING_SERVICE_INTERVAL, 100); + conf.setInt(OMConfigKeys.OZONE_PATH_DELETING_LIMIT_PER_TASK, 5); + conf.setTimeDuration(OZONE_BLOCK_DELETING_SERVICE_INTERVAL, 100, + TimeUnit.MILLISECONDS); + conf.setBoolean(OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY, omRatisEnabled); + conf.setBoolean(OZONE_ACL_ENABLED, true); + cluster = MiniOzoneCluster.newBuilder(conf) + .setNumDatanodes(3) + .build(); + cluster.waitForClusterToBeReady(); + client = cluster.newClient(); + om = cluster.getOzoneManager(); + bucket1 = TestDataUtil.createVolumeAndBucket( + client, VOLUME_NAME, BUCKET_NAME_ONE, BucketLayout.DEFAULT); + } + + @AfterEach + public void teardown() { + IOUtils.closeQuietly(client); + if (cluster != null) { + cluster.shutdown(); + } + } + + @Test + public void testSnapshotSplitAndMove() throws Exception { + SnapshotDeletingService snapshotDeletingService = (SnapshotDeletingService) + om.getKeyManager().getSnapshotDeletingService(); + Table<String, SnapshotInfo> snapshotInfoTable = + om.getMetadataManager().getSnapshotInfoTable(); + + createSnapshotDataForBucket1(); + + assertTableRowCount(snapshotInfoTable, 2); + GenericTestUtils.waitFor(() -> snapshotDeletingService + .getSuccessfulRunCount() >= 1, 1000, 10000); + + OmSnapshot bucket1snap3 = (OmSnapshot) om.getOmSnapshotManager() + .checkForSnapshot(VOLUME_NAME, BUCKET_NAME_ONE, + getSnapshotPrefix("bucket1snap3"), true); + + // Check bucket1key1 added to next non deleted snapshot db. + List<? extends Table.KeyValue<String, RepeatedOmKeyInfo>> omKeyInfos = + bucket1snap3.getMetadataManager() + .getDeletedTable().getRangeKVs(null, 100, + "/vol1/bucket1/bucket1key1"); + Assertions.assertEquals(1, omKeyInfos.size()); + } + + @Test + public void testMultipleSnapshotKeyReclaim() throws Exception { + + Table<String, RepeatedOmKeyInfo> deletedTable = + om.getMetadataManager().getDeletedTable(); + Table<String, SnapshotInfo> snapshotInfoTable = + om.getMetadataManager().getSnapshotInfoTable(); + + createSnapshotDataForBucket1(); + + BucketArgs bucketArgs = new BucketArgs.Builder() + .setBucketLayout(BucketLayout.LEGACY) + .build(); Review Comment: This should works for all 3 types of buckets? Parameterize this later? -- 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-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org