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 18:04:14 UTC

[solr] branch main 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 main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 23b69c6556d SOLR-16362: Logs: Truncate field values in logs if a doc fails to index (#990)
23b69c6556d is described below

commit 23b69c6556de1e30e1bd59972285f557e60715ec
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 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);