]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/db_impl/db_impl_debug.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / db / db_impl / 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/column_family.h"
13 #include "db/db_impl/db_impl.h"
14 #include "db/error_handler.h"
15 #include "db/periodic_task_scheduler.h"
16 #include "monitoring/thread_status_updater.h"
17 #include "util/cast_util.h"
18
19 namespace ROCKSDB_NAMESPACE {
20 uint64_t DBImpl::TEST_GetLevel0TotalSize() {
21 InstrumentedMutexLock l(&mutex_);
22 return default_cf_handle_->cfd()->current()->storage_info()->NumLevelBytes(0);
23 }
24
25 Status DBImpl::TEST_SwitchWAL() {
26 WriteContext write_context;
27 InstrumentedMutexLock l(&mutex_);
28 void* writer = TEST_BeginWrite();
29 auto s = SwitchWAL(&write_context);
30 TEST_EndWrite(writer);
31 return s;
32 }
33
34 uint64_t DBImpl::TEST_MaxNextLevelOverlappingBytes(
35 ColumnFamilyHandle* column_family) {
36 ColumnFamilyData* cfd;
37 if (column_family == nullptr) {
38 cfd = default_cf_handle_->cfd();
39 } else {
40 auto cfh = static_cast_with_check<ColumnFamilyHandleImpl>(column_family);
41 cfd = cfh->cfd();
42 }
43 InstrumentedMutexLock l(&mutex_);
44 return cfd->current()->storage_info()->MaxNextLevelOverlappingBytes();
45 }
46
47 void DBImpl::TEST_GetFilesMetaData(
48 ColumnFamilyHandle* column_family,
49 std::vector<std::vector<FileMetaData>>* metadata,
50 std::vector<std::shared_ptr<BlobFileMetaData>>* blob_metadata) {
51 assert(metadata);
52
53 auto cfh = static_cast_with_check<ColumnFamilyHandleImpl>(column_family);
54 assert(cfh);
55
56 auto cfd = cfh->cfd();
57 assert(cfd);
58
59 InstrumentedMutexLock l(&mutex_);
60
61 const auto* current = cfd->current();
62 assert(current);
63
64 const auto* vstorage = current->storage_info();
65 assert(vstorage);
66
67 metadata->resize(NumberLevels());
68
69 for (int level = 0; level < NumberLevels(); ++level) {
70 const std::vector<FileMetaData*>& files = vstorage->LevelFiles(level);
71
72 (*metadata)[level].clear();
73 (*metadata)[level].reserve(files.size());
74
75 for (const auto& f : files) {
76 (*metadata)[level].push_back(*f);
77 }
78 }
79
80 if (blob_metadata) {
81 *blob_metadata = vstorage->GetBlobFiles();
82 }
83 }
84
85 uint64_t DBImpl::TEST_Current_Manifest_FileNo() {
86 return versions_->manifest_file_number();
87 }
88
89 uint64_t DBImpl::TEST_Current_Next_FileNo() {
90 return versions_->current_next_file_number();
91 }
92
93 Status DBImpl::TEST_CompactRange(int level, const Slice* begin,
94 const Slice* end,
95 ColumnFamilyHandle* column_family,
96 bool disallow_trivial_move) {
97 ColumnFamilyData* cfd;
98 if (column_family == nullptr) {
99 cfd = default_cf_handle_->cfd();
100 } else {
101 auto cfh = static_cast_with_check<ColumnFamilyHandleImpl>(column_family);
102 cfd = cfh->cfd();
103 }
104 int output_level =
105 (cfd->ioptions()->compaction_style == kCompactionStyleUniversal ||
106 cfd->ioptions()->compaction_style == kCompactionStyleFIFO)
107 ? level
108 : level + 1;
109 return RunManualCompaction(
110 cfd, level, output_level, CompactRangeOptions(), begin, end, true,
111 disallow_trivial_move,
112 std::numeric_limits<uint64_t>::max() /*max_file_num_to_ignore*/,
113 "" /*trim_ts*/);
114 }
115
116 Status DBImpl::TEST_SwitchMemtable(ColumnFamilyData* cfd) {
117 WriteContext write_context;
118 InstrumentedMutexLock l(&mutex_);
119 if (cfd == nullptr) {
120 cfd = default_cf_handle_->cfd();
121 }
122
123 Status s;
124 void* writer = TEST_BeginWrite();
125 if (two_write_queues_) {
126 WriteThread::Writer nonmem_w;
127 nonmem_write_thread_.EnterUnbatched(&nonmem_w, &mutex_);
128 s = SwitchMemtable(cfd, &write_context);
129 nonmem_write_thread_.ExitUnbatched(&nonmem_w);
130 } else {
131 s = SwitchMemtable(cfd, &write_context);
132 }
133 TEST_EndWrite(writer);
134 return s;
135 }
136
137 Status DBImpl::TEST_FlushMemTable(bool wait, bool allow_write_stall,
138 ColumnFamilyHandle* cfh) {
139 FlushOptions fo;
140 fo.wait = wait;
141 fo.allow_write_stall = allow_write_stall;
142 ColumnFamilyData* cfd;
143 if (cfh == nullptr) {
144 cfd = default_cf_handle_->cfd();
145 } else {
146 auto cfhi = static_cast_with_check<ColumnFamilyHandleImpl>(cfh);
147 cfd = cfhi->cfd();
148 }
149 return FlushMemTable(cfd, fo, FlushReason::kTest);
150 }
151
152 Status DBImpl::TEST_FlushMemTable(ColumnFamilyData* cfd,
153 const FlushOptions& flush_opts) {
154 return FlushMemTable(cfd, flush_opts, FlushReason::kTest);
155 }
156
157 Status DBImpl::TEST_AtomicFlushMemTables(
158 const autovector<ColumnFamilyData*>& cfds, const FlushOptions& flush_opts) {
159 return AtomicFlushMemTables(cfds, flush_opts, FlushReason::kTest);
160 }
161
162 Status DBImpl::TEST_WaitForBackgroundWork() {
163 InstrumentedMutexLock l(&mutex_);
164 WaitForBackgroundWork();
165 return error_handler_.GetBGError();
166 }
167
168 Status DBImpl::TEST_WaitForFlushMemTable(ColumnFamilyHandle* column_family) {
169 ColumnFamilyData* cfd;
170 if (column_family == nullptr) {
171 cfd = default_cf_handle_->cfd();
172 } else {
173 auto cfh = static_cast_with_check<ColumnFamilyHandleImpl>(column_family);
174 cfd = cfh->cfd();
175 }
176 return WaitForFlushMemTable(cfd, nullptr, false);
177 }
178
179 Status DBImpl::TEST_WaitForCompact(bool wait_unscheduled) {
180 // Wait until the compaction completes
181 return WaitForCompact(wait_unscheduled);
182 }
183
184 Status DBImpl::TEST_WaitForPurge() {
185 InstrumentedMutexLock l(&mutex_);
186 while (bg_purge_scheduled_ && error_handler_.GetBGError().ok()) {
187 bg_cv_.Wait();
188 }
189 return error_handler_.GetBGError();
190 }
191
192 Status DBImpl::TEST_GetBGError() {
193 InstrumentedMutexLock l(&mutex_);
194 return error_handler_.GetBGError();
195 }
196
197 void DBImpl::TEST_LockMutex() { mutex_.Lock(); }
198
199 void DBImpl::TEST_UnlockMutex() { mutex_.Unlock(); }
200
201 void* DBImpl::TEST_BeginWrite() {
202 auto w = new WriteThread::Writer();
203 write_thread_.EnterUnbatched(w, &mutex_);
204 return reinterpret_cast<void*>(w);
205 }
206
207 void DBImpl::TEST_EndWrite(void* w) {
208 auto writer = reinterpret_cast<WriteThread::Writer*>(w);
209 write_thread_.ExitUnbatched(writer);
210 delete writer;
211 }
212
213 size_t DBImpl::TEST_LogsToFreeSize() {
214 InstrumentedMutexLock l(&log_write_mutex_);
215 return logs_to_free_.size();
216 }
217
218 uint64_t DBImpl::TEST_LogfileNumber() {
219 InstrumentedMutexLock l(&mutex_);
220 return logfile_number_;
221 }
222
223 Status DBImpl::TEST_GetAllImmutableCFOptions(
224 std::unordered_map<std::string, const ImmutableCFOptions*>* iopts_map) {
225 std::vector<std::string> cf_names;
226 std::vector<const ImmutableCFOptions*> iopts;
227 {
228 InstrumentedMutexLock l(&mutex_);
229 for (auto cfd : *versions_->GetColumnFamilySet()) {
230 cf_names.push_back(cfd->GetName());
231 iopts.push_back(cfd->ioptions());
232 }
233 }
234 iopts_map->clear();
235 for (size_t i = 0; i < cf_names.size(); ++i) {
236 iopts_map->insert({cf_names[i], iopts[i]});
237 }
238
239 return Status::OK();
240 }
241
242 uint64_t DBImpl::TEST_FindMinLogContainingOutstandingPrep() {
243 return logs_with_prep_tracker_.FindMinLogContainingOutstandingPrep();
244 }
245
246 size_t DBImpl::TEST_PreparedSectionCompletedSize() {
247 return logs_with_prep_tracker_.TEST_PreparedSectionCompletedSize();
248 }
249
250 size_t DBImpl::TEST_LogsWithPrepSize() {
251 return logs_with_prep_tracker_.TEST_LogsWithPrepSize();
252 }
253
254 uint64_t DBImpl::TEST_FindMinPrepLogReferencedByMemTable() {
255 autovector<MemTable*> empty_list;
256 return FindMinPrepLogReferencedByMemTable(versions_.get(), empty_list);
257 }
258
259 Status DBImpl::TEST_GetLatestMutableCFOptions(
260 ColumnFamilyHandle* column_family, MutableCFOptions* mutable_cf_options) {
261 InstrumentedMutexLock l(&mutex_);
262
263 auto cfh = static_cast_with_check<ColumnFamilyHandleImpl>(column_family);
264 *mutable_cf_options = *cfh->cfd()->GetLatestMutableCFOptions();
265 return Status::OK();
266 }
267
268 int DBImpl::TEST_BGCompactionsAllowed() const {
269 InstrumentedMutexLock l(&mutex_);
270 return GetBGJobLimits().max_compactions;
271 }
272
273 int DBImpl::TEST_BGFlushesAllowed() const {
274 InstrumentedMutexLock l(&mutex_);
275 return GetBGJobLimits().max_flushes;
276 }
277
278 SequenceNumber DBImpl::TEST_GetLastVisibleSequence() const {
279 if (last_seq_same_as_publish_seq_) {
280 return versions_->LastSequence();
281 } else {
282 return versions_->LastAllocatedSequence();
283 }
284 }
285
286 size_t DBImpl::TEST_GetWalPreallocateBlockSize(
287 uint64_t write_buffer_size) const {
288 InstrumentedMutexLock l(&mutex_);
289 return GetWalPreallocateBlockSize(write_buffer_size);
290 }
291
292 #ifndef ROCKSDB_LITE
293 void DBImpl::TEST_WaitForPeridicTaskRun(std::function<void()> callback) const {
294 periodic_task_scheduler_.TEST_WaitForRun(callback);
295 }
296
297 const PeriodicTaskScheduler& DBImpl::TEST_GetPeriodicTaskScheduler() const {
298 return periodic_task_scheduler_;
299 }
300
301 SeqnoToTimeMapping DBImpl::TEST_GetSeqnoToTimeMapping() const {
302 InstrumentedMutexLock l(&mutex_);
303 return seqno_time_mapping_;
304 }
305
306 #endif // !ROCKSDB_LITE
307
308 size_t DBImpl::TEST_EstimateInMemoryStatsHistorySize() const {
309 return EstimateInMemoryStatsHistorySize();
310 }
311 } // namespace ROCKSDB_NAMESPACE
312 #endif // NDEBUG