1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
13 #include "db/db_impl/db_impl.h"
14 #include "db/job_context.h"
15 #include "db/version_set.h"
16 #include "file/file_util.h"
17 #include "file/filename.h"
18 #include "port/port.h"
19 #include "rocksdb/db.h"
20 #include "rocksdb/env.h"
21 #include "test_util/sync_point.h"
22 #include "util/mutexlock.h"
24 namespace ROCKSDB_NAMESPACE
{
26 Status
DBImpl::GetLiveFiles(std::vector
<std::string
>& ret
,
27 uint64_t* manifest_file_size
,
28 bool flush_memtable
) {
29 *manifest_file_size
= 0;
34 // flush all dirty data to disk.
36 if (immutable_db_options_
.atomic_flush
) {
37 autovector
<ColumnFamilyData
*> cfds
;
38 SelectColumnFamiliesForAtomicFlush(&cfds
);
40 status
= AtomicFlushMemTables(cfds
, FlushOptions(),
41 FlushReason::kGetLiveFiles
);
42 if (status
.IsColumnFamilyDropped()) {
43 status
= Status::OK();
47 for (auto cfd
: *versions_
->GetColumnFamilySet()) {
48 if (cfd
->IsDropped()) {
53 status
= FlushMemTable(cfd
, FlushOptions(), FlushReason::kGetLiveFiles
);
54 TEST_SYNC_POINT("DBImpl::GetLiveFiles:1");
55 TEST_SYNC_POINT("DBImpl::GetLiveFiles:2");
57 cfd
->UnrefAndTryDelete();
58 if (!status
.ok() && !status
.IsColumnFamilyDropped()) {
60 } else if (status
.IsColumnFamilyDropped()) {
61 status
= Status::OK();
65 versions_
->GetColumnFamilySet()->FreeDeadColumnFamilies();
69 ROCKS_LOG_ERROR(immutable_db_options_
.info_log
, "Cannot Flush data %s\n",
70 status
.ToString().c_str());
75 // Make a set of all of the live table and blob files
76 std::vector
<uint64_t> live_table_files
;
77 std::vector
<uint64_t> live_blob_files
;
78 for (auto cfd
: *versions_
->GetColumnFamilySet()) {
79 if (cfd
->IsDropped()) {
82 cfd
->current()->AddLiveFiles(&live_table_files
, &live_blob_files
);
86 ret
.reserve(live_table_files
.size() + live_blob_files
.size() +
87 3); // for CURRENT + MANIFEST + OPTIONS
89 // create names of the live files. The names are not absolute
90 // paths, instead they are relative to dbname_;
91 for (const auto& table_file_number
: live_table_files
) {
92 ret
.emplace_back(MakeTableFileName("", table_file_number
));
95 for (const auto& blob_file_number
: live_blob_files
) {
96 ret
.emplace_back(BlobFileName("", blob_file_number
));
99 ret
.emplace_back(CurrentFileName(""));
100 ret
.emplace_back(DescriptorFileName("", versions_
->manifest_file_number()));
101 ret
.emplace_back(OptionsFileName("", versions_
->options_file_number()));
103 // find length of manifest file while holding the mutex lock
104 *manifest_file_size
= versions_
->manifest_file_size();
110 Status
DBImpl::GetSortedWalFiles(VectorLogPtr
& files
) {
112 // If caller disabled deletions, this function should return files that are
113 // guaranteed not to be deleted until deletions are re-enabled. We need to
114 // wait for pending purges to finish since WalManager doesn't know which
115 // files are going to be purged. Additional purges won't be scheduled as
116 // long as deletions are disabled (so the below loop must terminate).
117 InstrumentedMutexLock
l(&mutex_
);
118 while (disable_delete_obsolete_files_
> 0 &&
119 (pending_purge_obsolete_files_
> 0 || bg_purge_scheduled_
> 0)) {
123 return wal_manager_
.GetSortedWalFiles(files
);
126 Status
DBImpl::GetCurrentWalFile(std::unique_ptr
<LogFile
>* current_log_file
) {
127 uint64_t current_logfile_number
;
129 InstrumentedMutexLock
l(&mutex_
);
130 current_logfile_number
= logfile_number_
;
133 return wal_manager_
.GetLiveWalFile(current_logfile_number
, current_log_file
);
135 } // namespace ROCKSDB_NAMESPACE
137 #endif // ROCKSDB_LITE