smengcl commented on code in PR #11671:
URL: https://github.com/apache/ozone/pull/11671#discussion_r4346448564
##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestDBStoreBuilder.java:
##########
@@ -82,6 +86,87 @@ public void builderWithOpenClose(@TempDir Path tempDir)
throws Exception {
dbStore.close();
}
+ @ParameterizedTest
+ @EnumSource(value = DBProfile.class, names = {"SSD", "DISK"})
+ public void testCompactionOnDeletion(DBProfile profile, @TempDir Path
tempDir) throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setDouble("hadoop.hdds.db.rocksdb.compaction.deletion.ratio", 0.5);
+ conf.setEnum(HddsConfigKeys.HDDS_DB_PROFILE, profile);
+ try (RDBStore store =
DBStoreBuilder.newBuilder(conf).setName("deletions.db")
+ .setPath(tempDir).addTable("test").build()) {
+ Table<byte[], byte[]> table = store.getTable("test");
+ writeThenDelete(store, table);
+ store.flushDB();
+ GenericTestUtils.waitFor(() -> {
+ try {
+ return numDeletions(store) == 0;
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }, 100, 10000);
+ int count = 0;
+ try (Table.KeyValueIterator<byte[], byte[]> iterator = table.iterator())
{
+ while (iterator.hasNext()) {
+ Table.KeyValue<byte[], byte[]> entry = iterator.next();
+
assertArrayEquals(StringCodec.get().toPersistedFormat(String.format("%04d", 750
+ count)), entry.getKey());
+ assertArrayEquals(new byte[100], entry.getValue());
+ count++;
+ }
+ }
+ assertEquals(250, count);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(doubles = {0, 1})
+ public void testCompactionNotTriggered(double ratio, @TempDir Path tempDir)
throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ if (ratio != 0) {
+ conf.setDouble("hadoop.hdds.db.rocksdb.compaction.deletion.ratio",
ratio);
+ }
+ try (RDBStore store =
DBStoreBuilder.newBuilder(conf).setName("deletions.db")
+ .setPath(tempDir).addTable("test").setProfile(DBProfile.DISK).build())
{
+ Table<byte[], byte[]> table = store.getTable("test");
+ writeThenDelete(store, table);
+ // Keep the second SST's deletion ratio below 1.
+ table.put(StringCodec.get().toPersistedFormat("new-key"), new byte[100]);
+ store.flushDB();
+ assertThrows(TimeoutException.class, () -> GenericTestUtils.waitFor(()
-> {
+ try {
+ return numDeletions(store) < 750;
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }, 100, 2000));
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(doubles = {-0.1, 1.1, Double.NaN, Double.POSITIVE_INFINITY})
+ public void testInvalidDeletionRatio(double ratio, @TempDir Path tempDir) {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setDouble("hadoop.hdds.db.rocksdb.compaction.deletion.ratio", ratio);
+ IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class,
+ () ->
DBStoreBuilder.newBuilder(conf).setName("deletions.db").setPath(tempDir).build());
+
assertTrue(exception.getMessage().contains("hadoop.hdds.db.rocksdb.compaction.deletion.ratio"));
Review Comment:
nit: AssertJ shows the actual message on failure:
```suggestion
assertThat(exception).hasMessageContaining("hadoop.hdds.db.rocksdb.compaction.deletion.ratio");
```
Needs `import static org.assertj.core.api.Assertions.assertThat;`.
--
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]