mirror of https://github.com/apache/lucene.git
LUCENE-1191: if we hit OOM then don't commit any changes to the index
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@632124 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8f9781bbdb
commit
7af43e46d6
|
@ -289,6 +289,7 @@ public class IndexWriter {
|
||||||
private static Object MESSAGE_ID_LOCK = new Object();
|
private static Object MESSAGE_ID_LOCK = new Object();
|
||||||
private static int MESSAGE_ID = 0;
|
private static int MESSAGE_ID = 0;
|
||||||
private int messageID = -1;
|
private int messageID = -1;
|
||||||
|
volatile private boolean hitOOM;
|
||||||
|
|
||||||
private Directory directory; // where this index resides
|
private Directory directory; // where this index resides
|
||||||
private Analyzer analyzer; // how to analyze text
|
private Analyzer analyzer; // how to analyze text
|
||||||
|
@ -1610,6 +1611,13 @@ public class IndexWriter {
|
||||||
*/
|
*/
|
||||||
public void close(boolean waitForMerges) throws CorruptIndexException, IOException {
|
public void close(boolean waitForMerges) throws CorruptIndexException, IOException {
|
||||||
boolean doClose;
|
boolean doClose;
|
||||||
|
|
||||||
|
// If any methods have hit OutOfMemoryError, then abort
|
||||||
|
// on close, in case the internal state of IndexWriter
|
||||||
|
// or DocumentsWriter is corrupt
|
||||||
|
if (hitOOM)
|
||||||
|
abort();
|
||||||
|
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
// Ensure that only one thread actually gets to do the closing:
|
// Ensure that only one thread actually gets to do the closing:
|
||||||
if (!closing) {
|
if (!closing) {
|
||||||
|
@ -1676,7 +1684,9 @@ public class IndexWriter {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
closed = true;
|
closed = true;
|
||||||
}
|
}
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
hitOOM = true;
|
||||||
|
throw oom;
|
||||||
} finally {
|
} finally {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if (!closed)
|
if (!closed)
|
||||||
|
@ -1861,6 +1871,7 @@ public class IndexWriter {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
boolean doFlush = false;
|
boolean doFlush = false;
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
try {
|
||||||
try {
|
try {
|
||||||
doFlush = docWriter.addDocument(doc, analyzer);
|
doFlush = docWriter.addDocument(doc, analyzer);
|
||||||
success = true;
|
success = true;
|
||||||
|
@ -1883,6 +1894,10 @@ public class IndexWriter {
|
||||||
}
|
}
|
||||||
if (doFlush)
|
if (doFlush)
|
||||||
flush(true, false);
|
flush(true, false);
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
hitOOM = true;
|
||||||
|
throw oom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1893,9 +1908,14 @@ public class IndexWriter {
|
||||||
*/
|
*/
|
||||||
public void deleteDocuments(Term term) throws CorruptIndexException, IOException {
|
public void deleteDocuments(Term term) throws CorruptIndexException, IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
try {
|
||||||
boolean doFlush = docWriter.bufferDeleteTerm(term);
|
boolean doFlush = docWriter.bufferDeleteTerm(term);
|
||||||
if (doFlush)
|
if (doFlush)
|
||||||
flush(true, false);
|
flush(true, false);
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
hitOOM = true;
|
||||||
|
throw oom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1908,9 +1928,14 @@ public class IndexWriter {
|
||||||
*/
|
*/
|
||||||
public void deleteDocuments(Term[] terms) throws CorruptIndexException, IOException {
|
public void deleteDocuments(Term[] terms) throws CorruptIndexException, IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
try {
|
||||||
boolean doFlush = docWriter.bufferDeleteTerms(terms);
|
boolean doFlush = docWriter.bufferDeleteTerms(terms);
|
||||||
if (doFlush)
|
if (doFlush)
|
||||||
flush(true, false);
|
flush(true, false);
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
hitOOM = true;
|
||||||
|
throw oom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1946,6 +1971,7 @@ public class IndexWriter {
|
||||||
public void updateDocument(Term term, Document doc, Analyzer analyzer)
|
public void updateDocument(Term term, Document doc, Analyzer analyzer)
|
||||||
throws CorruptIndexException, IOException {
|
throws CorruptIndexException, IOException {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
try {
|
||||||
boolean doFlush = false;
|
boolean doFlush = false;
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
|
@ -1968,6 +1994,10 @@ public class IndexWriter {
|
||||||
}
|
}
|
||||||
if (doFlush)
|
if (doFlush)
|
||||||
flush(true, false);
|
flush(true, false);
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
hitOOM = true;
|
||||||
|
throw oom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for test purpose
|
// for test purpose
|
||||||
|
@ -2644,6 +2674,7 @@ public class IndexWriter {
|
||||||
throws CorruptIndexException, IOException {
|
throws CorruptIndexException, IOException {
|
||||||
|
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
try {
|
||||||
if (infoStream != null)
|
if (infoStream != null)
|
||||||
message("flush at addIndexes");
|
message("flush at addIndexes");
|
||||||
flush(true, false);
|
flush(true, false);
|
||||||
|
@ -2671,6 +2702,10 @@ public class IndexWriter {
|
||||||
rollbackTransaction();
|
rollbackTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
hitOOM = true;
|
||||||
|
throw oom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void resetMergeExceptions() {
|
private synchronized void resetMergeExceptions() {
|
||||||
|
@ -2706,6 +2741,8 @@ public class IndexWriter {
|
||||||
throws CorruptIndexException, IOException {
|
throws CorruptIndexException, IOException {
|
||||||
|
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
|
||||||
|
try {
|
||||||
if (infoStream != null)
|
if (infoStream != null)
|
||||||
message("flush at addIndexesNoOptimize");
|
message("flush at addIndexesNoOptimize");
|
||||||
flush(true, false);
|
flush(true, false);
|
||||||
|
@ -2748,6 +2785,10 @@ public class IndexWriter {
|
||||||
rollbackTransaction();
|
rollbackTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
hitOOM = true;
|
||||||
|
throw oom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If any of our segments are using a directory != ours
|
/* If any of our segments are using a directory != ours
|
||||||
|
@ -2793,6 +2834,7 @@ public class IndexWriter {
|
||||||
throws CorruptIndexException, IOException {
|
throws CorruptIndexException, IOException {
|
||||||
|
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
try {
|
||||||
optimize(); // start with zero or 1 seg
|
optimize(); // start with zero or 1 seg
|
||||||
|
|
||||||
final String mergedName = newSegmentName();
|
final String mergedName = newSegmentName();
|
||||||
|
@ -2865,6 +2907,10 @@ public class IndexWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
hitOOM = true;
|
||||||
|
throw oom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called after pending added and deleted
|
// This is called after pending added and deleted
|
||||||
|
@ -3121,6 +3167,9 @@ public class IndexWriter {
|
||||||
|
|
||||||
return flushDocs || flushDeletes;
|
return flushDocs || flushDeletes;
|
||||||
|
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
hitOOM = true;
|
||||||
|
throw oom;
|
||||||
} finally {
|
} finally {
|
||||||
docWriter.clearFlushPending();
|
docWriter.clearFlushPending();
|
||||||
docWriter.resumeAllThreads();
|
docWriter.resumeAllThreads();
|
||||||
|
@ -3259,6 +3308,9 @@ public class IndexWriter {
|
||||||
/* FIXME if we want to support non-contiguous segment merges */
|
/* FIXME if we want to support non-contiguous segment merges */
|
||||||
synchronized private boolean commitMerge(MergePolicy.OneMerge merge) throws IOException {
|
synchronized private boolean commitMerge(MergePolicy.OneMerge merge) throws IOException {
|
||||||
|
|
||||||
|
if (hitOOM)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (infoStream != null)
|
if (infoStream != null)
|
||||||
message("commitMerge: " + merge.segString(directory));
|
message("commitMerge: " + merge.segString(directory));
|
||||||
|
|
||||||
|
@ -3344,7 +3396,7 @@ public class IndexWriter {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
try {
|
||||||
try {
|
try {
|
||||||
mergeInit(merge);
|
mergeInit(merge);
|
||||||
|
|
||||||
|
@ -3392,6 +3444,10 @@ public class IndexWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
hitOOM = true;
|
||||||
|
throw oom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks whether this merge involves any segments
|
/** Checks whether this merge involves any segments
|
||||||
|
@ -3988,6 +4044,11 @@ public class IndexWriter {
|
||||||
* that. */
|
* that. */
|
||||||
private void sync(boolean includeFlushes, long sizeInBytes) throws IOException {
|
private void sync(boolean includeFlushes, long sizeInBytes) throws IOException {
|
||||||
|
|
||||||
|
if (hitOOM)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
message("start sync() includeFlushes=" + includeFlushes);
|
message("start sync() includeFlushes=" + includeFlushes);
|
||||||
|
|
||||||
if (!includeFlushes)
|
if (!includeFlushes)
|
||||||
|
@ -4126,6 +4187,10 @@ public class IndexWriter {
|
||||||
commitPending = true;
|
commitPending = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
hitOOM = true;
|
||||||
|
throw oom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue