diff --git a/logstash-core/src/main/java/org/logstash/ackedqueue/Queue.java b/logstash-core/src/main/java/org/logstash/ackedqueue/Queue.java index 74e550087..efdb7e5c3 100644 --- a/logstash-core/src/main/java/org/logstash/ackedqueue/Queue.java +++ b/logstash-core/src/main/java/org/logstash/ackedqueue/Queue.java @@ -509,21 +509,25 @@ public final class Queue implements Closeable { public boolean isFull() { lock.lock(); try { - if (this.maxBytes > 0L && isMaxBytesReached()) { - return true; - } else { - return (this.maxUnread > 0 && this.unreadCount >= this.maxUnread); - } + return isMaxBytesReached() || isMaxUnreadReached(); } finally { lock.unlock(); } } private boolean isMaxBytesReached() { + if (this.maxBytes <= 0L) { + return false; + } + final long persistedByteSize = getPersistedByteSize(); return ((persistedByteSize > this.maxBytes) || (persistedByteSize == this.maxBytes && !this.headPage.hasSpace(1))); } + private boolean isMaxUnreadReached() { + return this.maxUnread > 0 && (this.unreadCount >= this.maxUnread); + } + /** * Queue is considered empty if it does not contain any tail page and the headpage has no element or all * elements are acked @@ -636,7 +640,7 @@ public final class Queue implements Closeable { } if (! p.isFullyRead()) { - boolean wasFull = isFull(); + boolean wasFull = isMaxUnreadReached(); final SequencedList serialized = p.read(left); int n = serialized.getElements().size();