Xushaohong commented on code in PR #4294:
URL: https://github.com/apache/ozone/pull/4294#discussion_r1174901457
##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStore.java:
##########
@@ -359,4 +368,58 @@ public void testDowngrade() throws Exception {
}
}
+ @Test
+ public void testSstConsistency() throws IOException {
+ for (int i = 0; i < 10; i++) {
+ insertRandomData(rdbStore, 0);
+ insertRandomData(rdbStore, 1);
+ insertRandomData(rdbStore, 2);
+ }
+ DBCheckpoint dbCheckpoint1 = rdbStore.getCheckpoint(true);
+
+ for (int i = 0; i < 10; i++) {
+ insertRandomData(rdbStore, 0);
+ insertRandomData(rdbStore, 1);
+ insertRandomData(rdbStore, 2);
+ }
+ DBCheckpoint dbCheckpoint2 = rdbStore.getCheckpoint(true);
+ compareSstWithSameName(dbCheckpoint1.getCheckpointLocation().toFile(),
+ dbCheckpoint2.getCheckpointLocation().toFile());
+
+ for (int i = 0; i < 10; i++) {
+ insertRandomData(rdbStore, 0);
+ insertRandomData(rdbStore, 1);
+ insertRandomData(rdbStore, 2);
+ }
+ DBCheckpoint dbCheckpoint3 = rdbStore.getCheckpoint(true);
+ compareSstWithSameName(dbCheckpoint2.getCheckpointLocation().toFile(),
+ dbCheckpoint3.getCheckpointLocation().toFile());
+ }
+
+ private void compareSstWithSameName(File checkpoint1, File checkpoint2)
+ throws IOException {
+ FilenameFilter filter = (dir, name) -> name.endsWith(ROCKSDB_SST_SUFFIX);
+ String[] files1 = checkpoint1.list(filter);
+ String[] files2 = checkpoint1.list(filter);
+ assert files1 != null;
+ assert files2 != null;
+ // Get all file names in the both checkpoints
+ List<String> result = Arrays.asList(files1);
+ result.retainAll(Arrays.asList(files2));
+
+ for (String name: result) {
+ File fileInCk1 = new File(checkpoint1.getAbsoluteFile(), name);
+ File fileInCk2 = new File(checkpoint2.getAbsoluteFile(), name);
+ long length1 = fileInCk1.length();
+ long length2 = fileInCk2.length();
+ Assertions.assertEquals(length1, length2, name);
+
+ try (InputStream fileStream1 = new FileInputStream(fileInCk1);
+ InputStream fileStream2 = new FileInputStream(fileInCk2)) {
+ byte[] content1 = new byte[fileStream1.available()];
+ byte[] content2 = new byte[fileStream2.available()];
+ Assertions.assertArrayEquals(content1, content2);
Review Comment:
Oops, this is an empty array before reading into it. Thx for @ChenSammi
finding this bug.
--
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]