-
Notifications
You must be signed in to change notification settings - Fork 800
SOLR-17600 Replaces MapSerializable with MapWriter #4011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
629b684
3645172
02c3ef6
a37c1d5
8b53f86
5224a46
e671468
32da08a
234d79b
1ac31a6
d3d763d
409136c
0e46609
4fb8c2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| title: SOLR 17600 - Replace MapSerializable with MapWriter | ||
| type: changed | ||
| authors: | ||
| - name: Ivan Šarić | ||
| links: | ||
| - name: SOLR-17600 | ||
| url: https://issues.apache.org/jira/browse/SOLR-17600 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,6 @@ | |
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import java.lang.invoke.MethodHandles; | ||
| import java.util.HashMap; | ||
| import java.util.Locale; | ||
| import org.apache.solr.common.SolrException; | ||
| import org.apache.solr.common.cloud.ClusterState; | ||
|
|
@@ -34,6 +33,7 @@ | |
| import org.apache.solr.common.params.CoreAdminParams; | ||
| import org.apache.solr.common.params.ModifiableSolrParams; | ||
| import org.apache.solr.common.util.NamedList; | ||
| import org.apache.solr.common.util.SimpleOrderedMap; | ||
| import org.apache.solr.common.util.StrUtils; | ||
| import org.apache.solr.handler.component.ShardHandler; | ||
| import org.apache.solr.jersey.JacksonReflectMapWriter; | ||
|
|
@@ -80,8 +80,7 @@ public void call(ClusterState state, ZkNodeProps message, NamedList<Object> resu | |
| final ModifiableSolrParams coreApiParams = new ModifiableSolrParams(); | ||
| coreApiParams.set( | ||
| CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.INSTALLCOREDATA.toString()); | ||
| typedMessage.toMap(new HashMap<>()).forEach((k, v) -> coreApiParams.set(k, v.toString())); | ||
|
|
||
| new SimpleOrderedMap<>(typedMessage).forEach((k, v) -> coreApiParams.set(k, v.toString())); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // Send the core-admin request to each replica in the slice | ||
| final ShardHandler shardHandler = ccc.newShardHandler(); | ||
| shardRequestTracker.sliceCmd(clusterState, coreApiParams, null, installSlice, shardHandler); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,20 +23,22 @@ | |
| import static org.apache.solr.schema.FieldType.CLASS_NAME; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.solr.common.ConfigNode; | ||
| import org.apache.solr.common.MapSerializable; | ||
| import org.apache.solr.common.MapWriter; | ||
| import org.apache.solr.common.util.NamedList; | ||
| import org.apache.solr.common.util.SimpleOrderedMap; | ||
| import org.apache.solr.util.DOMConfigNode; | ||
| import org.w3c.dom.Node; | ||
|
|
||
| /** An Object which represents a Plugin of any type */ | ||
| public class PluginInfo implements MapSerializable { | ||
| public class PluginInfo implements MapWriter { | ||
| public final String name, className, type, pkgName; | ||
| public final ClassName cName; | ||
| public final NamedList<Object> initArgs; | ||
|
|
@@ -193,27 +195,19 @@ public PluginInfo getChild(String type) { | |
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings({"unchecked", "rawtypes"}) | ||
| public Map<String, Object> toMap(Map<String, Object> map) { | ||
| map.putAll(attributes); | ||
| Map m = map; | ||
| if (initArgs != null) m.putAll(initArgs.asMap(3)); | ||
| if (children != null) { | ||
| for (PluginInfo child : children) { | ||
| Object old = m.get(child.name); | ||
| if (old == null) { | ||
| m.put(child.name, child.toMap(new LinkedHashMap<>())); | ||
| } else if (old instanceof List list) { | ||
| list.add(child.toMap(new LinkedHashMap<>())); | ||
| } else { | ||
| ArrayList l = new ArrayList(); | ||
| l.add(old); | ||
| l.add(child.toMap(new LinkedHashMap<>())); | ||
| m.put(child.name, l); | ||
| } | ||
| } | ||
| @SuppressWarnings("unchecked") | ||
| public void writeMap(EntryWriter ew) throws IOException { | ||
| new NamedList<>(attributes).writeMap(ew); | ||
| if (initArgs != null) { | ||
| new SimpleOrderedMap<>(initArgs).writeMap(ew); | ||
| } | ||
|
Comment on lines
+200
to
+203
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not create a new Map just to ultimately write it! |
||
| if (children == null || children.isEmpty()) { | ||
| return; | ||
| } | ||
|
|
||
| for (PluginInfo child : children) { | ||
| child.writeMap(ew); | ||
| } | ||
| return m; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,10 +25,11 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.solr.cloud.ZkSolrResourceLoader; | ||
| import org.apache.solr.common.MapSerializable; | ||
| import org.apache.solr.common.MapWriter; | ||
| import org.apache.solr.common.SolrException; | ||
| import org.apache.solr.common.cloud.SolrZkClient; | ||
| import org.apache.solr.common.params.MultiMapSolrParams; | ||
| import org.apache.solr.common.util.SimpleOrderedMap; | ||
| import org.apache.solr.common.util.Utils; | ||
| import org.apache.zookeeper.KeeperException; | ||
| import org.apache.zookeeper.data.Stat; | ||
|
|
@@ -39,7 +40,7 @@ | |
| * The class encapsulates the request time parameters . This is immutable and any changes performed | ||
| * returns a copy of the Object with the changed values | ||
| */ | ||
| public class RequestParams implements MapSerializable { | ||
| public class RequestParams implements MapWriter { | ||
| private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
|
||
| private final Map<String, Object> data; | ||
|
|
@@ -113,8 +114,9 @@ public int getZnodeVersion() { | |
| } | ||
|
|
||
| @Override | ||
| public Map<String, Object> toMap(Map<String, Object> map) { | ||
| return getMapWithVersion(data, znodeVersion); | ||
| public void writeMap(EntryWriter ew) throws IOException { | ||
| ew.put(ConfigOverlay.ZNODEVER, znodeVersion); | ||
| data.forEach(ew::putNoEx); | ||
| } | ||
|
|
||
| public static Map<String, Object> getMapWithVersion(Map<String, Object> data, int znodeVersion) { | ||
|
|
@@ -130,7 +132,9 @@ public RequestParams setParams(String name, ParamSet paramSet) { | |
| Map p = (Map) deepCopy.get(NAME); | ||
| if (p == null) deepCopy.put(NAME, p = new LinkedHashMap<>()); | ||
| if (paramSet == null) p.remove(name); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this if should have { } to match the else?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that in Java conditionals should always use curly braces for clarity. This is the existing code that was not changed in my PR. I am hesitant to change it as I am not sure if there is a convention regarding this practice in the project. |
||
| else p.put(name, paramSet.toMap(new LinkedHashMap<>())); | ||
| else { | ||
| p.put(name, new SimpleOrderedMap<>(paramSet)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one's fine |
||
| } | ||
| return new RequestParams(deepCopy, znodeVersion); | ||
| } | ||
|
|
||
|
|
@@ -208,7 +212,7 @@ public byte[] toByteArray() { | |
| public static final String INVARIANTS = "_invariants_"; | ||
|
|
||
| @SuppressWarnings({"unchecked"}) | ||
| public static class ParamSet implements MapSerializable { | ||
| public static class ParamSet implements MapWriter { | ||
| private final Map<String, Object> defaults, appends, invariants; | ||
| Map<String, VersionedParams> paramsMap; | ||
| public final Map<String, Long> meta; | ||
|
|
@@ -235,12 +239,11 @@ public Long getVersion() { | |
| } | ||
|
|
||
| @Override | ||
| public Map<String, Object> toMap(Map<String, Object> result) { | ||
| result.putAll(defaults); | ||
| if (appends != null) result.put(APPENDS, appends); | ||
| if (invariants != null) result.put(INVARIANTS, invariants); | ||
| if (meta != null) result.put("", meta); | ||
| return result; | ||
| public void writeMap(EntryWriter ew) throws IOException { | ||
| defaults.forEach(ew::putNoEx); | ||
| if (appends != null) ew.put(APPENDS, appends); | ||
| if (invariants != null) ew.put(INVARIANTS, invariants); | ||
| if (meta != null) ew.put("", meta); | ||
| } | ||
|
|
||
| @SuppressWarnings({"rawtypes"}) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, avoid NamedList/SimpleOrderedMap
How about
p.initArgs.asMap(0)