mirror of https://github.com/apache/lucene.git
- Changed code to use IndexWriter.WRITE_LOCK_NAME.
- Cleaned up indentation a bit. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150096 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9e968c9127
commit
485e3c336f
|
@ -68,6 +68,11 @@ import org.apache.lucene.store.Lock;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.util.BitVector;
|
import org.apache.lucene.util.BitVector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIXME: Describe class <code>SegmentReader</code> here.
|
||||||
|
*
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
final class SegmentReader extends IndexReader {
|
final class SegmentReader extends IndexReader {
|
||||||
private boolean closeDirectory = false;
|
private boolean closeDirectory = false;
|
||||||
private String segment;
|
private String segment;
|
||||||
|
@ -82,7 +87,7 @@ final class SegmentReader extends IndexReader {
|
||||||
|
|
||||||
InputStream freqStream;
|
InputStream freqStream;
|
||||||
InputStream proxStream;
|
InputStream proxStream;
|
||||||
|
|
||||||
// Compound File Reader when based on a compound file segment
|
// Compound File Reader when based on a compound file segment
|
||||||
CompoundFileReader cfsReader;
|
CompoundFileReader cfsReader;
|
||||||
|
|
||||||
|
@ -94,21 +99,21 @@ final class SegmentReader extends IndexReader {
|
||||||
private Hashtable norms = new Hashtable();
|
private Hashtable norms = new Hashtable();
|
||||||
|
|
||||||
SegmentReader(SegmentInfo si, boolean closeDir)
|
SegmentReader(SegmentInfo si, boolean closeDir)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
this(si);
|
this(si);
|
||||||
closeDirectory = closeDir;
|
closeDirectory = closeDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
SegmentReader(SegmentInfo si)
|
SegmentReader(SegmentInfo si)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
super(si.dir);
|
super(si.dir);
|
||||||
segment = si.name;
|
segment = si.name;
|
||||||
|
|
||||||
// Use compound file directory for some files, if it exists
|
// Use compound file directory for some files, if it exists
|
||||||
Directory cfsDir = directory;
|
Directory cfsDir = directory;
|
||||||
if (directory.fileExists(segment + ".cfs")) {
|
if (directory.fileExists(segment + ".cfs")) {
|
||||||
cfsReader = new CompoundFileReader(directory, segment + ".cfs");
|
cfsReader = new CompoundFileReader(directory, segment + ".cfs");
|
||||||
cfsDir = cfsReader;
|
cfsDir = cfsReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No compound file exists - use the multi-file format
|
// No compound file exists - use the multi-file format
|
||||||
|
@ -128,18 +133,19 @@ final class SegmentReader extends IndexReader {
|
||||||
openNorms(cfsDir);
|
openNorms(cfsDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final synchronized void doClose() throws IOException {
|
final synchronized void doClose() throws IOException {
|
||||||
if (deletedDocsDirty) {
|
if (deletedDocsDirty) {
|
||||||
synchronized (directory) { // in- & inter-process sync
|
synchronized (directory) { // in- & inter-process sync
|
||||||
new Lock.With(directory.makeLock("commit.lock"), IndexWriter.COMMIT_LOCK_TIMEOUT) {
|
new Lock.With(directory.makeLock("IndexWriter.COMMIT_LOCK_NAME"),
|
||||||
public Object doBody() throws IOException {
|
IndexWriter.COMMIT_LOCK_TIMEOUT) {
|
||||||
deletedDocs.write(directory, segment + ".tmp");
|
public Object doBody() throws IOException {
|
||||||
directory.renameFile(segment + ".tmp", segment + ".del");
|
deletedDocs.write(directory, segment + ".tmp");
|
||||||
directory.touchFile("segments");
|
directory.renameFile(segment + ".tmp", segment + ".del");
|
||||||
return null;
|
directory.touchFile("segments");
|
||||||
}
|
return null;
|
||||||
}.run();
|
}
|
||||||
|
}.run();
|
||||||
}
|
}
|
||||||
deletedDocsDirty = false;
|
deletedDocsDirty = false;
|
||||||
}
|
}
|
||||||
|
@ -153,7 +159,7 @@ final class SegmentReader extends IndexReader {
|
||||||
proxStream.close();
|
proxStream.close();
|
||||||
|
|
||||||
closeNorms();
|
closeNorms();
|
||||||
|
|
||||||
if (cfsReader != null)
|
if (cfsReader != null)
|
||||||
cfsReader.close();
|
cfsReader.close();
|
||||||
|
|
||||||
|
@ -168,7 +174,7 @@ final class SegmentReader extends IndexReader {
|
||||||
static final boolean usesCompoundFile(SegmentInfo si) throws IOException {
|
static final boolean usesCompoundFile(SegmentInfo si) throws IOException {
|
||||||
return si.dir.fileExists(si.name + ".cfs");
|
return si.dir.fileExists(si.name + ".cfs");
|
||||||
}
|
}
|
||||||
|
|
||||||
final synchronized void doDelete(int docNum) throws IOException {
|
final synchronized void doDelete(int docNum) throws IOException {
|
||||||
if (deletedDocs == null)
|
if (deletedDocs == null)
|
||||||
deletedDocs = new BitVector(maxDoc());
|
deletedDocs = new BitVector(maxDoc());
|
||||||
|
@ -179,15 +185,15 @@ final class SegmentReader extends IndexReader {
|
||||||
final Vector files() throws IOException {
|
final Vector files() throws IOException {
|
||||||
Vector files = new Vector(16);
|
Vector files = new Vector(16);
|
||||||
final String ext[] = new String[] {
|
final String ext[] = new String[] {
|
||||||
"cfs", "fnm", "fdx", "fdt", "tii", "tis", "frq", "prx", "del"
|
"cfs", "fnm", "fdx", "fdt", "tii", "tis", "frq", "prx", "del"
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i=0; i<ext.length; i++) {
|
for (int i=0; i<ext.length; i++) {
|
||||||
String name = segment + "." + ext[i];
|
String name = segment + "." + ext[i];
|
||||||
if (directory.fileExists(name))
|
if (directory.fileExists(name))
|
||||||
files.addElement(name);
|
files.addElement(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < fieldInfos.size(); i++) {
|
for (int i = 0; i < fieldInfos.size(); i++) {
|
||||||
FieldInfo fi = fieldInfos.fieldInfo(i);
|
FieldInfo fi = fieldInfos.fieldInfo(i);
|
||||||
if (fi.isIndexed)
|
if (fi.isIndexed)
|
||||||
|
|
Loading…
Reference in New Issue