mirror of https://github.com/apache/lucene.git
LUCENE-3606: remove separate norms extension from indexfilenames
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3606@1210314 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
249883a232
commit
f05679bb5f
|
@ -17,8 +17,6 @@ package org.apache.lucene.index;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.apache.lucene.index.codecs.Codec; // for javadocs
|
import org.apache.lucene.index.codecs.Codec; // for javadocs
|
||||||
|
|
||||||
// TODO: put all files under codec and remove all the static extensions here
|
// TODO: put all files under codec and remove all the static extensions here
|
||||||
|
@ -62,9 +60,6 @@ public final class IndexFileNames {
|
||||||
/** Extension of deletes */
|
/** Extension of deletes */
|
||||||
public static final String DELETES_EXTENSION = "del";
|
public static final String DELETES_EXTENSION = "del";
|
||||||
|
|
||||||
/** Extension of separate norms */
|
|
||||||
public static final String SEPARATE_NORMS_EXTENSION = "s";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This array contains all filename extensions used by
|
* This array contains all filename extensions used by
|
||||||
* Lucene's index files, with one exception, namely the
|
* Lucene's index files, with one exception, namely the
|
||||||
|
@ -180,17 +175,5 @@ public final class IndexFileNames {
|
||||||
filename = filename.substring(0, idx);
|
filename = filename.substring(0, idx);
|
||||||
}
|
}
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the given filename ends with the separate norms file
|
|
||||||
* pattern: {@code SEPARATE_NORMS_EXTENSION + "[0-9]+"}.
|
|
||||||
*/
|
|
||||||
public static boolean isSeparateNormsFile(String filename) {
|
|
||||||
int idx = filename.lastIndexOf('.');
|
|
||||||
if (idx == -1) return false;
|
|
||||||
String ext = filename.substring(idx + 1);
|
|
||||||
return Pattern.matches(SEPARATE_NORMS_EXTENSION + "[0-9]+", ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.index.DocumentsWriterPerThread.FlushedSegment;
|
import org.apache.lucene.index.DocumentsWriterPerThread.FlushedSegment;
|
||||||
|
@ -3980,7 +3981,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
||||||
for (String file : files) {
|
for (String file : files) {
|
||||||
assert !IndexFileNames.matchesExtension(file, IndexFileNames.DELETES_EXTENSION)
|
assert !IndexFileNames.matchesExtension(file, IndexFileNames.DELETES_EXTENSION)
|
||||||
: ".del file is not allowed in .cfs: " + file;
|
: ".del file is not allowed in .cfs: " + file;
|
||||||
assert !IndexFileNames.isSeparateNormsFile(file)
|
assert !isSeparateNormsFile(file)
|
||||||
: "separate norms file (.s[0-9]+) is not allowed in .cfs: " + file;
|
: "separate norms file (.s[0-9]+) is not allowed in .cfs: " + file;
|
||||||
directory.copy(cfsDir, file, file, context);
|
directory.copy(cfsDir, file, file, context);
|
||||||
checkAbort.work(directory.fileLength(file));
|
checkAbort.work(directory.fileLength(file));
|
||||||
|
@ -3991,4 +3992,18 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given filename ends with the separate norms file
|
||||||
|
* pattern: {@code SEPARATE_NORMS_EXTENSION + "[0-9]+"}.
|
||||||
|
* @deprecated only for asserting
|
||||||
|
*/
|
||||||
|
@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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,6 +339,7 @@ public final class SegmentInfo implements Cloneable {
|
||||||
/**
|
/**
|
||||||
* @deprecated separate norms are not supported in >= 4.0
|
* @deprecated separate norms are not supported in >= 4.0
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
boolean hasSeparateNorms() {
|
boolean hasSeparateNorms() {
|
||||||
if (normGen == null) {
|
if (normGen == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -508,16 +509,12 @@ public final class SegmentInfo implements Cloneable {
|
||||||
if (delFileName != null && (delGen >= YES || dir.fileExists(delFileName))) {
|
if (delFileName != null && (delGen >= YES || dir.fileExists(delFileName))) {
|
||||||
fileSet.add(delFileName);
|
fileSet.add(delFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: push this to codec?
|
// because separate norm files are unconditionally stored outside cfs,
|
||||||
|
// we must explicitly ask for their filenames if we might have separate norms:
|
||||||
|
// remove this when 3.x indexes are no longer supported
|
||||||
if (normGen != null) {
|
if (normGen != null) {
|
||||||
for (Entry<Integer,Long> entry : normGen.entrySet()) {
|
codec.normsFormat().separateFiles(dir, this, fileSet);
|
||||||
long gen = entry.getValue();
|
|
||||||
if (gen >= YES) {
|
|
||||||
// Definitely a separate norm file, with generation:
|
|
||||||
fileSet.add(IndexFileNames.fileNameFromGeneration(name, IndexFileNames.SEPARATE_NORMS_EXTENSION + entry.getKey(), gen));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
files = new ArrayList<String>(fileSet);
|
files = new ArrayList<String>(fileSet);
|
||||||
|
|
|
@ -34,4 +34,11 @@ public abstract class NormsFormat {
|
||||||
public abstract NormsReader normsReader(Directory dir, SegmentInfo info, FieldInfos fields, IOContext context, Directory separateNormsDir) throws IOException;
|
public abstract NormsReader normsReader(Directory dir, SegmentInfo info, FieldInfos fields, IOContext context, Directory separateNormsDir) throws IOException;
|
||||||
public abstract NormsWriter normsWriter(SegmentWriteState state) throws IOException;
|
public abstract NormsWriter normsWriter(SegmentWriteState state) throws IOException;
|
||||||
public abstract void files(Directory dir, SegmentInfo info, Set<String> files) throws IOException;
|
public abstract void files(Directory dir, SegmentInfo info, Set<String> files) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: this should not be overridden!
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public void separateFiles(Directory dir, SegmentInfo info, Set<String> files) throws IOException {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,4 +45,9 @@ public class Lucene40NormsFormat extends NormsFormat {
|
||||||
public void files(Directory dir, SegmentInfo info, Set<String> files) throws IOException {
|
public void files(Directory dir, SegmentInfo info, Set<String> files) throws IOException {
|
||||||
Lucene40NormsReader.files(dir, info, files);
|
Lucene40NormsReader.files(dir, info, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void separateFiles(Directory dir, SegmentInfo info, Set<String> files) throws IOException {
|
||||||
|
Lucene40NormsReader.separateFiles(dir, info, files);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.HashMap;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.apache.lucene.index.FieldInfo;
|
import org.apache.lucene.index.FieldInfo;
|
||||||
import org.apache.lucene.index.FieldInfos;
|
import org.apache.lucene.index.FieldInfos;
|
||||||
|
@ -132,7 +133,7 @@ public class Lucene40NormsReader extends NormsReader {
|
||||||
|
|
||||||
private static String getNormFilename(String segmentName, Map<Integer,Long> normGen, int number) {
|
private static String getNormFilename(String segmentName, Map<Integer,Long> normGen, int number) {
|
||||||
if (hasSeparateNorms(normGen, number)) {
|
if (hasSeparateNorms(normGen, number)) {
|
||||||
return IndexFileNames.fileNameFromGeneration(segmentName, IndexFileNames.SEPARATE_NORMS_EXTENSION + number, normGen.get(number));
|
return IndexFileNames.fileNameFromGeneration(segmentName, Lucene40NormsWriter.SEPARATE_NORMS_EXTENSION + number, normGen.get(number));
|
||||||
} else {
|
} else {
|
||||||
// single file for all norms
|
// single file for all norms
|
||||||
return IndexFileNames.fileNameFromGeneration(segmentName, Lucene40NormsWriter.NORMS_EXTENSION, SegmentInfo.WITHOUT_GEN);
|
return IndexFileNames.fileNameFromGeneration(segmentName, Lucene40NormsWriter.NORMS_EXTENSION, SegmentInfo.WITHOUT_GEN);
|
||||||
|
@ -180,4 +181,19 @@ public class Lucene40NormsReader extends NormsReader {
|
||||||
files.add(normsFileName);
|
files.add(normsFileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
|
@Deprecated
|
||||||
|
static void separateFiles(Directory dir, SegmentInfo info, Set<String> files) throws IOException {
|
||||||
|
Map<Integer,Long> normGen = info.getNormGen();
|
||||||
|
if (normGen != null) {
|
||||||
|
for (Entry<Integer,Long> entry : normGen.entrySet()) {
|
||||||
|
long gen = entry.getValue();
|
||||||
|
if (gen >= SegmentInfo.YES) {
|
||||||
|
// Definitely a separate norm file, with generation:
|
||||||
|
files.add(IndexFileNames.fileNameFromGeneration(info.name, Lucene40NormsWriter.SEPARATE_NORMS_EXTENSION + entry.getKey(), gen));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,11 @@ public class Lucene40NormsWriter extends NormsWriter {
|
||||||
/** Extension of norms file */
|
/** Extension of norms file */
|
||||||
static final String NORMS_EXTENSION = "nrm";
|
static final String NORMS_EXTENSION = "nrm";
|
||||||
|
|
||||||
|
/** Extension of separate norms file
|
||||||
|
* @deprecated */
|
||||||
|
@Deprecated
|
||||||
|
static final String SEPARATE_NORMS_EXTENSION = "s";
|
||||||
|
|
||||||
public Lucene40NormsWriter(Directory directory, String segment, IOContext context) throws IOException {
|
public Lucene40NormsWriter(Directory directory, String segment, IOContext context) throws IOException {
|
||||||
final String normsFileName = IndexFileNames.segmentFileName(segment, "", NORMS_EXTENSION);
|
final String normsFileName = IndexFileNames.segmentFileName(segment, "", NORMS_EXTENSION);
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
Loading…
Reference in New Issue