From 04a2b6f941f6b59e7895aa8126c625fb4b758f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=BD=E6=98=B1=E5=B9=B3?= <32081217+shiyup@users.noreply.github.com> Date: Tue, 18 Jul 2023 16:16:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=8E=E8=BF=9C=E7=A8=8B?= =?UTF-8?q?=E4=B8=8B=E8=BD=BDrds-binlog=E6=96=87=E4=BB=B6=E5=88=B0?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E6=97=B6=E5=93=8D=E5=BA=94=E5=A4=B4=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8D=E5=88=B0Content-Length=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84NPE=E7=9A=84=E9=97=AE=E9=A2=98=20(#4760)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inbound/mysql/rds/BinlogDownloadQueue.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/rds/BinlogDownloadQueue.java b/parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/rds/BinlogDownloadQueue.java index 0b0c36f4..dabbd2ed 100644 --- a/parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/rds/BinlogDownloadQueue.java +++ b/parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/rds/BinlogDownloadQueue.java @@ -22,6 +22,7 @@ import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; +import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; @@ -209,7 +210,9 @@ public class BinlogDownloadQueue { private static void saveFile(File parentFile, String fileName, HttpResponse response) throws IOException { InputStream is = response.getEntity().getContent(); - long totalSize = Long.parseLong(response.getFirstHeader("Content-Length").getValue()); + boolean isChunked = response.getEntity().isChunked(); + Header contentLengthHeader = response.getFirstHeader("Content-Length"); + long totalSize = isChunked || contentLengthHeader == null ? 0 : Long.parseLong(contentLengthHeader.getValue()); if (response.getFirstHeader("Content-Disposition") != null) { fileName = response.getFirstHeader("Content-Disposition").getValue(); fileName = StringUtils.substringAfter(fileName, "filename="); @@ -262,11 +265,13 @@ public class BinlogDownloadQueue { while ((len = is.read(buffer)) != -1) { fos.write(buffer, 0, len); copySize += len; - long progress = copySize * 100 / totalSize; - if (progress >= nextPrintProgress) { - logger.info("download " + file.getName() + " progress : " + progress + if (totalSize > 0){ + long progress = copySize * 100 / totalSize; + if (progress >= nextPrintProgress) { + logger.info("download " + file.getName() + " progress : " + progress + "% , download size : " + copySize + ", total size : " + totalSize); - nextPrintProgress += 10; + nextPrintProgress += 10; + } } } logger.info("download file " + file.getName() + " end!");