You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ds...@apache.org on 2022/09/02 19:17:52 UTC
[solr] branch branch_9x updated: SOLR-16362: Logs: Truncate field values in logs if a doc fails to index (#990)
This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new bc861755521 SOLR-16362: Logs: Truncate field values in logs if a doc fails to index (#990)
bc861755521 is described below
commit bc861755521074c5101cfa20e965d522d17f6764
Author: Nazerke Seidan <se...@gmail.com>
AuthorDate: Fri Sep 2 14:04:08 2022 -0400
SOLR-16362: Logs: Truncate field values in logs if a doc fails to index (#990)
Co-authored-by: Nazerke Seidan <ns...@salesforce.com>
---
solr/CHANGES.txt | 1 +
.../core/src/java/org/apache/solr/update/DocumentBuilder.java | 11 ++++++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 2a3d76270fd..0ed5b5358cb 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -51,6 +51,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);