You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2012/06/11 20:11:53 UTC
svn commit: r1348952 - in /lucene/dev/trunk: ./ lucene/ lucene/core/
lucene/core/src/java/org/apache/lucene/index/
lucene/core/src/java/org/apache/lucene/store/
lucene/core/src/test/org/apache/lucene/codecs/lucene40/
lucene/core/src/test/org/apache/luc...
Author: rmuir
Date: Mon Jun 11 18:11:53 2012
New Revision: 1348952
URL: http://svn.apache.org/viewvc?rev=1348952&view=rev
Log:
LUCENE-4130: fix CompoundFileDirectory.listAll when the .cfs has a segment suffix
Modified:
lucene/dev/trunk/ (props changed)
lucene/dev/trunk/lucene/ (props changed)
lucene/dev/trunk/lucene/core/ (props changed)
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/CompoundFileDirectory.java
lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestAllFilesHaveCodecHeader.java
lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java?rev=1348952&r1=1348951&r2=1348952&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java Mon Jun 11 18:11:53 2012
@@ -140,6 +140,17 @@ public final class IndexFileNames {
return filename.endsWith("." + ext);
}
+ /** locates the boundary of the segment name, or -1 */
+ private static int indexOfSegmentName(String filename) {
+ // If it is a .del file, there's an '_' after the first character
+ int idx = filename.indexOf('_', 1);
+ if (idx == -1) {
+ // If it's not, strip everything that's before the '.'
+ idx = filename.indexOf('.');
+ }
+ return idx;
+ }
+
/**
* Strips the segment name out of the given file name. If you used
* {@link #segmentFileName} or {@link #fileNameFromGeneration} to create your
@@ -150,18 +161,27 @@ public final class IndexFileNames {
* if it does not contain a '.' and '_'.
*/
public static String stripSegmentName(String filename) {
- // If it is a .del file, there's an '_' after the first character
- int idx = filename.indexOf('_', 1);
- if (idx == -1) {
- // If it's not, strip everything that's before the '.'
- idx = filename.indexOf('.');
- }
+ int idx = indexOfSegmentName(filename);
if (idx != -1) {
filename = filename.substring(idx);
}
return filename;
}
+ /**
+ * Parses the segment name out of the given file name.
+ *
+ * @return the segment name only, or filename
+ * if it does not contain a '.' and '_'.
+ */
+ public static String parseSegmentName(String filename) {
+ int idx = indexOfSegmentName(filename);
+ if (idx != -1) {
+ filename = filename.substring(0, idx);
+ }
+ return filename;
+ }
+
public static String stripExtension(String filename) {
int idx = filename.indexOf('.');
if (idx != -1) {
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/CompoundFileDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/CompoundFileDirectory.java?rev=1348952&r1=1348951&r2=1348952&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/CompoundFileDirectory.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/CompoundFileDirectory.java Mon Jun 11 18:11:53 2012
@@ -204,7 +204,7 @@ public final class CompoundFileDirectory
} else {
res = entries.keySet().toArray(new String[entries.size()]);
// Add the segment name
- String seg = fileName.substring(0, fileName.indexOf('.'));
+ String seg = IndexFileNames.parseSegmentName(fileName);
for (int i = 0; i < res.length; i++) {
res[i] = seg + res[i];
}
Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestAllFilesHaveCodecHeader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestAllFilesHaveCodecHeader.java?rev=1348952&r1=1348951&r2=1348952&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestAllFilesHaveCodecHeader.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestAllFilesHaveCodecHeader.java Mon Jun 11 18:11:53 2012
@@ -69,11 +69,9 @@ public class TestAllFilesHaveCodecHeader
continue; // segments.gen has no header, thats ok
}
if (file.endsWith(IndexFileNames.COMPOUND_FILE_EXTENSION)) {
- /* TODO: enable this after resolving LUCENE-4130
- * CompoundFileDirectory cfsDir = new CompoundFileDirectory(dir, file, newIOContext(random()), false);
- * checkHeaders(cfsDir); // recurse into cfs
- * cfsDir.close();
- */
+ CompoundFileDirectory cfsDir = new CompoundFileDirectory(dir, file, newIOContext(random()), false);
+ checkHeaders(cfsDir); // recurse into cfs
+ cfsDir.close();
continue; // .cfs has its own header... would be nice to fix
}
if (file.endsWith(IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION)) {
Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java?rev=1348952&r1=1348951&r2=1348952&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java Mon Jun 11 18:11:53 2012
@@ -20,8 +20,11 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.io.File;
+import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
import org.apache.lucene.store.CompoundFileDirectory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexOutput;
@@ -804,4 +807,50 @@ public class TestCompoundFile extends Lu
cfr.close();
d.close();
}
+
+ public void testListAll() throws Exception {
+ Directory dir = newDirectory();
+ // riw should sometimes create docvalues fields, etc
+ RandomIndexWriter riw = new RandomIndexWriter(random(), dir);
+ Document doc = new Document();
+ // these fields should sometimes get term vectors, etc
+ Field idField = newStringField("id", "", Field.Store.NO);
+ Field bodyField = newTextField("body", "", Field.Store.NO);
+ doc.add(idField);
+ doc.add(bodyField);
+ for (int i = 0; i < 100; i++) {
+ idField.setStringValue(Integer.toString(i));
+ bodyField.setStringValue(_TestUtil.randomUnicodeString(random()));
+ riw.addDocument(doc);
+ if (random().nextInt(7) == 0) {
+ riw.commit();
+ }
+ }
+ riw.close();
+ checkFiles(dir);
+ dir.close();
+ }
+
+ // checks that we can open all files returned by listAll!
+ private void checkFiles(Directory dir) throws IOException {
+ for (String file : dir.listAll()) {
+ if (file.endsWith(IndexFileNames.COMPOUND_FILE_EXTENSION)) {
+ CompoundFileDirectory cfsDir = new CompoundFileDirectory(dir, file, newIOContext(random()), false);
+ checkFiles(cfsDir); // recurse into cfs
+ cfsDir.close();
+ }
+ IndexInput in = null;
+ boolean success = false;
+ try {
+ in = dir.openInput(file, newIOContext(random()));
+ success = true;
+ } finally {
+ if (success) {
+ IOUtils.close(in);
+ } else {
+ IOUtils.closeWhileHandlingException(in);
+ }
+ }
+ }
+ }
}