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:
parent
6d64a2a901
commit
68de2edb14
|
@ -129,15 +129,12 @@ public final class RefreshListeners implements ReferenceManager.RefreshListener,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
List<Tuple<Translog.Location, Consumer<Boolean>>> listeners = refreshListeners;
|
if (closed) {
|
||||||
if (listeners == null) {
|
throw new IllegalStateException("can't wait for refresh on a closed index");
|
||||||
if (closed) {
|
|
||||||
throw new IllegalStateException("can't wait for refresh on a closed index");
|
|
||||||
}
|
|
||||||
listeners = new ArrayList<>();
|
|
||||||
refreshListeners = listeners;
|
|
||||||
}
|
}
|
||||||
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);
|
ThreadContext.StoredContext storedContext = threadContext.newStoredContext(true);
|
||||||
Consumer<Boolean> contextPreservingListener = forced -> {
|
Consumer<Boolean> contextPreservingListener = forced -> {
|
||||||
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
|
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
|
||||||
|
@ -145,8 +142,12 @@ public final class RefreshListeners implements ReferenceManager.RefreshListener,
|
||||||
listener.accept(forced);
|
listener.accept(forced);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (listeners == null) {
|
||||||
|
listeners = new ArrayList<>();
|
||||||
|
}
|
||||||
// We have a free slot so register the listener
|
// We have a free slot so register the listener
|
||||||
listeners.add(new Tuple<>(location, contextPreservingListener));
|
listeners.add(new Tuple<>(location, contextPreservingListener));
|
||||||
|
refreshListeners = listeners;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue