Skip to content

SOLR-17625 NamedList.findRecursive-> _get #3355

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

Merged
merged 13 commits into from
Jun 2, 2025
Merged

Conversation

wildtusker
Copy link
Contributor

Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

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

I suspect you didn't review your work / the results.

You had List.of(new String[]{"foo", "bar"}) in all these places instead of List.of("foo", "bar"). Using IntelliJ "structural replace" feature, I easily fixed all of them at once and pushed to your PR.

There are newly declared variables everywhere. That should be completely unnecessary. You can fix them by doing doing "inline" refactoring in IntelliJ when clicking each needless variable (use a hot key to make it go quicker).

In places a String is casted, _getStr should be used.

In some places, I expect the default value (last arg) to be useful, which findRecursive didn't support.

All this makes this change look way worse but instead we should find essentially the same amount of code as before, mostly.

@@ -280,7 +281,8 @@ public int assertSolrNotRunning(String url, String credentials) throws Exception
System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeoutMs, TimeUnit.MILLISECONDS);
try (SolrClient solrClient = CLIUtils.getSolrClient(url, credentials)) {
NamedList<Object> response = solrClient.request(new HealthCheckRequest());
Integer statusCode = (Integer) response.findRecursive("responseHeader", "status");
Object value = response._get(List.of(new String[] {"responseHeader", "status"}), null);
Integer statusCode = (Integer) value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't declare new variables merely to cast.

String totalMemory = (String) systemInfo.findRecursive("jvm", "memory", "total");
Object value2 = systemInfo._get(List.of("jvm", "jmx", "upTimeMS"), null);
uptime = SolrCLI.uptime((Long) value2);
Object value1 = systemInfo._get(List.of("jvm", "memory", "used"), null);
Copy link
Contributor

Choose a reason for hiding this comment

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

use _getStr, same with below

@@ -862,14 +862,18 @@ public static void checkDiskSpace(
SolrRequest.METHOD.GET, "/admin/metrics", SolrRequest.SolrRequestType.ADMIN, params)
.process(cloudManager.getSolrClient());

Number size = (Number) rsp.getResponse().findRecursive("metrics", indexSizeMetricName);
NamedList<Object> entries1 = rsp.getResponse();
Copy link
Contributor

Choose a reason for hiding this comment

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

again, no need to declare another variable

Copy link
Contributor

Choose a reason for hiding this comment

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

still an issue

@wildtusker
Copy link
Contributor Author

  1. List.of(new String[]{"foo", "bar"})

  2. Made changes using Method Over loading .Got rid of List.of(new String[]{"foo", "bar"}) .Even the variables which were getting created

  3. Newly declared variables have been removed

4_getStr has not been used as of now.
Default value will be on case to case basis or where required.

Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

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

I did a partial review. I encourage you to review it fully (I do it for my own work).

I get the feeling that _get ought not to have a default parameter (at the end) since it's so rarely useful, judging from this PR anyway. If that makes sense; it'd be a separate PR later.

Comment on lines 321 to 322
String usedMemory = (String) info._get(List.of("jvm", "memory", "used"), null);
String totalMemory = (String) info._get(List.of("jvm", "memory", "total"), null);
Copy link
Contributor

Choose a reason for hiding this comment

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

_getStr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will make the change. _get is replaced with _getStr.

@@ -862,14 +862,18 @@ public static void checkDiskSpace(
SolrRequest.METHOD.GET, "/admin/metrics", SolrRequest.SolrRequestType.ADMIN, params)
.process(cloudManager.getSolrClient());

Number size = (Number) rsp.getResponse().findRecursive("metrics", indexSizeMetricName);
NamedList<Object> entries1 = rsp.getResponse();
Copy link
Contributor

Choose a reason for hiding this comment

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

still an issue

This reverts commit 81eed8a.           Changes made with help inline method feature.The methods were over loaded with 1 , 2 ,3 and 4 arguments with String type
Updated StatusTool.java SplitShardCmd.java doesnt require update
This reverts commit 81eed8a.           Changes made with help inline method feature.The methods were over loaded with 1 , 2 ,3 and 4 arguments with String type
Updated StatusTool.java SplitShardCmd.java doesnt require update
This reverts commit 81eed8a.           Changes made with help inline method feature.The methods were over loaded with 1 , 2 ,3 and 4 arguments with String type
update
String totalMemory = (String) systemInfo.findRecursive("jvm", "memory", "total");
uptime =
SolrCLI.uptime((Long) systemInfo._get(List.of("jvm", "jmx", "upTimeMS"), null));
String usedMemory = (String) systemInfo._get(List.of("jvm", "memory", "used"), null);
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume you didn't finish reviewing this PR since this shows some _getStr opportunities.

This reverts commit 81eed8a.           Changes made with help inline method feature.The methods were over loaded with 1 , 2 ,3 and 4 arguments with String type
update
Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

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

Please self review more next time so that you believe it to be ready. There were dubious entries1 that we discussed previously.

Otherwise looks good!

This reverts commit 81eed8a.           Changes made with help inline method feature.The methods were over loaded with 1 , 2 ,3 and 4 arguments with String type
update
@@ -438,8 +436,7 @@ public void testJsonFacets() throws Exception {
+ " } "
+ "}"));
{
NamedList<Object> entries1 = response.getResponse();
final NamedList<?> q1Res = (NamedList<?>) entries1._get(List.of("facets", "q1"), null);
final NamedList<?> q1Res = (NamedList<?>) response.getResponse()._get(List.of("facets", "q1"), null);
Copy link
Contributor

Choose a reason for hiding this comment

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

remember "gw tidy", I see here and elsewhere. I think you can configure IntelliJ better so that basic indentation like this would not be incorrect so often. I have an idea that I'll raise elsewhere that should reduce this annoyance.

wildtusker and others added 5 commits May 31, 2025 23:29
This reverts commit 81eed8a.           Changes made with help inline method feature.The methods were over loaded with 1 , 2 ,3 and 4 arguments with String type
update
@dsmiley dsmiley merged commit 51841d7 into apache:main Jun 2, 2025
1 check passed
dsmiley pushed a commit that referenced this pull request Jun 3, 2025
Replaced NamedList.findRecursive usages with _get, which can do Map traversal, and
  thus makes it easier to transition intermediate NamedLists to Maps.

(cherry picked from commit 51841d7)
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.

2 participants