fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
270 lines
8.0 KiB
270 lines
8.0 KiB
9 years ago
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||
8 years ago
|
// This source code is licensed under both the GPLv2 (found in the
|
||
|
// COPYING file in the root directory) and Apache 2.0 License
|
||
|
// (found in the LICENSE.Apache file in the root directory).
|
||
11 years ago
|
//
|
||
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style license that can be
|
||
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||
|
|
||
9 years ago
|
#ifndef NDEBUG
|
||
11 years ago
|
|
||
6 years ago
|
#include "db/db_impl/db_impl.h"
|
||
7 years ago
|
#include "db/error_handler.h"
|
||
8 years ago
|
#include "monitoring/thread_status_updater.h"
|
||
11 years ago
|
|
||
11 years ago
|
namespace rocksdb {
|
||
|
|
||
11 years ago
|
uint64_t DBImpl::TEST_GetLevel0TotalSize() {
|
||
10 years ago
|
InstrumentedMutexLock l(&mutex_);
|
||
10 years ago
|
return default_cf_handle_->cfd()->current()->storage_info()->NumLevelBytes(0);
|
||
11 years ago
|
}
|
||
|
|
||
7 years ago
|
void DBImpl::TEST_SwitchWAL() {
|
||
8 years ago
|
WriteContext write_context;
|
||
8 years ago
|
InstrumentedMutexLock l(&mutex_);
|
||
7 years ago
|
SwitchWAL(&write_context);
|
||
8 years ago
|
}
|
||
|
|
||
6 years ago
|
bool DBImpl::TEST_WALBufferIsEmpty(bool lock) {
|
||
|
if (lock) {
|
||
|
log_write_mutex_.Lock();
|
||
|
}
|
||
7 years ago
|
log::Writer* cur_log_writer = logs_.back().writer;
|
||
6 years ago
|
auto res = cur_log_writer->TEST_BufferIsEmpty();
|
||
|
if (lock) {
|
||
|
log_write_mutex_.Unlock();
|
||
|
}
|
||
|
return res;
|
||
7 years ago
|
}
|
||
|
|
||
11 years ago
|
int64_t DBImpl::TEST_MaxNextLevelOverlappingBytes(
|
||
|
ColumnFamilyHandle* column_family) {
|
||
|
ColumnFamilyData* cfd;
|
||
|
if (column_family == nullptr) {
|
||
|
cfd = default_cf_handle_->cfd();
|
||
|
} else {
|
||
|
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
|
||
|
cfd = cfh->cfd();
|
||
|
}
|
||
10 years ago
|
InstrumentedMutexLock l(&mutex_);
|
||
10 years ago
|
return cfd->current()->storage_info()->MaxNextLevelOverlappingBytes();
|
||
11 years ago
|
}
|
||
|
|
||
|
void DBImpl::TEST_GetFilesMetaData(
|
||
|
ColumnFamilyHandle* column_family,
|
||
|
std::vector<std::vector<FileMetaData>>* metadata) {
|
||
|
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
|
||
|
auto cfd = cfh->cfd();
|
||
10 years ago
|
InstrumentedMutexLock l(&mutex_);
|
||
11 years ago
|
metadata->resize(NumberLevels());
|
||
|
for (int level = 0; level < NumberLevels(); level++) {
|
||
10 years ago
|
const std::vector<FileMetaData*>& files =
|
||
10 years ago
|
cfd->current()->storage_info()->LevelFiles(level);
|
||
11 years ago
|
|
||
|
(*metadata)[level].clear();
|
||
|
for (const auto& f : files) {
|
||
|
(*metadata)[level].push_back(*f);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
uint64_t DBImpl::TEST_Current_Manifest_FileNo() {
|
||
10 years ago
|
return versions_->manifest_file_number();
|
||
11 years ago
|
}
|
||
|
|
||
7 years ago
|
uint64_t DBImpl::TEST_Current_Next_FileNo() {
|
||
|
return versions_->current_next_file_number();
|
||
|
}
|
||
|
|
||
11 years ago
|
Status DBImpl::TEST_CompactRange(int level, const Slice* begin,
|
||
|
const Slice* end,
|
||
10 years ago
|
ColumnFamilyHandle* column_family,
|
||
|
bool disallow_trivial_move) {
|
||
11 years ago
|
ColumnFamilyData* cfd;
|
||
|
if (column_family == nullptr) {
|
||
|
cfd = default_cf_handle_->cfd();
|
||
|
} else {
|
||
|
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
|
||
|
cfd = cfh->cfd();
|
||
|
}
|
||
|
int output_level =
|
||
10 years ago
|
(cfd->ioptions()->compaction_style == kCompactionStyleUniversal ||
|
||
|
cfd->ioptions()->compaction_style == kCompactionStyleFIFO)
|
||
11 years ago
|
? level
|
||
|
: level + 1;
|
||
6 years ago
|
return RunManualCompaction(cfd, level, output_level, CompactRangeOptions(),
|
||
|
begin, end, true, disallow_trivial_move,
|
||
|
port::kMaxUint64 /*max_file_num_to_ignore*/);
|
||
11 years ago
|
}
|
||
|
|
||
7 years ago
|
Status DBImpl::TEST_SwitchMemtable(ColumnFamilyData* cfd) {
|
||
|
WriteContext write_context;
|
||
|
InstrumentedMutexLock l(&mutex_);
|
||
|
if (cfd == nullptr) {
|
||
|
cfd = default_cf_handle_->cfd();
|
||
|
}
|
||
|
return SwitchMemtable(cfd, &write_context);
|
||
|
}
|
||
|
|
||
6 years ago
|
Status DBImpl::TEST_FlushMemTable(bool wait, bool allow_write_stall,
|
||
6 years ago
|
ColumnFamilyHandle* cfh) {
|
||
11 years ago
|
FlushOptions fo;
|
||
|
fo.wait = wait;
|
||
6 years ago
|
fo.allow_write_stall = allow_write_stall;
|
||
9 years ago
|
ColumnFamilyData* cfd;
|
||
|
if (cfh == nullptr) {
|
||
|
cfd = default_cf_handle_->cfd();
|
||
|
} else {
|
||
|
auto cfhi = reinterpret_cast<ColumnFamilyHandleImpl*>(cfh);
|
||
|
cfd = cfhi->cfd();
|
||
|
}
|
||
7 years ago
|
return FlushMemTable(cfd, fo, FlushReason::kTest);
|
||
11 years ago
|
}
|
||
|
|
||
|
Status DBImpl::TEST_WaitForFlushMemTable(ColumnFamilyHandle* column_family) {
|
||
|
ColumnFamilyData* cfd;
|
||
|
if (column_family == nullptr) {
|
||
|
cfd = default_cf_handle_->cfd();
|
||
|
} else {
|
||
|
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
|
||
|
cfd = cfh->cfd();
|
||
|
}
|
||
6 years ago
|
return WaitForFlushMemTable(cfd, nullptr, false);
|
||
11 years ago
|
}
|
||
|
|
||
7 years ago
|
Status DBImpl::TEST_WaitForCompact(bool wait_unscheduled) {
|
||
11 years ago
|
// Wait until the compaction completes
|
||
|
|
||
|
// TODO: a bug here. This function actually does not necessarily
|
||
|
// wait for compact. It actually waits for scheduled compaction
|
||
|
// OR flush to finish.
|
||
|
|
||
10 years ago
|
InstrumentedMutexLock l(&mutex_);
|
||
8 years ago
|
while ((bg_bottom_compaction_scheduled_ || bg_compaction_scheduled_ ||
|
||
7 years ago
|
bg_flush_scheduled_ ||
|
||
|
(wait_unscheduled && unscheduled_compactions_)) &&
|
||
6 years ago
|
(error_handler_.GetBGError() == Status::OK())) {
|
||
11 years ago
|
bg_cv_.Wait();
|
||
|
}
|
||
7 years ago
|
return error_handler_.GetBGError();
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
6 years ago
|
void DBImpl::TEST_LockMutex() { mutex_.Lock(); }
|
||
10 years ago
|
|
||
6 years ago
|
void DBImpl::TEST_UnlockMutex() { mutex_.Unlock(); }
|
||
10 years ago
|
|
||
|
void* DBImpl::TEST_BeginWrite() {
|
||
10 years ago
|
auto w = new WriteThread::Writer();
|
||
|
write_thread_.EnterUnbatched(w, &mutex_);
|
||
10 years ago
|
return reinterpret_cast<void*>(w);
|
||
|
}
|
||
|
|
||
|
void DBImpl::TEST_EndWrite(void* w) {
|
||
10 years ago
|
auto writer = reinterpret_cast<WriteThread::Writer*>(w);
|
||
10 years ago
|
write_thread_.ExitUnbatched(writer);
|
||
10 years ago
|
delete writer;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
size_t DBImpl::TEST_LogsToFreeSize() {
|
||
|
InstrumentedMutexLock l(&mutex_);
|
||
|
return logs_to_free_.size();
|
||
|
}
|
||
|
|
||
10 years ago
|
uint64_t DBImpl::TEST_LogfileNumber() {
|
||
|
InstrumentedMutexLock l(&mutex_);
|
||
|
return logfile_number_;
|
||
|
}
|
||
|
|
||
9 years ago
|
Status DBImpl::TEST_GetAllImmutableCFOptions(
|
||
|
std::unordered_map<std::string, const ImmutableCFOptions*>* iopts_map) {
|
||
|
std::vector<std::string> cf_names;
|
||
|
std::vector<const ImmutableCFOptions*> iopts;
|
||
|
{
|
||
|
InstrumentedMutexLock l(&mutex_);
|
||
|
for (auto cfd : *versions_->GetColumnFamilySet()) {
|
||
|
cf_names.push_back(cfd->GetName());
|
||
|
iopts.push_back(cfd->ioptions());
|
||
|
}
|
||
|
}
|
||
|
iopts_map->clear();
|
||
|
for (size_t i = 0; i < cf_names.size(); ++i) {
|
||
|
iopts_map->insert({cf_names[i], iopts[i]});
|
||
|
}
|
||
|
|
||
|
return Status::OK();
|
||
|
}
|
||
|
|
||
9 years ago
|
uint64_t DBImpl::TEST_FindMinLogContainingOutstandingPrep() {
|
||
7 years ago
|
return logs_with_prep_tracker_.FindMinLogContainingOutstandingPrep();
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
size_t DBImpl::TEST_PreparedSectionCompletedSize() {
|
||
7 years ago
|
return logs_with_prep_tracker_.TEST_PreparedSectionCompletedSize();
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
size_t DBImpl::TEST_LogsWithPrepSize() {
|
||
|
return logs_with_prep_tracker_.TEST_LogsWithPrepSize();
|
||
|
}
|
||
7 years ago
|
|
||
9 years ago
|
uint64_t DBImpl::TEST_FindMinPrepLogReferencedByMemTable() {
|
||
7 years ago
|
autovector<MemTable*> empty_list;
|
||
|
return FindMinPrepLogReferencedByMemTable(versions_.get(), nullptr,
|
||
|
empty_list);
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
Status DBImpl::TEST_GetLatestMutableCFOptions(
|
||
|
ColumnFamilyHandle* column_family, MutableCFOptions* mutable_cf_options) {
|
||
|
InstrumentedMutexLock l(&mutex_);
|
||
|
|
||
|
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
|
||
|
*mutable_cf_options = *cfh->cfd()->GetLatestMutableCFOptions();
|
||
|
return Status::OK();
|
||
|
}
|
||
|
|
||
8 years ago
|
int DBImpl::TEST_BGCompactionsAllowed() const {
|
||
|
InstrumentedMutexLock l(&mutex_);
|
||
8 years ago
|
return GetBGJobLimits().max_compactions;
|
||
|
}
|
||
|
|
||
|
int DBImpl::TEST_BGFlushesAllowed() const {
|
||
|
InstrumentedMutexLock l(&mutex_);
|
||
|
return GetBGJobLimits().max_flushes;
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
SequenceNumber DBImpl::TEST_GetLastVisibleSequence() const {
|
||
7 years ago
|
if (last_seq_same_as_publish_seq_) {
|
||
7 years ago
|
return versions_->LastSequence();
|
||
7 years ago
|
} else {
|
||
|
return versions_->LastAllocatedSequence();
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
size_t DBImpl::TEST_GetWalPreallocateBlockSize(
|
||
|
uint64_t write_buffer_size) const {
|
||
|
InstrumentedMutexLock l(&mutex_);
|
||
|
return GetWalPreallocateBlockSize(write_buffer_size);
|
||
|
}
|
||
|
|
||
6 years ago
|
void DBImpl::TEST_WaitForDumpStatsRun(std::function<void()> callback) const {
|
||
6 years ago
|
if (thread_dump_stats_ != nullptr) {
|
||
|
thread_dump_stats_->TEST_WaitForRun(callback);
|
||
|
}
|
||
|
}
|
||
6 years ago
|
|
||
|
void DBImpl::TEST_WaitForPersistStatsRun(std::function<void()> callback) const {
|
||
|
if (thread_persist_stats_ != nullptr) {
|
||
|
thread_persist_stats_->TEST_WaitForRun(callback);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool DBImpl::TEST_IsPersistentStatsEnabled() const {
|
||
|
return thread_persist_stats_ && thread_persist_stats_->IsRunning();
|
||
|
}
|
||
|
|
||
|
size_t DBImpl::TEST_EstiamteStatsHistorySize() const {
|
||
|
return EstiamteStatsHistorySize();
|
||
|
}
|
||
11 years ago
|
} // namespace rocksdb
|
||
9 years ago
|
#endif // NDEBUG
|