From 740fc3e6c492bb02bc32003b887679f6593b4226 Mon Sep 17 00:00:00 2001 From: Sanjay Yadav Date: Sat, 29 Nov 2025 18:19:43 +0530 Subject: [PATCH 1/8] SOLR-17787 CborResponseWriter should use content-type: application/cbor --- .../solr/response/CborResponseWriter.java | 4 +- .../solr/response/TestRawResponseWriter.java | 42 +++++++++++++++++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java b/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java index fd5bc68f113..3821c647dc9 100644 --- a/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java @@ -22,7 +22,6 @@ import java.io.OutputStream; import java.math.BigDecimal; import java.math.BigInteger; -import org.apache.solr.client.solrj.impl.JavaBinResponseParser; import org.apache.solr.common.util.NamedList; import org.apache.solr.request.SolrQueryRequest; @@ -31,6 +30,7 @@ * jackson library to write the stream out */ public class CborResponseWriter implements QueryResponseWriter { + public static final String APPLICATION_CBOR_VALUE = "application/cbor"; final CBORFactory cborFactory; final CBORFactory cborFactoryCompact; @@ -52,7 +52,7 @@ public void write( @Override public String getContentType(SolrQueryRequest request, SolrQueryResponse response) { - return JavaBinResponseParser.JAVABIN_CONTENT_TYPE; + return APPLICATION_CBOR_VALUE; } static class WriterImpl extends JSONWriter { diff --git a/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java b/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java index fea9ad10a4a..50d7995423d 100644 --- a/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java +++ b/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java @@ -20,12 +20,20 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.concurrent.atomic.LongAdder; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.cbor.CBORFactory; +import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; import org.apache.lucene.tests.util.TestUtil; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.impl.JavaBinResponseParser; import org.apache.solr.common.util.ContentStreamBase.ByteArrayStream; import org.apache.solr.common.util.ContentStreamBase.StringStream; import org.apache.solr.common.util.NamedList; +import org.apache.solr.handler.loader.CborLoader; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -35,6 +43,7 @@ public class TestRawResponseWriter extends SolrTestCaseJ4 { private static RawResponseWriter writerXmlBase; private static RawResponseWriter writerJsonBase; private static RawResponseWriter writerBinBase; + private static RawResponseWriter writeCborBase; private static RawResponseWriter writerNoBase; private static RawResponseWriter[] allWriters; @@ -51,9 +60,10 @@ public static void setupCoreAndWriters() throws Exception { writerXmlBase = newRawResponseWriter("xml"); writerJsonBase = newRawResponseWriter("json"); writerBinBase = newRawResponseWriter("javabin"); + writeCborBase = newRawResponseWriter("cbor"); allWriters = - new RawResponseWriter[] {writerXmlBase, writerJsonBase, writerBinBase, writerNoBase}; + new RawResponseWriter[] {writerXmlBase, writerJsonBase, writerBinBase,writeCborBase, writerNoBase}; } @AfterClass @@ -62,7 +72,7 @@ public static void cleanupWriters() { writerJsonBase = null; writerBinBase = null; writerNoBase = null; - + writeCborBase = null; allWriters = null; } @@ -125,6 +135,7 @@ public void testStructuredDataViaBaseWriters() throws IOException { assertEquals("application/xml; charset=UTF-8", writerXmlBase.getContentType(req(), rsp)); assertEquals("application/json; charset=UTF-8", writerJsonBase.getContentType(req(), rsp)); assertEquals("application/octet-stream", writerBinBase.getContentType(req(), rsp)); + assertEquals(CborResponseWriter.APPLICATION_CBOR_VALUE, writeCborBase.getContentType(req(), rsp)); // check response against each writer @@ -162,8 +173,33 @@ public void testStructuredDataViaBaseWriters() throws IOException { assertEquals("test", out.getVal(0)); assertEquals("foo", out.getName(1)); assertEquals("bar", out.getVal(1)); - } + // cbor + + byte[] cborBytes = serializeToCbor(json.getBytes()); + assertEquals(25, cborBytes.length); + LongAdder docsSz = new LongAdder(); + new CborLoader(null, (document) -> docsSz.increment()).stream(new ByteArrayInputStream(cborBytes)); + assertEquals(1, docsSz.intValue()); + + } + private byte[] serializeToCbor(byte[] is) throws IOException { + ByteArrayOutputStream baos; + ObjectMapper jsonMapper = new ObjectMapper(new JsonFactory()); + + // Read JSON file as a JsonNode + JsonNode jsonNode = jsonMapper.readTree(is); + // Create a CBOR ObjectMapper + baos = new ByteArrayOutputStream(); + + ObjectMapper cborMapper = + new ObjectMapper(CBORFactory.builder().enable(CBORGenerator.Feature.STRINGREF).build()); + JsonGenerator jsonGenerator = cborMapper.createGenerator(baos); + + jsonGenerator.writeTree(jsonNode); + jsonGenerator.close(); + return baos.toByteArray(); + } /** * Generates a new {@link RawResponseWriter} wrapping the specified baseWriter name (which much * either be an implicitly defined response writer, or one explicitly configured in From ab2e17a53e3608622ad79360582e40d472cbb255 Mon Sep 17 00:00:00 2001 From: Sanjay Yadav Date: Sat, 29 Nov 2025 19:15:18 +0530 Subject: [PATCH 2/8] SOLR-17787 executed tidy and changes the variable name --- .../solr/response/TestRawResponseWriter.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java b/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java index 50d7995423d..1fd8ee01a67 100644 --- a/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java +++ b/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java @@ -16,17 +16,17 @@ */ package org.apache.solr.response; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.concurrent.atomic.LongAdder; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import com.fasterxml.jackson.dataformat.cbor.CBORGenerator; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.atomic.LongAdder; import org.apache.lucene.tests.util.TestUtil; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.impl.JavaBinResponseParser; @@ -63,7 +63,9 @@ public static void setupCoreAndWriters() throws Exception { writeCborBase = newRawResponseWriter("cbor"); allWriters = - new RawResponseWriter[] {writerXmlBase, writerJsonBase, writerBinBase,writeCborBase, writerNoBase}; + new RawResponseWriter[] { + writerXmlBase, writerJsonBase, writerBinBase, writeCborBase, writerNoBase + }; } @AfterClass @@ -135,7 +137,8 @@ public void testStructuredDataViaBaseWriters() throws IOException { assertEquals("application/xml; charset=UTF-8", writerXmlBase.getContentType(req(), rsp)); assertEquals("application/json; charset=UTF-8", writerJsonBase.getContentType(req(), rsp)); assertEquals("application/octet-stream", writerBinBase.getContentType(req(), rsp)); - assertEquals(CborResponseWriter.APPLICATION_CBOR_VALUE, writeCborBase.getContentType(req(), rsp)); + assertEquals( + CborResponseWriter.APPLICATION_CBOR_VALUE, writeCborBase.getContentType(req(), rsp)); // check response against each writer @@ -178,11 +181,12 @@ public void testStructuredDataViaBaseWriters() throws IOException { byte[] cborBytes = serializeToCbor(json.getBytes()); assertEquals(25, cborBytes.length); - LongAdder docsSz = new LongAdder(); - new CborLoader(null, (document) -> docsSz.increment()).stream(new ByteArrayInputStream(cborBytes)); - assertEquals(1, docsSz.intValue()); - + LongAdder numberOfObjectsInResponse = new LongAdder(); + new CborLoader(null, (document) -> numberOfObjectsInResponse.increment()) + .stream(new ByteArrayInputStream(cborBytes)); + assertEquals(1, numberOfObjectsInResponse.intValue()); } + private byte[] serializeToCbor(byte[] is) throws IOException { ByteArrayOutputStream baos; ObjectMapper jsonMapper = new ObjectMapper(new JsonFactory()); @@ -200,6 +204,7 @@ private byte[] serializeToCbor(byte[] is) throws IOException { jsonGenerator.close(); return baos.toByteArray(); } + /** * Generates a new {@link RawResponseWriter} wrapping the specified baseWriter name (which much * either be an implicitly defined response writer, or one explicitly configured in From cf6cfad9a4473c0feaac9fa73975d737e3a96476 Mon Sep 17 00:00:00 2001 From: Sanjay Yadav Date: Wed, 3 Dec 2025 07:42:47 +0530 Subject: [PATCH 3/8] SOLR-17787 executed tidy and changes the variable name --- .../solr/response/TestRawResponseWriter.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java b/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java index 1fd8ee01a67..53c04b424aa 100644 --- a/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java +++ b/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java @@ -43,7 +43,7 @@ public class TestRawResponseWriter extends SolrTestCaseJ4 { private static RawResponseWriter writerXmlBase; private static RawResponseWriter writerJsonBase; private static RawResponseWriter writerBinBase; - private static RawResponseWriter writeCborBase; + private static RawResponseWriter writerCborBase; private static RawResponseWriter writerNoBase; private static RawResponseWriter[] allWriters; @@ -60,11 +60,11 @@ public static void setupCoreAndWriters() throws Exception { writerXmlBase = newRawResponseWriter("xml"); writerJsonBase = newRawResponseWriter("json"); writerBinBase = newRawResponseWriter("javabin"); - writeCborBase = newRawResponseWriter("cbor"); + writerCborBase = newRawResponseWriter("cbor"); allWriters = new RawResponseWriter[] { - writerXmlBase, writerJsonBase, writerBinBase, writeCborBase, writerNoBase + writerXmlBase, writerJsonBase, writerBinBase, writerCborBase, writerNoBase }; } @@ -74,7 +74,7 @@ public static void cleanupWriters() { writerJsonBase = null; writerBinBase = null; writerNoBase = null; - writeCborBase = null; + writerCborBase = null; allWriters = null; } @@ -138,7 +138,7 @@ public void testStructuredDataViaBaseWriters() throws IOException { assertEquals("application/json; charset=UTF-8", writerJsonBase.getContentType(req(), rsp)); assertEquals("application/octet-stream", writerBinBase.getContentType(req(), rsp)); assertEquals( - CborResponseWriter.APPLICATION_CBOR_VALUE, writeCborBase.getContentType(req(), rsp)); + CborResponseWriter.APPLICATION_CBOR_VALUE, writerCborBase.getContentType(req(), rsp)); // check response against each writer @@ -179,7 +179,7 @@ public void testStructuredDataViaBaseWriters() throws IOException { // cbor - byte[] cborBytes = serializeToCbor(json.getBytes()); + byte[] cborBytes = convertJsonToCborFormat(json.getBytes()); assertEquals(25, cborBytes.length); LongAdder numberOfObjectsInResponse = new LongAdder(); new CborLoader(null, (document) -> numberOfObjectsInResponse.increment()) @@ -187,12 +187,12 @@ public void testStructuredDataViaBaseWriters() throws IOException { assertEquals(1, numberOfObjectsInResponse.intValue()); } - private byte[] serializeToCbor(byte[] is) throws IOException { + private byte[] convertJsonToCborFormat(byte[] inputJson) throws IOException { ByteArrayOutputStream baos; ObjectMapper jsonMapper = new ObjectMapper(new JsonFactory()); // Read JSON file as a JsonNode - JsonNode jsonNode = jsonMapper.readTree(is); + JsonNode jsonNode = jsonMapper.readTree(inputJson); // Create a CBOR ObjectMapper baos = new ByteArrayOutputStream(); From d1e74c8baad218397bd783f169d164831adfb548 Mon Sep 17 00:00:00 2001 From: Sanjay Yadav Date: Wed, 3 Dec 2025 10:41:42 +0530 Subject: [PATCH 4/8] SOLR-17787 CborResponseWriter should use content-type: application/cbor --- .../src/java/org/apache/solr/response/CborResponseWriter.java | 4 ++-- .../test/org/apache/solr/response/TestRawResponseWriter.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java b/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java index 8aa473e03ee..3821c647dc9 100644 --- a/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/CborResponseWriter.java @@ -22,7 +22,6 @@ import java.io.OutputStream; import java.math.BigDecimal; import java.math.BigInteger; -import org.apache.solr.client.solrj.response.JavaBinResponseParser; import org.apache.solr.common.util.NamedList; import org.apache.solr.request.SolrQueryRequest; @@ -31,6 +30,7 @@ * jackson library to write the stream out */ public class CborResponseWriter implements QueryResponseWriter { + public static final String APPLICATION_CBOR_VALUE = "application/cbor"; final CBORFactory cborFactory; final CBORFactory cborFactoryCompact; @@ -52,7 +52,7 @@ public void write( @Override public String getContentType(SolrQueryRequest request, SolrQueryResponse response) { - return JavaBinResponseParser.JAVABIN_CONTENT_TYPE; + return APPLICATION_CBOR_VALUE; } static class WriterImpl extends JSONWriter { diff --git a/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java b/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java index 1e0888e87d0..7b822b18848 100644 --- a/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java +++ b/solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java @@ -179,7 +179,7 @@ public void testStructuredDataViaBaseWriters() throws IOException { // cbor - byte[] cborBytes = convertJsonToCborFormat(json.getBytes()); + byte[] cborBytes = convertJsonToCborFormat(json.getBytes(StandardCharsets.UTF_8)); assertEquals(25, cborBytes.length); LongAdder numberOfObjectsInResponse = new LongAdder(); new CborLoader(null, (document) -> numberOfObjectsInResponse.increment()) From 0def9dfe2280b4ce7c1bc2e75f92cdf2768910c7 Mon Sep 17 00:00:00 2001 From: Sanjay Yadav Date: Wed, 3 Dec 2025 11:36:08 +0530 Subject: [PATCH 5/8] SOLR-17787 CborResponseWriter should use content-type: application/cbor(change log) --- ...onseWriter-should-use-content-type-application.yaml.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelog/unreleased/SOLR-17787-CborResponseWriter-should-use-content-type-application.yaml.yml diff --git a/changelog/unreleased/SOLR-17787-CborResponseWriter-should-use-content-type-application.yaml.yml b/changelog/unreleased/SOLR-17787-CborResponseWriter-should-use-content-type-application.yaml.yml new file mode 100644 index 00000000000..cb73b4d104f --- /dev/null +++ b/changelog/unreleased/SOLR-17787-CborResponseWriter-should-use-content-type-application.yaml.yml @@ -0,0 +1,7 @@ +title: CborResponseWriter should use content-typ- application/cbor +type: other +authors: +- name: Sanjay Kumar Yadav +links: +- name: SOLR-17787 + url: https://issues.apache.org/jira/browse/SOLR-17787 From 8eaaba633cd75dcbaec14483104cb37dfcbb3d51 Mon Sep 17 00:00:00 2001 From: Sanjay Yadav Date: Tue, 9 Dec 2025 10:18:19 +0530 Subject: [PATCH 6/8] SOLR-17461 (cleanup) Move ClusterState string "Interner" json parser to Utils --- .../org/apache/solr/core/CoreContainer.java | 34 ++----------------- solr/solrj/build.gradle | 1 + .../solr/common/cloud/ClusterState.java | 15 ++++---- .../org/apache/solr/common/util/Utils.java | 25 ++++++++++++++ 4 files changed, 34 insertions(+), 41 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index cccb6bd8f2e..d2131b9c673 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -34,7 +34,7 @@ import static org.apache.solr.search.SolrIndexSearcher.EXECUTOR_MAX_CPU_THREADS; import static org.apache.solr.security.AuthenticationPlugin.AUTHENTICATION_PLUGIN_PROP; -import com.github.benmanes.caffeine.cache.Interner; + import com.google.common.annotations.VisibleForTesting; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.Tracer; @@ -86,7 +86,6 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.cloud.Aliases; -import org.apache.solr.common.cloud.ClusterState; import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Replica.State; @@ -162,8 +161,6 @@ import org.apache.zookeeper.KeeperException; import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.ApplicationHandler; -import org.noggit.JSONParser; -import org.noggit.ObjectBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -417,7 +414,6 @@ public CoreContainer(NodeConfig config, CoresLocator locator, boolean asyncSolrC if (null != this.cfg.getBooleanQueryMaxClauseCount()) { IndexSearcher.setMaxClauseCount(this.cfg.getBooleanQueryMaxClauseCount()); } - setWeakStringInterner(); this.coresLocator = locator; this.containerProperties = new Properties(config.getSolrProperties()); this.asyncSolrCoreLoad = asyncSolrCoreLoad; @@ -2416,31 +2412,5 @@ public void runAsync(Runnable r) { coreContainerAsyncTaskExecutor.execute(r); } - public static void setWeakStringInterner() { - boolean enable = "true".equals(System.getProperty("solr.use.str.intern", "true")); - if (!enable) return; - Interner interner = Interner.newWeakInterner(); - ClusterState.setStrInternerParser( - new Function<>() { - @Override - public ObjectBuilder apply(JSONParser p) { - try { - return new ObjectBuilder(p) { - @Override - public void addKeyVal(Object map, Object key, Object val) throws IOException { - if (key != null) { - key = interner.intern(key.toString()); - } - if (val instanceof String) { - val = interner.intern((String) val); - } - super.addKeyVal(map, key, val); - } - }; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - }); - } + } diff --git a/solr/solrj/build.gradle b/solr/solrj/build.gradle index b9520d5b0fd..d069ff0a982 100644 --- a/solr/solrj/build.gradle +++ b/solr/solrj/build.gradle @@ -44,6 +44,7 @@ dependencies { runtimeOnly libs.eclipse.jetty.alpnjavaclient compileOnly libs.stephenc.jcip.annotations + compileOnly libs.benmanes.caffeine testImplementation libs.apache.httpcomponents.httpclient testImplementation libs.apache.httpcomponents.httpcore diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java index 18e93ec7eb6..4eca2653e40 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java @@ -17,6 +17,7 @@ package org.apache.solr.common.cloud; import static org.apache.solr.common.util.Utils.STANDARDOBJBUILDER; +import static org.apache.solr.common.util.Utils.WEAKSTRINGINTERNEROBJBUILDER; import java.io.IOException; import java.lang.invoke.MethodHandles; @@ -389,14 +390,10 @@ public int size() { return collectionStates.size(); } - private static volatile Function STR_INTERNER_OBJ_BUILDER = - STANDARDOBJBUILDER; - - /** - * @lucene.internal - */ - public static void setStrInternerParser(Function fun) { - if (fun == null) return; - STR_INTERNER_OBJ_BUILDER = fun; + private static volatile Function STR_INTERNER_OBJ_BUILDER ; + static { + boolean enable = "true".equals(System.getProperty("solr.use.str.intern", "true")); + STR_INTERNER_OBJ_BUILDER = !enable? STANDARDOBJBUILDER: WEAKSTRINGINTERNEROBJBUILDER; } + } 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 1e2f69da972..f0dbd2b8624 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 @@ -72,6 +72,9 @@ import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; + + +import com.github.benmanes.caffeine.cache.Interner; import org.apache.solr.common.IteratorWriter; import org.apache.solr.common.LinkedHashMapWriter; import org.apache.solr.common.MapWriter; @@ -362,6 +365,7 @@ public static Object fromJSON(Reader is) { throw new RuntimeException(e); } }; + public static final Function MAPWRITEROBJBUILDER = jsonParser -> { try { @@ -376,6 +380,27 @@ public Object newObject() { } }; + public static final Function WEAKSTRINGINTERNEROBJBUILDER = + jsonParser -> { + try { + Interner interner = Interner.newWeakInterner(); + return new ObjectBuilder(jsonParser) { + @Override + public void addKeyVal(Object map, Object key, Object val) throws IOException { + if (key != null) { + key = interner.intern(key.toString()); + } + if (val instanceof String) { + val = interner.intern((String) val); + } + super.addKeyVal(map, key, val); + } + }; + } catch (IOException e) { + throw new RuntimeException(e); + } + }; + public static final Function MAPOBJBUILDER = jsonParser -> { try { From 48025f067771a1f883ce66d0e0d18516e0d3fbfd Mon Sep 17 00:00:00 2001 From: Sanjay Yadav Date: Wed, 10 Dec 2025 10:29:15 +0530 Subject: [PATCH 7/8] SOLR-17461 (cleanup) Move ClusterState string "Interner" json parser to Utils --- .../java/org/apache/solr/core/CoreContainer.java | 1 - solr/solrj/build.gradle | 4 +++- solr/solrj/gradle.lockfile | 2 +- .../apache/solr/common/cloud/ClusterState.java | 15 +++++++++++---- .../java/org/apache/solr/common/util/Utils.java | 4 +--- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index d2131b9c673..69cfe081652 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -58,7 +58,6 @@ import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeoutException; -import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; import org.apache.lucene.index.CorruptIndexException; diff --git a/solr/solrj/build.gradle b/solr/solrj/build.gradle index d069ff0a982..bb0829e23fd 100644 --- a/solr/solrj/build.gradle +++ b/solr/solrj/build.gradle @@ -41,10 +41,12 @@ dependencies { implementation libs.eclipse.jetty.client implementation libs.eclipse.jetty.util implementation libs.eclipse.jetty.io + implementation(libs.benmanes.caffeine) { transitive = false } + runtimeOnly libs.eclipse.jetty.alpnjavaclient compileOnly libs.stephenc.jcip.annotations - compileOnly libs.benmanes.caffeine + testImplementation libs.apache.httpcomponents.httpclient testImplementation libs.apache.httpcomponents.httpcore diff --git a/solr/solrj/gradle.lockfile b/solr/solrj/gradle.lockfile index 3ea7f9bb887..e3efe24e798 100644 --- a/solr/solrj/gradle.lockfile +++ b/solr/solrj/gradle.lockfile @@ -11,7 +11,7 @@ com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.20.0=jarValidation,t com.fasterxml.jackson.module:jackson-module-jakarta-xmlbind-annotations:2.20.0=jarValidation,testRuntimeClasspath com.fasterxml.jackson:jackson-bom:2.20.0=apiHelper,compileClasspath,jarValidation,runtimeClasspath,testCompileClasspath,testRuntimeClasspath com.fasterxml.woodstox:woodstox-core:7.0.0=jarValidation,testRuntimeClasspath -com.github.ben-manes.caffeine:caffeine:3.2.2=annotationProcessor,errorprone,jarValidation,testAnnotationProcessor,testRuntimeClasspath +com.github.ben-manes.caffeine:caffeine:3.2.2=annotationProcessor,compileClasspath,errorprone,jarValidation,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath com.github.kevinstern:software-and-algorithms:1.0=annotationProcessor,errorprone,testAnnotationProcessor com.github.stephenc.jcip:jcip-annotations:1.0-1=compileClasspath,compileOnlyHelper,jarValidation com.google.auto.service:auto-service-annotations:1.0.1=annotationProcessor,errorprone,testAnnotationProcessor diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java index 4eca2653e40..11eaf26eef2 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java @@ -390,10 +390,17 @@ public int size() { return collectionStates.size(); } - private static volatile Function STR_INTERNER_OBJ_BUILDER ; + private static volatile Function STR_INTERNER_OBJ_BUILDER; + static { - boolean enable = "true".equals(System.getProperty("solr.use.str.intern", "true")); - STR_INTERNER_OBJ_BUILDER = !enable? STANDARDOBJBUILDER: WEAKSTRINGINTERNEROBJBUILDER; + ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + if (contextClassLoader == null) { + contextClassLoader = ClusterState.class.getClassLoader(); + } + String resourcePath = "com/github/benmanes/caffeine/cache/Interner.class"; + boolean hasInterner = + contextClassLoader.getResource(resourcePath) != null + || ClassLoader.getSystemResource(resourcePath) != null; + STR_INTERNER_OBJ_BUILDER = hasInterner ? WEAKSTRINGINTERNEROBJBUILDER : STANDARDOBJBUILDER; } - } 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 f0dbd2b8624..1b1068a3e4f 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 @@ -22,6 +22,7 @@ import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR; import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.github.benmanes.caffeine.cache.Interner; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.EOFException; @@ -72,9 +73,6 @@ import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; - - -import com.github.benmanes.caffeine.cache.Interner; import org.apache.solr.common.IteratorWriter; import org.apache.solr.common.LinkedHashMapWriter; import org.apache.solr.common.MapWriter; From 794192584b334e3b0e586b36b84e4406ae4890b9 Mon Sep 17 00:00:00 2001 From: Sanjay Yadav Date: Wed, 10 Dec 2025 10:30:01 +0530 Subject: [PATCH 8/8] SOLR-17461 (cleanup) Move ClusterState string "Interner" json parser to Utils --- ...7461-Move-ClusterState-string-json-parser-to-Utils.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/SOLR-17461-Move-ClusterState-string-json-parser-to-Utils.yml diff --git a/changelog/unreleased/SOLR-17461-Move-ClusterState-string-json-parser-to-Utils.yml b/changelog/unreleased/SOLR-17461-Move-ClusterState-string-json-parser-to-Utils.yml new file mode 100644 index 00000000000..ec14f7a75a0 --- /dev/null +++ b/changelog/unreleased/SOLR-17461-Move-ClusterState-string-json-parser-to-Utils.yml @@ -0,0 +1,8 @@ +# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc +title: Move ClusterState string json parser to Utils +type: other # added, changed, fixed, deprecated, removed, dependency_update, security, other +authors: + - name: Sanjay Yadav +links: + - name: SOLR-17461 + url: https://issues.apache.org/jira/browse/SOLR-17461