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

svn commit: r1478640 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/facet/ lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/ lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/

Author: shaie
Date: Fri May  3 03:58:55 2013
New Revision: 1478640

URL: http://svn.apache.org/r1478640
Log:
LUCENE-4972: DirectoryTaxonomyWriter makes a commit even if no changes were made

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
    lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java

Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1478640&r1=1478639&r2=1478640&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Fri May  3 03:58:55 2013
@@ -54,6 +54,9 @@ Bug Fixes
 
 * LUCENE-4974: CommitIndexTask was broken if no params were set. (Shai Erera)
 
+* LUCENE-4972: DirectoryTaxonomyWriter created empty commits even if no changes 
+  were made. (Shai Erera, Michael McCandless)
+  
 Optimizations
 
 * LUCENE-4938: Don't use an unnecessarily large priority queue in IndexSearcher

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java?rev=1478640&r1=1478639&r2=1478640&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java Fri May  3 03:58:55 2013
@@ -225,7 +225,7 @@ public class DirectoryTaxonomyWriter imp
       }
       // no commit data, or no epoch in it means an old taxonomy, so set its epoch to 1, for lack
       // of a better value.
-      indexEpoch = epochStr == null ? 1 : Long.parseLong(epochStr);
+      indexEpoch = epochStr == null ? 1 : Long.parseLong(epochStr, 16);
     }
     
     if (openMode == OpenMode.CREATE) {
@@ -355,8 +355,7 @@ public class DirectoryTaxonomyWriter imp
   @Override
   public synchronized void close() throws IOException {
     if (!isClosed) {
-      indexWriter.setCommitData(combinedCommitData(indexWriter.getCommitData()));
-      indexWriter.commit();
+      commit();
       doClose();
     }
   }
@@ -617,7 +616,11 @@ public class DirectoryTaxonomyWriter imp
   @Override
   public synchronized void commit() throws IOException {
     ensureOpen();
-    indexWriter.setCommitData(combinedCommitData(indexWriter.getCommitData()));
+    // LUCENE-4972: if we always call setCommitData, we create empty commits
+    String epochStr = indexWriter.getCommitData().get(INDEX_EPOCH);
+    if (epochStr == null || Long.parseLong(epochStr, 16) != indexEpoch) {
+      indexWriter.setCommitData(combinedCommitData(indexWriter.getCommitData()));
+    }
     indexWriter.commit();
   }
 
@@ -627,7 +630,7 @@ public class DirectoryTaxonomyWriter imp
     if (commitData != null) {
       m.putAll(commitData);
     }
-    m.put(INDEX_EPOCH, Long.toString(indexEpoch));
+    m.put(INDEX_EPOCH, Long.toString(indexEpoch, 16));
     return m;
   }
   
@@ -648,7 +651,11 @@ public class DirectoryTaxonomyWriter imp
   @Override
   public synchronized void prepareCommit() throws IOException {
     ensureOpen();
-    indexWriter.setCommitData(combinedCommitData(indexWriter.getCommitData()));
+    // LUCENE-4972: if we always call setCommitData, we create empty commits
+    String epochStr = indexWriter.getCommitData().get(INDEX_EPOCH);
+    if (epochStr == null || Long.parseLong(epochStr, 16) != indexEpoch) {
+      indexWriter.setCommitData(combinedCommitData(indexWriter.getCommitData()));
+    }
     indexWriter.prepareCommit();
   }
   

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java?rev=1478640&r1=1478639&r2=1478640&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java Fri May  3 03:58:55 2013
@@ -359,5 +359,58 @@ public class TestDirectoryTaxonomyWriter
     taxoWriter.close();
     dir.close();
   }
+
+  @Test
+  public void testCommitNoEmptyCommits() throws Exception {
+    // LUCENE-4972: DTW used to create empty commits even if no changes were made
+    Directory dir = newDirectory();
+    DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);
+    taxoWriter.addCategory(new CategoryPath("a"));
+    taxoWriter.commit();
+    
+    long gen1 = SegmentInfos.getLastCommitGeneration(dir);
+    taxoWriter.commit();
+    long gen2 = SegmentInfos.getLastCommitGeneration(dir);
+    assertEquals("empty commit should not have changed the index", gen1, gen2);
+    
+    taxoWriter.close();
+    dir.close();
+  }
+  
+  @Test
+  public void testCloseNoEmptyCommits() throws Exception {
+    // LUCENE-4972: DTW used to create empty commits even if no changes were made
+    Directory dir = newDirectory();
+    DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);
+    taxoWriter.addCategory(new CategoryPath("a"));
+    taxoWriter.commit();
+    
+    long gen1 = SegmentInfos.getLastCommitGeneration(dir);
+    taxoWriter.close();
+    long gen2 = SegmentInfos.getLastCommitGeneration(dir);
+    assertEquals("empty commit should not have changed the index", gen1, gen2);
+    
+    taxoWriter.close();
+    dir.close();
+  }
+  
+  @Test
+  public void testPrepareCommitNoEmptyCommits() throws Exception {
+    // LUCENE-4972: DTW used to create empty commits even if no changes were made
+    Directory dir = newDirectory();
+    DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);
+    taxoWriter.addCategory(new CategoryPath("a"));
+    taxoWriter.prepareCommit();
+    taxoWriter.commit();
+    
+    long gen1 = SegmentInfos.getLastCommitGeneration(dir);
+    taxoWriter.prepareCommit();
+    taxoWriter.commit();
+    long gen2 = SegmentInfos.getLastCommitGeneration(dir);
+    assertEquals("empty commit should not have changed the index", gen1, gen2);
+    
+    taxoWriter.close();
+    dir.close();
+  }
   
 }