SOLR-13130: during the ResponseBuilder.STAGE_GET_FIELDS directly copy string bytes and avoid creating String Objects

This commit is contained in:
Noble Paul 2019-01-27 16:02:11 +11:00
parent 000785e68e
commit 250d21da94
3 changed files with 22 additions and 2 deletions

View File

@ -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
----------------------

View File

@ -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());

View File

@ -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<Object> processResponse(InputStream body, String encoding) {
try {
return (NamedList<Object>) new JavaBinCodec(null,stringCache).unmarshal(body);
return (NamedList<Object>) 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;