2020-08-27 20:54:43 +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).
|
|
|
|
#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;
|
2021-01-26 07:07:26 +01:00
|
|
|
class SystemClock;
|
2021-05-05 22:59:21 +02:00
|
|
|
struct ImmutableOptions;
|
2020-08-27 20:54:43 +02:00
|
|
|
struct MutableCFOptions;
|
|
|
|
struct FileOptions;
|
|
|
|
class BlobFileAddition;
|
|
|
|
class Status;
|
|
|
|
class Slice;
|
|
|
|
class BlobLogWriter;
|
2021-02-16 18:47:12 +01:00
|
|
|
class IOTracer;
|
2021-03-18 04:43:22 +01:00
|
|
|
class BlobFileCompletionCallback;
|
2020-08-27 20:54:43 +02:00
|
|
|
|
|
|
|
class BlobFileBuilder {
|
|
|
|
public:
|
2021-03-15 12:32:24 +01:00
|
|
|
BlobFileBuilder(VersionSet* versions, FileSystem* fs,
|
2021-05-05 22:59:21 +02:00
|
|
|
const ImmutableOptions* immutable_options,
|
2020-08-27 20:54:43 +02:00
|
|
|
const MutableCFOptions* mutable_cf_options,
|
2020-08-31 21:30:02 +02:00
|
|
|
const FileOptions* file_options, int job_id,
|
|
|
|
uint32_t column_family_id,
|
|
|
|
const std::string& column_family_name,
|
2020-08-27 20:54:43 +02:00
|
|
|
Env::IOPriority io_priority,
|
|
|
|
Env::WriteLifeTimeHint write_hint,
|
2021-02-16 18:47:12 +01:00
|
|
|
const std::shared_ptr<IOTracer>& io_tracer,
|
2021-03-18 04:43:22 +01:00
|
|
|
BlobFileCompletionCallback* blob_callback,
|
2020-09-15 06:10:09 +02:00
|
|
|
std::vector<std::string>* blob_file_paths,
|
2020-08-27 20:54:43 +02:00
|
|
|
std::vector<BlobFileAddition>* blob_file_additions);
|
|
|
|
|
2021-03-15 12:32:24 +01:00
|
|
|
BlobFileBuilder(std::function<uint64_t()> file_number_generator,
|
2021-05-05 22:59:21 +02:00
|
|
|
FileSystem* fs, const ImmutableOptions* immutable_options,
|
2020-08-27 20:54:43 +02:00
|
|
|
const MutableCFOptions* mutable_cf_options,
|
2020-08-31 21:30:02 +02:00
|
|
|
const FileOptions* file_options, int job_id,
|
|
|
|
uint32_t column_family_id,
|
|
|
|
const std::string& column_family_name,
|
2020-08-27 20:54:43 +02:00
|
|
|
Env::IOPriority io_priority,
|
|
|
|
Env::WriteLifeTimeHint write_hint,
|
2021-02-16 18:47:12 +01:00
|
|
|
const std::shared_ptr<IOTracer>& io_tracer,
|
2021-03-18 04:43:22 +01:00
|
|
|
BlobFileCompletionCallback* blob_callback,
|
2020-09-15 06:10:09 +02:00
|
|
|
std::vector<std::string>* blob_file_paths,
|
2020-08-27 20:54:43 +02:00
|
|
|
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();
|
2021-03-18 04:43:22 +01:00
|
|
|
void Abandon();
|
2020-08-27 20:54:43 +02:00
|
|
|
|
|
|
|
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_;
|
2021-06-17 01:50:43 +02:00
|
|
|
const ImmutableOptions* immutable_options_;
|
2020-08-27 20:54:43 +02:00
|
|
|
uint64_t min_blob_size_;
|
|
|
|
uint64_t blob_file_size_;
|
|
|
|
CompressionType blob_compression_type_;
|
|
|
|
const FileOptions* file_options_;
|
2020-08-31 21:30:02 +02:00
|
|
|
int job_id_;
|
2020-08-27 20:54:43 +02:00
|
|
|
uint32_t column_family_id_;
|
2020-08-31 21:30:02 +02:00
|
|
|
std::string column_family_name_;
|
2020-08-27 20:54:43 +02:00
|
|
|
Env::IOPriority io_priority_;
|
|
|
|
Env::WriteLifeTimeHint write_hint_;
|
2021-02-16 18:47:12 +01:00
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
2021-03-18 04:43:22 +01:00
|
|
|
BlobFileCompletionCallback* blob_callback_;
|
2020-09-15 06:10:09 +02:00
|
|
|
std::vector<std::string>* blob_file_paths_;
|
2020-08-27 20:54:43 +02:00
|
|
|
std::vector<BlobFileAddition>* blob_file_additions_;
|
|
|
|
std::unique_ptr<BlobLogWriter> writer_;
|
|
|
|
uint64_t blob_count_;
|
|
|
|
uint64_t blob_bytes_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|