Revert "Prevent usage of not initialized IndexCollection"
On master this change is causing an endless loop when running the
acceptance tests, see comments on I487111ad.
This reverts commit cf1bb5487e.
Change-Id: Ie81e9961b96e4206d55d9dc4c60514cd3704b4a7
This commit is contained in:
@@ -23,7 +23,6 @@ import com.google.inject.Singleton;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
/** Dynamic pointers to the index versions used for searching and writing. */
|
/** Dynamic pointers to the index versions used for searching and writing. */
|
||||||
@@ -31,29 +30,21 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
public class IndexCollection implements LifecycleListener {
|
public class IndexCollection implements LifecycleListener {
|
||||||
private final CopyOnWriteArrayList<ChangeIndex> writeIndexes;
|
private final CopyOnWriteArrayList<ChangeIndex> writeIndexes;
|
||||||
private final AtomicReference<ChangeIndex> searchIndex;
|
private final AtomicReference<ChangeIndex> searchIndex;
|
||||||
private final CountDownLatch initLatch;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public IndexCollection() {
|
public IndexCollection() {
|
||||||
this.writeIndexes = Lists.newCopyOnWriteArrayList();
|
this.writeIndexes = Lists.newCopyOnWriteArrayList();
|
||||||
this.searchIndex = new AtomicReference<>();
|
this.searchIndex = new AtomicReference<>();
|
||||||
this.initLatch = new CountDownLatch(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return the current search index version. */
|
/** @return the current search index version. */
|
||||||
public ChangeIndex getSearchIndex() {
|
public ChangeIndex getSearchIndex() {
|
||||||
try {
|
|
||||||
initLatch.await();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
return searchIndex.get();
|
return searchIndex.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSearchIndex(ChangeIndex index) {
|
public void setSearchIndex(ChangeIndex index) {
|
||||||
ChangeIndex old = searchIndex.getAndSet(index);
|
ChangeIndex old = searchIndex.getAndSet(index);
|
||||||
initLatch.countDown();
|
|
||||||
if (old != null && old != index && !writeIndexes.contains(old)) {
|
if (old != null && old != index && !writeIndexes.contains(old)) {
|
||||||
old.close();
|
old.close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user