From 38dfa406ff3cf2b83f7ab2ed292fbff8a651209e Mon Sep 17 00:00:00 2001 From: Zhichao Cao Date: Mon, 13 Apr 2020 19:11:19 -0700 Subject: [PATCH] Add NewFileChecksumGenCrc32cFactory to file checksum (#6688) Summary: Add NewFileChecksumGenCrc32cFactory to file checksum public interface such that applications can use the build in crc32 checksum factory. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6688 Test Plan: pass make asan_check Reviewed By: riversand963 Differential Revision: D21006859 Pulled By: zhichao-cao fbshipit-source-id: ea8a45196a8b77c310728ab05f6cc0f49f3baef0 --- HISTORY.md | 3 +++ include/rocksdb/file_checksum.h | 6 ++++++ tools/ldb_cmd_test.cc | 4 +--- util/file_checksum_helper.cc | 6 ++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 145525668..bc7b2784f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,9 @@ ### Bug Fixes * Fix wrong result being read from ingested file. May happen when a key in the file happen to be prefix of another key also in the file. The issue can further cause more data corruption. The issue exists with rocksdb >= 5.0.0 since DB::IngestExternalFile() was introduced. +### Public API Change +* Add NewFileChecksumGenCrc32cFactory to the file checksum public API, such that the builtin Crc32c based file checksum generator factory can be used by applications. + ### New Features * Added support for pipelined & parallel compression optimization for `BlockBasedTableBuilder`. This optimization makes block building, block compression and block appending a pipeline, and uses multiple threads to accelerate block compression. Users can set `CompressionOptions::parallel_threads` greater than 1 to enable compression parallelism. * Provide an allocator for memkind to be used with block cache. This is to work with memory technologies (Intel DCPMM is one such technology currently available) that require different libraries for allocation and management (such as PMDK and memkind). The high capacities available make it possible to provision large caches (up to several TBs in size) beyond what is achievable with DRAM. diff --git a/include/rocksdb/file_checksum.h b/include/rocksdb/file_checksum.h index 61975f0f3..e7b27fb78 100644 --- a/include/rocksdb/file_checksum.h +++ b/include/rocksdb/file_checksum.h @@ -97,4 +97,10 @@ class FileChecksumList { // Create a new file checksum list. extern FileChecksumList* NewFileChecksumList(); +// Return a shared_ptr of the builtin Crc32 based file checksum generatory +// factory object, which can be shared to create the Crc32c based checksum +// generator object. +extern std::shared_ptr +GetFileChecksumGenCrc32cFactory(); + } // namespace ROCKSDB_NAMESPACE diff --git a/tools/ldb_cmd_test.cc b/tools/ldb_cmd_test.cc index db3f7e50a..8bc9c438a 100644 --- a/tools/ldb_cmd_test.cc +++ b/tools/ldb_cmd_test.cc @@ -344,9 +344,7 @@ TEST_F(LdbCmdTest, DumpFileChecksumCRC32) { Options opts; opts.env = env.get(); opts.create_if_missing = true; - FileChecksumGenCrc32cFactory* file_checksum_gen_factory = - new FileChecksumGenCrc32cFactory(); - opts.file_checksum_gen_factory.reset(file_checksum_gen_factory); + opts.file_checksum_gen_factory = GetFileChecksumGenCrc32cFactory(); DB* db = nullptr; std::string dbname = test::TmpDir(); diff --git a/util/file_checksum_helper.cc b/util/file_checksum_helper.cc index 5a8b6ded9..e8f32fb84 100644 --- a/util/file_checksum_helper.cc +++ b/util/file_checksum_helper.cc @@ -77,4 +77,10 @@ FileChecksumList* NewFileChecksumList() { return checksum_list; } +std::shared_ptr GetFileChecksumGenCrc32cFactory() { + static std::shared_ptr default_crc32c_gen_factory( + new FileChecksumGenCrc32cFactory()); + return default_crc32c_gen_factory; +} + } // namespace ROCKSDB_NAMESPACE -- GitLab