dsmiley commented on code in PR #4149: URL: https://github.com/apache/solr/pull/4149#discussion_r3012804156
########## solr/core/src/test/org/apache/solr/handler/admin/LukeHandlerCloudTest.java: ########## @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.handler.admin; + +import static org.apache.solr.common.params.CommonParams.DISTRIB; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.SolrQuery; +import org.apache.solr.client.solrj.request.schema.SchemaRequest; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.cloud.DocCollection; +import org.apache.solr.common.cloud.Replica; +import org.apache.solr.common.cloud.Slice; +import org.apache.solr.common.params.ModifiableSolrParams; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** Cloud-specific Luke tests that require SolrCloud features like managed schema and Schema API. */ +public class LukeHandlerCloudTest extends SolrCloudTestCase { + + @BeforeClass + public static void setupCluster() throws Exception { + configureCluster(2).addConfig("managed", configset("cloud-managed")).configure(); + } + + @AfterClass + public static void afterClass() throws Exception { + shutdownCluster(); Review Comment: is that really necessary? ########## solr/core/src/test/org/apache/solr/handler/admin/LukeHandlerCloudTest.java: ########## @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.handler.admin; + +import static org.apache.solr.common.params.CommonParams.DISTRIB; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.SolrQuery; +import org.apache.solr.client.solrj.request.schema.SchemaRequest; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.cloud.DocCollection; +import org.apache.solr.common.cloud.Replica; +import org.apache.solr.common.cloud.Slice; +import org.apache.solr.common.params.ModifiableSolrParams; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** Cloud-specific Luke tests that require SolrCloud features like managed schema and Schema API. */ +public class LukeHandlerCloudTest extends SolrCloudTestCase { Review Comment: nice! ########## solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java: ########## @@ -544,10 +561,35 @@ private void aggregateShardField( } } - Long docsAsLong = fi.getDocsAsLong(); - if (docsAsLong != null) { - fieldData.aggregated.compute( - KEY_DOCS_AS_LONG, (key, val) -> val == null ? docsAsLong : (Long) val + docsAsLong); + // "docs" → sum of per-shard doc counts (number of documents containing this field) + long docsLong = fi.getDocs(); + fieldData.aggregated.compute( + KEY_DOCS, (key, val) -> val == null ? docsLong : (Long) val + docsLong); + } + + /** + * Minimum client version that understands Long values in distributed Luke responses. Distributed + * Luke aggregates counts across shards, which can overflow Integer. Older clients cast these + * values to Integer and would fail with a ClassCastException. + */ + private static final SolrVersion DISTRIB_LONG_COUNTS_MIN_VERSION = + SolrVersion.forIntegers(10, 2, 0); Review Comment: let's be more optimistic and choose 10.1. there's no news of 10.1 yet ########## solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java: ########## @@ -544,10 +561,35 @@ private void aggregateShardField( } } - Long docsAsLong = fi.getDocsAsLong(); - if (docsAsLong != null) { - fieldData.aggregated.compute( - KEY_DOCS_AS_LONG, (key, val) -> val == null ? docsAsLong : (Long) val + docsAsLong); + // "docs" → sum of per-shard doc counts (number of documents containing this field) + long docsLong = fi.getDocs(); + fieldData.aggregated.compute( + KEY_DOCS, (key, val) -> val == null ? docsLong : (Long) val + docsLong); + } + + /** + * Minimum client version that understands Long values in distributed Luke responses. Distributed + * Luke aggregates counts across shards, which can overflow Integer. Older clients cast these + * values to Integer and would fail with a ClassCastException. + */ + private static final SolrVersion DISTRIB_LONG_COUNTS_MIN_VERSION = + SolrVersion.forIntegers(10, 2, 0); + + private static boolean shouldNarrowLongsForOldClient(SolrQueryRequest req) { + HttpSolrCall call = req.getHttpSolrCall(); + if (call == null) return false; + SolrVersion clientVersion = call.getUserAgentSolrVersion(); + return clientVersion != null && clientVersion.lessThan(DISTRIB_LONG_COUNTS_MIN_VERSION); + } + + /** Narrows a Long value to Integer if it fits, for javabin backward compatibility. */ + private static void narrowLongToInt(NamedList<Object> nl, String key) { + int idx = nl.indexOf(key, 0); + if (idx >= 0) { + Object val = nl.getVal(idx); + if (val instanceof Long l && l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE) { Review Comment: I like the approach here! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
