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 06:56:10 UTC

[solr] branch jira/solr16565 created (now e4aa798d35b)

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

noble pushed a change to branch jira/solr16565
in repository https://gitbox.apache.org/repos/asf/solr.git


      at e4aa798d35b SOLR-16565: posting the same file to the package store should not throw an error

This branch includes the following new commits:

     new e4aa798d35b SOLR-16565: posting the same file to the package store should not throw an error

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[solr] 01/01: SOLR-16565: posting the same file to the package store should not throw an error

Posted by no...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

noble pushed a commit to branch jira/solr16565
in repository https://gitbox.apache.org/repos/asf/solr.git

commit e4aa798d35bb837f0d09a6c911edebea7dc5cc6b
Author: Noble Paul <no...@gmail.com>
AuthorDate: Wed Nov 30 17:55:42 2022 +1100

    SOLR-16565: posting the same file to the package store should not throw an error
---
 .../org/apache/solr/filestore/PackageStoreAPI.java | 33 ++++++++++++++++++++++
 .../solr/filestore/TestDistribPackageStore.java    | 13 ++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)

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..6d56119ac79 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,21 @@ public class PackageStoreAPI {
         otherAttribs.forEach(ew.getBiConsumer());
       }
     }
+
+    @Override
+    public int hashCode() {
+      return sha512.hashCode();
+    }
+
+    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;
   }
 
   /**