lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1226575 - in /lucene/dev/branches/solrcloud/solr/core/src: java/org/apache/solr/update/UpdateLog.java test/org/apache/solr/search/TestRecovery.java
Date Mon, 02 Jan 2012 23:35:28 GMT
Author: yonik
Date: Mon Jan  2 23:35:28 2012
New Revision: 1226575

URL: http://svn.apache.org/viewvc?rev=1226575&view=rev
Log:
also use active logs for reporting last versions, add some test code

Modified:
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/UpdateLog.java
    lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/search/TestRecovery.java

Modified: lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/UpdateLog.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/UpdateLog.java?rev=1226575&r1=1226574&r2=1226575&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/UpdateLog.java
(original)
+++ lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/UpdateLog.java
Mon Jan  2 23:35:28 2012
@@ -73,7 +73,7 @@ public class UpdateLog implements Plugin
 
   private TransactionLog tlog;
   private TransactionLog prevTlog;
-  private Deque<TransactionLog> logs = new LinkedList<TransactionLog>();  //
list of recent logs
+  private Deque<TransactionLog> logs = new LinkedList<TransactionLog>();  //
list of recent logs, newest first
   private int numOldRecords;  // number of records in the recent logs
 
   private Map<BytesRef,LogPtr> map = new HashMap<BytesRef, LogPtr>();
@@ -166,14 +166,14 @@ public class UpdateLog implements Plugin
     }
 
     while (logs.size() > 0) {
-      TransactionLog log = logs.peekFirst();
+      TransactionLog log = logs.peekLast();
       int nrec = log.numRecords();
       // remove oldest log if we don't need it to keep at least numRecordsToKeep, or if
       // we already have the limit of 10 log files.
       if (currRecords - nrec >= numRecordsToKeep || logs.size() >= 10) {
         currRecords -= nrec;
         numOldRecords -= nrec;
-        logs.removeFirst().decref();  // dereference so it will be deleted when no longer
in use
+        logs.removeLast().decref();  // dereference so it will be deleted when no longer
in use
         continue;
       }
 
@@ -181,7 +181,7 @@ public class UpdateLog implements Plugin
     }
 
     oldLog.incref();  // prevent this from being deleted
-    logs.addLast(oldLog);
+    logs.addFirst(oldLog);
   }
 
 
@@ -542,9 +542,9 @@ public class UpdateLog implements Plugin
   }
 
 
-
+  // TODO: nocommit: decrement the references of the transaction logs at some point
   public class RecentUpdates {
-    Deque<TransactionLog> logList;
+    Deque<TransactionLog> logList;    // newest first
     List<List<LogPtr>> updates;
 
     public List<Long> getVersions(int n) {
@@ -626,6 +626,14 @@ public class UpdateLog implements Plugin
       for (TransactionLog log : logList) {
         log.incref();
       }
+      if (prevTlog != null) {
+        prevTlog.incref();
+        logList.addFirst(prevTlog);
+      }
+      if (tlog != null) {
+        tlog.incref();
+        logList.addFirst(tlog);
+      }
     }
 
     // TODO: what if I hand out a list of updates, then do an update, then hand out another
list (and

Modified: lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/search/TestRecovery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/search/TestRecovery.java?rev=1226575&r1=1226574&r2=1226575&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/search/TestRecovery.java
(original)
+++ lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/search/TestRecovery.java
Mon Jan  2 23:35:28 2012
@@ -185,8 +185,17 @@ public class TestRecovery extends SolrTe
       updateJ(jsonAdd(sdoc("id","2", "_version_","102")), params(SEEN_LEADER,SEEN_LEADER_VAL));
       updateJ(jsonAdd(sdoc("id","3", "_version_","103")), params(SEEN_LEADER,SEEN_LEADER_VAL));
       deleteAndGetVersion("1", params(SEEN_LEADER,SEEN_LEADER_VAL, "_version_","-201"));
+
+      assertJQ(req("qt","/get", "getVersions","4")
+          ,"=={'versions':[-201,103,102,101]}"
+      );
+
       assertU(commit());
 
+      assertJQ(req("qt","/get", "getVersions","4")
+          ,"=={'versions':[-201,103,102,101]}"
+      );
+
       // updates should be buffered, so we should not see any results yet.
       assertJQ(req("q", "*:*")
           , "/response/numFound==0"
@@ -210,6 +219,12 @@ public class TestRecovery extends SolrTe
       UpdateLog.RecoveryInfo rinfo = rinfoFuture.get();
       assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
 
+
+      assertJQ(req("qt","/get", "getVersions","4")
+          ,"=={'versions':[-201,103,102,101]}"
+      );
+
+
       assertJQ(req("q", "*:*")
           , "/response/numFound==2"
       );
@@ -235,6 +250,9 @@ public class TestRecovery extends SolrTe
       // currently buffered id:8 (even if it doesn't currently support versioning)
       updateJ("{\"delete\": { \"query\":\"id:2 OR id:8\" }}", params(SEEN_LEADER,SEEN_LEADER_VAL,
"_version_","-300"));
 
+      assertJQ(req("qt","/get", "getVersions","10")
+          ,"=={'versions':[-300,108,105,106,-94,104,3,-201,103,102]}"  // the "3" appears
because versions aren't checked while buffering
+      );
 
       logReplay.drainPermits();
       rinfoFuture = ulog.applyBufferedUpdates();



Mime
View raw message