1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
15 #include "db/log_writer.h"
22 inline bool HaveSomethingToDelete() const {
23 return full_scan_candidate_files
.size() || sst_delete_files
.size() ||
24 log_delete_files
.size() || manifest_delete_files
.size() ||
25 new_superversion
!= nullptr || superversions_to_free
.size() > 0 ||
26 memtables_to_free
.size() > 0 || logs_to_free
.size() > 0;
29 // Structure to store information for candidate files to delete.
30 struct CandidateFileInfo
{
31 std::string file_name
;
33 CandidateFileInfo(std::string name
, uint32_t path
)
34 : file_name(std::move(name
)), path_id(path
) {}
35 bool operator==(const CandidateFileInfo
& other
) const {
36 return file_name
== other
.file_name
&& path_id
== other
.path_id
;
43 // a list of all files that we'll consider deleting
44 // (every once in a while this is filled up with all files
45 // in the DB directory)
46 // (filled only if we're doing full scan)
47 std::vector
<CandidateFileInfo
> full_scan_candidate_files
;
49 // the list of all live sst files that cannot be deleted
50 std::vector
<FileDescriptor
> sst_live
;
52 // a list of sst files that we need to delete
53 std::vector
<FileMetaData
*> sst_delete_files
;
55 // a list of log files that we need to delete
56 std::vector
<uint64_t> log_delete_files
;
58 // a list of log files that we need to preserve during full purge since they
59 // will be reused later
60 std::vector
<uint64_t> log_recycle_files
;
62 // a list of manifest files that we need to delete
63 std::vector
<std::string
> manifest_delete_files
;
65 // a list of memtables to be free
66 autovector
<MemTable
*> memtables_to_free
;
68 autovector
<SuperVersion
*> superversions_to_free
;
70 autovector
<log::Writer
*> logs_to_free
;
72 SuperVersion
* new_superversion
; // if nullptr no new superversion
74 // the current manifest_file_number, log_number and prev_log_number
75 // that corresponds to the set of files in 'live'.
76 uint64_t manifest_file_number
;
77 uint64_t pending_manifest_file_number
;
79 uint64_t prev_log_number
;
81 uint64_t min_pending_output
= 0;
82 uint64_t prev_total_log_size
= 0;
83 size_t num_alive_log_files
= 0;
84 uint64_t size_log_to_delete
= 0;
86 explicit JobContext(int _job_id
, bool create_superversion
= false) {
88 manifest_file_number
= 0;
89 pending_manifest_file_number
= 0;
92 new_superversion
= create_superversion
? new SuperVersion() : nullptr;
95 // For non-empty JobContext Clean() has to be called at least once before
96 // before destruction (see asserts in ~JobContext()). Should be called with
97 // unlocked DB mutex. Destructor doesn't call Clean() to avoid accidentally
98 // doing potentially slow Clean() with locked DB mutex.
100 // free pending memtables
101 for (auto m
: memtables_to_free
) {
104 // free superversions
105 for (auto s
: superversions_to_free
) {
108 for (auto l
: logs_to_free
) {
111 // if new_superversion was not used, it will be non-nullptr and needs
113 delete new_superversion
;
115 memtables_to_free
.clear();
116 superversions_to_free
.clear();
117 logs_to_free
.clear();
118 new_superversion
= nullptr;
122 assert(memtables_to_free
.size() == 0);
123 assert(superversions_to_free
.size() == 0);
124 assert(new_superversion
== nullptr);
125 assert(logs_to_free
.size() == 0);
129 } // namespace rocksdb