From 36b887ee7c13044e0dbfefc536d9108e25e57ba2 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 4 Jul 2016 19:22:12 -0400 Subject: [PATCH] Throw translog corrupted exception on malformed op Today when reading a malformed operation from the translog, we throw an assertion error that is immediately caught and wrapped into a translog corrupted exception. This commit replaces this by electing to directly throw a translog corrupted exception instead. Additionally, this cleanup also addressed a double-wrapped translog corrupted exception. Namely, verifying the checksum can throw a translog corrupted exception which the existing code would catch and wrap again in a translog corrupted exception. Relates #19256 --- .../java/org/elasticsearch/index/translog/Translog.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/translog/Translog.java b/core/src/main/java/org/elasticsearch/index/translog/Translog.java index d26a06a5ce6..eb22c84cf0e 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/core/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -1128,7 +1128,7 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC try { final int opSize = in.readInt(); if (opSize < 4) { // 4byte for the checksum - throw new AssertionError("operation size must be at least 4 but was: " + opSize); + throw new TranslogCorruptedException("operation size must be at least 4 but was: " + opSize); } in.resetDigest(); // size is not part of the checksum! if (in.markSupported()) { // if we can we validate the checksum first @@ -1143,10 +1143,10 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC } operation = Translog.Operation.readType(in); verifyChecksum(in); + } catch (TranslogCorruptedException e) { + throw e; } catch (EOFException e) { throw new TruncatedTranslogException("reached premature end of file, translog is truncated", e); - } catch (AssertionError | Exception e) { - throw new TranslogCorruptedException("translog corruption while reading from stream", e); } return operation; }