mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 16:30:56 +00:00
699f45049d
Summary: Background: Cache warming up will cause potential read performance degradation due to reading blocks from storage to the block cache. Since in production, the workload and access pattern to a certain DB is stable, it is a potential solution to dump out the blocks belonging to a certain DB to persist storage (e.g., to a file) and bulk-load the blocks to Secondary cache before the DB is relaunched. For example, when migrating a DB form host A to host B, it will take a short period of time, the access pattern to blocks in the block cache will not change much. It is efficient to dump out the blocks of certain DB, migrate to the destination host and insert them to the Secondary cache before we relaunch the DB. Design: we introduce the interface of CacheDumpWriter and CacheDumpRead for user to store the blocks dumped out from block cache. RocksDB will encode all the information and send the string to the writer. User can implement their own writer it they want. CacheDumper and CacheLoad are introduced to save the blocks and load the blocks respectively. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8912 Test Plan: add new tests to lru_cache_test and pass make check. Reviewed By: pdillinger Differential Revision: D31452871 Pulled By: zhichao-cao fbshipit-source-id: 11ab4f5d03e383f476947116361d54188d36ec48
70 lines
2.6 KiB
C++
70 lines
2.6 KiB
C++
// Copyright (c) Facebook, Inc. and its affiliates. 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).
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
#include "rocksdb/utilities/cache_dump_load.h"
|
|
|
|
#include "file/writable_file_writer.h"
|
|
#include "port/lang.h"
|
|
#include "rocksdb/env.h"
|
|
#include "rocksdb/file_system.h"
|
|
#include "table/format.h"
|
|
#include "util/crc32c.h"
|
|
#include "utilities/cache_dump_load_impl.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
IOStatus NewToFileCacheDumpWriter(const std::shared_ptr<FileSystem>& fs,
|
|
const FileOptions& file_opts,
|
|
const std::string& file_name,
|
|
std::unique_ptr<CacheDumpWriter>* writer) {
|
|
std::unique_ptr<WritableFileWriter> file_writer;
|
|
IOStatus io_s = WritableFileWriter::Create(fs, file_name, file_opts,
|
|
&file_writer, nullptr);
|
|
if (!io_s.ok()) {
|
|
return io_s;
|
|
}
|
|
writer->reset(new ToFileCacheDumpWriter(std::move(file_writer)));
|
|
return io_s;
|
|
}
|
|
|
|
IOStatus NewFromFileCacheDumpReader(const std::shared_ptr<FileSystem>& fs,
|
|
const FileOptions& file_opts,
|
|
const std::string& file_name,
|
|
std::unique_ptr<CacheDumpReader>* reader) {
|
|
std::unique_ptr<RandomAccessFileReader> file_reader;
|
|
IOStatus io_s = RandomAccessFileReader::Create(fs, file_name, file_opts,
|
|
&file_reader, nullptr);
|
|
if (!io_s.ok()) {
|
|
return io_s;
|
|
}
|
|
reader->reset(new FromFileCacheDumpReader(std::move(file_reader)));
|
|
return io_s;
|
|
}
|
|
|
|
Status NewDefaultCacheDumper(const CacheDumpOptions& dump_options,
|
|
const std::shared_ptr<Cache>& cache,
|
|
std::unique_ptr<CacheDumpWriter>&& writer,
|
|
std::unique_ptr<CacheDumper>* cache_dumper) {
|
|
cache_dumper->reset(
|
|
new CacheDumperImpl(dump_options, cache, std::move(writer)));
|
|
return Status::OK();
|
|
}
|
|
|
|
Status NewDefaultCacheDumpedLoader(
|
|
const CacheDumpOptions& dump_options,
|
|
const BlockBasedTableOptions& toptions,
|
|
const std::shared_ptr<SecondaryCache>& secondary_cache,
|
|
std::unique_ptr<CacheDumpReader>&& reader,
|
|
std::unique_ptr<CacheDumpedLoader>* cache_dump_loader) {
|
|
cache_dump_loader->reset(new CacheDumpedLoaderImpl(
|
|
dump_options, toptions, secondary_cache, std::move(reader)));
|
|
return Status::OK();
|
|
}
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
|
#endif // ROCKSDB_LITE
|