-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing Delete PIT service layer changes (#3949)
* Delete pit service layer changes Signed-off-by: Bharathwaj G <bharath78910@gmail.com>
- Loading branch information
1 parent
a34a4c0
commit f4b0eef
Showing
19 changed files
with
2,033 additions
and
8 deletions.
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.