Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-3661: remove .del from IndexFileNames

Robert Muir6117558c44f9
diff --git a/lucene/src/java/org/apache/lucene/codecs/LiveDocsFormat.java b/lucene/src/java/org/apache/lucene/codecs/LiveDocsFormat.java
index e3e5e467a1d..3bbb1142697 100644
--- a/lucene/src/java/org/apache/lucene/codecs/LiveDocsFormat.java
+++ b/lucene/src/java/org/apache/lucene/codecs/LiveDocsFormat.java
@@ -30,5 +30,5 @@ public abstract class LiveDocsFormat {
public abstract MutableBits newLiveDocs(int size) throws IOException;
public abstract Bits readLiveDocs(Directory dir, SegmentInfo info, IOContext context) throws IOException;
public abstract void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, IOContext context) throws IOException;
- public abstract void files(Directory dir, SegmentInfo info, Set<String> files) throws IOException;
+ public abstract void separateFiles(Directory dir, SegmentInfo info, Set<String> files) throws IOException;
}
diff --git a/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.java b/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.java
index 76850fc1e14..42fcdf68a54 100644
--- a/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.java
+++ b/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.java
@@ -13,6 +13,9 @@ import org.apache.lucene.util.MutableBits;
public class Lucene40LiveDocsFormat extends LiveDocsFormat {
+ /** Extension of deletes */
+ static final String DELETES_EXTENSION = "del";
+
@Override
public MutableBits newLiveDocs(int size) throws IOException {
BitVector bitVector = new BitVector(size);
@@ -22,14 +25,14 @@ public class Lucene40LiveDocsFormat extends LiveDocsFormat {
@Override
public Bits readLiveDocs(Directory dir, SegmentInfo info, IOContext context) throws IOException {
- String filename = IndexFileNames.fileNameFromGeneration(info.name, IndexFileNames.DELETES_EXTENSION, info.getDelGen());
+ String filename = IndexFileNames.fileNameFromGeneration(info.name, DELETES_EXTENSION, info.getDelGen());
return new BitVector(dir, filename, context);
}
@Override
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, IOContext context) throws IOException {
// nocommit: this api is ugly...
- String filename = IndexFileNames.fileNameFromGeneration(info.name, IndexFileNames.DELETES_EXTENSION, info.getDelGen());
+ String filename = IndexFileNames.fileNameFromGeneration(info.name, DELETES_EXTENSION, info.getDelGen());
// nocommit: is it somehow cleaner to still have IW do this try/finally/delete stuff and add abort() instead?
boolean success = false;
@@ -49,9 +52,9 @@ public class Lucene40LiveDocsFormat extends LiveDocsFormat {
}
@Override
- public void files(Directory dir, SegmentInfo info, Set<String> files) throws IOException {
+ public void separateFiles(Directory dir, SegmentInfo info, Set<String> files) throws IOException {
if (info.hasDeletions()) {
- files.add(IndexFileNames.fileNameFromGeneration(info.name, IndexFileNames.DELETES_EXTENSION, info.getDelGen()));
+ files.add(IndexFileNames.fileNameFromGeneration(info.name, DELETES_EXTENSION, info.getDelGen()));
}
}
}
diff --git a/lucene/src/java/org/apache/lucene/index/IndexFileNames.java b/lucene/src/java/org/apache/lucene/index/IndexFileNames.java
index 080a0478d05..1bcb493b1d8 100644
--- a/lucene/src/java/org/apache/lucene/index/IndexFileNames.java
+++ b/lucene/src/java/org/apache/lucene/index/IndexFileNames.java
@@ -57,9 +57,6 @@ public final class IndexFileNames {
/** Extension of compound file for doc store files*/
public static final String COMPOUND_FILE_STORE_EXTENSION = "cfx";
- /** Extension of deletes */
- public static final String DELETES_EXTENSION = "del";
-
/**
* This array contains all filename extensions used by
* Lucene's index files, with one exception, namely the
@@ -70,7 +67,6 @@ public final class IndexFileNames {
public static final String INDEX_EXTENSIONS[] = new String[] {
COMPOUND_FILE_EXTENSION,
COMPOUND_FILE_ENTRIES_EXTENSION,
- DELETES_EXTENSION,
GEN_EXTENSION,
COMPOUND_FILE_STORE_EXTENSION,
};
diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.java
index 512157f063a..fada43524e8 100644
--- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java
@@ -30,7 +30,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.regex.Pattern;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.codecs.Codec;
@@ -4071,11 +4070,8 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
Collection<String> files = info.files();
CompoundFileDirectory cfsDir = new CompoundFileDirectory(directory, fileName, context, true);
try {
+ assert assertNoSeparateFiles(files, directory, info);
for (String file : files) {
- assert !IndexFileNames.matchesExtension(file, IndexFileNames.DELETES_EXTENSION)
- : ".del file is not allowed in .cfs: " + file;
- assert !isSeparateNormsFile(file)
- : "separate norms file (.s[0-9]+) is not allowed in .cfs: " + file;
directory.copy(cfsDir, file, file, context);
checkAbort.work(directory.fileLength(file));
}
@@ -4088,15 +4084,19 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
/**
- * Returns true if the given filename ends with the separate norms file
- * pattern: {@code SEPARATE_NORMS_EXTENSION + "[0-9]+"}.
- * @deprecated only for asserting
+ * used only by assert: checks that filenames about to be put in cfs belong.
*/
- @Deprecated
- private static boolean isSeparateNormsFile(String filename) {
- int idx = filename.lastIndexOf('.');
- if (idx == -1) return false;
- String ext = filename.substring(idx + 1);
- return Pattern.matches("s[0-9]+", ext);
+ private static boolean assertNoSeparateFiles(Collection<String> files,
+ Directory dir, SegmentInfo info) throws IOException {
+ // maybe this is overkill, but codec naming clashes would be bad.
+ Set<String> separateFiles = new HashSet<String>();
+ Codec codec = info.getCodec();
+ codec.normsFormat().separateFiles(dir, info, separateFiles);
+ codec.liveDocsFormat().separateFiles(dir, info, separateFiles);
+
+ for (String file : files) {
+ assert !separateFiles.contains(file) : file + " should not go in CFS!";
+ }
+ return true;
}
}
diff --git a/lucene/src/java/org/apache/lucene/index/SegmentInfo.java b/lucene/src/java/org/apache/lucene/index/SegmentInfo.java
index d5b01d6d38d..824ba9d0abc 100644
--- a/lucene/src/java/org/apache/lucene/index/SegmentInfo.java
+++ b/lucene/src/java/org/apache/lucene/index/SegmentInfo.java
@@ -495,9 +495,10 @@ public final class SegmentInfo implements Cloneable {
}
}
- String delFileName = IndexFileNames.fileNameFromGeneration(name, IndexFileNames.DELETES_EXTENSION, delGen);
- if (delFileName != null && (delGen >= YES || dir.fileExists(delFileName))) {
- fileSet.add(delFileName);
+ // because deletions are stored outside CFS, we must check deletes here
+ // note: before the WTF logic was: delFileName != null && (hasDeletions() || fileExists(delFileName))...
+ if (hasDeletions()) {
+ codec.liveDocsFormat().separateFiles(dir, this, fileSet);
}
// because separate norm files are unconditionally stored outside cfs,