From 23f3239dfd5c5e8fa4c1c35b9b9764f0aa9e01a5 Mon Sep 17 00:00:00 2001 From: Ben Osheroff Date: Sun, 14 Jul 2019 18:28:36 +0200 Subject: [PATCH] fixes for non-strictly sequential behavior in JSON fields as of MySQL 8.0.16, there are cases (see https://github.com/zendesk/maxwell/issues/1290) in which MySQL places JSON binary data at the offset specified in the header instead of just laying it out in order. --- .../event/deserialization/json/JsonBinary.java | 3 +++ .../mysql/binlog/io/ByteArrayInputStream.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/json/JsonBinary.java b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/json/JsonBinary.java index a6b5fc0e..61fe3e66 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/json/JsonBinary.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/json/JsonBinary.java @@ -189,6 +189,7 @@ public JsonBinary(byte[] bytes) { public JsonBinary(ByteArrayInputStream contents) { this.reader = contents; + this.reader.mark(Integer.MAX_VALUE); } public String getString() { @@ -397,6 +398,8 @@ protected void parseObject(boolean small, JsonFormatter formatter) } } else { // Parse the value ... + this.reader.reset(); + this.reader.skip(entry.index + 1); parse(entry.type, formatter); } } diff --git a/src/main/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStream.java b/src/main/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStream.java index 350b8709..d899818c 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStream.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStream.java @@ -218,4 +218,18 @@ public void skipToTheEndOfTheBlock() throws IOException { } } + @Override + public synchronized void mark(int readlimit) { + inputStream.mark(readlimit); + } + + @Override + public boolean markSupported() { + return inputStream.markSupported(); + } + + @Override + public synchronized void reset() throws IOException { + inputStream.reset(); + } }