You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/08/12 11:52:47 UTC
[lucene-solr] branch reference_impl_dev updated: @525 Just try to
be efficient, we will get along fine.
This is an automated email from the ASF dual-hosted git repository.
markrmiller pushed a commit to branch reference_impl_dev
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/reference_impl_dev by this push:
new 68747e1 @525 Just try to be efficient, we will get along fine.
68747e1 is described below
commit 68747e10e98ef4ac869fe0045e70be7eaee55e68
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Wed Aug 12 06:52:29 2020 -0500
@525 Just try to be efficient, we will get along fine.
---
.../java/org/apache/solr/core/SolrXmlConfig.java | 46 +-
.../java/org/apache/solr/core/XmlConfigFile.java | 537 +++++++++------------
.../apache/solr/servlet/SolrDispatchFilter.java | 3 +-
.../solr/client/solrj/impl/Http2SolrClient.java | 2 +-
.../apache/solr/common/util/ValidatingJsonMap.java | 3 +-
5 files changed, 244 insertions(+), 347 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
index 59432d9..b9a53d2 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
@@ -150,7 +150,7 @@ public class SolrXmlConfig {
}
try (InputStream inputStream = Files.newInputStream(configFile)) {
- return fromInputStream(solrHome, inputStream, substituteProps);
+ return fromInputStream(solrHome, inputStream, substituteProps, false, Files.size(configFile));
} catch (SolrException exc) {
throw exc;
} catch (Exception exc) {
@@ -172,15 +172,23 @@ public class SolrXmlConfig {
return fromInputStream(solrHome, is, substituteProps, false);
}
- public static NodeConfig fromInputStream(Path solrHome, InputStream is, Properties substituteProps, boolean fromZookeeper) {
+ public static NodeConfig fromInputStream(Path solrHome, InputStream is, Properties substituteProps, boolean fromZookeeper, long size) {
SolrResourceLoader loader = new SolrResourceLoader(solrHome);
if (substituteProps == null) {
substituteProps = new Properties();
}
try {
- byte[] buf = IOUtils.toByteArray(is);
+ byte[] buf;
+
+ if (size != -1) {
+ buf = IOUtils.toByteArray(is, size);
+ } else {
+ buf = IOUtils.toByteArray(is);
+ }
+
try (ByteArrayInputStream dup = new ByteArrayInputStream(buf)) {
- XmlConfigFile config = new XmlConfigFile(loader, null, new InputSource(dup), null, substituteProps);
+ XmlConfigFile config = new XmlConfigFile(loader, null,
+ new InputSource(dup), null, substituteProps);
return fromConfig(solrHome, config, fromZookeeper);
}
} catch (SolrException exc) {
@@ -192,28 +200,8 @@ public class SolrXmlConfig {
}
}
-
- public static NodeConfig fromInputStream(Path solrHome, ByteBuffer buffer, Properties substituteProps) {
- return fromInputStream(solrHome, buffer, substituteProps, false);
- }
-
- public static NodeConfig fromInputStream(Path solrHome, ByteBuffer buffer, Properties substituteProps, boolean fromZookeeper) {
- SolrResourceLoader loader = new SolrResourceLoader(solrHome);
- if (substituteProps == null) {
- substituteProps = new Properties();
- }
- try {
-
- XmlConfigFile config = new XmlConfigFile(loader, null, buffer, null, substituteProps);
- return fromConfig(solrHome, config, fromZookeeper);
-
- } catch (SolrException exc) {
- log.error("Exception reading config", exc);
- throw exc;
- } catch (Exception e) {
- ParWork.propegateInterrupt(e);
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
- }
+ private static NodeConfig fromInputStream(Path solrHome, InputStream inputStream, Properties substituteProps, boolean fromZookeeper) {
+ return fromInputStream(solrHome, inputStream, substituteProps, fromZookeeper, -1);
}
public static NodeConfig fromSolrHome(Path solrHome, Properties substituteProps) {
@@ -221,7 +209,7 @@ public class SolrXmlConfig {
}
private static void checkForIllegalConfig(XmlConfigFile config) {
- // woah! it's best if we don't do this - resource killer
+ // woah! it's best if we don't do this - resource killer - note: perhaps not as bad now that xml is more efficient?
// failIfFound(config, "solr/@coreLoadThreads");
// failIfFound(config, "solr/@persistent");
// failIfFound(config, "solr/@sharedLib");
@@ -586,7 +574,7 @@ public class SolrXmlConfig {
MBeanServer mBeanServer = JmxUtil.findFirstMBeanServer();
if (mBeanServer != null && !hasJmxReporter && !Boolean.getBoolean("solr.disableJmxReporter")) {
log.info("MBean server found: {}, but no JMX reporters were configured - adding default JMX reporter.", mBeanServer);
- Map<String,Object> attributes = new HashMap<>();
+ Map<String,Object> attributes = new HashMap<>(2);
attributes.put("name", "default");
attributes.put("class", SolrJmxReporter.class.getName());
PluginInfo defaultPlugin = new PluginInfo("reporter", attributes);
@@ -600,7 +588,7 @@ public class SolrXmlConfig {
if (nodes == null || nodes.getLength() == 0) {
return NodeConfig.NodeConfigBuilder.DEFAULT_HIDDEN_SYS_PROPS;
}
- Set<String> props = new HashSet<>();
+ Set<String> props = new HashSet<>(nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
String prop = DOMUtil.getText(nodes.item(i));
if (prop != null && !prop.trim().isEmpty()) {
diff --git a/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java b/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java
index 1256cfa..a36572c 100644
--- a/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java
+++ b/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java
@@ -96,7 +96,7 @@ public class XmlConfigFile { // formerly simply "Config"
public static final Transformer tx = tfactory.newTransformer();
private final Document doc;
- //private final Document origDoc; // with unsubstituted properties
+
private final String prefix;
private final String name;
private final SolrResourceLoader loader;
@@ -141,8 +141,7 @@ public class XmlConfigFile { // formerly simply "Config"
* @param substituteProps optional property substitution
*/
public XmlConfigFile(SolrResourceLoader loader, String name, InputSource is, String prefix, Properties substituteProps)
- throws ParserConfigurationException, IOException, SAXException,
- XMLStreamException {
+ throws IOException, SAXException {
if( loader == null ) {
loader = new SolrResourceLoader(SolrPaths.locateSolrHome());
}
@@ -163,9 +162,7 @@ public class XmlConfigFile { // formerly simply "Config"
is.setSystemId(SystemIdResolver.createSystemIdFromResourceName(name));
}
-
try {
-
DocumentBuilderImpl b = new DocumentBuilderImpl();
if (is.getSystemId() != null) {
@@ -192,369 +189,279 @@ public class XmlConfigFile { // formerly simply "Config"
DOMUtil.substituteProperties(doc, substituteProperties);
}
}
-
- public XmlConfigFile(SolrResourceLoader loader, String name, ByteBuffer buffer, String prefix, Properties substituteProps) throws ParserConfigurationException, IOException, SAXException
- {
- if( loader == null ) {
- loader = new SolrResourceLoader(SolrPaths.locateSolrHome());
+ private static Document copyDoc (Document doc) throws TransformerException {
+ DOMSource source = new DOMSource(doc);
+ DOMResult result = new DOMResult();
+ tx.transform(source, result);
+ return (Document) result.getNode();
}
- this.loader = loader;
- this.name = name;
- this.prefix = (prefix != null && !prefix.endsWith("/"))? prefix + '/' : prefix;
- if (buffer == null) {
- if (name == null || name.length() == 0) {
- throw new IllegalArgumentException("Null or empty name:" + name);
- }
- InputStream in = loader.openResource(name);
- if (in instanceof ZkSolrResourceLoader.ZkByteArrayInputStream) {
- zkVersion = ((ZkSolrResourceLoader.ZkByteArrayInputStream) in).getStat().getVersion();
- log.debug("loaded config {} with version {} ",name,zkVersion);
+ /*
+ * Assert that assertCondition is true.
+ * If not, prints reason as log warning.
+ * If failCondition is true, then throw exception instead of warning
+ */
+ public static void assertWarnOrFail (String reason,boolean assertCondition,
+ boolean failCondition){
+ if (assertCondition) {
+ return;
+ } else if (failCondition) {
+ throw new SolrException(SolrException.ErrorCode.FORBIDDEN, reason);
+ } else {
+ log.warn(reason);
}
- // is = new InputSource(in);
- // is.setSystemId(SystemIdResolver.createSystemIdFromResourceName(name));
}
- // try {
- // DOMWriterImpl writer = new DOMWriterImpl();
- // } catch (XMLStreamException e) {
- // e.printStackTrace();
- // }
-
- AsyncXMLStreamReader asyncReader = null;
- try {
-
- InputFactoryImpl factory = new InputFactoryImpl();
- factory.configureForSpeed();
- factory.setXMLResolver(loader.getSysIdResolver().asXMLResolver());
- factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
- asyncReader = factory.createAsyncFor(buffer);
-// asyncReader.getConfig().setActualEncoding("UTF-8");
-// asyncReader.getConfig().setXmlEncoding("UTF-8");
-// asyncReader.getConfig().setActualEncoding("UTF-8");
-// asyncReader.getConfig().setIllegalCharHandler(new IllegalCharHandler() {
-// @Override
-// public char convertIllegalChar(int invalidChar) throws WFCException {
-// return 0;
-// }
-// });
-
- } catch (XMLStreamException e) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
- }
- final AsyncByteBufferFeeder feeder = (AsyncByteBufferFeeder) asyncReader.getInputFeeder();
- int type = 0;
-
- do {
- // May need to feed multiple "segments"
- while (true) {
- try {
- if (!((type = asyncReader.next()) == AsyncXMLStreamReader.EVENT_INCOMPLETE))
- break;
- } catch (XMLStreamException e) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
- }
-// if (feeder.needMoreInput()) {
-// try {
-// feeder.feedInput(buffer);
-// } catch (XMLStreamException e) {
-// throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
-// }
-// }
-// if (!buffer.hasRemaining()) { // to indicate end-of-content (important for error handling)
-// feeder.endOfInput();
-// }
- }
- // and once we have full event, we just dump out event type (for now)
- System.out.println("Got event of type: "+type);
- // could also just copy event as is, using Stax, or do any other normal non-blocking handling:
- // xmlStreamWriter.copyEventFromReader(asyncReader, false);
- } while (type != END_DOCUMENT);
-
- Source src=new StAXSource(asyncReader);
- DOMResult dst=new DOMResult();
- try {
- tfactory.newTransformer().transform(src, dst);
- } catch (TransformerException e) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
- }
- doc = (Document) dst.getNode(); //
- try {
- asyncReader.close();
- } catch (XMLStreamException e) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
- }
-
- this.substituteProperties = substituteProps;
- if (substituteProps != null) {
- DOMUtil.substituteProperties(doc, substituteProperties);
+ /** Returns non-null props to substitute. Param is the base/default set, also non-null. */
+ protected Properties getSubstituteProperties () {
+ return this.substituteProperties;
}
- }
- private static Document copyDoc(Document doc) throws TransformerException {
- DOMSource source = new DOMSource(doc);
- DOMResult result = new DOMResult();
- tx.transform(source, result);
- return (Document) result.getNode();
- }
-
- /*
- * Assert that assertCondition is true.
- * If not, prints reason as log warning.
- * If failCondition is true, then throw exception instead of warning
+ /**
+ * @since solr 1.3
*/
- public static void assertWarnOrFail(String reason, boolean assertCondition, boolean failCondition) {
- if (assertCondition) {
- return;
- } else if (failCondition) {
- throw new SolrException(SolrException.ErrorCode.FORBIDDEN, reason);
- } else {
- log.warn(reason);
+ public SolrResourceLoader getResourceLoader () {
+ return loader;
}
- }
- /** Returns non-null props to substitute. Param is the base/default set, also non-null. */
- protected Properties getSubstituteProperties() {
- return this.substituteProperties;
- }
+ /**
+ * @since solr 1.3
+ */
+ public String getResourceName () {
+ return name;
+ }
- /**
- * @since solr 1.3
- */
- public SolrResourceLoader getResourceLoader()
- {
- return loader;
- }
+ public String getName () {
+ return name;
+ }
- /**
- * @since solr 1.3
- */
- public String getResourceName() {
- return name;
- }
+ public Document getDocument () {
+ return doc;
+ }
- public String getName() {
- return name;
- }
-
- public Document getDocument() {
- return doc;
- }
+ public XPath getXPath () {
+ return IndexSchema.getXpath();
+ }
- public XPath getXPath() {
- return IndexSchema.getXpath();
- }
+ private String normalize (String path){
+ return (prefix == null || path.startsWith("/")) ? path : prefix + path;
+ }
- private String normalize(String path) {
- return (prefix==null || path.startsWith("/")) ? path : prefix+path;
- }
-
- public Object evaluate(String path, QName type) {
- try {
- String xstr=normalize(path);
+ public Object evaluate (String path, QName type){
+ try {
+ String xstr = normalize(path);
- // TODO: instead of prepending /prefix/, we could do the search rooted at /prefix...
- Object o = IndexSchema.getXpath().evaluate(xstr, doc, type);
- return o;
+ // TODO: instead of prepending /prefix/, we could do the search rooted at /prefix...
+ Object o = IndexSchema.getXpath().evaluate(xstr, doc, type);
+ return o;
- } catch (XPathExpressionException e) {
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + path +" for " + name,e);
+ } catch (XPathExpressionException e) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Error in xpath:" + path + " for " + name, e);
+ }
}
- }
- public Node getNode(String path, boolean errifMissing) {
- return getNode(path, doc, errifMissing);
- }
+ public Node getNode (String path,boolean errifMissing){
+ return getNode(path, doc, errifMissing);
+ }
- public Node getNode(String path, Document doc, boolean errIfMissing) {
- String xstr = normalize(path);
+ public Node getNode (String path, Document doc,boolean errIfMissing){
+ String xstr = normalize(path);
- try {
- NodeList nodes = (NodeList)IndexSchema.getXpath().evaluate(xstr, doc,
- XPathConstants.NODESET);
- if (nodes==null || 0 == nodes.getLength() ) {
- if (errIfMissing) {
- throw new RuntimeException(name + " missing "+path);
- } else {
- log.trace("{} missing optional {}", name, path);
- return null;
+ try {
+ NodeList nodes = (NodeList) IndexSchema.getXpath()
+ .evaluate(xstr, doc, XPathConstants.NODESET);
+ if (nodes == null || 0 == nodes.getLength()) {
+ if (errIfMissing) {
+ throw new RuntimeException(name + " missing " + path);
+ } else {
+ log.trace("{} missing optional {}", name, path);
+ return null;
+ }
}
+ if (1 < nodes.getLength()) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ name + " contains more than one value for config path: " + path);
+ }
+ Node nd = nodes.item(0);
+ log.trace("{}:{}={}", name, path, nd);
+ return nd;
+
+ } catch (XPathExpressionException e) {
+ SolrException.log(log, "Error in xpath", e);
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Error in xpath:" + xstr + " for " + name, e);
+ } catch (SolrException e) {
+ throw (e);
+ } catch (Exception e) {
+ ParWork.propegateInterrupt(e);
+ SolrException.log(log, "Error in xpath", e);
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Error in xpath:" + xstr + " for " + name, e);
}
- if ( 1 < nodes.getLength() ) {
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
- name + " contains more than one value for config path: " + path);
- }
- Node nd = nodes.item(0);
- log.trace("{}:{}={}", name, path, nd);
- return nd;
-
- } catch (XPathExpressionException e) {
- SolrException.log(log,"Error in xpath",e);
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr + " for " + name,e);
- } catch (SolrException e) {
- throw(e);
- } catch (Exception e) {
- ParWork.propegateInterrupt(e);
- SolrException.log(log,"Error in xpath",e);
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr+ " for " + name,e);
}
- }
- public NodeList getNodeList(String path, boolean errIfMissing) {
- String xstr = normalize(path);
+ public NodeList getNodeList (String path,boolean errIfMissing){
+ String xstr = normalize(path);
- try {
- NodeList nodeList = (NodeList) IndexSchema.getXpath().evaluate(xstr, doc, XPathConstants.NODESET);
-
- if (null == nodeList) {
- if (errIfMissing) {
- throw new RuntimeException(name + " missing "+path);
- } else {
- log.trace("{} missing optional {}", name, path);
- return null;
+ try {
+ NodeList nodeList = (NodeList) IndexSchema.getXpath()
+ .evaluate(xstr, doc, XPathConstants.NODESET);
+
+ if (null == nodeList) {
+ if (errIfMissing) {
+ throw new RuntimeException(name + " missing " + path);
+ } else {
+ log.trace("{} missing optional {}", name, path);
+ return null;
+ }
}
- }
- log.trace("{}:{}={}", name, path, nodeList);
- return nodeList;
-
- } catch (XPathExpressionException e) {
- SolrException.log(log,"Error in xpath",e);
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr + " for " + name,e);
- } catch (SolrException e) {
- throw(e);
- } catch (Exception e) {
- ParWork.propegateInterrupt(e);
- SolrException.log(log,"Error in xpath",e);
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr+ " for " + name,e);
+ log.trace("{}:{}={}", name, path, nodeList);
+ return nodeList;
+
+ } catch (XPathExpressionException e) {
+ SolrException.log(log, "Error in xpath", e);
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Error in xpath:" + xstr + " for " + name, e);
+ } catch (SolrException e) {
+ throw (e);
+ } catch (Exception e) {
+ ParWork.propegateInterrupt(e);
+ SolrException.log(log, "Error in xpath", e);
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Error in xpath:" + xstr + " for " + name, e);
+ }
}
- }
- /**
- * Returns the set of attributes on the given element that are not among the given knownAttributes,
- * or null if all attributes are known.
- */
- public Set<String> getUnknownAttributes(Element element, String... knownAttributes) {
- Set<String> knownAttributeSet = new HashSet<>(Arrays.asList(knownAttributes));
- Set<String> unknownAttributeSet = null;
- NamedNodeMap attributes = element.getAttributes();
- for (int i = 0 ; i < attributes.getLength() ; ++i) {
- final String attributeName = attributes.item(i).getNodeName();
- if ( ! knownAttributeSet.contains(attributeName)) {
- if (null == unknownAttributeSet) {
- unknownAttributeSet = new HashSet<>();
+ /**
+ * Returns the set of attributes on the given element that are not among the given knownAttributes,
+ * or null if all attributes are known.
+ */
+ public Set<String> getUnknownAttributes (Element element, String...
+ knownAttributes){
+ Set<String> knownAttributeSet = new HashSet<>(
+ Arrays.asList(knownAttributes));
+ Set<String> unknownAttributeSet = null;
+ NamedNodeMap attributes = element.getAttributes();
+ for (int i = 0; i < attributes.getLength(); ++i) {
+ final String attributeName = attributes.item(i).getNodeName();
+ if (!knownAttributeSet.contains(attributeName)) {
+ if (null == unknownAttributeSet) {
+ unknownAttributeSet = new HashSet<>();
+ }
+ unknownAttributeSet.add(attributeName);
}
- unknownAttributeSet.add(attributeName);
}
+ return unknownAttributeSet;
}
- return unknownAttributeSet;
- }
- /**
- * Logs an error and throws an exception if any of the element(s) at the given elementXpath
- * contains an attribute name that is not among knownAttributes.
- */
- public void complainAboutUnknownAttributes(String elementXpath, String... knownAttributes) {
- SortedMap<String,SortedSet<String>> problems = new TreeMap<>();
- NodeList nodeList = getNodeList(elementXpath, false);
- for (int i = 0 ; i < nodeList.getLength() ; ++i) {
- Element element = (Element)nodeList.item(i);
- Set<String> unknownAttributes = getUnknownAttributes(element, knownAttributes);
- if (null != unknownAttributes) {
- String elementName = element.getNodeName();
- SortedSet<String> allUnknownAttributes = problems.get(elementName);
- if (null == allUnknownAttributes) {
- allUnknownAttributes = new TreeSet<>();
- problems.put(elementName, allUnknownAttributes);
+ /**
+ * Logs an error and throws an exception if any of the element(s) at the given elementXpath
+ * contains an attribute name that is not among knownAttributes.
+ */
+ public void complainAboutUnknownAttributes (String elementXpath, String...
+ knownAttributes){
+ SortedMap<String,SortedSet<String>> problems = new TreeMap<>();
+ NodeList nodeList = getNodeList(elementXpath, false);
+ for (int i = 0; i < nodeList.getLength(); ++i) {
+ Element element = (Element) nodeList.item(i);
+ Set<String> unknownAttributes = getUnknownAttributes(element,
+ knownAttributes);
+ if (null != unknownAttributes) {
+ String elementName = element.getNodeName();
+ SortedSet<String> allUnknownAttributes = problems.get(elementName);
+ if (null == allUnknownAttributes) {
+ allUnknownAttributes = new TreeSet<>();
+ problems.put(elementName, allUnknownAttributes);
+ }
+ allUnknownAttributes.addAll(unknownAttributes);
}
- allUnknownAttributes.addAll(unknownAttributes);
}
- }
- if (problems.size() > 0) {
- StringBuilder message = new StringBuilder();
- for (Map.Entry<String,SortedSet<String>> entry : problems.entrySet()) {
- if (message.length() > 0) {
- message.append(", ");
- }
- message.append('<');
- message.append(entry.getKey());
- for (String attributeName : entry.getValue()) {
- message.append(' ');
- message.append(attributeName);
- message.append("=\"...\"");
+ if (problems.size() > 0) {
+ StringBuilder message = new StringBuilder();
+ for (Map.Entry<String,SortedSet<String>> entry : problems.entrySet()) {
+ if (message.length() > 0) {
+ message.append(", ");
+ }
+ message.append('<');
+ message.append(entry.getKey());
+ for (String attributeName : entry.getValue()) {
+ message.append(' ');
+ message.append(attributeName);
+ message.append("=\"...\"");
+ }
+ message.append('>');
}
- message.append('>');
+ message.insert(0, "Unknown attribute(s) on element(s): ");
+ String msg = message.toString();
+ SolrException.log(log, msg);
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg);
}
- message.insert(0, "Unknown attribute(s) on element(s): ");
- String msg = message.toString();
- SolrException.log(log, msg);
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg);
}
- }
- public String getVal(String path, boolean errIfMissing) {
- Node nd = getNode(path,errIfMissing);
- if (nd==null) return null;
+ public String getVal (String path,boolean errIfMissing){
+ Node nd = getNode(path, errIfMissing);
+ if (nd == null) return null;
- String txt = DOMUtil.getText(nd);
+ String txt = DOMUtil.getText(nd);
- log.debug("{} {}={}", name, path, txt);
- return txt;
- }
+ log.debug("{} {}={}", name, path, txt);
+ return txt;
+ }
+ public String get (String path){
+ return getVal(path, true);
+ }
- public String get(String path) {
- return getVal(path,true);
- }
+ public String get (String path, String def){
+ String val = getVal(path, false);
+ if (val == null || val.length() == 0) {
+ return def;
+ }
+ return val;
+ }
- public String get(String path, String def) {
- String val = getVal(path, false);
- if (val == null || val.length() == 0) {
- return def;
+ public int getInt (String path){
+ return Integer.parseInt(getVal(path, true));
}
- return val;
- }
- public int getInt(String path) {
- return Integer.parseInt(getVal(path, true));
- }
+ public int getInt (String path,int def){
+ String val = getVal(path, false);
+ return val != null ? Integer.parseInt(val) : def;
+ }
- public int getInt(String path, int def) {
- String val = getVal(path, false);
- return val!=null ? Integer.parseInt(val) : def;
- }
+ public boolean getBool (String path){
+ return Boolean.parseBoolean(getVal(path, true));
+ }
- public boolean getBool(String path) {
- return Boolean.parseBoolean(getVal(path, true));
- }
+ public boolean getBool (String path,boolean def){
+ String val = getVal(path, false);
+ return val != null ? Boolean.parseBoolean(val) : def;
+ }
- public boolean getBool(String path, boolean def) {
- String val = getVal(path, false);
- return val!=null ? Boolean.parseBoolean(val) : def;
- }
+ public float getFloat (String path){
+ return Float.parseFloat(getVal(path, true));
+ }
- public float getFloat(String path) {
- return Float.parseFloat(getVal(path, true));
- }
+ public float getFloat (String path,float def){
+ String val = getVal(path, false);
+ return val != null ? Float.parseFloat(val) : def;
+ }
- public float getFloat(String path, float def) {
- String val = getVal(path, false);
- return val!=null ? Float.parseFloat(val) : def;
- }
+ public double getDouble (String path){
+ return Double.parseDouble(getVal(path, true));
+ }
- public double getDouble(String path){
- return Double.parseDouble(getVal(path, true));
- }
+ public double getDouble (String path,double def){
+ String val = getVal(path, false);
+ return val != null ? Double.parseDouble(val) : def;
+ }
- public double getDouble(String path, double def) {
- String val = getVal(path, false);
- return val != null ? Double.parseDouble(val) : def;
- }
+ /**If this config is loaded from zk the version is relevant other wise -1 is returned
+ */
+ public int getZnodeVersion () {
+ return zkVersion;
+ }
- /**If this config is loaded from zk the version is relevant other wise -1 is returned
- */
- public int getZnodeVersion(){
- return zkVersion;
}
-
-}
diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
index 448ce8b..64a2664 100644
--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
@@ -321,7 +321,8 @@ public class SolrDispatchFilter extends BaseSolrFilter {
log.error("Found solr.xml in ZooKeeper with no data in it");
throw new SolrException(ErrorCode.SERVER_ERROR, "Found solr.xml in ZooKeeper with no data in it");
}
- return SolrXmlConfig.fromInputStream(solrHome, new ByteArrayInputStream(data), nodeProperties, true);
+ return SolrXmlConfig.fromInputStream(solrHome, new ByteArrayInputStream(data), nodeProperties, true,
+ data.length);
} catch (KeeperException.NoNodeException e) {
// okay
} catch (Exception e) {
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
index f7a3a1a..51eadac 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
@@ -635,7 +635,7 @@ public class Http2SolrClient extends SolrClient {
for (Map.Entry<String,String> entry : headers.entrySet()) {
req.header(entry.getKey(), entry.getValue());
}
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
contentWriter.write(baos);
//TODO reduce memory usage
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/ValidatingJsonMap.java b/solr/solrj/src/java/org/apache/solr/common/util/ValidatingJsonMap.java
index 3272688..ef370b5 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/ValidatingJsonMap.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/ValidatingJsonMap.java
@@ -17,6 +17,7 @@
package org.apache.solr.common.util;
+import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -333,7 +334,7 @@ public class ValidatingJsonMap implements Map<String, Object>, NavigableObject {
throw new RuntimeException("invalid API spec: " + resourceName);
}
ValidatingJsonMap map = null;
- try (InputStream is = resource.openStream()) {
+ try (InputStream is = new BufferedInputStream(resource.openStream())) {
try {
map = fromJSON(is, includeLocation);
} catch (Exception e) {