-
Notifications
You must be signed in to change notification settings - Fork 141
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
Remove direct ClusterState access in LocalClusterState #2696
Remove direct ClusterState access in LocalClusterState #2696
Conversation
4f21fe5
to
bc189aa
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2696 +/- ##
============================================
- Coverage 95.33% 95.33% -0.01%
- Complexity 5089 5097 +8
============================================
Files 494 496 +2
Lines 14287 14297 +10
Branches 957 957
============================================
+ Hits 13621 13630 +9
- Misses 645 646 +1
Partials 21 21
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Looks like you've got some spotless violations here:
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':spotlessJavaCheck'.
> The following files had format violations:
legacy/src/main/java/org/opensearch/sql/legacy/esdomain/LocalClusterState.java
@@ -202,6 +201,7 @@ public Collection<Object> createComponents( | |||
dataSourceService.createDataSource(defaultOpenSearchDataSourceMetadata()); | |||
LocalClusterState.state().setClusterService(clusterService); | |||
LocalClusterState.state().setPluginSettings((OpenSearchSettings) pluginSettings); | |||
LocalClusterState.state().setClient(client); |
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.
"LocalClusterState" is a misnomer now that it is just a pass-through to making a call via the Client, though renaming might make this change more intrusive.
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.
Agreed!
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.index.IndexNotFoundException; | ||
import org.opensearch.sql.common.setting.Settings; | ||
import org.opensearch.sql.legacy.esdomain.mapping.IndexMappings; | ||
import org.opensearch.sql.opensearch.setting.OpenSearchSettings; | ||
|
||
import java.util.Arrays; |
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.
You should generally avoid re-ordering imports unless the new order follows a project-wide convention.
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.
Sounds good! I'll submit a new revision with this change reverted
* Sets the plugin's settings. | ||
* @param settings The non-null plugin settings instance | ||
*/ | ||
public void setPluginSettings(@NonNull OpenSearchSettings settings) { |
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.
Slightly outside the scope of this PR, but it's not immediately obvious why this class is registering a settings update consumer and maintaining it's local cache of settings in latestSettings
. It appears to be duplicating what is already happening in OpenSearchSettings. I wonder if getSettingValue()
can be changed to just be a pass-through to OpenSearchSettings and all usage of the ClusterService can be removed from this class?
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 get the feeling that you're right, but I also haven't spent enough time around it to be sure
public void setResolver(IndexNameExpressionResolver resolver) { | ||
this.resolver = resolver; | ||
} | ||
|
||
private LocalClusterState() { |
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.
No-op method, do we need this ?
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'm keeping it here to keep the constructor visibility rules the same. We could also use lombok to add an auto-generated private constructor
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.
Update: I've decided to use lombok to generate the constructor instead
} else { | ||
mappings = findMappings(state, concreteIndices, fieldFilter); | ||
} | ||
Map<String, MappingMetadata> mappingMetadata = client.admin() |
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.
trying to understand, we are removing SQL cached mappings and always fetch it from client.
Why do we always want to fetch it from client?
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.
The mappings are already cached locally in the cluster state. By fetching via the client we are removing the data synchronization issues between cluster service and this class and avoiding the need for push based notifications to keep data in sync
Map<String, MappingMetadata> mappingMetadata = client.admin() | ||
.indices() | ||
.prepareGetMappings(indices) | ||
.setLocal(true) |
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 presume this always gets mappings from local node, what if the data is stale?
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.
If the data is stale, it will behave as it does today as even today's access is resolved locally.
That being said, it will fail requests with a 4xx as the fields are missing
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.
We can accept this as it is the same as V2. Any thoughts on the long-term implications if schema freshness is critical?
…Mappings Signed-off-by: Frank Dattalo <[email protected]>
bc189aa
to
e67da5f
Compare
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.
LGTM Thanks for the changes.
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.
Thx!
Map<String, MappingMetadata> mappingMetadata = client.admin() | ||
.indices() | ||
.prepareGetMappings(indices) | ||
.setLocal(true) |
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.
We can accept this as it is the same as V2. Any thoughts on the long-term implications if schema freshness is critical?
Description
This commit refactors the LocalClusterState singleton to instead access cluster state through the
org.opensearch.client.Client
abstract interface.Issues Resolved
Check List
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.