You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2014/06/18 00:53:20 UTC
svn commit: r1603308 - in /lucene/dev/branches/lucene_solr_4_9: ./ solr/
solr/core/ solr/core/src/java/org/apache/solr/schema/
solr/core/src/test/org/apache/solr/schema/
Author: sarowe
Date: Tue Jun 17 22:53:19 2014
New Revision: 1603308
URL: http://svn.apache.org/r1603308
Log:
SOLR-6164: Copy Fields Schema additions are not distributed to other nodes (merged trunk r1603300 and r1603301)
Added:
lucene/dev/branches/lucene_solr_4_9/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchemaConcurrent.java (props changed)
- copied unchanged from r1603300, lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchemaConcurrent.java
Removed:
lucene/dev/branches/lucene_solr_4_9/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchemaAddField.java
lucene/dev/branches/lucene_solr_4_9/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchemaAddFields.java
lucene/dev/branches/lucene_solr_4_9/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchemaCopyFields.java
Modified:
lucene/dev/branches/lucene_solr_4_9/ (props changed)
lucene/dev/branches/lucene_solr_4_9/solr/ (props changed)
lucene/dev/branches/lucene_solr_4_9/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/lucene_solr_4_9/solr/core/ (props changed)
lucene/dev/branches/lucene_solr_4_9/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
lucene/dev/branches/lucene_solr_4_9/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
Modified: lucene/dev/branches/lucene_solr_4_9/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_9/solr/CHANGES.txt?rev=1603308&r1=1603307&r2=1603308&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_9/solr/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_9/solr/CHANGES.txt Tue Jun 17 22:53:19 2014
@@ -123,6 +123,9 @@ Bug Fixes
* SOLR-6129: DateFormatTransformer doesn't resolve dateTimeFormat. (Aaron LaBella via shalin)
+* SOLR-6164: Copy Fields Schema additions are not distributed to other nodes.
+ (Gregory Chanan via Steve Rowe)
+
Other Changes
---------------------
Modified: lucene/dev/branches/lucene_solr_4_9/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_9/solr/core/src/java/org/apache/solr/schema/IndexSchema.java?rev=1603308&r1=1603307&r2=1603308&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_9/solr/core/src/java/org/apache/solr/schema/IndexSchema.java (original)
+++ lucene/dev/branches/lucene_solr_4_9/solr/core/src/java/org/apache/solr/schema/IndexSchema.java Tue Jun 17 22:53:19 2014
@@ -583,44 +583,7 @@ public class IndexSchema {
// expression = "/schema/copyField";
dynamicCopyFields = new DynamicCopy[] {};
- expression = "//" + COPY_FIELD;
- nodes = (NodeList) xpath.evaluate(expression, document, XPathConstants.NODESET);
-
- for (int i=0; i<nodes.getLength(); i++) {
- node = nodes.item(i);
- NamedNodeMap attrs = node.getAttributes();
-
- String source = DOMUtil.getAttr(attrs, SOURCE, COPY_FIELD + " definition");
- String dest = DOMUtil.getAttr(attrs, DESTINATION, COPY_FIELD + " definition");
- String maxChars = DOMUtil.getAttr(attrs, MAX_CHARS);
- int maxCharsInt = CopyField.UNLIMITED;
- if (maxChars != null) {
- try {
- maxCharsInt = Integer.parseInt(maxChars);
- } catch (NumberFormatException e) {
- log.warn("Couldn't parse " + MAX_CHARS + " attribute for " + COPY_FIELD + " from "
- + source + " to " + dest + " as integer. The whole field will be copied.");
- }
- }
-
- if (dest.equals(uniqueKeyFieldName)) {
- String msg = UNIQUE_KEY + " field ("+uniqueKeyFieldName+
- ") can not be the " + DESTINATION + " of a " + COPY_FIELD + "(" + SOURCE + "=" +source+")";
- log.error(msg);
- throw new SolrException(ErrorCode.SERVER_ERROR, msg);
-
- }
-
- registerCopyField(source, dest, maxCharsInt);
- }
-
- for (Map.Entry<SchemaField, Integer> entry : copyFieldTargetCounts.entrySet()) {
- if (entry.getValue() > 1 && !entry.getKey().multiValued()) {
- log.warn("Field " + entry.getKey().name + " is not multivalued "+
- "and destination for multiple " + COPY_FIELDS + " ("+
- entry.getValue()+")");
- }
- }
+ loadCopyFields(document, xpath);
//Run the callbacks on SchemaAware now that everything else is done
for (SchemaAware aware : schemaAware) {
@@ -739,6 +702,50 @@ public class IndexSchema {
}
/**
+ * Loads the copy fields
+ */
+ protected synchronized void loadCopyFields(Document document, XPath xpath) throws XPathExpressionException {
+ String expression = "//" + COPY_FIELD;
+ NodeList nodes = (NodeList)xpath.evaluate(expression, document, XPathConstants.NODESET);
+
+ for (int i=0; i<nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ NamedNodeMap attrs = node.getAttributes();
+
+ String source = DOMUtil.getAttr(attrs, SOURCE, COPY_FIELD + " definition");
+ String dest = DOMUtil.getAttr(attrs, DESTINATION, COPY_FIELD + " definition");
+ String maxChars = DOMUtil.getAttr(attrs, MAX_CHARS);
+
+ int maxCharsInt = CopyField.UNLIMITED;
+ if (maxChars != null) {
+ try {
+ maxCharsInt = Integer.parseInt(maxChars);
+ } catch (NumberFormatException e) {
+ log.warn("Couldn't parse " + MAX_CHARS + " attribute for " + COPY_FIELD + " from "
+ + source + " to " + dest + " as integer. The whole field will be copied.");
+ }
+ }
+
+ if (dest.equals(uniqueKeyFieldName)) {
+ String msg = UNIQUE_KEY + " field ("+uniqueKeyFieldName+
+ ") can not be the " + DESTINATION + " of a " + COPY_FIELD + "(" + SOURCE + "=" +source+")";
+ log.error(msg);
+ throw new SolrException(ErrorCode.SERVER_ERROR, msg);
+ }
+
+ registerCopyField(source, dest, maxCharsInt);
+ }
+
+ for (Map.Entry<SchemaField, Integer> entry : copyFieldTargetCounts.entrySet()) {
+ if (entry.getValue() > 1 && !entry.getKey().multiValued()) {
+ log.warn("Field " + entry.getKey().name + " is not multivalued "+
+ "and destination for multiple " + COPY_FIELDS + " ("+
+ entry.getValue()+")");
+ }
+ }
+ }
+
+ /**
* Converts a sequence of path steps into a rooted path, by inserting slashes in front of each step.
* @param steps The steps to join with slashes to form a path
* @return a rooted path: a leading slash followed by the given steps joined with slashes
Modified: lucene/dev/branches/lucene_solr_4_9/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_9/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java?rev=1603308&r1=1603307&r2=1603308&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_9/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java (original)
+++ lucene/dev/branches/lucene_solr_4_9/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java Tue Jun 17 22:53:19 2014
@@ -43,6 +43,7 @@ import java.nio.charset.StandardCharsets
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
/** Solr-managed schema - non-user-editable, but can be mutable via internal and external REST API requests. */
@@ -338,6 +339,13 @@ public final class ManagedIndexSchema ex
Document document = schemaConf.getDocument();
final XPath xpath = schemaConf.getXPath();
newSchema.loadFields(document, xpath);
+ // let's completely rebuild the copy fields from the schema in ZK.
+ // create new copyField-related objects so we don't affect the
+ // old schema
+ newSchema.copyFieldsMap = new HashMap<>();
+ newSchema.dynamicCopyFields = null;
+ newSchema.copyFieldTargetCounts = new HashMap<>();
+ newSchema.loadCopyFields(document, xpath);
if (null != uniqueKeyField) {
newSchema.requiredFields.add(uniqueKeyField);
}