From 945513556bdd2719dee6caf02cb0973b40cb8790 Mon Sep 17 00:00:00 2001 From: Zhichao Cao Date: Wed, 10 Feb 2021 22:18:33 -0800 Subject: [PATCH] Handoff checksum Implementation (#7523) Summary: in PR https://github.com/facebook/rocksdb/issues/7419 , we introduce the new Append and PositionedAppend APIs to WritableFile at File System, which enable RocksDB to pass the data verification information (e.g., checksum of the data) to the lower layer. In this PR, we use the new API in WritableFileWriter, such that the file created via WritableFileWrite can pass the checksum to the storage layer. To control which types file should apply the checksum handoff, we add checksum_handoff_file_types to DBOptions. User can use this option to control which file types (Currently supported file tyes: kLogFile, kTableFile, kDescriptorFile.) should use the new Append and PositionedAppend APIs to handoff the verification information. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7523 Test Plan: add new unit test, pass make check/ make asan_check Reviewed By: pdillinger Differential Revision: D24313271 Pulled By: zhichao-cao fbshipit-source-id: aafd69091ae85c3318e3e17cbb96fe7338da11d0 Signed-off-by: Changlong Chen --- include/rocksdb/file_system.h | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/include/rocksdb/file_system.h b/include/rocksdb/file_system.h index 393b7647a6..43f082d410 100644 --- a/include/rocksdb/file_system.h +++ b/include/rocksdb/file_system.h @@ -17,6 +17,7 @@ #pragma once #include + #include #include #include @@ -25,9 +26,11 @@ #include #include #include + #include "rocksdb/env.h" #include "rocksdb/io_status.h" #include "rocksdb/options.h" +#include "rocksdb/table.h" #include "rocksdb/thread_status.h" namespace ROCKSDB_NAMESPACE { @@ -97,16 +100,22 @@ struct FileOptions : EnvOptions { // to be issued for the file open/creation IOOptions io_options; - FileOptions() : EnvOptions() {} + // The checksum type that is used to calculate the checksum value for + // handoff during file writes. + ChecksumType handoff_checksum_type; + + FileOptions() : EnvOptions(), handoff_checksum_type(ChecksumType::kCRC32c) {} FileOptions(const DBOptions& opts) - : EnvOptions(opts) {} + : EnvOptions(opts), handoff_checksum_type(ChecksumType::kCRC32c) {} FileOptions(const EnvOptions& opts) - : EnvOptions(opts) {} + : EnvOptions(opts), handoff_checksum_type(ChecksumType::kCRC32c) {} FileOptions(const FileOptions& opts) - : EnvOptions(opts), io_options(opts.io_options) {} + : EnvOptions(opts), + io_options(opts.io_options), + handoff_checksum_type(opts.handoff_checksum_type) {} FileOptions& operator=(const FileOptions& opts) = default; }; @@ -740,10 +749,14 @@ class FSWritableFile { virtual IOStatus Append(const Slice& data, const IOOptions& options, IODebugContext* dbg) = 0; - // EXPERIMENTAL / CURRENTLY UNUSED - // Append data with verification information + // Append data with verification information. // Note that this API change is experimental and it might be changed in - // the future. Currently, RocksDB does not use this API. + // the future. Currently, RocksDB only generates crc32c based checksum for + // the file writes when the checksum handoff option is set. + // Expected behavior: if the handoff_checksum_type in FileOptions (currently, + // ChecksumType::kCRC32C is set as default) is not supported by this + // FSWritableFile, the information in DataVerificationInfo can be ignored + // (i.e. does not perform checksum verification). virtual IOStatus Append(const Slice& data, const IOOptions& options, const DataVerificationInfo& /* verification_info */, IODebugContext* dbg) { @@ -777,10 +790,14 @@ class FSWritableFile { return IOStatus::NotSupported("PositionedAppend"); } - // EXPERIMENTAL / CURRENTLY UNUSED // PositionedAppend data with verification information. // Note that this API change is experimental and it might be changed in - // the future. Currently, RocksDB does not use this API. + // the future. Currently, RocksDB only generates crc32c based checksum for + // the file writes when the checksum handoff option is set. + // Expected behavior: if the handoff_checksum_type in FileOptions (currently, + // ChecksumType::kCRC32C is set as default) is not supported by this + // FSWritableFile, the information in DataVerificationInfo can be ignored + // (i.e. does not perform checksum verification). virtual IOStatus PositionedAppend( const Slice& /* data */, uint64_t /* offset */, const IOOptions& /*options*/,