You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rj...@apache.org on 2013/11/14 05:20:41 UTC
svn commit: r1541809 - in /lucene/dev/branches/branch_4x: ./ solr/
solr/core/ solr/core/src/java/org/apache/solr/core/
solr/core/src/java/org/apache/solr/handler/component/
solr/core/src/java/org/apache/solr/util/
solr/core/src/test/org/apache/solr/ so...
Author: rjernst
Date: Thu Nov 14 04:20:41 2013
New Revision: 1541809
URL: http://svn.apache.org/r1541809
Log:
SOLR-5399: Add distributed request tracking information to DebugComponent
Added:
lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
- copied unchanged from r1541774, lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/solr/ (props changed)
lucene/dev/branches/branch_4x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_4x/solr/core/ (props changed)
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CoreContainer.java
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/TestDistributedSearch.java
lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java
lucene/dev/branches/branch_4x/solr/solrj/ (props changed)
lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java
Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1541809&r1=1541808&r2=1541809&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Thu Nov 14 04:20:41 2013
@@ -37,6 +37,11 @@ Upgrading from Solr 4.6.0
Detailed Change List
----------------------
+Other Changes
+---------------------
+
+* SOLR-5399: Add distributed request tracking information to DebugComponent
+ (Tomás Fernández Löbbe via Ryan Ernst)
================== 4.6.0 ==================
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CoreContainer.java?rev=1541809&r1=1541808&r2=1541809&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CoreContainer.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CoreContainer.java Thu Nov 14 04:20:41 2013
@@ -17,27 +17,6 @@
package org.apache.solr.core;
-import com.google.common.collect.Maps;
-
-import org.apache.solr.cloud.ZkController;
-import org.apache.solr.cloud.ZkSolrResourceLoader;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.cloud.ZooKeeperException;
-import org.apache.solr.common.util.ExecutorUtil;
-import org.apache.solr.common.util.SolrjNamedThreadFactory;
-import org.apache.solr.handler.admin.CollectionsHandler;
-import org.apache.solr.handler.admin.CoreAdminHandler;
-import org.apache.solr.handler.admin.InfoHandler;
-import org.apache.solr.handler.component.ShardHandlerFactory;
-import org.apache.solr.logging.LogWatcher;
-import org.apache.solr.schema.IndexSchema;
-import org.apache.solr.schema.IndexSchemaFactory;
-import org.apache.solr.util.DefaultSolrThreadFactory;
-import org.apache.solr.util.FileUtils;
-import org.apache.zookeeper.KeeperException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.File;
@@ -67,6 +46,7 @@ import org.apache.solr.common.SolrExcept
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.ZooKeeperException;
import org.apache.solr.common.util.ExecutorUtil;
+import org.apache.solr.common.util.SolrjNamedThreadFactory;
import org.apache.solr.handler.admin.CollectionsHandler;
import org.apache.solr.handler.admin.CoreAdminHandler;
import org.apache.solr.handler.admin.InfoHandler;
@@ -120,6 +100,8 @@ public class CoreContainer {
protected final String solrHome;
protected final CoresLocator coresLocator;
+
+ private String hostName;
{
log.info("New CoreContainer " + System.identityHashCode(this));
@@ -224,6 +206,9 @@ public class CoreContainer {
if (shareSchema) {
indexSchemaCache = new ConcurrentHashMap<String,IndexSchema>();
}
+
+ hostName = cfg.getHost();
+ log.info("Host Name: " + hostName);
zkSys.initZooKeeper(this, solrHome, cfg);
@@ -899,6 +884,10 @@ public class CoreContainer {
public String getAdminPath() {
return cfg.getAdminPath();
}
+
+ public String getHostName() {
+ return this.hostName;
+ }
/**
* Gets the alternate path for multicore handling:
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java?rev=1541809&r1=1541808&r2=1541809&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java Thu Nov 14 04:20:41 2013
@@ -19,15 +19,26 @@ package org.apache.solr.handler.componen
import static org.apache.solr.common.params.CommonParams.FQ;
-import org.apache.solr.common.params.CommonParams;
-
import java.io.IOException;
import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.lucene.search.Query;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.QueryParsing;
import org.apache.solr.util.SolrPluginUtils;
@@ -41,10 +52,34 @@ public class DebugComponent extends Sear
{
public static final String COMPONENT_NAME = "debug";
+ /**
+ * A counter to ensure that no RID is equal, even if they fall in the same millisecond
+ */
+ private static final AtomicLong ridCounter = new AtomicLong();
+
+ /**
+ * Map containing all the possible stages as key and
+ * the corresponding readable purpose as value
+ */
+ private static final Map<Integer, String> stages;
+
+ static {
+ Map<Integer, String> map = new TreeMap<Integer, String>();
+ map.put(ResponseBuilder.STAGE_START, "START");
+ map.put(ResponseBuilder.STAGE_PARSE_QUERY, "PARSE_QUERY");
+ map.put(ResponseBuilder.STAGE_TOP_GROUPS, "TOP_GROUPS");
+ map.put(ResponseBuilder.STAGE_EXECUTE_QUERY, "EXECUTE_QUERY");
+ map.put(ResponseBuilder.STAGE_GET_FIELDS, "GET_FIELDS");
+ map.put(ResponseBuilder.STAGE_DONE, "DONE");
+ stages = Collections.unmodifiableMap(map);
+ }
+
@Override
public void prepare(ResponseBuilder rb) throws IOException
{
-
+ if(rb.isDebugTrack() && rb.isDistrib) {
+ doDebugTrack(rb);
+ }
}
@SuppressWarnings("unchecked")
@@ -52,7 +87,6 @@ public class DebugComponent extends Sear
public void process(ResponseBuilder rb) throws IOException
{
if( rb.isDebug() ) {
-
NamedList stdinfo = SolrPluginUtils.doStandardDebug( rb.req,
rb.getQueryString(), rb.getQuery(), rb.getResults().docList, rb.isDebugQuery(), rb.isDebugResults());
@@ -68,7 +102,7 @@ public class DebugComponent extends Sear
if (rb.isDebugQuery() && rb.getQparser() != null) {
rb.getQparser().addDebugInfo(rb.getDebugInfo());
}
-
+
if (null != rb.getDebugInfo() ) {
if (rb.isDebugQuery() && null != rb.getFilters() ) {
info.add("filter_queries",rb.req.getParams().getParams(FQ));
@@ -86,29 +120,68 @@ public class DebugComponent extends Sear
}
+ private void doDebugTrack(ResponseBuilder rb) {
+ SolrQueryRequest req = rb.req;
+ String rid = req.getParams().get(CommonParams.REQUEST_ID);
+ if(rid == null || "".equals(rid)) {
+ rid = generateRid(rb);
+ ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
+ params.add(CommonParams.REQUEST_ID, rid);//add rid to the request so that shards see it
+ req.setParams(params);
+ }
+ rb.addDebug(rid, "track", CommonParams.REQUEST_ID);//to see it in the response
+ rb.rsp.addToLog(CommonParams.REQUEST_ID, rid); //to see it in the logs of the landing core
+
+ }
+
+ private String generateRid(ResponseBuilder rb) {
+ String hostName = rb.req.getCore().getCoreDescriptor().getCoreContainer().getHostName();
+ return hostName + "-" + rb.req.getCore().getName() + "-" + System.currentTimeMillis() + "-" + ridCounter.getAndIncrement();
+ }
+
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
if (!rb.isDebug()) return;
-
+
// Turn on debug to get explain only when retrieving fields
if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
sreq.purpose |= ShardRequest.PURPOSE_GET_DEBUG;
if (rb.isDebugAll()) {
sreq.params.set(CommonParams.DEBUG_QUERY, "true");
- } else if (rb.isDebugQuery()){
- sreq.params.set(CommonParams.DEBUG, CommonParams.QUERY);
- } else if (rb.isDebugTimings()){
- sreq.params.set(CommonParams.DEBUG, CommonParams.TIMING);
- } else if (rb.isDebugResults()){
- sreq.params.set(CommonParams.DEBUG, CommonParams.RESULTS);
+ } else if (rb.isDebug()) {
+ if (rb.isDebugQuery()){
+ sreq.params.add(CommonParams.DEBUG, CommonParams.QUERY);
+ }
+ if (rb.isDebugTimings()){
+ sreq.params.add(CommonParams.DEBUG, CommonParams.TIMING);
+ }
+ if (rb.isDebugResults()){
+ sreq.params.add(CommonParams.DEBUG, CommonParams.RESULTS);
+ }
}
} else {
sreq.params.set(CommonParams.DEBUG_QUERY, "false");
}
+ if (rb.isDebugTrack()) {
+ sreq.params.add(CommonParams.DEBUG, CommonParams.TRACK);
+ sreq.params.set(CommonParams.REQUEST_ID, rb.req.getParams().get(CommonParams.REQUEST_ID));
+ sreq.params.set(CommonParams.REQUEST_PURPOSE, SolrPluginUtils.getRequestPurpose(sreq.purpose));
+ }
}
@Override
public void handleResponses(ResponseBuilder rb, ShardRequest sreq) {
+ if (rb.isDebugTrack() && rb.isDistrib && !rb.finished.isEmpty()) {
+ @SuppressWarnings("unchecked")
+ NamedList<Object> stageList = (NamedList<Object>) ((NamedList<Object>)rb.getDebugInfo().get("track")).get(stages.get(rb.stage));
+ if(stageList == null) {
+ stageList = new NamedList<Object>();
+ rb.addDebug(stageList, "track", stages.get(rb.stage));
+ }
+ for(ShardResponse response: sreq.responses) {
+ stageList.add(response.getShard(), getTrackResponse(response));
+ }
+ }
}
private Set<String> excludeSet = new HashSet<String>(Arrays.asList("explain"));
@@ -116,7 +189,7 @@ public class DebugComponent extends Sear
@Override
public void finishStage(ResponseBuilder rb) {
if (rb.isDebug() && rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
- NamedList<Object> info = null;
+ NamedList<Object> info = rb.getDebugInfo();
NamedList explain = new SimpleOrderedMap();
Map.Entry<String, Object>[] arr = new NamedList.NamedListEntry[rb.resultIds.size()];
@@ -165,9 +238,28 @@ public class DebugComponent extends Sear
rb.setDebugInfo(info);
rb.rsp.add("debug", rb.getDebugInfo() );
}
+
}
+ private NamedList<String> getTrackResponse(ShardResponse shardResponse) {
+ NamedList<String> namedList = new NamedList<String>();
+ NamedList<Object> responseNL = shardResponse.getSolrResponse().getResponse();
+ @SuppressWarnings("unchecked")
+ NamedList<Object> responseHeader = (NamedList<Object>)responseNL.get("responseHeader");
+ if(responseHeader != null) {
+ namedList.add("QTime", responseHeader.get("QTime").toString());
+ }
+ namedList.add("ElapsedTime", String.valueOf(shardResponse.getSolrResponse().getElapsedTime()));
+ namedList.add("RequestPurpose", shardResponse.getShardRequest().params.get(CommonParams.REQUEST_PURPOSE));
+ SolrDocumentList docList = (SolrDocumentList)shardResponse.getSolrResponse().getResponse().get("response");
+ if(docList != null) {
+ namedList.add("NumFound", String.valueOf(docList.getNumFound()));
+ }
+ namedList.add("Response", String.valueOf(responseNL));
+ return namedList;
+ }
+
Object merge(Object source, Object dest, Set<String> exclude) {
if (source == null) return dest;
if (dest == null) {
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java?rev=1541809&r1=1541808&r2=1541809&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java Thu Nov 14 04:20:41 2013
@@ -62,7 +62,7 @@ public class ResponseBuilder
private boolean needDocSet = false;
private int fieldFlags = 0;
//private boolean debug = false;
- private boolean debugTimings, debugQuery, debugResults;
+ private boolean debugTimings, debugQuery, debugResults, debugTrack;
private QParser qparser = null;
private String queryString = null;
@@ -212,7 +212,7 @@ public class ResponseBuilder
//-------------------------------------------------------------------------
public boolean isDebug() {
- return debugQuery || debugTimings || debugResults;
+ return debugQuery || debugTimings || debugResults || debugTrack;
}
/**
@@ -220,13 +220,22 @@ public class ResponseBuilder
* @return true if all debugging options are on
*/
public boolean isDebugAll(){
- return debugQuery && debugTimings && debugResults;
+ return debugQuery && debugTimings && debugResults && debugTrack;
}
-
+
public void setDebug(boolean dbg){
debugQuery = dbg;
debugTimings = dbg;
debugResults = dbg;
+ debugTrack = dbg;
+ }
+
+ public boolean isDebugTrack() {
+ return debugTrack;
+ }
+
+ public void setDebugTrack(boolean debugTrack) {
+ this.debugTrack = debugTrack;
}
public boolean isDebugTimings() {
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java?rev=1541809&r1=1541808&r2=1541809&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java Thu Nov 14 04:20:41 2013
@@ -17,6 +17,20 @@
package org.apache.solr.util;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.regex.Pattern;
+
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.BooleanClause;
@@ -37,6 +51,7 @@ import org.apache.solr.common.util.StrUt
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.component.HighlightComponent;
import org.apache.solr.handler.component.ResponseBuilder;
+import org.apache.solr.handler.component.ShardRequest;
import org.apache.solr.highlight.SolrHighlighter;
import org.apache.solr.parser.QueryParser;
import org.apache.solr.request.SolrQueryRequest;
@@ -56,18 +71,6 @@ import org.apache.solr.search.SolrIndexS
import org.apache.solr.search.SolrQueryParser;
import org.apache.solr.search.SyntaxError;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Pattern;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-
/**
* <p>Utilities that may be of use to RequestHandlers.</p>
*
@@ -82,6 +85,31 @@ import java.lang.reflect.InvocationTarge
* default parameter settings.
*/
public class SolrPluginUtils {
+
+
+ /**
+ * Map containing all the possible purposes codes of a request as key and
+ * the corresponding readable purpose as value
+ */
+ private static final Map<Integer, String> purposes;
+
+ static {
+ Map<Integer, String> map = new TreeMap<Integer, String>();
+ map.put(ShardRequest.PURPOSE_PRIVATE, "PRIVATE");
+ map.put(ShardRequest.PURPOSE_GET_TERM_DFS, "GET_TERM_DFS");
+ map.put(ShardRequest.PURPOSE_GET_TOP_IDS, "GET_TOP_IDS");
+ map.put(ShardRequest.PURPOSE_REFINE_TOP_IDS, "REFINE_TOP_IDS");
+ map.put(ShardRequest.PURPOSE_GET_FACETS, "GET_FACETS");
+ map.put(ShardRequest.PURPOSE_REFINE_FACETS, "REFINE_FACETS");
+ map.put(ShardRequest.PURPOSE_GET_FIELDS, "GET_FIELDS");
+ map.put(ShardRequest.PURPOSE_GET_HIGHLIGHTS, "GET_HIGHLIGHTS");
+ map.put(ShardRequest.PURPOSE_GET_DEBUG, "GET_DEBUG");
+ map.put(ShardRequest.PURPOSE_GET_STATS, "GET_STATS");
+ map.put(ShardRequest.PURPOSE_GET_TERMS, "GET_TERMS");
+ map.put(ShardRequest.PURPOSE_GET_TOP_GROUPS, "GET_TOP_GROUPS");
+ map.put(ShardRequest.PURPOSE_GET_MLT_RESULTS, "GET_MLT_RESULTS");
+ purposes = Collections.unmodifiableMap(map);
+ }
/**
* Set default-ish params on a SolrQueryRequest.
@@ -204,6 +232,8 @@ public class SolrPluginUtils {
rb.setDebugQuery(true);
} else if (params[i].equals(CommonParams.RESULTS)){
rb.setDebugResults(true);
+ } else if (params[i].equals(CommonParams.TRACK)){
+ rb.setDebugTrack(true);
}
}
}
@@ -262,6 +292,7 @@ public class SolrPluginUtils {
return dbg;
}
+
public static void doStandardQueryDebug(
SolrQueryRequest req,
String userQuery,
@@ -299,7 +330,6 @@ public class SolrPluginUtils {
dbg.add("explain", explainStruct
? explanationsToNamedLists(explain)
: explanationsToStrings(explain));
-
String otherQueryS = req.getParams().get(CommonParams.EXPLAIN_OTHER);
if (otherQueryS != null && otherQueryS.length() > 0) {
DocList otherResults = doSimpleQuery(otherQueryS, req, 0, 10);
@@ -642,6 +672,7 @@ public class SolrPluginUtils {
// Pattern to detect consecutive + and/or - operators
// \s+[+-](?:\s*[+-]+)+
private final static Pattern CONSECUTIVE_OP_PATTERN = Pattern.compile( "\\s+[+-](?:\\s*[+-]+)+" );
+ protected static final String UNKNOWN_VALUE = "Unknown";
/**
* Strips operators that are used illegally, otherwise returns its
@@ -930,6 +961,33 @@ public class SolrPluginUtils {
}
}
}
+
+
+
+ /**
+ * Given the integer purpose of a request generates a readable value corresponding
+ * the request purposes (there can be more than one on a single request). If
+ * there is a purpose parameter present that's not known this method will
+ * return {@value #UNKNOWN_VALUE}
+ * @param reqPurpose Numeric request purpose
+ * @return a comma separated list of purposes or {@value #UNKNOWN_VALUE}
+ */
+ public static String getRequestPurpose(Integer reqPurpose) {
+ if (reqPurpose != null) {
+ StringBuilder builder = new StringBuilder();
+ for (Map.Entry<Integer, String>entry : purposes.entrySet()) {
+ if ((reqPurpose & entry.getKey()) != 0) {
+ builder.append(entry.getValue() + ",");
+ }
+ }
+ if (builder.length() == 0) {
+ return UNKNOWN_VALUE;
+ }
+ builder.setLength(builder.length() - 1);
+ return builder.toString();
+ }
+ return UNKNOWN_VALUE;
+ }
}
Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/TestDistributedSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/TestDistributedSearch.java?rev=1541809&r1=1541808&r2=1541809&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/TestDistributedSearch.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/TestDistributedSearch.java Thu Nov 14 04:20:41 2013
@@ -113,6 +113,8 @@ public class TestDistributedSearch exten
vals[i] = "test " + i;
}
indexr(id, 17, "SubjectTerms_mfacet", vals);
+
+
for (int i=100; i<150; i++) {
indexr(id, i);
@@ -315,6 +317,7 @@ public class TestDistributedSearch exten
handle.put("explain", SKIPVAL); // internal docids differ, idf differs w/o global idf
handle.put("debug", UNORDERED);
handle.put("time", SKIPVAL);
+ handle.put("track", SKIP); //track is not included in single node search
query("q","now their fox sat had put","fl","*,score",CommonParams.DEBUG_QUERY, "true");
query("q", "id:[1 TO 5]", CommonParams.DEBUG_QUERY, "true");
query("q", "id:[1 TO 5]", CommonParams.DEBUG, CommonParams.TIMING);
Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java?rev=1541809&r1=1541808&r2=1541809&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java Thu Nov 14 04:20:41 2013
@@ -516,6 +516,7 @@ public class BasicDistributedZk2Test ext
handle.put("explain", SKIPVAL);
handle.put("debug", UNORDERED);
handle.put("time", SKIPVAL);
+ handle.put("track", SKIP);
query("q", "now their fox sat had put", "fl", "*,score",
CommonParams.DEBUG_QUERY, "true");
query("q", "id:[1 TO 5]", CommonParams.DEBUG_QUERY, "true");
Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java?rev=1541809&r1=1541808&r2=1541809&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java Thu Nov 14 04:20:41 2013
@@ -326,6 +326,7 @@ public class BasicDistributedZkTest exte
handle.put("explain", SKIPVAL);
handle.put("debug", UNORDERED);
handle.put("time", SKIPVAL);
+ handle.put("track", SKIP);
query(false, new Object[] {"q","now their fox sat had put","fl","*,score",CommonParams.DEBUG_QUERY, "true"});
query(false, new Object[] {"q", "id:[1 TO 5]", CommonParams.DEBUG_QUERY, "true"});
query(false, new Object[] {"q", "id:[1 TO 5]", CommonParams.DEBUG, CommonParams.TIMING});
Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java?rev=1541809&r1=1541808&r2=1541809&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java Thu Nov 14 04:20:41 2013
@@ -16,8 +16,18 @@ package org.apache.solr.handler.componen
* limitations under the License.
*/
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
+
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -139,4 +149,90 @@ public class DebugComponentTest extends
);
}
+
+ @Test
+ public void testModifyRequestTrack() {
+ DebugComponent component = new DebugComponent();
+ List<SearchComponent> components = new ArrayList<SearchComponent>(1);
+ components.add(component);
+ for(int i = 0; i < 10; i++) {
+ SolrQueryRequest req = req("q", "test query", "distrib", "true", CommonParams.REQUEST_ID, "123456-my_rid");
+ SolrQueryResponse resp = new SolrQueryResponse();
+ ResponseBuilder rb = new ResponseBuilder(req, resp, components);
+ ShardRequest sreq = new ShardRequest();
+ sreq.params = new ModifiableSolrParams();
+ sreq.purpose = ShardRequest.PURPOSE_GET_FIELDS;
+ sreq.purpose |= ShardRequest.PURPOSE_GET_DEBUG;
+ //expecting the same results with debugQuery=true or debug=track
+ if(random().nextBoolean()) {
+ rb.setDebug(true);
+ } else {
+ rb.setDebug(false);
+ rb.setDebugTrack(true);
+ //should not depend on other debug options
+ rb.setDebugQuery(random().nextBoolean());
+ rb.setDebugTimings(random().nextBoolean());
+ rb.setDebugResults(random().nextBoolean());
+ }
+ component.modifyRequest(rb, null, sreq);
+ //if the request has debugQuery=true or debug=track, the sreq should get debug=track always
+ assertTrue(Arrays.asList(sreq.params.getParams(CommonParams.DEBUG)).contains(CommonParams.TRACK));
+ //the purpose must be added as readable param to be included in the shard logs
+ assertEquals("GET_FIELDS,GET_DEBUG", sreq.params.get(CommonParams.REQUEST_PURPOSE));
+ //the rid must be added to be included in the shard logs
+ assertEquals("123456-my_rid", sreq.params.get(CommonParams.REQUEST_ID));
+ }
+
+ }
+
+ @Test
+ public void testPrepare() throws IOException {
+ DebugComponent component = new DebugComponent();
+ List<SearchComponent> components = new ArrayList<SearchComponent>(1);
+ components.add(component);
+ SolrQueryRequest req;
+ ResponseBuilder rb;
+ for(int i = 0; i < 10; i++) {
+ req = req("q", "test query", "distrib", "true");
+ rb = new ResponseBuilder(req, new SolrQueryResponse(), components);
+ rb.isDistrib = true;
+ //expecting the same results with debugQuery=true or debug=track
+ if(random().nextBoolean()) {
+ rb.setDebug(true);
+ } else {
+ rb.setDebug(false);
+ rb.setDebugTrack(true);
+ //should not depend on other debug options
+ rb.setDebugQuery(random().nextBoolean());
+ rb.setDebugTimings(random().nextBoolean());
+ rb.setDebugResults(random().nextBoolean());
+ }
+ component.prepare(rb);
+ ensureRidPresent(rb, null);
+ }
+
+ req = req("q", "test query", "distrib", "true", CommonParams.REQUEST_ID, "123");
+ rb = new ResponseBuilder(req, new SolrQueryResponse(), components);
+ rb.isDistrib = true;
+ rb.setDebug(true);
+ component.prepare(rb);
+ ensureRidPresent(rb, "123");
+ }
+
+ @SuppressWarnings("unchecked")
+ private void ensureRidPresent(ResponseBuilder rb, String expectedRid) {
+ SolrQueryRequest req = rb.req;
+ SolrQueryResponse resp = rb.rsp;
+ //a generated request ID should be added to the request
+ String rid = req.getParams().get(CommonParams.REQUEST_ID);
+ if(expectedRid == null) {
+ assertTrue(rid + " Doesn't match expected pattern.", Pattern.matches(".*-collection1-[0-9]*-[0-9]+", rid));
+ } else {
+ assertEquals("Expecting " + expectedRid + " but found " + rid, expectedRid, rid);
+ }
+ //The request ID is added to the debug/track section
+ assertEquals(rid, ((NamedList<Object>)rb.getDebugInfo().get("track")).get(CommonParams.REQUEST_ID));
+ //RID must be added to the toLog, so that it's included in the main request log
+ assertEquals(rid, resp.getToLog().get(CommonParams.REQUEST_ID));
+ }
}
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java?rev=1541809&r1=1541808&r2=1541809&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java Thu Nov 14 04:20:41 2013
@@ -122,7 +122,10 @@ public interface CommonParams {
* {@link #DEBUG} value indicating an interest in debug output related to the Query (parsing, etc.)
*/
public static final String QUERY = "query";
-
+ /**
+ * {@link #DEBUG} value indicating an interest in debug output related to the distributed tracking
+ */
+ public static final String TRACK = "track";
/**
* boolean indicating whether score explanations should structured (true),
* or plain text (false)
@@ -206,5 +209,15 @@ public interface CommonParams {
*/
public static final String COST = "cost";
+ /**
+ * Request ID parameter added to the request when using debug=track
+ */
+ public static final String REQUEST_ID = "rid";
+
+ /**
+ * Request Purpose parameter added to each internal shard request when using debug=track
+ */
+ public static final String REQUEST_PURPOSE = "requestPurpose";
+
}