|
@@ -27,29 +27,22 @@ import java.util.Random;
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
-import org.apache.hadoop.hdds.scm.TestUtils;
|
|
|
-import org.apache.hadoop.hdfs.DFSUtil;
|
|
|
import org.apache.hadoop.hdfs.server.datanode.StorageLocation;
|
|
|
-import org.apache.hadoop.hdds.protocol.DatanodeDetails;
|
|
|
import org.apache.hadoop.ozone.OzoneConfigKeys;
|
|
|
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
|
|
|
-import org.apache.hadoop.ozone.OzoneConsts;
|
|
|
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
|
|
|
import org.apache.hadoop.ozone.container.ContainerTestHelper;
|
|
|
+import org.apache.hadoop.ozone.container.common.interfaces.ContainerDeletionChoosingPolicy;
|
|
|
import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer;
|
|
|
import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData;
|
|
|
-import org.apache.hadoop.ozone.container.keyvalue.helpers.KeyUtils;
|
|
|
import org.apache.hadoop.test.GenericTestUtils;
|
|
|
-import org.apache.hadoop.utils.MetadataStore;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Before;
|
|
|
-import org.junit.Ignore;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
/**
|
|
|
* The class for testing container deletion choosing policy.
|
|
|
*/
|
|
|
-@Ignore
|
|
|
public class TestContainerDeletionChoosingPolicy {
|
|
|
private static String path;
|
|
|
private static ContainerSet containerSet;
|
|
@@ -73,7 +66,8 @@ public class TestContainerDeletionChoosingPolicy {
|
|
|
}
|
|
|
Assert.assertTrue(containerDir.mkdirs());
|
|
|
|
|
|
- conf.set(ScmConfigKeys.OZONE_SCM_CONTAINER_DELETION_CHOOSING_POLICY,
|
|
|
+ conf.set(
|
|
|
+ ScmConfigKeys.OZONE_SCM_KEY_VALUE_CONTAINER_DELETION_CHOOSING_POLICY,
|
|
|
RandomContainerDeletionChoosingPolicy.class.getName());
|
|
|
List<StorageLocation> pathLists = new LinkedList<>();
|
|
|
pathLists.add(StorageLocation.parse(containerDir.getAbsolutePath()));
|
|
@@ -89,15 +83,17 @@ public class TestContainerDeletionChoosingPolicy {
|
|
|
containerSet.getContainerMap().containsKey(data.getContainerID()));
|
|
|
}
|
|
|
|
|
|
- List<ContainerData> result0 = containerSet
|
|
|
- .chooseContainerForBlockDeletion(5);
|
|
|
+ ContainerDeletionChoosingPolicy deletionPolicy =
|
|
|
+ new RandomContainerDeletionChoosingPolicy();
|
|
|
+ List<ContainerData> result0 =
|
|
|
+ containerSet.chooseContainerForBlockDeletion(5, deletionPolicy);
|
|
|
Assert.assertEquals(5, result0.size());
|
|
|
|
|
|
// test random choosing
|
|
|
List<ContainerData> result1 = containerSet
|
|
|
- .chooseContainerForBlockDeletion(numContainers);
|
|
|
+ .chooseContainerForBlockDeletion(numContainers, deletionPolicy);
|
|
|
List<ContainerData> result2 = containerSet
|
|
|
- .chooseContainerForBlockDeletion(numContainers);
|
|
|
+ .chooseContainerForBlockDeletion(numContainers, deletionPolicy);
|
|
|
|
|
|
boolean hasShuffled = false;
|
|
|
for (int i = 0; i < numContainers; i++) {
|
|
@@ -118,12 +114,12 @@ public class TestContainerDeletionChoosingPolicy {
|
|
|
}
|
|
|
Assert.assertTrue(containerDir.mkdirs());
|
|
|
|
|
|
- conf.set(ScmConfigKeys.OZONE_SCM_CONTAINER_DELETION_CHOOSING_POLICY,
|
|
|
+ conf.set(
|
|
|
+ ScmConfigKeys.OZONE_SCM_KEY_VALUE_CONTAINER_DELETION_CHOOSING_POLICY,
|
|
|
TopNOrderedContainerDeletionChoosingPolicy.class.getName());
|
|
|
List<StorageLocation> pathLists = new LinkedList<>();
|
|
|
pathLists.add(StorageLocation.parse(containerDir.getAbsolutePath()));
|
|
|
containerSet = new ContainerSet();
|
|
|
- DatanodeDetails datanodeDetails = TestUtils.getDatanodeDetails();
|
|
|
|
|
|
int numContainers = 10;
|
|
|
Random random = new Random();
|
|
@@ -131,38 +127,28 @@ public class TestContainerDeletionChoosingPolicy {
|
|
|
// create [numContainers + 1] containers
|
|
|
for (int i = 0; i <= numContainers; i++) {
|
|
|
long containerId = RandomUtils.nextLong();
|
|
|
- KeyValueContainerData data = new KeyValueContainerData(new Long(i),
|
|
|
- ContainerTestHelper.CONTAINER_MAX_SIZE_GB);
|
|
|
+ KeyValueContainerData data =
|
|
|
+ new KeyValueContainerData(new Long(containerId),
|
|
|
+ ContainerTestHelper.CONTAINER_MAX_SIZE_GB);
|
|
|
+ if (i != numContainers) {
|
|
|
+ int deletionBlocks = random.nextInt(numContainers) + 1;
|
|
|
+ data.incrPendingDeletionBlocks(deletionBlocks);
|
|
|
+ name2Count.put(containerId, deletionBlocks);
|
|
|
+ }
|
|
|
KeyValueContainer container = new KeyValueContainer(data, conf);
|
|
|
containerSet.addContainer(container);
|
|
|
Assert.assertTrue(
|
|
|
containerSet.getContainerMap().containsKey(containerId));
|
|
|
-
|
|
|
- // don't create deletion blocks in the last container.
|
|
|
- if (i == numContainers) {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- // create random number of deletion blocks and write to container db
|
|
|
- int deletionBlocks = random.nextInt(numContainers) + 1;
|
|
|
- // record <ContainerName, DeletionCount> value
|
|
|
- name2Count.put(containerId, deletionBlocks);
|
|
|
- for (int j = 0; j <= deletionBlocks; j++) {
|
|
|
- MetadataStore metadata = KeyUtils.getDB(data, conf);
|
|
|
- String blk = "blk" + i + "-" + j;
|
|
|
- byte[] blkBytes = DFSUtil.string2Bytes(blk);
|
|
|
- metadata.put(
|
|
|
- DFSUtil.string2Bytes(OzoneConsts.DELETING_KEY_PREFIX + blk),
|
|
|
- blkBytes);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- List<ContainerData> result0 = containerSet
|
|
|
- .chooseContainerForBlockDeletion(5);
|
|
|
+ ContainerDeletionChoosingPolicy deletionPolicy =
|
|
|
+ new TopNOrderedContainerDeletionChoosingPolicy();
|
|
|
+ List<ContainerData> result0 =
|
|
|
+ containerSet.chooseContainerForBlockDeletion(5, deletionPolicy);
|
|
|
Assert.assertEquals(5, result0.size());
|
|
|
|
|
|
List<ContainerData> result1 = containerSet
|
|
|
- .chooseContainerForBlockDeletion(numContainers + 1);
|
|
|
+ .chooseContainerForBlockDeletion(numContainers + 1, deletionPolicy);
|
|
|
// the empty deletion blocks container should not be chosen
|
|
|
Assert.assertEquals(numContainers, result1.size());
|
|
|
|