You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2015/03/25 22:43:30 UTC
svn commit: r1669237 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/core/
solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
solr/core/src/java/org/apache/solr/util/SolrLogLayout.java
Author: shalin
Date: Wed Mar 25 21:43:29 2015
New Revision: 1669237
URL: http://svn.apache.org/r1669237
Log:
SOLR-6673: Log collection, shard, replica, core name for update and search requests
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/solr/ (props changed)
lucene/dev/branches/branch_5x/solr/core/ (props changed)
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/SolrLogLayout.java
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java?rev=1669237&r1=1669236&r2=1669237&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java Wed Mar 25 21:43:29 2015
@@ -36,6 +36,7 @@ import org.apache.http.impl.client.Close
import org.apache.http.util.EntityUtils;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.cloud.CloudDescriptor;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.Aliases;
@@ -307,14 +308,15 @@ public class SolrDispatchFilter extends
if (core != null) {
path = path.substring( idx );
- MDCUtils.setCore(core.getName());
+ addMDCValues(cores, core);
}
}
if (core == null) {
if (!cores.isZooKeeperAware() ) {
core = cores.getCore("");
- if (core != null)
- MDCUtils.setCore(core.getName());
+ if (core != null) {
+ addMDCValues(cores, core);
+ }
}
}
}
@@ -326,7 +328,7 @@ public class SolrDispatchFilter extends
if (core != null) {
// we found a core, update the path
path = path.substring( idx );
- MDCUtils.setCore(core.getName());
+ addMDCValues(cores, core);
}
// if we couldn't find it locally, look on other nodes
@@ -361,7 +363,7 @@ public class SolrDispatchFilter extends
// try the default core
if (core == null) {
core = cores.getCore("");
- MDCUtils.setCore(core.getName());
+ addMDCValues(cores, core);
}
}
@@ -491,6 +493,16 @@ public class SolrDispatchFilter extends
chain.doFilter(request, response);
}
+ private void addMDCValues(CoreContainer cores, SolrCore core) {
+ MDCUtils.setCore(core.getName());
+ if (cores.isZooKeeperAware()) {
+ CloudDescriptor cloud = core.getCoreDescriptor().getCloudDescriptor();
+ MDCUtils.setCollection(cloud.getCollectionName());
+ MDCUtils.setShard(cloud.getShardId());
+ MDCUtils.setReplica(cloud.getCoreNodeName());
+ }
+ }
+
private Map<String , Integer> checkStateIsValid(CoreContainer cores, String stateVer) {
Map<String, Integer> result = null;
String[] pairs = null;
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/SolrLogLayout.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/SolrLogLayout.java?rev=1669237&r1=1669236&r2=1669237&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/SolrLogLayout.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/SolrLogLayout.java Wed Mar 25 21:43:29 2015
@@ -11,10 +11,9 @@ import org.apache.log4j.spi.LoggingEvent
import org.apache.log4j.spi.ThrowableInformation;
import org.apache.solr.cloud.ZkController;
import org.apache.solr.common.SolrException;
+import org.apache.solr.common.StringUtils;
import org.apache.solr.common.cloud.Replica;
-import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.core.SolrCore;
-import org.apache.solr.logging.MDCUtils;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestInfo;
import org.slf4j.MDC;
@@ -371,14 +370,17 @@ public class SolrLogLayout extends Layou
private void appendMDC(StringBuilder sb) {
- sb.append(" [" + getMDCValueOrEmpty(COLLECTION_PROP) + "] ");
- sb.append("[" + getMDCValueOrEmpty(SHARD_ID_PROP) + "] ");
- sb.append("[" + getMDCValueOrEmpty(REPLICA_PROP) + "] ");
- sb.append("[" + getMDCValueOrEmpty(CORE_NAME_PROP)+"] ");
- }
-
- private String getMDCValueOrEmpty(String key) {
- String val = MDC.get(key);
- return val==null? "": val;
+ if (!StringUtils.isEmpty(MDC.get(COLLECTION_PROP))) {
+ sb.append(" C:").append(MDC.get(COLLECTION_PROP));
+ }
+ if (!StringUtils.isEmpty(MDC.get(SHARD_ID_PROP))) {
+ sb.append(" S:").append(MDC.get(SHARD_ID_PROP));
+ }
+ if (!StringUtils.isEmpty(MDC.get(REPLICA_PROP))) {
+ sb.append(" R:").append(MDC.get(REPLICA_PROP));
+ }
+ if (!StringUtils.isEmpty(MDC.get(CORE_NAME_PROP))) {
+ sb.append(" c:").append(MDC.get(CORE_NAME_PROP));
+ }
}
}