Skip to content

HDDS-15342. Make RocksDB bottommost level compaction options configurable for background compaction#10419

Open
ptlrs wants to merge 9 commits into
apache:masterfrom
ptlrs:HDDS-15342-Make-RocksDB-BottommostLevelCompaction-options-configurable
Open

HDDS-15342. Make RocksDB bottommost level compaction options configurable for background compaction#10419
ptlrs wants to merge 9 commits into
apache:masterfrom
ptlrs:HDDS-15342-Make-RocksDB-BottommostLevelCompaction-options-configurable

Conversation

@ptlrs

@ptlrs ptlrs commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

RocksDB allows multiple configurations for configuration the compaction strategy for the bottom-most layer. These configurations impact the compaction times.

This PR makes the compaction strategy configurable.

  • Adds a config for setting the compaction strategy
  • Sets the default strategy to kSkip which is faster than kForce
  • Adds tests

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-15342

How was this patch tested?

CI: https://github.com/ptlrs/ozone/actions/runs/26857346964

</property>
<property>
<name>ozone.om.compaction.service.bottommostlevelcompaction</name>
<value>0</value>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use kSkip/kForce for better readability.

@ptlrs ptlrs Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree that a string option will be more readable, I have kept it this way because I want to use the native org.rocksdb.CompactRangeOptions.BottommostLevelCompaction#fromRocksId method.

That method converts an integer to compaction type. There is no method that RocksDB provides that converts a string to target compaction type.

The reason for keeping it this way is that I want to avoid writing and updating our custom method as and when RocksDB provides new compaction type options.

For example, the latest RocksDB already has a kForceOptimized option which our current version doesn't support. I want to avoid creating such manual mappings and validations in Ozone code.

In case we fail to provide a mapping for some future option, we will not be able to use that option even if RocksDB supports it.

As a compromise, the helper text provides the relevant information that is needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to avoid writing and updating our custom method as and when RocksDB provides new compaction type options

No custom method is needed if the config value is converted to enum BottommostLevelCompaction using Configuration.getEnum instead getInt.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code to use getEnum

@sarvekshayr sarvekshayr Jul 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getEnum expects enum names with this change. Please update the value as well as the description.

@sarvekshayr sarvekshayr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ptlrs for working on this.

@sarvekshayr sarvekshayr marked this pull request as ready for review June 10, 2026 05:20
@sarvekshayr

sarvekshayr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Failed acceptance (tools) CI - CompactOMDB defaults to kSkip which does not reduce the OM DB size in this test. #10428 should fix this test by passing the compaction type as kForce and be merged first.

Compact OM DB Column Family
    [Arguments]        ${column_family}
    Execute    ozone repair om compact --cf=${column_family} --service-id ${OM_SERVICE_ID} --node-id om1 --blc 2

Comment thread hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java Outdated
Comment thread hadoop-hdds/common/src/main/resources/ozone-default.xml Outdated

@ashishkumar50 ashishkumar50 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptlrs Thanks for the update, LGTM.

@ashishkumar50

Copy link
Copy Markdown
Contributor

@ptlrs Can you please look at test failure, looks related.

@ptlrs

ptlrs commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

@ashishkumar50 as @sarvekshayr had also observed, this PR depends on #10428 which fixes the failing Robot test.

Can we please merge that first? I may need to pull the changes in this PR after that.

ptlrs added 2 commits June 17, 2026 10:23
…ocksDB-BottommostLevelCompaction-options-configurable

# Conflicts:
#	hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/CompactDBUtil.java
#	hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/CompactionService.java
@ptlrs

ptlrs commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Hi @ashishkumar50 @sarvekshayr, could you please take another look? I have merged the changes from master. The robot test should now pass.

</property>
<property>
<name>ozone.om.compaction.service.bottommostlevelcompaction</name>
<value>0</value>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to avoid writing and updating our custom method as and when RocksDB provides new compaction type options

No custom method is needed if the config value is converted to enum BottommostLevelCompaction using Configuration.getEnum instead getInt.

</description>
</property>
<property>
<name>ozone.om.compaction.service.bottommostlevelcompaction</name>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use - as separator in last part of the property name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? bottommostlevelcompaction is the original name as per org.rocksdb.CompactRangeOptions.BottommostLevelCompaction.

Most importantly, searching for bottommostlevelcompaction brings up all instances of it in both code and configuration in my IDE. Adding a separator would break that.

@adoroszlai adoroszlai Jul 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BottommostLevelCompaction uses CamelCase. The same with lower case needs some separator, e.g. - (kebab-case) or _ (snake_case) for readability. In config property names - is commonly used.

Comment on lines +52 to +71
@Test
void testCompactWithKSkip() {
assertDoesNotThrow(() ->
CompactDBUtil.compactTable(omMetadataManager, "keyTable",
ManagedCompactRangeOptions.BottommostLevelCompaction.kSkip));
}

@Test
void testCompactWithKForce() {
assertDoesNotThrow(() ->
CompactDBUtil.compactTable(omMetadataManager, "keyTable",
ManagedCompactRangeOptions.BottommostLevelCompaction.kForce));
}

@Test
void testCompactWithKIfHaveCompactionFilter() {
assertDoesNotThrow(() ->
CompactDBUtil.compactTable(omMetadataManager, "keyTable",
ManagedCompactRangeOptions.BottommostLevelCompaction.kIfHaveCompactionFilter));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use @ParameterizedTest with @EnumSource.

Comment on lines +88 to +101
@Test
void testConfigValueMapsToCorrectEnum() {
assertEquals(ManagedCompactRangeOptions.BottommostLevelCompaction.kSkip,
ManagedCompactRangeOptions.BottommostLevelCompaction.fromRocksId(0));
assertEquals(ManagedCompactRangeOptions.BottommostLevelCompaction.kIfHaveCompactionFilter,
ManagedCompactRangeOptions.BottommostLevelCompaction.fromRocksId(1));
assertEquals(ManagedCompactRangeOptions.BottommostLevelCompaction.kForce,
ManagedCompactRangeOptions.BottommostLevelCompaction.fromRocksId(2));
}

@Test
void testInvalidConfigValueReturnsNull() {
assertNull(ManagedCompactRangeOptions.BottommostLevelCompaction.fromRocksId(99));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests exercising RocksDB method fromRocksId would be unnecessary with the enum config approach.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

This PR has been marked as stale due to 21 days of inactivity. Please comment or remove the stale label to keep it open. Otherwise, it will be automatically closed in 7 days.

@github-actions github-actions Bot added the stale label Jul 9, 2026
@sarvekshayr

Copy link
Copy Markdown
Contributor

@ptlrs Could you please drive this PR to completion by addressing the minor comments given?

@github-actions github-actions Bot removed the stale label Jul 10, 2026
…ocksDB-BottommostLevelCompaction-options-configurable
@ptlrs ptlrs requested a review from adoroszlai July 13, 2026 22:56
…BottommostLevelCompaction configuration values.

@sarvekshayr sarvekshayr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the patch @ptlrs.

  • Please look into the CI build failure.

  • Let's update compaction CLI to also use enum names instead of int - #10428
    It can also be done in a follow-up PR.

Comment on lines +1596 to +1602
<value>0</value>
<tag>OZONE, OM, PERFORMANCE</tag>
<description>
Bottommost level compaction type for compaction.
Invalid values will default to kSkip.
Valid values: 0 (kSkip), 1 (kIfHaveCompactionFilter), 2 (kForce), 3 (kForceOptimized).
</description>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getEnum expects enum names with this change. Please update the value as well as the description.

Suggested change
<value>0</value>
<tag>OZONE, OM, PERFORMANCE</tag>
<description>
Bottommost level compaction type for compaction.
Invalid values will default to kSkip.
Valid values: 0 (kSkip), 1 (kIfHaveCompactionFilter), 2 (kForce), 3 (kForceOptimized).
</description>
<value>kSkip</value>
<tag>OZONE, OM, PERFORMANCE</tag>
<description>
Bottommost level compaction type for compaction.
Invalid values will default to kSkip.
Valid values: kSkip, kIfHaveCompactionFilter, kForce, kForceOptimized.
</description>

Comment on lines +686 to +688
* Bottommost level compaction type for manual compaction.
* Invalid values will default to kSkip.
* Valid values: 0 (kSkip), 1 (kIfHaveCompactionFilter), 2 (kForce), 3 (kForceOptimized).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Bottommost level compaction type for manual compaction.
* Invalid values will default to kSkip.
* Valid values: 0 (kSkip), 1 (kIfHaveCompactionFilter), 2 (kForce), 3 (kForceOptimized).
* Bottommost level compaction type for background compaction service.
* Invalid values will default to kSkip.
* Valid values: kSkip, kIfHaveCompactionFilter, kForce, kForceOptimized.

@Test
public void testConfiguredCompactionLevelKForce() {
OzoneConfiguration conf = new OzoneConfiguration();
conf.setInt(OZONE_OM_COMPACTION_SERVICE_BOTTOMMOSTLEVELCOMPACTION, 2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
conf.setInt(OZONE_OM_COMPACTION_SERVICE_BOTTOMMOSTLEVELCOMPACTION, 2);
conf.set(OZONE_OM_COMPACTION_SERVICE_BOTTOMMOSTLEVELCOMPACTION, "kForce");

@Test
public void testInvalidCompactionLevelFallsBackToDefault() {
OzoneConfiguration conf = new OzoneConfiguration();
conf.setInt(OZONE_OM_COMPACTION_SERVICE_BOTTOMMOSTLEVELCOMPACTION, 99);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any invalid string can be used here -

Suggested change
conf.setInt(OZONE_OM_COMPACTION_SERVICE_BOTTOMMOSTLEVELCOMPACTION, 99);
conf.set(OZONE_OM_COMPACTION_SERVICE_BOTTOMMOSTLEVELCOMPACTION, "abc");

return compactableTables;
}

@VisibleForTesting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VisibleForTesting annotation is no longer used, see HDDS-12725.

Suggested change
@VisibleForTesting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants