2016-02-09 23:12:00 +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).
|
2014-09-25 18:14:01 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
2019-05-31 22:21:36 +00:00
|
|
|
#include <vector>
|
2022-10-25 20:49:09 +00:00
|
|
|
|
2019-05-31 22:21:36 +00:00
|
|
|
#include "db/db_impl/db_impl.h"
|
2014-09-25 18:14:01 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2014-09-25 18:14:01 +00:00
|
|
|
|
2022-08-29 20:36:23 +00:00
|
|
|
// TODO: Share common structure with DBImplSecondary and DBImplReadOnly
|
2014-09-25 18:14:01 +00:00
|
|
|
class CompactedDBImpl : public DBImpl {
|
|
|
|
public:
|
|
|
|
CompactedDBImpl(const DBOptions& options, const std::string& dbname);
|
2019-09-12 01:07:12 +00:00
|
|
|
// No copying allowed
|
|
|
|
CompactedDBImpl(const CompactedDBImpl&) = delete;
|
|
|
|
void operator=(const CompactedDBImpl&) = delete;
|
|
|
|
|
2021-03-23 20:47:56 +00:00
|
|
|
~CompactedDBImpl() override;
|
2014-09-25 18:14:01 +00:00
|
|
|
|
|
|
|
static Status Open(const Options& options, const std::string& dbname,
|
|
|
|
DB** dbptr);
|
|
|
|
|
|
|
|
// Implementations of the DB interface
|
|
|
|
using DB::Get;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Get(const ReadOptions& options, ColumnFamilyHandle* column_family,
|
2024-02-16 17:21:06 +00:00
|
|
|
const Slice& key, PinnableSlice* value,
|
|
|
|
std::string* timestamp) override;
|
2022-05-24 19:14:10 +00:00
|
|
|
|
2014-09-25 20:34:51 +00:00
|
|
|
using DB::MultiGet;
|
2022-05-24 19:14:10 +00:00
|
|
|
// Note that CompactedDBImpl::MultiGet is not the optimized version of
|
|
|
|
// MultiGet to use.
|
|
|
|
// TODO: optimize CompactedDBImpl::MultiGet, see DBImpl::MultiGet for details.
|
2024-02-16 17:21:06 +00:00
|
|
|
void MultiGet(const ReadOptions& options, size_t num_keys,
|
|
|
|
ColumnFamilyHandle** column_families, const Slice* keys,
|
|
|
|
PinnableSlice* values, std::string* timestamps,
|
|
|
|
Status* statuses, const bool sorted_input) override;
|
2014-09-25 18:14:01 +00:00
|
|
|
|
|
|
|
using DBImpl::Put;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Put(const WriteOptions& /*options*/,
|
|
|
|
ColumnFamilyHandle* /*column_family*/, const Slice& /*key*/,
|
|
|
|
const Slice& /*value*/) override {
|
2014-09-25 18:14:01 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
2022-06-25 22:30:47 +00:00
|
|
|
|
|
|
|
using DBImpl::PutEntity;
|
|
|
|
Status PutEntity(const WriteOptions& /* options */,
|
|
|
|
ColumnFamilyHandle* /* column_family */,
|
|
|
|
const Slice& /* key */,
|
|
|
|
const WideColumns& /* columns */) override {
|
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
|
|
|
|
2014-09-25 18:14:01 +00:00
|
|
|
using DBImpl::Merge;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Merge(const WriteOptions& /*options*/,
|
|
|
|
ColumnFamilyHandle* /*column_family*/, const Slice& /*key*/,
|
|
|
|
const Slice& /*value*/) override {
|
2014-09-25 18:14:01 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
2022-06-25 22:30:47 +00:00
|
|
|
|
2014-09-25 18:14:01 +00:00
|
|
|
using DBImpl::Delete;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Delete(const WriteOptions& /*options*/,
|
|
|
|
ColumnFamilyHandle* /*column_family*/,
|
|
|
|
const Slice& /*key*/) override {
|
2014-09-25 18:14:01 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Write(const WriteOptions& /*options*/,
|
|
|
|
WriteBatch* /*updates*/) override {
|
2014-09-25 18:14:01 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
|
|
|
using DBImpl::CompactRange;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status CompactRange(const CompactRangeOptions& /*options*/,
|
|
|
|
ColumnFamilyHandle* /*column_family*/,
|
|
|
|
const Slice* /*begin*/, const Slice* /*end*/) override {
|
2014-09-25 18:14:01 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
Status DisableFileDeletions() override {
|
2014-09-25 18:14:01 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
2024-02-14 02:36:25 +00:00
|
|
|
Status EnableFileDeletions() override {
|
2014-09-25 18:14:01 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
2024-01-31 21:14:42 +00:00
|
|
|
Status GetLiveFiles(std::vector<std::string>& ret,
|
|
|
|
uint64_t* manifest_file_size,
|
|
|
|
bool /*flush_memtable*/) override {
|
2018-12-08 01:03:49 +00:00
|
|
|
return DBImpl::GetLiveFiles(ret, manifest_file_size,
|
|
|
|
false /* flush_memtable */);
|
2014-09-25 18:14:01 +00:00
|
|
|
}
|
|
|
|
using DBImpl::Flush;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Flush(const FlushOptions& /*options*/,
|
|
|
|
ColumnFamilyHandle* /*column_family*/) override {
|
2014-09-25 18:14:01 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
2020-12-22 22:52:29 +00:00
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
Status SyncWAL() override {
|
2020-12-22 22:52:29 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
|
|
|
|
2017-01-19 23:43:51 +00:00
|
|
|
using DB::IngestExternalFile;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status IngestExternalFile(
|
2018-03-05 21:08:17 +00:00
|
|
|
ColumnFamilyHandle* /*column_family*/,
|
|
|
|
const std::vector<std::string>& /*external_files*/,
|
|
|
|
const IngestExternalFileOptions& /*ingestion_options*/) override {
|
2017-01-19 23:43:51 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
2023-06-15 19:25:04 +00:00
|
|
|
|
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 19:22:21 +00:00
|
|
|
using DB::CreateColumnFamilyWithImport;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status CreateColumnFamilyWithImport(
|
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 19:22:21 +00:00
|
|
|
const ColumnFamilyOptions& /*options*/,
|
|
|
|
const std::string& /*column_family_name*/,
|
|
|
|
const ImportColumnFamilyOptions& /*import_options*/,
|
2023-06-15 19:25:04 +00:00
|
|
|
const std::vector<const ExportImportFilesMetaData*>& /*metadatas*/,
|
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 19:22:21 +00:00
|
|
|
ColumnFamilyHandle** /*handle*/) override {
|
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
2014-09-25 18:14:01 +00:00
|
|
|
|
2023-05-18 20:25:01 +00:00
|
|
|
using DB::ClipColumnFamily;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status ClipColumnFamily(ColumnFamilyHandle* /*column_family*/,
|
|
|
|
const Slice& /*begin*/,
|
|
|
|
const Slice& /*end*/) override {
|
2023-05-18 20:25:01 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
|
|
|
|
2022-08-29 20:36:23 +00:00
|
|
|
// FIXME: some missing overrides for more "write" functions
|
|
|
|
// Share with DBImplReadOnly?
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Status FlushForGetLiveFiles() override {
|
|
|
|
// No-op for read-only DB
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2014-09-25 18:14:01 +00:00
|
|
|
private:
|
|
|
|
friend class DB;
|
2014-09-25 20:34:51 +00:00
|
|
|
inline size_t FindFile(const Slice& key);
|
2014-09-25 18:14:01 +00:00
|
|
|
Status Init(const Options& options);
|
|
|
|
|
|
|
|
ColumnFamilyData* cfd_;
|
|
|
|
Version* version_;
|
|
|
|
const Comparator* user_comparator_;
|
2014-10-28 17:03:13 +00:00
|
|
|
LevelFilesBrief files_;
|
2014-09-25 18:14:01 +00:00
|
|
|
};
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|