LUCENE-3661: remove .del from IndexFileNames

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3661@1233726 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-01-20 02:18:59 +00:00
parent 2dee41b88e
commit 6117558c44
5 changed files with 26 additions and 26 deletions

View File

@ -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;
}

View File

@ -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()));
}
}
}

View File

@ -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,
};

View File

@ -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;
}
}

View File

@ -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,