SOLR-6141: fix TestBulkSchemaConcurrent; fix field deletion to fail when a dynamic copy field directive has the field as its source; don't attempt to decrement a SchemaField's count in copyFieldTargetCounts if it's not present in the map.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1669055 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Rowe 2015-03-25 06:25:24 +00:00
parent ba99ec8104
commit 9b255d6cc4
2 changed files with 20 additions and 8 deletions

View File

@ -449,9 +449,16 @@ public final class ManagedIndexSchema extends IndexSchema {
for (String name : names) {
SchemaField field = getFieldOrNull(name);
if (null != field) {
if (copyFieldsMap.containsKey(name) || isCopyFieldTarget(field)) {
throw new SolrException(ErrorCode.BAD_REQUEST, "Can't delete '" + name
+ "' because it's referred to by at least one copy field directive.");
String message = "Can't delete field '" + name
+ "' because it's referred to by at least one copy field directive.";
if (newSchema.copyFieldsMap.containsKey(name) || newSchema.isCopyFieldTarget(field)) {
throw new SolrException(ErrorCode.BAD_REQUEST, message);
}
for (int i = 0 ; i < newSchema.dynamicCopyFields.length ; ++i) {
DynamicCopy dynamicCopy = newSchema.dynamicCopyFields[i];
if (name.equals(dynamicCopy.getRegex())) {
throw new SolrException(ErrorCode.BAD_REQUEST, message);
}
}
newSchema.fields.remove(name);
newSchema.fieldsWithDefaultValue.remove(field);
@ -844,7 +851,10 @@ public final class ManagedIndexSchema extends IndexSchema {
DynamicCopy dynamicCopy = dynamicCopyFields[i];
if (source.equals(dynamicCopy.getRegex()) && dest.equals(dynamicCopy.getDestFieldName())) {
found = true;
decrementCopyFieldTargetCount(dynamicCopy.getDestination().getPrototype());
SchemaField destinationPrototype = dynamicCopy.getDestination().getPrototype();
if (copyFieldTargetCounts.containsKey(destinationPrototype)) {
decrementCopyFieldTargetCount(destinationPrototype);
}
if (dynamicCopyFields.length > 1) {
DynamicCopy[] temp = new DynamicCopy[dynamicCopyFields.length - 1];
System.arraycopy(dynamicCopyFields, 0, temp, 0, i);
@ -1126,7 +1136,9 @@ public final class ManagedIndexSchema extends IndexSchema {
if (typeName.equals(destinationPrototype.getType().getTypeName())
|| (null != sourceDynamicBase && typeName.equals(sourceDynamicBase.getPrototype().getType().getTypeName()))) {
dynamicCopyFieldsToRebuild.add(dynamicCopy);
newSchema.decrementCopyFieldTargetCount(destinationPrototype);
if (newSchema.copyFieldTargetCounts.containsKey(destinationPrototype)) {
newSchema.decrementCopyFieldTargetCount(destinationPrototype);
}
// don't add this dynamic copy field to newDynamicCopyFields - effectively removing it
} else {
newDynamicCopyFields.add(dynamicCopy);

View File

@ -152,7 +152,7 @@ public class TestBulkSchemaConcurrent extends AbstractFullDistribZkTestBase {
payload = payload.replace("replaceFieldA", aField);
payload = payload.replace("replaceDynamicField", dynamicFldName);
payload = payload.replace("replaceDynamicCopyFieldDest",dynamicCopyFldDest);
payload = payload.replace("replaceDynamicCopyFieldDest", dynamicCopyFldDest);
payload = payload.replace("myNewFieldTypeName", newFieldTypeName);
RestTestHarness publisher = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
@ -269,12 +269,12 @@ public class TestBulkSchemaConcurrent extends AbstractFullDistribZkTestBase {
private void invokeBulkDeleteCall(int seed, ArrayList<String> errs) throws Exception {
String payload = "{\n" +
" 'delete-field' : {'name':'replaceFieldA'},\n" +
" 'delete-dynamic-field' : {'name' :'replaceDynamicField'},\n" +
" 'delete-copy-field' : {\n" +
" 'source' :'replaceFieldA',\n" +
" 'dest':['replaceDynamicCopyFieldDest']\n" +
" },\n" +
" 'delete-field' : {'name':'replaceFieldA'},\n" +
" 'delete-dynamic-field' : {'name' :'replaceDynamicField'},\n" +
" 'delete-field-type' : {'name' :'myNewFieldTypeName'}\n" +
" }";
String aField = "a" + seed;