Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
35 changes: 2 additions & 33 deletions solr/core/src/java/org/apache/solr/core/CoreContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -86,7 +85,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;
Expand Down Expand Up @@ -162,8 +160,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;

Expand Down Expand Up @@ -417,7 +413,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;
Expand Down Expand Up @@ -2416,31 +2411,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<String> 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);
}
}
});
}

}
3 changes: 3 additions & 0 deletions solr/solrj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ 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


testImplementation libs.apache.httpcomponents.httpclient
testImplementation libs.apache.httpcomponents.httpcore

Expand Down
2 changes: 1 addition & 1 deletion solr/solrj/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -389,14 +390,17 @@ public int size() {
return collectionStates.size();
}

private static volatile Function<JSONParser, ObjectBuilder> STR_INTERNER_OBJ_BUILDER =
STANDARDOBJBUILDER;
private static volatile Function<JSONParser, ObjectBuilder> STR_INTERNER_OBJ_BUILDER;

/**
* @lucene.internal
*/
public static void setStrInternerParser(Function<JSONParser, ObjectBuilder> fun) {
if (fun == null) return;
STR_INTERNER_OBJ_BUILDER = fun;
static {
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;
}
}
23 changes: 23 additions & 0 deletions solr/solrj/src/java/org/apache/solr/common/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -362,6 +363,7 @@ public static Object fromJSON(Reader is) {
throw new RuntimeException(e);
}
};

public static final Function<JSONParser, ObjectBuilder> MAPWRITEROBJBUILDER =
jsonParser -> {
try {
Expand All @@ -376,6 +378,27 @@ public Object newObject() {
}
};

public static final Function<JSONParser, ObjectBuilder> WEAKSTRINGINTERNEROBJBUILDER =
jsonParser -> {
try {
Interner<String> 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<JSONParser, ObjectBuilder> MAPOBJBUILDER =
jsonParser -> {
try {
Expand Down