You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sh...@apache.org on 2019/07/18 11:39:34 UTC
[hadoop] branch trunk updated: HDDS-1654. Ensure container state on
datanode gets synced to disk whennever state change happens. Cotributed by
Shashikant Banerjee. (#923)
This is an automated email from the ASF dual-hosted git repository.
shashikant pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new 20cf50c HDDS-1654. Ensure container state on datanode gets synced to disk whennever state change happens. Cotributed by Shashikant Banerjee. (#923)
20cf50c is described below
commit 20cf50c6d054324503225c772256f0f91678599a
Author: Shashikant Banerjee <sh...@apache.org>
AuthorDate: Thu Jul 18 17:09:05 2019 +0530
HDDS-1654. Ensure container state on datanode gets synced to disk whennever state change happens. Cotributed by Shashikant Banerjee. (#923)
---
.../hadoop/ozone/container/common/impl/ContainerDataYaml.java | 9 +++++++--
.../common/transport/server/ratis/ContainerStateMachine.java | 3 +++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerDataYaml.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerDataYaml.java
index 1571944..1f9966c 100644
--- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerDataYaml.java
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerDataYaml.java
@@ -80,6 +80,7 @@ public final class ContainerDataYaml {
public static void createContainerFile(ContainerType containerType,
ContainerData containerData, File containerFile) throws IOException {
Writer writer = null;
+ FileOutputStream out = null;
try {
// Create Yaml for given container type
Yaml yaml = getYamlForContainerType(containerType);
@@ -87,13 +88,17 @@ public final class ContainerDataYaml {
containerData.computeAndSetChecksum(yaml);
// Write the ContainerData with checksum to Yaml file.
- writer = new OutputStreamWriter(new FileOutputStream(
- containerFile), "UTF-8");
+ out = new FileOutputStream(
+ containerFile);
+ writer = new OutputStreamWriter(out, "UTF-8");
yaml.dump(containerData, writer);
} finally {
try {
if (writer != null) {
+ writer.flush();
+ // make sure the container metadata is synced to disk.
+ out.getFD().sync();
writer.close();
}
} catch (IOException ex) {
diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java
index 5c3fa85..d82d114 100644
--- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java
@@ -262,6 +262,9 @@ public class ContainerStateMachine extends BaseStateMachine {
LOG.info("{}: Taking a snapshot at:{} file {}", gid, ti, snapshotFile);
try (FileOutputStream fos = new FileOutputStream(snapshotFile)) {
persistContainerSet(fos);
+ fos.flush();
+ // make sure the snapshot file is synced
+ fos.getFD().sync();
} catch (IOException ioe) {
LOG.info("{}: Failed to write snapshot at:{} file {}", gid, ti,
snapshotFile);
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org