HDDS-1654. Ensure container state on datanode gets synced to disk whennever state change happens. Cotributed by Shashikant Banerjee. (#923)
This commit is contained in:
parent
ccceedb432
commit
20cf50c6d0
|
@ -80,6 +80,7 @@ public final class ContainerDataYaml {
|
||||||
public static void createContainerFile(ContainerType containerType,
|
public static void createContainerFile(ContainerType containerType,
|
||||||
ContainerData containerData, File containerFile) throws IOException {
|
ContainerData containerData, File containerFile) throws IOException {
|
||||||
Writer writer = null;
|
Writer writer = null;
|
||||||
|
FileOutputStream out = null;
|
||||||
try {
|
try {
|
||||||
// Create Yaml for given container type
|
// Create Yaml for given container type
|
||||||
Yaml yaml = getYamlForContainerType(containerType);
|
Yaml yaml = getYamlForContainerType(containerType);
|
||||||
|
@ -87,13 +88,17 @@ public final class ContainerDataYaml {
|
||||||
containerData.computeAndSetChecksum(yaml);
|
containerData.computeAndSetChecksum(yaml);
|
||||||
|
|
||||||
// Write the ContainerData with checksum to Yaml file.
|
// Write the ContainerData with checksum to Yaml file.
|
||||||
writer = new OutputStreamWriter(new FileOutputStream(
|
out = new FileOutputStream(
|
||||||
containerFile), "UTF-8");
|
containerFile);
|
||||||
|
writer = new OutputStreamWriter(out, "UTF-8");
|
||||||
yaml.dump(containerData, writer);
|
yaml.dump(containerData, writer);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (writer != null) {
|
if (writer != null) {
|
||||||
|
writer.flush();
|
||||||
|
// make sure the container metadata is synced to disk.
|
||||||
|
out.getFD().sync();
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
|
|
@ -262,6 +262,9 @@ public class ContainerStateMachine extends BaseStateMachine {
|
||||||
LOG.info("{}: Taking a snapshot at:{} file {}", gid, ti, snapshotFile);
|
LOG.info("{}: Taking a snapshot at:{} file {}", gid, ti, snapshotFile);
|
||||||
try (FileOutputStream fos = new FileOutputStream(snapshotFile)) {
|
try (FileOutputStream fos = new FileOutputStream(snapshotFile)) {
|
||||||
persistContainerSet(fos);
|
persistContainerSet(fos);
|
||||||
|
fos.flush();
|
||||||
|
// make sure the snapshot file is synced
|
||||||
|
fos.getFD().sync();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
LOG.info("{}: Failed to write snapshot at:{} file {}", gid, ti,
|
LOG.info("{}: Failed to write snapshot at:{} file {}", gid, ti,
|
||||||
snapshotFile);
|
snapshotFile);
|
||||||
|
|
Loading…
Reference in New Issue