You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2012/01/19 03:49:28 UTC

svn commit: r1233151 - in /lucene/dev/branches/solrcloud/solr: core/src/java/org/apache/solr/update/processor/ core/src/test/org/apache/solr/search/ test-framework/src/java/org/apache/solr/

Author: yonik
Date: Thu Jan 19 02:49:27 2012
New Revision: 1233151

URL: http://svn.apache.org/viewvc?rev=1233151&view=rev
Log:
add deleteByQuery versions, expand tests

Modified:
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java
    lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java
    lucene/dev/branches/solrcloud/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java

Modified: lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java?rev=1233151&r1=1233150&r2=1233151&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java (original)
+++ lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java Thu Jan 19 02:49:27 2012
@@ -81,6 +81,7 @@ public class DistributedUpdateProcessor 
 
   private NamedList addsResponse = null;
   private NamedList deleteResponse = null;
+  private NamedList deleteByQueryResponse = null;
   private CharsRef scratch;
   
   private final SchemaField idField;
@@ -642,6 +643,15 @@ public class DistributedUpdateProcessor 
         }
       }
     }
+
+    if (returnVersions && rsp != null) {
+      if (deleteByQueryResponse == null) {
+        deleteByQueryResponse = new NamedList<String>();
+        rsp.add("deleteByQuery",deleteByQueryResponse);
+      }
+      deleteByQueryResponse.add(cmd.getQuery(), cmd.getVersion());
+    }
+
   }
 
   @Override

Modified: lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java?rev=1233151&r1=1233150&r2=1233151&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java (original)
+++ lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java Thu Jan 19 02:49:27 2012
@@ -213,7 +213,10 @@ public class TestRealTimeGet extends Sol
         ,"=={'doc':null}"
     );
 
-
+    version = addAndGetVersion(sdoc("id","2"), null);
+    long version2 = deleteByQueryAndGetVersion("id:2", null);
+    assertTrue(Math.abs(version2) > version );
+    
   }
 
 
@@ -299,7 +302,7 @@ public class TestRealTimeGet extends Sol
     final int commitPercent = 5 + random.nextInt(20);
     final int softCommitPercent = 30+random.nextInt(75); // what percent of the commits are soft
     final int deletePercent = 4+random.nextInt(25);
-    final int deleteByQueryPercent = 0;  // real-time get isn't currently supported with delete-by-query
+    final int deleteByQueryPercent = 1+random.nextInt(5);
     final int ndocs = 5 + (random.nextBoolean() ? random.nextInt(25) : random.nextInt(200));
     int nWriteThreads = 5 + random.nextInt(25);
 
@@ -533,7 +536,7 @@ public class TestRealTimeGet extends Sol
     final int commitPercent = 5 + random.nextInt(20);
     final int softCommitPercent = 30+random.nextInt(75); // what percent of the commits are soft
     final int deletePercent = 4+random.nextInt(25);
-    final int deleteByQueryPercent = 0;  // real-time get isn't currently supported with delete-by-query
+    final int deleteByQueryPercent = 1 + random.nextInt(5);
     final int ndocs = 5 + (random.nextBoolean() ? random.nextInt(25) : random.nextInt(200));
     int nWriteThreads = 5 + random.nextInt(25);
 
@@ -635,7 +638,20 @@ public class TestRealTimeGet extends Sol
 
                 verbose("deleting id", id, "val=",nextVal,"DONE");
               } else if (oper < commitPercent + deletePercent + deleteByQueryPercent) {
+                verbose("deleteByQyery id",id,"val=",nextVal);
+
+                Long version = deleteByQueryAndGetVersion("id:"+Integer.toString(id), null);
+                assertTrue(version < 0);
+
+                // only update model if the version is newer
+                synchronized (model) {
+                  DocInfo currInfo = model.get(id);
+                  if (Math.abs(version) > Math.abs(currInfo.version)) {
+                    model.put(id, new DocInfo(version, -nextVal));
+                  }
+                }
 
+                verbose("deleteByQyery id", id, "val=",nextVal,"DONE");
               } else {
                 verbose("adding id", id, "val=", nextVal);
 

Modified: lucene/dev/branches/solrcloud/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java?rev=1233151&r1=1233150&r2=1233151&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/branches/solrcloud/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java Thu Jan 19 02:49:27 2012
@@ -773,7 +773,7 @@ public abstract class SolrTestCaseJ4 ext
     return out.toString();
   }
 
-    /** Creates a JSON add command from a SolrInputDocument list.  Doesn't currently handle boosts. */
+    /** Creates a JSON delete command from an id list */
   public static String jsonDelId(Object... ids) {
     CharArr out = new CharArr();
     try {
@@ -794,6 +794,27 @@ public abstract class SolrTestCaseJ4 ext
   }
 
 
+  /** Creates a JSON deleteByQuery command */
+  public static String jsonDelQ(String... queries) {
+    CharArr out = new CharArr();
+    try {
+      out.append('{');
+      boolean first = true;
+      for (Object q : queries) {
+        if (first) first=false;
+        else out.append(',');
+        out.append("\"delete\":{\"query\":");
+        out.append(JSONUtil.toJSON(q));
+        out.append('}');
+      }
+      out.append('}');
+    } catch (IOException e) {
+      // should never happen
+    }
+    return out.toString();
+  }
+
+
   public static Long addAndGetVersion(SolrInputDocument sdoc, SolrParams params) throws Exception {
     String response = updateJ(jsonAdd(sdoc), params);
     Map rsp = (Map)ObjectBuilder.fromJSON(response);
@@ -810,6 +831,13 @@ public abstract class SolrTestCaseJ4 ext
     return (Long) lst.get(1);
   }
 
+  public static Long deleteByQueryAndGetVersion(String q, SolrParams params) throws Exception {
+    String response = updateJ(jsonDelQ(q), params);
+    Map rsp = (Map)ObjectBuilder.fromJSON(response);
+    List lst = (List)rsp.get("deleteByQuery");
+    if (lst == null || lst.size() == 0) return null;
+    return (Long) lst.get(1);
+  }
 
   /////////////////////////////////////////////////////////////////////////////////////
   //////////////////////////// random document / index creation ///////////////////////