2016-10-21 02:05:32 +02:00
|
|
|
// Copyright (c) 2011-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).
|
2016-10-21 02:05:32 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_set>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "db/column_family.h"
|
|
|
|
#include "db/internal_stats.h"
|
|
|
|
#include "db/snapshot_impl.h"
|
2020-08-13 02:28:10 +02:00
|
|
|
#include "env/file_system_tracer.h"
|
2019-09-13 23:48:18 +02:00
|
|
|
#include "logging/event_logger.h"
|
2017-04-06 04:02:00 +02:00
|
|
|
#include "options/db_options.h"
|
2016-10-21 02:05:32 +02:00
|
|
|
#include "rocksdb/db.h"
|
2021-01-26 07:07:26 +01:00
|
|
|
#include "rocksdb/file_system.h"
|
2016-10-21 02:05:32 +02:00
|
|
|
#include "rocksdb/sst_file_writer.h"
|
|
|
|
#include "util/autovector.h"
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2016-10-21 02:05:32 +02:00
|
|
|
|
2019-06-21 19:12:29 +02:00
|
|
|
class Directories;
|
2021-01-26 07:07:26 +01:00
|
|
|
class SystemClock;
|
2019-06-21 19:12:29 +02:00
|
|
|
|
2016-10-21 02:05:32 +02:00
|
|
|
struct IngestedFileInfo {
|
|
|
|
// External file path
|
|
|
|
std::string external_file_path;
|
2019-08-15 05:58:59 +02:00
|
|
|
// Smallest internal key in external file
|
|
|
|
InternalKey smallest_internal_key;
|
|
|
|
// Largest internal key in external file
|
|
|
|
InternalKey largest_internal_key;
|
2016-10-21 02:05:32 +02:00
|
|
|
// Sequence number for keys in external file
|
|
|
|
SequenceNumber original_seqno;
|
|
|
|
// Offset of the global sequence number field in the file, will
|
|
|
|
// be zero if version is 1 (global seqno is not supported)
|
|
|
|
size_t global_seqno_offset;
|
|
|
|
// External file size
|
|
|
|
uint64_t file_size;
|
|
|
|
// total number of keys in external file
|
|
|
|
uint64_t num_entries;
|
2018-07-14 07:40:23 +02:00
|
|
|
// total number of range deletions in external file
|
|
|
|
uint64_t num_range_deletions;
|
2016-12-05 23:16:23 +01:00
|
|
|
// Id of column family this file shoule be ingested into
|
|
|
|
uint32_t cf_id;
|
2016-12-06 22:56:17 +01:00
|
|
|
// TableProperties read from external file
|
|
|
|
TableProperties table_properties;
|
2016-10-21 02:05:32 +02:00
|
|
|
// Version of external file
|
|
|
|
int version;
|
|
|
|
|
|
|
|
// FileDescriptor for the file inside the DB
|
|
|
|
FileDescriptor fd;
|
|
|
|
// file path that we picked for file inside the DB
|
2018-04-13 19:47:54 +02:00
|
|
|
std::string internal_file_path;
|
2016-10-21 02:05:32 +02:00
|
|
|
// Global sequence number that we picked for the file inside the DB
|
|
|
|
SequenceNumber assigned_seqno = 0;
|
|
|
|
// Level inside the DB we picked for the external file.
|
|
|
|
int picked_level = 0;
|
2018-04-13 19:47:54 +02:00
|
|
|
// Whether to copy or link the external sst file. copy_file will be set to
|
|
|
|
// false if ingestion_options.move_files is true and underlying FS
|
2018-04-16 23:18:51 +02:00
|
|
|
// supports link operation. Need to provide a default value to make the
|
|
|
|
// undefined-behavior sanity check of llvm happy. Since
|
|
|
|
// ingestion_options.move_files is false by default, thus copy_file is true
|
|
|
|
// by default.
|
|
|
|
bool copy_file = true;
|
Ingest SST files with checksum information (#6891)
Summary:
Application can ingest SST files with file checksum information, such that during ingestion, DB is able to check data integrity and identify of the SST file. The PR introduces generate_and_verify_file_checksum to IngestExternalFileOption to control if the ingested checksum information should be verified with the generated checksum.
1. If generate_and_verify_file_checksum options is *FALSE*: *1)* if DB does not enable SST file checksum, the checksum information ingested will be ignored; *2)* if DB enables the SST file checksum and the checksum function name matches the checksum function name in DB, we trust the ingested checksum, store it in Manifest. If the checksum function name does not match, we treat that as an error and fail the IngestExternalFile() call.
2. If generate_and_verify_file_checksum options is *TRUE*: *1)* if DB does not enable SST file checksum, the checksum information ingested will be ignored; *2)* if DB enable the SST file checksum, we will use the checksum generator from DB to calculate the checksum for each ingested SST files after they are copied or moved. Then, compare the checksum results with the ingested checksum information: _A)_ if the checksum function name does not match, _verification always report true_ and we store the DB generated checksum information in Manifest. _B)_ if the checksum function name mach, and checksum match, ingestion continues and stores the checksum information in the Manifest. Otherwise, terminate file ingestion and report file corruption.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6891
Test Plan: added unit test, pass make asan_check
Reviewed By: pdillinger
Differential Revision: D21935988
Pulled By: zhichao-cao
fbshipit-source-id: 7b55f486632db467e76d72602218d0658aa7f6ed
2020-06-11 23:25:01 +02:00
|
|
|
// The checksum of ingested file
|
|
|
|
std::string file_checksum;
|
|
|
|
// The name of checksum function that generate the checksum
|
|
|
|
std::string file_checksum_func_name;
|
2021-10-08 19:29:06 +02:00
|
|
|
// The temperature of the file to be ingested
|
|
|
|
Temperature file_temperature = Temperature::kUnknown;
|
2016-10-21 02:05:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ExternalSstFileIngestionJob {
|
|
|
|
public:
|
|
|
|
ExternalSstFileIngestionJob(
|
2021-03-15 12:32:24 +01:00
|
|
|
VersionSet* versions, ColumnFamilyData* cfd,
|
|
|
|
const ImmutableDBOptions& db_options, const EnvOptions& env_options,
|
|
|
|
SnapshotList* db_snapshots,
|
2019-06-21 19:12:29 +02:00
|
|
|
const IngestExternalFileOptions& ingestion_options,
|
2020-08-13 02:28:10 +02:00
|
|
|
Directories* directories, EventLogger* event_logger,
|
|
|
|
const std::shared_ptr<IOTracer>& io_tracer)
|
2021-03-15 12:32:24 +01:00
|
|
|
: clock_(db_options.clock),
|
2020-08-13 02:28:10 +02:00
|
|
|
fs_(db_options.fs, io_tracer),
|
2016-10-21 02:05:32 +02:00
|
|
|
versions_(versions),
|
|
|
|
cfd_(cfd),
|
|
|
|
db_options_(db_options),
|
|
|
|
env_options_(env_options),
|
|
|
|
db_snapshots_(db_snapshots),
|
|
|
|
ingestion_options_(ingestion_options),
|
2019-06-21 19:12:29 +02:00
|
|
|
directories_(directories),
|
2019-09-13 23:48:18 +02:00
|
|
|
event_logger_(event_logger),
|
2021-01-26 07:07:26 +01:00
|
|
|
job_start_time_(clock_->NowMicros()),
|
2020-08-19 01:19:22 +02:00
|
|
|
consumed_seqno_count_(0),
|
|
|
|
io_tracer_(io_tracer) {
|
2019-06-21 19:12:29 +02:00
|
|
|
assert(directories != nullptr);
|
|
|
|
}
|
2016-10-21 02:05:32 +02:00
|
|
|
|
|
|
|
// Prepare the job by copying external files into the DB.
|
2018-05-21 23:33:55 +02:00
|
|
|
Status Prepare(const std::vector<std::string>& external_files_paths,
|
Ingest SST files with checksum information (#6891)
Summary:
Application can ingest SST files with file checksum information, such that during ingestion, DB is able to check data integrity and identify of the SST file. The PR introduces generate_and_verify_file_checksum to IngestExternalFileOption to control if the ingested checksum information should be verified with the generated checksum.
1. If generate_and_verify_file_checksum options is *FALSE*: *1)* if DB does not enable SST file checksum, the checksum information ingested will be ignored; *2)* if DB enables the SST file checksum and the checksum function name matches the checksum function name in DB, we trust the ingested checksum, store it in Manifest. If the checksum function name does not match, we treat that as an error and fail the IngestExternalFile() call.
2. If generate_and_verify_file_checksum options is *TRUE*: *1)* if DB does not enable SST file checksum, the checksum information ingested will be ignored; *2)* if DB enable the SST file checksum, we will use the checksum generator from DB to calculate the checksum for each ingested SST files after they are copied or moved. Then, compare the checksum results with the ingested checksum information: _A)_ if the checksum function name does not match, _verification always report true_ and we store the DB generated checksum information in Manifest. _B)_ if the checksum function name mach, and checksum match, ingestion continues and stores the checksum information in the Manifest. Otherwise, terminate file ingestion and report file corruption.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6891
Test Plan: added unit test, pass make asan_check
Reviewed By: pdillinger
Differential Revision: D21935988
Pulled By: zhichao-cao
fbshipit-source-id: 7b55f486632db467e76d72602218d0658aa7f6ed
2020-06-11 23:25:01 +02:00
|
|
|
const std::vector<std::string>& files_checksums,
|
|
|
|
const std::vector<std::string>& files_checksum_func_names,
|
2021-10-08 19:29:06 +02:00
|
|
|
const Temperature& file_temperature, uint64_t next_file_number,
|
|
|
|
SuperVersion* sv);
|
2016-10-21 02:05:32 +02:00
|
|
|
|
|
|
|
// Check if we need to flush the memtable before running the ingestion job
|
|
|
|
// This will be true if the files we are ingesting are overlapping with any
|
|
|
|
// key range in the memtable.
|
2018-02-28 02:08:34 +01:00
|
|
|
//
|
|
|
|
// @param super_version A referenced SuperVersion that will be held for the
|
|
|
|
// duration of this function.
|
|
|
|
//
|
|
|
|
// Thread-safe
|
|
|
|
Status NeedsFlush(bool* flush_needed, SuperVersion* super_version);
|
2016-10-21 02:05:32 +02:00
|
|
|
|
|
|
|
// Will execute the ingestion job and prepare edit() to be applied.
|
|
|
|
// REQUIRES: Mutex held
|
|
|
|
Status Run();
|
|
|
|
|
|
|
|
// Update column family stats.
|
|
|
|
// REQUIRES: Mutex held
|
|
|
|
void UpdateStats();
|
|
|
|
|
2017-06-05 20:23:31 +02:00
|
|
|
// Cleanup after successful/failed job
|
2016-10-21 02:05:32 +02:00
|
|
|
void Cleanup(const Status& status);
|
|
|
|
|
|
|
|
VersionEdit* edit() { return &edit_; }
|
|
|
|
|
2016-12-06 22:56:17 +01:00
|
|
|
const autovector<IngestedFileInfo>& files_to_ingest() const {
|
|
|
|
return files_to_ingest_;
|
|
|
|
}
|
|
|
|
|
2019-09-13 23:48:18 +02:00
|
|
|
// How many sequence numbers did we consume as part of the ingest job?
|
|
|
|
int ConsumedSequenceNumbersCount() const { return consumed_seqno_count_; }
|
2019-02-13 04:07:25 +01:00
|
|
|
|
2016-10-21 02:05:32 +02:00
|
|
|
private:
|
|
|
|
// Open the external file and populate `file_to_ingest` with all the
|
|
|
|
// external information we need to ingest this file.
|
|
|
|
Status GetIngestedFileInfo(const std::string& external_file,
|
2018-05-21 23:33:55 +02:00
|
|
|
IngestedFileInfo* file_to_ingest,
|
|
|
|
SuperVersion* sv);
|
2016-10-21 02:05:32 +02:00
|
|
|
|
2021-10-13 05:38:36 +02:00
|
|
|
// Assign `file_to_ingest` the appropriate sequence number and the lowest
|
2017-04-26 22:28:39 +02:00
|
|
|
// possible level that it can be ingested to according to compaction_style.
|
2016-10-21 02:05:32 +02:00
|
|
|
// REQUIRES: Mutex held
|
2017-04-26 22:28:39 +02:00
|
|
|
Status AssignLevelAndSeqnoForIngestedFile(SuperVersion* sv,
|
|
|
|
bool force_global_seqno,
|
|
|
|
CompactionStyle compaction_style,
|
2019-09-13 23:48:18 +02:00
|
|
|
SequenceNumber last_seqno,
|
2017-04-26 22:28:39 +02:00
|
|
|
IngestedFileInfo* file_to_ingest,
|
|
|
|
SequenceNumber* assigned_seqno);
|
2016-10-21 02:05:32 +02:00
|
|
|
|
2017-05-17 20:32:26 +02:00
|
|
|
// File that we want to ingest behind always goes to the lowest level;
|
|
|
|
// we just check that it fits in the level, that DB allows ingest_behind,
|
|
|
|
// and that we don't have 0 seqnums at the upper levels.
|
|
|
|
// REQUIRES: Mutex held
|
|
|
|
Status CheckLevelForIngestedBehindFile(IngestedFileInfo* file_to_ingest);
|
|
|
|
|
2016-10-21 02:05:32 +02:00
|
|
|
// Set the file global sequence number to `seqno`
|
|
|
|
Status AssignGlobalSeqnoForIngestedFile(IngestedFileInfo* file_to_ingest,
|
|
|
|
SequenceNumber seqno);
|
Ingest SST files with checksum information (#6891)
Summary:
Application can ingest SST files with file checksum information, such that during ingestion, DB is able to check data integrity and identify of the SST file. The PR introduces generate_and_verify_file_checksum to IngestExternalFileOption to control if the ingested checksum information should be verified with the generated checksum.
1. If generate_and_verify_file_checksum options is *FALSE*: *1)* if DB does not enable SST file checksum, the checksum information ingested will be ignored; *2)* if DB enables the SST file checksum and the checksum function name matches the checksum function name in DB, we trust the ingested checksum, store it in Manifest. If the checksum function name does not match, we treat that as an error and fail the IngestExternalFile() call.
2. If generate_and_verify_file_checksum options is *TRUE*: *1)* if DB does not enable SST file checksum, the checksum information ingested will be ignored; *2)* if DB enable the SST file checksum, we will use the checksum generator from DB to calculate the checksum for each ingested SST files after they are copied or moved. Then, compare the checksum results with the ingested checksum information: _A)_ if the checksum function name does not match, _verification always report true_ and we store the DB generated checksum information in Manifest. _B)_ if the checksum function name mach, and checksum match, ingestion continues and stores the checksum information in the Manifest. Otherwise, terminate file ingestion and report file corruption.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6891
Test Plan: added unit test, pass make asan_check
Reviewed By: pdillinger
Differential Revision: D21935988
Pulled By: zhichao-cao
fbshipit-source-id: 7b55f486632db467e76d72602218d0658aa7f6ed
2020-06-11 23:25:01 +02:00
|
|
|
// Generate the file checksum and store in the IngestedFileInfo
|
|
|
|
IOStatus GenerateChecksumForIngestedFile(IngestedFileInfo* file_to_ingest);
|
2016-10-21 02:05:32 +02:00
|
|
|
|
|
|
|
// Check if `file_to_ingest` can fit in level `level`
|
|
|
|
// REQUIRES: Mutex held
|
|
|
|
bool IngestedFileFitInLevel(const IngestedFileInfo* file_to_ingest,
|
|
|
|
int level);
|
|
|
|
|
2019-06-21 19:12:29 +02:00
|
|
|
// Helper method to sync given file.
|
|
|
|
template <typename TWritableFile>
|
|
|
|
Status SyncIngestedFile(TWritableFile* file);
|
|
|
|
|
2021-03-15 12:32:24 +01:00
|
|
|
SystemClock* clock_;
|
2020-08-13 02:28:10 +02:00
|
|
|
FileSystemPtr fs_;
|
2016-10-21 02:05:32 +02:00
|
|
|
VersionSet* versions_;
|
|
|
|
ColumnFamilyData* cfd_;
|
|
|
|
const ImmutableDBOptions& db_options_;
|
|
|
|
const EnvOptions& env_options_;
|
|
|
|
SnapshotList* db_snapshots_;
|
|
|
|
autovector<IngestedFileInfo> files_to_ingest_;
|
|
|
|
const IngestExternalFileOptions& ingestion_options_;
|
2019-06-21 19:12:29 +02:00
|
|
|
Directories* directories_;
|
2019-09-13 23:48:18 +02:00
|
|
|
EventLogger* event_logger_;
|
2016-10-21 02:05:32 +02:00
|
|
|
VersionEdit edit_;
|
|
|
|
uint64_t job_start_time_;
|
2019-09-13 23:48:18 +02:00
|
|
|
int consumed_seqno_count_;
|
|
|
|
// Set in ExternalSstFileIngestionJob::Prepare(), if true all files are
|
|
|
|
// ingested in L0
|
|
|
|
bool files_overlap_{false};
|
Ingest SST files with checksum information (#6891)
Summary:
Application can ingest SST files with file checksum information, such that during ingestion, DB is able to check data integrity and identify of the SST file. The PR introduces generate_and_verify_file_checksum to IngestExternalFileOption to control if the ingested checksum information should be verified with the generated checksum.
1. If generate_and_verify_file_checksum options is *FALSE*: *1)* if DB does not enable SST file checksum, the checksum information ingested will be ignored; *2)* if DB enables the SST file checksum and the checksum function name matches the checksum function name in DB, we trust the ingested checksum, store it in Manifest. If the checksum function name does not match, we treat that as an error and fail the IngestExternalFile() call.
2. If generate_and_verify_file_checksum options is *TRUE*: *1)* if DB does not enable SST file checksum, the checksum information ingested will be ignored; *2)* if DB enable the SST file checksum, we will use the checksum generator from DB to calculate the checksum for each ingested SST files after they are copied or moved. Then, compare the checksum results with the ingested checksum information: _A)_ if the checksum function name does not match, _verification always report true_ and we store the DB generated checksum information in Manifest. _B)_ if the checksum function name mach, and checksum match, ingestion continues and stores the checksum information in the Manifest. Otherwise, terminate file ingestion and report file corruption.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6891
Test Plan: added unit test, pass make asan_check
Reviewed By: pdillinger
Differential Revision: D21935988
Pulled By: zhichao-cao
fbshipit-source-id: 7b55f486632db467e76d72602218d0658aa7f6ed
2020-06-11 23:25:01 +02:00
|
|
|
// Set in ExternalSstFileIngestionJob::Prepare(), if true and DB
|
|
|
|
// file_checksum_gen_factory is set, DB will generate checksum each file.
|
|
|
|
bool need_generate_file_checksum_{true};
|
2020-08-19 01:19:22 +02:00
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
2016-10-21 02:05:32 +02:00
|
|
|
};
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|