Skip to content

Add cluster.blocks.read.auto_release setting (#20539)#20582

Open
Seungmin123 wants to merge 1 commit intoopensearch-project:mainfrom
Seungmin123:fix/disk-threshold-auto-release-read-block-20539
Open

Add cluster.blocks.read.auto_release setting (#20539)#20582
Seungmin123 wants to merge 1 commit intoopensearch-project:mainfrom
Seungmin123:fix/disk-threshold-auto-release-read-block-20539

Conversation

@Seungmin123
Copy link
Copy Markdown

Description

This PR fixes a bug in the DiskThresholdMonitor where it was unconditionally auto-releasing index.blocks.read on all indices, even when manually set by users.

This fix introduces a new dynamic cluster setting cluster.blocks.read.auto_release (defaulting to true for backward compatibility) that controls whether the cluster should automatically release read blocks. By setting this to false, users can ensure that manually-set read blocks persist until explicitly removed.

Related Issues

Resolves #20539

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The DiskThresholdMonitor was unconditionally auto-releasing
index.blocks.read on all indices. This fix adds a new setting
cluster.blocks.read.auto_release (defaulting to true) to control
this behavior, allowing users to disable automatic release of
manually-set read blocks.

Signed-off-by: Seungmin123 <dltmdals147@gmail.com>
@Seungmin123 Seungmin123 requested a review from a team as a code owner February 10, 2026 05:09
@github-actions github-actions bot added bug Something isn't working good first issue Good for newcomers Search Search query, autocomplete ...etc labels Feb 10, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

Added a new cluster setting cluster.blocks.read.auto_release to control automatic release of manually-set index read blocks. The setting defaults to true and integrates into DiskThresholdMonitor's read block handling logic, allowing users to prevent unconditional auto-release of read blocks set outside the system.

Changes

Cohort / File(s) Summary
Settings Registration
CHANGELOG.md, server/src/main/java/org/opensearch/common/settings/ClusterSettings.java
Added changelog entry and registered new cluster.blocks.read.auto_release setting in built-in cluster settings collection.
DiskThresholdSettings Configuration
server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdSettings.java
Introduced new public static INDEX_READ_BLOCK_AUTO_RELEASE setting (boolean, default true, dynamic, node-scoped), plus getter and setter methods to manage the auto-release state.
Read Block Handling Logic
server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitor.java
Modified handleReadBlocks method to conditionally compute indices eligible for auto-release only when isIndexReadBlockAutoReleaseEnabled() returns true; otherwise uses empty set to prevent release.
Feature Tests
server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitorTests.java, server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdSettingsTests.java
Added test methods verifying auto-release occurs when enabled, does not occur when disabled, and that setting changes propagate correctly. Updated existing defaults test to verify default enabled state.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

enhancement

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a new cluster.blocks.read.auto_release setting. It directly relates to the primary objective of the PR.
Description check ✅ Passed The description includes the required sections (Description, Related Issues, Check List) and clearly explains the bug fix and the new setting with backward compatibility consideration.
Linked Issues check ✅ Passed The PR successfully implements the suggested fix from issue #20539: adds cluster.blocks.read.auto_release setting to DiskThresholdSettings, modifies DiskThresholdMonitor to conditionally auto-release read blocks based on this setting, and includes appropriate test coverage.
Out of Scope Changes check ✅ Passed All changes are directly related to the objectives: adding the new setting to DiskThresholdSettings, updating DiskThresholdMonitor to use it, registering it in ClusterSettings, and adding tests for the functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitor.java`:
- Around line 497-509: The current logic skips releasing any read blocks when
diskThresholdSettings.isIndexReadBlockAutoReleaseEnabled() is false, which also
prevents releasing system-set read blocks; update the computation of
indicesToReleaseReadBlock to exclude indices in indicesNotToAutoRelease rather
than returning Set.of() when auto-release is disabled and also add that
exclusion filter in the enabled branch: inside the Stream for
indicesToReleaseReadBlock (and in the else case), filter out indices where
indicesNotToAutoRelease.contains(index) == true so only indices not protected by
indicesNotToAutoRelease are eligible for auto-release; refer to
diskThresholdSettings.isIndexReadBlockAutoReleaseEnabled(),
indicesToReleaseReadBlock, indicesNotToAutoRelease and mirror the conditional
behavior used by handleReadOnlyBlocks/onNewInfo.
🧹 Nitpick comments (1)
server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitorTests.java (1)

545-659: Tests are correct and cover both scenarios well.

Two optional suggestions:

  1. Extract shared setup — both tests duplicate the cluster state construction (~20 lines). A private helper like buildClusterStateWithReadBlock(String indexName) would reduce noise.

  2. Use the existing clusterInfo() helper (line 1497) instead of directly constructing ClusterInfo (lines 595, 655). The helper is used consistently in all other tests in this file.

♻️ Suggested simplification for ClusterInfo construction
-        monitor.onNewInfo(new org.opensearch.cluster.ClusterInfo(usages, Map.of(), Map.of(), Map.of(), Map.of(), Map.of(), Map.of()));
+        monitor.onNewInfo(clusterInfo(usages));

Apply in both tests (lines 595 and 655).

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebc51dc and 7bcc0fb.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitor.java
  • server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdSettings.java
  • server/src/main/java/org/opensearch/common/settings/ClusterSettings.java
  • server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitorTests.java
  • server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdSettingsTests.java
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-01-13T17:40:27.167Z
Learnt from: reta
Repo: opensearch-project/OpenSearch PR: 20411
File: server/src/main/java/org/opensearch/index/codec/CodecService.java:112-133
Timestamp: 2026-01-13T17:40:27.167Z
Learning: Avoid capturing or evaluating a supplier (e.g., this::defaultCodec) upfront when passing it to a registry during object construction. If registries may replace defaults during iteration (as in EnginePlugin.getAdditionalCodecs), pass the supplier itself and only resolve it at use time. This ensures dynamic behavior is preserved during initialization and prevents premature binding of defaults in codecs/registry setup. This pattern should apply to similar initialization paths in Java server code where registries may mutate defaults during construction.

Applied to files:

  • server/src/main/java/org/opensearch/common/settings/ClusterSettings.java
  • server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdSettings.java
  • server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitor.java
🧬 Code graph analysis (1)
server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitorTests.java (1)
server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdSettings.java (1)
  • DiskThresholdSettings (56-537)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Code-Diff-Analyzer / Code-Diff-Analyzer
🔇 Additional comments (6)
CHANGELOG.md (1)

16-16: LGTM!

Changelog entry is correctly placed under "Fixed" and references the right issue.

server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdSettings.java (1)

117-122: LGTM!

The new setting definition correctly mirrors the existing CLUSTER_CREATE_INDEX_BLOCK_AUTO_RELEASE pattern — boolSetting, default true, Dynamic, NodeScope. Constructor initialization, update consumer registration, and getter/setter are all consistent with the established conventions in this class.

server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitor.java (1)

496-509: LGTM — conditional auto-release logic is correct.

The guard on isIndexReadBlockAutoReleaseEnabled() cleanly mirrors the approach used for isCreateIndexBlockAutoReleaseEnabled() in handleClusterCreateIndexBlocks. When disabled, Set.of() prevents any auto-release; when enabled, the existing stream filter logic is preserved.

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java (1)

363-363: LGTM!

Correctly registered alongside the existing CLUSTER_CREATE_INDEX_BLOCK_AUTO_RELEASE setting.

server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdSettingsTests.java (2)

61-61: LGTM!

Default assertion is correctly added to verify isIndexReadBlockAutoReleaseEnabled() returns true.


66-78: LGTM!

Clean test for dynamic update of the new setting. Follows the established test pattern in this file.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +497 to +509
final Set<String> indicesToReleaseReadBlock;
if (diskThresholdSettings.isIndexReadBlockAutoReleaseEnabled()) {
indicesToReleaseReadBlock = StreamSupport.stream(
Spliterators.spliterator(state.routingTable().indicesRouting().entrySet(), 0),
false
)
.map(Map.Entry::getKey)
.filter(index -> indicesToBlockRead.contains(index) == false)
.filter(index -> state.getBlocks().hasIndexBlock(index, IndexMetadata.INDEX_READ_BLOCK))
.collect(Collectors.toSet());
} else {
indicesToReleaseReadBlock = Set.of();
}
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.

⚠️ Potential issue | 🟡 Minor

Setting auto_release=false also suppresses release of system-set read blocks (warm node file cache).

When disabled, this prevents auto-release of all index.blocks.read blocks — including those set by the system when warm nodes breach the file cache search threshold (lines 190-195 in onNewInfo). If a warm node temporarily exceeds the threshold and later recovers, the read block will remain stuck until manually removed or the setting is re-enabled.

Consider whether this is the intended behavior. The analogous handleReadOnlyBlocks method uses the indicesNotToAutoRelease set to selectively protect system-set blocks while still allowing release of others. A similar approach here — only auto-releasing blocks on indices not in indicesNotToAutoRelease — would allow disabling auto-release of manually-set blocks while still permitting system-set blocks to be released.

🤖 Prompt for AI Agents
In
`@server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitor.java`
around lines 497 - 509, The current logic skips releasing any read blocks when
diskThresholdSettings.isIndexReadBlockAutoReleaseEnabled() is false, which also
prevents releasing system-set read blocks; update the computation of
indicesToReleaseReadBlock to exclude indices in indicesNotToAutoRelease rather
than returning Set.of() when auto-release is disabled and also add that
exclusion filter in the enabled branch: inside the Stream for
indicesToReleaseReadBlock (and in the else case), filter out indices where
indicesNotToAutoRelease.contains(index) == true so only indices not protected by
indicesNotToAutoRelease are eligible for auto-release; refer to
diskThresholdSettings.isIndexReadBlockAutoReleaseEnabled(),
indicesToReleaseReadBlock, indicesNotToAutoRelease and mirror the conditional
behavior used by handleReadOnlyBlocks/onNewInfo.

@opensearch-trigger-bot
Copy link
Copy Markdown
Contributor

This PR is stalled because it has been open for 30 days with no activity.

@opensearch-trigger-bot opensearch-trigger-bot bot added the stalled Issues that have stalled label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working good first issue Good for newcomers Search Search query, autocomplete ...etc stalled Issues that have stalled

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] DiskThresholdMonitor unconditionally auto-releases user-set index.blocks.read setting

1 participant