/src/rocksdb/db/import_column_family_job.h
Line | Count | Source |
1 | | // Copyright (c) Meta Platforms, Inc. and affiliates. |
2 | | // |
3 | | // This source code is licensed under both the GPLv2 (found in the |
4 | | // COPYING file in the root directory) and Apache 2.0 License |
5 | | // (found in the LICENSE.Apache file in the root directory). |
6 | | |
7 | | #pragma once |
8 | | #include <string> |
9 | | #include <unordered_set> |
10 | | #include <vector> |
11 | | |
12 | | #include "db/column_family.h" |
13 | | #include "db/external_sst_file_ingestion_job.h" |
14 | | #include "db/snapshot_impl.h" |
15 | | #include "options/db_options.h" |
16 | | #include "rocksdb/db.h" |
17 | | #include "rocksdb/metadata.h" |
18 | | #include "rocksdb/sst_file_writer.h" |
19 | | #include "util/autovector.h" |
20 | | |
21 | | namespace ROCKSDB_NAMESPACE { |
22 | | struct EnvOptions; |
23 | | class SystemClock; |
24 | | |
25 | | // Imports a set of sst files as is into a new column family. Logic is similar |
26 | | // to ExternalSstFileIngestionJob. |
27 | | class ImportColumnFamilyJob { |
28 | | // All file information of an imported CF, mainly used to |
29 | | // calculate whether there is overlap between CFs |
30 | | struct ColumnFamilyIngestFileInfo { |
31 | | // Smallest internal key in cf |
32 | | InternalKey smallest_internal_key; |
33 | | // Largest internal key in cf |
34 | | InternalKey largest_internal_key; |
35 | | }; |
36 | | |
37 | | public: |
38 | | ImportColumnFamilyJob( |
39 | | VersionSet* versions, ColumnFamilyData* cfd, |
40 | | const ImmutableDBOptions& db_options, const EnvOptions& env_options, |
41 | | const ImportColumnFamilyOptions& import_options, |
42 | | const std::vector<std::vector<LiveFileMetaData*>>& metadatas, |
43 | | const std::shared_ptr<IOTracer>& io_tracer) |
44 | 0 | : clock_(db_options.clock), |
45 | 0 | versions_(versions), |
46 | 0 | cfd_(cfd), |
47 | 0 | db_options_(db_options), |
48 | 0 | fs_(db_options_.fs, io_tracer), |
49 | 0 | env_options_(env_options), |
50 | 0 | import_options_(import_options), |
51 | 0 | metadatas_(metadatas), |
52 | 0 | io_tracer_(io_tracer) {} |
53 | | |
54 | | // Prepare the job by copying external files into the DB. |
55 | | Status Prepare(uint64_t next_file_number, SuperVersion* sv); |
56 | | |
57 | | // Will execute the import job and prepare edit() to be applied. |
58 | | // REQUIRES: Mutex held |
59 | | Status Run(); |
60 | | |
61 | | // Cleanup after successful/failed job |
62 | | void Cleanup(const Status& status); |
63 | | |
64 | 0 | VersionEdit* edit() { return &edit_; } |
65 | | |
66 | 0 | const std::vector<std::vector<IngestedFileInfo>>& files_to_import() const { |
67 | 0 | return files_to_import_; |
68 | 0 | } |
69 | | |
70 | | private: |
71 | | // Open the external file and populate `file_to_import` with all the |
72 | | // external information we need to import this file. |
73 | | Status GetIngestedFileInfo(const std::string& external_file, |
74 | | uint64_t new_file_number, SuperVersion* sv, |
75 | | const LiveFileMetaData& file_meta, |
76 | | IngestedFileInfo* file_to_import); |
77 | | |
78 | | SystemClock* clock_; |
79 | | VersionSet* versions_; |
80 | | ColumnFamilyData* cfd_; |
81 | | const ImmutableDBOptions& db_options_; |
82 | | const FileSystemPtr fs_; |
83 | | const EnvOptions& env_options_; |
84 | | std::vector<std::vector<IngestedFileInfo>> files_to_import_; |
85 | | VersionEdit edit_; |
86 | | const ImportColumnFamilyOptions& import_options_; |
87 | | const std::vector<std::vector<LiveFileMetaData*>> metadatas_; |
88 | | const std::shared_ptr<IOTracer> io_tracer_; |
89 | | }; |
90 | | |
91 | | } // namespace ROCKSDB_NAMESPACE |