55f7ded80d
Summary: Originally the 2 options `db_log_dir` and `wal_dir` will be reused in a snapshot db since the options files are just copied. By default, if `wal_dir` was not set when a db was created, it is set to the db's dir. Therefore, the snapshot db will use the same WAL dir. If both the original db and the snapshot db write to or delete from the WAL dir, one may modify or delete files which belong to the other. The same applies to `db_log_dir` as well, but as info log files are not copied or linked, it is simpler for this option. 2 arguments are added to `Checkpoint::CreateCheckpoint()`, allowing to override these 2 options. `wal_dir`: If the function argument `wal_dir` is empty, or set to the original db location, or the checkpoint location, the snapshot's `wal_dir` option will be updated to the checkpoint location. Otherwise, the absolute path specified in the argument will be used. During checkpointing, live WAL files will be copied or linked the new location, instead of the current WAL dir specified in the original db. `db_log_dir`: Same as `wal_dir`, but no files will be copied or linked. A new unit test was added: `CheckpointTest.CheckpointWithOptionsDirsTest`. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8572 Test Plan: New unit test ``` checkpoint_test --gtest_filter="CheckpointTest.CheckpointWithOptionsDirsTest" ``` Output ``` Note: Google Test filter = CheckpointTest.CheckpointWithOptionsDirsTest [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from CheckpointTest [ RUN ] CheckpointTest.CheckpointWithOptionsDirsTest [ OK ] CheckpointTest.CheckpointWithOptionsDirsTest (11712 ms) [----------] 1 test from CheckpointTest (11712 ms total) [----------] Global test environment tear-down [==========] 1 test from 1 test case ran. (11713 ms total) [ PASSED ] 1 test. ``` This test will fail without this patch. Just modify the code to remove the 2 arguments introduced in this patch in `CreateCheckpoint()`. Reviewed By: zhichao-cao Differential Revision: D29832761 Pulled By: autopear fbshipit-source-id: e6a639b4d674380df82998c0839e79cab695fe29
74 lines
2.7 KiB
C++
74 lines
2.7 KiB
C++
// Copyright (c) 2017-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
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
#include "rocksdb/utilities/checkpoint.h"
|
|
|
|
#include <string>
|
|
#include "file/filename.h"
|
|
#include "rocksdb/db.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
class CheckpointImpl : public Checkpoint {
|
|
public:
|
|
explicit CheckpointImpl(DB* db) : db_(db) {}
|
|
|
|
Status CreateCheckpoint(const std::string& checkpoint_dir,
|
|
uint64_t log_size_for_flush,
|
|
uint64_t* sequence_number_ptr,
|
|
const std::string& db_log_dir,
|
|
const std::string& wal_dir) override;
|
|
|
|
Status ExportColumnFamily(ColumnFamilyHandle* handle,
|
|
const std::string& export_dir,
|
|
ExportImportFilesMetaData** metadata) override;
|
|
|
|
// Checkpoint logic can be customized by providing callbacks for link, copy,
|
|
// or create.
|
|
Status CreateCustomCheckpoint(
|
|
const DBOptions& db_options,
|
|
std::function<Status(const std::string& src_dirname,
|
|
const std::string& fname, FileType type)>
|
|
link_file_cb,
|
|
std::function<Status(const std::string& src_dirname,
|
|
const std::string& fname, uint64_t size_limit_bytes,
|
|
FileType type, const std::string& checksum_func_name,
|
|
const std::string& checksum_val)>
|
|
copy_file_cb,
|
|
std::function<Status(const std::string& fname,
|
|
const std::string& contents, FileType type)>
|
|
create_file_cb,
|
|
uint64_t* sequence_number, uint64_t log_size_for_flush,
|
|
bool get_live_table_checksum = false);
|
|
|
|
private:
|
|
void CleanStagingDirectory(const std::string& path, Logger* info_log);
|
|
|
|
// Export logic customization by providing callbacks for link or copy.
|
|
Status ExportFilesInMetaData(
|
|
const DBOptions& db_options, const ColumnFamilyMetaData& metadata,
|
|
std::function<Status(const std::string& src_dirname,
|
|
const std::string& fname)>
|
|
link_file_cb,
|
|
std::function<Status(const std::string& src_dirname,
|
|
const std::string& fname)>
|
|
copy_file_cb);
|
|
|
|
Status CopyOptionsFile(const std::string& src_file,
|
|
const std::string& target_file,
|
|
const std::string& db_log_dir,
|
|
const std::string& wal_dir);
|
|
|
|
private:
|
|
DB* db_;
|
|
};
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
|
|
|
#endif // ROCKSDB_LITE
|