lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jan...@apache.org
Subject [lucene-solr] branch branch_8x updated: SOLR-13238: BlobHandler generates non-padded md5
Date Sat, 14 Sep 2019 20:47:41 GMT
This is an automated email from the ASF dual-hosted git repository.

janhoy pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new a5b5585  SOLR-13238: BlobHandler generates non-padded md5
a5b5585 is described below

commit a5b558582293c7ef4b05e505e3d4cef493cbd1d9
Author: Jan H√łydahl <janhoy@apache.org>
AuthorDate: Sat Sep 14 22:23:17 2019 +0200

    SOLR-13238: BlobHandler generates non-padded md5
    
    (cherry picked from commit 31735eeb402d7b00785bba484093b81107ffc2c9)
---
 solr/CHANGES.txt                                             |  2 ++
 solr/core/src/java/org/apache/solr/handler/BlobHandler.java  |  4 ++--
 .../src/test/org/apache/solr/handler/TestBlobHandler.java    | 12 ++++++++++--
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a5fd2ee..96237e9 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -149,6 +149,8 @@ Bug Fixes
 * SOLR-13240: Fixed UTILIZENODE action resulting in IllegalArgumentException.
   (Hendrik Haddorp, Richard Goodman, Tim Owen, shalin, noble, Christine Poerschke)
 
+* SOLR-13238: BlobHandler generates non-padded md5 (Jeff Walraven via janhoy)
+
 Other Changes
 ----------------------
 
diff --git a/solr/core/src/java/org/apache/solr/handler/BlobHandler.java b/solr/core/src/java/org/apache/solr/handler/BlobHandler.java
index ee3adae..d2d0d8a 100644
--- a/solr/core/src/java/org/apache/solr/handler/BlobHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/BlobHandler.java
@@ -20,7 +20,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.invoke.MethodHandles;
-import java.math.BigInteger;
 import java.nio.ByteBuffer;
 import java.security.MessageDigest;
 import java.util.Collection;
@@ -28,6 +27,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.codec.binary.Hex;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.index.Term;
@@ -114,7 +114,7 @@ public class BlobHandler extends RequestHandlerBase implements PluginInfoInitial
         }
         MessageDigest m = MessageDigest.getInstance("MD5");
         m.update(payload.array(), payload.position(), payload.limit());
-        String md5 = new BigInteger(1, m.digest()).toString(16);
+        String md5 = new String(Hex.encodeHex(m.digest()));
 
         int duplicateCount = req.getSearcher().count(new TermQuery(new Term("md5", md5)));
         if (duplicateCount > 0) {
diff --git a/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java b/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java
index 88e6076..32ecc9e 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java
@@ -20,7 +20,6 @@ import java.io.IOException;
 import java.lang.invoke.MethodHandles;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.http.HttpEntity;
@@ -86,6 +85,7 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase {
           "type"),null));
 
       checkBlobPost(baseUrl, cloudClient);
+      checkBlobPostMd5(baseUrl, cloudClient);
     }
   }
 
@@ -108,6 +108,15 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase {
     compareInputAndOutput(baseUrl + "/.system/blob/test/1?wt=filestream", bytarr, cloudClient);
   }
 
+  static void checkBlobPostMd5(String baseUrl, CloudSolrClient cloudClient) throws Exception
{
+    String blobName = "md5Test";
+    String stringValue = "MHMyugAGUxFzeqbpxVemACGbQ"; // Random string requires padding in
md5 hash
+    String stringValueMd5 = "02d82dd5aabc47fae54ee3dd236ad83d";
+    postAndCheck(cloudClient, baseUrl, blobName, ByteBuffer.wrap(stringValue.getBytes(StandardCharsets.UTF_8)),
1);
+    MapWriter map = TestSolrConfigHandlerConcurrent.getAsMap(baseUrl + "/.system/blob/" +
blobName, cloudClient);
+    assertEquals(stringValueMd5, map._getStr("response/docs[0]/md5", null));
+  }
+
   public static void createSystemCollection(SolrClient client) throws SolrServerException,
IOException {
     CollectionAdminResponse response1;
     CollectionAdminRequest.Create createCollectionRequest = CollectionAdminRequest.createCollection(".system",1,2);
@@ -121,7 +130,6 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase {
 
     String url;
     MapWriter map = null;
-    List l;
     final RTimer timer = new RTimer();
     int i = 0;
     for (; i < 150; i++) {//15 secs


Mime
View raw message