mirror of https://github.com/apache/lucene.git
don't construct verbose message Strings unless infoStream is non-null
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@724033 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
36a03da823
commit
19c82a230d
|
@ -94,8 +94,12 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean verbose() {
|
||||
return writer != null && writer.verbose();
|
||||
}
|
||||
|
||||
private void message(String message) {
|
||||
if (writer != null)
|
||||
if (verbose())
|
||||
writer.message("CMS: " + message);
|
||||
}
|
||||
|
||||
|
@ -115,11 +119,14 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
|
|||
|
||||
public synchronized void sync() {
|
||||
while(mergeThreadCount() > 0) {
|
||||
message("now wait for threads; currently " + mergeThreads.size() + " still running");
|
||||
if (verbose())
|
||||
message("now wait for threads; currently " + mergeThreads.size() + " still running");
|
||||
final int count = mergeThreads.size();
|
||||
for(int i=0;i<count;i++)
|
||||
message(" " + i + ": " + ((MergeThread) mergeThreads.get(i)));
|
||||
|
||||
if (verbose()) {
|
||||
for(int i=0;i<count;i++)
|
||||
message(" " + i + ": " + ((MergeThread) mergeThreads.get(i)));
|
||||
}
|
||||
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -154,9 +161,11 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
|
|||
// these newly proposed merges will likely already be
|
||||
// registered.
|
||||
|
||||
message("now merge");
|
||||
message(" index: " + writer.segString());
|
||||
|
||||
if (verbose()) {
|
||||
message("now merge");
|
||||
message(" index: " + writer.segString());
|
||||
}
|
||||
|
||||
// Iterate, pulling from the IndexWriter's queue of
|
||||
// pending merges, until it's empty:
|
||||
while(true) {
|
||||
|
@ -167,7 +176,8 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
|
|||
|
||||
MergePolicy.OneMerge merge = writer.getNextMerge();
|
||||
if (merge == null) {
|
||||
message(" no more merges pending; now return");
|
||||
if (verbose())
|
||||
message(" no more merges pending; now return");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -177,7 +187,8 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
|
|||
|
||||
synchronized(this) {
|
||||
while (mergeThreadCount() >= maxThreadCount) {
|
||||
message(" too many merge threads running; stalling...");
|
||||
if (verbose())
|
||||
message(" too many merge threads running; stalling...");
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException ie) {
|
||||
|
@ -185,7 +196,8 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
|
|||
}
|
||||
}
|
||||
|
||||
message(" consider merge " + merge.segString(dir));
|
||||
if (verbose())
|
||||
message(" consider merge " + merge.segString(dir));
|
||||
|
||||
assert mergeThreadCount() < maxThreadCount;
|
||||
|
||||
|
@ -193,7 +205,8 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
|
|||
// merge:
|
||||
final MergeThread merger = getMergeThread(writer, merge);
|
||||
mergeThreads.add(merger);
|
||||
message(" launch new thread [" + merger.getName() + "]");
|
||||
if (verbose())
|
||||
message(" launch new thread [" + merger.getName() + "]");
|
||||
merger.start();
|
||||
}
|
||||
}
|
||||
|
@ -253,7 +266,8 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
|
|||
|
||||
try {
|
||||
|
||||
message(" merge thread: start");
|
||||
if (verbose())
|
||||
message(" merge thread: start");
|
||||
|
||||
while(true) {
|
||||
setRunningMerge(merge);
|
||||
|
@ -264,12 +278,14 @@ public class ConcurrentMergeScheduler extends MergeScheduler {
|
|||
merge = writer.getNextMerge();
|
||||
if (merge != null) {
|
||||
writer.mergeInit(merge);
|
||||
message(" merge thread: do another merge " + merge.segString(dir));
|
||||
if (verbose())
|
||||
message(" merge thread: do another merge " + merge.segString(dir));
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
message(" merge thread: done");
|
||||
if (verbose())
|
||||
message(" merge thread: done");
|
||||
|
||||
} catch (Throwable exc) {
|
||||
|
||||
|
|
|
@ -395,7 +395,8 @@ final class DocumentsWriter {
|
|||
}
|
||||
|
||||
void message(String message) {
|
||||
writer.message("DW: " + message);
|
||||
if (infoStream != null)
|
||||
writer.message("DW: " + message);
|
||||
}
|
||||
|
||||
final List openFiles = new ArrayList();
|
||||
|
@ -433,7 +434,8 @@ final class DocumentsWriter {
|
|||
synchronized void abort() throws IOException {
|
||||
|
||||
try {
|
||||
message("docWriter: now abort");
|
||||
if (infoStream != null)
|
||||
message("docWriter: now abort");
|
||||
|
||||
// Forcefully remove waiting ThreadStates from line
|
||||
waitQueue.abort();
|
||||
|
|
|
@ -1181,7 +1181,8 @@ public class IndexWriter {
|
|||
oldInfos.read(directory, commit.getSegmentsFileName());
|
||||
segmentInfos.replace(oldInfos);
|
||||
changeCount++;
|
||||
message("init: loaded commit \"" + commit.getSegmentsFileName() + "\"");
|
||||
if (infoStream != null)
|
||||
message("init: loaded commit \"" + commit.getSegmentsFileName() + "\"");
|
||||
}
|
||||
|
||||
// We assume that this segments_N was previously
|
||||
|
@ -1606,6 +1607,11 @@ public class IndexWriter {
|
|||
return infoStream;
|
||||
}
|
||||
|
||||
/** Returns true if verbosing is enabled (i.e., infoStream != null). */
|
||||
public boolean verbose() {
|
||||
return infoStream != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum time to wait for a write lock (in milliseconds) for this instance of IndexWriter. @see
|
||||
* @see #setDefaultWriteLockTimeout to change the default value for all instances of IndexWriter.
|
||||
|
@ -1817,9 +1823,8 @@ public class IndexWriter {
|
|||
docStoreSegment = docWriter.closeDocStore();
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
if (infoStream != null)
|
||||
message("hit exception closing doc store segment");
|
||||
if (!success && infoStream != null) {
|
||||
message("hit exception closing doc store segment");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3582,7 +3587,8 @@ public class IndexWriter {
|
|||
if (!autoCommit && pendingCommit != null)
|
||||
throw new IllegalStateException("prepareCommit was already called with no corresponding call to commit");
|
||||
|
||||
message("prepareCommit: flush");
|
||||
if (infoStream != null)
|
||||
message("prepareCommit: flush");
|
||||
|
||||
flush(true, true, true);
|
||||
|
||||
|
@ -3658,12 +3664,14 @@ public class IndexWriter {
|
|||
waitForCommit();
|
||||
|
||||
try {
|
||||
message("commit: start");
|
||||
if (infoStream != null)
|
||||
message("commit: start");
|
||||
|
||||
if (autoCommit || pendingCommit == null) {
|
||||
message("commit: now prepare");
|
||||
if (infoStream != null)
|
||||
message("commit: now prepare");
|
||||
prepareCommit(commitUserData, true);
|
||||
} else
|
||||
} else if (infoStream != null)
|
||||
message("commit: already prepared");
|
||||
|
||||
finishCommit();
|
||||
|
@ -3676,9 +3684,11 @@ public class IndexWriter {
|
|||
|
||||
if (pendingCommit != null) {
|
||||
try {
|
||||
message("commit: pendingCommit != null");
|
||||
if (infoStream != null)
|
||||
message("commit: pendingCommit != null");
|
||||
pendingCommit.finishCommit(directory);
|
||||
message("commit: wrote segments file \"" + pendingCommit.getCurrentSegmentFileName() + "\"");
|
||||
if (infoStream != null)
|
||||
message("commit: wrote segments file \"" + pendingCommit.getCurrentSegmentFileName() + "\"");
|
||||
lastCommitChangeCount = pendingCommitChangeCount;
|
||||
segmentInfos.updateGeneration(pendingCommit);
|
||||
segmentInfos.setUserData(pendingCommit.getUserData());
|
||||
|
@ -3690,10 +3700,11 @@ public class IndexWriter {
|
|||
notifyAll();
|
||||
}
|
||||
|
||||
} else
|
||||
message("commit: pendingCommit == null; skip");
|
||||
} else if (infoStream != null)
|
||||
message("commit: pendingCommit == null; skip");
|
||||
|
||||
message("commit: done");
|
||||
if (infoStream != null)
|
||||
message("commit: done");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4008,7 +4019,8 @@ public class IndexWriter {
|
|||
|
||||
if (deletes != null) {
|
||||
merge.info.advanceDelGen();
|
||||
message("commit merge deletes to " + merge.info.getDelFileName());
|
||||
if (infoStream != null)
|
||||
message("commit merge deletes to " + merge.info.getDelFileName());
|
||||
deletes.write(directory, merge.info.getDelFileName());
|
||||
merge.info.setDelCount(delCount);
|
||||
assert delCount == deletes.count();
|
||||
|
@ -4857,7 +4869,8 @@ public class IndexWriter {
|
|||
// Because we incRef'd this commit point, above,
|
||||
// the file had better exist:
|
||||
assert directory.fileExists(fileName): "file '" + fileName + "' does not exist dir=" + directory;
|
||||
message("now sync " + fileName);
|
||||
if (infoStream != null)
|
||||
message("now sync " + fileName);
|
||||
directory.sync(fileName);
|
||||
success = true;
|
||||
} finally {
|
||||
|
@ -4888,7 +4901,8 @@ public class IndexWriter {
|
|||
|
||||
// Wait now for any current pending commit to complete:
|
||||
while(pendingCommit != null) {
|
||||
message("wait for existing pendingCommit to finish...");
|
||||
if (infoStream != null)
|
||||
message("wait for existing pendingCommit to finish...");
|
||||
doWait();
|
||||
}
|
||||
|
||||
|
@ -4917,14 +4931,15 @@ public class IndexWriter {
|
|||
pendingCommitChangeCount = myChangeCount;
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success)
|
||||
if (!success && infoStream != null)
|
||||
message("hit exception committing segments file");
|
||||
}
|
||||
} else
|
||||
} else if (infoStream != null)
|
||||
message("sync superseded by newer infos");
|
||||
}
|
||||
|
||||
message("done all syncs");
|
||||
if (infoStream != null)
|
||||
message("done all syncs");
|
||||
|
||||
assert testPoint("midStartCommitSuccess");
|
||||
|
||||
|
|
|
@ -63,8 +63,12 @@ public abstract class LogMergePolicy extends MergePolicy {
|
|||
private boolean useCompoundDocStore = true;
|
||||
private IndexWriter writer;
|
||||
|
||||
protected boolean verbose() {
|
||||
return writer != null && writer.verbose();
|
||||
}
|
||||
|
||||
private void message(String message) {
|
||||
if (writer != null)
|
||||
if (verbose())
|
||||
writer.message("LMP: " + message);
|
||||
}
|
||||
|
||||
|
@ -258,20 +262,23 @@ public abstract class LogMergePolicy extends MergePolicy {
|
|||
|
||||
final int numSegments = segmentInfos.size();
|
||||
|
||||
message("findMergesToExpungeDeletes: " + numSegments + " segments");
|
||||
if (verbose())
|
||||
message("findMergesToExpungeDeletes: " + numSegments + " segments");
|
||||
|
||||
MergeSpecification spec = new MergeSpecification();
|
||||
int firstSegmentWithDeletions = -1;
|
||||
for(int i=0;i<numSegments;i++) {
|
||||
final SegmentInfo info = segmentInfos.info(i);
|
||||
if (info.hasDeletions()) {
|
||||
message(" segment " + info.name + " has deletions");
|
||||
if (verbose())
|
||||
message(" segment " + info.name + " has deletions");
|
||||
if (firstSegmentWithDeletions == -1)
|
||||
firstSegmentWithDeletions = i;
|
||||
else if (i - firstSegmentWithDeletions == mergeFactor) {
|
||||
// We've seen mergeFactor segments in a row with
|
||||
// deletions, so force a merge now:
|
||||
message(" add merge " + firstSegmentWithDeletions + " to " + (i-1) + " inclusive");
|
||||
if (verbose())
|
||||
message(" add merge " + firstSegmentWithDeletions + " to " + (i-1) + " inclusive");
|
||||
spec.add(new OneMerge(segmentInfos.range(firstSegmentWithDeletions, i), useCompoundFile));
|
||||
firstSegmentWithDeletions = i;
|
||||
}
|
||||
|
@ -279,14 +286,16 @@ public abstract class LogMergePolicy extends MergePolicy {
|
|||
// End of a sequence of segments with deletions, so,
|
||||
// merge those past segments even if it's fewer than
|
||||
// mergeFactor segments
|
||||
message(" add merge " + firstSegmentWithDeletions + " to " + (i-1) + " inclusive");
|
||||
if (verbose())
|
||||
message(" add merge " + firstSegmentWithDeletions + " to " + (i-1) + " inclusive");
|
||||
spec.add(new OneMerge(segmentInfos.range(firstSegmentWithDeletions, i), useCompoundFile));
|
||||
firstSegmentWithDeletions = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstSegmentWithDeletions != -1) {
|
||||
message(" add merge " + firstSegmentWithDeletions + " to " + (numSegments-1) + " inclusive");
|
||||
if (verbose())
|
||||
message(" add merge " + firstSegmentWithDeletions + " to " + (numSegments-1) + " inclusive");
|
||||
spec.add(new OneMerge(segmentInfos.range(firstSegmentWithDeletions, numSegments), useCompoundFile));
|
||||
}
|
||||
|
||||
|
@ -304,7 +313,8 @@ public abstract class LogMergePolicy extends MergePolicy {
|
|||
|
||||
final int numSegments = infos.size();
|
||||
this.writer = writer;
|
||||
message("findMerges: " + numSegments + " segments");
|
||||
if (verbose())
|
||||
message("findMerges: " + numSegments + " segments");
|
||||
|
||||
// Compute levels, which is just log (base mergeFactor)
|
||||
// of the size of each segment
|
||||
|
@ -371,7 +381,8 @@ public abstract class LogMergePolicy extends MergePolicy {
|
|||
}
|
||||
upto--;
|
||||
}
|
||||
message(" level " + levelBottom + " to " + maxLevel + ": " + (1+upto-start) + " segments");
|
||||
if (verbose())
|
||||
message(" level " + levelBottom + " to " + maxLevel + ": " + (1+upto-start) + " segments");
|
||||
|
||||
// Finally, record all merges that are viable at this level:
|
||||
int end = start + mergeFactor;
|
||||
|
@ -385,9 +396,10 @@ public abstract class LogMergePolicy extends MergePolicy {
|
|||
if (!anyTooLarge) {
|
||||
if (spec == null)
|
||||
spec = new MergeSpecification();
|
||||
message(" " + start + " to " + end + ": add this merge");
|
||||
if (verbose())
|
||||
message(" " + start + " to " + end + ": add this merge");
|
||||
spec.add(new OneMerge(infos.range(start, end), useCompoundFile));
|
||||
} else
|
||||
} else if (verbose())
|
||||
message(" " + start + " to " + end + ": contains segment over maxMergeSize or maxMergeDocs; skipping");
|
||||
|
||||
start = end;
|
||||
|
|
Loading…
Reference in New Issue