]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/db_impl_debug.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / db / db_impl_debug.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 // 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.
9
10 #ifndef NDEBUG
11
12 #include "db/db_impl.h"
13 #include "db/error_handler.h"
14 #include "monitoring/thread_status_updater.h"
15
16 namespace rocksdb {
17
18 uint64_t DBImpl::TEST_GetLevel0TotalSize() {
19 InstrumentedMutexLock l(&mutex_);
20 return default_cf_handle_->cfd()->current()->storage_info()->NumLevelBytes(0);
21 }
22
23 void DBImpl::TEST_SwitchWAL() {
24 WriteContext write_context;
25 InstrumentedMutexLock l(&mutex_);
26 SwitchWAL(&write_context);
27 }
28
29 bool DBImpl::TEST_WALBufferIsEmpty() {
30 InstrumentedMutexLock wl(&log_write_mutex_);
31 log::Writer* cur_log_writer = logs_.back().writer;
32 return cur_log_writer->TEST_BufferIsEmpty();
33 }
34
35 int64_t DBImpl::TEST_MaxNextLevelOverlappingBytes(
36 ColumnFamilyHandle* column_family) {
37 ColumnFamilyData* cfd;
38 if (column_family == nullptr) {
39 cfd = default_cf_handle_->cfd();
40 } else {
41 auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
42 cfd = cfh->cfd();
43 }
44 InstrumentedMutexLock l(&mutex_);
45 return cfd->current()->storage_info()->MaxNextLevelOverlappingBytes();
46 }
47
48 void DBImpl::TEST_GetFilesMetaData(
49 ColumnFamilyHandle* column_family,
50 std::vector<std::vector<FileMetaData>>* metadata) {
51 auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
52 auto cfd = cfh->cfd();
53 InstrumentedMutexLock l(&mutex_);
54 metadata->resize(NumberLevels());
55 for (int level = 0; level < NumberLevels(); level++) {
56 const std::vector<FileMetaData*>& files =
57 cfd->current()->storage_info()->LevelFiles(level);
58
59 (*metadata)[level].clear();
60 for (const auto& f : files) {
61 (*metadata)[level].push_back(*f);
62 }
63 }
64 }
65
66 uint64_t DBImpl::TEST_Current_Manifest_FileNo() {
67 return versions_->manifest_file_number();
68 }
69
70 uint64_t DBImpl::TEST_Current_Next_FileNo() {
71 return versions_->current_next_file_number();
72 }
73
74 Status DBImpl::TEST_CompactRange(int level, const Slice* begin,
75 const Slice* end,
76 ColumnFamilyHandle* column_family,
77 bool disallow_trivial_move) {
78 ColumnFamilyData* cfd;
79 if (column_family == nullptr) {
80 cfd = default_cf_handle_->cfd();
81 } else {
82 auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
83 cfd = cfh->cfd();
84 }
85 int output_level =
86 (cfd->ioptions()->compaction_style == kCompactionStyleUniversal ||
87 cfd->ioptions()->compaction_style == kCompactionStyleFIFO)
88 ? level
89 : level + 1;
90 return RunManualCompaction(cfd, level, output_level, 0, 0, begin, end, true,
91 disallow_trivial_move);
92 }
93
94 Status DBImpl::TEST_SwitchMemtable(ColumnFamilyData* cfd) {
95 WriteContext write_context;
96 InstrumentedMutexLock l(&mutex_);
97 if (cfd == nullptr) {
98 cfd = default_cf_handle_->cfd();
99 }
100 return SwitchMemtable(cfd, &write_context);
101 }
102
103 Status DBImpl::TEST_FlushMemTable(bool wait, bool allow_write_stall,
104 ColumnFamilyHandle* cfh) {
105 FlushOptions fo;
106 fo.wait = wait;
107 fo.allow_write_stall = allow_write_stall;
108 ColumnFamilyData* cfd;
109 if (cfh == nullptr) {
110 cfd = default_cf_handle_->cfd();
111 } else {
112 auto cfhi = reinterpret_cast<ColumnFamilyHandleImpl*>(cfh);
113 cfd = cfhi->cfd();
114 }
115 return FlushMemTable(cfd, fo, FlushReason::kTest);
116 }
117
118 Status DBImpl::TEST_WaitForFlushMemTable(ColumnFamilyHandle* column_family) {
119 ColumnFamilyData* cfd;
120 if (column_family == nullptr) {
121 cfd = default_cf_handle_->cfd();
122 } else {
123 auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
124 cfd = cfh->cfd();
125 }
126 return WaitForFlushMemTable(cfd);
127 }
128
129 Status DBImpl::TEST_WaitForCompact(bool wait_unscheduled) {
130 // Wait until the compaction completes
131
132 // TODO: a bug here. This function actually does not necessarily
133 // wait for compact. It actually waits for scheduled compaction
134 // OR flush to finish.
135
136 InstrumentedMutexLock l(&mutex_);
137 while ((bg_bottom_compaction_scheduled_ || bg_compaction_scheduled_ ||
138 bg_flush_scheduled_ ||
139 (wait_unscheduled && unscheduled_compactions_)) &&
140 (error_handler_.GetBGError() == Status::OK())) {
141 bg_cv_.Wait();
142 }
143 return error_handler_.GetBGError();
144 }
145
146 void DBImpl::TEST_LockMutex() {
147 mutex_.Lock();
148 }
149
150 void DBImpl::TEST_UnlockMutex() {
151 mutex_.Unlock();
152 }
153
154 void* DBImpl::TEST_BeginWrite() {
155 auto w = new WriteThread::Writer();
156 write_thread_.EnterUnbatched(w, &mutex_);
157 return reinterpret_cast<void*>(w);
158 }
159
160 void DBImpl::TEST_EndWrite(void* w) {
161 auto writer = reinterpret_cast<WriteThread::Writer*>(w);
162 write_thread_.ExitUnbatched(writer);
163 delete writer;
164 }
165
166 size_t DBImpl::TEST_LogsToFreeSize() {
167 InstrumentedMutexLock l(&mutex_);
168 return logs_to_free_.size();
169 }
170
171 uint64_t DBImpl::TEST_LogfileNumber() {
172 InstrumentedMutexLock l(&mutex_);
173 return logfile_number_;
174 }
175
176 Status DBImpl::TEST_GetAllImmutableCFOptions(
177 std::unordered_map<std::string, const ImmutableCFOptions*>* iopts_map) {
178 std::vector<std::string> cf_names;
179 std::vector<const ImmutableCFOptions*> iopts;
180 {
181 InstrumentedMutexLock l(&mutex_);
182 for (auto cfd : *versions_->GetColumnFamilySet()) {
183 cf_names.push_back(cfd->GetName());
184 iopts.push_back(cfd->ioptions());
185 }
186 }
187 iopts_map->clear();
188 for (size_t i = 0; i < cf_names.size(); ++i) {
189 iopts_map->insert({cf_names[i], iopts[i]});
190 }
191
192 return Status::OK();
193 }
194
195 uint64_t DBImpl::TEST_FindMinLogContainingOutstandingPrep() {
196 return logs_with_prep_tracker_.FindMinLogContainingOutstandingPrep();
197 }
198
199 size_t DBImpl::TEST_PreparedSectionCompletedSize() {
200 return logs_with_prep_tracker_.TEST_PreparedSectionCompletedSize();
201 }
202
203 size_t DBImpl::TEST_LogsWithPrepSize() {
204 return logs_with_prep_tracker_.TEST_LogsWithPrepSize();
205 }
206
207 uint64_t DBImpl::TEST_FindMinPrepLogReferencedByMemTable() {
208 autovector<MemTable*> empty_list;
209 return FindMinPrepLogReferencedByMemTable(versions_.get(), nullptr,
210 empty_list);
211 }
212
213 Status DBImpl::TEST_GetLatestMutableCFOptions(
214 ColumnFamilyHandle* column_family, MutableCFOptions* mutable_cf_options) {
215 InstrumentedMutexLock l(&mutex_);
216
217 auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
218 *mutable_cf_options = *cfh->cfd()->GetLatestMutableCFOptions();
219 return Status::OK();
220 }
221
222 int DBImpl::TEST_BGCompactionsAllowed() const {
223 InstrumentedMutexLock l(&mutex_);
224 return GetBGJobLimits().max_compactions;
225 }
226
227 int DBImpl::TEST_BGFlushesAllowed() const {
228 InstrumentedMutexLock l(&mutex_);
229 return GetBGJobLimits().max_flushes;
230 }
231
232 SequenceNumber DBImpl::TEST_GetLastVisibleSequence() const {
233 if (last_seq_same_as_publish_seq_) {
234 return versions_->LastSequence();
235 } else {
236 return versions_->LastAllocatedSequence();
237 }
238 }
239
240 size_t DBImpl::TEST_GetWalPreallocateBlockSize(
241 uint64_t write_buffer_size) const {
242 InstrumentedMutexLock l(&mutex_);
243 return GetWalPreallocateBlockSize(write_buffer_size);
244 }
245
246 } // namespace rocksdb
247 #endif // NDEBUG