Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-16861: Correct(override) MDC info for `CoordinatorHttpSolrCall` (#1753)

patsonluk5a41ff0c94e0
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 {