-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add query parameters to delete request cache on heap and disk selectively #15
Changes from all commits
47c4082
1107061
abf1390
5120cda
e76e6e6
65bf1ac
bdb4376
e0c0b67
589b414
c03fedd
e0842dd
c437bbd
e3a37ff
19f2e9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action; | ||
|
||
public interface InputValidator { | ||
void validateInput() throws IllegalArgumentException; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
package org.opensearch.action.admin.indices.cache.clear; | ||
|
||
import org.opensearch.Version; | ||
import org.opensearch.action.InputValidator; | ||
import org.opensearch.action.support.broadcast.BroadcastRequest; | ||
import org.opensearch.core.common.Strings; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
|
@@ -45,12 +46,14 @@ | |
* | ||
* @opensearch.internal | ||
*/ | ||
public class ClearIndicesCacheRequest extends BroadcastRequest<ClearIndicesCacheRequest> { | ||
public class ClearIndicesCacheRequest extends BroadcastRequest<ClearIndicesCacheRequest> implements InputValidator { | ||
|
||
private boolean queryCache = false; | ||
private boolean fieldDataCache = false; | ||
private boolean requestCache = false; | ||
private boolean fileCache = false; | ||
private boolean requestCacheOnDisk = false; | ||
private boolean requestCacheOnHeap = false; | ||
private String[] fields = Strings.EMPTY_ARRAY; | ||
|
||
public ClearIndicesCacheRequest(StreamInput in) throws IOException { | ||
|
@@ -59,6 +62,12 @@ public ClearIndicesCacheRequest(StreamInput in) throws IOException { | |
fieldDataCache = in.readBoolean(); | ||
fields = in.readStringArray(); | ||
requestCache = in.readBoolean(); | ||
if (in.getVersion().onOrAfter(Version.V_2_12_0)) { | ||
requestCacheOnDisk = in.readBoolean(); | ||
} | ||
if (in.getVersion().onOrAfter(Version.V_2_12_0)) { | ||
requestCacheOnHeap = in.readBoolean(); | ||
} | ||
if (in.getVersion().onOrAfter(Version.V_2_8_0)) { | ||
fileCache = in.readBoolean(); | ||
} | ||
|
@@ -81,11 +90,29 @@ public boolean requestCache() { | |
return this.requestCache; | ||
} | ||
|
||
public boolean requestCacheOnDisk() { | ||
return this.requestCacheOnDisk; | ||
} | ||
|
||
public boolean requestCacheOnHeap() { | ||
return this.requestCacheOnHeap; | ||
} | ||
|
||
public ClearIndicesCacheRequest requestCache(boolean requestCache) { | ||
this.requestCache = requestCache; | ||
return this; | ||
} | ||
|
||
public ClearIndicesCacheRequest requestCacheOnDisk(boolean requestCacheOnDisk) { | ||
this.requestCacheOnDisk = requestCacheOnDisk; | ||
return this; | ||
} | ||
|
||
public ClearIndicesCacheRequest requestCacheOnHeap(boolean requestCacheOnHeap) { | ||
this.requestCacheOnHeap = requestCacheOnHeap; | ||
return this; | ||
} | ||
|
||
public boolean fieldDataCache() { | ||
return this.fieldDataCache; | ||
} | ||
|
@@ -120,8 +147,23 @@ public void writeTo(StreamOutput out) throws IOException { | |
out.writeBoolean(fieldDataCache); | ||
out.writeStringArrayNullable(fields); | ||
out.writeBoolean(requestCache); | ||
if (out.getVersion().onOrAfter(Version.V_2_12_0)) { | ||
out.writeBoolean(requestCacheOnDisk); | ||
} | ||
if (out.getVersion().onOrAfter(Version.V_2_12_0)) { | ||
out.writeBoolean(requestCacheOnHeap); | ||
} | ||
kiranprakash154 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (out.getVersion().onOrAfter(Version.V_2_8_0)) { | ||
out.writeBoolean(fileCache); | ||
} | ||
} | ||
|
||
public void validateInput() { | ||
if (requestCache && requestCacheOnDisk) { | ||
throw new IllegalArgumentException("Invalid parameters: cannot have both request and requestCacheOnDisk set to true"); | ||
} | ||
if (requestCache && requestCacheOnHeap) { | ||
throw new IllegalArgumentException("Invalid parameters: cannot have both request and requestCacheOnHeap set to true"); | ||
} | ||
} | ||
Comment on lines
+161
to
+168
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets remove this for now and keep it consistent with rest of the actions. Move this logic to the actual function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the validity of the ClearIndicesCacheRequest should be scoped to the ClearIndicesCacheRequest class right ? |
||
} |
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.
I feel like something like this must already exist somewhere... seems like a general problem that many APIs would have to solve