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
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
#include <string>
|
2019-05-31 22:21:36 +00:00
|
|
|
#include <vector>
|
|
|
|
#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
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-09-25 18:14:01 +00:00
|
|
|
virtual ~CompactedDBImpl();
|
|
|
|
|
|
|
|
static Status Open(const Options& options, const std::string& dbname,
|
|
|
|
DB** dbptr);
|
|
|
|
|
|
|
|
// Implementations of the DB interface
|
|
|
|
using DB::Get;
|
|
|
|
virtual Status Get(const ReadOptions& options,
|
|
|
|
ColumnFamilyHandle* column_family, const Slice& key,
|
2017-03-13 18:44:50 +00:00
|
|
|
PinnableSlice* value) override;
|
2014-09-25 20:34:51 +00:00
|
|
|
using DB::MultiGet;
|
|
|
|
virtual std::vector<Status> MultiGet(
|
|
|
|
const ReadOptions& options,
|
|
|
|
const std::vector<ColumnFamilyHandle*>&,
|
|
|
|
const std::vector<Slice>& keys, std::vector<std::string>* values)
|
|
|
|
override;
|
2014-09-25 18:14:01 +00:00
|
|
|
|
|
|
|
using DBImpl::Put;
|
2018-03-05 21:08:17 +00:00
|
|
|
virtual 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.");
|
|
|
|
}
|
|
|
|
using DBImpl::Merge;
|
2018-03-05 21:08:17 +00:00
|
|
|
virtual 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.");
|
|
|
|
}
|
|
|
|
using DBImpl::Delete;
|
2018-03-05 21:08:17 +00:00
|
|
|
virtual 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.");
|
|
|
|
}
|
2018-03-05 21:08:17 +00:00
|
|
|
virtual 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;
|
2018-03-05 21:08:17 +00:00
|
|
|
virtual 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.");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Status DisableFileDeletions() override {
|
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
2018-03-05 21:08:17 +00:00
|
|
|
virtual Status EnableFileDeletions(bool /*force*/) override {
|
2014-09-25 18:14:01 +00:00
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
2018-12-08 01:03:49 +00:00
|
|
|
virtual Status GetLiveFiles(std::vector<std::string>& ret,
|
|
|
|
uint64_t* manifest_file_size,
|
|
|
|
bool /*flush_memtable*/) override {
|
|
|
|
return DBImpl::GetLiveFiles(ret, manifest_file_size,
|
|
|
|
false /* flush_memtable */);
|
2014-09-25 18:14:01 +00:00
|
|
|
}
|
|
|
|
using DBImpl::Flush;
|
2018-03-05 21:08:17 +00:00
|
|
|
virtual 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
|
|
|
|
|
|
|
virtual Status SyncWAL() override {
|
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
|
|
|
|
2017-01-19 23:43:51 +00:00
|
|
|
using DB::IngestExternalFile;
|
|
|
|
virtual 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.");
|
|
|
|
}
|
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;
|
|
|
|
virtual Status CreateColumnFamilyWithImport(
|
|
|
|
const ColumnFamilyOptions& /*options*/,
|
|
|
|
const std::string& /*column_family_name*/,
|
|
|
|
const ImportColumnFamilyOptions& /*import_options*/,
|
|
|
|
const ExportImportFilesMetaData& /*metadata*/,
|
|
|
|
ColumnFamilyHandle** /*handle*/) override {
|
|
|
|
return Status::NotSupported("Not supported in compacted db mode.");
|
|
|
|
}
|
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
|
2014-09-25 18:14:01 +00:00
|
|
|
#endif // ROCKSDB_LITE
|