Add AppendWithVerify and PositionedAppendWithVerify to Env and FileSystem (#7419)

Summary:
Add new AppendWithVerify and PositionedAppendWithVerify APIs to Env and FileSystem to bring the data verification information (data checksum information) from upper layer (e.g., WritableFileWriter) to the storage layer. This PR only include the API definition, no functional codes are added to unblock other developers which depend on these APIs.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/7419

Test Plan: make -j32

Reviewed By: pdillinger

Differential Revision: D23883196

Pulled By: zhichao-cao

fbshipit-source-id: 94676c26bc56144cc32e3661f84f21eccd790411
This commit is contained in:
Zhichao Cao 2020-09-23 19:00:30 -07:00 committed by Facebook GitHub Bot
parent 98ac6b646a
commit 0ce9b3a22d
5 changed files with 90 additions and 0 deletions

View File

@ -727,11 +727,22 @@ class LegacyWritableFileWrapper : public FSWritableFile {
IODebugContext* /*dbg*/) override { IODebugContext* /*dbg*/) override {
return status_to_io_status(target_->Append(data)); return status_to_io_status(target_->Append(data));
} }
IOStatus Append(const Slice& data, const IOOptions& /*options*/,
const DataVerificationInfo& /*verification_info*/,
IODebugContext* /*dbg*/) override {
return status_to_io_status(target_->Append(data));
}
IOStatus PositionedAppend(const Slice& data, uint64_t offset, IOStatus PositionedAppend(const Slice& data, uint64_t offset,
const IOOptions& /*options*/, const IOOptions& /*options*/,
IODebugContext* /*dbg*/) override { IODebugContext* /*dbg*/) override {
return status_to_io_status(target_->PositionedAppend(data, offset)); return status_to_io_status(target_->PositionedAppend(data, offset));
} }
IOStatus PositionedAppend(const Slice& data, uint64_t offset,
const IOOptions& /*options*/,
const DataVerificationInfo& /*verification_info*/,
IODebugContext* /*dbg*/) override {
return status_to_io_status(target_->PositionedAppend(data, offset));
}
IOStatus Truncate(uint64_t size, const IOOptions& /*options*/, IOStatus Truncate(uint64_t size, const IOOptions& /*options*/,
IODebugContext* /*dbg*/) override { IODebugContext* /*dbg*/) override {
return status_to_io_status(target_->Truncate(size)); return status_to_io_status(target_->Truncate(size));

View File

@ -244,10 +244,21 @@ class FSWritableFileTracingWrapper : public FSWritableFileWrapper {
IOStatus Append(const Slice& data, const IOOptions& options, IOStatus Append(const Slice& data, const IOOptions& options,
IODebugContext* dbg) override; IODebugContext* dbg) override;
IOStatus Append(const Slice& data, const IOOptions& options,
const DataVerificationInfo& /*verification_info*/,
IODebugContext* dbg) override {
return Append(data, options, dbg);
}
IOStatus PositionedAppend(const Slice& data, uint64_t offset, IOStatus PositionedAppend(const Slice& data, uint64_t offset,
const IOOptions& options, const IOOptions& options,
IODebugContext* dbg) override; IODebugContext* dbg) override;
IOStatus PositionedAppend(const Slice& data, uint64_t offset,
const IOOptions& options,
const DataVerificationInfo& /*verification_info*/,
IODebugContext* dbg) override {
return PositionedAppend(data, offset, options, dbg);
}
IOStatus Truncate(uint64_t size, const IOOptions& options, IOStatus Truncate(uint64_t size, const IOOptions& options,
IODebugContext* dbg) override; IODebugContext* dbg) override;

16
env/io_posix.h vendored
View File

@ -242,9 +242,20 @@ class PosixWritableFile : public FSWritableFile {
virtual IOStatus Close(const IOOptions& opts, IODebugContext* dbg) override; virtual IOStatus Close(const IOOptions& opts, IODebugContext* dbg) override;
virtual IOStatus Append(const Slice& data, const IOOptions& opts, virtual IOStatus Append(const Slice& data, const IOOptions& opts,
IODebugContext* dbg) override; IODebugContext* dbg) override;
virtual IOStatus Append(const Slice& data, const IOOptions& opts,
const DataVerificationInfo& /* verification_info */,
IODebugContext* dbg) override {
return Append(data, opts, dbg);
}
virtual IOStatus PositionedAppend(const Slice& data, uint64_t offset, virtual IOStatus PositionedAppend(const Slice& data, uint64_t offset,
const IOOptions& opts, const IOOptions& opts,
IODebugContext* dbg) override; IODebugContext* dbg) override;
virtual IOStatus PositionedAppend(
const Slice& data, uint64_t offset, const IOOptions& opts,
const DataVerificationInfo& /* verification_info */,
IODebugContext* dbg) override {
return PositionedAppend(data, offset, opts, dbg);
}
virtual IOStatus Flush(const IOOptions& opts, IODebugContext* dbg) override; virtual IOStatus Flush(const IOOptions& opts, IODebugContext* dbg) override;
virtual IOStatus Sync(const IOOptions& opts, IODebugContext* dbg) override; virtual IOStatus Sync(const IOOptions& opts, IODebugContext* dbg) override;
virtual IOStatus Fsync(const IOOptions& opts, IODebugContext* dbg) override; virtual IOStatus Fsync(const IOOptions& opts, IODebugContext* dbg) override;
@ -331,6 +342,11 @@ class PosixMmapFile : public FSWritableFile {
virtual IOStatus Close(const IOOptions& opts, IODebugContext* dbg) override; virtual IOStatus Close(const IOOptions& opts, IODebugContext* dbg) override;
virtual IOStatus Append(const Slice& data, const IOOptions& opts, virtual IOStatus Append(const Slice& data, const IOOptions& opts,
IODebugContext* dbg) override; IODebugContext* dbg) override;
virtual IOStatus Append(const Slice& data, const IOOptions& opts,
const DataVerificationInfo& /* verification_info */,
IODebugContext* dbg) override {
return Append(data, opts, dbg);
}
virtual IOStatus Flush(const IOOptions& opts, IODebugContext* dbg) override; virtual IOStatus Flush(const IOOptions& opts, IODebugContext* dbg) override;
virtual IOStatus Sync(const IOOptions& opts, IODebugContext* dbg) override; virtual IOStatus Sync(const IOOptions& opts, IODebugContext* dbg) override;
virtual IOStatus Fsync(const IOOptions& opts, IODebugContext* dbg) override; virtual IOStatus Fsync(const IOOptions& opts, IODebugContext* dbg) override;

View File

@ -702,6 +702,13 @@ class FSRandomAccessFile {
// RandomAccessFileWrapper too. // RandomAccessFileWrapper too.
}; };
// A data structure brings the data verification information, which is
// used togther with data being written to a file.
struct DataVerificationInfo {
// checksum of the data being written.
Slice checksum;
};
// A file abstraction for sequential writing. The implementation // A file abstraction for sequential writing. The implementation
// must provide buffering since callers may append small fragments // must provide buffering since callers may append small fragments
// at a time to the file. // at a time to the file.
@ -729,6 +736,16 @@ class FSWritableFile {
virtual IOStatus Append(const Slice& data, const IOOptions& options, virtual IOStatus Append(const Slice& data, const IOOptions& options,
IODebugContext* dbg) = 0; IODebugContext* dbg) = 0;
// EXPERIMENTAL / CURRENTLY UNUSED
// 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.
virtual IOStatus Append(const Slice& data, const IOOptions& options,
const DataVerificationInfo& /* verification_info */,
IODebugContext* dbg) {
return Append(data, options, dbg);
}
// PositionedAppend data to the specified offset. The new EOF after append // PositionedAppend data to the specified offset. The new EOF after append
// must be larger than the previous EOF. This is to be used when writes are // must be larger than the previous EOF. This is to be used when writes are
// not backed by OS buffers and hence has to always start from the start of // not backed by OS buffers and hence has to always start from the start of
@ -756,6 +773,18 @@ class FSWritableFile {
return IOStatus::NotSupported(); return IOStatus::NotSupported();
} }
// 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.
virtual IOStatus PositionedAppend(
const Slice& /* data */, uint64_t /* offset */,
const IOOptions& /*options*/,
const DataVerificationInfo& /* verification_info */,
IODebugContext* /*dbg*/) {
return IOStatus::NotSupported();
}
// Truncate is necessary to trim the file to the correct size // Truncate is necessary to trim the file to the correct size
// before closing. It is not always possible to keep track of the file // before closing. It is not always possible to keep track of the file
// size due to whole pages writes. The behavior is undefined if called // size due to whole pages writes. The behavior is undefined if called
@ -1286,11 +1315,23 @@ class FSWritableFileWrapper : public FSWritableFile {
IODebugContext* dbg) override { IODebugContext* dbg) override {
return target_->Append(data, options, dbg); return target_->Append(data, options, dbg);
} }
IOStatus Append(const Slice& data, const IOOptions& options,
const DataVerificationInfo& verification_info,
IODebugContext* dbg) override {
return target_->Append(data, options, verification_info, dbg);
}
IOStatus PositionedAppend(const Slice& data, uint64_t offset, IOStatus PositionedAppend(const Slice& data, uint64_t offset,
const IOOptions& options, const IOOptions& options,
IODebugContext* dbg) override { IODebugContext* dbg) override {
return target_->PositionedAppend(data, offset, options, dbg); return target_->PositionedAppend(data, offset, options, dbg);
} }
IOStatus PositionedAppend(const Slice& data, uint64_t offset,
const IOOptions& options,
const DataVerificationInfo& verification_info,
IODebugContext* dbg) override {
return target_->PositionedAppend(data, offset, options, verification_info,
dbg);
}
IOStatus Truncate(uint64_t size, const IOOptions& options, IOStatus Truncate(uint64_t size, const IOOptions& options,
IODebugContext* dbg) override { IODebugContext* dbg) override {
return target_->Truncate(size, options, dbg); return target_->Truncate(size, options, dbg);

View File

@ -64,6 +64,11 @@ class TestFSWritableFile : public FSWritableFile {
virtual ~TestFSWritableFile(); virtual ~TestFSWritableFile();
virtual IOStatus Append(const Slice& data, const IOOptions&, virtual IOStatus Append(const Slice& data, const IOOptions&,
IODebugContext*) override; IODebugContext*) override;
virtual IOStatus Append(const Slice& data, const IOOptions& options,
const DataVerificationInfo& /*verification_info*/,
IODebugContext* dbg) override {
return Append(data, options, dbg);
}
virtual IOStatus Truncate(uint64_t size, const IOOptions& options, virtual IOStatus Truncate(uint64_t size, const IOOptions& options,
IODebugContext* dbg) override { IODebugContext* dbg) override {
return target_->Truncate(size, options, dbg); return target_->Truncate(size, options, dbg);
@ -78,6 +83,12 @@ class TestFSWritableFile : public FSWritableFile {
IODebugContext* dbg) override { IODebugContext* dbg) override {
return target_->PositionedAppend(data, offset, options, dbg); return target_->PositionedAppend(data, offset, options, dbg);
} }
IOStatus PositionedAppend(const Slice& data, uint64_t offset,
const IOOptions& options,
const DataVerificationInfo& /*verification_info*/,
IODebugContext* dbg) override {
return PositionedAppend(data, offset, options, dbg);
}
virtual size_t GetRequiredBufferAlignment() const override { virtual size_t GetRequiredBufferAlignment() const override {
return target_->GetRequiredBufferAlignment(); return target_->GetRequiredBufferAlignment();
} }