You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2013/05/05 23:06:11 UTC

svn commit: r1479394 - in /lucene/dev/trunk/lucene/core/src: java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java

Author: mikemccand
Date: Sun May  5 21:06:10 2013
New Revision: 1479394

URL: http://svn.apache.org/r1479394
Log:
LUCENE-4976: add missing sync / delete old save files

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java?rev=1479394&r1=1479393&r2=1479394&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java Sun May  5 21:06:10 2013
@@ -19,6 +19,7 @@ package org.apache.lucene.index;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map.Entry;
@@ -201,6 +202,15 @@ public class PersistentSnapshotDeletionP
       }
     }
 
+    dir.sync(Collections.singletonList(fileName));
+    
+    if (nextWriteGen > 0) {
+      String lastSaveFile = SNAPSHOTS_PREFIX + (nextWriteGen-1);
+      if (dir.fileExists(lastSaveFile)) {
+        dir.deleteFile(lastSaveFile);
+      }
+    }
+
     nextWriteGen++;
   }
 

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java?rev=1479394&r1=1479393&r2=1479394&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java Sun May  5 21:06:10 2013
@@ -49,7 +49,7 @@ public class TestPersistentSnapshotDelet
   @Test
   public void testExistingSnapshots() throws Exception {
     int numSnapshots = 3;
-    Directory dir = newDirectory();
+    MockDirectoryWrapper dir = newMockDirectory();
     IndexWriter writer = new IndexWriter(dir, getConfig(random(), getDeletionPolicy(dir)));
     PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
     assertNull(psdp.getLastSaveFile());
@@ -57,6 +57,19 @@ public class TestPersistentSnapshotDelet
     assertNotNull(psdp.getLastSaveFile());
     writer.close();
 
+    // Make sure only 1 save file exists:
+    int count = 0;
+    for(String file : dir.listAll()) {
+      if (file.startsWith(PersistentSnapshotDeletionPolicy.SNAPSHOTS_PREFIX)) {
+        count++;
+      }
+    }
+    assertEquals(1, count);
+
+    // Make sure we fsync:
+    dir.crash();
+    dir.clearCrash();
+
     // Re-initialize and verify snapshots were persisted
     psdp = new PersistentSnapshotDeletionPolicy(
         new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND);