YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/db_impl_debug.cc
Line
Count
Source (jump to first uncovered line)
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
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
21
// Use of this source code is governed by a BSD-style license that can be
22
// found in the LICENSE file. See the AUTHORS file for names of contributors.
23
24
#include "yb/rocksdb/db/db_impl.h"
25
#include "yb/rocksdb/db/version_set.h"
26
27
namespace rocksdb {
28
29
0
uint64_t DBImpl::TEST_GetLevel0TotalSize() {
30
0
  InstrumentedMutexLock l(&mutex_);
31
0
  return default_cf_handle_->cfd()->current()->storage_info()->NumLevelBytes(0);
32
0
}
33
34
6
int DBImpl::TEST_NumRunningLargeCompactions() {
35
6
  return num_running_large_compactions_;
36
6
}
37
38
21
int DBImpl::TEST_NumTotalRunningCompactions() {
39
21
  InstrumentedMutexLock l(&mutex_);
40
21
  return num_total_running_compactions_;
41
21
}
42
43
1
int DBImpl::TEST_NumRunningFlushes() {
44
1
  InstrumentedMutexLock l(&mutex_);
45
1
  return num_running_flushes_;
46
1
}
47
48
1
int DBImpl::TEST_NumBackgroundCompactionsScheduled() {
49
1
  InstrumentedMutexLock l(&mutex_);
50
1
  return bg_compaction_scheduled_;
51
1
}
52
53
int64_t DBImpl::TEST_MaxNextLevelOverlappingBytes(
54
15
    ColumnFamilyHandle* column_family) {
55
15
  ColumnFamilyData* cfd;
56
15
  if (column_family == nullptr) {
57
0
    cfd = default_cf_handle_->cfd();
58
15
  } else {
59
15
    auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
60
15
    cfd = cfh->cfd();
61
15
  }
62
15
  InstrumentedMutexLock l(&mutex_);
63
15
  return cfd->current()->storage_info()->MaxNextLevelOverlappingBytes();
64
15
}
65
66
void DBImpl::TEST_GetFilesMetaData(
67
    ColumnFamilyHandle* column_family,
68
32
    std::vector<std::vector<FileMetaData>>* metadata) {
69
32
  auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
70
32
  auto cfd = cfh->cfd();
71
32
  InstrumentedMutexLock l(&mutex_);
72
32
  metadata->resize(NumberLevels());
73
241
  for (int level = 0; level < NumberLevels(); 
level++209
) {
74
209
    const std::vector<FileMetaData*>& files =
75
209
        cfd->current()->storage_info()->LevelFiles(level);
76
77
209
    (*metadata)[level].clear();
78
209
    for (const auto& f : files) {
79
138
      (*metadata)[level].push_back(*f);
80
138
    }
81
209
  }
82
32
}
83
84
15
uint64_t DBImpl::TEST_Current_Manifest_FileNo() {
85
15
  return versions_->manifest_file_number();
86
15
}
87
88
Status DBImpl::TEST_CompactRange(int level, const Slice* begin,
89
                                 const Slice* end,
90
                                 ColumnFamilyHandle* column_family,
91
3.60k
                                 bool disallow_trivial_move) {
92
3.60k
  ColumnFamilyData* cfd;
93
3.60k
  if (column_family == nullptr) {
94
255
    cfd = default_cf_handle_->cfd();
95
3.35k
  } else {
96
3.35k
    auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
97
3.35k
    cfd = cfh->cfd();
98
3.35k
  }
99
3.60k
  int output_level =
100
3.60k
      (cfd->ioptions()->compaction_style == kCompactionStyleUniversal ||
101
3.60k
       
cfd->ioptions()->compaction_style == kCompactionStyleFIFO3.42k
)
102
3.60k
          ? 
level185
103
3.60k
          : 
level + 13.42k
;
104
3.60k
  return RunManualCompaction(cfd, level, output_level, 0, begin, end, true,
105
3.60k
                             disallow_trivial_move);
106
3.60k
}
107
108
455
Status DBImpl::TEST_FlushMemTable(bool wait) {
109
455
  FlushOptions fo;
110
455
  fo.wait = wait;
111
455
  return FlushMemTable(default_cf_handle_->cfd(), fo);
112
455
}
113
114
8.36k
Status DBImpl::TEST_WaitForFlushMemTable(ColumnFamilyHandle* column_family) {
115
8.36k
  ColumnFamilyData* cfd;
116
8.36k
  if (column_family == nullptr) {
117
3.37k
    cfd = default_cf_handle_->cfd();
118
4.99k
  } else {
119
4.99k
    auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
120
4.99k
    cfd = cfh->cfd();
121
4.99k
  }
122
8.36k
  return WaitForFlushMemTable(cfd);
123
8.36k
}
124
125
1.59k
Status DBImpl::TEST_WaitForCompact() {
126
  // Wait until the compaction completes
127
128
  // TODO: a bug here. This function actually does not necessarily
129
  // wait for compact. It actually waits for scheduled compaction
130
  // OR flush to finish.
131
132
1.59k
  InstrumentedMutexLock l(&mutex_);
133
3.08k
  while ((bg_compaction_scheduled_ || 
bg_flush_scheduled_1.70k
) &&
bg_error_.ok()1.49k
) {
134
1.49k
    bg_cv_.Wait();
135
1.49k
  }
136
1.59k
  return bg_error_;
137
1.59k
}
138
139
18.6k
void DBImpl::TEST_LockMutex() {
140
18.6k
  mutex_.Lock();
141
18.6k
}
142
143
18.6k
void DBImpl::TEST_UnlockMutex() {
144
18.6k
  mutex_.Unlock();
145
18.6k
}
146
147
1
void* DBImpl::TEST_BeginWrite() {
148
1
  auto w = new WriteThread::Writer();
149
1
  write_thread_.EnterUnbatched(w, &mutex_);
150
1
  return reinterpret_cast<void*>(w);
151
1
}
152
153
1
void DBImpl::TEST_EndWrite(void* w) {
154
1
  auto writer = reinterpret_cast<WriteThread::Writer*>(w);
155
1
  write_thread_.ExitUnbatched(writer);
156
1
  delete writer;
157
1
}
158
159
100k
size_t DBImpl::TEST_LogsToFreeSize() {
160
100k
  InstrumentedMutexLock l(&mutex_);
161
100k
  return logs_to_free_.size();
162
100k
}
163
164
2
uint64_t DBImpl::TEST_LogfileNumber() {
165
2
  InstrumentedMutexLock l(&mutex_);
166
2
  return logfile_number_;
167
2
}
168
169
Status DBImpl::TEST_GetAllImmutableCFOptions(
170
0
    std::unordered_map<std::string, const ImmutableCFOptions*>* iopts_map) {
171
0
  std::vector<std::string> cf_names;
172
0
  std::vector<const ImmutableCFOptions*> iopts;
173
0
  {
174
0
    InstrumentedMutexLock l(&mutex_);
175
0
    for (auto cfd : *versions_->GetColumnFamilySet()) {
176
0
      cf_names.push_back(cfd->GetName());
177
0
      iopts.push_back(cfd->ioptions());
178
0
    }
179
0
  }
180
0
  iopts_map->clear();
181
0
  for (size_t i = 0; i < cf_names.size(); ++i) {
182
0
    iopts_map->insert({cf_names[i], iopts[i]});
183
0
  }
184
185
0
  return Status::OK();
186
0
}
187
188
}  // namespace rocksdb