Fix assertion at end of forceRefreshes (#37559)

This commit ensures that we only change refreshListeners to a list if we're actually adding
something to the list.
This commit is contained in:
Yannick Welsch 2019-01-17 19:18:47 +01:00 committed by GitHub
parent 6d64a2a901
commit 68de2edb14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 8 deletions

View File

@ -129,15 +129,12 @@ public final class RefreshListeners implements ReferenceManager.RefreshListener,
return true;
}
synchronized (this) {
List<Tuple<Translog.Location, Consumer<Boolean>>> listeners = refreshListeners;
if (listeners == null) {
if (closed) {
throw new IllegalStateException("can't wait for refresh on a closed index");
}
listeners = new ArrayList<>();
refreshListeners = listeners;
if (closed) {
throw new IllegalStateException("can't wait for refresh on a closed index");
}
if (refreshForcers == 0 && listeners.size() < getMaxRefreshListeners.getAsInt()) {
List<Tuple<Translog.Location, Consumer<Boolean>>> listeners = refreshListeners;
final int maxRefreshes = getMaxRefreshListeners.getAsInt();
if (refreshForcers == 0 && maxRefreshes > 0 && (listeners == null || listeners.size() < maxRefreshes)) {
ThreadContext.StoredContext storedContext = threadContext.newStoredContext(true);
Consumer<Boolean> contextPreservingListener = forced -> {
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
@ -145,8 +142,12 @@ public final class RefreshListeners implements ReferenceManager.RefreshListener,
listener.accept(forced);
}
};
if (listeners == null) {
listeners = new ArrayList<>();
}
// We have a free slot so register the listener
listeners.add(new Tuple<>(location, contextPreservingListener));
refreshListeners = listeners;
return false;
}
}