You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by no...@apache.org on 2022/11/30 07:58:10 UTC

[solr] branch branch_9x updated: SOLR-16565: posting the same file to the package store should not throw an error (#1199)

This is an automated email from the ASF dual-hosted git repository.

noble 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 b034e030e24 SOLR-16565: posting the same file to the package store should not throw an error (#1199)
b034e030e24 is described below

commit b034e030e24a2bc6952f1802f9675b2c70a0eb19
Author: Noble Paul <no...@users.noreply.github.com>
AuthorDate: Wed Nov 30 18:57:21 2022 +1100

    SOLR-16565: posting the same file to the package store should not throw an error (#1199)
---
 solr/CHANGES.txt                                   |  1 +
 .../org/apache/solr/filestore/PackageStoreAPI.java | 34 ++++++++++++++++++++++
 .../solr/filestore/TestDistribPackageStore.java    | 13 ++++++++-
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 34bcb370b69..f230b2bfd01 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -55,6 +55,7 @@ Improvements
   Solr Core also no longer contains the JettySolrRunner (now living in the testing framework), removing the need for Jetty Server dependencies in solr-core.
   (Houston Putman)
 
+* SOLR-16565: posting the same file to the package store should not throw an error (noble)
 Optimizations
 ---------------------
 
diff --git a/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java b/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java
index 0a98bba9a2f..4f4403356fb 100644
--- a/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java
+++ b/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java
@@ -30,6 +30,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.function.Consumer;
 import java.util.function.Supplier;
@@ -203,6 +204,23 @@ public class PackageStoreAPI {
           List<String> signatures = readSignatures(req, buf);
           MetaData meta = _createJsonMetaData(buf, signatures);
           PackageStore.FileType type = packageStore.getType(path, true);
+          boolean[] returnAfter = new boolean[] {false};
+          if (type == PackageStore.FileType.FILE) {
+            // a file already exist at the same path
+            packageStore.get(
+                path,
+                fileEntry -> {
+                  if (meta.equals(fileEntry.meta)) {
+                    // the file content is same too. this is an idempotent put
+                    // do not throw an error
+                    returnAfter[0] = true;
+                    rsp.add(CommonParams.FILE, path);
+                    rsp.add("message", "File with same metadata exists ");
+                  }
+                },
+                true);
+          }
+          if (returnAfter[0]) return;
           if (type != PackageStore.FileType.NOFILE) {
             throw new SolrException(
                 SolrException.ErrorCode.BAD_REQUEST, "Path already exists " + path);
@@ -389,6 +407,22 @@ public class PackageStoreAPI {
         otherAttribs.forEach(ew.getBiConsumer());
       }
     }
+
+    @Override
+    public int hashCode() {
+      return sha512.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object that) {
+      if (that instanceof MetaData) {
+        MetaData metaData = (MetaData) that;
+        return Objects.equals(sha512, metaData.sha512)
+            && Objects.equals(signatures, metaData.signatures)
+            && Objects.equals(otherAttribs, metaData.otherAttribs);
+      }
+      return false;
+    }
   }
 
   static final String INVALIDCHARS = " /\\#&*\n\t%@~`=+^$><?{}[]|:;!";
diff --git a/solr/core/src/test/org/apache/solr/filestore/TestDistribPackageStore.java b/solr/core/src/test/org/apache/solr/filestore/TestDistribPackageStore.java
index d646b9e1785..f4ead6626df 100644
--- a/solr/core/src/test/org/apache/solr/filestore/TestDistribPackageStore.java
+++ b/solr/core/src/test/org/apache/solr/filestore/TestDistribPackageStore.java
@@ -105,6 +105,15 @@ public class TestDistribPackageStore extends SolrCloudTestCase {
           "/package/mypkg/v1.0/runtimelibs.jar",
           "L3q/qIGs4NaF6JiO0ZkMUFa88j0OmYc+I6O7BOdNuMct/xoZ4h73aZHZGc0+nmI1f/U3bOlMPINlSOM6LK3JpQ==");
 
+      NavigableObject rsp =
+          postFile(
+              cluster.getSolrClient(),
+              getFileContent("runtimecode/runtimelibs.jar.bin"),
+              "/package/mypkg/v1.0/runtimelibs.jar",
+              "L3q/qIGs4NaF6JiO0ZkMUFa88j0OmYc+I6O7BOdNuMct/xoZ4h73aZHZGc0+nmI1f/U3bOlMPINlSOM6LK3JpQ==");
+
+      assertTrue(rsp._getStr("message", "").contains("File with same metadata exists "));
+
       assertResponseValues(
           10,
           cluster.getSolrClient(),
@@ -323,7 +332,8 @@ public class TestDistribPackageStore extends SolrCloudTestCase {
         false);
   }
 
-  public static void postFile(SolrClient client, ByteBuffer buffer, String name, String sig)
+  public static NavigableObject postFile(
+      SolrClient client, ByteBuffer buffer, String name, String sig)
       throws SolrServerException, IOException {
     String resource = "/cluster/files" + name;
     ModifiableSolrParams params = new ModifiableSolrParams();
@@ -338,6 +348,7 @@ public class TestDistribPackageStore extends SolrCloudTestCase {
             .build()
             .process(client);
     assertEquals(name, rsp.getResponse().get(CommonParams.FILE));
+    return rsp;
   }
 
   /**