Skip to content

Commit

Permalink
Use FileChecksumGenFactory for SST file checksum (#6600)
Browse files Browse the repository at this point in the history
Summary:
In the current implementation, sst file checksum is calculated by a shared checksum function object, which may make some checksum function hard to be applied here such as SHA1. In this implementation, each sst file will have its own checksum generator obejct, created by FileChecksumGenFactory. User needs to implement its own FilechecksumGenerator and Factory to plugin the in checksum calculation method.
Pull Request resolved: facebook/rocksdb#6600

Test Plan: tested with make asan_check

Reviewed By: riversand963

Differential Revision: D20717670

Pulled By: zhichao-cao

fbshipit-source-id: 2a74c1c280ac11a07a1980185b43b671acaa71c6
Signed-off-by: Changlong Chen <levisonchen@live.cn>
  • Loading branch information
zhichao-cao authored and mm304321141 committed Jun 23, 2021
1 parent c066741 commit 1da81fd
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions include/rocksdb/file_checksum.h
Expand Up @@ -18,27 +18,44 @@

namespace ROCKSDB_NAMESPACE {

// FileChecksumFunc is the function class to generates the checksum value
struct FileChecksumGenContext {
std::string file_name;
};

// FileChecksumGenerator is the class to generates the checksum value
// for each file when the file is written to the file system.
class FileChecksumFunc {
class FileChecksumGenerator {
public:
virtual ~FileChecksumFunc() {}
// Return the checksum of concat (A, data[0,n-1]) where init_checksum is the
// returned value of some string A. It is used to maintain the checksum of a
// stream of data
virtual std::string Extend(const std::string& init_checksum, const char* data,
size_t n) = 0;
virtual ~FileChecksumGenerator() {}

// Update the current result after process the data. For different checksum
// functions, the temporal results may be stored and used in Update to
// include the new data.
virtual void Update(const char* data, size_t n) = 0;

// Return the checksum value of data[0,n-1]
virtual std::string Value(const char* data, size_t n) = 0;
// Generate the final results if no further new data will be updated.
virtual void Finalize() = 0;

// Return a processed value of the checksum for store in somewhere
virtual std::string ProcessChecksum(const std::string& checksum) = 0;
// Get the checksum
virtual std::string GetChecksum() const = 0;

// Returns a name that identifies the current file checksum function.
virtual const char* Name() const = 0;
};

// Create the FileChecksumGenerator object for each SST file.
class FileChecksumGenFactory {
public:
virtual ~FileChecksumGenFactory() {}

// Create a new FileChecksumGenerator.
virtual std::unique_ptr<FileChecksumGenerator> CreateFileChecksumGenerator(
const FileChecksumGenContext& context) = 0;

// Return the name of this FileChecksumGenFactory.
virtual const char* Name() const = 0;
};

// FileChecksumList stores the checksum information of a list of files (e.g.,
// SST files). The FileChecksumLIst can be used to store the checksum
// information of all SST file getting from the MANIFEST, which are
Expand Down Expand Up @@ -80,7 +97,4 @@ class FileChecksumList {
// Create a new file checksum list.
extern FileChecksumList* NewFileChecksumList();

// Create a Crc32c based file checksum function
extern FileChecksumFunc* CreateFileChecksumFuncCrc32c();

} // namespace ROCKSDB_NAMESPACE

0 comments on commit 1da81fd

Please sign in to comment.