Skip to content
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

Bug Fix , delete OpenSearch index when DROP INDEX #2250

Merged
merged 3 commits into from
Oct 6, 2023

Conversation

penghuo
Copy link
Collaborator

@penghuo penghuo commented Oct 6, 2023

Description

bug fix drop index

Issues Resolved

#2224

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@@ -11,5 +11,5 @@ public interface FlintIndexMetadataReader {
* @param indexDetails indexDetails.
* @return jobId.
*/
String getJobIdFromFlintIndexMetadata(IndexDetails indexDetails);
FlintIndexMetadata getJobIdFromFlintIndexMetadata(IndexDetails indexDetails);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: change method name.
Also, return type in comments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

JSONObject dummyData = new JSONObject();
dummyData.put("result", new JSONArray());
dummyData.put("schema", new JSONArray());
dummyData.put("applicationId", "fakeDropId");
Copy link
Member

Choose a reason for hiding this comment

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

nit: change to fakeApplicationId.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

String queryId =
RandomStringUtils.randomAlphanumeric(PREFIX_LEN)
+ String.join(DELIMITER, status, errorMsg);
return Base64.getEncoder().encodeToString(queryId.getBytes(StandardCharsets.UTF_8));
Copy link
Member

@vamsi-amazon vamsi-amazon Oct 6, 2023

Choose a reason for hiding this comment

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

What is the usual length of this result?
If it is more or less similar to emrJobId it would be good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

SXlRbFhVczI1bEZBSUxFRA== similar

@@ -23,4 +23,38 @@ public class IndexDetails {
private Boolean autoRefresh = false;
private boolean isDropIndex;
private FlintIndexType indexType;

public String openSearchIndexName() {
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense 👍

@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

Merging #2250 (f325997) into main (55e8e84) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##               main    #2250   +/-   ##
=========================================
  Coverage     96.59%   96.60%           
- Complexity     4730     4736    +6     
=========================================
  Files           439      441    +2     
  Lines         12691    12728   +37     
  Branches        871      875    +4     
=========================================
+ Hits          12259    12296   +37     
  Misses          424      424           
  Partials          8        8           
Flag Coverage Δ
sql-engine 96.60% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...OpensearchAsyncQueryJobMetadataStorageService.java 100.00% <100.00%> (ø)
...rch/sql/spark/dispatcher/SparkQueryDispatcher.java 100.00% <100.00%> (ø)
...earch/sql/spark/dispatcher/model/IndexDetails.java 100.00% <100.00%> (ø)
...opensearch/sql/spark/flint/FlintIndexMetadata.java 100.00% <100.00%> (ø)
.../sql/spark/flint/FlintIndexMetadataReaderImpl.java 100.00% <100.00%> (ø)

@@ -53,6 +67,8 @@ public class SparkQueryDispatcher {

private FlintIndexMetadataReader flintIndexMetadataReader;

private Client client;
Copy link
Member

Choose a reason for hiding this comment

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

[Not a hard requirement if possible]
Instead of having client in SparkQueryDispatcher: can we move all the Flint Index logic to One class.

For example: Change FlintIndexMetadataReader -> FlintIndexHanlder and handle deletion logic in that class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agree.
do it later. fix bug first.

Comment on lines 222 to 228
try {
AcknowledgedResponse response =
client.admin().indices().delete(new DeleteIndexRequest().indices(indexName)).get();
if (!response.isAcknowledged()) {
errorMsg = String.format("failed to delete index %s", indexName);
LOG.error(errorMsg);
}
Copy link
Member

Choose a reason for hiding this comment

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

As suggested in above comment can we move this to FlintIndexHandler or some other class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agree.
do it later. fix bug first.

String dropIndexDummyJobId = RandomStringUtils.randomAlphanumeric(16);
FlintIndexMetadata indexMetadata =
flintIndexMetadataReader.getJobIdFromFlintIndexMetadata(indexDetails);
// if index is created without auto refresh. there is no job to cancel.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing this. I missed a lot of cases.

@@ -64,6 +80,11 @@ public DispatchQueryResponse dispatch(DispatchQueryRequest dispatchQueryRequest)
}

public JSONObject getQueryResponse(AsyncQueryJobMetadata asyncQueryJobMetadata) {
// todo. refactor query process logic in plugin.
Copy link
Member

Choose a reason for hiding this comment

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

What does this mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

using if ... else.. not a good solution, we need to add abstraction. e.g. QueryTracker.

try {
if (indexMetadata.isAutoRefresh()) {
emrServerlessClient.cancelJobRun(
dispatchQueryRequest.getApplicationId(), indexMetadata.getJobId());
Copy link
Collaborator

@dai-chen dai-chen Oct 6, 2023

Choose a reason for hiding this comment

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

so if this AppId is different from what's in metadata, we either fail here or assume job is already migrated to this App ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for open source, there is only one appid.
we should handle multiple appId cases in future.

Signed-off-by: Peng Huo <[email protected]>
@penghuo penghuo merged commit 0c78105 into opensearch-project:main Oct 6, 2023
21 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 6, 2023
* Bug Fix, delete opensearch index when DROP INDEX

Signed-off-by: Peng Huo <[email protected]>

* address comments

Signed-off-by: Peng Huo <[email protected]>

---------

Signed-off-by: Peng Huo <[email protected]>
(cherry picked from commit 0c78105)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 6, 2023
* Bug Fix, delete opensearch index when DROP INDEX

Signed-off-by: Peng Huo <[email protected]>

* address comments

Signed-off-by: Peng Huo <[email protected]>

---------

Signed-off-by: Peng Huo <[email protected]>
(cherry picked from commit 0c78105)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
penghuo pushed a commit that referenced this pull request Oct 7, 2023
* Bug Fix, delete opensearch index when DROP INDEX



* address comments



---------


(cherry picked from commit 0c78105)

Signed-off-by: Peng Huo <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
penghuo pushed a commit that referenced this pull request Oct 7, 2023
* Bug Fix, delete opensearch index when DROP INDEX



* address comments



---------


(cherry picked from commit 0c78105)

Signed-off-by: Peng Huo <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants