You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2020/07/05 06:26:34 UTC

[lucene-solr] 03/03: SOLR-14404: update was not working

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

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

commit 4c3ea27336a41d31d067768afe5f99624c905fb9
Author: noble <no...@apache.org>
AuthorDate: Sun Jul 5 16:25:09 2020 +1000

    SOLR-14404: update was not working
---
 .../apache/solr/api/CustomContainerPlugins.java    | 31 +++++++++++++++-------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java b/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java
index fe537d9..6536276 100644
--- a/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java
+++ b/solr/core/src/java/org/apache/solr/api/CustomContainerPlugins.java
@@ -130,27 +130,29 @@ public class CustomContainerPlugins implements ClusterPropertiesListener, MapWri
           continue;
         }
         if (e.getValue() == Diff.ADDED) {
+          // this plugin is totally new
           for (ApiHolder holder : apiInfo.holders) {
             containerApiBag.register(holder, getTemplateVars(apiInfo.info));
           }
           currentPlugins.put(e.getKey(), apiInfo);
         } else {
+          //this plugin is being updated
           ApiInfo old = currentPlugins.put(e.getKey(), apiInfo);
-          List<ApiHolder> replaced = new ArrayList<>();
           for (ApiHolder holder : apiInfo.holders) {
-            Api oldApi = containerApiBag.lookup(holder.getPath(),
-                holder.getMethod().toString(), null);
-            if (oldApi instanceof ApiHolder) {
-              replaced.add((ApiHolder) oldApi);
-            }
+            //register all new paths
             containerApiBag.register(holder, getTemplateVars(apiInfo.info));
           }
           if (old != null) {
-            for (ApiHolder holder : old.holders) {
-              if (replaced.contains(holder)) continue;// this path is present in the new one as well. so it already got replaced
-              containerApiBag.unregister(holder.getMethod(),getActualPath(old, holder.getPath()));
+            //this is an update of the plugin. But, it is possible that
+            // some paths are remved in the newer version of the plugin
+            for (ApiHolder oldHolder : old.holders) {
+              if(apiInfo.get(oldHolder.api.getEndPoint()) == null) {
+                //there was a path in the old plugin which is not present in the new one
+                containerApiBag.unregister(oldHolder.getMethod(),getActualPath(old, oldHolder.getPath()));
+              }
             }
             if (old instanceof Closeable) {
+              //close the old instance of the plugin
               closeWhileHandlingException((Closeable) old);
             }
           }
@@ -208,6 +210,17 @@ public class CustomContainerPlugins implements ClusterPropertiesListener, MapWri
     private Class klas;
     Object instance;
 
+    ApiHolder get(EndPoint endPoint) {
+      for (ApiHolder holder : holders) {
+        EndPoint e = holder.api.getEndPoint();
+        if(Objects.equals(endPoint.method()[0] , e.method()[0]) &&
+            Objects.equals(endPoint.path()[0], e.path()[0])) {
+          return holder;
+        }
+      }
+      return null;
+    }
+
 
     @SuppressWarnings({"unchecked","rawtypes"})
     public ApiInfo(PluginMeta info, List<String> errs) {