errose28 commented on code in PR #8604:
URL: https://github.com/apache/ozone/pull/8604#discussion_r2246020173
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueContainer.java:
##########
@@ -291,6 +292,56 @@ public void testEmptyContainerImportExport(
checkContainerFilesPresent(data, 0);
}
+ @ContainerTestVersionInfo.ContainerTest
+ public void testEmptyMerkleTreeImportExport(ContainerTestVersionInfo
versionInfo) throws Exception {
+ init(versionInfo);
+ createContainer();
+ closeContainer();
+
+ KeyValueContainerData data = keyValueContainer.getContainerData();
+ // Create an empty checksum file that exists but has no valid merkle tree
+ File checksumFile =
ContainerChecksumTreeManager.getContainerChecksumFile(data);
+ ContainerProtos.ContainerChecksumInfo emptyContainerInfo =
ContainerProtos.ContainerChecksumInfo
+ .newBuilder().build();
+ try (OutputStream tmpOutputStream =
Files.newOutputStream(checksumFile.toPath())) {
+ emptyContainerInfo.writeTo(tmpOutputStream);
+ }
+
+ // Check state of original container.
+ checkContainerFilesPresent(data, 0);
+
+ //destination path
+ File exportTar = Files.createFile(
+ folder.toPath().resolve("export.tar")).toFile();
+ TarContainerPacker packer = new TarContainerPacker(NO_COMPRESSION);
+ //export the container
+ try (OutputStream fos = Files.newOutputStream(exportTar.toPath())) {
+ keyValueContainer.exportContainerData(fos, packer);
+ }
+
+ KeyValueContainerUtil.removeContainer(
+ keyValueContainer.getContainerData(), CONF);
+ keyValueContainer.delete();
+
+ // import container.
+ try (InputStream fis = Files.newInputStream(exportTar.toPath())) {
+ keyValueContainer.importContainerData(fis, packer);
+ }
+
+ // Make sure empty chunks dir was unpacked.
+ checkContainerFilesPresent(data, 0);
+ data = keyValueContainer.getContainerData();
+ ContainerProtos.ContainerChecksumInfo checksumInfo =
ContainerChecksumTreeManager.readChecksumInfo(data);
+ assertFalse(checksumInfo.hasContainerMerkleTree());
+ // The import should not fail and the checksum should be 0
+ assertEquals(0, data.getDataChecksum());
+ // The checksum is not stored in rocksDB as the container merkle tree
doesn't exist.
+ try (DBHandle dbHandle = BlockUtils.getDB(data, new OzoneConfiguration()))
{
+ Long dbDataChecksum =
dbHandle.getStore().getMetadataTable().get(data.getContainerDataChecksumKey());
+ assertNull(dbDataChecksum);
+ }
Review Comment:
The case where file and DB do not have a checksum stored and the in-memory
value returns 0 is still a valid container with all checksums matching. This
method should pass in this case. Tests that need additional checks that DB
values are or are not present can do those in addition to this call.
--
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]