-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add FileCache Prune REST API endpoint #19321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add FileCache Prune REST API endpoint #19321
Conversation
- Implements POST /_cache/remote/prune endpoint for manual cache cleanup - Adds comprehensive action, transport, and REST handler implementation - Includes full test coverage for all components
❌ Gradle check result for 7788eb6: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Mind opening an issue to describe the purpose of this new API? |
Gradle Check failed due to Flaky Tests : #17486 |
server/src/main/java/org/opensearch/action/admin/cluster/cache/PruneCacheAction.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/opensearch/action/admin/cluster/cache/PruneCacheAction.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/opensearch/action/admin/cluster/cache/PruneCacheRequest.java
Outdated
Show resolved
Hide resolved
❕ Gradle check result for 5f88ec4: UNSTABLE Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #19321 +/- ##
==========================================
Coverage 72.96% 72.97%
- Complexity 69825 69870 +45
==========================================
Files 5667 5673 +6
Lines 320555 320700 +145
Branches 46348 46364 +16
==========================================
+ Hits 233908 234035 +127
- Misses 67769 67782 +13
- Partials 18878 18883 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
❌ Gradle check result for ca35f02: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Requesting Review CC : @Harsh-87 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from these minor comments, rest of the changes LGTM.
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof NodePruneCacheResponse)) return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: The convention is to use == false
instead of !
.
public boolean isPartiallySuccessful() { | ||
return !getNodes().isEmpty() && !failures().isEmpty(); | ||
} | ||
|
||
/** | ||
* Check if the operation was completely successful (all targeted nodes succeeded) | ||
* | ||
* @return true if all targeted nodes succeeded | ||
*/ | ||
public boolean isCompletelySuccessful() { | ||
return !getNodes().isEmpty() && failures().isEmpty(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using these methods anywhere else except in tests? If not we can mark these @VisibleForTesting
instead of making them public.
); | ||
} | ||
|
||
if (warmNodes.isEmpty() && nodeIds.length == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodeIds.length == 0
check is redundant here.
|
||
@Override | ||
protected NodePruneCacheResponse nodeOperation(NodeRequest nodeRequest) { | ||
PruneCacheRequest request = nodeRequest.getRequest(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't see request
getting used here.
if (fileCache != null) { | ||
b.bind(FileCache.class).toInstance(fileCache); | ||
} else { | ||
b.bind(FileCache.class).toProvider(() -> null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b.bind(FileCache.class).toProvider(() -> null); | |
b.bind(FileCache.class).toProvider(Providers.of(null)); |
assert request.concreteNodes() == null : "request concreteNodes shouldn't be set"; | ||
|
||
String[] nodeIds = clusterState.nodes().resolveNodes(request.nodesIds()); | ||
List<DiscoveryNode> warmNodes = Arrays.stream(nodeIds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can first collect Warm nodes and then take intersection with the nodeIds from request and we can reuse the same list at Line 85.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if this PR get's merged first then we can get the same list directly fromDiscoveryNodes.getWarmNodes()
as well.
Add FileCache Prune REST API
Introduces a REST API for on-demand pruning of OpenSearch's file cache. This production-ready implementation enables operators to efficiently manage disk space across warm node clusters.
Issue
#19322
Implementation Architecture
Implements OpenSearch's advanced TransportNodesAction pattern for sophisticated multi-node coordination:
API Specification
Endpoint
Parameters
nodes
(optional) — Comma-separated list of node IDs or node selectors (e.g.,warm:true
)node
(optional) — Single node ID for targeted operationstimeout
(optional) — Operation timeout (e.g.,30s
,2m
,1h
)Response Format
Files Added
Files Modified
Advanced Capabilities
Intelligent Node Targeting
Test Architecture
PruneCacheRequestResponseTests.java
TransportPruneCacheActionTests.java
RestPruneCacheActionTests.java
Behavior Details
FileCache.prune()
and returns actual freed bytes with capacity metricsSequence Flow Diagram