From dd62be160201046764cb66396cc93f27796d77d2 Mon Sep 17 00:00:00 2001 From: yang wei Date: Fri, 5 Jul 2019 11:32:40 +0800 Subject: [PATCH] ARTEMIS-2414 Sync before closing file in case data loss --- .../activemq/artemis/core/io/mapped/MappedSequentialFile.java | 2 ++ .../apache/activemq/artemis/core/io/nio/NIOSequentialFile.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java index 9990bf909c..fb12c9ab15 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java @@ -361,6 +361,8 @@ final class MappedSequentialFile implements SequentialFile { @Override public void close(boolean waitOnSync) { if (this.mappedFile != null) { + if (factory.isDatasync()) + this.mappedFile.force(); this.mappedFile.close(); this.mappedFile = null; } diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java index f241ac06a4..46749ac6fe 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java @@ -135,6 +135,8 @@ public class NIOSequentialFile extends AbstractSequentialFile { try { if (channel != null) { + if (factory.isDatasync()) + channel.force(false); channel.close(); } } catch (ClosedChannelException e) {