Skip to content
Permalink
Browse files
Fsync TOC and Digest files after they're written
Patch by Maciej Sokol; reviewed by brandonwilliams and bereng for
CASSANDRA-10709
  • Loading branch information
masokol authored and driftx committed May 13, 2022
1 parent 0bcc354 commit 5d427ff6e535ba60f0d2f3e07781de9fcdc8fd42
Showing 3 changed files with 14 additions and 7 deletions.
@@ -1,4 +1,5 @@
3.0.27
* fsync TOC and digest files (CASSANDRA-10709)
* Fix URISyntaxException in nodetool with updated Java (CASSANDRA-17581)
* Schema mutations may not be completed on drain (CASSANDRA-17524)
* Fix data corruption in AbstractCompositeType due to static boolean byte buffers (CASSANDRA-14752)
@@ -299,10 +299,13 @@ protected static Set<Component> readTOC(Descriptor descriptor) throws IOExceptio
protected static void appendTOC(Descriptor descriptor, Collection<Component> components)
{
File tocFile = new File(descriptor.filenameFor(Component.TOC));
try (PrintWriter w = new PrintWriter(new FileWriter(tocFile, true)))
try (FileOutputStream fos = new FileOutputStream(tocFile);
PrintWriter w = new PrintWriter(fos))
{
for (Component component : components)
w.println(component.name);
w.flush();
fos.getFD().sync();
}
catch (IOException e)
{
@@ -17,20 +17,20 @@
*/
package org.apache.cassandra.io.util;

import java.io.BufferedWriter;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOError;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.charset.StandardCharsets;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum;

import com.google.common.base.Charsets;

import org.apache.cassandra.io.FSWriteError;
import org.apache.cassandra.io.sstable.Component;
import org.apache.cassandra.io.sstable.Descriptor;
@@ -209,9 +209,12 @@ public void writeFullChecksum(Descriptor descriptor)
if (descriptor.digestComponent == null)
throw new NullPointerException("Null digest component for " + descriptor.ksname + '.' + descriptor.cfname + " file " + descriptor.baseFilename());
File outFile = new File(descriptor.filenameFor(descriptor.digestComponent));
try (BufferedWriter out =Files.newBufferedWriter(outFile.toPath(), Charsets.UTF_8))
try (FileOutputStream fos = new FileOutputStream(outFile);
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(fos)))
{
out.write(String.valueOf(fullChecksum.getValue()));
out.write(String.valueOf(fullChecksum.getValue()).getBytes(StandardCharsets.UTF_8));
out.flush();
fos.getFD().sync();
}
catch (IOException e)
{

0 comments on commit 5d427ff

Please sign in to comment.