diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 312d8a783f6..4464c4c2b09 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -183,6 +183,8 @@ Optimizations This gives a lower absolute score but doesn't affect ordering, as this is a constant factor which is the same for every document. Use LegacyBM25SimilarityFactory if you need the old 6.x/7.x scoring. See also upgrade notes (janhoy) +* SOLR-13130: during the ResponseBuilder.STAGE_GET_FIELDS directly copy string bytes and avoid creating String Objects (noble) + Other Changes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java index 03a08ce339f..3943d28162d 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java @@ -36,6 +36,7 @@ import java.util.function.Predicate; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrResponse; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.impl.BinaryResponseParser; import org.apache.solr.client.solrj.impl.Http2SolrClient; import org.apache.solr.client.solrj.impl.LBSolrClient; import org.apache.solr.client.solrj.request.QueryRequest; @@ -53,6 +54,7 @@ import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ShardParams; import org.apache.solr.common.params.SolrParams; +import org.apache.solr.common.util.JavaBinCodec; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.StrUtils; import org.apache.solr.core.CoreDescriptor; @@ -62,6 +64,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; +import static org.apache.solr.handler.component.ShardRequest.PURPOSE_GET_FIELDS; + public class HttpShardHandler extends ShardHandler { /** @@ -132,6 +136,13 @@ public class HttpShardHandler extends ShardHandler { return urls; } + private static final BinaryResponseParser READ_STR_AS_CHARSEQ_PARSER = new BinaryResponseParser() { + @Override + protected JavaBinCodec createCodec() { + return new JavaBinCodec(null, stringCache).setReadStringAsCharSeq(true); + } + }; + @Override public void submit(final ShardRequest sreq, final String shard, final ModifiableSolrParams params) { // do this outside of the callable for thread safety reasons @@ -158,6 +169,9 @@ public class HttpShardHandler extends ShardHandler { SolrRequestInfo requestInfo = SolrRequestInfo.getRequestInfo(); if (requestInfo != null) req.setUserPrincipal(requestInfo.getReq().getUserPrincipal()); + if (sreq.purpose == PURPOSE_GET_FIELDS) { + req.setResponseParser(READ_STR_AS_CHARSEQ_PARSER); + } // no need to set the response parser as binary is the default // req.setResponseParser(new BinaryResponseParser()); diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryResponseParser.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryResponseParser.java index 18baf039f59..e033abb12a7 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryResponseParser.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryResponseParser.java @@ -32,7 +32,7 @@ import java.io.Reader; public class BinaryResponseParser extends ResponseParser { public static final String BINARY_CONTENT_TYPE = "application/octet-stream"; - private JavaBinCodec.StringCache stringCache; + protected JavaBinCodec.StringCache stringCache; public BinaryResponseParser setStringCache(JavaBinCodec.StringCache cache) { this.stringCache = cache; @@ -47,13 +47,17 @@ public class BinaryResponseParser extends ResponseParser { @Override public NamedList processResponse(InputStream body, String encoding) { try { - return (NamedList) new JavaBinCodec(null,stringCache).unmarshal(body); + return (NamedList) createCodec().unmarshal(body); } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "parsing error", e); } } + protected JavaBinCodec createCodec() { + return new JavaBinCodec(null, stringCache); + } + @Override public String getContentType() { return BINARY_CONTENT_TYPE;