Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Adds support for dynamically updatable search analyzers #290

Merged
merged 14 commits into from
Sep 12, 2020

Conversation

setiah
Copy link
Contributor

@setiah setiah commented Sep 9, 2020

Issue #, if available:

Description of changes:
This change is to add support for hot update of search analyzers in Elasticsearch. It exposes a new REST Api POST /_opendistro/_refresh_search_analyzers/{index}, which when invoked, refreshes those analyzers in memory which were created with is_updateable flag as true. This can be used to refresh synonym list used for search time analysis, without closing and reopening the index.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Himanshu Setia added 6 commits September 8, 2020 19:24
commit c8c8233
Author: Himanshu Setia <[email protected]>
Date:   Tue Sep 8 19:21:58 2020 -0700

    removing comments, linting changes

commit 52526e8
Author: Himanshu Setia <[email protected]>
Date:   Tue Sep 8 19:09:30 2020 -0700

    Making refresh_synonym_analyzer uri odfe compatible

commit d4cc71e
Author: Himanshu Setia <[email protected]>
Date:   Tue Sep 8 18:33:39 2020 -0700

    Adding copyright disclaimer to new files

commit 9af7fdf
Author: Himanshu Setia <[email protected]>
Date:   Tue Sep 8 17:26:53 2020 -0700

    Misc - removing comments, adding newline, etc.

commit 1c85f18
Author: Himanshu Setia <[email protected]>
Date:   Tue Sep 8 16:39:26 2020 -0700

    Adding _refresh_synonym_analyzer API to support dynamic update for search analyzers
@codecov
Copy link

codecov bot commented Sep 9, 2020

Codecov Report

Merging #290 into master will decrease coverage by 0.49%.
The diff coverage is 53.33%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #290      +/-   ##
============================================
- Coverage     75.32%   74.83%   -0.50%     
- Complexity      703      718      +15     
============================================
  Files            89       95       +6     
  Lines          3919     4009      +90     
  Branches        625      633       +8     
============================================
+ Hits           2952     3000      +48     
- Misses          641      683      +42     
  Partials        326      326              
Impacted Files Coverage Δ Complexity Δ
...nt/refreshanalyzer/RefreshSearchAnalyzerRequest.kt 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...refreshanalyzer/RestRefreshSearchAnalyzerAction.kt 41.66% <41.66%> (ø) 3.00 <3.00> (?)
...t/refreshanalyzer/RefreshSearchAnalyzerResponse.kt 44.73% <44.73%> (ø) 6.00 <6.00> (?)
...shanalyzer/TransportRefreshSearchAnalyzerAction.kt 52.17% <52.17%> (ø) 1.00 <1.00> (?)
...ent/refreshanalyzer/RefreshSearchAnalyzerAction.kt 75.00% <75.00%> (ø) 2.00 <2.00> (?)
...ticsearch/indexmanagement/IndexManagementPlugin.kt 91.17% <100.00%> (+0.55%) 9.00 <0.00> (ø)
...reshanalyzer/RefreshSearchAnalyzerShardResponse.kt 100.00% <100.00%> (ø) 3.00 <3.00> (?)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1042dd6...02db791. Read the comment docs.

@setiah setiah requested review from dbbaughe and qreshi September 9, 2020 23:58
@setiah
Copy link
Contributor Author

setiah commented Sep 10, 2020

In the process of adding more UTs to close the codecov/patch gap

@Throws(IOException::class)
constructor(inp: StreamInput) : super(inp) {
val resultSize: Int = inp.readVInt()
for (i in 0..resultSize) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a common pattern you saw elsewhere for reading off streaminput?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, does this constructor only take the streaminput in the format outputted by writeTo? if so, you can change writeTo to do something like:

out.writeList(shardResponses)

and then here you can read the list and pass a class reference to the element of the list (assuming it's Writeable)

inp.readList(::RefreshSearchAnalyzerShardResponse)

You can find a similar example of this in the Monitor data class for Alerting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found this pattern in BroadcastResponse.java, although the one that Mohammad suggested looks to be a better way. I have modified it in my latest commit. Thanks for the suggestion Mo!


val failureSize: Int = inp.readVInt()
for (i in 0..failureSize) {
shardFailures.add(FailedShardDetails(inp.readString(), inp.readInt(), inp.readString()))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Make FailedShardDetails writeable and just pass in the streaminput/output

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I wanted to do some refactoring on this but couldn't get to it earlier. It's done now, the new version does not use this class now.

private val analysisRegistry: AnalysisRegistry

@Throws(IOException::class)
override fun readShardResult(`in`: StreamInput): RefreshSearchAnalyzerShardResponse? {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove nullable return type as it seems to never be null

}

override fun newResponse(
request: RefreshSearchAnalyzerRequest?,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking: can this be null or was this just from autocomplete from IDE

failedShards: Int,
results: List<RefreshSearchAnalyzerShardResponse>,
shardFailures: List<DefaultShardOperationFailedException>,
clusterState: ClusterState?
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking: can this be null or was this just from autocomplete from IDE

}

@Throws(IOException::class)
override fun readRequestFrom(`in`: StreamInput): RefreshSearchAnalyzerRequest? {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove nullable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

Comment on lines 35 to 44
val expectedErrorMessage = mapOf(
"error" to mapOf(
"root_cause" to listOf<Map<String, Any>>(
mapOf("type" to "parse_exception", "reason" to "request body is required")
),
"type" to "parse_exception",
"reason" to "request body is required"
),
"status" to 400
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be not what you are trying to test? If testing for missing indices I'd expect to see an expected message for throw IllegalArgumentException("Missing indices")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the uri change caused the exception behavior to change. I will revert back the uri and change this back

Himanshu Setia and others added 4 commits September 10, 2020 16:16
Squashed commit of the following:

commit d87842e4ccb592a39d6b6897a2b9cde9ddc2839f
Author: Himanshu Setia <[email protected]>
Date:   Thu Sep 10 23:36:24 2020 -0700

    Reverting RefreshSearchAnalyzerResponse stream input output parsing test for fixing later

commit 33ef3223acde38a64575255f7ec702f807d0502e
Author: Himanshu Setia <[email protected]>
Date:   Thu Sep 10 23:34:49 2020 -0700

    Fixing missing indices test

commit 8516d2142362c61630682bf7353e019bf9f6a9eb
Author: Himanshu Setia <[email protected]>
Date:   Thu Sep 10 21:59:55 2020 -0700

    CR comments and added more UTs

commit d306421ca462f2614756a73231baeeb56b388365
Author: Himanshu Setia <[email protected]>
Date:   Thu Sep 10 20:15:59 2020 -0700

    shardFailure refactoring

commit da80de7a68fef05e524e624ea1a8da6afdbf11d4
Author: Himanshu Setia <[email protected]>
Date:   Thu Sep 10 18:14:45 2020 -0700

    Working changes after refactoring shardFailure

commit be9bf2daaa31fb6444f799a8f3ed3d0383551471
Author: Himanshu Setia <[email protected]>
Date:   Thu Sep 10 17:45:31 2020 -0700

    Corrected response parsing for indices with some failed shards

commit 256f06ed23ac4ab2d78724601a1dd7e9d1423331
Author: Himanshu Setia <[email protected]>
Date:   Thu Sep 10 17:12:00 2020 -0700

    Working
@@ -20,7 +20,7 @@ import org.elasticsearch.common.io.stream.Writeable

class RefreshSearchAnalyzerAction : ActionType<RefreshSearchAnalyzerResponse>(NAME, reader) {
companion object {
const val NAME = "indices:admin/refresh_search_analyzer"
const val NAME = "indices:admin/_refresh_search_analyzers"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it common to prefix _ on the action names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it's not. Will change back to indices:admin/refresh_search_analyzers

dbbaughe
dbbaughe previously approved these changes Sep 11, 2020
@setiah setiah merged commit a095266 into opendistro-for-elasticsearch:master Sep 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants