You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by js...@apache.org on 2023/07/06 13:27:06 UTC

[solr] branch branch_9x updated (4bde8fe3d0f -> 179ed4817cc)

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

jsweeney pushed a change to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


    from 4bde8fe3d0f CHANGES.txt for SOLR-16812, SOLR-16860, SOLR-16861
     new 1934c56aca7 SOLR-16861: Correct(override) MDC info for `CoordinatorHttpSolrCall` (#1753)
     new 179ed4817cc SOLR-16860: Remove collection -> synthetic core mapping in Coordinator Node upon collection deletion (#1754)

The 2 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.


Summary of changes:
 solr/CHANGES.txt                                   |  2 --
 .../solr/servlet/CoordinatorHttpSolrCall.java      | 34 +++++++++++++++++++---
 .../apache/solr/search/TestCoordinatorRole.java    | 15 +++++++++-
 3 files changed, 44 insertions(+), 7 deletions(-)


[solr] 01/02: SOLR-16861: Correct(override) MDC info for `CoordinatorHttpSolrCall` (#1753)

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

jsweeney pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git

commit 1934c56aca7c4a20d9156d5ae67b639556d25b81
Author: patsonluk <pa...@users.noreply.github.com>
AuthorDate: Wed Jul 5 05:17:04 2023 -0700

    SOLR-16861: Correct(override) MDC info for `CoordinatorHttpSolrCall` (#1753)
---
 .../solr/servlet/CoordinatorHttpSolrCall.java      | 23 +++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
index a9448d1310c..df95f712a4c 100644
--- a/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
+++ b/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
@@ -37,6 +37,7 @@ import org.apache.solr.common.util.Utils;
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.CoreDescriptor;
 import org.apache.solr.core.SolrCore;
+import org.apache.solr.logging.MDCLoggingContext;
 import org.apache.solr.request.DelegatingSolrQueryRequest;
 import org.apache.solr.request.LocalSolrQueryRequest;
 import org.apache.solr.request.SolrQueryRequest;
@@ -73,9 +74,11 @@ public class CoordinatorHttpSolrCall extends HttpSolrCall {
 
   public static SolrCore getCore(
       Factory factory, HttpSolrCall solrCall, String collectionName, boolean isPreferLeader) {
-    String sytheticCoreName = factory.collectionVsCoreNameMapping.get(collectionName);
-    if (sytheticCoreName != null) {
-      return solrCall.cores.getCore(sytheticCoreName);
+    String syntheticCoreName = factory.collectionVsCoreNameMapping.get(collectionName);
+    if (syntheticCoreName != null) {
+      SolrCore syntheticCore = solrCall.cores.getCore(syntheticCoreName);
+      setMDCLoggingContext(collectionName);
+      return syntheticCore;
     } else {
       ZkStateReader zkStateReader = solrCall.cores.getZkController().getZkStateReader();
       ClusterState clusterState = zkStateReader.getClusterState();
@@ -117,12 +120,26 @@ public class CoordinatorHttpSolrCall extends HttpSolrCall {
           addReplica(syntheticCollectionName, solrCall.cores);
           core = solrCall.getCoreByCollection(syntheticCollectionName, isPreferLeader);
         }
+        setMDCLoggingContext(collectionName);
         return core;
       }
       return null;
     }
   }
 
+  /**
+   * Overrides the MDC context as the core set was synthetic core, which does not reflect the
+   * collection being operated on
+   */
+  private static void setMDCLoggingContext(String collectionName) {
+    MDCLoggingContext.setCollection(collectionName);
+
+    // below is irrelevant for call to coordinator
+    MDCLoggingContext.setCoreName(null);
+    MDCLoggingContext.setShard(null);
+    MDCLoggingContext.setCoreName(null);
+  }
+
   private static void addReplica(String syntheticCollectionName, CoreContainer cores) {
     SolrQueryResponse rsp = new SolrQueryResponse();
     try {


[solr] 02/02: SOLR-16860: Remove collection -> synthetic core mapping in Coordinator Node upon collection deletion (#1754)

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

jsweeney pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git

commit 179ed4817cce5eb6a19fd9a7b4a179f6c1ac8f53
Author: patsonluk <pa...@users.noreply.github.com>
AuthorDate: Thu Jul 6 06:21:19 2023 -0700

    SOLR-16860: Remove collection -> synthetic core mapping in Coordinator Node upon collection deletion (#1754)
    
    * CoordinatorHttpSolrCall should remove collection from mapping upon collection deletion
    
    * Updated CHANGES.txt
    
    ---------
    
    Co-authored-by: Justin Sweeney <ju...@fullstory.com>
---
 solr/CHANGES.txt                                          |  2 --
 .../org/apache/solr/servlet/CoordinatorHttpSolrCall.java  | 11 ++++++++++-
 .../test/org/apache/solr/search/TestCoordinatorRole.java  | 15 ++++++++++++++-
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 3a4967656bd..bdc23977a13 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -247,8 +247,6 @@ Bug Fixes
 
 * SOLR-16861: Coordinator node does not have the correct collection/core in MDCLoggingContext (Patson Luk)
 
-
-
 Dependency Upgrades
 ---------------------
 * PR#1494: Upgrade forbiddenapis to 3.5 (Uwe Schindler)
diff --git a/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
index df95f712a4c..ee30474a506 100644
--- a/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
+++ b/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java
@@ -105,7 +105,16 @@ public class CoordinatorHttpSolrCall extends HttpSolrCall {
               .cores
               .getZkController()
               .getZkStateReader()
-              .registerDocCollectionWatcher(collectionName, collection -> collection == null);
+              .registerDocCollectionWatcher(
+                  collectionName,
+                  collection -> {
+                    if (collection == null) {
+                      factory.collectionVsCoreNameMapping.remove(collectionName);
+                      return true;
+                    } else {
+                      return false;
+                    }
+                  });
           if (log.isDebugEnabled()) {
             log.debug("coordinator node, returns synthetic core: {}", core.getName());
           }
diff --git a/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java
index 705429de5e5..14d866d1f3a 100644
--- a/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java
+++ b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java
@@ -443,19 +443,32 @@ public class TestCoordinatorRole extends SolrCloudTestCase {
       assertTrue(!zkWatchAccessor.getWatchedCollections().contains(TEST_COLLECTION));
       new QueryRequest(new SolrQuery("*:*"))
           .setPreferredNodes(List.of(coordinatorJetty.getNodeName()))
-          .process(client, TEST_COLLECTION);
+          .process(client, TEST_COLLECTION); // ok no exception thrown
 
       // now it should be watching it after the query
       assertTrue(zkWatchAccessor.getWatchedCollections().contains(TEST_COLLECTION));
 
       CollectionAdminRequest.deleteReplica(TEST_COLLECTION, "shard1", 1).process(client);
       cluster.waitForActiveCollection(TEST_COLLECTION, 1, 1);
+      new QueryRequest(new SolrQuery("*:*"))
+          .setPreferredNodes(List.of(coordinatorJetty.getNodeName()))
+          .process(client, TEST_COLLECTION); // ok no exception thrown
 
       // still one replica left, should not remove the watch
       assertTrue(zkWatchAccessor.getWatchedCollections().contains(TEST_COLLECTION));
 
       CollectionAdminRequest.deleteCollection(TEST_COLLECTION).process(client);
       zkStateReader.waitForState(TEST_COLLECTION, 30, TimeUnit.SECONDS, Objects::isNull);
+      assertNull(zkStateReader.getCollection(TEST_COLLECTION)); // check the cluster state
+
+      // ensure querying throws exception
+      assertExceptionThrownWithMessageContaining(
+          SolrException.class,
+          List.of("Collection not found"),
+          () ->
+              new QueryRequest(new SolrQuery("*:*"))
+                  .setPreferredNodes(List.of(coordinatorJetty.getNodeName()))
+                  .process(client, TEST_COLLECTION));
 
       // watch should be removed after collection deletion
       assertTrue(!zkWatchAccessor.getWatchedCollections().contains(TEST_COLLECTION));