]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/db_filesnapshot.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / db / db_filesnapshot.cc
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).
5 //
6
7 #ifndef ROCKSDB_LITE
8
9 #include <stdint.h>
10 #include <algorithm>
11 #include <cinttypes>
12 #include <string>
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"
23
24 namespace ROCKSDB_NAMESPACE {
25
26 Status DBImpl::GetLiveFiles(std::vector<std::string>& ret,
27 uint64_t* manifest_file_size,
28 bool flush_memtable) {
29 *manifest_file_size = 0;
30
31 mutex_.Lock();
32
33 if (flush_memtable) {
34 // flush all dirty data to disk.
35 Status status;
36 if (immutable_db_options_.atomic_flush) {
37 autovector<ColumnFamilyData*> cfds;
38 SelectColumnFamiliesForAtomicFlush(&cfds);
39 mutex_.Unlock();
40 status = AtomicFlushMemTables(cfds, FlushOptions(),
41 FlushReason::kGetLiveFiles);
42 if (status.IsColumnFamilyDropped()) {
43 status = Status::OK();
44 }
45 mutex_.Lock();
46 } else {
47 for (auto cfd : *versions_->GetColumnFamilySet()) {
48 if (cfd->IsDropped()) {
49 continue;
50 }
51 cfd->Ref();
52 mutex_.Unlock();
53 status = FlushMemTable(cfd, FlushOptions(), FlushReason::kGetLiveFiles);
54 TEST_SYNC_POINT("DBImpl::GetLiveFiles:1");
55 TEST_SYNC_POINT("DBImpl::GetLiveFiles:2");
56 mutex_.Lock();
57 cfd->UnrefAndTryDelete();
58 if (!status.ok() && !status.IsColumnFamilyDropped()) {
59 break;
60 } else if (status.IsColumnFamilyDropped()) {
61 status = Status::OK();
62 }
63 }
64 }
65 versions_->GetColumnFamilySet()->FreeDeadColumnFamilies();
66
67 if (!status.ok()) {
68 mutex_.Unlock();
69 ROCKS_LOG_ERROR(immutable_db_options_.info_log, "Cannot Flush data %s\n",
70 status.ToString().c_str());
71 return status;
72 }
73 }
74
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()) {
80 continue;
81 }
82 cfd->current()->AddLiveFiles(&live_table_files, &live_blob_files);
83 }
84
85 ret.clear();
86 ret.reserve(live_table_files.size() + live_blob_files.size() +
87 3); // for CURRENT + MANIFEST + OPTIONS
88
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));
93 }
94
95 for (const auto& blob_file_number : live_blob_files) {
96 ret.emplace_back(BlobFileName("", blob_file_number));
97 }
98
99 ret.emplace_back(CurrentFileName(""));
100 ret.emplace_back(DescriptorFileName("", versions_->manifest_file_number()));
101 ret.emplace_back(OptionsFileName("", versions_->options_file_number()));
102
103 // find length of manifest file while holding the mutex lock
104 *manifest_file_size = versions_->manifest_file_size();
105
106 mutex_.Unlock();
107 return Status::OK();
108 }
109
110 Status DBImpl::GetSortedWalFiles(VectorLogPtr& files) {
111 {
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)) {
120 bg_cv_.Wait();
121 }
122 }
123 return wal_manager_.GetSortedWalFiles(files);
124 }
125
126 Status DBImpl::GetCurrentWalFile(std::unique_ptr<LogFile>* current_log_file) {
127 uint64_t current_logfile_number;
128 {
129 InstrumentedMutexLock l(&mutex_);
130 current_logfile_number = logfile_number_;
131 }
132
133 return wal_manager_.GetLiveWalFile(current_logfile_number, current_log_file);
134 }
135 } // namespace ROCKSDB_NAMESPACE
136
137 #endif // ROCKSDB_LITE