Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-1654. Ensure container state on datanode gets synced to disk whennever state change happens. #923

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -80,20 +80,25 @@ private 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);
// Compute Checksum and update ContainerData
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) {
Expand Down
Expand Up @@ -249,6 +249,9 @@ public long takeSnapshot() throws IOException {
LOG.info("Taking a snapshot to file {}", snapshotFile);
try (FileOutputStream fos = new FileOutputStream(snapshotFile)) {
persistContainerSet(fos);
fos.flush();
// make sure the snapshot file is synced
bshashikant marked this conversation as resolved.
Show resolved Hide resolved
fos.getFD().sync();
} catch (IOException ioe) {
LOG.warn("Failed to write snapshot file \"" + snapshotFile
+ "\", last applied index=" + ti);
Expand Down