2014-04-15 20:39:26 +00:00
|
|
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2014-04-15 22:59:34 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
2014-04-15 20:39:26 +00:00
|
|
|
|
|
|
|
#include "db/db_impl.h"
|
|
|
|
|
2014-04-15 20:51:07 +00:00
|
|
|
namespace rocksdb {
|
|
|
|
|
2014-04-15 20:39:26 +00:00
|
|
|
void DBImpl::TEST_PurgeObsoleteteWAL() { PurgeObsoleteWALFiles(); }
|
|
|
|
|
|
|
|
uint64_t DBImpl::TEST_GetLevel0TotalSize() {
|
|
|
|
MutexLock l(&mutex_);
|
|
|
|
return default_cf_handle_->cfd()->current()->NumLevelBytes(0);
|
|
|
|
}
|
|
|
|
|
2014-09-05 00:40:41 +00:00
|
|
|
Iterator* DBImpl::TEST_NewInternalIterator(Arena* arena,
|
|
|
|
ColumnFamilyHandle* column_family) {
|
2014-04-15 20:39:26 +00:00
|
|
|
ColumnFamilyData* cfd;
|
|
|
|
if (column_family == nullptr) {
|
|
|
|
cfd = default_cf_handle_->cfd();
|
|
|
|
} else {
|
|
|
|
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
|
|
|
|
cfd = cfh->cfd();
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_.Lock();
|
|
|
|
SuperVersion* super_version = cfd->GetSuperVersion()->Ref();
|
|
|
|
mutex_.Unlock();
|
|
|
|
ReadOptions roptions;
|
2014-09-05 00:40:41 +00:00
|
|
|
return NewInternalIterator(roptions, cfd, super_version, arena);
|
2014-04-15 20:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
MutexLock l(&mutex_);
|
|
|
|
return cfd->current()->MaxNextLevelOverlappingBytes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DBImpl::TEST_GetFilesMetaData(
|
|
|
|
ColumnFamilyHandle* column_family,
|
|
|
|
std::vector<std::vector<FileMetaData>>* metadata) {
|
|
|
|
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
|
|
|
|
auto cfd = cfh->cfd();
|
|
|
|
MutexLock l(&mutex_);
|
|
|
|
metadata->resize(NumberLevels());
|
|
|
|
for (int level = 0; level < NumberLevels(); level++) {
|
|
|
|
const std::vector<FileMetaData*>& files = cfd->current()->files_[level];
|
|
|
|
|
|
|
|
(*metadata)[level].clear();
|
|
|
|
for (const auto& f : files) {
|
|
|
|
(*metadata)[level].push_back(*f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t DBImpl::TEST_Current_Manifest_FileNo() {
|
|
|
|
return versions_->ManifestFileNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DBImpl::TEST_CompactRange(int level, const Slice* begin,
|
|
|
|
const Slice* end,
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
int output_level =
|
2014-05-21 18:43:35 +00:00
|
|
|
(cfd->options()->compaction_style == kCompactionStyleUniversal ||
|
|
|
|
cfd->options()->compaction_style == kCompactionStyleFIFO)
|
2014-04-15 20:39:26 +00:00
|
|
|
? level
|
|
|
|
: level + 1;
|
2014-07-17 00:39:18 +00:00
|
|
|
return RunManualCompaction(cfd, level, output_level, 0, begin, end);
|
2014-04-15 20:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Status DBImpl::TEST_FlushMemTable(bool wait) {
|
|
|
|
FlushOptions fo;
|
|
|
|
fo.wait = wait;
|
|
|
|
return FlushMemTable(default_cf_handle_->cfd(), fo);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
return WaitForFlushMemTable(cfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DBImpl::TEST_WaitForCompact() {
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
MutexLock l(&mutex_);
|
|
|
|
while ((bg_compaction_scheduled_ || bg_flush_scheduled_) && bg_error_.ok()) {
|
|
|
|
bg_cv_.Wait();
|
|
|
|
}
|
|
|
|
return bg_error_;
|
|
|
|
}
|
2014-04-29 17:27:58 +00:00
|
|
|
|
|
|
|
Status DBImpl::TEST_ReadFirstRecord(const WalFileType type,
|
|
|
|
const uint64_t number,
|
|
|
|
SequenceNumber* sequence) {
|
|
|
|
return ReadFirstRecord(type, number, sequence);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DBImpl::TEST_ReadFirstLine(const std::string& fname,
|
|
|
|
SequenceNumber* sequence) {
|
|
|
|
return ReadFirstLine(fname, sequence);
|
|
|
|
}
|
2014-09-05 22:20:05 +00:00
|
|
|
|
|
|
|
void DBImpl::TEST_LockMutex() {
|
|
|
|
mutex_.Lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DBImpl::TEST_UnlockMutex() {
|
|
|
|
mutex_.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void* DBImpl::TEST_BeginWrite() {
|
2014-09-12 23:23:58 +00:00
|
|
|
auto w = new WriteThread::Writer(&mutex_);
|
|
|
|
Status s = write_thread_.EnterWriteThread(w, 0);
|
2014-09-05 22:20:05 +00:00
|
|
|
assert(s.ok() && !w->done); // No timeout and nobody should do our job
|
|
|
|
return reinterpret_cast<void*>(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DBImpl::TEST_EndWrite(void* w) {
|
2014-09-12 23:23:58 +00:00
|
|
|
auto writer = reinterpret_cast<WriteThread::Writer*>(w);
|
|
|
|
write_thread_.ExitWriteThread(writer, writer, Status::OK());
|
2014-09-08 15:01:25 +00:00
|
|
|
delete writer;
|
2014-09-05 22:20:05 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 20:51:07 +00:00
|
|
|
} // namespace rocksdb
|
2014-04-15 22:59:34 +00:00
|
|
|
#endif // ROCKSDB_LITE
|