2017-04-24 23:57:27 +02:00
|
|
|
// Copyright (c) 2017-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-04-24 23:57:27 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
|
|
|
#include "rocksdb/utilities/checkpoint.h"
|
|
|
|
|
|
|
|
#include <string>
|
2019-05-30 05:44:08 +02:00
|
|
|
#include "file/filename.h"
|
2017-04-24 23:57:27 +02:00
|
|
|
#include "rocksdb/db.h"
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2017-04-24 23:57:27 +02:00
|
|
|
|
|
|
|
class CheckpointImpl : public Checkpoint {
|
|
|
|
public:
|
|
|
|
explicit CheckpointImpl(DB* db) : db_(db) {}
|
|
|
|
|
2021-02-17 21:40:33 +01:00
|
|
|
Status CreateCheckpoint(const std::string& checkpoint_dir,
|
|
|
|
uint64_t log_size_for_flush,
|
2021-08-03 03:27:11 +02:00
|
|
|
uint64_t* sequence_number_ptr) override;
|
2021-02-17 21:40:33 +01:00
|
|
|
|
|
|
|
Status ExportColumnFamily(ColumnFamilyHandle* handle,
|
|
|
|
const std::string& export_dir,
|
|
|
|
ExportImportFilesMetaData** metadata) override;
|
Export Import sst files (#5495)
Summary:
Refresh of the earlier change here - https://github.com/facebook/rocksdb/issues/5135
This is a review request for code change needed for - https://github.com/facebook/rocksdb/issues/3469
"Add support for taking snapshot of a column family and creating column family from a given CF snapshot"
We have an implementation for this that we have been testing internally. We have two new APIs that together provide this functionality.
(1) ExportColumnFamily() - This API is modelled after CreateCheckpoint() as below.
// Exports all live SST files of a specified Column Family onto export_dir,
// returning SST files information in metadata.
// - SST files will be created as hard links when the directory specified
// is in the same partition as the db directory, copied otherwise.
// - export_dir should not already exist and will be created by this API.
// - Always triggers a flush.
virtual Status ExportColumnFamily(ColumnFamilyHandle* handle,
const std::string& export_dir,
ExportImportFilesMetaData** metadata);
Internally, the API will DisableFileDeletions(), GetColumnFamilyMetaData(), Parse through
metadata, creating links/copies of all the sst files, EnableFileDeletions() and complete the call by
returning the list of file metadata.
(2) CreateColumnFamilyWithImport() - This API is modeled after IngestExternalFile(), but invoked only during a CF creation as below.
// CreateColumnFamilyWithImport() will create a new column family with
// column_family_name and import external SST files specified in metadata into
// this column family.
// (1) External SST files can be created using SstFileWriter.
// (2) External SST files can be exported from a particular column family in
// an existing DB.
// Option in import_options specifies whether the external files are copied or
// moved (default is copy). When option specifies copy, managing files at
// external_file_path is caller's responsibility. When option specifies a
// move, the call ensures that the specified files at external_file_path are
// deleted on successful return and files are not modified on any error
// return.
// On error return, column family handle returned will be nullptr.
// ColumnFamily will be present on successful return and will not be present
// on error return. ColumnFamily may be present on any crash during this call.
virtual Status CreateColumnFamilyWithImport(
const ColumnFamilyOptions& options, const std::string& column_family_name,
const ImportColumnFamilyOptions& import_options,
const ExportImportFilesMetaData& metadata,
ColumnFamilyHandle** handle);
Internally, this API creates a new CF, parses all the sst files and adds it to the specified column family, at the same level and with same sequence number as in the metadata. Also performs safety checks with respect to overlaps between the sst files being imported.
If incoming sequence number is higher than current local sequence number, local sequence
number is updated to reflect this.
Note, as the sst files is are being moved across Column Families, Column Family name in sst file
will no longer match the actual column family on destination DB. The API does not modify Column
Family name or id in the sst files being imported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5495
Differential Revision: D16018881
fbshipit-source-id: 9ae2251025d5916d35a9fc4ea4d6707f6be16ff9
2019-07-17 21:22:21 +02:00
|
|
|
|
2017-04-24 23:57:27 +02:00
|
|
|
// Checkpoint logic can be customized by providing callbacks for link, copy,
|
|
|
|
// or create.
|
|
|
|
Status CreateCustomCheckpoint(
|
|
|
|
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,
|
2020-07-03 03:13:31 +02:00
|
|
|
FileType type, const std::string& checksum_func_name,
|
|
|
|
const std::string& checksum_val)>
|
2017-04-24 23:57:27 +02:00
|
|
|
copy_file_cb,
|
|
|
|
std::function<Status(const std::string& fname,
|
|
|
|
const std::string& contents, FileType type)>
|
|
|
|
create_file_cb,
|
2020-07-03 03:13:31 +02:00
|
|
|
uint64_t* sequence_number, uint64_t log_size_for_flush,
|
2020-08-26 19:37:59 +02:00
|
|
|
bool get_live_table_checksum = false);
|
2017-04-24 23:57:27 +02:00
|
|
|
|
|
|
|
private:
|
2018-06-22 01:22:57 +02:00
|
|
|
void CleanStagingDirectory(const std::string& path, Logger* info_log);
|
Export Import sst files (#5495)
Summary:
Refresh of the earlier change here - https://github.com/facebook/rocksdb/issues/5135
This is a review request for code change needed for - https://github.com/facebook/rocksdb/issues/3469
"Add support for taking snapshot of a column family and creating column family from a given CF snapshot"
We have an implementation for this that we have been testing internally. We have two new APIs that together provide this functionality.
(1) ExportColumnFamily() - This API is modelled after CreateCheckpoint() as below.
// Exports all live SST files of a specified Column Family onto export_dir,
// returning SST files information in metadata.
// - SST files will be created as hard links when the directory specified
// is in the same partition as the db directory, copied otherwise.
// - export_dir should not already exist and will be created by this API.
// - Always triggers a flush.
virtual Status ExportColumnFamily(ColumnFamilyHandle* handle,
const std::string& export_dir,
ExportImportFilesMetaData** metadata);
Internally, the API will DisableFileDeletions(), GetColumnFamilyMetaData(), Parse through
metadata, creating links/copies of all the sst files, EnableFileDeletions() and complete the call by
returning the list of file metadata.
(2) CreateColumnFamilyWithImport() - This API is modeled after IngestExternalFile(), but invoked only during a CF creation as below.
// CreateColumnFamilyWithImport() will create a new column family with
// column_family_name and import external SST files specified in metadata into
// this column family.
// (1) External SST files can be created using SstFileWriter.
// (2) External SST files can be exported from a particular column family in
// an existing DB.
// Option in import_options specifies whether the external files are copied or
// moved (default is copy). When option specifies copy, managing files at
// external_file_path is caller's responsibility. When option specifies a
// move, the call ensures that the specified files at external_file_path are
// deleted on successful return and files are not modified on any error
// return.
// On error return, column family handle returned will be nullptr.
// ColumnFamily will be present on successful return and will not be present
// on error return. ColumnFamily may be present on any crash during this call.
virtual Status CreateColumnFamilyWithImport(
const ColumnFamilyOptions& options, const std::string& column_family_name,
const ImportColumnFamilyOptions& import_options,
const ExportImportFilesMetaData& metadata,
ColumnFamilyHandle** handle);
Internally, this API creates a new CF, parses all the sst files and adds it to the specified column family, at the same level and with same sequence number as in the metadata. Also performs safety checks with respect to overlaps between the sst files being imported.
If incoming sequence number is higher than current local sequence number, local sequence
number is updated to reflect this.
Note, as the sst files is are being moved across Column Families, Column Family name in sst file
will no longer match the actual column family on destination DB. The API does not modify Column
Family name or id in the sst files being imported.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5495
Differential Revision: D16018881
fbshipit-source-id: 9ae2251025d5916d35a9fc4ea4d6707f6be16ff9
2019-07-17 21:22:21 +02:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
private:
|
2017-04-24 23:57:27 +02:00
|
|
|
DB* db_;
|
|
|
|
};
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2017-04-24 23:57:27 +02:00
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|