Skip to content

Commit 20cf50c

Browse files
committed
HDDS-1654. Ensure container state on datanode gets synced to disk whennever state change happens. Cotributed by Shashikant Banerjee. (#923)
1 parent ccceedb commit 20cf50c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerDataYaml.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,25 @@ private ContainerDataYaml() {
8080
public static void createContainerFile(ContainerType containerType,
8181
ContainerData containerData, File containerFile) throws IOException {
8282
Writer writer = null;
83+
FileOutputStream out = null;
8384
try {
8485
// Create Yaml for given container type
8586
Yaml yaml = getYamlForContainerType(containerType);
8687
// Compute Checksum and update ContainerData
8788
containerData.computeAndSetChecksum(yaml);
8889

8990
// Write the ContainerData with checksum to Yaml file.
90-
writer = new OutputStreamWriter(new FileOutputStream(
91-
containerFile), "UTF-8");
91+
out = new FileOutputStream(
92+
containerFile);
93+
writer = new OutputStreamWriter(out, "UTF-8");
9294
yaml.dump(containerData, writer);
9395

9496
} finally {
9597
try {
9698
if (writer != null) {
99+
writer.flush();
100+
// make sure the container metadata is synced to disk.
101+
out.getFD().sync();
97102
writer.close();
98103
}
99104
} catch (IOException ex) {

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ public long takeSnapshot() throws IOException {
262262
LOG.info("{}: Taking a snapshot at:{} file {}", gid, ti, snapshotFile);
263263
try (FileOutputStream fos = new FileOutputStream(snapshotFile)) {
264264
persistContainerSet(fos);
265+
fos.flush();
266+
// make sure the snapshot file is synced
267+
fos.getFD().sync();
265268
} catch (IOException ioe) {
266269
LOG.info("{}: Failed to write snapshot at:{} file {}", gid, ti,
267270
snapshotFile);

0 commit comments

Comments
 (0)