This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new a733331b8fd SOLR-18149: remove ClusterState.createFromJson --
deprecated (#4777)
a733331b8fd is described below
commit a733331b8fd9ae5c054de4af487e383d09bf451a
Author: Serhiy Bzhezytskyy <[email protected]>
AuthorDate: Tue Aug 25 01:28:52 2026 +0300
SOLR-18149: remove ClusterState.createFromJson -- deprecated (#4777)
And removed mostly unused String intern on ClusterState. Prefer simplicity
over dubious improvement we don't even have today.
---
.../java/org/apache/solr/core/CoreContainer.java | 34 ----------------
.../org/apache/solr/core/backup/BackupManager.java | 5 ++-
.../org/apache/solr/cloud/ClusterStateTest.java | 18 ++-------
.../test/org/apache/solr/cloud/SliceStateTest.java | 4 +-
.../org/apache/solr/common/cloud/ClusterState.java | 46 ----------------------
.../solrj/impl/CloudSolrClientCacheTest.java | 15 +++++--
6 files changed, 21 insertions(+), 101 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 81f3b067fd0..86a3b2677d9 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,6 @@ import static
org.apache.solr.metrics.SolrMetricProducer.TYPE_ATTR;
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;
@@ -58,7 +57,6 @@ import java.util.concurrent.ConcurrentHashMap;
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;
@@ -85,7 +83,6 @@ import org.apache.solr.common.AlreadyClosedException;
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;
@@ -163,8 +160,6 @@ import org.apache.solr.util.tracing.TraceUtils;
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;
@@ -418,7 +413,6 @@ public class CoreContainer {
if (null != this.cfg.getBooleanQueryMaxClauseCount()) {
IndexSearcher.setMaxClauseCount(this.cfg.getBooleanQueryMaxClauseCount());
}
- setWeakStringInterner();
this.coresLocator = locator;
this.containerProperties = new Properties(config.getSolrProperties());
this.asyncSolrCoreLoad = asyncSolrCoreLoad;
@@ -2501,34 +2495,6 @@ public class CoreContainer {
coreContainerAsyncTaskExecutor.execute(r);
}
- public static void setWeakStringInterner() {
- boolean enable = "true".equals(EnvUtils.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);
- }
- }
- });
- }
-
/**
* Audit an event if our audit plugin is installed and wants to audit this
type of event.
*
diff --git a/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java
b/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java
index 3d4ae4d2f0e..ac3bd04900b 100644
--- a/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java
+++ b/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java
@@ -224,7 +224,10 @@ public class BackupManager {
is.readBytes(arr, 0, (int) is.length());
// set a default created date, we don't aim at reading actual zookeeper
state. The restored
// collection will have a new creation date when persisted in zookeeper.
- ClusterState c_state = ClusterState.createFromJson(-1, arr, Set.of(),
Instant.EPOCH, null);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> stateMap = (Map<String, Object>) Utils.fromJSON(arr,
0, arr.length);
+ ClusterState c_state =
+ ClusterState.createFromCollectionMap(-1, stateMap, Set.of(),
Instant.EPOCH, null);
return c_state.getCollection(collectionName);
}
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/ClusterStateTest.java
b/solr/core/src/test/org/apache/solr/cloud/ClusterStateTest.java
index f6a4fd48be5..6014d281606 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ClusterStateTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ClusterStateTest.java
@@ -75,8 +75,10 @@ public class ClusterStateTest extends SolrTestCaseJ4 {
byte[] bytes = Utils.toJSON(clusterState);
Instant creationTime = Instant.now();
+ @SuppressWarnings("unchecked")
+ Map<String, Object> stateMap = (Map<String, Object>) Utils.fromJSON(bytes,
0, bytes.length);
ClusterState loadedClusterState =
- ClusterState.createFromJson(-1, bytes, liveNodes, creationTime, null);
+ ClusterState.createFromCollectionMap(-1, stateMap, liveNodes,
creationTime, null);
assertFalse(
loadedClusterState.getCollection("collection1").getProperties().containsKey("shards"));
@@ -104,19 +106,5 @@ public class ClusterStateTest extends SolrTestCaseJ4 {
assertEquals(creationTime,
loadedClusterState.getCollection("collection1").getCreationTime());
assertEquals(creationTime,
loadedClusterState.getCollection("collection2").getCreationTime());
-
- loadedClusterState =
- ClusterState.createFromJson(-1, new byte[0], liveNodes, Instant.now(),
null);
-
- assertEquals(
- "Provided liveNodes not used properly", 2,
loadedClusterState.getLiveNodes().size());
- assertEquals("Should not have collections", 0, loadedClusterState.size());
-
- loadedClusterState =
- ClusterState.createFromJson(-1, (byte[]) null, liveNodes,
Instant.now(), null);
-
- assertEquals(
- "Provided liveNodes not used properly", 2,
loadedClusterState.getLiveNodes().size());
- assertEquals("Should not have collections", 0, loadedClusterState.size());
}
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/SliceStateTest.java
b/solr/core/src/test/org/apache/solr/cloud/SliceStateTest.java
index 6be03e4c791..53a28be81e2 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SliceStateTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SliceStateTest.java
@@ -69,8 +69,10 @@ public class SliceStateTest extends SolrTestCaseJ4 {
ClusterState clusterState = new ClusterState(liveNodes, collectionStates);
byte[] bytes = Utils.toJSON(clusterState);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> stateMap = (Map<String, Object>) Utils.fromJSON(bytes,
0, bytes.length);
ClusterState loadedClusterState =
- ClusterState.createFromJson(-1, bytes, liveNodes, Instant.now(), null);
+ ClusterState.createFromCollectionMap(-1, stateMap, liveNodes,
Instant.now(), null);
assertSame(
"Default state not set to active",
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 ba92c3a9011..7064c13e707 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
@@ -16,8 +16,6 @@
*/
package org.apache.solr.common.cloud;
-import static org.apache.solr.common.util.Utils.STANDARDOBJBUILDER;
-
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.time.Instant;
@@ -31,17 +29,12 @@ import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.Function;
import java.util.stream.Stream;
import org.apache.solr.common.MapWriter;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.DocCollection.CollectionStateProps;
import org.apache.solr.common.util.CollectionUtil;
-import org.apache.solr.common.util.Utils;
-import org.noggit.JSONParser;
-import org.noggit.JSONWriter;
-import org.noggit.ObjectBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -197,34 +190,6 @@ public class ClusterState implements MapWriter {
return sb.toString();
}
- /**
- * Create a ClusterState from Json. This method doesn't support legacy
configName location and
- * thus don't call it where that's important
- *
- * @param bytes a byte array of a Json representation of a mapping from
collection name to the
- * Json representation of a {@link DocCollection} as written by {@link
#write(JSONWriter)}. It
- * can represent one or more collections.
- * @param liveNodes list of live nodes
- * @param creationTime assigns this date to all {@link DocCollection}
referenced by the returned
- * {@link ClusterState}
- * @return the ClusterState
- */
- @Deprecated
- public static ClusterState createFromJson(
- int version,
- byte[] bytes,
- Set<String> liveNodes,
- Instant creationTime,
- DocCollection.PrsSupplier prsSupplier) {
- if (bytes == null || bytes.length == 0) {
- return new ClusterState(liveNodes, Map.of());
- }
- @SuppressWarnings({"unchecked"})
- Map<String, Object> stateMap =
- (Map<String, Object>) Utils.fromJSON(bytes, 0, bytes.length,
STR_INTERNER_OBJ_BUILDER);
- return createFromCollectionMap(version, stateMap, liveNodes, creationTime,
prsSupplier);
- }
-
@Deprecated
public static ClusterState createFromCollectionMap(
int version,
@@ -388,15 +353,4 @@ public class ClusterState implements MapWriter {
public int size() {
return collectionStates.size();
}
-
- private static volatile Function<JSONParser, ObjectBuilder>
STR_INTERNER_OBJ_BUILDER =
- STANDARDOBJBUILDER;
-
- /**
- * @lucene.internal
- */
- public static void setStrInternerParser(Function<JSONParser, ObjectBuilder>
fun) {
- if (fun == null) return;
- STR_INTERNER_OBJ_BUILDER = fun;
- }
}
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
index 18a279cbcd2..0b671fb81d4 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
@@ -57,6 +57,7 @@ import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SolrNamedThreadFactory;
+import org.apache.solr.common.util.Utils;
import org.junit.BeforeClass;
public class CloudSolrClientCacheTest extends SolrTestCaseJ4 {
@@ -106,9 +107,12 @@ public class CloudSolrClientCacheTest extends
SolrTestCaseJ4 {
}
}.build()) {
livenodes.addAll(Set.of("192.168.1.108:7574_solr",
"192.168.1.108:8983_solr"));
+ byte[] coll1StateBytes = COLL1_STATE.getBytes(UTF_8);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> stateMap =
+ (Map<String, Object>) Utils.fromJSON(coll1StateBytes, 0,
coll1StateBytes.length);
ClusterState cs =
- ClusterState.createFromJson(
- 1, COLL1_STATE.getBytes(UTF_8), Set.of(), Instant.now(), null);
+ ClusterState.createFromCollectionMap(1, stateMap, Set.of(),
Instant.now(), null);
refs.put(collName, new Ref(collName));
colls.put(collName, cs.getCollectionOrNull(collName));
responses.put(
@@ -346,9 +350,12 @@ public class CloudSolrClientCacheTest extends
SolrTestCaseJ4 {
}
private DocCollection loadCollection(String collection, int version) throws
Exception {
+ byte[] coll1StateBytes = COLL1_STATE.getBytes(UTF_8);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> stateMap =
+ (Map<String, Object>) Utils.fromJSON(coll1StateBytes, 0,
coll1StateBytes.length);
ClusterState state =
- ClusterState.createFromJson(
- version, COLL1_STATE.getBytes(UTF_8), Set.of(), Instant.now(),
null);
+ ClusterState.createFromCollectionMap(version, stateMap, Set.of(),
Instant.now(), null);
return state.getCollectionOrNull(collection);
}