2017-05-10 23:54:35 +02:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// 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).
|
2017-05-10 23:54:35 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
2020-06-10 00:12:59 +02:00
|
|
|
#include "db/blob/blob_log_format.h"
|
2017-05-10 23:54:35 +02:00
|
|
|
#include "rocksdb/slice.h"
|
2017-11-28 20:42:28 +01:00
|
|
|
#include "rocksdb/statistics.h"
|
2017-05-10 23:54:35 +02:00
|
|
|
#include "rocksdb/status.h"
|
|
|
|
#include "rocksdb/types.h"
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2017-05-10 23:54:35 +02:00
|
|
|
|
|
|
|
class WritableFileWriter;
|
2021-01-26 07:07:26 +01:00
|
|
|
class SystemClock;
|
2017-05-10 23:54:35 +02:00
|
|
|
/**
|
2020-07-07 02:10:41 +02:00
|
|
|
* BlobLogWriter is the blob log stream writer. It provides an append-only
|
2017-05-10 23:54:35 +02:00
|
|
|
* abstraction for writing blob data.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Look at blob_db_format.h to see the details of the record formats.
|
|
|
|
*/
|
|
|
|
|
2020-07-07 02:10:41 +02:00
|
|
|
class BlobLogWriter {
|
2017-05-10 23:54:35 +02:00
|
|
|
public:
|
|
|
|
// Create a writer that will append data to "*dest".
|
|
|
|
// "*dest" must be initially empty.
|
2020-07-07 02:10:41 +02:00
|
|
|
// "*dest" must remain live while this BlobLogWriter is in use.
|
2021-01-26 07:07:26 +01:00
|
|
|
BlobLogWriter(std::unique_ptr<WritableFileWriter>&& dest,
|
|
|
|
const std::shared_ptr<SystemClock>& clock,
|
2020-07-14 22:50:26 +02:00
|
|
|
Statistics* statistics, uint64_t log_number, bool use_fsync,
|
Do not explicitly flush blob files when using the integrated BlobDB (#7892)
Summary:
In the original stacked BlobDB implementation, which writes blobs to blob files
immediately and treats blob files as logs, it makes sense to flush the file after
writing each blob to protect against process crashes; however, in the integrated
implementation, which builds blob files in the background jobs, this unnecessarily
reduces performance. This patch fixes this by simply adding a `do_flush` flag to
`BlobLogWriter`, which is set to `true` by the stacked implementation and to `false`
by the new code. Note: the change itself is trivial but the tests needed some work;
since in the new implementation, blobs are now buffered, adding a blob to
`BlobFileBuilder` is no longer guaranteed to result in an actual I/O. Therefore, we can
no longer rely on `FaultInjectionTestEnv` when testing failure cases; instead, we
manipulate the return values of I/O methods directly using `SyncPoint`s.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7892
Test Plan: `make check`
Reviewed By: jay-zhuang
Differential Revision: D26022814
Pulled By: ltamasi
fbshipit-source-id: b3dce419f312137fa70d84cdd9b908fd5d60d8cd
2021-01-25 22:30:17 +01:00
|
|
|
bool do_flush, uint64_t boffset = 0);
|
2017-10-27 22:14:34 +02:00
|
|
|
// No copying allowed
|
2020-07-07 02:10:41 +02:00
|
|
|
BlobLogWriter(const BlobLogWriter&) = delete;
|
|
|
|
BlobLogWriter& operator=(const BlobLogWriter&) = delete;
|
2017-10-27 22:14:34 +02:00
|
|
|
|
2020-08-27 20:54:43 +02:00
|
|
|
~BlobLogWriter();
|
2019-09-12 03:07:12 +02:00
|
|
|
|
2017-10-27 22:14:34 +02:00
|
|
|
static void ConstructBlobHeader(std::string* buf, const Slice& key,
|
|
|
|
const Slice& val, uint64_t expiration);
|
2017-05-10 23:54:35 +02:00
|
|
|
|
|
|
|
Status AddRecord(const Slice& key, const Slice& val, uint64_t* key_offset,
|
|
|
|
uint64_t* blob_offset);
|
|
|
|
|
2017-10-27 22:14:34 +02:00
|
|
|
Status AddRecord(const Slice& key, const Slice& val, uint64_t expiration,
|
|
|
|
uint64_t* key_offset, uint64_t* blob_offset);
|
2017-05-10 23:54:35 +02:00
|
|
|
|
|
|
|
Status EmitPhysicalRecord(const std::string& headerbuf, const Slice& key,
|
|
|
|
const Slice& val, uint64_t* key_offset,
|
|
|
|
uint64_t* blob_offset);
|
|
|
|
|
2020-08-27 20:54:43 +02:00
|
|
|
Status AppendFooter(BlobLogFooter& footer, std::string* checksum_method,
|
|
|
|
std::string* checksum_value);
|
2017-05-10 23:54:35 +02:00
|
|
|
|
2017-10-27 22:14:34 +02:00
|
|
|
Status WriteHeader(BlobLogHeader& header);
|
2017-05-10 23:54:35 +02:00
|
|
|
|
|
|
|
WritableFileWriter* file() { return dest_.get(); }
|
|
|
|
|
|
|
|
const WritableFileWriter* file() const { return dest_.get(); }
|
|
|
|
|
|
|
|
uint64_t get_log_number() const { return log_number_; }
|
|
|
|
|
2017-12-11 21:01:22 +01:00
|
|
|
Status Sync();
|
2017-05-10 23:54:35 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<WritableFileWriter> dest_;
|
2021-01-26 07:07:26 +01:00
|
|
|
std::shared_ptr<SystemClock> clock_;
|
2017-11-28 20:42:28 +01:00
|
|
|
Statistics* statistics_;
|
2017-05-10 23:54:35 +02:00
|
|
|
uint64_t log_number_;
|
|
|
|
uint64_t block_offset_; // Current offset in block
|
|
|
|
bool use_fsync_;
|
Do not explicitly flush blob files when using the integrated BlobDB (#7892)
Summary:
In the original stacked BlobDB implementation, which writes blobs to blob files
immediately and treats blob files as logs, it makes sense to flush the file after
writing each blob to protect against process crashes; however, in the integrated
implementation, which builds blob files in the background jobs, this unnecessarily
reduces performance. This patch fixes this by simply adding a `do_flush` flag to
`BlobLogWriter`, which is set to `true` by the stacked implementation and to `false`
by the new code. Note: the change itself is trivial but the tests needed some work;
since in the new implementation, blobs are now buffered, adding a blob to
`BlobFileBuilder` is no longer guaranteed to result in an actual I/O. Therefore, we can
no longer rely on `FaultInjectionTestEnv` when testing failure cases; instead, we
manipulate the return values of I/O methods directly using `SyncPoint`s.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7892
Test Plan: `make check`
Reviewed By: jay-zhuang
Differential Revision: D26022814
Pulled By: ltamasi
fbshipit-source-id: b3dce419f312137fa70d84cdd9b908fd5d60d8cd
2021-01-25 22:30:17 +01:00
|
|
|
bool do_flush_;
|
2017-05-10 23:54:35 +02:00
|
|
|
|
|
|
|
public:
|
2017-10-17 21:11:52 +02:00
|
|
|
enum ElemType { kEtNone, kEtFileHdr, kEtRecord, kEtFileFooter };
|
2017-05-10 23:54:35 +02:00
|
|
|
ElemType last_elem_type_;
|
|
|
|
};
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|