mirror of
https://github.com/apache/lucene.git
synced 2025-02-10 03:55:46 +00:00
defensively switch to AtomicLong for IndexWriter's changeCount; make failing test a bit more evil
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1671258 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2d15d935f0
commit
4297e28f7a
@ -255,7 +255,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||||||
private final Directory mergeDirectory; // used for merging
|
private final Directory mergeDirectory; // used for merging
|
||||||
private final Analyzer analyzer; // how to analyze text
|
private final Analyzer analyzer; // how to analyze text
|
||||||
|
|
||||||
private volatile long changeCount; // increments every time a change is completed
|
private final AtomicLong changeCount = new AtomicLong(); // increments every time a change is completed
|
||||||
private volatile long lastCommitChangeCount; // last changeCount that was committed
|
private volatile long lastCommitChangeCount; // last changeCount that was committed
|
||||||
|
|
||||||
private List<SegmentCommitInfo> rollbackSegments; // list of segmentInfo we will fallback to if the commit fails
|
private List<SegmentCommitInfo> rollbackSegments; // list of segmentInfo we will fallback to if the commit fails
|
||||||
@ -1526,7 +1526,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||||||
// could close, re-open and re-return the same segment
|
// could close, re-open and re-return the same segment
|
||||||
// name that was previously returned which can cause
|
// name that was previously returned which can cause
|
||||||
// problems at least with ConcurrentMergeScheduler.
|
// problems at least with ConcurrentMergeScheduler.
|
||||||
changeCount++;
|
changeCount.incrementAndGet();
|
||||||
segmentInfos.changed();
|
segmentInfos.changed();
|
||||||
return "_" + Integer.toString(segmentInfos.counter++, Character.MAX_RADIX);
|
return "_" + Integer.toString(segmentInfos.counter++, Character.MAX_RADIX);
|
||||||
}
|
}
|
||||||
@ -1974,7 +1974,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||||||
deleter.checkpoint(segmentInfos, false);
|
deleter.checkpoint(segmentInfos, false);
|
||||||
deleter.refresh();
|
deleter.refresh();
|
||||||
|
|
||||||
lastCommitChangeCount = changeCount;
|
lastCommitChangeCount = changeCount.get();
|
||||||
|
|
||||||
deleter.close();
|
deleter.close();
|
||||||
|
|
||||||
@ -2089,7 +2089,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||||||
// Don't bother saving any changes in our segmentInfos
|
// Don't bother saving any changes in our segmentInfos
|
||||||
readerPool.dropAll(false);
|
readerPool.dropAll(false);
|
||||||
// Mark that the index has changed
|
// Mark that the index has changed
|
||||||
++changeCount;
|
changeCount.incrementAndGet();
|
||||||
segmentInfos.changed();
|
segmentInfos.changed();
|
||||||
globalFieldNumberMap.clear();
|
globalFieldNumberMap.clear();
|
||||||
|
|
||||||
@ -2202,13 +2202,13 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||||||
* close/commit we will write a new segments file, but
|
* close/commit we will write a new segments file, but
|
||||||
* does NOT bump segmentInfos.version. */
|
* does NOT bump segmentInfos.version. */
|
||||||
synchronized void checkpointNoSIS() throws IOException {
|
synchronized void checkpointNoSIS() throws IOException {
|
||||||
changeCount++;
|
changeCount.incrementAndGet();
|
||||||
deleter.checkpoint(segmentInfos, false);
|
deleter.checkpoint(segmentInfos, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Called internally if any index state has changed. */
|
/** Called internally if any index state has changed. */
|
||||||
synchronized void changed() {
|
synchronized void changed() {
|
||||||
changeCount++;
|
changeCount.incrementAndGet();
|
||||||
segmentInfos.changed();
|
segmentInfos.changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2712,7 +2712,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||||||
// sneak into the commit point:
|
// sneak into the commit point:
|
||||||
toCommit = segmentInfos.clone();
|
toCommit = segmentInfos.clone();
|
||||||
|
|
||||||
pendingCommitChangeCount = changeCount;
|
pendingCommitChangeCount = changeCount.get();
|
||||||
|
|
||||||
// This protects the segmentInfos we are now going
|
// This protects the segmentInfos we are now going
|
||||||
// to commit. This is important in case, eg, while
|
// to commit. This is important in case, eg, while
|
||||||
@ -2770,7 +2770,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||||||
*/
|
*/
|
||||||
public final synchronized void setCommitData(Map<String,String> commitUserData) {
|
public final synchronized void setCommitData(Map<String,String> commitUserData) {
|
||||||
segmentInfos.setUserData(new HashMap<>(commitUserData));
|
segmentInfos.setUserData(new HashMap<>(commitUserData));
|
||||||
++changeCount;
|
changeCount.incrementAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2826,7 +2826,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||||||
* merged finished, this method may return true right
|
* merged finished, this method may return true right
|
||||||
* after you had just called {@link #commit}. */
|
* after you had just called {@link #commit}. */
|
||||||
public final boolean hasUncommittedChanges() {
|
public final boolean hasUncommittedChanges() {
|
||||||
return changeCount != lastCommitChangeCount || docWriter.anyChanges() || bufferedUpdatesStream.any();
|
return changeCount.get() != lastCommitChangeCount || docWriter.anyChanges() || bufferedUpdatesStream.any();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void commitInternal(MergePolicy mergePolicy) throws IOException {
|
private final void commitInternal(MergePolicy mergePolicy) throws IOException {
|
||||||
@ -4253,7 +4253,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||||||
|
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
|
|
||||||
if (lastCommitChangeCount > changeCount) {
|
if (lastCommitChangeCount > changeCount.get()) {
|
||||||
throw new IllegalStateException("lastCommitChangeCount=" + lastCommitChangeCount + ",changeCount=" + changeCount);
|
throw new IllegalStateException("lastCommitChangeCount=" + lastCommitChangeCount + ",changeCount=" + changeCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.MockAnalyzer;
|
import org.apache.lucene.analysis.MockAnalyzer;
|
||||||
import org.apache.lucene.document.Document;
|
import org.apache.lucene.document.Document;
|
||||||
@ -293,12 +294,14 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCase {
|
|||||||
|
|
||||||
Thread[] threads = new Thread[10];
|
Thread[] threads = new Thread[10];
|
||||||
final IndexCommit[] snapshots = new IndexCommit[threads.length];
|
final IndexCommit[] snapshots = new IndexCommit[threads.length];
|
||||||
|
final CountDownLatch startingGun = new CountDownLatch(1);
|
||||||
for (int i = 0; i < threads.length; i++) {
|
for (int i = 0; i < threads.length; i++) {
|
||||||
final int finalI = i;
|
final int finalI = i;
|
||||||
threads[i] = new Thread() {
|
threads[i] = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
startingGun.await();
|
||||||
writer.addDocument(new Document());
|
writer.addDocument(new Document());
|
||||||
writer.commit();
|
writer.commit();
|
||||||
snapshots[finalI] = sdp.snapshot();
|
snapshots[finalI] = sdp.snapshot();
|
||||||
@ -314,6 +317,8 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCase {
|
|||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startingGun.countDown();
|
||||||
|
|
||||||
for (Thread t : threads) {
|
for (Thread t : threads) {
|
||||||
t.join();
|
t.join();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user