lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r1210782 - in /lucene/dev/branches/solrcloud/solr: core/src/java/org/apache/solr/handler/ core/src/java/org/apache/solr/update/ core/src/test/org/apache/solr/cloud/ solrj/src/java/org/apache/solr/client/solrj/request/
Date Tue, 06 Dec 2011 05:06:07 GMT
Author: markrmiller
Date: Tue Dec  6 05:06:07 2011
New Revision: 1210782

URL: http://svn.apache.org/viewvc?rev=1210782&view=rev
Log:
allow delete version to be specified in solr xml so that it can be propagated by the cmd distributor
- allows distrib delete to work - also enable a couple delete tests that where commented out
/ ignored

Modified:
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/handler/XMLLoader.java
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java
    lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/BasicFullDistributedZkTest.java
    lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/FullDistributedZkTest.java
    lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequestExt.java

Modified: lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/handler/XMLLoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/handler/XMLLoader.java?rev=1210782&r1=1210781&r2=1210782&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/handler/XMLLoader.java
(original)
+++ lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/handler/XMLLoader.java
Tue Dec  6 05:06:07 2011
@@ -204,12 +204,22 @@ class XMLLoader extends ContentStreamLoa
                     "unexpected XML tag /delete/" + mode);
           }
           text.setLength(0);
+          
+          if ("id".equals(mode)) {
+            for (int i = 0; i < parser.getAttributeCount(); i++) {
+              String attrName = parser.getAttributeLocalName(i);
+              String attrVal = parser.getAttributeValue(i);
+              if (XmlUpdateRequestHandler.VERSION.equals(attrName)) {
+                deleteCmd.setVersion(Long.parseLong(attrVal));
+              }
+            }
+          }
           break;
 
         case XMLStreamConstants.END_ELEMENT:
           String currTag = parser.getLocalName();
           if ("id".equals(currTag)) {
-            deleteCmd.setId(text.toString());
+            deleteCmd.setId(text.toString());         
           } else if ("query".equals(currTag)) {
             deleteCmd.setQuery(text.toString());
           } else if ("delete".equals(currTag)) {

Modified: lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java?rev=1210782&r1=1210781&r2=1210782&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java
(original)
+++ lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java
Tue Dec  6 05:06:07 2011
@@ -46,6 +46,8 @@ public class XmlUpdateRequestHandler ext
 
   public static final String OVERWRITE = "overwrite";
   
+  public static final String VERSION = "version";
+  
   // NOTE: This constant is for use with the <add> XML tag, not the HTTP param with
same name
   public static final String COMMIT_WITHIN = "commitWithin";
 

Modified: lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java?rev=1210782&r1=1210781&r2=1210782&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java
(original)
+++ lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java
Tue Dec  6 05:06:07 2011
@@ -242,7 +242,7 @@ public class SolrCmdDistributor {
     
     for (DeleteUpdateCommand cmd : dlist) {
       if (cmd.isDeleteById()) {
-        ureq.deleteById(cmd.getId());
+        ureq.deleteById(cmd.getId(), cmd.getVersion());
       } else {
         ureq.deleteByQuery(cmd.query);
       }

Modified: lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/BasicFullDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/BasicFullDistributedZkTest.java?rev=1210782&r1=1210781&r2=1210782&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/BasicFullDistributedZkTest.java
(original)
+++ lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/BasicFullDistributedZkTest.java
Tue Dec  6 05:06:07 2011
@@ -27,7 +27,6 @@ import org.junit.Ignore;
 /**
  * Super basic testing, no shard restarting or anything.
  */
-@Ignore("distrib delete not working yet")
 public class BasicFullDistributedZkTest extends FullDistributedZkTest {
   
   
@@ -44,9 +43,6 @@ public class BasicFullDistributedZkTest 
   
   @Override
   public void doTest() throws Exception {
-    // GRRRRR - this is needed because it takes a while for all the shards to learn about
the cluster state
-    Thread.sleep(5000);
-    
     handle.clear();
     handle.put("QTime", SKIPVAL);
     handle.put("timestamp", SKIPVAL);

Modified: lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/FullDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/FullDistributedZkTest.java?rev=1210782&r1=1210781&r2=1210782&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/FullDistributedZkTest.java
(original)
+++ lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/FullDistributedZkTest.java
Tue Dec  6 05:06:07 2011
@@ -692,39 +692,39 @@ public class FullDistributedZkTest exten
 
     assertDocCounts();
     
-//    String docId = "99999999";
-//    indexr("id", docId, t1, "originalcontent");
-//    
-//    commit();
-//    
-//    ModifiableSolrParams params = new ModifiableSolrParams();
-//    params.add("distrib", "true");
-//    params.add("q", t1 + ":originalcontent");
-//    QueryResponse results = clients.get(0).query(params);
-//    assertEquals(1, results.getResults().getNumFound());
-//    System.out.println("results:" + results);
-//    
-//    // update doc
-//    indexr("id", docId, t1, "updatedcontent");
-//    
-//    commit();
-//    
-//    results = clients.get(0).query(params);
-//    assertEquals(0, results.getResults().getNumFound());
-//    
-//    params.set("q", t1 + ":updatedcontent");
-//    
-//    results = clients.get(0).query(params);
-//    assertEquals(1, results.getResults().getNumFound());
-//    
-//    UpdateRequest uReq = new UpdateRequest();
-//    uReq.setParam(UpdateParams.UPDATE_CHAIN, DISTRIB_UPDATE_CHAIN);
-//    uReq.deleteById(docId).process(clients.get(0));
-//    
-//    commit();
-//    
-//    results = clients.get(0).query(params);
-//    assertEquals(0, results.getResults().getNumFound());
+    String docId = "99999999";
+    indexr("id", docId, t1, "originalcontent");
+    
+    commit();
+    
+    ModifiableSolrParams params = new ModifiableSolrParams();
+    params.add("distrib", "true");
+    params.add("q", t1 + ":originalcontent");
+    QueryResponse results = clients.get(0).query(params);
+    assertEquals(1, results.getResults().getNumFound());
+    System.out.println("results:" + results);
+    
+    // update doc
+    indexr("id", docId, t1, "updatedcontent");
+    
+    commit();
+    
+    results = clients.get(0).query(params);
+    assertEquals(0, results.getResults().getNumFound());
+    
+    params.set("q", t1 + ":updatedcontent");
+    
+    results = clients.get(0).query(params);
+    assertEquals(1, results.getResults().getNumFound());
+    
+    UpdateRequest uReq = new UpdateRequest();
+    uReq.setParam(UpdateParams.UPDATE_CHAIN, DISTRIB_UPDATE_CHAIN);
+    uReq.deleteById(docId).process(clients.get(0));
+    
+    commit();
+    
+    results = clients.get(0).query(params);
+    assertEquals(0, results.getResults().getNumFound());
     
     // expire a session...
     //CloudJettyRunner cloudJetty = shardToJetty.get("shard1").get(0);

Modified: lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequestExt.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequestExt.java?rev=1210782&r1=1210781&r2=1210782&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequestExt.java
(original)
+++ lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequestExt.java
Tue Dec  6 05:06:07 2011
@@ -22,7 +22,9 @@ import java.io.StringWriter;
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.solr.client.solrj.util.ClientUtils;
 import org.apache.solr.common.SolrInputDocument;
@@ -33,7 +35,7 @@ import org.apache.solr.common.util.XML;
 public class UpdateRequestExt extends AbstractUpdateRequest {
   
   private List<SolrDoc> documents = null;
-  private List<String> deleteById = null;
+  private Map<String,Long> deleteById = null;
   private List<String> deleteQuery = null;
   
   private class SolrDoc {
@@ -105,17 +107,27 @@ public class UpdateRequestExt extends Ab
   
   public UpdateRequestExt deleteById(String id) {
     if (deleteById == null) {
-      deleteById = new ArrayList<String>();
+      deleteById = new HashMap<String,Long>();
     }
-    deleteById.add(id);
+    deleteById.put(id, null);
+    return this;
+  }
+  
+  public UpdateRequestExt deleteById(String id, Long version) {
+    if (deleteById == null) {
+      deleteById = new HashMap<String,Long>();
+    }
+    deleteById.put(id, version);
     return this;
   }
   
   public UpdateRequestExt deleteById(List<String> ids) {
     if (deleteById == null) {
-      deleteById = new ArrayList<String>(ids);
+      deleteById = new HashMap<String,Long>();
     } else {
-      deleteById.addAll(ids);
+      for (String id : ids) {
+        deleteById.put(id, null);
+      }
     }
     return this;
   }
@@ -178,9 +190,15 @@ public class UpdateRequestExt extends Ab
     if (deleteI || deleteQ) {
       writer.append("<delete>");
       if (deleteI) {
-        for (String id : deleteById) {
-          writer.append("<id>");
-          XML.escapeCharData(id, writer);
+        for (Map.Entry<String,Long> entry : deleteById.entrySet()) {
+          writer.append("<id");
+          Long version = entry.getValue();
+          if (version != null) {
+            writer.append(" version=\"" + version + "\"");
+          }
+          writer.append(">");
+          
+          XML.escapeCharData(entry.getKey(), writer);
           writer.append("</id>");
         }
       }
@@ -216,8 +234,8 @@ public class UpdateRequestExt extends Ab
 
     return docLists;
   }
-  
-  public List<String> getDeleteById() {
+
+  public Map<String,Long> getDeleteById() {
     return deleteById;
   }
   



Mime
View raw message