You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rj...@apache.org on 2015/02/02 18:40:03 UTC

svn commit: r1656523 - in /lucene/dev/branches/branch_5x/lucene: ./ backward-codecs/src/test/org/apache/lucene/index/ core/src/java/org/apache/lucene/index/

Author: rjernst
Date: Mon Feb  2 17:40:03 2015
New Revision: 1656523

URL: http://svn.apache.org/r1656523
Log:
LUCENE-6213: Add useful exception message when commit contains segments from legacy codecs

Added:
    lucene/dev/branches/branch_5x/lucene/backward-codecs/src/test/org/apache/lucene/index/unsupported.4x-with-3x-segments.zip   (with props)
Modified:
    lucene/dev/branches/branch_5x/lucene/CHANGES.txt
    lucene/dev/branches/branch_5x/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java

Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1656523&r1=1656522&r2=1656523&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Mon Feb  2 17:40:03 2015
@@ -550,6 +550,9 @@ Other
 
 * LUCENE-5915: Remove Pulsing postings format. (Robert Muir)
 
+* LUCENE-6213: Add useful exception message when commit contains segments from legacy codecs.
+  (Ryan Ernst)
+
 ======================= Lucene 4.10.4 ======================
 
 * LUCENE-6207: Fixed consumption of several terms enums on the same

Modified: lucene/dev/branches/branch_5x/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?rev=1656523&r1=1656522&r2=1656523&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/dev/branches/branch_5x/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Mon Feb  2 17:40:03 2015
@@ -305,7 +305,8 @@ public class TestBackwardsCompatibility
       "3.6.1-cfs",
       "3.6.1-nocfs",
       "3.6.2-cfs",
-      "3.6.2-nocfs"
+      "3.6.2-nocfs",
+      "4x-with-3x-segments"
   };
   
   final static String[] oldSingleSegmentNames = {"4.0.0-optimized-cfs",

Added: lucene/dev/branches/branch_5x/lucene/backward-codecs/src/test/org/apache/lucene/index/unsupported.4x-with-3x-segments.zip
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/backward-codecs/src/test/org/apache/lucene/index/unsupported.4x-with-3x-segments.zip?rev=1656523&view=auto
==============================================================================
Binary file - no diff available.

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java?rev=1656523&r1=1656522&r2=1656523&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java Mon Feb  2 17:40:03 2015
@@ -37,6 +37,7 @@ import org.apache.lucene.codecs.DocValue
 import org.apache.lucene.codecs.FieldInfosFormat;
 import org.apache.lucene.codecs.LiveDocsFormat;
 import org.apache.lucene.store.ChecksumIndexInput;
+import org.apache.lucene.store.DataInput;
 import org.apache.lucene.store.DataOutput;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
@@ -322,7 +323,7 @@ public final class SegmentInfos implemen
         } else {
           segmentID = null;
         }
-        Codec codec = Codec.forName(input.readString());
+        Codec codec = readCodec(input);
         SegmentInfo info = codec.segmentInfoFormat().read(directory, segName, segmentID, IOContext.READ);
         info.setCodec(codec);
         long delGen = input.readLong();
@@ -394,6 +395,31 @@ public final class SegmentInfos implemen
     }
   }
 
+  private static final String[] unsupportedCodecs = {
+      "Lucene3x"
+  };
+
+  private static Codec readCodec(DataInput input) throws IOException {
+    final String name = input.readString();
+    try {
+      return Codec.forName(name);
+    } catch (IllegalArgumentException e) {
+      // give better error messages if we can, first check if this is a legacy codec
+      for (String codec : unsupportedCodecs) {
+        if (codec.equals(name)) {
+          IOException newExc = new IndexFormatTooOldException(input, "Codec '" + name + "' is too old");
+          newExc.initCause(e);
+          throw newExc;
+        }
+      }
+      // or maybe it's an old default codec that moved
+      if (name.startsWith("Lucene")) {
+        throw new IllegalArgumentException("Could not load codec '" + name + "'.  Did you forget to add lucene-backward-codecs.jar?", e);
+      }
+      throw e;
+    }
+  }
+
   /** Find the latest commit ({@code segments_N file}) and
    *  load all {@link SegmentCommitInfo}s. */
   public static final SegmentInfos readLatestCommit(Directory directory) throws IOException {