SOLR-14579: Comment SolrJ 'Utils' generic map functions

This commit is contained in:
Erick Erickson 2020-09-05 09:19:45 -04:00
parent 6c94ca9cb3
commit f71ba62d4a
7 changed files with 19 additions and 41 deletions

View File

@ -239,6 +239,9 @@ Other Changes
* SOLR-14731: Rename @SolrSingleThreaded to @SolrThreadUnsafe, mark DistribPackageStore with the annotation
(marcussorealheis)
* SOLR-14579: Comment SolrJ 'Utils' generic map functions
(Megan Carey and a lot of education from Uwe Schindler via Erick Erickson)
================== 8.6.2 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

View File

@ -151,7 +151,7 @@ public class ContainerPluginsApi {
SolrZkClient zkClient = zkClientSupplier.get();
try {
Map<String, Object> clusterPropsJson = (Map<String, Object>) Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat(), true));
return (Map<String, Object>) clusterPropsJson.computeIfAbsent(PLUGIN, Utils.NEW_LINKED_HASHMAP_FUN);
return (Map<String, Object>) clusterPropsJson.computeIfAbsent(PLUGIN, o -> new LinkedHashMap<>());
} catch (KeeperException.NoNodeException e) {
return new LinkedHashMap<>();
} catch (KeeperException | InterruptedException e) {
@ -165,7 +165,7 @@ public class ContainerPluginsApi {
zkClientSupplier.get().atomicUpdate(ZkStateReader.CLUSTER_PROPS, bytes -> {
Map rawJson = bytes == null ? new LinkedHashMap() :
(Map) Utils.fromJSON(bytes);
Map pluginsModified = modifier.apply((Map) rawJson.computeIfAbsent(PLUGIN, Utils.NEW_LINKED_HASHMAP_FUN));
Map pluginsModified = modifier.apply((Map) rawJson.computeIfAbsent(PLUGIN, o -> new LinkedHashMap<>()));
if (pluginsModified == null) return null;
rawJson.put(PLUGIN, pluginsModified);
return Utils.toJSON(rawJson);

View File

@ -282,15 +282,11 @@ public class PackageAPI {
log.error("Error deserializing packages.json", e);
packages = new Packages();
}
@SuppressWarnings({"rawtypes"})
List list = packages.packages.computeIfAbsent(add.pkg, Utils.NEW_ARRAYLIST_FUN);
for (Object o : list) {
if (o instanceof PkgVersion) {
PkgVersion version = (PkgVersion) o;
if (Objects.equals(version.version, add.version)) {
payload.addError("Version '" + add.version + "' exists already");
return null;
}
List<PkgVersion> list = packages.packages.computeIfAbsent(add.pkg, o -> new ArrayList<>());
for (PkgVersion version : list) {
if (Objects.equals(version.version, add.version)) {
payload.addError("Version '" + add.version + "' exists already");
return null;
}
}
list.add(new PkgVersion(add));

View File

@ -42,7 +42,6 @@ import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.ShardParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.Utils;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.ShardRequest;
import org.apache.solr.handler.component.ShardResponse;
@ -130,7 +129,7 @@ public class ExactStatsCache extends StatsCache {
protected void addToPerShardColStats(SolrQueryRequest req, String shard, Map<String,CollectionStats> colStats) {
@SuppressWarnings({"unchecked"})
Map<String,Map<String,CollectionStats>> perShardColStats = (Map<String,Map<String,CollectionStats>>) req.getContext().computeIfAbsent(PER_SHARD_COL_STATS, Utils.NEW_HASHMAP_FUN);
Map<String,Map<String,CollectionStats>> perShardColStats = (Map<String,Map<String,CollectionStats>>) req.getContext().computeIfAbsent(PER_SHARD_COL_STATS, o -> new HashMap<>());
perShardColStats.put(shard, colStats);
}
@ -146,7 +145,7 @@ public class ExactStatsCache extends StatsCache {
Map<String,TermStats> termStats = StatsUtil.termStatsMapFromString(termStatsString);
if (termStats != null) {
@SuppressWarnings({"unchecked"})
Map<String,Map<String,TermStats>> perShardTermStats = (Map<String,Map<String,TermStats>>) req.getContext().computeIfAbsent(PER_SHARD_TERM_STATS, Utils.NEW_HASHMAP_FUN);
Map<String,Map<String,TermStats>> perShardTermStats = (Map<String,Map<String,TermStats>>) req.getContext().computeIfAbsent(PER_SHARD_TERM_STATS, o -> new HashMap<>());
perShardTermStats.put(shard, termStats);
}
}
@ -318,13 +317,13 @@ public class ExactStatsCache extends StatsCache {
protected void addToGlobalColStats(SolrQueryRequest req,
Entry<String,CollectionStats> e) {
@SuppressWarnings({"unchecked"})
Map<String,CollectionStats> currentGlobalColStats = (Map<String,CollectionStats>) req.getContext().computeIfAbsent(CURRENT_GLOBAL_COL_STATS, Utils.NEW_HASHMAP_FUN);
Map<String,CollectionStats> currentGlobalColStats = (Map<String,CollectionStats>) req.getContext().computeIfAbsent(CURRENT_GLOBAL_COL_STATS, o -> new HashMap<>());
currentGlobalColStats.put(e.getKey(), e.getValue());
}
protected void addToGlobalTermStats(SolrQueryRequest req, Entry<String,TermStats> e) {
@SuppressWarnings({"unchecked"})
Map<String,TermStats> currentGlobalTermStats = (Map<String,TermStats>) req.getContext().computeIfAbsent(CURRENT_GLOBAL_TERM_STATS, Utils.NEW_HASHMAP_FUN);
Map<String,TermStats> currentGlobalTermStats = (Map<String,TermStats>) req.getContext().computeIfAbsent(CURRENT_GLOBAL_TERM_STATS, o -> new HashMap<>());
currentGlobalTermStats.put(e.getKey(), e.getValue());
}

View File

@ -147,9 +147,7 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriter
}
@Override
public Map<String, Map<String, List<Replica>>> getReplicaInfo(String node, Collection<String> keys) {
@SuppressWarnings({"unchecked"})
Map<String, Map<String, List<Replica>>> result = nodeVsCollectionVsShardVsReplicaInfo.computeIfAbsent(node, Utils.NEW_HASHMAP_FUN);
if (!keys.isEmpty()) {
Map<String, Map<String, List<Replica>>> result = nodeVsCollectionVsShardVsReplicaInfo.computeIfAbsent(node, o -> new HashMap<>()); if (!keys.isEmpty()) {
Map<String, Pair<String, Replica>> metricsKeyVsTagReplica = new HashMap<>();
forEachReplica(result, r -> {
for (String key : keys) {

View File

@ -52,7 +52,6 @@ import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.regex.Matcher;
@ -97,18 +96,6 @@ import static java.util.concurrent.TimeUnit.NANOSECONDS;
public class Utils {
@SuppressWarnings({"rawtypes"})
public static final Function NEW_HASHMAP_FUN = o -> new HashMap<>();
@SuppressWarnings({"rawtypes"})
public static final Function NEW_LINKED_HASHMAP_FUN = o -> new LinkedHashMap<>();
@SuppressWarnings({"rawtypes"})
public static final Function NEW_ATOMICLONG_FUN = o -> new AtomicLong();
@SuppressWarnings({"rawtypes"})
public static final Function NEW_ARRAYLIST_FUN = o -> new ArrayList<>();
@SuppressWarnings({"rawtypes"})
public static final Function NEW_SYNCHRONIZED_ARRAYLIST_FUN = o -> Collections.synchronizedList(new ArrayList<>());
@SuppressWarnings({"rawtypes"})
public static final Function NEW_HASHSET_FUN = o -> new HashSet<>();
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@SuppressWarnings({"rawtypes"})

View File

@ -35,9 +35,6 @@ import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.util.FastJavaBinDecoder.Tag;
import static org.apache.solr.common.util.Utils.NEW_ARRAYLIST_FUN;
import static org.apache.solr.common.util.Utils.NEW_LINKED_HASHMAP_FUN;
public class TestFastJavabinDecoder extends SolrTestCaseJ4 {
public void testTagRead() throws Exception {
@ -96,20 +93,18 @@ public class TestFastJavabinDecoder extends SolrTestCaseJ4 {
assertEquals(Utils.writeJson(m2, new StringWriter(), true).toString(),
Utils.writeJson(fastMap, new StringWriter(), true).toString());
@SuppressWarnings({"unchecked"})
@SuppressWarnings({"unchecked", "rawtypes"})
Object newMap = new FastJavaBinDecoder()
.withInputStream(new FastInputStream(null, baos.getbuf(), 0, baos.size()))
.decode(e -> {
e.listenContainer(new LinkedHashMap<>(), e_ -> {
@SuppressWarnings({"rawtypes"})
Map rootMap = (Map) e_.ctx();
if (e_.type() == DataEntry.Type.ENTRY_ITER) {
e_.listenContainer(rootMap.computeIfAbsent(e_.name(), NEW_ARRAYLIST_FUN),
e_.listenContainer(rootMap.computeIfAbsent(e_.name(), o -> new ArrayList<>()),
FastJavaBinDecoder.getEntryListener());
} else if (e_.type() == DataEntry.Type.KEYVAL_ITER) {
e_.listenContainer(rootMap.computeIfAbsent(e_.name(), NEW_LINKED_HASHMAP_FUN), e1 -> {
@SuppressWarnings({"rawtypes"})
Map m1 = (Map) e1.ctx();
e_.listenContainer(rootMap.computeIfAbsent(e_.name(), o -> new LinkedHashMap<>()), e1 -> {
Map<CharSequence,String> m1 = (Map<CharSequence,String>) e1.ctx();
if ("k1".equals(e1.name())) {
m1.put(e1.name(), e1.val().toString());
}