mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
handle specified dlq-dir with no segments
Before, the DeadLetterQueueReadManager would throw an exception when it attempted to choose to read a segment from its segments list and that list was empty. This fixes that. Fixes #6880
This commit is contained in:
parent
2dd135a162
commit
86f5070a27
2 changed files with 16 additions and 0 deletions
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.logstash.common.io;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.logstash.DLQEntry;
|
||||
import org.logstash.Timestamp;
|
||||
|
||||
|
@ -38,6 +40,7 @@ import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
|
|||
import static org.logstash.common.io.DeadLetterQueueWriteManager.getSegmentPaths;
|
||||
|
||||
public class DeadLetterQueueReadManager {
|
||||
private static final Logger logger = LogManager.getLogger(DeadLetterQueueReadManager.class);
|
||||
|
||||
private RecordIOReader currentReader;
|
||||
private final Path queuePath;
|
||||
|
@ -104,6 +107,11 @@ public class DeadLetterQueueReadManager {
|
|||
long timeoutRemaining = timeout;
|
||||
if (currentReader == null) {
|
||||
timeoutRemaining -= pollNewSegments(timeout);
|
||||
// If no new segments are found, exit
|
||||
if (segments.isEmpty()) {
|
||||
logger.debug("No entries found: no segment files found in dead-letter-queue directory");
|
||||
return null;
|
||||
}
|
||||
currentReader = new RecordIOReader(segments.first());
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,9 @@ import org.logstash.Event;
|
|||
import org.logstash.Timestamp;
|
||||
import org.logstash.ackedqueue.StringElement;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
|
||||
|
@ -134,4 +136,10 @@ public class DeadLetterQueueReadManagerTest {
|
|||
assertThat(entry.getEntryTime().toIso8601(), equalTo(target.toIso8601()));
|
||||
assertThat(entry.getReason(), equalTo("543"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidDirectory() throws Exception {
|
||||
DeadLetterQueueReadManager readManager = new DeadLetterQueueReadManager(dir);
|
||||
assertThat(readManager.pollEntry(100), is(nullValue()));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue