This is an automated email from the ASF dual-hosted git repository.

brandonwilliams pushed a commit to branch cassandra-3.11
in repository https://gitbox.apache.org/repos/asf/cassandra.git

commit d043217ff0e16ee3fa14e84def4ba33a458b542e
Merge: e5c96230ac 5d427ff6e5
Author: Brandon Williams <[email protected]>
AuthorDate: Fri May 13 06:48:10 2022 -0500

    Merge branch 'cassandra-3.0' into cassandra-3.11

 CHANGES.txt                                               |  1 +
 src/java/org/apache/cassandra/io/sstable/SSTable.java     |  5 ++++-
 src/java/org/apache/cassandra/io/util/ChecksumWriter.java | 11 ++++++-----
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --cc CHANGES.txt
index 0eb2acba28,4462e22067..f409859eea
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,12 -1,5 +1,13 @@@
 -3.0.27
 +3.11.13
 + * Upgrade jackson-databind to 2.13.2.2 (CASSANDRA-17556)
 + * Upgrade slf4j to 1.7.25 (CASSANDRA-17474)
 + * Upgrade jackson to 2.13.2 (CASSANDRA-17492)
 + * emit warning on keyspace creation when replication factor is bigger than 
the number of nodes (CASSANDRA-16747)
 + * Fix snapshot true size calculation (CASSANDRA-17267)
 + * Validate existence of DCs when repairing (CASSANDRA-17407)
 + * dropping of a materialized view creates a snapshot with dropped- prefix 
(CASSANDRA-17415)
 +Merged from 3.0:
+  * 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)
diff --cc src/java/org/apache/cassandra/io/util/ChecksumWriter.java
index dc5eaea62d,0000000000..50aaccbc7c
mode 100644,000000..100644
--- a/src/java/org/apache/cassandra/io/util/ChecksumWriter.java
+++ b/src/java/org/apache/cassandra/io/util/ChecksumWriter.java
@@@ -1,103 -1,0 +1,104 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +
 +package org.apache.cassandra.io.util;
 +
 +import java.io.*;
 +import java.nio.ByteBuffer;
- import java.nio.file.Files;
++import java.nio.charset.StandardCharsets;
 +import java.util.zip.CRC32;
 +
 +import javax.annotation.Nonnull;
 +
- import com.google.common.base.Charsets;
- 
 +import org.apache.cassandra.io.FSWriteError;
 +
 +public class ChecksumWriter
 +{
 +    private final CRC32 incrementalChecksum = new CRC32();
 +    private final DataOutput incrementalOut;
 +    private final CRC32 fullChecksum = new CRC32();
 +
 +    public ChecksumWriter(DataOutput incrementalOut)
 +    {
 +        this.incrementalOut = incrementalOut;
 +    }
 +
 +    public void writeChunkSize(int length)
 +    {
 +        try
 +        {
 +            incrementalOut.writeInt(length);
 +        }
 +        catch (IOException e)
 +        {
 +            throw new IOError(e);
 +        }
 +    }
 +
 +    // checksumIncrementalResult indicates if the checksum we compute for 
this buffer should itself be
 +    // included in the full checksum, translating to if the partial checksum 
is serialized along with the
 +    // data it checksums (in which case the file checksum as calculated by 
external tools would mismatch if
 +    // we did not include it), or independently.
 +
 +    // CompressedSequentialWriters serialize the partial checksums inline 
with the compressed data chunks they
 +    // corroborate, whereas ChecksummedSequentialWriters serialize them to a 
different file.
 +    public void appendDirect(ByteBuffer bb, boolean checksumIncrementalResult)
 +    {
 +        try
 +        {
 +            ByteBuffer toAppend = bb.duplicate();
 +            toAppend.mark();
 +            incrementalChecksum.update(toAppend);
 +            toAppend.reset();
 +
 +            int incrementalChecksumValue = (int) 
incrementalChecksum.getValue();
 +            incrementalOut.writeInt(incrementalChecksumValue);
 +
 +            fullChecksum.update(toAppend);
 +            if (checksumIncrementalResult)
 +            {
 +                ByteBuffer byteBuffer = ByteBuffer.allocate(4);
 +                byteBuffer.putInt(incrementalChecksumValue);
 +                assert byteBuffer.arrayOffset() == 0;
 +                fullChecksum.update(byteBuffer.array(), 0, 
byteBuffer.array().length);
 +            }
 +            incrementalChecksum.reset();
 +
 +        }
 +        catch (IOException e)
 +        {
 +            throw new IOError(e);
 +        }
 +    }
 +
 +    public void writeFullChecksum(@Nonnull File digestFile)
 +    {
-         try (BufferedWriter out = 
Files.newBufferedWriter(digestFile.toPath(), Charsets.UTF_8))
++        try (FileOutputStream fos = new FileOutputStream(digestFile);
++             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)
 +        {
 +            throw new FSWriteError(e, digestFile);
 +        }
 +    }
 +}
 +


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to