-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Implementing Delete PIT service layer changes #3949
Merged
Bukhtawar
merged 22 commits into
opensearch-project:main
from
bharath-techie:deletepitservice
Jul 26, 2022
Merged
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a8be024
Create pit service layer changes
bharath-techie 8a8f708
Create pit service layer changes
bharath-techie f20dbdc
Delete pit service layer changes
bharath-techie fa9946b
Create pit service layer changes
bharath-techie 8f673c5
Merge branch 'createpitservice' of github.com:bharath-techie/OpenSear…
bharath-techie 97c4f77
changing to consistent action names
bharath-techie bfcb50a
changing to consistent action names
bharath-techie f96c9d7
Addressing review comment
bharath-techie 7f9d1b8
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie 5d8ec6b
Addressing review comment
bharath-techie 987cb57
Addressing review comments
bharath-techie 9497923
Merge branch 'createpitservice' of github.com:bharath-techie/OpenSear…
bharath-techie 8fcc25c
Addressing review comments
bharath-techie ab3f0d4
Merge branch 'createpitservice' of github.com:bharath-techie/OpenSear…
bharath-techie 41d342d
Resolving conflicts
bharath-techie 25bb645
Addressing comments
bharath-techie 717cd66
Addressing comments
bharath-techie f4db20b
Addressing review comment
bharath-techie 3f08013
Addressing review comment - adding tests to test concurrency
bharath-techie f76fa24
Addressing review comment - adding tests to test concurrency
bharath-techie d870dd5
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie ae618ff
Merge branch 'deletepitservice' of github.com:bharath-techie/OpenSear…
bharath-techie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
server/src/main/java/org/opensearch/action/search/DeletePitAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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.search; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
/** | ||
* Action type for deleting point in time searches | ||
*/ | ||
public class DeletePitAction extends ActionType<DeletePitResponse> { | ||
|
||
public static final DeletePitAction INSTANCE = new DeletePitAction(); | ||
public static final String NAME = "indices:data/read/point_in_time/delete"; | ||
|
||
private DeletePitAction() { | ||
super(NAME, DeletePitResponse::new); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
server/src/main/java/org/opensearch/action/search/DeletePitInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* 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.search; | ||
|
||
import org.opensearch.common.ParseField; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.common.io.stream.Writeable; | ||
import org.opensearch.common.xcontent.ConstructingObjectParser; | ||
import org.opensearch.common.xcontent.ToXContent; | ||
import org.opensearch.common.xcontent.XContentBuilder; | ||
import org.opensearch.transport.TransportResponse; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.opensearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
||
/** | ||
* This class captures if deletion of pit is successful along with pit id | ||
*/ | ||
public class DeletePitInfo extends TransportResponse implements Writeable, ToXContent { | ||
/** | ||
* This will be true if PIT reader contexts are deleted ond also if contexts are not found. | ||
*/ | ||
private final boolean successful; | ||
|
||
private final String pitId; | ||
|
||
public DeletePitInfo(boolean successful, String pitId) { | ||
this.successful = successful; | ||
this.pitId = pitId; | ||
} | ||
|
||
public DeletePitInfo(StreamInput in) throws IOException { | ||
successful = in.readBoolean(); | ||
pitId = in.readString(); | ||
|
||
} | ||
|
||
public boolean isSuccessful() { | ||
return successful; | ||
} | ||
|
||
public String getPitId() { | ||
return pitId; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeBoolean(successful); | ||
out.writeString(pitId); | ||
} | ||
|
||
static final ConstructingObjectParser<DeletePitInfo, Void> PARSER = new ConstructingObjectParser<>( | ||
"delete_pit_info", | ||
true, | ||
args -> new DeletePitInfo((boolean) args[0], (String) args[1]) | ||
); | ||
|
||
static { | ||
PARSER.declareBoolean(constructorArg(), new ParseField("successful")); | ||
PARSER.declareString(constructorArg(), new ParseField("pitId")); | ||
} | ||
|
||
private static final ParseField SUCCESSFUL = new ParseField("successful"); | ||
private static final ParseField PIT_ID = new ParseField("pitId"); | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(SUCCESSFUL.getPreferredName(), successful); | ||
builder.field(PIT_ID.getPreferredName(), pitId); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
} |
121 changes: 121 additions & 0 deletions
121
server/src/main/java/org/opensearch/action/search/DeletePitRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
|
||
/* | ||
* 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.search; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.common.xcontent.ToXContent; | ||
import org.opensearch.common.xcontent.ToXContentObject; | ||
import org.opensearch.common.xcontent.XContentBuilder; | ||
import org.opensearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.opensearch.action.ValidateActions.addValidationError; | ||
|
||
/** | ||
* Request to delete one or more PIT search contexts based on IDs. | ||
*/ | ||
public class DeletePitRequest extends ActionRequest implements ToXContentObject { | ||
|
||
/** | ||
* List of PIT IDs to be deleted , and use "_all" to delete all PIT reader contexts | ||
*/ | ||
private final List<String> pitIds = new ArrayList<>(); | ||
|
||
public DeletePitRequest(StreamInput in) throws IOException { | ||
super(in); | ||
pitIds.addAll(Arrays.asList(in.readStringArray())); | ||
} | ||
|
||
public DeletePitRequest(String... pitIds) { | ||
this.pitIds.addAll(Arrays.asList(pitIds)); | ||
} | ||
|
||
public DeletePitRequest(List<String> pitIds) { | ||
this.pitIds.addAll(pitIds); | ||
} | ||
|
||
public DeletePitRequest() {} | ||
|
||
public List<String> getPitIds() { | ||
return pitIds; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (pitIds == null || pitIds.isEmpty()) { | ||
validationException = addValidationError("no pit ids specified", validationException); | ||
} | ||
return validationException; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
if (pitIds == null) { | ||
out.writeVInt(0); | ||
} else { | ||
out.writeStringArray(pitIds.toArray(new String[pitIds.size()])); | ||
} | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
builder.startObject(); | ||
builder.startArray("pit_id"); | ||
for (String pitId : pitIds) { | ||
builder.value(pitId); | ||
} | ||
builder.endArray(); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public void fromXContent(XContentParser parser) throws IOException { | ||
pitIds.clear(); | ||
if (parser.nextToken() != XContentParser.Token.START_OBJECT) { | ||
throw new IllegalArgumentException("Malformed content, must start with an object"); | ||
} else { | ||
XContentParser.Token token; | ||
String currentFieldName = null; | ||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { | ||
if (token == XContentParser.Token.FIELD_NAME) { | ||
currentFieldName = parser.currentName(); | ||
} else if ("pit_id".equals(currentFieldName)) { | ||
if (token == XContentParser.Token.START_ARRAY) { | ||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { | ||
if (token.isValue() == false) { | ||
throw new IllegalArgumentException("pit_id array element should only contain pit_id"); | ||
} | ||
pitIds.add(parser.text()); | ||
} | ||
} else { | ||
if (token.isValue() == false) { | ||
throw new IllegalArgumentException("pit_id element should only contain pit_id"); | ||
} | ||
pitIds.add(parser.text()); | ||
} | ||
} else { | ||
throw new IllegalArgumentException( | ||
"Unknown parameter [" + currentFieldName + "] in request body or parameter is of the wrong type[" + token + "] " | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: put this inside the if block instead of negating it and returning early