]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/db_filesnapshot.cc
add subtree-ish sources for 12.0.3
[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 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.
5 //
6 // Copyright (c) 2012 Facebook.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file.
9
10 #ifndef ROCKSDB_LITE
11
12 #ifndef __STDC_FORMAT_MACROS
13 #define __STDC_FORMAT_MACROS
14 #endif
15
16 #include <inttypes.h>
17 #include <stdint.h>
18 #include <algorithm>
19 #include <string>
20 #include "db/db_impl.h"
21 #include "db/job_context.h"
22 #include "db/version_set.h"
23 #include "port/port.h"
24 #include "rocksdb/db.h"
25 #include "rocksdb/env.h"
26 #include "util/file_util.h"
27 #include "util/filename.h"
28 #include "util/mutexlock.h"
29 #include "util/sync_point.h"
30
31 namespace rocksdb {
32
33 Status DBImpl::DisableFileDeletions() {
34 InstrumentedMutexLock l(&mutex_);
35 ++disable_delete_obsolete_files_;
36 if (disable_delete_obsolete_files_ == 1) {
37 ROCKS_LOG_INFO(immutable_db_options_.info_log, "File Deletions Disabled");
38 } else {
39 ROCKS_LOG_WARN(immutable_db_options_.info_log,
40 "File Deletions Disabled, but already disabled. Counter: %d",
41 disable_delete_obsolete_files_);
42 }
43 return Status::OK();
44 }
45
46 Status DBImpl::EnableFileDeletions(bool force) {
47 // Job id == 0 means that this is not our background process, but rather
48 // user thread
49 JobContext job_context(0);
50 bool should_purge_files = false;
51 {
52 InstrumentedMutexLock l(&mutex_);
53 if (force) {
54 // if force, we need to enable file deletions right away
55 disable_delete_obsolete_files_ = 0;
56 } else if (disable_delete_obsolete_files_ > 0) {
57 --disable_delete_obsolete_files_;
58 }
59 if (disable_delete_obsolete_files_ == 0) {
60 ROCKS_LOG_INFO(immutable_db_options_.info_log, "File Deletions Enabled");
61 should_purge_files = true;
62 FindObsoleteFiles(&job_context, true);
63 } else {
64 ROCKS_LOG_WARN(
65 immutable_db_options_.info_log,
66 "File Deletions Enable, but not really enabled. Counter: %d",
67 disable_delete_obsolete_files_);
68 }
69 }
70 if (should_purge_files) {
71 PurgeObsoleteFiles(job_context);
72 }
73 job_context.Clean();
74 LogFlush(immutable_db_options_.info_log);
75 return Status::OK();
76 }
77
78 int DBImpl::IsFileDeletionsEnabled() const {
79 return disable_delete_obsolete_files_;
80 }
81
82 Status DBImpl::GetLiveFiles(std::vector<std::string>& ret,
83 uint64_t* manifest_file_size,
84 bool flush_memtable) {
85 *manifest_file_size = 0;
86
87 mutex_.Lock();
88
89 if (flush_memtable) {
90 // flush all dirty data to disk.
91 Status status;
92 for (auto cfd : *versions_->GetColumnFamilySet()) {
93 if (cfd->IsDropped()) {
94 continue;
95 }
96 cfd->Ref();
97 mutex_.Unlock();
98 status = FlushMemTable(cfd, FlushOptions());
99 TEST_SYNC_POINT("DBImpl::GetLiveFiles:1");
100 TEST_SYNC_POINT("DBImpl::GetLiveFiles:2");
101 mutex_.Lock();
102 cfd->Unref();
103 if (!status.ok()) {
104 break;
105 }
106 }
107 versions_->GetColumnFamilySet()->FreeDeadColumnFamilies();
108
109 if (!status.ok()) {
110 mutex_.Unlock();
111 ROCKS_LOG_ERROR(immutable_db_options_.info_log, "Cannot Flush data %s\n",
112 status.ToString().c_str());
113 return status;
114 }
115 }
116
117 // Make a set of all of the live *.sst files
118 std::vector<FileDescriptor> live;
119 for (auto cfd : *versions_->GetColumnFamilySet()) {
120 if (cfd->IsDropped()) {
121 continue;
122 }
123 cfd->current()->AddLiveFiles(&live);
124 }
125
126 ret.clear();
127 ret.reserve(live.size() + 3); // *.sst + CURRENT + MANIFEST + OPTIONS
128
129 // create names of the live files. The names are not absolute
130 // paths, instead they are relative to dbname_;
131 for (auto live_file : live) {
132 ret.push_back(MakeTableFileName("", live_file.GetNumber()));
133 }
134
135 ret.push_back(CurrentFileName(""));
136 ret.push_back(DescriptorFileName("", versions_->manifest_file_number()));
137 ret.push_back(OptionsFileName("", versions_->options_file_number()));
138
139 // find length of manifest file while holding the mutex lock
140 *manifest_file_size = versions_->manifest_file_size();
141
142 mutex_.Unlock();
143 return Status::OK();
144 }
145
146 Status DBImpl::GetSortedWalFiles(VectorLogPtr& files) {
147 return wal_manager_.GetSortedWalFiles(files);
148 }
149
150 }
151
152 #endif // ROCKSDB_LITE