]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/db/db_filesnapshot.cc
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / db / db_filesnapshot.cc
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
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).
7c673cae 5//
7c673cae
FG
6
7#ifndef ROCKSDB_LITE
8
9#ifndef __STDC_FORMAT_MACROS
10#define __STDC_FORMAT_MACROS
11#endif
12
13#include <inttypes.h>
14#include <stdint.h>
15#include <algorithm>
16#include <string>
17#include "db/db_impl.h"
18#include "db/job_context.h"
19#include "db/version_set.h"
20#include "port/port.h"
21#include "rocksdb/db.h"
22#include "rocksdb/env.h"
23#include "util/file_util.h"
24#include "util/filename.h"
25#include "util/mutexlock.h"
26#include "util/sync_point.h"
27
28namespace rocksdb {
29
30Status DBImpl::DisableFileDeletions() {
31 InstrumentedMutexLock l(&mutex_);
32 ++disable_delete_obsolete_files_;
33 if (disable_delete_obsolete_files_ == 1) {
34 ROCKS_LOG_INFO(immutable_db_options_.info_log, "File Deletions Disabled");
35 } else {
36 ROCKS_LOG_WARN(immutable_db_options_.info_log,
37 "File Deletions Disabled, but already disabled. Counter: %d",
38 disable_delete_obsolete_files_);
39 }
40 return Status::OK();
41}
42
43Status DBImpl::EnableFileDeletions(bool force) {
44 // Job id == 0 means that this is not our background process, but rather
45 // user thread
46 JobContext job_context(0);
494da23a 47 bool file_deletion_enabled = false;
7c673cae
FG
48 {
49 InstrumentedMutexLock l(&mutex_);
50 if (force) {
51 // if force, we need to enable file deletions right away
52 disable_delete_obsolete_files_ = 0;
53 } else if (disable_delete_obsolete_files_ > 0) {
54 --disable_delete_obsolete_files_;
55 }
56 if (disable_delete_obsolete_files_ == 0) {
494da23a 57 file_deletion_enabled = true;
7c673cae 58 FindObsoleteFiles(&job_context, true);
11fdf7f2 59 bg_cv_.SignalAll();
7c673cae
FG
60 }
61 }
494da23a
TL
62 if (file_deletion_enabled) {
63 ROCKS_LOG_INFO(immutable_db_options_.info_log, "File Deletions Enabled");
7c673cae 64 PurgeObsoleteFiles(job_context);
494da23a
TL
65 } else {
66 ROCKS_LOG_WARN(immutable_db_options_.info_log,
67 "File Deletions Enable, but not really enabled. Counter: %d",
68 disable_delete_obsolete_files_);
7c673cae
FG
69 }
70 job_context.Clean();
71 LogFlush(immutable_db_options_.info_log);
72 return Status::OK();
73}
74
75int DBImpl::IsFileDeletionsEnabled() const {
11fdf7f2 76 return !disable_delete_obsolete_files_;
7c673cae
FG
77}
78
79Status DBImpl::GetLiveFiles(std::vector<std::string>& ret,
80 uint64_t* manifest_file_size,
81 bool flush_memtable) {
82 *manifest_file_size = 0;
83
84 mutex_.Lock();
85
86 if (flush_memtable) {
87 // flush all dirty data to disk.
88 Status status;
494da23a
TL
89 if (immutable_db_options_.atomic_flush) {
90 autovector<ColumnFamilyData*> cfds;
91 SelectColumnFamiliesForAtomicFlush(&cfds);
7c673cae 92 mutex_.Unlock();
494da23a
TL
93 status = AtomicFlushMemTables(cfds, FlushOptions(),
94 FlushReason::kGetLiveFiles);
7c673cae 95 mutex_.Lock();
494da23a
TL
96 } else {
97 for (auto cfd : *versions_->GetColumnFamilySet()) {
98 if (cfd->IsDropped()) {
99 continue;
100 }
101 cfd->Ref();
102 mutex_.Unlock();
103 status = FlushMemTable(cfd, FlushOptions(), FlushReason::kGetLiveFiles);
104 TEST_SYNC_POINT("DBImpl::GetLiveFiles:1");
105 TEST_SYNC_POINT("DBImpl::GetLiveFiles:2");
106 mutex_.Lock();
107 cfd->Unref();
108 if (!status.ok()) {
109 break;
110 }
7c673cae
FG
111 }
112 }
113 versions_->GetColumnFamilySet()->FreeDeadColumnFamilies();
114
115 if (!status.ok()) {
116 mutex_.Unlock();
117 ROCKS_LOG_ERROR(immutable_db_options_.info_log, "Cannot Flush data %s\n",
118 status.ToString().c_str());
119 return status;
120 }
121 }
122
123 // Make a set of all of the live *.sst files
124 std::vector<FileDescriptor> live;
125 for (auto cfd : *versions_->GetColumnFamilySet()) {
126 if (cfd->IsDropped()) {
127 continue;
128 }
129 cfd->current()->AddLiveFiles(&live);
130 }
131
132 ret.clear();
133 ret.reserve(live.size() + 3); // *.sst + CURRENT + MANIFEST + OPTIONS
134
135 // create names of the live files. The names are not absolute
136 // paths, instead they are relative to dbname_;
494da23a 137 for (const auto& live_file : live) {
7c673cae
FG
138 ret.push_back(MakeTableFileName("", live_file.GetNumber()));
139 }
140
141 ret.push_back(CurrentFileName(""));
142 ret.push_back(DescriptorFileName("", versions_->manifest_file_number()));
143 ret.push_back(OptionsFileName("", versions_->options_file_number()));
144
145 // find length of manifest file while holding the mutex lock
146 *manifest_file_size = versions_->manifest_file_size();
147
148 mutex_.Unlock();
149 return Status::OK();
150}
151
152Status DBImpl::GetSortedWalFiles(VectorLogPtr& files) {
11fdf7f2
TL
153 {
154 // If caller disabled deletions, this function should return files that are
155 // guaranteed not to be deleted until deletions are re-enabled. We need to
156 // wait for pending purges to finish since WalManager doesn't know which
157 // files are going to be purged. Additional purges won't be scheduled as
158 // long as deletions are disabled (so the below loop must terminate).
159 InstrumentedMutexLock l(&mutex_);
160 while (disable_delete_obsolete_files_ > 0 &&
161 pending_purge_obsolete_files_ > 0) {
162 bg_cv_.Wait();
163 }
164 }
7c673cae
FG
165 return wal_manager_.GetSortedWalFiles(files);
166}
167
168}
169
170#endif // ROCKSDB_LITE