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/04 18:46:46 UTC

svn commit: r1227236 - in /lucene/dev/branches/solrcloud/solr: core/src/java/org/apache/solr/update/TransactionLog.java core/src/java/org/apache/solr/update/UpdateLog.java solrj/src/java/org/apache/solr/common/util/FastInputStream.java

Author: yonik
Date: Wed Jan  4 17:46:45 2012
New Revision: 1227236

URL: http://svn.apache.org/viewvc?rev=1227236&view=rev
Log:
don't create separate tlog to recover from, use one from old log list, seek to end when opening existing file so we can append correctly

Modified:
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.java
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/UpdateLog.java
    lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/util/FastInputStream.java

Modified: lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.java?rev=1227236&r1=1227235&r2=1227236&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.java (original)
+++ lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.java Wed Jan  4 17:46:45 2012
@@ -144,7 +144,10 @@ public class TransactionLog {
       if (openExisting) {
         if (start > 0) {
           readHeader(null);
+          raf.seek(start);
+          assert channel.position() == start;
           fos.setWritten(start);    // reflect that we aren't starting at the beginning
+          assert fos.size() == channel.size();
         } else {
           addGlobalStrings(globalStrings);
         }
@@ -356,7 +359,7 @@ public class TransactionLog {
     synchronized (this) {
       try {
         long pos = fos.size();   // if we had flushed, this should be equal to channel.position()
-        log.error("COMMIT STARTING AT " + pos);   // nocommit
+
         if (pos == 0) {
           writeLogHeader(codec);
           pos = fos.size();
@@ -367,12 +370,10 @@ public class TransactionLog {
         codec.writeLong(cmd.getVersion());
         codec.writeStr(END_MESSAGE);  // ensure these bytes are (almost) last in the file
 
-        log.error("COMMIT STARTING AT " + pos + " ENDING AT " +fos.size());
-
         endRecord(pos);
         
-        fos.flush();  // flush since this will be the last record in a log file
-        log.error("COMMIT END BACK POINTER RECORD AT" +fos.size());
+        fos.flush();  // flush since this will be the last record in a log fill
+        assert fos.size() == channel.size();
 
         return pos;
       } catch (IOException e) {
@@ -416,6 +417,10 @@ public class TransactionLog {
     }
   }
 
+  public boolean try_incref() {
+    return refcount.incrementAndGet() > 1;
+  }
+
   public void decref() {
     if (refcount.decrementAndGet() == 0) {
       close();
@@ -451,7 +456,7 @@ public class TransactionLog {
   private void close() {
     try {
       if (debug) {
-        log.debug("Closing " + this);
+        log.debug("Closing tlog" + this);
       }
 
       fos.flush();
@@ -558,6 +563,7 @@ public class TransactionLog {
       synchronized (TransactionLog.this) {
         fos.flushBuffer();
         sz = fos.size();
+        assert sz == channel.size();
       }
 
       fis = new ChannelFastInputStream(channel, 0);

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=1227236&r1=1227235&r2=1227236&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 Wed Jan  4 17:46:45 2012
@@ -74,6 +74,7 @@ public class UpdateLog implements Plugin
   private TransactionLog tlog;
   private TransactionLog prevTlog;
   private Deque<TransactionLog> logs = new LinkedList<TransactionLog>();  // list of recent logs, newest first
+  private TransactionLog newestLogOnStartup;
   private int numOldRecords;  // number of records in the recent logs
 
   private Map<BytesRef,LogPtr> map = new HashMap<BytesRef, LogPtr>();
@@ -145,11 +146,13 @@ public class UpdateLog implements Plugin
     tlogFiles = getLogList(tlogDir);
     id = getLastLogId() + 1;   // add 1 since we will create a new log for the next update
 
+    TransactionLog oldLog = null;
     for (String oldLogName : tlogFiles) {
       // TODO: what about an uncompleted tlog file?
-      TransactionLog oldLog = new TransactionLog( new File(tlogDir, oldLogName), null, true );
+      oldLog = new TransactionLog( new File(tlogDir, oldLogName), null, true );
       addOldLog(oldLog);
     }
+    newestLogOnStartup = oldLog;
 
     versionInfo = new VersionInfo(uhandler, 256);
   }
@@ -495,19 +498,24 @@ public class UpdateLog implements Plugin
 
   public Future<RecoveryInfo> recoverFromLog() {
     recoveryInfo = new RecoveryInfo();
-    if (tlogFiles.length == 0) return null;
-    TransactionLog oldTlog = null;
+    if (newestLogOnStartup == null) return null;
 
-    oldTlog = new TransactionLog( new File(tlogDir, tlogFiles[tlogFiles.length-1]), null, true );
+    if (!newestLogOnStartup.try_incref()) return null;   // log file was already closed
+
+    // now that we've incremented the reference, the log shouldn't go away.
     try {
-      if (oldTlog.endsWithCommit()) return null;
+      if (newestLogOnStartup.endsWithCommit()) {
+        newestLogOnStartup.decref();
+        return null;
+      }
     } catch (IOException e) {
-      log.error("Error inspecting tlog " + oldTlog);
+      log.error("Error inspecting tlog " + newestLogOnStartup);
+      newestLogOnStartup.decref();
       return null;
     }
 
     ExecutorCompletionService<RecoveryInfo> cs = new ExecutorCompletionService<RecoveryInfo>(recoveryExecutor);
-    LogReplayer replayer = new LogReplayer(oldTlog, false);
+    LogReplayer replayer = new LogReplayer(newestLogOnStartup, false);
 
     versionInfo.blockUpdates();
     try {

Modified: lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/util/FastInputStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/util/FastInputStream.java?rev=1227236&r1=1227235&r2=1227236&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/util/FastInputStream.java (original)
+++ lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/util/FastInputStream.java Wed Jan  4 17:46:45 2012
@@ -68,7 +68,9 @@ public class FastInputStream extends Inp
   public int readUnsignedByte() throws IOException {
     if (pos >= end) {
       refill();
-      if (pos >= end) throw new EOFException();
+      if (pos >= end) {
+        throw new EOFException();
+      }
     }
     return buf[pos++] & 0xff;
   }