|
@@ -17,26 +17,38 @@
|
|
|
|
|
|
package org.apache.hadoop.ozone.container.common.impl;
|
|
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
import org.apache.commons.codec.binary.Hex;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
-import org.apache.hadoop.fs.FileUtil;
|
|
|
import org.apache.hadoop.hdds.client.BlockID;
|
|
|
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
|
|
|
+import org.apache.hadoop.hdds.protocol.proto
|
|
|
+ .StorageContainerDatanodeProtocolProtos;
|
|
|
+import org.apache.hadoop.hdds.scm.ScmConfigKeys;
|
|
|
import org.apache.hadoop.hdfs.server.datanode.StorageLocation;
|
|
|
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.TestUtils;
|
|
|
import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException;
|
|
|
import org.apache.hadoop.ozone.container.ContainerTestHelper;
|
|
|
+import org.apache.hadoop.ozone.container.common.interfaces.Container;
|
|
|
+import org.apache.hadoop.ozone.container.common.interfaces.VolumeChoosingPolicy;
|
|
|
+import org.apache.hadoop.ozone.container.common.volume
|
|
|
+ .RoundRobinVolumeChoosingPolicy;
|
|
|
+import org.apache.hadoop.ozone.container.common.volume.VolumeSet;
|
|
|
+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.ozone.container.keyvalue.helpers
|
|
|
+ .KeyValueContainerLocationUtil;
|
|
|
+import org.apache.hadoop.ozone.container.keyvalue.impl.ChunkManagerImpl;
|
|
|
+import org.apache.hadoop.ozone.container.keyvalue.impl.KeyManagerImpl;
|
|
|
+import org.apache.hadoop.ozone.container.keyvalue.interfaces.ChunkManager;
|
|
|
+import org.apache.hadoop.ozone.container.keyvalue.interfaces.KeyManager;
|
|
|
import org.apache.hadoop.test.GenericTestUtils;
|
|
|
import org.apache.hadoop.ozone.container.common.helpers.ChunkInfo;
|
|
|
-import org.apache.hadoop.ozone.container.common.helpers.ContainerData;
|
|
|
-import org.apache.hadoop.ozone.container.common.helpers.ContainerUtils;
|
|
|
import org.apache.hadoop.ozone.container.common.helpers.KeyData;
|
|
|
-import org.apache.hadoop.ozone.container.common.helpers.KeyUtils;
|
|
|
-import org.apache.hadoop.hdds.scm.container.common.helpers.Pipeline;
|
|
|
import org.apache.hadoop.utils.MetadataStore;
|
|
|
import org.junit.After;
|
|
|
import org.junit.AfterClass;
|
|
@@ -51,7 +63,6 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.file.DirectoryStream;
|
|
|
import java.nio.file.Files;
|
|
@@ -65,11 +76,10 @@ import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY;
|
|
|
import static org.apache.hadoop.ozone.OzoneConsts.CONTAINER_ROOT_PREFIX;
|
|
|
-import static org.apache.hadoop.ozone.container.ContainerTestHelper
|
|
|
- .createSingleNodePipeline;
|
|
|
import static org.apache.hadoop.ozone.container.ContainerTestHelper.getChunk;
|
|
|
import static org.apache.hadoop.ozone.container.ContainerTestHelper.getData;
|
|
|
import static org.apache.hadoop.ozone.container.ContainerTestHelper
|
|
@@ -95,40 +105,42 @@ public class TestContainerPersistence {
|
|
|
|
|
|
private static Logger log =
|
|
|
LoggerFactory.getLogger(TestContainerPersistence.class);
|
|
|
+ private static String hddsPath;
|
|
|
private static String path;
|
|
|
- private static ContainerManagerImpl containerManager;
|
|
|
- private static ChunkManagerImpl chunkManager;
|
|
|
- private static KeyManagerImpl keyManager;
|
|
|
private static OzoneConfiguration conf;
|
|
|
private static List<StorageLocation> pathLists = new LinkedList<>();
|
|
|
private Long containerID = 8888L;;
|
|
|
+ private static final String datanodeUuid = UUID.randomUUID().toString();
|
|
|
+ private static final String scmId = UUID.randomUUID().toString();
|
|
|
+
|
|
|
+ private static ContainerSet containerSet;
|
|
|
+ private static VolumeSet volumeSet;
|
|
|
+ private static VolumeChoosingPolicy volumeChoosingPolicy;
|
|
|
+ private static KeyManager keyManager;
|
|
|
+ private static ChunkManager chunkManager;
|
|
|
|
|
|
@BeforeClass
|
|
|
public static void init() throws Throwable {
|
|
|
conf = new OzoneConfiguration();
|
|
|
- path = GenericTestUtils
|
|
|
+ hddsPath = GenericTestUtils
|
|
|
.getTempPath(TestContainerPersistence.class.getSimpleName());
|
|
|
- path += conf.getTrimmed(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT,
|
|
|
+ path = hddsPath + conf.getTrimmed(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT,
|
|
|
OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT_DEFAULT);
|
|
|
conf.set(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, path);
|
|
|
+ conf.set(ScmConfigKeys.HDDS_DATANODE_DIR_KEY, hddsPath);
|
|
|
|
|
|
File containerDir = new File(path);
|
|
|
if (containerDir.exists()) {
|
|
|
FileUtils.deleteDirectory(new File(path));
|
|
|
}
|
|
|
Assert.assertTrue(containerDir.mkdirs());
|
|
|
-
|
|
|
- containerManager = new ContainerManagerImpl();
|
|
|
- chunkManager = new ChunkManagerImpl(containerManager);
|
|
|
- containerManager.setChunkManager(chunkManager);
|
|
|
- keyManager = new KeyManagerImpl(containerManager, conf);
|
|
|
- containerManager.setKeyManager(keyManager);
|
|
|
-
|
|
|
+ volumeChoosingPolicy = new RoundRobinVolumeChoosingPolicy();
|
|
|
}
|
|
|
|
|
|
@AfterClass
|
|
|
public static void shutdown() throws IOException {
|
|
|
FileUtils.deleteDirectory(new File(path));
|
|
|
+ FileUtils.deleteDirectory(new File(hddsPath));
|
|
|
}
|
|
|
|
|
|
@Before
|
|
@@ -140,7 +152,10 @@ public class TestContainerPersistence {
|
|
|
Paths.get(path).resolve(CONTAINER_ROOT_PREFIX).toString());
|
|
|
|
|
|
pathLists.clear();
|
|
|
- containerManager.getContainerMap().clear();
|
|
|
+ containerSet = new ContainerSet();
|
|
|
+ volumeSet = new VolumeSet(datanodeUuid, conf);
|
|
|
+ keyManager = new KeyManagerImpl(conf);
|
|
|
+ chunkManager = new ChunkManagerImpl();
|
|
|
|
|
|
if (!new File(loc.getNormalizedUri()).mkdirs()) {
|
|
|
throw new IOException("unable to create paths. " +
|
|
@@ -152,26 +167,18 @@ public class TestContainerPersistence {
|
|
|
StorageLocation location = StorageLocation.parse(dir);
|
|
|
FileUtils.forceMkdir(new File(location.getNormalizedUri()));
|
|
|
}
|
|
|
-
|
|
|
- containerManager.init(conf, pathLists, TestUtils.getDatanodeDetails());
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
@After
|
|
|
public void cleanupDir() throws IOException {
|
|
|
- // Shutdown containerManager
|
|
|
- containerManager.writeLock();
|
|
|
- try {
|
|
|
- containerManager.shutdown();
|
|
|
- } finally {
|
|
|
- containerManager.writeUnlock();
|
|
|
- }
|
|
|
-
|
|
|
// Clean up SCM metadata
|
|
|
log.info("Deleting {}", path);
|
|
|
FileUtils.deleteDirectory(new File(path));
|
|
|
+ log.info("Deleting {}", hddsPath);
|
|
|
+ FileUtils.deleteDirectory(new File(hddsPath));
|
|
|
|
|
|
// Clean up SCM datanode container metadata/data
|
|
|
- for (String dir : conf.getStrings(DFS_DATANODE_DATA_DIR_KEY)) {
|
|
|
+ for (String dir : conf.getStrings(ScmConfigKeys.HDDS_DATANODE_DIR_KEY)) {
|
|
|
StorageLocation location = StorageLocation.parse(dir);
|
|
|
FileUtils.deleteDirectory(new File(location.getNormalizedUri()));
|
|
|
}
|
|
@@ -181,32 +188,39 @@ public class TestContainerPersistence {
|
|
|
return ContainerTestHelper.getTestContainerID();
|
|
|
}
|
|
|
|
|
|
+ private Container addContainer(ContainerSet containerSet, long containerID)
|
|
|
+ throws IOException {
|
|
|
+ KeyValueContainerData data = new KeyValueContainerData(containerID,
|
|
|
+ ContainerTestHelper.CONTAINER_MAX_SIZE_GB);
|
|
|
+ data.addMetadata("VOLUME", "shire");
|
|
|
+ data.addMetadata("owner)", "bilbo");
|
|
|
+ KeyValueContainer container = new KeyValueContainer(data, conf);
|
|
|
+ container.create(volumeSet, volumeChoosingPolicy, scmId);
|
|
|
+ containerSet.addContainer(container);
|
|
|
+ return container;
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testCreateContainer() throws Exception {
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- ContainerData data = new ContainerData(testContainerID, conf);
|
|
|
- data.addMetadata("VOLUME", "shire");
|
|
|
- data.addMetadata("owner)", "bilbo");
|
|
|
- containerManager.createContainer(data);
|
|
|
- Assert.assertTrue(containerManager.getContainerMap()
|
|
|
+ addContainer(containerSet, testContainerID);
|
|
|
+ Assert.assertTrue(containerSet.getContainerMap()
|
|
|
.containsKey(testContainerID));
|
|
|
- ContainerData cData = containerManager
|
|
|
- .getContainerMap().get(testContainerID);
|
|
|
+ KeyValueContainerData kvData =
|
|
|
+ (KeyValueContainerData) containerSet.getContainer(testContainerID)
|
|
|
+ .getContainerData();
|
|
|
|
|
|
- Assert.assertNotNull(cData);
|
|
|
- Assert.assertNotNull(cData.getContainerPath());
|
|
|
- Assert.assertNotNull(cData.getDBPath());
|
|
|
+ Assert.assertNotNull(kvData);
|
|
|
+ Assert.assertTrue(new File(kvData.getMetadataPath()).exists());
|
|
|
+ Assert.assertTrue(new File(kvData.getChunksPath()).exists());
|
|
|
+ Assert.assertTrue(kvData.getDbFile().exists());
|
|
|
|
|
|
-
|
|
|
- Assert.assertTrue(new File(cData.getContainerPath())
|
|
|
- .exists());
|
|
|
-
|
|
|
- Path meta = Paths.get(cData.getDBPath()).getParent();
|
|
|
+ Path meta = kvData.getDbFile().toPath().getParent();
|
|
|
Assert.assertTrue(meta != null && Files.exists(meta));
|
|
|
|
|
|
MetadataStore store = null;
|
|
|
try {
|
|
|
- store = KeyUtils.getDB(cData, conf);
|
|
|
+ store = KeyUtils.getDB(kvData, conf);
|
|
|
Assert.assertNotNull(store);
|
|
|
} finally {
|
|
|
if (store != null) {
|
|
@@ -219,12 +233,9 @@ public class TestContainerPersistence {
|
|
|
public void testCreateDuplicateContainer() throws Exception {
|
|
|
long testContainerID = getTestContainerID();
|
|
|
|
|
|
- ContainerData data = new ContainerData(testContainerID, conf);
|
|
|
- data.addMetadata("VOLUME", "shire");
|
|
|
- data.addMetadata("owner)", "bilbo");
|
|
|
- containerManager.createContainer(data);
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
try {
|
|
|
- containerManager.createContainer(data);
|
|
|
+ containerSet.addContainer(container);
|
|
|
fail("Expected Exception not thrown.");
|
|
|
} catch (IOException ex) {
|
|
|
Assert.assertNotNull(ex);
|
|
@@ -237,54 +248,40 @@ public class TestContainerPersistence {
|
|
|
Thread.sleep(100);
|
|
|
long testContainerID2 = getTestContainerID();
|
|
|
|
|
|
- ContainerData data = new ContainerData(testContainerID1, conf);
|
|
|
- data.addMetadata("VOLUME", "shire");
|
|
|
- data.addMetadata("owner)", "bilbo");
|
|
|
- containerManager.createContainer(data);
|
|
|
- containerManager.closeContainer(testContainerID1);
|
|
|
+ Container container1 = addContainer(containerSet, testContainerID1);
|
|
|
+ container1.close();
|
|
|
|
|
|
- data = new ContainerData(testContainerID2, conf);
|
|
|
- data.addMetadata("VOLUME", "shire");
|
|
|
- data.addMetadata("owner)", "bilbo");
|
|
|
- containerManager.createContainer(data);
|
|
|
- containerManager.closeContainer(testContainerID2);
|
|
|
+ Container container2 = addContainer(containerSet, testContainerID2);
|
|
|
|
|
|
- Assert.assertTrue(containerManager.getContainerMap()
|
|
|
+ Assert.assertTrue(containerSet.getContainerMap()
|
|
|
.containsKey(testContainerID1));
|
|
|
- Assert.assertTrue(containerManager.getContainerMap()
|
|
|
+ Assert.assertTrue(containerSet.getContainerMap()
|
|
|
.containsKey(testContainerID2));
|
|
|
|
|
|
- containerManager.deleteContainer(testContainerID1, false);
|
|
|
- Assert.assertFalse(containerManager.getContainerMap()
|
|
|
+ container1.delete(false);
|
|
|
+ containerSet.removeContainer(testContainerID1);
|
|
|
+ Assert.assertFalse(containerSet.getContainerMap()
|
|
|
.containsKey(testContainerID1));
|
|
|
|
|
|
- // Let us make sure that we are able to re-use a container name after
|
|
|
- // delete.
|
|
|
-
|
|
|
- data = new ContainerData(testContainerID1, conf);
|
|
|
- data.addMetadata("VOLUME", "shire");
|
|
|
- data.addMetadata("owner)", "bilbo");
|
|
|
- containerManager.createContainer(data);
|
|
|
- containerManager.closeContainer(testContainerID1);
|
|
|
-
|
|
|
- // Assert we still have both containers.
|
|
|
- Assert.assertTrue(containerManager.getContainerMap()
|
|
|
- .containsKey(testContainerID1));
|
|
|
- Assert.assertTrue(containerManager.getContainerMap()
|
|
|
- .containsKey(testContainerID2));
|
|
|
-
|
|
|
- // Add some key to a container and then delete.
|
|
|
- // Delete should fail because the container is no longer empty.
|
|
|
+ // Adding key to a deleted container should fail.
|
|
|
+ exception.expect(StorageContainerException.class);
|
|
|
+ exception.expectMessage("Error opening DB.");
|
|
|
BlockID blockID1 = ContainerTestHelper.getTestBlockID(testContainerID1);
|
|
|
- KeyData someKey = new KeyData(blockID1);
|
|
|
- someKey.setChunks(new LinkedList<ContainerProtos.ChunkInfo>());
|
|
|
- keyManager.putKey(someKey);
|
|
|
+ KeyData someKey1 = new KeyData(blockID1);
|
|
|
+ someKey1.setChunks(new LinkedList<ContainerProtos.ChunkInfo>());
|
|
|
+ keyManager.putKey(container1, someKey1);
|
|
|
+
|
|
|
+ // Deleting a non-empty container should fail.
|
|
|
+ BlockID blockID2 = ContainerTestHelper.getTestBlockID(testContainerID2);
|
|
|
+ KeyData someKey2 = new KeyData(blockID2);
|
|
|
+ someKey2.setChunks(new LinkedList<ContainerProtos.ChunkInfo>());
|
|
|
+ keyManager.putKey(container2, someKey2);
|
|
|
|
|
|
exception.expect(StorageContainerException.class);
|
|
|
exception.expectMessage(
|
|
|
"Container cannot be deleted because it is not empty.");
|
|
|
- containerManager.deleteContainer(testContainerID1, false);
|
|
|
- Assert.assertTrue(containerManager.getContainerMap()
|
|
|
+ container2.delete(false);
|
|
|
+ Assert.assertTrue(containerSet.getContainerMap()
|
|
|
.containsKey(testContainerID1));
|
|
|
}
|
|
|
|
|
@@ -295,21 +292,21 @@ public class TestContainerPersistence {
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- ContainerData data = new ContainerData(testContainerID, conf);
|
|
|
- containerManager.createContainer(data);
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
|
|
|
// Close a bunch of containers.
|
|
|
- // Put closed container names to a list.
|
|
|
if (i%3 == 0) {
|
|
|
- containerManager.closeContainer(testContainerID);
|
|
|
- containerIDs.add(testContainerID);
|
|
|
+ container.close();
|
|
|
}
|
|
|
+ containerIDs.add(testContainerID);
|
|
|
}
|
|
|
|
|
|
- // The container report only returns reports of closed containers.
|
|
|
- List<ContainerData> reports = containerManager.getClosedContainerReports();
|
|
|
- Assert.assertEquals(4, reports.size());
|
|
|
- for(ContainerData report : reports) {
|
|
|
+ // ContainerSet#getContainerReport currently returns all containers (open
|
|
|
+ // and closed) reports.
|
|
|
+ List<StorageContainerDatanodeProtocolProtos.ContainerInfo> reports =
|
|
|
+ containerSet.getContainerReport().getReportsList();
|
|
|
+ Assert.assertEquals(10, reports.size());
|
|
|
+ for(StorageContainerDatanodeProtocolProtos.ContainerInfo report : reports) {
|
|
|
long actualContainerID = report.getContainerID();
|
|
|
Assert.assertTrue(containerIDs.remove(actualContainerID));
|
|
|
}
|
|
@@ -324,24 +321,21 @@ public class TestContainerPersistence {
|
|
|
*/
|
|
|
@Test
|
|
|
public void testListContainer() throws IOException {
|
|
|
- final int count = 50;
|
|
|
+ final int count = 10;
|
|
|
final int step = 5;
|
|
|
|
|
|
Map<Long, ContainerData> testMap = new HashMap<>();
|
|
|
for (int x = 0; x < count; x++) {
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- ContainerData data = new ContainerData(testContainerID, conf);
|
|
|
- data.addMetadata("VOLUME", "shire");
|
|
|
- data.addMetadata("owner)", "bilbo");
|
|
|
- containerManager.createContainer(data);
|
|
|
- testMap.put(testContainerID, data);
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
+ testMap.put(testContainerID, container.getContainerData());
|
|
|
}
|
|
|
|
|
|
int counter = 0;
|
|
|
long prevKey = 0;
|
|
|
List<ContainerData> results = new LinkedList<>();
|
|
|
while (counter < count) {
|
|
|
- containerManager.listContainer(prevKey, step, results);
|
|
|
+ containerSet.listContainer(prevKey, step, results);
|
|
|
for (int y = 0; y < results.size(); y++) {
|
|
|
testMap.remove(results.get(y).getContainerID());
|
|
|
}
|
|
@@ -350,7 +344,7 @@ public class TestContainerPersistence {
|
|
|
|
|
|
//Assert that container is returning results in a sorted fashion.
|
|
|
Assert.assertTrue(prevKey < nextKey);
|
|
|
- prevKey = nextKey;
|
|
|
+ prevKey = nextKey + 1;
|
|
|
results.clear();
|
|
|
}
|
|
|
// Assert that we listed all the keys that we had put into
|
|
@@ -358,22 +352,18 @@ public class TestContainerPersistence {
|
|
|
Assert.assertTrue(testMap.isEmpty());
|
|
|
}
|
|
|
|
|
|
- private ChunkInfo writeChunkHelper(BlockID blockID,
|
|
|
- Pipeline pipeline) throws IOException,
|
|
|
- NoSuchAlgorithmException {
|
|
|
+ private ChunkInfo writeChunkHelper(BlockID blockID)
|
|
|
+ throws IOException, NoSuchAlgorithmException {
|
|
|
final int datalen = 1024;
|
|
|
long testContainerID = blockID.getContainerID();
|
|
|
- ContainerData cData = new ContainerData(testContainerID, conf);
|
|
|
- cData.addMetadata("VOLUME", "shire");
|
|
|
- cData.addMetadata("owner", "bilbo");
|
|
|
- if(!containerManager.getContainerMap()
|
|
|
- .containsKey(testContainerID)) {
|
|
|
- containerManager.createContainer(cData);
|
|
|
+ Container container = containerSet.getContainer(testContainerID);
|
|
|
+ if (container == null) {
|
|
|
+ container = addContainer(containerSet, testContainerID);
|
|
|
}
|
|
|
ChunkInfo info = getChunk(blockID.getLocalID(), 0, 0, datalen);
|
|
|
byte[] data = getData(datalen);
|
|
|
setDataChecksum(info, data);
|
|
|
- chunkManager.writeChunk(blockID, info, data, COMBINED);
|
|
|
+ chunkManager.writeChunk(container, blockID, info, data, COMBINED);
|
|
|
return info;
|
|
|
|
|
|
}
|
|
@@ -389,8 +379,7 @@ public class TestContainerPersistence {
|
|
|
NoSuchAlgorithmException {
|
|
|
BlockID blockID = ContainerTestHelper.
|
|
|
getTestBlockID(getTestContainerID());
|
|
|
- Pipeline pipeline = createSingleNodePipeline();
|
|
|
- writeChunkHelper(blockID, pipeline);
|
|
|
+ writeChunkHelper(blockID);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -407,27 +396,22 @@ public class TestContainerPersistence {
|
|
|
final int chunkCount = 1024;
|
|
|
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- Map<String, ChunkInfo> fileHashMap = new HashMap<>();
|
|
|
-
|
|
|
- ContainerData cData = new ContainerData(testContainerID, conf);
|
|
|
- cData.addMetadata("VOLUME", "shire");
|
|
|
- cData.addMetadata("owner)", "bilbo");
|
|
|
- containerManager.createContainer(cData);
|
|
|
- BlockID blockID = ContainerTestHelper.
|
|
|
- getTestBlockID(testContainerID);
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
|
|
|
+ BlockID blockID = ContainerTestHelper.getTestBlockID(testContainerID);
|
|
|
+ Map<String, ChunkInfo> fileHashMap = new HashMap<>();
|
|
|
for (int x = 0; x < chunkCount; x++) {
|
|
|
ChunkInfo info = getChunk(blockID.getLocalID(), x, 0, datalen);
|
|
|
byte[] data = getData(datalen);
|
|
|
setDataChecksum(info, data);
|
|
|
- chunkManager.writeChunk(blockID, info, data, COMBINED);
|
|
|
+ chunkManager.writeChunk(container, blockID, info, data, COMBINED);
|
|
|
String fileName = String.format("%s.data.%d", blockID.getLocalID(), x);
|
|
|
fileHashMap.put(fileName, info);
|
|
|
}
|
|
|
|
|
|
- ContainerData cNewData = containerManager.readContainer(testContainerID);
|
|
|
+ ContainerData cNewData = container.getContainerData();
|
|
|
Assert.assertNotNull(cNewData);
|
|
|
- Path dataDir = ContainerUtils.getDataDirectory(cNewData);
|
|
|
+ Path dataDir = Paths.get(cNewData.getDataPath());
|
|
|
|
|
|
String globFormat = String.format("%s.data.*", blockID.getLocalID());
|
|
|
MessageDigest sha = MessageDigest.getInstance(OzoneConsts.FILE_HASH);
|
|
@@ -451,7 +435,7 @@ public class TestContainerPersistence {
|
|
|
for (int x = 0; x < chunkCount; x++) {
|
|
|
String fileName = String.format("%s.data.%d", blockID.getLocalID(), x);
|
|
|
ChunkInfo info = fileHashMap.get(fileName);
|
|
|
- byte[] data = chunkManager.readChunk(blockID, info);
|
|
|
+ byte[] data = chunkManager.readChunk(container, blockID, info);
|
|
|
sha.update(data);
|
|
|
Assert.assertEquals(Hex.encodeHexString(sha.digest()),
|
|
|
info.getChecksum());
|
|
@@ -472,23 +456,19 @@ public class TestContainerPersistence {
|
|
|
final int length = datalen/2;
|
|
|
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- BlockID blockID = ContainerTestHelper.
|
|
|
- getTestBlockID(testContainerID);
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
|
|
|
- ContainerData cData = new ContainerData(testContainerID, conf);
|
|
|
- cData.addMetadata("VOLUME", "shire");
|
|
|
- cData.addMetadata("owner)", "bilbo");
|
|
|
- containerManager.createContainer(cData);
|
|
|
+ BlockID blockID = ContainerTestHelper.getTestBlockID(testContainerID);
|
|
|
ChunkInfo info = getChunk(blockID.getLocalID(), 0, 0, datalen);
|
|
|
byte[] data = getData(datalen);
|
|
|
setDataChecksum(info, data);
|
|
|
- chunkManager.writeChunk(blockID, info, data, COMBINED);
|
|
|
+ chunkManager.writeChunk(container, blockID, info, data, COMBINED);
|
|
|
|
|
|
- byte[] readData = chunkManager.readChunk(blockID, info);
|
|
|
+ byte[] readData = chunkManager.readChunk(container, blockID, info);
|
|
|
assertTrue(Arrays.equals(data, readData));
|
|
|
|
|
|
ChunkInfo info2 = getChunk(blockID.getLocalID(), 0, start, length);
|
|
|
- byte[] readData2 = chunkManager.readChunk(blockID, info2);
|
|
|
+ byte[] readData2 = chunkManager.readChunk(container, blockID, info2);
|
|
|
assertEquals(length, readData2.length);
|
|
|
assertTrue(Arrays.equals(
|
|
|
Arrays.copyOfRange(data, start, start + length), readData2));
|
|
@@ -507,31 +487,29 @@ public class TestContainerPersistence {
|
|
|
final int datalen = 1024;
|
|
|
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- BlockID blockID = ContainerTestHelper.
|
|
|
- getTestBlockID(testContainerID);
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
|
|
|
- ContainerData cData = new ContainerData(testContainerID, conf);
|
|
|
- cData.addMetadata("VOLUME", "shire");
|
|
|
- cData.addMetadata("owner)", "bilbo");
|
|
|
- containerManager.createContainer(cData);
|
|
|
+ BlockID blockID = ContainerTestHelper.getTestBlockID(testContainerID);
|
|
|
ChunkInfo info = getChunk(blockID.getLocalID(), 0, 0, datalen);
|
|
|
byte[] data = getData(datalen);
|
|
|
setDataChecksum(info, data);
|
|
|
- chunkManager.writeChunk(blockID, info, data, COMBINED);
|
|
|
+ chunkManager.writeChunk(container, blockID, info, data, COMBINED);
|
|
|
try {
|
|
|
- chunkManager.writeChunk(blockID, info, data, COMBINED);
|
|
|
- } catch (IOException ex) {
|
|
|
- Assert.assertTrue(ex.getCause().getMessage().contains(
|
|
|
+ chunkManager.writeChunk(container, blockID, info, data, COMBINED);
|
|
|
+ } catch (StorageContainerException ex) {
|
|
|
+ Assert.assertTrue(ex.getMessage().contains(
|
|
|
"Rejecting write chunk request. OverWrite flag required"));
|
|
|
+ Assert.assertEquals(ex.getResult(),
|
|
|
+ ContainerProtos.Result.OVERWRITE_FLAG_REQUIRED);
|
|
|
}
|
|
|
|
|
|
// With the overwrite flag it should work now.
|
|
|
info.addMetadata(OzoneConsts.CHUNK_OVERWRITE, "true");
|
|
|
- chunkManager.writeChunk(blockID, info, data, COMBINED);
|
|
|
- long bytesUsed = containerManager.getBytesUsed(testContainerID);
|
|
|
+ chunkManager.writeChunk(container, blockID, info, data, COMBINED);
|
|
|
+ long bytesUsed = container.getContainerData().getBytesUsed();
|
|
|
Assert.assertEquals(datalen, bytesUsed);
|
|
|
|
|
|
- long bytesWrite = containerManager.getWriteBytes(testContainerID);
|
|
|
+ long bytesWrite = container.getContainerData().getWriteBytes();
|
|
|
Assert.assertEquals(datalen * 2, bytesWrite);
|
|
|
}
|
|
|
|
|
@@ -549,13 +527,9 @@ public class TestContainerPersistence {
|
|
|
final int chunkCount = 1024;
|
|
|
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- BlockID blockID = ContainerTestHelper.
|
|
|
- getTestBlockID(testContainerID);
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
|
|
|
- ContainerData cData = new ContainerData(testContainerID, conf);
|
|
|
- cData.addMetadata("VOLUME", "shire");
|
|
|
- cData.addMetadata("owner)", "bilbo");
|
|
|
- containerManager.createContainer(cData);
|
|
|
+ BlockID blockID = ContainerTestHelper.getTestBlockID(testContainerID);
|
|
|
MessageDigest oldSha = MessageDigest.getInstance(OzoneConsts.FILE_HASH);
|
|
|
for (int x = 0; x < chunkCount; x++) {
|
|
|
// we are writing to the same chunk file but at different offsets.
|
|
@@ -564,12 +538,12 @@ public class TestContainerPersistence {
|
|
|
byte[] data = getData(datalen);
|
|
|
oldSha.update(data);
|
|
|
setDataChecksum(info, data);
|
|
|
- chunkManager.writeChunk(blockID, info, data, COMBINED);
|
|
|
+ chunkManager.writeChunk(container, blockID, info, data, COMBINED);
|
|
|
}
|
|
|
|
|
|
// Request to read the whole data in a single go.
|
|
|
ChunkInfo largeChunk = getChunk(blockID.getLocalID(), 0, 0, datalen * chunkCount);
|
|
|
- byte[] newdata = chunkManager.readChunk(blockID, largeChunk);
|
|
|
+ byte[] newdata = chunkManager.readChunk(container, blockID, largeChunk);
|
|
|
MessageDigest newSha = MessageDigest.getInstance(OzoneConsts.FILE_HASH);
|
|
|
newSha.update(newdata);
|
|
|
Assert.assertEquals(Hex.encodeHexString(oldSha.digest()),
|
|
@@ -587,21 +561,17 @@ public class TestContainerPersistence {
|
|
|
NoSuchAlgorithmException {
|
|
|
final int datalen = 1024;
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- BlockID blockID = ContainerTestHelper.
|
|
|
- getTestBlockID(testContainerID);
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
|
|
|
- ContainerData cData = new ContainerData(testContainerID, conf);
|
|
|
- cData.addMetadata("VOLUME", "shire");
|
|
|
- cData.addMetadata("owner)", "bilbo");
|
|
|
- containerManager.createContainer(cData);
|
|
|
+ BlockID blockID = ContainerTestHelper.getTestBlockID(testContainerID);
|
|
|
ChunkInfo info = getChunk(blockID.getLocalID(), 0, 0, datalen);
|
|
|
byte[] data = getData(datalen);
|
|
|
setDataChecksum(info, data);
|
|
|
- chunkManager.writeChunk(blockID, info, data, COMBINED);
|
|
|
- chunkManager.deleteChunk(blockID, info);
|
|
|
+ chunkManager.writeChunk(container, blockID, info, data, COMBINED);
|
|
|
+ chunkManager.deleteChunk(container, blockID, info);
|
|
|
exception.expect(StorageContainerException.class);
|
|
|
exception.expectMessage("Unable to find the chunk file.");
|
|
|
- chunkManager.readChunk(blockID, info);
|
|
|
+ chunkManager.readChunk(container, blockID, info);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -613,16 +583,16 @@ public class TestContainerPersistence {
|
|
|
@Test
|
|
|
public void testPutKey() throws IOException, NoSuchAlgorithmException {
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- BlockID blockID = ContainerTestHelper.
|
|
|
- getTestBlockID(testContainerID);
|
|
|
- Pipeline pipeline = createSingleNodePipeline();
|
|
|
- ChunkInfo info = writeChunkHelper(blockID, pipeline);
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
+
|
|
|
+ BlockID blockID = ContainerTestHelper.getTestBlockID(testContainerID);
|
|
|
+ ChunkInfo info = writeChunkHelper(blockID);
|
|
|
KeyData keyData = new KeyData(blockID);
|
|
|
List<ContainerProtos.ChunkInfo> chunkList = new LinkedList<>();
|
|
|
chunkList.add(info.getProtoBufMessage());
|
|
|
keyData.setChunks(chunkList);
|
|
|
- keyManager.putKey(keyData);
|
|
|
- KeyData readKeyData = keyManager.getKey(keyData);
|
|
|
+ keyManager.putKey(container, keyData);
|
|
|
+ KeyData readKeyData = keyManager.getKey(container, keyData.getBlockID());
|
|
|
ChunkInfo readChunk =
|
|
|
ChunkInfo.getFromProtoBuf(readKeyData.getChunks().get(0));
|
|
|
Assert.assertEquals(info.getChecksum(), readChunk.getChecksum());
|
|
@@ -641,11 +611,10 @@ public class TestContainerPersistence {
|
|
|
final int datalen = 1024;
|
|
|
long totalSize = 0L;
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- BlockID blockID = ContainerTestHelper.
|
|
|
- getTestBlockID(testContainerID);
|
|
|
- Pipeline pipeline = createSingleNodePipeline();
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
+ BlockID blockID = ContainerTestHelper.getTestBlockID(testContainerID);
|
|
|
List<ChunkInfo> chunkList = new LinkedList<>();
|
|
|
- ChunkInfo info = writeChunkHelper(blockID, pipeline);
|
|
|
+ ChunkInfo info = writeChunkHelper(blockID);
|
|
|
totalSize += datalen;
|
|
|
chunkList.add(info);
|
|
|
for (int x = 1; x < chunkCount; x++) {
|
|
@@ -653,18 +622,18 @@ public class TestContainerPersistence {
|
|
|
info = getChunk(blockID.getLocalID(), x, x * datalen, datalen);
|
|
|
byte[] data = getData(datalen);
|
|
|
setDataChecksum(info, data);
|
|
|
- chunkManager.writeChunk(blockID, info, data, COMBINED);
|
|
|
- totalSize += datalen * (x + 1);
|
|
|
+ chunkManager.writeChunk(container, blockID, info, data, COMBINED);
|
|
|
+ totalSize += datalen;
|
|
|
chunkList.add(info);
|
|
|
}
|
|
|
|
|
|
- long bytesUsed = containerManager.getBytesUsed(testContainerID);
|
|
|
+ long bytesUsed = container.getContainerData().getBytesUsed();
|
|
|
Assert.assertEquals(totalSize, bytesUsed);
|
|
|
- long writeBytes = containerManager.getWriteBytes(testContainerID);
|
|
|
+ long writeBytes = container.getContainerData().getWriteBytes();
|
|
|
Assert.assertEquals(chunkCount * datalen, writeBytes);
|
|
|
- long readCount = containerManager.getReadCount(testContainerID);
|
|
|
+ long readCount = container.getContainerData().getReadCount();
|
|
|
Assert.assertEquals(0, readCount);
|
|
|
- long writeCount = containerManager.getWriteCount(testContainerID);
|
|
|
+ long writeCount = container.getContainerData().getWriteCount();
|
|
|
Assert.assertEquals(chunkCount, writeCount);
|
|
|
|
|
|
KeyData keyData = new KeyData(blockID);
|
|
@@ -673,8 +642,8 @@ public class TestContainerPersistence {
|
|
|
chunkProtoList.add(i.getProtoBufMessage());
|
|
|
}
|
|
|
keyData.setChunks(chunkProtoList);
|
|
|
- keyManager.putKey(keyData);
|
|
|
- KeyData readKeyData = keyManager.getKey(keyData);
|
|
|
+ keyManager.putKey(container, keyData);
|
|
|
+ KeyData readKeyData = keyManager.getKey(container, keyData.getBlockID());
|
|
|
ChunkInfo lastChunk = chunkList.get(chunkList.size() - 1);
|
|
|
ChunkInfo readChunk =
|
|
|
ChunkInfo.getFromProtoBuf(readKeyData.getChunks().get(readKeyData
|
|
@@ -691,18 +660,18 @@ public class TestContainerPersistence {
|
|
|
@Test
|
|
|
public void testDeleteKey() throws IOException, NoSuchAlgorithmException {
|
|
|
long testContainerID = getTestContainerID();
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
BlockID blockID = ContainerTestHelper.getTestBlockID(testContainerID);
|
|
|
- Pipeline pipeline = createSingleNodePipeline();
|
|
|
- ChunkInfo info = writeChunkHelper(blockID, pipeline);
|
|
|
+ ChunkInfo info = writeChunkHelper(blockID);
|
|
|
KeyData keyData = new KeyData(blockID);
|
|
|
List<ContainerProtos.ChunkInfo> chunkList = new LinkedList<>();
|
|
|
chunkList.add(info.getProtoBufMessage());
|
|
|
keyData.setChunks(chunkList);
|
|
|
- keyManager.putKey(keyData);
|
|
|
- keyManager.deleteKey(blockID);
|
|
|
+ keyManager.putKey(container, keyData);
|
|
|
+ keyManager.deleteKey(container, blockID);
|
|
|
exception.expect(StorageContainerException.class);
|
|
|
exception.expectMessage("Unable to find the key.");
|
|
|
- keyManager.getKey(keyData);
|
|
|
+ keyManager.getKey(container, keyData.getBlockID());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -715,19 +684,18 @@ public class TestContainerPersistence {
|
|
|
public void testDeleteKeyTwice() throws IOException,
|
|
|
NoSuchAlgorithmException {
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- BlockID blockID = ContainerTestHelper.
|
|
|
- getTestBlockID(testContainerID);
|
|
|
- Pipeline pipeline = createSingleNodePipeline();
|
|
|
- ChunkInfo info = writeChunkHelper(blockID, pipeline);
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
+ BlockID blockID = ContainerTestHelper.getTestBlockID(testContainerID);
|
|
|
+ ChunkInfo info = writeChunkHelper(blockID);
|
|
|
KeyData keyData = new KeyData(blockID);
|
|
|
List<ContainerProtos.ChunkInfo> chunkList = new LinkedList<>();
|
|
|
chunkList.add(info.getProtoBufMessage());
|
|
|
keyData.setChunks(chunkList);
|
|
|
- keyManager.putKey(keyData);
|
|
|
- keyManager.deleteKey(blockID);
|
|
|
+ keyManager.putKey(container, keyData);
|
|
|
+ keyManager.deleteKey(container, blockID);
|
|
|
exception.expect(StorageContainerException.class);
|
|
|
exception.expectMessage("Unable to find the key.");
|
|
|
- keyManager.deleteKey(blockID);
|
|
|
+ keyManager.deleteKey(container, blockID);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -738,88 +706,86 @@ public class TestContainerPersistence {
|
|
|
*/
|
|
|
@Test
|
|
|
public void testUpdateContainer() throws IOException {
|
|
|
- long testContainerID = ContainerTestHelper.
|
|
|
- getTestContainerID();
|
|
|
- ContainerData data = new ContainerData(testContainerID, conf);
|
|
|
- data.addMetadata("VOLUME", "shire");
|
|
|
- data.addMetadata("owner", "bilbo");
|
|
|
+ long testContainerID = ContainerTestHelper.getTestContainerID();
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
|
|
|
- containerManager.createContainer(data);
|
|
|
-
|
|
|
- File orgContainerFile = containerManager.getContainerFile(data);
|
|
|
+ File orgContainerFile = KeyValueContainerLocationUtil.getContainerFile(
|
|
|
+ new File(container.getContainerData().getMetadataPath()),
|
|
|
+ String.valueOf(testContainerID));
|
|
|
Assert.assertTrue(orgContainerFile.exists());
|
|
|
|
|
|
- ContainerData newData = new ContainerData(testContainerID, conf);
|
|
|
- newData.addMetadata("VOLUME", "shire_new");
|
|
|
- newData.addMetadata("owner", "bilbo_new");
|
|
|
+ Map<String, String> newMetadata = Maps.newHashMap();
|
|
|
+ newMetadata.put("VOLUME", "shire_new");
|
|
|
+ newMetadata.put("owner", "bilbo_new");
|
|
|
|
|
|
- containerManager.updateContainer(testContainerID, newData, false);
|
|
|
+ container.update(newMetadata, false);
|
|
|
|
|
|
- Assert.assertEquals(1, containerManager.getContainerMap().size());
|
|
|
- Assert.assertTrue(containerManager.getContainerMap()
|
|
|
+ Assert.assertEquals(1, containerSet.getContainerMap().size());
|
|
|
+ Assert.assertTrue(containerSet.getContainerMap()
|
|
|
.containsKey(testContainerID));
|
|
|
|
|
|
// Verify in-memory map
|
|
|
- ContainerData actualNewData = containerManager.getContainerMap()
|
|
|
- .get(testContainerID);
|
|
|
+ ContainerData actualNewData =
|
|
|
+ containerSet.getContainer(testContainerID).getContainerData();
|
|
|
Assert.assertEquals("shire_new",
|
|
|
- actualNewData.getAllMetadata().get("VOLUME"));
|
|
|
+ actualNewData.getMetadata().get("VOLUME"));
|
|
|
Assert.assertEquals("bilbo_new",
|
|
|
- actualNewData.getAllMetadata().get("owner"));
|
|
|
+ actualNewData.getMetadata().get("owner"));
|
|
|
|
|
|
// Verify container data on disk
|
|
|
- File newContainerFile = containerManager.getContainerFile(actualNewData);
|
|
|
+ File newContainerFile = KeyValueContainerLocationUtil.getContainerFile(
|
|
|
+ new File(actualNewData.getMetadataPath()),
|
|
|
+ String.valueOf(testContainerID));
|
|
|
Assert.assertTrue("Container file should exist.",
|
|
|
newContainerFile.exists());
|
|
|
Assert.assertEquals("Container file should be in same location.",
|
|
|
orgContainerFile.getAbsolutePath(),
|
|
|
newContainerFile.getAbsolutePath());
|
|
|
|
|
|
- try (FileInputStream newIn = new FileInputStream(newContainerFile)) {
|
|
|
- ContainerProtos.ContainerData actualContainerDataProto =
|
|
|
- ContainerProtos.ContainerData.parseDelimitedFrom(newIn);
|
|
|
- ContainerData actualContainerData = ContainerData
|
|
|
- .getFromProtBuf(actualContainerDataProto, conf);
|
|
|
- Assert.assertEquals("shire_new",
|
|
|
- actualContainerData.getAllMetadata().get("VOLUME"));
|
|
|
- Assert.assertEquals("bilbo_new",
|
|
|
- actualContainerData.getAllMetadata().get("owner"));
|
|
|
- }
|
|
|
+ ContainerData actualContainerData = ContainerDataYaml.readContainerFile(
|
|
|
+ newContainerFile);
|
|
|
+ Assert.assertEquals("shire_new",
|
|
|
+ actualContainerData.getMetadata().get("VOLUME"));
|
|
|
+ Assert.assertEquals("bilbo_new",
|
|
|
+ actualContainerData.getMetadata().get("owner"));
|
|
|
+
|
|
|
|
|
|
// Test force update flag.
|
|
|
- // Delete container file then try to update without force update flag.
|
|
|
- FileUtil.fullyDelete(newContainerFile);
|
|
|
+ // Close the container and then try to update without force update flag.
|
|
|
+ container.close();
|
|
|
try {
|
|
|
- containerManager.updateContainer(testContainerID, newData, false);
|
|
|
+ container.update(newMetadata, false);
|
|
|
} catch (StorageContainerException ex) {
|
|
|
- Assert.assertEquals("Container file not exists or "
|
|
|
- + "corrupted. ID: " + testContainerID, ex.getMessage());
|
|
|
+ Assert.assertEquals("Updating a closed container without force option " +
|
|
|
+ "is not allowed. ContainerID: " + testContainerID, ex.getMessage());
|
|
|
}
|
|
|
|
|
|
// Update with force flag, it should be success.
|
|
|
- newData = new ContainerData(testContainerID, conf);
|
|
|
- newData.addMetadata("VOLUME", "shire_new_1");
|
|
|
- newData.addMetadata("owner", "bilbo_new_1");
|
|
|
- containerManager.updateContainer(testContainerID, newData, true);
|
|
|
+ newMetadata.put("VOLUME", "shire_new_1");
|
|
|
+ newMetadata.put("owner", "bilbo_new_1");
|
|
|
+ container.update(newMetadata, true);
|
|
|
|
|
|
// Verify in-memory map
|
|
|
- actualNewData = containerManager.getContainerMap()
|
|
|
- .get(testContainerID);
|
|
|
+ actualNewData =
|
|
|
+ containerSet.getContainer(testContainerID).getContainerData();
|
|
|
Assert.assertEquals("shire_new_1",
|
|
|
- actualNewData.getAllMetadata().get("VOLUME"));
|
|
|
+ actualNewData.getMetadata().get("VOLUME"));
|
|
|
Assert.assertEquals("bilbo_new_1",
|
|
|
- actualNewData.getAllMetadata().get("owner"));
|
|
|
+ actualNewData.getMetadata().get("owner"));
|
|
|
|
|
|
// Update a non-existing container
|
|
|
exception.expect(StorageContainerException.class);
|
|
|
- exception.expectMessage("Container doesn't exist.");
|
|
|
- containerManager.updateContainer(RandomUtils.nextLong(),
|
|
|
- newData, false);
|
|
|
+ exception.expectMessage("Container is an Inconsistent state, missing " +
|
|
|
+ "required files(.container, .chksm).");
|
|
|
+ Container nonExistentContainer = new KeyValueContainer(
|
|
|
+ new KeyValueContainerData(RandomUtils.nextLong(),
|
|
|
+ ContainerTestHelper.CONTAINER_MAX_SIZE_GB), conf);
|
|
|
+ nonExistentContainer.update(newMetadata, false);
|
|
|
}
|
|
|
|
|
|
- private KeyData writeKeyHelper(Pipeline pipeline, BlockID blockID)
|
|
|
+ private KeyData writeKeyHelper(BlockID blockID)
|
|
|
throws IOException, NoSuchAlgorithmException {
|
|
|
- ChunkInfo info = writeChunkHelper(blockID, pipeline);
|
|
|
+ ChunkInfo info = writeChunkHelper(blockID);
|
|
|
KeyData keyData = new KeyData(blockID);
|
|
|
List<ContainerProtos.ChunkInfo> chunkList = new LinkedList<>();
|
|
|
chunkList.add(info.getProtoBufMessage());
|
|
@@ -829,20 +795,18 @@ public class TestContainerPersistence {
|
|
|
|
|
|
@Test
|
|
|
public void testListKey() throws Exception {
|
|
|
-
|
|
|
long testContainerID = getTestContainerID();
|
|
|
- Pipeline pipeline = createSingleNodePipeline();
|
|
|
+ Container container = addContainer(containerSet, testContainerID);
|
|
|
List<BlockID> expectedKeys = new ArrayList<>();
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
- BlockID blockID = new BlockID(
|
|
|
- testContainerID, i);
|
|
|
+ BlockID blockID = new BlockID(testContainerID, i);
|
|
|
expectedKeys.add(blockID);
|
|
|
- KeyData kd = writeKeyHelper(pipeline, blockID);
|
|
|
- keyManager.putKey(kd);
|
|
|
+ KeyData kd = writeKeyHelper(blockID);
|
|
|
+ keyManager.putKey(container, kd);
|
|
|
}
|
|
|
|
|
|
// List all keys
|
|
|
- List<KeyData> result = keyManager.listKey(testContainerID, 0, 100);
|
|
|
+ List<KeyData> result = keyManager.listKey(container, 0, 100);
|
|
|
Assert.assertEquals(10, result.size());
|
|
|
|
|
|
int index = 0;
|
|
@@ -855,7 +819,7 @@ public class TestContainerPersistence {
|
|
|
|
|
|
// List key with startKey filter
|
|
|
long k6 = expectedKeys.get(6).getLocalID();
|
|
|
- result = keyManager.listKey(testContainerID, k6, 100);
|
|
|
+ result = keyManager.listKey(container, k6, 100);
|
|
|
|
|
|
Assert.assertEquals(4, result.size());
|
|
|
for (int i = 6; i < 10; i++) {
|
|
@@ -866,6 +830,6 @@ public class TestContainerPersistence {
|
|
|
// Count must be >0
|
|
|
exception.expect(IllegalArgumentException.class);
|
|
|
exception.expectMessage("Count must be a positive number.");
|
|
|
- keyManager.listKey(testContainerID, 0, -1);
|
|
|
+ keyManager.listKey(container, 0, -1);
|
|
|
}
|
|
|
}
|