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/11/11 15:44:58 UTC
[lucene-solr] branch reference_impl_dev updated: @1164 Meant to
remove this.
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 39849c5 @1164 Meant to remove this.
39849c5 is described below
commit 39849c5f7c117448ebfe6f86a9805dfeac76ab7a
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Wed Nov 11 09:41:05 2020 -0600
@1164 Meant to remove this.
---
.../org/apache/solr/schema/ManagedIndexSchema.java | 343 +++++++++------------
1 file changed, 142 insertions(+), 201 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
index 85e460d..bf60922 100644
--- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
@@ -121,9 +121,6 @@ public final class ManagedIndexSchema extends IndexSchema {
this.collection = collection;
this.managedSchemaResourceName = managedSchemaResourceName;
this.schemaZkVersion = schemaZkVersion;
- if (this.schemaZkVersion == -1) {
- throw new IllegalArgumentException();
- }
this.schemaUpdateLock = schemaUpdateLock;
}
@@ -436,87 +433,72 @@ public final class ManagedIndexSchema extends IndexSchema {
Map<String, Collection<String>> copyFieldNames,
boolean persist) {
ManagedIndexSchema newSchema;
- try {
-
- if (persist) {
- schemaUpdateLock.lockInterruptibly();
+ if (isMutable) {
+ boolean success = false;
+ if (copyFieldNames == null){
+ copyFieldNames = Collections.emptyMap();
}
- if (isMutable) {
- boolean success = false;
- if (copyFieldNames == null) {
- copyFieldNames = Collections.emptyMap();
- }
- newSchema = shallowCopy(true);
+ newSchema = shallowCopy(true);
- newSchema.fields = new ConcurrentHashMap<>(fields.size());
- ManagedIndexSchema finalNewSchema = newSchema;
- fields.forEach((s, schemaField) -> {
- finalNewSchema.fields.put(s, schemaField);
- });
+ newSchema.fields = new ConcurrentHashMap<>(fields.size());
+ ManagedIndexSchema finalNewSchema = newSchema;
+ fields.forEach((s, schemaField) -> {
+ finalNewSchema.fields.put(s, schemaField);
+ });
- newSchema.requiredFields = ConcurrentHashMap.newKeySet(requiredFields.size());
- newSchema.requiredFields.addAll(requiredFields);
- newSchema.fieldsWithDefaultValue = ConcurrentHashMap.newKeySet(fieldsWithDefaultValue.size());
- newSchema.fieldsWithDefaultValue.addAll(fieldsWithDefaultValue);
- newSchema.fieldTypes = new ConcurrentHashMap<>(fieldTypes.size());
- newSchema.fieldTypes.putAll(fieldTypes);
-
- Map<String,Collection<String>> finalCopyFieldNames = copyFieldNames;
- newFields.forEach(newField -> {
- if (null != finalNewSchema.fields.get(newField.getName())) {
- String msg = "Field '" + newField.getName() + "' already exists.";
- throw new FieldExistsException(ErrorCode.BAD_REQUEST, msg);
- }
- finalNewSchema.fields.put(newField.getName(), newField);
+ newSchema.requiredFields = ConcurrentHashMap.newKeySet(requiredFields.size());
+ newSchema.requiredFields.addAll(requiredFields);
+ newSchema.fieldsWithDefaultValue = ConcurrentHashMap.newKeySet(fieldsWithDefaultValue.size());
+ newSchema.fieldsWithDefaultValue.addAll(fieldsWithDefaultValue);
+ newSchema.fieldTypes = new ConcurrentHashMap<>(fieldTypes.size());
+ newSchema.fieldTypes.putAll(fieldTypes);
+
+ Map<String,Collection<String>> finalCopyFieldNames = copyFieldNames;
+ newFields.forEach(newField -> {
+ if (null != finalNewSchema.fields.get(newField.getName())) {
+ String msg = "Field '" + newField.getName() + "' already exists.";
+ throw new FieldExistsException(ErrorCode.BAD_REQUEST, msg);
+ }
+ finalNewSchema.fields.put(newField.getName(), newField);
- if (null != newField.getDefaultValue()) {
- if (log.isDebugEnabled()) {
- log.debug("{} contains default value: {}", newField.getName(), newField.getDefaultValue());
- }
- finalNewSchema.fieldsWithDefaultValue.add(newField);
+ if (null != newField.getDefaultValue()) {
+ if (log.isDebugEnabled()) {
+ log.debug("{} contains default value: {}", newField.getName(), newField.getDefaultValue());
}
- if (newField.isRequired()) {
- if (log.isDebugEnabled()) {
- log.debug("{} is required in this schema", newField.getName());
- }
- finalNewSchema.requiredFields.add(newField);
+ finalNewSchema.fieldsWithDefaultValue.add(newField);
+ }
+ if (newField.isRequired()) {
+ if (log.isDebugEnabled()) {
+ log.debug("{} is required in this schema", newField.getName());
}
- Collection<String> copyFields = finalCopyFieldNames.get(newField.getName());
- if (copyFields != null) {
- for (String copyField : copyFields) {
- finalNewSchema.registerCopyField(newField.getName(), copyField);
- }
+ finalNewSchema.requiredFields.add(newField);
+ }
+ Collection<String> copyFields = finalCopyFieldNames.get(newField.getName());
+ if (copyFields != null) {
+ for (String copyField : copyFields) {
+ finalNewSchema.registerCopyField(newField.getName(), copyField);
}
+ }
- });
+ });
- newSchema.postReadInform();
+ newSchema.postReadInform();
- newSchema.refreshAnalyzers();
+ newSchema.refreshAnalyzers();
- if (persist) {
- success = newSchema.persistManagedSchema(false); // don't just create - update it if it already exists
- if (success) {
- log.debug("Added field(s): {}", newFields);
- } else {
- log.error("Failed to add field(s): {}", newFields);
- newSchema = null;
- }
- }
- } else {
- String msg = "This ManagedIndexSchema is not mutable.";
- log.error(msg);
- throw new SolrException(ErrorCode.SERVER_ERROR, msg);
- }
- } catch (InterruptedException e) {
- ParWork.propagateInterrupt(e);
- throw new AlreadyClosedException();
- } finally {
- if (persist) {
- if (schemaUpdateLock.isHeldByCurrentThread()) {
- schemaUpdateLock.unlock();
+ if(persist) {
+ success = newSchema.persistManagedSchema(false); // don't just create - update it if it already exists
+ if (success) {
+ log.debug("Added field(s): {}", newFields);
+ } else {
+ log.error("Failed to add field(s): {}", newFields);
+ newSchema = null;
}
}
+ } else {
+ String msg = "This ManagedIndexSchema is not mutable.";
+ log.error(msg);
+ throw new SolrException(ErrorCode.SERVER_ERROR, msg);
}
return newSchema;
}
@@ -650,58 +632,44 @@ public final class ManagedIndexSchema extends IndexSchema {
public ManagedIndexSchema addDynamicFields(Collection<SchemaField> newDynamicFields,
Map<String,Collection<String>> copyFieldNames, boolean persist) {
ManagedIndexSchema newSchema;
- try {
- if (persist) {
- schemaUpdateLock.lockInterruptibly();
+ if (isMutable) {
+ boolean success = false;
+ if (copyFieldNames == null){
+ copyFieldNames = Collections.emptyMap();
}
- if (isMutable) {
- boolean success = false;
- if (copyFieldNames == null) {
- copyFieldNames = Collections.emptyMap();
- }
- newSchema = shallowCopy(true);
-
- for (SchemaField newDynamicField : newDynamicFields) {
- List<DynamicField> dFields = new ArrayList<>(Arrays.asList(newSchema.dynamicFields));
- if (isDuplicateDynField(dFields, newDynamicField)) {
- String msg = "Dynamic field '" + newDynamicField.getName() + "' already exists.";
- throw new FieldExistsException(ErrorCode.BAD_REQUEST, msg);
- }
- dFields.add(new DynamicField(newDynamicField));
- newSchema.dynamicFields = dynamicFieldListToSortedArray(dFields);
+ newSchema = shallowCopy(true);
- Collection<String> copyFields = copyFieldNames.get(newDynamicField.getName());
- if (copyFields != null) {
- for (String copyField : copyFields) {
- newSchema.registerCopyField(newDynamicField.getName(), copyField);
- }
- }
+ for (SchemaField newDynamicField : newDynamicFields) {
+ List<DynamicField> dFields = new ArrayList<>(Arrays.asList(newSchema.dynamicFields));
+ if (isDuplicateDynField(dFields, newDynamicField)) {
+ String msg = "Dynamic field '" + newDynamicField.getName() + "' already exists.";
+ throw new FieldExistsException(ErrorCode.BAD_REQUEST, msg);
}
+ dFields.add(new DynamicField(newDynamicField));
+ newSchema.dynamicFields = dynamicFieldListToSortedArray(dFields);
- newSchema.postReadInform();
- newSchema.refreshAnalyzers();
- if (persist) {
- success = newSchema.persistManagedSchema(false); // don't just create - update it if it already exists
- if (success) {
- log.debug("Added dynamic field(s): {}", newDynamicFields);
- } else {
- log.error("Failed to add dynamic field(s): {}", newDynamicFields);
+ Collection<String> copyFields = copyFieldNames.get(newDynamicField.getName());
+ if (copyFields != null) {
+ for (String copyField : copyFields) {
+ newSchema.registerCopyField(newDynamicField.getName(), copyField);
}
}
- } else {
- String msg = "This ManagedIndexSchema is not mutable.";
- log.error(msg);
- throw new SolrException(ErrorCode.SERVER_ERROR, msg);
}
- } catch (InterruptedException e) {
- ParWork.propagateInterrupt(e);
- throw new AlreadyClosedException();
- } finally {
+
+ newSchema.postReadInform();
+ newSchema.refreshAnalyzers();
if (persist) {
- if (schemaUpdateLock.isHeldByCurrentThread()) {
- schemaUpdateLock.unlock();
+ success = newSchema.persistManagedSchema(false); // don't just create - update it if it already exists
+ if (success) {
+ log.debug("Added dynamic field(s): {}", newDynamicFields);
+ } else {
+ log.error("Failed to add dynamic field(s): {}", newDynamicFields);
}
}
+ } else {
+ String msg = "This ManagedIndexSchema is not mutable.";
+ log.error(msg);
+ throw new SolrException(ErrorCode.SERVER_ERROR, msg);
}
return newSchema;
}
@@ -847,46 +815,32 @@ public final class ManagedIndexSchema extends IndexSchema {
@Override
public ManagedIndexSchema addCopyFields(Map<String, Collection<String>> copyFields, boolean persist) {
ManagedIndexSchema newSchema;
- try {
- if (persist) {
- schemaUpdateLock.lockInterruptibly();
- }
- if (isMutable) {
- boolean success = false;
- newSchema = shallowCopy(true);
- for (Map.Entry<String,Collection<String>> entry : copyFields.entrySet()) {
- //Key is the name of the field, values are the destinations
-
- for (String destination : entry.getValue()) {
- newSchema.registerCopyField(entry.getKey(), destination);
- }
- }
- newSchema.postReadInform();
- newSchema.refreshAnalyzers();
- if (persist) {
- success = newSchema.persistManagedSchema(false); // don't just create - update it if it already exists
- if (success) {
- if (log.isDebugEnabled()) {
- log.debug("Added copy fields for {} sources", copyFields.size());
- }
- } else {
- log.error("Failed to add copy fields for {} sources", copyFields.size());
- }
+ if (isMutable) {
+ boolean success = false;
+ newSchema = shallowCopy(true);
+ for (Map.Entry<String, Collection<String>> entry : copyFields.entrySet()) {
+ //Key is the name of the field, values are the destinations
+
+ for (String destination : entry.getValue()) {
+ newSchema.registerCopyField(entry.getKey(), destination);
}
- } else {
- String msg = "This ManagedIndexSchema is not mutable.";
- log.error(msg);
- throw new SolrException(ErrorCode.SERVER_ERROR, msg);
}
- } catch (InterruptedException e) {
- ParWork.propagateInterrupt(e);
- throw new AlreadyClosedException();
- } finally {
- if (persist) {
- if (schemaUpdateLock.isHeldByCurrentThread()) {
- schemaUpdateLock.unlock();
+ newSchema.postReadInform();
+ newSchema.refreshAnalyzers();
+ if(persist) {
+ success = newSchema.persistManagedSchema(false); // don't just create - update it if it already exists
+ if (success) {
+ if (log.isDebugEnabled()) {
+ log.debug("Added copy fields for {} sources", copyFields.size());
+ }
+ } else {
+ log.error("Failed to add copy fields for {} sources", copyFields.size());
}
}
+ } else {
+ String msg = "This ManagedIndexSchema is not mutable.";
+ log.error(msg);
+ throw new SolrException(ErrorCode.SERVER_ERROR, msg);
}
return newSchema;
}
@@ -1046,71 +1000,58 @@ public final class ManagedIndexSchema extends IndexSchema {
}
public ManagedIndexSchema addFieldTypes(List<FieldType> fieldTypeList, boolean persist) {
- ManagedIndexSchema newSchema;
- try {
- if (persist) {
- schemaUpdateLock.lockInterruptibly();
- }
-
- if (!isMutable) {
- String msg = "This ManagedIndexSchema is not mutable.";
- log.error(msg);
- throw new SolrException(ErrorCode.SERVER_ERROR, msg);
- }
-
- newSchema = shallowCopy(true);
+ if (!isMutable) {
+ String msg = "This ManagedIndexSchema is not mutable.";
+ log.error(msg);
+ throw new SolrException(ErrorCode.SERVER_ERROR, msg);
+ }
- // we shallow copied fieldTypes, but since we're changing them, we need to do a true
- // deep copy before adding the new field types
+ ManagedIndexSchema newSchema = shallowCopy(true);
- HashMap<Object,Object> tmpMap = new HashMap<>(fieldTypes.size());
- fieldTypes.forEach((s, fieldType) -> {
- tmpMap.put(s, fieldType);
- });
+ // we shallow copied fieldTypes, but since we're changing them, we need to do a true
+ // deep copy before adding the new field types
- newSchema.fieldTypes = new ConcurrentHashMap<>((HashMap) tmpMap.clone());
+ HashMap<Object,Object> tmpMap = new HashMap<>(fieldTypes.size());
+ fieldTypes.forEach((s, fieldType) -> {
+ tmpMap.put(s, fieldType);
+ });
- // do a first pass to validate the field types don't exist already
- for (FieldType fieldType : fieldTypeList) {
- String typeName = fieldType.getTypeName();
- if (newSchema.getFieldTypeByName(typeName) != null) {
- throw new FieldExistsException(ErrorCode.BAD_REQUEST, "Field type '" + typeName + "' already exists!");
- }
+ newSchema.fieldTypes = new ConcurrentHashMap<>((HashMap) tmpMap.clone());
- newSchema.fieldTypes.put(typeName, fieldType);
+ // do a first pass to validate the field types don't exist already
+ for (FieldType fieldType : fieldTypeList) {
+ String typeName = fieldType.getTypeName();
+ if (newSchema.getFieldTypeByName(typeName) != null) {
+ throw new FieldExistsException(ErrorCode.BAD_REQUEST,
+ "Field type '" + typeName + "' already exists!");
}
- newSchema.postReadInform();
+ newSchema.fieldTypes.put(typeName, fieldType);
+ }
- newSchema.refreshAnalyzers();
+ newSchema.postReadInform();
- if (persist) {
- boolean success = newSchema.persistManagedSchema(false);
- if (success) {
- if (log.isDebugEnabled()) {
- StringBuilder fieldTypeNames = new StringBuilder();
- for (int i = 0; i < fieldTypeList.size(); i++) {
- if (i > 0) fieldTypeNames.append(", ");
- fieldTypeNames.append(fieldTypeList.get(i).typeName);
- }
- log.debug("Added field types: {}", fieldTypeNames);
+ newSchema.refreshAnalyzers();
+
+ if (persist) {
+ boolean success = newSchema.persistManagedSchema(false);
+ if (success) {
+ if (log.isDebugEnabled()) {
+ StringBuilder fieldTypeNames = new StringBuilder();
+ for (int i=0; i < fieldTypeList.size(); i++) {
+ if (i > 0) fieldTypeNames.append(", ");
+ fieldTypeNames.append(fieldTypeList.get(i).typeName);
}
- } else {
- // this is unlikely to happen as most errors are handled as exceptions in the persist code
- log.error("Failed to add field types: {}", fieldTypeList);
- throw new SolrException(ErrorCode.SERVER_ERROR, "Failed to persist updated schema due to underlying storage issue; check log for more details!");
- }
- }
- } catch (InterruptedException e) {
- ParWork.propagateInterrupt(e);
- throw new AlreadyClosedException();
- } finally {
- if (persist) {
- if (schemaUpdateLock.isHeldByCurrentThread()) {
- schemaUpdateLock.unlock();
+ log.debug("Added field types: {}", fieldTypeNames);
}
+ } else {
+ // this is unlikely to happen as most errors are handled as exceptions in the persist code
+ log.error("Failed to add field types: {}", fieldTypeList);
+ throw new SolrException(ErrorCode.SERVER_ERROR,
+ "Failed to persist updated schema due to underlying storage issue; check log for more details!");
}
}
+
return newSchema;
}