From dd7cd8994e1a089f440e0ee171769c7856b76120 Mon Sep 17 00:00:00 2001 From: Pierre Salagnac Date: Mon, 11 May 2026 15:37:18 +0200 Subject: [PATCH] SOLR-18237: Do not copy data before noggit parsing This removes the buffer with full data copy when deserializing collection state from Zookeeper data. --- changelog/unreleased/SOLR-18237-no-buffer.yml | 7 +++++++ .../java/org/apache/solr/common/util/Utils.java | 17 ++++------------- 2 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 changelog/unreleased/SOLR-18237-no-buffer.yml diff --git a/changelog/unreleased/SOLR-18237-no-buffer.yml b/changelog/unreleased/SOLR-18237-no-buffer.yml new file mode 100644 index 000000000000..830416b6f5b4 --- /dev/null +++ b/changelog/unreleased/SOLR-18237-no-buffer.yml @@ -0,0 +1,7 @@ +title: Do not copy full data for UTF8 to Java string conversion for deserializing a collection state +type: fixed +authors: + - name: Pierre Salagnac +links: + - name: SOLR-18237 + url: https://issues.apache.org/jira/browse/SOLR-18237 diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java index 8db2d1c0ae16..3b1fc0d40b29 100644 --- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java +++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java @@ -83,12 +83,9 @@ import org.noggit.JSONWriter; import org.noggit.ObjectBuilder; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class Utils { - private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - public static final Random RANDOM; static { @@ -297,16 +294,10 @@ public static Object fromJSON( if (utf8 == null || utf8.length == 0 || length == 0) { return Map.of(); } - // convert directly from bytes to chars - // and parse directly from that instead of going through - // intermediate strings or readers - CharArr chars = new CharArr(); - ByteUtils.UTF8toUTF16(utf8, offset, length, chars); - JSONParser parser = new JSONParser(chars.getArray(), chars.getStart(), chars.length()); - parser.setFlags( - parser.getFlags() - | JSONParser.ALLOW_MISSING_COLON_COMMA_BEFORE_OBJECT - | JSONParser.OPTIONAL_OUTER_BRACES); + // convert from bytes to chars on-the-fly and parse directly + // from that instead of going through intermediate buffers + Reader reader = new InputStreamReader(new ByteArrayInputStream(utf8, offset, length), UTF_8); + JSONParser parser = getJSONParser(reader); try { return fun.apply(parser).getValStrict(); } catch (IOException e) {