12f1137355
Summary: Introduces and uses a SystemClock class to RocksDB. This class contains the time-related functions of an Env and these functions can be redirected from the Env to the SystemClock. Many of the places that used an Env (Timer, PerfStepTimer, RepeatableThread, RateLimiter, WriteController) for time-related functions have been changed to use SystemClock instead. There are likely more places that can be changed, but this is a start to show what can/should be done. Over time it would be nice to migrate most (if not all) of the uses of the time functions from the Env to the SystemClock. There are several Env classes that implement these functions. Most of these have not been converted yet to SystemClock implementations; that will come in a subsequent PR. It would be good to unify many of the Mock Timer implementations, so that they behave similarly and be tested similarly (some override Sleep, some use a MockSleep, etc). Additionally, this change will allow new methods to be introduced to the SystemClock (like https://github.com/facebook/rocksdb/issues/7101 WaitFor) in a consistent manner across a smaller number of classes. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7858 Reviewed By: pdillinger Differential Revision: D26006406 Pulled By: mrambacher fbshipit-source-id: ed10a8abbdab7ff2e23d69d85bd25b3e7e899e90
93 lines
3.2 KiB
C++
93 lines
3.2 KiB
C++
// 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 <cinttypes>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "rocksdb/compression_type.h"
|
|
#include "rocksdb/env.h"
|
|
#include "rocksdb/rocksdb_namespace.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
class VersionSet;
|
|
class FileSystem;
|
|
class SystemClock;
|
|
struct ImmutableCFOptions;
|
|
struct MutableCFOptions;
|
|
struct FileOptions;
|
|
class BlobFileAddition;
|
|
class Status;
|
|
class Slice;
|
|
class BlobLogWriter;
|
|
|
|
class BlobFileBuilder {
|
|
public:
|
|
BlobFileBuilder(VersionSet* versions, Env* env, FileSystem* fs,
|
|
const ImmutableCFOptions* immutable_cf_options,
|
|
const MutableCFOptions* mutable_cf_options,
|
|
const FileOptions* file_options, int job_id,
|
|
uint32_t column_family_id,
|
|
const std::string& column_family_name,
|
|
Env::IOPriority io_priority,
|
|
Env::WriteLifeTimeHint write_hint,
|
|
std::vector<std::string>* blob_file_paths,
|
|
std::vector<BlobFileAddition>* blob_file_additions);
|
|
|
|
BlobFileBuilder(std::function<uint64_t()> file_number_generator, Env* env,
|
|
FileSystem* fs,
|
|
const ImmutableCFOptions* immutable_cf_options,
|
|
const MutableCFOptions* mutable_cf_options,
|
|
const FileOptions* file_options, int job_id,
|
|
uint32_t column_family_id,
|
|
const std::string& column_family_name,
|
|
Env::IOPriority io_priority,
|
|
Env::WriteLifeTimeHint write_hint,
|
|
std::vector<std::string>* blob_file_paths,
|
|
std::vector<BlobFileAddition>* blob_file_additions);
|
|
|
|
BlobFileBuilder(const BlobFileBuilder&) = delete;
|
|
BlobFileBuilder& operator=(const BlobFileBuilder&) = delete;
|
|
|
|
~BlobFileBuilder();
|
|
|
|
Status Add(const Slice& key, const Slice& value, std::string* blob_index);
|
|
Status Finish();
|
|
|
|
private:
|
|
bool IsBlobFileOpen() const;
|
|
Status OpenBlobFileIfNeeded();
|
|
Status CompressBlobIfNeeded(Slice* blob, std::string* compressed_blob) const;
|
|
Status WriteBlobToFile(const Slice& key, const Slice& blob,
|
|
uint64_t* blob_file_number, uint64_t* blob_offset);
|
|
Status CloseBlobFile();
|
|
Status CloseBlobFileIfNeeded();
|
|
|
|
std::function<uint64_t()> file_number_generator_;
|
|
FileSystem* fs_;
|
|
std::shared_ptr<SystemClock> clock_;
|
|
const ImmutableCFOptions* immutable_cf_options_;
|
|
uint64_t min_blob_size_;
|
|
uint64_t blob_file_size_;
|
|
CompressionType blob_compression_type_;
|
|
const FileOptions* file_options_;
|
|
int job_id_;
|
|
uint32_t column_family_id_;
|
|
std::string column_family_name_;
|
|
Env::IOPriority io_priority_;
|
|
Env::WriteLifeTimeHint write_hint_;
|
|
std::vector<std::string>* blob_file_paths_;
|
|
std::vector<BlobFileAddition>* blob_file_additions_;
|
|
std::unique_ptr<BlobLogWriter> writer_;
|
|
uint64_t blob_count_;
|
|
uint64_t blob_bytes_;
|
|
};
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|