-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Refactor: Rename DataSourceTaskIdHolder and extract load spec holder to its own class #18732
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
base: master
Are you sure you want to change the base?
Conversation
…ss to avoid confusion.
| "Cannot specify both `lookupTier` and `lookupTierIsDatasource`" | ||
| ); | ||
| final String lookupTier = lookupTierIsDatasource ? dataSourceTaskIdHolder.getDataSource() : this.lookupTier; | ||
| final String lookupTier = lookupTierIsDatasource ? taskPropsHolder.getDataSource() : this.lookupTier; |
Check notice
Code scanning / CodeQL
Possible confusion of local and field Note
getLookupTier
lookupTier
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 13 days ago
To fix the problem, we should rename the local variable in the getLookupTier() method to avoid overshadowing the field name. This means giving the local variable a new, clear, and context-specific name while ensuring the assignment and uses of the variable are updated to match the new name. The best choice is to use a name like tierToUse, which clearly identifies its role as the lookup tier value that will be used in the final return.
Steps:
- In
getLookupTier(), changefinal String lookupTier = ...tofinal String tierToUse = .... - Update all uses of the local variable within the method (namely, the argument to
emptyToNullNonDruidDataStringandPreconditions.checkNotNull) to referencetierToUseinstead oflookupTier. - No additional imports or method definitions are required.
All changes can be made within the method body in server/src/main/java/org/apache/druid/query/lookup/LookupListeningAnnouncerConfig.java.
-
Copy modified line R58 -
Copy modified line R61
| @@ -55,10 +55,10 @@ | ||
| !(lookupTierIsDatasource && null != lookupTier), | ||
| "Cannot specify both `lookupTier` and `lookupTierIsDatasource`" | ||
| ); | ||
| final String lookupTier = lookupTierIsDatasource ? taskPropsHolder.getDataSource() : this.lookupTier; | ||
| final String tierToUse = lookupTierIsDatasource ? taskPropsHolder.getDataSource() : this.lookupTier; | ||
|
|
||
| return Preconditions.checkNotNull( | ||
| lookupTier == null ? DEFAULT_TIER : StringUtils.emptyToNullNonDruidDataString(lookupTier), | ||
| tierToUse == null ? DEFAULT_TIER : StringUtils.emptyToNullNonDruidDataString(tierToUse), | ||
| "Cannot have empty lookup tier from %s", | ||
| lookupTierIsDatasource ? "bound value" : LookupModule.PROPERTY_BASE | ||
| ); |
kfaraz
left a comment
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.
Thanks for putting this together, @abhishekrb19 !
I had a slightly different approach in mind.
In the original class, DatasourceTaskIdHolder all the fields are derived from Task itself, so we should probably just:
- Rename it to
PeonTaskHolderto denote that this class is meaningful only for a peon and that it contains the task that the peon is running - Just keep one field inside it
Task taskand add methodgetTask() - Retain the original utility methods
getDatasource(),getTaskId(),getLookupLoadinSpec()etc. - Create the
PeonTaskHolderin a@Providesmethod inCliPeon. - In non peon servers, bind the
PeonTaskHolderto null.
Let me know if this would make sense.
|
Thanks for the review, @kfaraz! I think the approach of keeping one renamed class would work well and makes sense. Just one caveat: the |
|
Ah, I see, thanks for clarifying that, @abhishekrb19 ! All the current usages of In that case, I think we should add an interface Sound good? |
|
@kfaraz sorry I ran into some hiccups with the bindings last week and didn't get a chance to take a closer look, but I'm hoping to revive this change again soon. Btw I noticed this deprecated comment on EmbeddedMiddleManager, so most (or all?) the tests seem to use the indexer for good reasons. Given that there are some subtle differences between indexers and MMs, do you have any suggestions for embedded tests that use MMs? At the very least, I was thinking of updating some of the embedded tests to use |
No worries, @abhishekrb19 ! 🙂
If the purpose is to test out peons in an embedded test setup, you could do a couple of things:
For local testing, please feel free to update any test to use an MM instead of Indexer. Most of them should work fine for both Indexer and MM. Please let me know if this meets yours needs. |
|
Sounds good, thanks for the pointer @kfaraz! I will give that a try |
Refactor:
LookupLoadSpecandBroadcastDatasourceLoadingSpecto a new class calledLoadSpecHolder. These are applicable to all servers, includingCliPeonservers.DataSourceTaskIdHoldertoTaskPropertiesHolder. This is applicable to onlyCliPeonservers.This separation makes the intent clearer, as
DataSourceTaskIdHolderwas previously misleading as it held more than just the dataSource and taskId fields.The
TaskPropertiesHoldercurrently containtaskIdanddataSourcefields injected from the CliPeon. In the future, we can extend it to also includegroupIdandtaskTypefrom the Task and add those dimensions to all the metric modules as applicable.This PR has: