From 06a2dcebea66153fc8efa6ccf7c77ada5c2896ff Mon Sep 17 00:00:00 2001 From: Zhichao Cao Date: Thu, 14 May 2020 14:56:10 -0700 Subject: [PATCH] Move checksum calculation ahead of memory copy (#6844) Summary: Originally, the checksum of appended data in writable file writer is calculated after the data is copied to the buffer. It will not be able to catch the bit flip happens during copy. Move the checksum calculation before it. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6844 Test Plan: pass make asan_check Reviewed By: cheng-chang Differential Revision: D21576726 Pulled By: zhichao-cao fbshipit-source-id: 0a062a1f19886f6ea0d4e3f557e6f4b799773254 --- file/writable_file_writer.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/file/writable_file_writer.cc b/file/writable_file_writer.cc index ec4e7c8c3..2f44f7f58 100644 --- a/file/writable_file_writer.cc +++ b/file/writable_file_writer.cc @@ -30,6 +30,9 @@ IOStatus WritableFileWriter::Append(const Slice& data) { TEST_KILL_RANDOM("WritableFileWriter::Append:0", rocksdb_kill_odds * REDUCE_ODDS2); + // Calculate the checksum of appended data + CalculateFileChecksum(data); + { IOSTATS_TIMER_GUARD(prepare_write_nanos); TEST_SYNC_POINT("WritableFileWriter::Append:BeforePrepareWrite"); @@ -89,7 +92,6 @@ IOStatus WritableFileWriter::Append(const Slice& data) { TEST_KILL_RANDOM("WritableFileWriter::Append:1", rocksdb_kill_odds); if (s.ok()) { filesize_ += data.size(); - CalculateFileChecksum(data); } return s; }