2019-09-16 19:31:27 +02:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
//
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <atomic>
|
|
|
|
#include <string>
|
2020-09-08 19:49:01 +02:00
|
|
|
|
2020-02-11 00:42:46 +01:00
|
|
|
#include "db/version_edit.h"
|
2020-09-08 19:49:01 +02:00
|
|
|
#include "env/file_system_tracer.h"
|
2019-09-16 19:31:27 +02:00
|
|
|
#include "port/port.h"
|
2020-02-11 00:42:46 +01:00
|
|
|
#include "rocksdb/file_checksum.h"
|
Introduce a new storage specific Env API (#5761)
Summary:
The current Env API encompasses both storage/file operations, as well as OS related operations. Most of the APIs return a Status, which does not have enough metadata about an error, such as whether its retry-able or not, scope (i.e fault domain) of the error etc., that may be required in order to properly handle a storage error. The file APIs also do not provide enough control over the IO SLA, such as timeout, prioritization, hinting about placement and redundancy etc.
This PR separates out the file/storage APIs from Env into a new FileSystem class. The APIs are updated to return an IOStatus with metadata about the error, as well as to take an IOOptions structure as input in order to allow more control over the IO.
The user can set both ```options.env``` and ```options.file_system``` to specify that RocksDB should use the former for OS related operations and the latter for storage operations. Internally, a ```CompositeEnvWrapper``` has been introduced that inherits from ```Env``` and redirects individual methods to either an ```Env``` implementation or the ```FileSystem``` as appropriate. When options are sanitized during ```DB::Open```, ```options.env``` is replaced with a newly allocated ```CompositeEnvWrapper``` instance if both env and file_system have been specified. This way, the rest of the RocksDB code can continue to function as before.
This PR also ports PosixEnv to the new API by splitting it into two - PosixEnv and PosixFileSystem. PosixEnv is defined as a sub-class of CompositeEnvWrapper, and threading/time functions are overridden with Posix specific implementations in order to avoid an extra level of indirection.
The ```CompositeEnvWrapper``` translates ```IOStatus``` return code to ```Status```, and sets the severity to ```kSoftError``` if the io_status is retryable. The error handling code in RocksDB can then recover the DB automatically.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5761
Differential Revision: D18868376
Pulled By: anand1976
fbshipit-source-id: 39efe18a162ea746fabac6360ff529baba48486f
2019-12-13 23:47:08 +01:00
|
|
|
#include "rocksdb/file_system.h"
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
2020-03-28 00:03:05 +01:00
|
|
|
#include "rocksdb/io_status.h"
|
2019-09-16 19:31:27 +02:00
|
|
|
#include "rocksdb/listener.h"
|
|
|
|
#include "rocksdb/rate_limiter.h"
|
|
|
|
#include "test_util/sync_point.h"
|
|
|
|
#include "util/aligned_buffer.h"
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2019-09-16 19:31:27 +02:00
|
|
|
class Statistics;
|
2021-01-26 07:07:26 +01:00
|
|
|
class SystemClock;
|
2019-09-16 19:31:27 +02:00
|
|
|
|
|
|
|
// WritableFileWriter is a wrapper on top of Env::WritableFile. It provides
|
|
|
|
// facilities to:
|
|
|
|
// - Handle Buffered and Direct writes.
|
|
|
|
// - Rate limit writes.
|
|
|
|
// - Flush and Sync the data to the underlying filesystem.
|
|
|
|
// - Notify any interested listeners on the completion of a write.
|
|
|
|
// - Update IO stats.
|
|
|
|
class WritableFileWriter {
|
|
|
|
private:
|
|
|
|
#ifndef ROCKSDB_LITE
|
2020-07-22 17:53:21 +02:00
|
|
|
void NotifyOnFileWriteFinish(
|
|
|
|
uint64_t offset, size_t length,
|
|
|
|
const FileOperationInfo::StartTimePoint& start_ts,
|
|
|
|
const FileOperationInfo::FinishTimePoint& finish_ts,
|
|
|
|
const IOStatus& io_status) {
|
2020-07-08 03:19:32 +02:00
|
|
|
FileOperationInfo info(FileOperationType::kWrite, file_name_, start_ts,
|
|
|
|
finish_ts, io_status);
|
2019-09-16 19:31:27 +02:00
|
|
|
info.offset = offset;
|
|
|
|
info.length = length;
|
|
|
|
|
|
|
|
for (auto& listener : listeners_) {
|
|
|
|
listener->OnFileWriteFinish(info);
|
|
|
|
}
|
2020-05-08 21:36:49 +02:00
|
|
|
info.status.PermitUncheckedError();
|
2019-09-16 19:31:27 +02:00
|
|
|
}
|
2020-07-22 17:53:21 +02:00
|
|
|
void NotifyOnFileFlushFinish(
|
|
|
|
const FileOperationInfo::StartTimePoint& start_ts,
|
|
|
|
const FileOperationInfo::FinishTimePoint& finish_ts,
|
|
|
|
const IOStatus& io_status) {
|
2020-07-08 03:19:32 +02:00
|
|
|
FileOperationInfo info(FileOperationType::kFlush, file_name_, start_ts,
|
|
|
|
finish_ts, io_status);
|
|
|
|
|
|
|
|
for (auto& listener : listeners_) {
|
|
|
|
listener->OnFileFlushFinish(info);
|
|
|
|
}
|
|
|
|
info.status.PermitUncheckedError();
|
|
|
|
}
|
|
|
|
void NotifyOnFileSyncFinish(
|
2020-07-22 17:53:21 +02:00
|
|
|
const FileOperationInfo::StartTimePoint& start_ts,
|
|
|
|
const FileOperationInfo::FinishTimePoint& finish_ts,
|
|
|
|
const IOStatus& io_status,
|
2020-07-08 03:19:32 +02:00
|
|
|
FileOperationType type = FileOperationType::kSync) {
|
|
|
|
FileOperationInfo info(type, file_name_, start_ts, finish_ts, io_status);
|
|
|
|
|
|
|
|
for (auto& listener : listeners_) {
|
|
|
|
listener->OnFileSyncFinish(info);
|
|
|
|
}
|
|
|
|
info.status.PermitUncheckedError();
|
|
|
|
}
|
|
|
|
void NotifyOnFileRangeSyncFinish(
|
|
|
|
uint64_t offset, size_t length,
|
2020-07-22 17:53:21 +02:00
|
|
|
const FileOperationInfo::StartTimePoint& start_ts,
|
|
|
|
const FileOperationInfo::FinishTimePoint& finish_ts,
|
2020-07-08 03:19:32 +02:00
|
|
|
const IOStatus& io_status) {
|
|
|
|
FileOperationInfo info(FileOperationType::kRangeSync, file_name_, start_ts,
|
|
|
|
finish_ts, io_status);
|
|
|
|
info.offset = offset;
|
|
|
|
info.length = length;
|
|
|
|
|
|
|
|
for (auto& listener : listeners_) {
|
|
|
|
listener->OnFileRangeSyncFinish(info);
|
|
|
|
}
|
|
|
|
info.status.PermitUncheckedError();
|
|
|
|
}
|
2020-07-22 17:53:21 +02:00
|
|
|
void NotifyOnFileTruncateFinish(
|
|
|
|
const FileOperationInfo::StartTimePoint& start_ts,
|
|
|
|
const FileOperationInfo::FinishTimePoint& finish_ts,
|
|
|
|
const IOStatus& io_status) {
|
2020-07-08 03:19:32 +02:00
|
|
|
FileOperationInfo info(FileOperationType::kTruncate, file_name_, start_ts,
|
|
|
|
finish_ts, io_status);
|
|
|
|
|
|
|
|
for (auto& listener : listeners_) {
|
|
|
|
listener->OnFileTruncateFinish(info);
|
|
|
|
}
|
|
|
|
info.status.PermitUncheckedError();
|
|
|
|
}
|
2020-07-22 17:53:21 +02:00
|
|
|
void NotifyOnFileCloseFinish(
|
|
|
|
const FileOperationInfo::StartTimePoint& start_ts,
|
|
|
|
const FileOperationInfo::FinishTimePoint& finish_ts,
|
|
|
|
const IOStatus& io_status) {
|
2020-07-08 03:19:32 +02:00
|
|
|
FileOperationInfo info(FileOperationType::kClose, file_name_, start_ts,
|
|
|
|
finish_ts, io_status);
|
|
|
|
|
|
|
|
for (auto& listener : listeners_) {
|
|
|
|
listener->OnFileCloseFinish(info);
|
|
|
|
}
|
|
|
|
info.status.PermitUncheckedError();
|
|
|
|
}
|
2021-11-19 02:09:54 +01:00
|
|
|
|
|
|
|
void NotifyOnIOError(const IOStatus& io_status, FileOperationType operation,
|
|
|
|
const std::string& file_path, size_t length = 0,
|
|
|
|
uint64_t offset = 0) {
|
|
|
|
if (listeners_.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
IOErrorInfo io_error_info(io_status, operation, file_path, length, offset);
|
|
|
|
for (auto& listener : listeners_) {
|
|
|
|
listener->OnIOError(io_error_info);
|
|
|
|
}
|
|
|
|
io_error_info.io_status.PermitUncheckedError();
|
|
|
|
}
|
2019-09-16 19:31:27 +02:00
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
|
|
|
|
bool ShouldNotifyListeners() const { return !listeners_.empty(); }
|
2020-05-21 17:10:43 +02:00
|
|
|
void UpdateFileChecksum(const Slice& data);
|
2021-02-11 07:18:33 +01:00
|
|
|
void Crc32cHandoffChecksumCalculation(const char* data, size_t size,
|
|
|
|
char* buf);
|
2019-09-16 19:31:27 +02:00
|
|
|
|
|
|
|
std::string file_name_;
|
2020-09-08 19:49:01 +02:00
|
|
|
FSWritableFilePtr writable_file_;
|
2021-03-15 12:32:24 +01:00
|
|
|
SystemClock* clock_;
|
2019-09-16 19:31:27 +02:00
|
|
|
AlignedBuffer buf_;
|
|
|
|
size_t max_buffer_size_;
|
|
|
|
// Actually written data size can be used for truncate
|
|
|
|
// not counting padding data
|
|
|
|
uint64_t filesize_;
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
// This is necessary when we use unbuffered access
|
|
|
|
// and writes must happen on aligned offsets
|
|
|
|
// so we need to go back and write that page again
|
|
|
|
uint64_t next_write_offset_;
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
bool pending_sync_;
|
|
|
|
uint64_t last_sync_size_;
|
|
|
|
uint64_t bytes_per_sync_;
|
|
|
|
RateLimiter* rate_limiter_;
|
|
|
|
Statistics* stats_;
|
|
|
|
std::vector<std::shared_ptr<EventListener>> listeners_;
|
2020-03-30 00:57:02 +02:00
|
|
|
std::unique_ptr<FileChecksumGenerator> checksum_generator_;
|
|
|
|
bool checksum_finalized_;
|
2021-02-11 07:18:33 +01:00
|
|
|
bool perform_data_verification_;
|
Using existing crc32c checksum in checksum handoff for Manifest and WAL (#8412)
Summary:
In PR https://github.com/facebook/rocksdb/issues/7523 , checksum handoff is introduced in RocksDB for WAL, Manifest, and SST files. When user enable checksum handoff for a certain type of file, before the data is written to the lower layer storage system, we calculate the checksum (crc32c) of each piece of data and pass the checksum down with the data, such that data verification can be down by the lower layer storage system if it has the capability. However, it cannot cover the whole lifetime of the data in the memory and also it potentially introduces extra checksum calculation overhead.
In this PR, we introduce a new interface in WritableFileWriter::Append, which allows the caller be able to pass the data and the checksum (crc32c) together. In this way, WritableFileWriter can directly use the pass-in checksum (crc32c) to generate the checksum of data being passed down to the storage system. It saves the calculation overhead and achieves higher protection coverage. When a new checksum is added with the data, we use Crc32cCombine https://github.com/facebook/rocksdb/issues/8305 to combine the existing checksum and the new checksum. To avoid the segmenting of data by rate-limiter before it is stored, rate-limiter is called enough times to accumulate enough credits for a certain write. This design only support Manifest and WAL which use log_writer in the current stage.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8412
Test Plan: make check, add new testing cases.
Reviewed By: anand1976
Differential Revision: D29151545
Pulled By: zhichao-cao
fbshipit-source-id: 75e2278c5126cfd58393c67b1efd18dcc7a30772
2021-06-25 09:46:33 +02:00
|
|
|
uint32_t buffered_data_crc32c_checksum_;
|
|
|
|
bool buffered_data_with_checksum_;
|
2019-09-16 19:31:27 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
WritableFileWriter(
|
Introduce a new storage specific Env API (#5761)
Summary:
The current Env API encompasses both storage/file operations, as well as OS related operations. Most of the APIs return a Status, which does not have enough metadata about an error, such as whether its retry-able or not, scope (i.e fault domain) of the error etc., that may be required in order to properly handle a storage error. The file APIs also do not provide enough control over the IO SLA, such as timeout, prioritization, hinting about placement and redundancy etc.
This PR separates out the file/storage APIs from Env into a new FileSystem class. The APIs are updated to return an IOStatus with metadata about the error, as well as to take an IOOptions structure as input in order to allow more control over the IO.
The user can set both ```options.env``` and ```options.file_system``` to specify that RocksDB should use the former for OS related operations and the latter for storage operations. Internally, a ```CompositeEnvWrapper``` has been introduced that inherits from ```Env``` and redirects individual methods to either an ```Env``` implementation or the ```FileSystem``` as appropriate. When options are sanitized during ```DB::Open```, ```options.env``` is replaced with a newly allocated ```CompositeEnvWrapper``` instance if both env and file_system have been specified. This way, the rest of the RocksDB code can continue to function as before.
This PR also ports PosixEnv to the new API by splitting it into two - PosixEnv and PosixFileSystem. PosixEnv is defined as a sub-class of CompositeEnvWrapper, and threading/time functions are overridden with Posix specific implementations in order to avoid an extra level of indirection.
The ```CompositeEnvWrapper``` translates ```IOStatus``` return code to ```Status```, and sets the severity to ```kSoftError``` if the io_status is retryable. The error handling code in RocksDB can then recover the DB automatically.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5761
Differential Revision: D18868376
Pulled By: anand1976
fbshipit-source-id: 39efe18a162ea746fabac6360ff529baba48486f
2019-12-13 23:47:08 +01:00
|
|
|
std::unique_ptr<FSWritableFile>&& file, const std::string& _file_name,
|
2021-03-15 12:32:24 +01:00
|
|
|
const FileOptions& options, SystemClock* clock = nullptr,
|
2020-09-08 19:49:01 +02:00
|
|
|
const std::shared_ptr<IOTracer>& io_tracer = nullptr,
|
2019-09-16 19:31:27 +02:00
|
|
|
Statistics* stats = nullptr,
|
2020-02-11 00:42:46 +01:00
|
|
|
const std::vector<std::shared_ptr<EventListener>>& listeners = {},
|
2021-02-11 07:18:33 +01:00
|
|
|
FileChecksumGenFactory* file_checksum_gen_factory = nullptr,
|
Using existing crc32c checksum in checksum handoff for Manifest and WAL (#8412)
Summary:
In PR https://github.com/facebook/rocksdb/issues/7523 , checksum handoff is introduced in RocksDB for WAL, Manifest, and SST files. When user enable checksum handoff for a certain type of file, before the data is written to the lower layer storage system, we calculate the checksum (crc32c) of each piece of data and pass the checksum down with the data, such that data verification can be down by the lower layer storage system if it has the capability. However, it cannot cover the whole lifetime of the data in the memory and also it potentially introduces extra checksum calculation overhead.
In this PR, we introduce a new interface in WritableFileWriter::Append, which allows the caller be able to pass the data and the checksum (crc32c) together. In this way, WritableFileWriter can directly use the pass-in checksum (crc32c) to generate the checksum of data being passed down to the storage system. It saves the calculation overhead and achieves higher protection coverage. When a new checksum is added with the data, we use Crc32cCombine https://github.com/facebook/rocksdb/issues/8305 to combine the existing checksum and the new checksum. To avoid the segmenting of data by rate-limiter before it is stored, rate-limiter is called enough times to accumulate enough credits for a certain write. This design only support Manifest and WAL which use log_writer in the current stage.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8412
Test Plan: make check, add new testing cases.
Reviewed By: anand1976
Differential Revision: D29151545
Pulled By: zhichao-cao
fbshipit-source-id: 75e2278c5126cfd58393c67b1efd18dcc7a30772
2021-06-25 09:46:33 +02:00
|
|
|
bool perform_data_verification = false,
|
|
|
|
bool buffered_data_with_checksum = false)
|
2020-09-08 19:49:01 +02:00
|
|
|
: file_name_(_file_name),
|
2021-01-25 23:35:45 +01:00
|
|
|
writable_file_(std::move(file), io_tracer, _file_name),
|
2021-01-26 07:07:26 +01:00
|
|
|
clock_(clock),
|
2019-09-16 19:31:27 +02:00
|
|
|
buf_(),
|
|
|
|
max_buffer_size_(options.writable_file_max_buffer_size),
|
|
|
|
filesize_(0),
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
next_write_offset_(0),
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
pending_sync_(false),
|
|
|
|
last_sync_size_(0),
|
|
|
|
bytes_per_sync_(options.bytes_per_sync),
|
|
|
|
rate_limiter_(options.rate_limiter),
|
|
|
|
stats_(stats),
|
2020-02-11 00:42:46 +01:00
|
|
|
listeners_(),
|
2020-03-30 00:57:02 +02:00
|
|
|
checksum_generator_(nullptr),
|
2021-02-11 07:18:33 +01:00
|
|
|
checksum_finalized_(false),
|
Using existing crc32c checksum in checksum handoff for Manifest and WAL (#8412)
Summary:
In PR https://github.com/facebook/rocksdb/issues/7523 , checksum handoff is introduced in RocksDB for WAL, Manifest, and SST files. When user enable checksum handoff for a certain type of file, before the data is written to the lower layer storage system, we calculate the checksum (crc32c) of each piece of data and pass the checksum down with the data, such that data verification can be down by the lower layer storage system if it has the capability. However, it cannot cover the whole lifetime of the data in the memory and also it potentially introduces extra checksum calculation overhead.
In this PR, we introduce a new interface in WritableFileWriter::Append, which allows the caller be able to pass the data and the checksum (crc32c) together. In this way, WritableFileWriter can directly use the pass-in checksum (crc32c) to generate the checksum of data being passed down to the storage system. It saves the calculation overhead and achieves higher protection coverage. When a new checksum is added with the data, we use Crc32cCombine https://github.com/facebook/rocksdb/issues/8305 to combine the existing checksum and the new checksum. To avoid the segmenting of data by rate-limiter before it is stored, rate-limiter is called enough times to accumulate enough credits for a certain write. This design only support Manifest and WAL which use log_writer in the current stage.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8412
Test Plan: make check, add new testing cases.
Reviewed By: anand1976
Differential Revision: D29151545
Pulled By: zhichao-cao
fbshipit-source-id: 75e2278c5126cfd58393c67b1efd18dcc7a30772
2021-06-25 09:46:33 +02:00
|
|
|
perform_data_verification_(perform_data_verification),
|
|
|
|
buffered_data_crc32c_checksum_(0),
|
|
|
|
buffered_data_with_checksum_(buffered_data_with_checksum) {
|
2022-01-28 04:29:17 +01:00
|
|
|
assert(!use_direct_io() || max_buffer_size_ > 0);
|
2019-09-16 19:31:27 +02:00
|
|
|
TEST_SYNC_POINT_CALLBACK("WritableFileWriter::WritableFileWriter:0",
|
|
|
|
reinterpret_cast<void*>(max_buffer_size_));
|
|
|
|
buf_.Alignment(writable_file_->GetRequiredBufferAlignment());
|
|
|
|
buf_.AllocateNewBuffer(std::min((size_t)65536, max_buffer_size_));
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
std::for_each(listeners.begin(), listeners.end(),
|
|
|
|
[this](const std::shared_ptr<EventListener>& e) {
|
|
|
|
if (e->ShouldBeNotifiedOnFileIO()) {
|
|
|
|
listeners_.emplace_back(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
#else // !ROCKSDB_LITE
|
|
|
|
(void)listeners;
|
|
|
|
#endif
|
2020-03-30 00:57:02 +02:00
|
|
|
if (file_checksum_gen_factory != nullptr) {
|
|
|
|
FileChecksumGenContext checksum_gen_context;
|
|
|
|
checksum_gen_context.file_name = _file_name;
|
|
|
|
checksum_generator_ =
|
|
|
|
file_checksum_gen_factory->CreateFileChecksumGenerator(
|
|
|
|
checksum_gen_context);
|
|
|
|
}
|
2019-09-16 19:31:27 +02:00
|
|
|
}
|
|
|
|
|
2021-10-07 20:40:20 +02:00
|
|
|
static IOStatus Create(const std::shared_ptr<FileSystem>& fs,
|
|
|
|
const std::string& fname, const FileOptions& file_opts,
|
|
|
|
std::unique_ptr<WritableFileWriter>* writer,
|
|
|
|
IODebugContext* dbg);
|
2019-09-16 19:31:27 +02:00
|
|
|
WritableFileWriter(const WritableFileWriter&) = delete;
|
|
|
|
|
|
|
|
WritableFileWriter& operator=(const WritableFileWriter&) = delete;
|
|
|
|
|
2020-05-08 21:36:49 +02:00
|
|
|
~WritableFileWriter() {
|
|
|
|
auto s = Close();
|
|
|
|
s.PermitUncheckedError();
|
|
|
|
}
|
2019-09-16 19:31:27 +02:00
|
|
|
|
|
|
|
std::string file_name() const { return file_name_; }
|
|
|
|
|
Using existing crc32c checksum in checksum handoff for Manifest and WAL (#8412)
Summary:
In PR https://github.com/facebook/rocksdb/issues/7523 , checksum handoff is introduced in RocksDB for WAL, Manifest, and SST files. When user enable checksum handoff for a certain type of file, before the data is written to the lower layer storage system, we calculate the checksum (crc32c) of each piece of data and pass the checksum down with the data, such that data verification can be down by the lower layer storage system if it has the capability. However, it cannot cover the whole lifetime of the data in the memory and also it potentially introduces extra checksum calculation overhead.
In this PR, we introduce a new interface in WritableFileWriter::Append, which allows the caller be able to pass the data and the checksum (crc32c) together. In this way, WritableFileWriter can directly use the pass-in checksum (crc32c) to generate the checksum of data being passed down to the storage system. It saves the calculation overhead and achieves higher protection coverage. When a new checksum is added with the data, we use Crc32cCombine https://github.com/facebook/rocksdb/issues/8305 to combine the existing checksum and the new checksum. To avoid the segmenting of data by rate-limiter before it is stored, rate-limiter is called enough times to accumulate enough credits for a certain write. This design only support Manifest and WAL which use log_writer in the current stage.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8412
Test Plan: make check, add new testing cases.
Reviewed By: anand1976
Differential Revision: D29151545
Pulled By: zhichao-cao
fbshipit-source-id: 75e2278c5126cfd58393c67b1efd18dcc7a30772
2021-06-25 09:46:33 +02:00
|
|
|
// When this Append API is called, if the crc32c_checksum is not provided, we
|
|
|
|
// will calculate the checksum internally.
|
|
|
|
IOStatus Append(const Slice& data, uint32_t crc32c_checksum = 0);
|
2019-09-16 19:31:27 +02:00
|
|
|
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
2020-03-28 00:03:05 +01:00
|
|
|
IOStatus Pad(const size_t pad_bytes);
|
2019-09-16 19:31:27 +02:00
|
|
|
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
2020-03-28 00:03:05 +01:00
|
|
|
IOStatus Flush();
|
2019-09-16 19:31:27 +02:00
|
|
|
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
2020-03-28 00:03:05 +01:00
|
|
|
IOStatus Close();
|
2019-09-16 19:31:27 +02:00
|
|
|
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
2020-03-28 00:03:05 +01:00
|
|
|
IOStatus Sync(bool use_fsync);
|
2019-09-16 19:31:27 +02:00
|
|
|
|
|
|
|
// Sync only the data that was already Flush()ed. Safe to call concurrently
|
|
|
|
// with Append() and Flush(). If !writable_file_->IsSyncThreadSafe(),
|
|
|
|
// returns NotSupported status.
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
2020-03-28 00:03:05 +01:00
|
|
|
IOStatus SyncWithoutFlush(bool use_fsync);
|
2019-09-16 19:31:27 +02:00
|
|
|
|
|
|
|
uint64_t GetFileSize() const { return filesize_; }
|
|
|
|
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
2020-03-28 00:03:05 +01:00
|
|
|
IOStatus InvalidateCache(size_t offset, size_t length) {
|
2019-09-16 19:31:27 +02:00
|
|
|
return writable_file_->InvalidateCache(offset, length);
|
|
|
|
}
|
|
|
|
|
Introduce a new storage specific Env API (#5761)
Summary:
The current Env API encompasses both storage/file operations, as well as OS related operations. Most of the APIs return a Status, which does not have enough metadata about an error, such as whether its retry-able or not, scope (i.e fault domain) of the error etc., that may be required in order to properly handle a storage error. The file APIs also do not provide enough control over the IO SLA, such as timeout, prioritization, hinting about placement and redundancy etc.
This PR separates out the file/storage APIs from Env into a new FileSystem class. The APIs are updated to return an IOStatus with metadata about the error, as well as to take an IOOptions structure as input in order to allow more control over the IO.
The user can set both ```options.env``` and ```options.file_system``` to specify that RocksDB should use the former for OS related operations and the latter for storage operations. Internally, a ```CompositeEnvWrapper``` has been introduced that inherits from ```Env``` and redirects individual methods to either an ```Env``` implementation or the ```FileSystem``` as appropriate. When options are sanitized during ```DB::Open```, ```options.env``` is replaced with a newly allocated ```CompositeEnvWrapper``` instance if both env and file_system have been specified. This way, the rest of the RocksDB code can continue to function as before.
This PR also ports PosixEnv to the new API by splitting it into two - PosixEnv and PosixFileSystem. PosixEnv is defined as a sub-class of CompositeEnvWrapper, and threading/time functions are overridden with Posix specific implementations in order to avoid an extra level of indirection.
The ```CompositeEnvWrapper``` translates ```IOStatus``` return code to ```Status```, and sets the severity to ```kSoftError``` if the io_status is retryable. The error handling code in RocksDB can then recover the DB automatically.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5761
Differential Revision: D18868376
Pulled By: anand1976
fbshipit-source-id: 39efe18a162ea746fabac6360ff529baba48486f
2019-12-13 23:47:08 +01:00
|
|
|
FSWritableFile* writable_file() const { return writable_file_.get(); }
|
2019-09-16 19:31:27 +02:00
|
|
|
|
|
|
|
bool use_direct_io() { return writable_file_->use_direct_io(); }
|
|
|
|
|
|
|
|
bool TEST_BufferIsEmpty() { return buf_.CurrentSize() == 0; }
|
|
|
|
|
2020-03-30 00:57:02 +02:00
|
|
|
void TEST_SetFileChecksumGenerator(
|
|
|
|
FileChecksumGenerator* checksum_generator) {
|
|
|
|
checksum_generator_.reset(checksum_generator);
|
2020-02-11 00:42:46 +01:00
|
|
|
}
|
|
|
|
|
2020-03-30 00:57:02 +02:00
|
|
|
std::string GetFileChecksum();
|
2020-02-11 00:42:46 +01:00
|
|
|
|
|
|
|
const char* GetFileChecksumFuncName() const;
|
|
|
|
|
2019-09-16 19:31:27 +02:00
|
|
|
private:
|
|
|
|
// Used when os buffering is OFF and we are writing
|
|
|
|
// DMA such as in Direct I/O mode
|
|
|
|
#ifndef ROCKSDB_LITE
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
2020-03-28 00:03:05 +01:00
|
|
|
IOStatus WriteDirect();
|
Using existing crc32c checksum in checksum handoff for Manifest and WAL (#8412)
Summary:
In PR https://github.com/facebook/rocksdb/issues/7523 , checksum handoff is introduced in RocksDB for WAL, Manifest, and SST files. When user enable checksum handoff for a certain type of file, before the data is written to the lower layer storage system, we calculate the checksum (crc32c) of each piece of data and pass the checksum down with the data, such that data verification can be down by the lower layer storage system if it has the capability. However, it cannot cover the whole lifetime of the data in the memory and also it potentially introduces extra checksum calculation overhead.
In this PR, we introduce a new interface in WritableFileWriter::Append, which allows the caller be able to pass the data and the checksum (crc32c) together. In this way, WritableFileWriter can directly use the pass-in checksum (crc32c) to generate the checksum of data being passed down to the storage system. It saves the calculation overhead and achieves higher protection coverage. When a new checksum is added with the data, we use Crc32cCombine https://github.com/facebook/rocksdb/issues/8305 to combine the existing checksum and the new checksum. To avoid the segmenting of data by rate-limiter before it is stored, rate-limiter is called enough times to accumulate enough credits for a certain write. This design only support Manifest and WAL which use log_writer in the current stage.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8412
Test Plan: make check, add new testing cases.
Reviewed By: anand1976
Differential Revision: D29151545
Pulled By: zhichao-cao
fbshipit-source-id: 75e2278c5126cfd58393c67b1efd18dcc7a30772
2021-06-25 09:46:33 +02:00
|
|
|
IOStatus WriteDirectWithChecksum();
|
2019-09-16 19:31:27 +02:00
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
// Normal write
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
2020-03-28 00:03:05 +01:00
|
|
|
IOStatus WriteBuffered(const char* data, size_t size);
|
Using existing crc32c checksum in checksum handoff for Manifest and WAL (#8412)
Summary:
In PR https://github.com/facebook/rocksdb/issues/7523 , checksum handoff is introduced in RocksDB for WAL, Manifest, and SST files. When user enable checksum handoff for a certain type of file, before the data is written to the lower layer storage system, we calculate the checksum (crc32c) of each piece of data and pass the checksum down with the data, such that data verification can be down by the lower layer storage system if it has the capability. However, it cannot cover the whole lifetime of the data in the memory and also it potentially introduces extra checksum calculation overhead.
In this PR, we introduce a new interface in WritableFileWriter::Append, which allows the caller be able to pass the data and the checksum (crc32c) together. In this way, WritableFileWriter can directly use the pass-in checksum (crc32c) to generate the checksum of data being passed down to the storage system. It saves the calculation overhead and achieves higher protection coverage. When a new checksum is added with the data, we use Crc32cCombine https://github.com/facebook/rocksdb/issues/8305 to combine the existing checksum and the new checksum. To avoid the segmenting of data by rate-limiter before it is stored, rate-limiter is called enough times to accumulate enough credits for a certain write. This design only support Manifest and WAL which use log_writer in the current stage.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8412
Test Plan: make check, add new testing cases.
Reviewed By: anand1976
Differential Revision: D29151545
Pulled By: zhichao-cao
fbshipit-source-id: 75e2278c5126cfd58393c67b1efd18dcc7a30772
2021-06-25 09:46:33 +02:00
|
|
|
IOStatus WriteBufferedWithChecksum(const char* data, size_t size);
|
Pass IOStatus to write path and set retryable IO Error as hard error in BG jobs (#6487)
Summary:
In the current code base, we use Status to get and store the returned status from the call. Specifically, for IO related functions, the current Status cannot reflect the IO Error details such as error scope, error retryable attribute, and others. With the implementation of https://github.com/facebook/rocksdb/issues/5761, we have the new Wrapper for IO, which returns IOStatus instead of Status. However, the IOStatus is purged at the lower level of write path and transferred to Status.
The first job of this PR is to pass the IOStatus to the write path (flush, WAL write, and Compaction). The second job is to identify the Retryable IO Error as HardError, and set the bg_error_ as HardError. In this case, the DB Instance becomes read only. User is informed of the Status and need to take actions to deal with it (e.g., call db->Resume()).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6487
Test Plan: Added the testing case to error_handler_fs_test. Pass make asan_check
Reviewed By: anand1976
Differential Revision: D20685017
Pulled By: zhichao-cao
fbshipit-source-id: ff85f042896243abcd6ef37877834e26f36b6eb0
2020-03-28 00:03:05 +01:00
|
|
|
IOStatus RangeSync(uint64_t offset, uint64_t nbytes);
|
|
|
|
IOStatus SyncInternal(bool use_fsync);
|
2019-09-16 19:31:27 +02:00
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|