mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Improved logging of version mismatch in DLQ file reader (RecordIOReader)
Fixes #11039
This commit is contained in:
parent
8f78612e93
commit
c2391b1849
2 changed files with 28 additions and 2 deletions
|
@ -55,8 +55,12 @@ public final class RecordIOReader implements Closeable {
|
|||
ByteBuffer versionBuffer = ByteBuffer.allocate(1);
|
||||
this.channel.read(versionBuffer);
|
||||
versionBuffer.rewind();
|
||||
if (versionBuffer.get() != VERSION) {
|
||||
throw new RuntimeException("Invalid file. check version");
|
||||
byte versionInFile = versionBuffer.get();
|
||||
if (versionInFile != VERSION) {
|
||||
this.channel.close();
|
||||
throw new RuntimeException(String.format(
|
||||
"Invalid version on PQ data file %s. Expected version: %c. Version found on file: %c",
|
||||
path, VERSION, versionInFile));
|
||||
}
|
||||
this.channelPosition = this.channel.position();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,9 @@ import org.logstash.ackedqueue.StringElement;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Function;
|
||||
|
@ -20,6 +22,7 @@ import static org.hamcrest.CoreMatchers.nullValue;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.logstash.common.io.RecordIOWriter.BLOCK_SIZE;
|
||||
import static org.logstash.common.io.RecordIOWriter.RECORD_HEADER_SIZE;
|
||||
import static org.logstash.common.io.RecordIOWriter.VERSION;
|
||||
|
||||
public class RecordIOReaderTest {
|
||||
private Path file;
|
||||
|
@ -172,6 +175,25 @@ public class RecordIOReaderTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersion() throws IOException {
|
||||
RecordIOWriter writer = new RecordIOWriter(file);
|
||||
FileChannel channel = FileChannel.open(file, StandardOpenOption.READ);
|
||||
ByteBuffer versionBuffer = ByteBuffer.allocate(1);
|
||||
channel.read(versionBuffer);
|
||||
versionBuffer.rewind();
|
||||
channel.close();
|
||||
assertThat(versionBuffer.get() == VERSION, equalTo(true));
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void testVersionMismatch() throws IOException {
|
||||
FileChannel channel = FileChannel.open(file, StandardOpenOption.WRITE);
|
||||
channel.write(ByteBuffer.wrap(new byte[] { '2' }));
|
||||
channel.close();
|
||||
RecordIOReader reader = new RecordIOReader(file);
|
||||
}
|
||||
|
||||
private char[] fillArray(final int fillSize) {
|
||||
char[] blockSize= new char[fillSize];
|
||||
Arrays.fill(blockSize, 'e');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue