Summary: as part of the effort to get rid of OLD_CompressData and OLD_UncompressData and the old implementations in compression.h. It's unfortunate the the existing blob file schema doesn't allow storing blobs uncompressed when the compressed version is larger, so we have to work around that. Note that use of GrowableBuffer in place of std::string is intended to avoid the potential performance overhead of zeroing out memory before overwriting it. Also includes some cleanup of includes Pull Request resolved: https://github.com/facebook/rocksdb/pull/14234 Test Plan: some unit test updates as needed. Crash test covers integrated blob support. I'm not too concerned about performance, as until a future schema change, this code is committing the grave performance error of storing compressed data larger than uncompressed. Reviewed By: mszeszko-meta, hx235 Differential Revision: D90544049 Pulled By: pdillinger fbshipit-source-id: 2f2ed16de63990b797cc06c8dad36b5869dac302
115 lines
4.5 KiB
C++
115 lines
4.5 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 <memory>
|
|
|
|
#include "db/blob/blob_read_request.h"
|
|
#include "file/random_access_file_reader.h"
|
|
#include "rocksdb/advanced_compression.h"
|
|
#include "rocksdb/compression_type.h"
|
|
#include "rocksdb/rocksdb_namespace.h"
|
|
#include "util/autovector.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
class Status;
|
|
struct ImmutableOptions;
|
|
struct FileOptions;
|
|
class HistogramImpl;
|
|
struct ReadOptions;
|
|
class Slice;
|
|
class FilePrefetchBuffer;
|
|
class BlobContents;
|
|
class Statistics;
|
|
|
|
class BlobFileReader {
|
|
public:
|
|
static Status Create(const ImmutableOptions& immutable_options,
|
|
const ReadOptions& read_options,
|
|
const FileOptions& file_options,
|
|
uint32_t column_family_id,
|
|
HistogramImpl* blob_file_read_hist,
|
|
uint64_t blob_file_number,
|
|
const std::shared_ptr<IOTracer>& io_tracer,
|
|
std::unique_ptr<BlobFileReader>* reader);
|
|
|
|
BlobFileReader(const BlobFileReader&) = delete;
|
|
BlobFileReader& operator=(const BlobFileReader&) = delete;
|
|
|
|
~BlobFileReader();
|
|
|
|
Status GetBlob(const ReadOptions& read_options, const Slice& user_key,
|
|
uint64_t offset, uint64_t value_size,
|
|
CompressionType compression_type,
|
|
FilePrefetchBuffer* prefetch_buffer,
|
|
MemoryAllocator* allocator,
|
|
std::unique_ptr<BlobContents>* result,
|
|
uint64_t* bytes_read) const;
|
|
|
|
// offsets must be sorted in ascending order by caller.
|
|
void MultiGetBlob(
|
|
const ReadOptions& read_options, MemoryAllocator* allocator,
|
|
autovector<std::pair<BlobReadRequest*, std::unique_ptr<BlobContents>>>&
|
|
blob_reqs,
|
|
uint64_t* bytes_read) const;
|
|
|
|
CompressionType GetCompressionType() const { return compression_type_; }
|
|
|
|
uint64_t GetFileSize() const { return file_size_; }
|
|
|
|
private:
|
|
BlobFileReader(std::unique_ptr<RandomAccessFileReader>&& file_reader,
|
|
uint64_t file_size, CompressionType compression_type,
|
|
std::shared_ptr<Decompressor> decompressor, SystemClock* clock,
|
|
Statistics* statistics);
|
|
|
|
static Status OpenFile(const ImmutableOptions& immutable_options,
|
|
const FileOptions& file_opts,
|
|
HistogramImpl* blob_file_read_hist,
|
|
uint64_t blob_file_number,
|
|
const std::shared_ptr<IOTracer>& io_tracer,
|
|
uint64_t* file_size,
|
|
std::unique_ptr<RandomAccessFileReader>* file_reader);
|
|
|
|
static Status ReadHeader(const RandomAccessFileReader* file_reader,
|
|
const ReadOptions& read_options,
|
|
uint32_t column_family_id, Statistics* statistics,
|
|
CompressionType* compression_type);
|
|
|
|
static Status ReadFooter(const RandomAccessFileReader* file_reader,
|
|
const ReadOptions& read_options, uint64_t file_size,
|
|
Statistics* statistics);
|
|
|
|
using Buffer = std::unique_ptr<char[]>;
|
|
|
|
static Status ReadFromFile(const RandomAccessFileReader* file_reader,
|
|
const ReadOptions& read_options,
|
|
uint64_t read_offset, size_t read_size,
|
|
Statistics* statistics, Slice* slice, Buffer* buf,
|
|
AlignedBuf* aligned_buf);
|
|
|
|
static Status VerifyBlob(const Slice& record_slice, const Slice& user_key,
|
|
uint64_t value_size);
|
|
|
|
static Status UncompressBlobIfNeeded(const Slice& value_slice,
|
|
CompressionType compression_type,
|
|
Decompressor* decompressor,
|
|
MemoryAllocator* allocator,
|
|
SystemClock* clock,
|
|
Statistics* statistics,
|
|
std::unique_ptr<BlobContents>* result);
|
|
|
|
std::unique_ptr<RandomAccessFileReader> file_reader_;
|
|
uint64_t file_size_;
|
|
CompressionType compression_type_;
|
|
std::shared_ptr<Decompressor> decompressor_;
|
|
SystemClock* clock_;
|
|
Statistics* statistics_;
|
|
};
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|