Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-16362: Logs: Truncate field values in logs if a doc fails to index (#990)

Nazerke Seidan23b69c6556de
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 598dc6f624e..efcee6bb1f5 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -73,6 +73,7 @@ Improvements
* SOLR-16353: Make SplitShardCmd#checkDiskSpace disableable through a system property. (Haythem Khiri)
+* SOLR-16362: Logs: Truncate field values in logs if a doc fails to index. (Nazerke Seidan, David Smiley)
Optimizations
---------------------
diff --git a/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java b/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
index b2ccb338ea5..6455514d6f8 100644
--- a/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
+++ b/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
@@ -41,6 +41,7 @@ public class DocumentBuilder {
// accessible only for tests
static int MIN_LENGTH_TO_MOVE_LAST =
Integer.getInteger("solr.docBuilder.minLengthToMoveLast", 4 * 1024); // internal setting
+ static int MAX_VALUES_AS_STRING_LENGTH = 256;
/**
* Add a field value to a given document.
@@ -161,6 +162,14 @@ public class DocumentBuilder {
&& !sfield.multiValued()
&& field.getValueCount() > 1
&& !(sfield.getType() instanceof DenseVectorField)) {
+
+ // Ensure we do not flood the logs with extremely long values
+ String fieldValue = field.getValue().toString();
+ if (fieldValue.length() > MAX_VALUES_AS_STRING_LENGTH) {
+ assert fieldValue.endsWith("]");
+ fieldValue = fieldValue.substring(0, MAX_VALUES_AS_STRING_LENGTH - 4) + "...]";
+ }
+
throw new SolrException(
SolrException.ErrorCode.BAD_REQUEST,
"ERROR: "
@@ -168,7 +177,7 @@ public class DocumentBuilder {
+ "multiple values encountered for non multiValued field "
+ sfield.getName()
+ ": "
- + field.getValue());
+ + fieldValue);
}
List<CopyField> copyFields = schema.getCopyFieldsList(name);