2015-12-16 02:20:10 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00: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).
|
2015-12-16 02:20:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2017-04-06 02:02:00 +00:00
|
|
|
#include "monitoring/statistics.h"
|
2017-03-04 02:09:43 +00:00
|
|
|
#include "table/format.h"
|
|
|
|
#include "table/persistent_cache_options.h"
|
2015-12-16 02:20:10 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2015-12-16 02:20:10 +00:00
|
|
|
|
|
|
|
struct BlockContents;
|
|
|
|
|
|
|
|
// PersistentCacheHelper
|
|
|
|
//
|
|
|
|
// Encapsulates some of the helper logic for read and writing from the cache
|
|
|
|
class PersistentCacheHelper {
|
|
|
|
public:
|
Refactor to avoid confusing "raw block" (#10408)
Summary:
We have a lot of confusing code because of mixed, sometimes
completely opposite uses of of the term "raw block" or "raw contents",
sometimes within the same source file. For example, in `BlockBasedTableBuilder`,
`raw_block_contents` and `raw_size` generally referred to uncompressed block
contents and size, while `WriteRawBlock` referred to writing a block that
is already compressed if it is going to be. Meanwhile, in
`BlockBasedTable`, `raw_block_contents` either referred to a (maybe
compressed) block with trailer, or a maybe compressed block maybe
without trailer. (Note: left as follow-up work to use C++ typing to
better sort out the various kinds of BlockContents.)
This change primarily tries to apply some consistent terminology around
the kinds of block representations, avoiding the unclear "raw". (Any
meaning of "raw" assumes some bias toward the storage layer or toward
the logical data layer.) Preferred terminology:
* **Serialized block** - bytes that go into storage. For block-based table
(usually the case) this includes the block trailer. WART: block `size` may or
may not include the trailer; need to be clear about whether it does or not.
* **Maybe compressed block** - like a serialized block, but without the
trailer (or no promise of including a trailer). Must be accompanied by a
CompressionType.
* **Uncompressed block** - "payload" bytes that are either stored with no
compression, used as input to compression function, or result of
decompression function.
* **Parsed block** - an in-memory form of a block in block cache, as it is
used by the table reader. Different C++ types are used depending on the
block type (see block_like_traits.h).
Other refactorings:
* Misc corrections/improvements of internal API comments
* Remove a few misleading / unhelpful / redundant comments.
* Use move semantics in some places to simplify contracts
* Use better parameter names to indicate which parameters are used for
outputs
* Remove some extraneous `extern`
* Various clean-ups to `CacheDumperImpl` (mostly unnecessary code)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/10408
Test Plan: existing tests
Reviewed By: akankshamahajan15
Differential Revision: D38172617
Pulled By: pdillinger
fbshipit-source-id: ccb99299f324ac5ca46996d34c5089621a4f260c
2022-09-22 18:25:32 +00:00
|
|
|
// Insert block into cache of serialized blocks. Size includes block trailer
|
|
|
|
// (if applicable).
|
|
|
|
static void InsertSerialized(const PersistentCacheOptions& cache_options,
|
|
|
|
const BlockHandle& handle, const char* data,
|
|
|
|
const size_t size);
|
|
|
|
|
|
|
|
// Insert block into cache of uncompressed blocks. No block trailer.
|
|
|
|
static void InsertUncompressed(const PersistentCacheOptions& cache_options,
|
|
|
|
const BlockHandle& handle,
|
|
|
|
const BlockContents& contents);
|
|
|
|
|
|
|
|
// Lookup block from cache of serialized blocks. Size includes block trailer
|
|
|
|
// (if applicable).
|
|
|
|
static Status LookupSerialized(const PersistentCacheOptions& cache_options,
|
|
|
|
const BlockHandle& handle,
|
|
|
|
std::unique_ptr<char[]>* out_data,
|
|
|
|
const size_t expected_data_size);
|
|
|
|
|
|
|
|
// Lookup block from uncompressed cache. No block trailer.
|
|
|
|
static Status LookupUncompressed(const PersistentCacheOptions& cache_options,
|
|
|
|
const BlockHandle& handle,
|
|
|
|
BlockContents* contents);
|
2015-12-16 02:20:10 +00:00
|
|
|
};
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|