db_impl_debug.cc 4.7 KB
Newer Older
I
Igor Canadi 已提交
1 2 3 4 5 6 7 8 9
//  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.

10
#ifndef ROCKSDB_LITE
I
Igor Canadi 已提交
11 12 13

#include "db/db_impl.h"

14 15
namespace rocksdb {

I
Igor Canadi 已提交
16 17 18 19 20 21 22
void DBImpl::TEST_PurgeObsoleteteWAL() { PurgeObsoleteWALFiles(); }

uint64_t DBImpl::TEST_GetLevel0TotalSize() {
  MutexLock l(&mutex_);
  return default_cf_handle_->cfd()->current()->NumLevelBytes(0);
}

23 24
Iterator* DBImpl::TEST_NewInternalIterator(Arena* arena,
                                           ColumnFamilyHandle* column_family) {
I
Igor Canadi 已提交
25 26 27 28 29 30 31 32 33 34 35 36
  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;
37
  return NewInternalIterator(roptions, cfd, super_version, arena);
I
Igor Canadi 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
}

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 =
I
Igor Canadi 已提交
85 86
      (cfd->options()->compaction_style == kCompactionStyleUniversal ||
       cfd->options()->compaction_style == kCompactionStyleFIFO)
I
Igor Canadi 已提交
87 88
          ? level
          : level + 1;
89
  return RunManualCompaction(cfd, level, output_level, 0, begin, end);
I
Igor Canadi 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
}

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_;
}
I
Igor Canadi 已提交
122 123 124 125 126 127 128 129 130 131 132

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);
}
133 134 135 136 137 138 139 140 141 142

void DBImpl::TEST_LockMutex() {
  mutex_.Lock();
}

void DBImpl::TEST_UnlockMutex() {
  mutex_.Unlock();
}

void* DBImpl::TEST_BeginWrite() {
I
Igor Canadi 已提交
143 144
  auto w = new WriteThread::Writer(&mutex_);
  Status s = write_thread_.EnterWriteThread(w, 0);
145 146 147 148 149
  assert(s.ok() && !w->done);  // No timeout and nobody should do our job
  return reinterpret_cast<void*>(w);
}

void DBImpl::TEST_EndWrite(void* w) {
I
Igor Canadi 已提交
150 151
  auto writer = reinterpret_cast<WriteThread::Writer*>(w);
  write_thread_.ExitWriteThread(writer, writer, Status::OK());
I
Igor Canadi 已提交
152
  delete writer;
153 154
}

155
}  // namespace rocksdb
156
#endif  // ROCKSDB_LITE