|
|
|
// 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).
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <atomic>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "db/version_edit.h"
|
|
|
|
#include "port/port.h"
|
|
|
|
#include "rocksdb/comparator.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
5 years ago
|
|
|
#include "rocksdb/io_status.h"
|
|
|
|
#include "rocksdb/table.h"
|
|
|
|
#include "table/internal_iterator.h"
|
|
|
|
#include "table/table_builder.h"
|
|
|
|
#include "table/table_reader.h"
|
|
|
|
#include "test_util/testharness.h"
|
|
|
|
#include "test_util/testutil.h"
|
|
|
|
#include "util/kv_map.h"
|
|
|
|
#include "util/mutexlock.h"
|
|
|
|
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
namespace mock {
|
|
|
|
using KVPair = std::pair<std::string, std::string>;
|
|
|
|
using KVVector = std::vector<KVPair>;
|
|
|
|
|
|
|
|
KVVector MakeMockFile(std::initializer_list<KVPair> l = {});
|
|
|
|
void SortKVVector(KVVector* kv_vector,
|
|
|
|
const Comparator* ucmp = BytewiseComparator());
|
|
|
|
|
|
|
|
struct MockTableFileSystem {
|
|
|
|
port::Mutex mutex;
|
|
|
|
std::map<uint32_t, KVVector> files;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MockTableFactory : public TableFactory {
|
|
|
|
public:
|
|
|
|
enum MockCorruptionMode {
|
|
|
|
kCorruptNone,
|
|
|
|
kCorruptKey,
|
|
|
|
kCorruptValue,
|
|
|
|
kCorruptReorderKey,
|
|
|
|
};
|
|
|
|
|
|
|
|
MockTableFactory();
|
|
|
|
const char* Name() const override { return "MockTable"; }
|
|
|
|
using TableFactory::NewTableReader;
|
|
|
|
Status NewTableReader(
|
|
|
|
const ReadOptions& ro, const TableReaderOptions& table_reader_options,
|
|
|
|
std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
|
|
|
|
std::unique_ptr<TableReader>* table_reader,
|
|
|
|
bool prefetch_index_and_filter_in_cache = true) const override;
|
A new call back to TablePropertiesCollector to allow users know the entry is add, delete or merge
Summary:
Currently users have no idea a key is add, delete or merge from TablePropertiesCollector call back. Add a new function to add it.
Also refactor the codes so that
(1) make table property collector and internal table property collector two separate data structures with the later one now exposed
(2) table builders only receive internal table properties
Test Plan: Add cases in table_properties_collector_test to cover both of old and new ways of using TablePropertiesCollector.
Reviewers: yhchiang, igor.sugak, rven, igor
Reviewed By: rven, igor
Subscribers: meyering, yoshinorim, maykov, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D35373
10 years ago
|
|
|
TableBuilder* NewTableBuilder(
|
|
|
|
const TableBuilderOptions& table_builder_options,
|
|
|
|
uint32_t column_familly_id, WritableFileWriter* file) const override;
|
|
|
|
|
|
|
|
// This function will directly create mock table instead of going through
|
|
|
|
// MockTableBuilder. file_contents has to have a format of <internal_key,
|
|
|
|
// value>. Those key-value pairs will then be inserted into the mock table.
|
|
|
|
Status CreateMockTable(Env* env, const std::string& fname,
|
|
|
|
KVVector file_contents);
|
|
|
|
|
|
|
|
virtual std::string GetPrintableOptions() const override {
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCorruptionMode(MockCorruptionMode mode) { corrupt_mode_ = mode; }
|
|
|
|
// This function will assert that only a single file exists and that the
|
|
|
|
// contents are equal to file_contents
|
|
|
|
void AssertSingleFile(const KVVector& file_contents);
|
|
|
|
void AssertLatestFile(const KVVector& file_contents);
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t GetAndWriteNextID(WritableFileWriter* file) const;
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
9 years ago
|
|
|
uint32_t GetIDFromFile(RandomAccessFileReader* file) const;
|
|
|
|
|
|
|
|
mutable MockTableFileSystem file_system_;
|
|
|
|
mutable std::atomic<uint32_t> next_id_;
|
|
|
|
MockCorruptionMode corrupt_mode_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mock
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|