lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1242918 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/src/test/org/apache/lucene/index/ lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/ lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/direc...
Date Fri, 10 Feb 2012 20:57:44 GMT
Author: mikemccand
Date: Fri Feb 10 20:57:43 2012
New Revision: 1242918

URL: http://svn.apache.org/viewvc?rev=1242918&view=rev
Log:
LUCENE-3760: clean up IndexReader/SegmentInfos APIs

Removed:
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestAllZerosSegmentsFile.java
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestDeletionPolicy.java
Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/CHANGES.txt
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReader.java
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
    lucene/dev/branches/branch_3x/lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.java
    lucene/dev/branches/branch_3x/lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java
    lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
    lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
    lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java
    lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
    lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexReader.java
    lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
    lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestAllZerosSegmentsFile.java
    lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestDeletionPolicy.java
    lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestIndexReader.java
    lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java

Modified: lucene/dev/branches/branch_3x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/CHANGES.txt?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/lucene/CHANGES.txt Fri Feb 10 20:57:43 2012
@@ -59,6 +59,11 @@ Changes in backwards compatibility polic
   
 * LUCENE-3712: Removed unused and untested ReaderUtil#subReader methods.
   (Uwe Schindler)
+
+* LUCENE-3760: In IndexReader/DirectoryReader, deprecate static
+  methods getCurrentVersion and getCommitUserData, and non-static
+  method getCommitUserData (use getIndexCommit().getUserData()
+  instead).  (Ryan McKinley, Robert Muir, Mike McCandless)
   
 * LUCENE-3672: Deprecate Directory.fileModified,
   IndexCommit.getTimestamp and .getVersion and

Modified: lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReader.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReader.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReader.java
Fri Feb 10 20:57:43 2012
@@ -75,8 +75,6 @@ public class TestIndexReader extends Luc
       IndexReader r2 = IndexReader.open(d, false);
       assertEquals(c.getUserData(), commitUserData);
 
-      assertEquals(sis.getCurrentSegmentFileName(), c.getSegmentsFileName());
-
       // Change the index
       writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
           new MockAnalyzer(random)).setOpenMode(
@@ -826,8 +824,6 @@ public class TestIndexReader extends Luc
       IndexReader r = IndexReader.open(d, false);
       IndexCommit c = r.getIndexCommit();
 
-      assertEquals(sis.getCurrentSegmentFileName(), c.getSegmentsFileName());
-
       assertTrue(c.equals(r.getIndexCommit()));
 
       // Change the index

Modified: lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
Fri Feb 10 20:57:43 2012
@@ -958,206 +958,6 @@ public class TestIndexWriterExceptions e
     dir.close();
   }
   
-  // LUCENE-1044: Simulate checksum error in segments_N
-  public void testSegmentsChecksumError() throws IOException {
-    Directory dir = newDirectory();
-
-    IndexWriter writer = null;
-
-    writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)));
-
-    // add 100 documents
-    for (int i = 0; i < 100; i++) {
-      addDoc(writer);
-    }
-
-    // close
-    writer.close();
-
-    long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
-    assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
-
-    final String segmentsFileName = SegmentInfos.getCurrentSegmentFileName(dir);
-    IndexInput in = dir.openInput(segmentsFileName);
-    IndexOutput out = dir.createOutput(IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
"", 1+gen));
-    out.copyBytes(in, in.length()-1);
-    byte b = in.readByte();
-    out.writeByte((byte) (1+b));
-    out.close();
-    in.close();
-
-    IndexReader reader = null;
-    try {
-      reader = IndexReader.open(dir, true);
-    } catch (IOException e) {
-      e.printStackTrace(System.out);
-      fail("segmentInfos failed to retry fallback to correct segments_N file");
-    }
-    reader.close();
-    dir.close();
-  }
-  
-  // Simulate a corrupt index by removing last byte of
-  // latest segments file and make sure we get an
-  // IOException trying to open the index:
-  public void testSimulatedCorruptIndex1() throws IOException {
-      MockDirectoryWrapper dir = newDirectory();
-      dir.setCheckIndexOnClose(false); // we are corrupting it!
-
-      IndexWriter writer = null;
-
-      writer  = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)));
-
-      // add 100 documents
-      for (int i = 0; i < 100; i++) {
-          addDoc(writer);
-      }
-
-      // close
-      writer.close();
-
-      long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
-      assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
-
-      String fileNameIn = SegmentInfos.getCurrentSegmentFileName(dir);
-      String fileNameOut = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
-                                                                 "",
-                                                                 1+gen);
-      IndexInput in = dir.openInput(fileNameIn);
-      IndexOutput out = dir.createOutput(fileNameOut);
-      long length = in.length();
-      for(int i=0;i<length-1;i++) {
-        out.writeByte(in.readByte());
-      }
-      in.close();
-      out.close();
-      dir.deleteFile(fileNameIn);
-
-      IndexReader reader = null;
-      try {
-        reader = IndexReader.open(dir, true);
-        fail("reader did not hit IOException on opening a corrupt index");
-      } catch (Exception e) {
-      }
-      if (reader != null) {
-        reader.close();
-      }
-      dir.close();
-  }
-  
-  // Simulate a corrupt index by removing one of the cfs
-  // files and make sure we get an IOException trying to
-  // open the index:
-  public void testSimulatedCorruptIndex2() throws IOException {
-      MockDirectoryWrapper dir = newDirectory();
-      dir.setCheckIndexOnClose(false); // we are corrupting it!
-      IndexWriter writer = null;
-
-      writer  = new IndexWriter(
-          dir,
-          newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).
-              setMergePolicy(newLogMergePolicy(true))
-      );
-      ((LogMergePolicy) writer.getConfig().getMergePolicy()).setNoCFSRatio(1.0);
-
-      // add 100 documents
-      for (int i = 0; i < 100; i++) {
-          addDoc(writer);
-      }
-
-      // close
-      writer.close();
-
-      long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
-      assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
-
-      String[] files = dir.listAll();
-      boolean corrupted = false;
-      for(int i=0;i<files.length;i++) {
-        if (files[i].endsWith(".cfs")) {
-          dir.deleteFile(files[i]);
-          corrupted = true;
-          break;
-        }
-      }
-      assertTrue("failed to find cfs file to remove", corrupted);
-
-      IndexReader reader = null;
-      try {
-        reader = IndexReader.open(dir, true);
-        fail("reader did not hit IOException on opening a corrupt index");
-      } catch (Exception e) {
-      }
-      if (reader != null) {
-        reader.close();
-      }
-      dir.close();
-  }
-  
-  // Simulate a writer that crashed while writing segments
-  // file: make sure we can still open the index (ie,
-  // gracefully fallback to the previous segments file),
-  // and that we can add to the index:
-  public void testSimulatedCrashedWriter() throws IOException {
-      MockDirectoryWrapper dir = newDirectory();
-      dir.setPreventDoubleWrite(false);
-
-      IndexWriter writer = null;
-
-      writer  = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)));
-
-      // add 100 documents
-      for (int i = 0; i < 100; i++) {
-          addDoc(writer);
-      }
-
-      // close
-      writer.close();
-
-      long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
-      assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
-
-      // Make the next segments file, with last byte
-      // missing, to simulate a writer that crashed while
-      // writing segments file:
-      String fileNameIn = SegmentInfos.getCurrentSegmentFileName(dir);
-      String fileNameOut = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
-                                                                 "",
-                                                                 1+gen);
-      IndexInput in = dir.openInput(fileNameIn);
-      IndexOutput out = dir.createOutput(fileNameOut);
-      long length = in.length();
-      for(int i=0;i<length-1;i++) {
-        out.writeByte(in.readByte());
-      }
-      in.close();
-      out.close();
-
-      IndexReader reader = null;
-      try {
-        reader = IndexReader.open(dir, true);
-      } catch (Exception e) {
-        fail("reader failed to open on a crashed index");
-      }
-      reader.close();
-
-      try {
-        writer  = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.CREATE));
-      } catch (Exception e) {
-        e.printStackTrace(System.out);
-        fail("writer failed to open on a crashed index");
-      }
-
-      // add 100 documents
-      for (int i = 0; i < 100; i++) {
-          addDoc(writer);
-      }
-
-      // close
-      writer.close();
-      dir.close();
-  }
-
   public void testAddDocsNonAbortingException() throws Exception {
     final Directory dir = newDirectory();
     final RandomIndexWriter w = new RandomIndexWriter(random, dir);

Modified: lucene/dev/branches/branch_3x/lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.java
Fri Feb 10 20:57:43 2012
@@ -242,7 +242,7 @@ public interface TaxonomyReader extends 
    * Retrieve user committed data.
    * @see TaxonomyWriter#commit(Map)
    */
-  public Map<String, String> getCommitUserData();
+  public Map<String, String> getCommitUserData() throws IOException;
 
   /**
    * Expert: increments the refCount of this TaxonomyReader instance. 

Modified: lucene/dev/branches/branch_3x/lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java
Fri Feb 10 20:57:43 2012
@@ -353,8 +353,8 @@ public class DirectoryTaxonomyReader imp
     
     // validate that a refresh is valid at this point, i.e. that the taxonomy 
     // was not recreated since this reader was last opened or refresshed.
-    String t1 = indexReader.getCommitUserData().get(DirectoryTaxonomyWriter.INDEX_CREATE_TIME);
-    String t2 = r2.getCommitUserData().get(DirectoryTaxonomyWriter.INDEX_CREATE_TIME);
+    String t1 = indexReader.getIndexCommit().getUserData().get(DirectoryTaxonomyWriter.INDEX_CREATE_TIME);
+    String t2 = r2.getIndexCommit().getUserData().get(DirectoryTaxonomyWriter.INDEX_CREATE_TIME);
     if (t1==null) {
     	if (t2!=null) {
     		r2.close();
@@ -442,9 +442,9 @@ public class DirectoryTaxonomyReader imp
     }
   }
 
-  public Map<String, String> getCommitUserData() {
+  public Map<String, String> getCommitUserData() throws IOException {
     ensureOpen();
-    return indexReader.getCommitUserData();
+    return indexReader.getIndexCommit().getUserData();
   }
   
   private ChildrenArrays childrenArrays;

Modified: lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
Fri Feb 10 20:57:43 2012
@@ -80,7 +80,7 @@ public class TestDirectoryTaxonomyWriter
     ltw.close();
     IndexReader r = IndexReader.open(dir);
     assertEquals("2 categories plus root should have been committed to the underlying directory",
3, r.numDocs());
-    Map <String, String> readUserCommitData = r.getCommitUserData();
+    Map <String, String> readUserCommitData = r.getIndexCommit().getUserData();
     assertTrue("wrong value extracted from commit data", 
         "1 2 3".equals(readUserCommitData.get("testing")));
     r.close();

Modified: lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
Fri Feb 10 20:57:43 2012
@@ -357,7 +357,7 @@ public class CheckIndex {
     }
     
     final int numSegments = sis.size();
-    final String segmentsFileName = sis.getCurrentSegmentFileName();
+    final String segmentsFileName = sis.getSegmentsFileName();
     IndexInput input = null;
     try {
       input = dir.openInput(segmentsFileName);
@@ -1035,7 +1035,7 @@ public class CheckIndex {
         System.out.println("Writing...");
         checker.fixIndex(result);
         System.out.println("OK");
-        System.out.println("Wrote new segments file \"" + result.newSegments.getCurrentSegmentFileName()
+ "\"");
+        System.out.println("Wrote new segments file \"" + result.newSegments.getSegmentsFileName()
+ "\"");
       }
     }
     System.out.println("");

Modified: lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java
Fri Feb 10 20:57:43 2012
@@ -297,7 +297,7 @@ class DirectoryReader extends IndexReade
     }
     buffer.append(getClass().getSimpleName());
     buffer.append('(');
-    final String segmentsFile = segmentInfos.getCurrentSegmentFileName();
+    final String segmentsFile = segmentInfos.getSegmentsFileName();
     if (segmentsFile != null) {
       buffer.append(segmentsFile);
     }
@@ -464,7 +464,7 @@ class DirectoryReader extends IndexReade
       if (directory != commit.getDirectory()) {
         throw new IOException("the specified commit does not match the specified Directory");
       }
-      if (segmentInfos != null && commit.getSegmentsFileName().equals(segmentInfos.getCurrentSegmentFileName()))
{
+      if (segmentInfos != null && commit.getSegmentsFileName().equals(segmentInfos.getSegmentsFileName()))
{
         if (readOnly != openReadOnly) {
           // Just fallback to clone
           return clone(openReadOnly);
@@ -1005,7 +1005,7 @@ class DirectoryReader extends IndexReade
     private final int segmentCount;
 
     ReaderCommit(SegmentInfos infos, Directory dir) throws IOException {
-      segmentsFileName = infos.getCurrentSegmentFileName();
+      segmentsFileName = infos.getSegmentsFileName();
       this.dir = dir;
       userData = infos.getUserData();
       files = Collections.unmodifiableCollection(infos.files(dir, true));

Modified: lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
Fri Feb 10 20:57:43 2012
@@ -139,7 +139,7 @@ final class IndexFileDeleter {
     this.infoStream = infoStream;
     this.writer = writer;
 
-    final String currentSegmentsFile = segmentInfos.getCurrentSegmentFileName();
+    final String currentSegmentsFile = segmentInfos.getSegmentsFileName();
 
     if (infoStream != null) {
       message("init: current segments file is \"" + currentSegmentsFile + "\"; deletionPolicy="
+ policy);
@@ -233,7 +233,7 @@ final class IndexFileDeleter {
         throw new CorruptIndexException("failed to locate current segments_N file");
       }
       if (infoStream != null) {
-        message("forced open of current segments file " + segmentInfos.getCurrentSegmentFileName());
+        message("forced open of current segments file " + segmentInfos.getSegmentsFileName());
       }
       currentCommitPoint = new CommitPoint(commitsToDelete, directory, sis);
       commits.add(currentCommitPoint);
@@ -442,7 +442,7 @@ final class IndexFileDeleter {
     assert locked();
 
     if (infoStream != null) {
-      message("now checkpoint \"" + segmentInfos.getCurrentSegmentFileName() + "\" [" + segmentInfos.size()
+ " segments " + "; isCommit = " + isCommit + "]");
+      message("now checkpoint \"" + segmentInfos.getSegmentsFileName() + "\" [" + segmentInfos.size()
+ " segments " + "; isCommit = " + isCommit + "]");
     }
 
     // Try again now to delete any previously un-deletable
@@ -649,7 +649,7 @@ final class IndexFileDeleter {
       this.directory = directory;
       this.commitsToDelete = commitsToDelete;
       userData = segmentInfos.getUserData();
-      segmentsFileName = segmentInfos.getCurrentSegmentFileName();
+      segmentsFileName = segmentInfos.getSegmentsFileName();
       version = segmentInfos.getVersion();
       generation = segmentInfos.getGeneration();
       files = Collections.unmodifiableCollection(segmentInfos.files(directory, true));

Modified: lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexReader.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexReader.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexReader.java
Fri Feb 10 20:57:43 2012
@@ -933,7 +933,7 @@ public abstract class IndexReader implem
    * @return version number.
    * @throws CorruptIndexException if the index is corrupt
    * @throws IOException if there is a low-level IO error
-   * @deprecated Use {@link SegmentInfos#readCurrentVersion}.
+   * @deprecated Use {@link #getVersion} on an opened IndexReader.
    */
   @Deprecated
   public static long getCurrentVersion(Directory directory) throws CorruptIndexException,
IOException {
@@ -952,10 +952,15 @@ public abstract class IndexReader implem
    * @throws CorruptIndexException if the index is corrupt
    * @throws IOException if there is a low-level IO error
    *
-   * @see #getCommitUserData()
+   * @deprecated Call {@link
+   * #getIndexCommit} on an open IndexReader, and then call
+   * {@link IndexCommit#getUserData}.
    */
+  @Deprecated
   public static Map<String,String> getCommitUserData(Directory directory) throws CorruptIndexException,
IOException {
-    return SegmentInfos.readCurrentUserData(directory);
+    SegmentInfos sis = new SegmentInfos();
+    sis.read(directory);
+    return sis.getUserData();
   }
 
   /**
@@ -981,8 +986,10 @@ public abstract class IndexReader implem
    * IndexWriter#commit(Map)} has never been called for
    * this index.
    *
-   * @see #getCommitUserData(Directory)
+   * @deprecated Call {@link #getIndexCommit} and then call
+   * {@link IndexCommit#getUserData}.
    */
+  @Deprecated
   public Map<String,String> getCommitUserData() {
     throw new UnsupportedOperationException("This reader does not support this method.");
   }
@@ -1472,7 +1479,7 @@ public abstract class IndexReader implem
    * @param commitUserData Opaque Map (String -> String)
    *  that's recorded into the segments file in the index,
    *  and retrievable by {@link
-   *  IndexReader#getCommitUserData}.
+   *  IndexCommit#getUserData}.
    * @throws IOException
    * @deprecated Write support will be removed in Lucene 4.0.
    */

Modified: lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
Fri Feb 10 20:57:43 2012
@@ -3331,7 +3331,7 @@ public class IndexWriter implements Clos
    *  @param commitUserData Opaque Map (String->String)
    *  that's recorded into the segments file in the index,
    *  and retrievable by {@link
-   *  IndexReader#getCommitUserData}.  Note that when
+   *  IndexCommit#getUserData}.  Note that when
    *  IndexWriter commits itself during {@link #close}, the
    *  commitUserData is unchanged (just carried over from
    *  the prior commit).  If this is null then the previous
@@ -3484,11 +3484,13 @@ public class IndexWriter implements Clos
 
     if (pendingCommit != null) {
       try {
-        if (infoStream != null)
+        if (infoStream != null) {
     	  message("commit: pendingCommit != null");
+        }
         pendingCommit.finishCommit(directory);
-        if (infoStream != null)
-          message("commit: wrote segments file \"" + pendingCommit.getCurrentSegmentFileName()
+ "\"");
+        if (infoStream != null) {
+          message("commit: wrote segments file \"" + pendingCommit.getSegmentsFileName()
+ "\"");
+        }
         lastCommitChangeCount = pendingCommitChangeCount;
         segmentInfos.updateGeneration(pendingCommit);
         segmentInfos.setUserData(pendingCommit.getUserData());

Modified: lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
Fri Feb 10 20:57:43 2012
@@ -145,12 +145,12 @@ public final class SegmentInfos implemen
   }
 
   /**
-   * Get the generation (N) of the current segments_N file
-   * from a list of files.
+   * Get the generation of the most recent commit to the
+   * list of index files (N in the segments_N file).
    *
    * @param files -- array of file names to check
    */
-  public static long getCurrentSegmentGeneration(String[] files) {
+  public static long getLastCommitGeneration(String[] files) {
     if (files == null) {
       return -1;
     }
@@ -168,48 +168,48 @@ public final class SegmentInfos implemen
   }
 
   /**
-   * Get the generation (N) of the current segments_N file
-   * in the directory.
+   * Get the generation of the most recent commit to the
+   * index in this directory (N in the segments_N file).
    *
    * @param directory -- directory to search for the latest segments_N file
    */
-  public static long getCurrentSegmentGeneration(Directory directory) throws IOException
{
+  public static long getLastCommitGeneration(Directory directory) throws IOException {
     try {
-      return getCurrentSegmentGeneration(directory.listAll());
+      return getLastCommitGeneration(directory.listAll());
     } catch (NoSuchDirectoryException nsde) {
       return -1;
     }
   }
 
   /**
-   * Get the filename of the current segments_N file
-   * from a list of files.
+   * Get the filename of the segments_N file for the most
+   * recent commit in the list of index files.
    *
    * @param files -- array of file names to check
    */
 
-  public static String getCurrentSegmentFileName(String[] files) throws IOException {
+  public static String getLastCommitSegmentsFileName(String[] files) throws IOException {
     return IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
                                                  "",
-                                                 getCurrentSegmentGeneration(files));
+                                                 getLastCommitGeneration(files));
   }
 
   /**
-   * Get the filename of the current segments_N file
-   * in the directory.
+   * Get the filename of the segments_N file for the most
+   * recent commit to the index in this Directory.
    *
    * @param directory -- directory to search for the latest segments_N file
    */
-  public static String getCurrentSegmentFileName(Directory directory) throws IOException
{
+  public static String getLastCommitSegmentsFileName(Directory directory) throws IOException
{
     return IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
                                                  "",
-                                                 getCurrentSegmentGeneration(directory));
+                                                 getLastCommitGeneration(directory));
   }
 
   /**
    * Get the segments_N filename in use by this segment infos.
    */
-  public String getCurrentSegmentFileName() {
+  public String getSegmentsFileName() {
     return IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
                                                  "",
                                                  lastGeneration);
@@ -467,7 +467,10 @@ public final class SegmentInfos implemen
    * Current version number from segments file.
    * @throws CorruptIndexException if the index is corrupt
    * @throws IOException if there is a low-level IO error
+   * @deprecated Load the SegmentInfos and then call {@link
+   * #getVersion}.
    */
+  @Deprecated
   public static long readCurrentVersion(Directory directory)
     throws CorruptIndexException, IOException {
 
@@ -481,18 +484,6 @@ public final class SegmentInfos implemen
     return sis.version;
   }
 
-  /**
-   * Returns userData from latest segments file
-   * @throws CorruptIndexException if the index is corrupt
-   * @throws IOException if there is a low-level IO error
-   */
-  public static Map<String,String> readCurrentUserData(Directory directory)
-    throws CorruptIndexException, IOException {
-    SegmentInfos sis = new SegmentInfos();
-    sis.read(directory);
-    return sis.getUserData();
-  }
-
   /** If non-null, information about retries when loading
    * the segments file will be printed to this.
    */
@@ -611,7 +602,7 @@ public final class SegmentInfos implemen
           files = directory.listAll();
           
           if (files != null) {
-            genA = getCurrentSegmentGeneration(files);
+            genA = getLastCommitGeneration(files);
           }
           
           if (infoStream != null) {
@@ -844,7 +835,14 @@ public final class SegmentInfos implemen
   public Collection<String> files(Directory dir, boolean includeSegmentsFile) throws
IOException {
     HashSet<String> files = new HashSet<String>();
     if (includeSegmentsFile) {
-      files.add(getCurrentSegmentFileName());
+      final String segmentFileName = getSegmentsFileName();
+      if (segmentFileName != null) {
+        /*
+         * TODO: if lastGen == -1 we get might get null here it seems wrong to
+         * add null to the files set
+         */
+        files.add(segmentFileName);
+      }
     }
     final int size = size();
     for(int i=0;i<size;i++) {
@@ -938,7 +936,7 @@ public final class SegmentInfos implemen
 
   public String toString(Directory directory) {
     StringBuilder buffer = new StringBuilder();
-    buffer.append(getCurrentSegmentFileName()).append(": ");
+    buffer.append(getSegmentsFileName()).append(": ");
     final int count = size();
     for(int i = 0; i < count; i++) {
       if (i > 0) {

Modified: lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestAllZerosSegmentsFile.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestAllZerosSegmentsFile.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestAllZerosSegmentsFile.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestAllZerosSegmentsFile.java
Fri Feb 10 20:57:43 2012
@@ -32,7 +32,7 @@ public class TestAllZerosSegmentsFile ex
 
     String nextSegmentsFile = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
                                                                     "",
-                                                                    SegmentInfos.getCurrentSegmentGeneration(dir)+1);
+                                                                    SegmentInfos.getLastCommitGeneration(dir)+1);
     IndexOutput out = dir.createOutput(nextSegmentsFile);
     for(int idx=0;idx<8;idx++) {
       out.writeByte((byte) 0);

Modified: lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestDeletionPolicy.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestDeletionPolicy.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestDeletionPolicy.java
Fri Feb 10 20:57:43 2012
@@ -248,7 +248,7 @@ public class TestDeletionPolicy extends 
     // segments_N's that still exist are in fact within SECONDS
     // seconds of the last one's mod time, and, that I can
     // open a reader on each:
-    long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
+    long gen = SegmentInfos.getLastCommitGeneration(dir);
     
     String fileName = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
                                                             "",
@@ -359,7 +359,7 @@ public class TestDeletionPolicy extends 
       // Simplistic check: just verify all segments_N's still
       // exist, and, I can open a reader on each:
       dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
-      long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
+      long gen = SegmentInfos.getLastCommitGeneration(dir);
       while(gen > 0) {
         IndexReader reader = IndexReader.open(dir, true);
         reader.close();
@@ -582,7 +582,7 @@ public class TestDeletionPolicy extends 
       // Simplistic check: just verify only the past N segments_N's still
       // exist, and, I can open a reader on each:
       dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
-      long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
+      long gen = SegmentInfos.getLastCommitGeneration(dir);
       for(int i=0;i<N+1;i++) {
         try {
           IndexReader reader = IndexReader.open(dir, true);
@@ -689,7 +689,7 @@ public class TestDeletionPolicy extends 
 
       // Simplistic check: just verify only the past N segments_N's still
       // exist, and, I can open a reader on each:
-      long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
+      long gen = SegmentInfos.getLastCommitGeneration(dir);
 
       dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
       int expectedCount = 176;
@@ -802,7 +802,7 @@ public class TestDeletionPolicy extends 
 
       // Simplistic check: just verify only the past N segments_N's still
       // exist, and, I can open a reader on each:
-      long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
+      long gen = SegmentInfos.getLastCommitGeneration(dir);
 
       dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
       int expectedCount = 0;

Modified: lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestIndexReader.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestIndexReader.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestIndexReader.java
Fri Feb 10 20:57:43 2012
@@ -76,7 +76,7 @@ public class TestIndexReader extends Luc
       IndexReader r2 = IndexReader.open(d, false);
       assertEquals(c.getUserData(), commitUserData);
 
-      assertEquals(sis.getCurrentSegmentFileName(), c.getSegmentsFileName());
+      assertEquals(sis.getSegmentsFileName(), c.getSegmentsFileName());
 
       // Change the index
       writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
@@ -924,7 +924,7 @@ public class TestIndexReader extends Luc
       IndexReader r = IndexReader.open(d, false);
       IndexCommit c = r.getIndexCommit();
 
-      assertEquals(sis.getCurrentSegmentFileName(), c.getSegmentsFileName());
+      assertEquals(sis.getSegmentsFileName(), c.getSegmentsFileName());
 
       assertTrue(c.equals(r.getIndexCommit()));
 

Modified: lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java?rev=1242918&r1=1242917&r2=1242918&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
Fri Feb 10 20:57:43 2012
@@ -974,10 +974,10 @@ public class TestIndexWriterExceptions e
     // close
     writer.close();
 
-    long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
+    long gen = SegmentInfos.getLastCommitGeneration(dir);
     assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
 
-    final String segmentsFileName = SegmentInfos.getCurrentSegmentFileName(dir);
+    final String segmentsFileName = SegmentInfos.getLastCommitSegmentsFileName(dir);
     IndexInput in = dir.openInput(segmentsFileName);
     IndexOutput out = dir.createOutput(IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
"", 1+gen));
     out.copyBytes(in, in.length()-1);
@@ -1016,10 +1016,10 @@ public class TestIndexWriterExceptions e
       // close
       writer.close();
 
-      long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
+      long gen = SegmentInfos.getLastCommitGeneration(dir);
       assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
 
-      String fileNameIn = SegmentInfos.getCurrentSegmentFileName(dir);
+      String fileNameIn = SegmentInfos.getLastCommitSegmentsFileName(dir);
       String fileNameOut = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
                                                                  "",
                                                                  1+gen);
@@ -1068,7 +1068,7 @@ public class TestIndexWriterExceptions e
       // close
       writer.close();
 
-      long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
+      long gen = SegmentInfos.getLastCommitGeneration(dir);
       assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
 
       String[] files = dir.listAll();
@@ -1114,13 +1114,13 @@ public class TestIndexWriterExceptions e
       // close
       writer.close();
 
-      long gen = SegmentInfos.getCurrentSegmentGeneration(dir);
+      long gen = SegmentInfos.getLastCommitGeneration(dir);
       assertTrue("segment generation should be > 0 but got " + gen, gen > 0);
 
       // Make the next segments file, with last byte
       // missing, to simulate a writer that crashed while
       // writing segments file:
-      String fileNameIn = SegmentInfos.getCurrentSegmentFileName(dir);
+      String fileNameIn = SegmentInfos.getLastCommitSegmentsFileName(dir);
       String fileNameOut = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
                                                                  "",
                                                                  1+gen);



Mime
View raw message