SOLR-6673: Log collection, shard, replica, core name for update and search requests

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1669236 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2015-03-25 21:42:41 +00:00
parent b741482d58
commit ed325dc91c
2 changed files with 30 additions and 16 deletions

View File

@ -36,6 +36,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
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 BaseSolrFilter {
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 BaseSolrFilter {
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 BaseSolrFilter {
// 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 BaseSolrFilter {
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;

View File

@ -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 Layout {
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));
}
}
}