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"
|
2015-01-13 08:04:08 +00:00
|
|
|
#include "util/thread_status_updater.h"
|
2014-04-15 20:39:26 +00:00
|
|
|
|
2014-04-15 20:51:07 +00:00
|
|
|
namespace rocksdb {
|
|
|
|
|
2014-04-15 20:39:26 +00:00
|
|
|
uint64_t DBImpl::TEST_GetLevel0TotalSize() {
|
2015-02-05 05:39:45 +00:00
|
|
|
InstrumentedMutexLock l(&mutex_);
|
2014-10-31 15:48:19 +00:00
|
|
|
return default_cf_handle_->cfd()->current()->storage_info()->NumLevelBytes(0);
|
2014-04-15 20:39:26 +00:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
2015-02-05 05:39:45 +00:00
|
|
|
InstrumentedMutexLock l(&mutex_);
|
2014-10-31 15:48:19 +00:00
|
|
|
return cfd->current()->storage_info()->MaxNextLevelOverlappingBytes();
|
2014-04-15 20:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DBImpl::TEST_GetFilesMetaData(
|
|
|
|
ColumnFamilyHandle* column_family,
|
|
|
|
std::vector<std::vector<FileMetaData>>* metadata) {
|
|
|
|
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
|
|
|
|
auto cfd = cfh->cfd();
|
2015-02-05 05:39:45 +00:00
|
|
|
InstrumentedMutexLock l(&mutex_);
|
2014-04-15 20:39:26 +00:00
|
|
|
metadata->resize(NumberLevels());
|
|
|
|
for (int level = 0; level < NumberLevels(); level++) {
|
2014-10-27 22:49:46 +00:00
|
|
|
const std::vector<FileMetaData*>& files =
|
2014-10-31 15:48:19 +00:00
|
|
|
cfd->current()->storage_info()->LevelFiles(level);
|
2014-04-15 20:39:26 +00:00
|
|
|
|
|
|
|
(*metadata)[level].clear();
|
|
|
|
for (const auto& f : files) {
|
|
|
|
(*metadata)[level].push_back(*f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t DBImpl::TEST_Current_Manifest_FileNo() {
|
2014-11-04 01:45:55 +00:00
|
|
|
return versions_->manifest_file_number();
|
2014-04-15 20:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Status DBImpl::TEST_CompactRange(int level, const Slice* begin,
|
|
|
|
const Slice* end,
|
Allowing L0 -> L1 trivial move on sorted data
Summary:
This diff updates the logic of how we do trivial move, now trivial move can run on any number of files in input level as long as they are not overlapping
The conditions for trivial move have been updated
Introduced conditions:
- Trivial move cannot happen if we have a compaction filter (except if the compaction is not manual)
- Input level files cannot be overlapping
Removed conditions:
- Trivial move only run when the compaction is not manual
- Input level should can contain only 1 file
More context on what tests failed because of Trivial move
```
DBTest.CompactionsGenerateMultipleFiles
This test is expecting compaction on a file in L0 to generate multiple files in L1, this test will fail with trivial move because we end up with one file in L1
```
```
DBTest.NoSpaceCompactRange
This test expect compaction to fail when we force environment to report running out of space, of course this is not valid in trivial move situation
because trivial move does not need any extra space, and did not check for that
```
```
DBTest.DropWrites
Similar to DBTest.NoSpaceCompactRange
```
```
DBTest.DeleteObsoleteFilesPendingOutputs
This test expect that a file in L2 is deleted after it's moved to L3, this is not valid with trivial move because although the file was moved it is now used by L3
```
```
CuckooTableDBTest.CompactionIntoMultipleFiles
Same as DBTest.CompactionsGenerateMultipleFiles
```
This diff is based on a work by @sdong https://reviews.facebook.net/D34149
Test Plan: make -j64 check
Reviewers: rven, sdong, igor
Reviewed By: igor
Subscribers: yhchiang, ott, march, dhruba, sdong
Differential Revision: https://reviews.facebook.net/D34797
2015-06-04 23:51:25 +00:00
|
|
|
ColumnFamilyHandle* column_family,
|
|
|
|
bool disallow_trivial_move) {
|
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();
|
|
|
|
}
|
|
|
|
int output_level =
|
2014-11-18 18:20:10 +00:00
|
|
|
(cfd->ioptions()->compaction_style == kCompactionStyleUniversal ||
|
|
|
|
cfd->ioptions()->compaction_style == kCompactionStyleFIFO)
|
2014-04-15 20:39:26 +00:00
|
|
|
? level
|
|
|
|
: level + 1;
|
Allowing L0 -> L1 trivial move on sorted data
Summary:
This diff updates the logic of how we do trivial move, now trivial move can run on any number of files in input level as long as they are not overlapping
The conditions for trivial move have been updated
Introduced conditions:
- Trivial move cannot happen if we have a compaction filter (except if the compaction is not manual)
- Input level files cannot be overlapping
Removed conditions:
- Trivial move only run when the compaction is not manual
- Input level should can contain only 1 file
More context on what tests failed because of Trivial move
```
DBTest.CompactionsGenerateMultipleFiles
This test is expecting compaction on a file in L0 to generate multiple files in L1, this test will fail with trivial move because we end up with one file in L1
```
```
DBTest.NoSpaceCompactRange
This test expect compaction to fail when we force environment to report running out of space, of course this is not valid in trivial move situation
because trivial move does not need any extra space, and did not check for that
```
```
DBTest.DropWrites
Similar to DBTest.NoSpaceCompactRange
```
```
DBTest.DeleteObsoleteFilesPendingOutputs
This test expect that a file in L2 is deleted after it's moved to L3, this is not valid with trivial move because although the file was moved it is now used by L3
```
```
CuckooTableDBTest.CompactionIntoMultipleFiles
Same as DBTest.CompactionsGenerateMultipleFiles
```
This diff is based on a work by @sdong https://reviews.facebook.net/D34149
Test Plan: make -j64 check
Reviewers: rven, sdong, igor
Reviewed By: igor
Subscribers: yhchiang, ott, march, dhruba, sdong
Differential Revision: https://reviews.facebook.net/D34797
2015-06-04 23:51:25 +00:00
|
|
|
return RunManualCompaction(cfd, level, output_level, 0, begin, end,
|
|
|
|
disallow_trivial_move);
|
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.
|
|
|
|
|
2015-02-05 05:39:45 +00:00
|
|
|
InstrumentedMutexLock l(&mutex_);
|
2014-04-15 20:39:26 +00:00
|
|
|
while ((bg_compaction_scheduled_ || bg_flush_scheduled_) && bg_error_.ok()) {
|
|
|
|
bg_cv_.Wait();
|
|
|
|
}
|
|
|
|
return bg_error_;
|
|
|
|
}
|
2014-04-29 17:27:58 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-03-30 19:04:10 +00:00
|
|
|
size_t DBImpl::TEST_LogsToFreeSize() {
|
|
|
|
InstrumentedMutexLock l(&mutex_);
|
|
|
|
return logs_to_free_.size();
|
|
|
|
}
|
|
|
|
|
2015-07-02 21:27:00 +00:00
|
|
|
uint64_t DBImpl::TEST_LogfileNumber() {
|
|
|
|
InstrumentedMutexLock l(&mutex_);
|
|
|
|
return logfile_number_;
|
|
|
|
}
|
|
|
|
|
2014-04-15 20:51:07 +00:00
|
|
|
} // namespace rocksdb
|
2014-04-15 22:59:34 +00:00
|
|
|
#endif // ROCKSDB_LITE
|