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_filesnapshot.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) 2012 Facebook.
21
// Use of this source code is governed by a BSD-style license that can be
22
// found in the LICENSE file.
23
24
#ifndef ROCKSDB_LITE
25
26
#ifndef __STDC_FORMAT_MACROS
27
#define __STDC_FORMAT_MACROS
28
#endif
29
30
#include <stdint.h>
31
#include <inttypes.h>
32
#include <algorithm>
33
#include <string>
34
#include "yb/rocksdb/db/db_impl.h"
35
#include "yb/rocksdb/db/filename.h"
36
#include "yb/rocksdb/db/job_context.h"
37
#include "yb/rocksdb/db/version_set.h"
38
#include "yb/rocksdb/db.h"
39
#include "yb/rocksdb/env.h"
40
#include "yb/rocksdb/port/port.h"
41
#include "yb/rocksdb/util/mutexlock.h"
42
#include "yb/rocksdb/util/sync_point.h"
43
#include "yb/rocksdb/util/file_util.h"
44
45
namespace rocksdb {
46
47
2.18k
Status DBImpl::DisableFileDeletions() {
48
2.18k
  InstrumentedMutexLock l(&mutex_);
49
2.18k
  ++disable_delete_obsolete_files_;
50
2.18k
  if (disable_delete_obsolete_files_ == 1) {
51
2.10k
    RLOG(InfoLogLevel::INFO_LEVEL, db_options_.info_log,
52
2.10k
        "File Deletions Disabled");
53
2.10k
  } else {
54
81
    RLOG(InfoLogLevel::WARN_LEVEL, db_options_.info_log,
55
81
        "File Deletions Disabled, but already disabled. Counter: %d",
56
81
        disable_delete_obsolete_files_);
57
81
  }
58
2.18k
  return Status::OK();
59
2.18k
}
60
61
2.13k
Status DBImpl::EnableFileDeletions(bool force) {
62
  // Job id == 0 means that this is not our background process, but rather
63
  // user thread
64
2.13k
  JobContext job_context(0);
65
2.13k
  bool should_purge_files = false;
66
2.13k
  {
67
2.13k
    InstrumentedMutexLock l(&mutex_);
68
2.13k
    if (force) {
69
      // if force, we need to enable file deletions right away
70
30
      disable_delete_obsolete_files_ = 0;
71
2.10k
    } else if (disable_delete_obsolete_files_ > 0) {
72
2.10k
      --disable_delete_obsolete_files_;
73
2.10k
    }
74
2.13k
    if (disable_delete_obsolete_files_ == 0) {
75
2.10k
      RLOG(InfoLogLevel::INFO_LEVEL, db_options_.info_log,
76
2.10k
          "File Deletions Enabled");
77
2.10k
      should_purge_files = true;
78
2.10k
      FindObsoleteFiles(&job_context, true);
79
2.10k
    } else {
80
30
      RLOG(InfoLogLevel::WARN_LEVEL, db_options_.info_log,
81
30
          "File Deletions Enable, but not really enabled. Counter: %d",
82
30
          disable_delete_obsolete_files_);
83
30
    }
84
2.13k
  }
85
2.13k
  if (should_purge_files) {
86
2.10k
    PurgeObsoleteFiles(job_context);
87
2.10k
  }
88
2.13k
  job_context.Clean();
89
2.13k
  LogFlush(db_options_.info_log);
90
2.13k
  return Status::OK();
91
2.13k
}
92
93
150
int DBImpl::IsFileDeletionsEnabled() const {
94
150
  return disable_delete_obsolete_files_;
95
150
}
96
97
Status DBImpl::GetLiveFiles(std::vector<std::string> &ret,
98
    uint64_t *manifest_file_size,
99
2.09k
    bool flush_memtable) {
100
101
2.09k
  *manifest_file_size = 0;
102
103
2.09k
  mutex_.Lock();
104
105
2.09k
  if (flush_memtable) {
106
    // flush all dirty data to disk.
107
2.08k
    Status status;
108
2.09k
    for (auto cfd : *versions_->GetColumnFamilySet()) {
109
2.09k
      if (cfd->IsDropped()) {
110
0
        continue;
111
0
      }
112
2.09k
      cfd->Ref();
113
2.09k
      mutex_.Unlock();
114
2.09k
      status = FlushMemTable(cfd, FlushOptions());
115
2.09k
      TEST_SYNC_POINT("DBImpl::GetLiveFiles:1");
116
2.09k
      TEST_SYNC_POINT("DBImpl::GetLiveFiles:2");
117
2.09k
      mutex_.Lock();
118
2.09k
      cfd->Unref();
119
2.09k
      if (!status.ok()) {
120
0
        break;
121
0
      }
122
2.09k
    }
123
2.08k
    versions_->GetColumnFamilySet()->FreeDeadColumnFamilies();
124
125
2.08k
    if (!status.ok()) {
126
0
      mutex_.Unlock();
127
0
      RLOG(InfoLogLevel::ERROR_LEVEL, db_options_.info_log,
128
0
          "Cannot Flush data %s\n", status.ToString().c_str());
129
0
      return status;
130
0
    }
131
2.08k
  }
132
133
  // Make a set of all of the live *.sst files
134
2.09k
  std::vector<FileDescriptor> live;
135
2.11k
  for (auto cfd : *versions_->GetColumnFamilySet()) {
136
2.11k
    if (cfd->IsDropped()) {
137
0
      continue;
138
0
    }
139
2.11k
    cfd->current()->AddLiveFiles(&live);
140
2.11k
  }
141
142
2.09k
  ret.clear();
143
  // For each block-based split SST table we expect one base file and one data file.
144
  // So, we reserve space in `ret` for this number of SST files.
145
  // Since we will be using block-based split SST for YB, we don't care about reserving more
146
  // memory for other types of SST, which are still supported as a legacy functionality.
147
2.09k
  ret.reserve(live.size() * 2 + 2); // *.sst + *.sst.sblock + CURRENT + MANIFEST
148
149
  // create names of the live files. The names are not absolute
150
  // paths, instead they are relative to dbname_;
151
2.64k
  for (auto live_file : live) {
152
2.64k
    const std::string base_fname = MakeTableFileName("", live_file.GetNumber());
153
2.64k
    ret.push_back(base_fname);
154
2.64k
    if (live_file.total_file_size > live_file.base_file_size) {
155
2.64k
      ret.push_back(TableBaseToDataFileName(base_fname));
156
2.64k
    }
157
2.64k
  }
158
159
2.09k
  ret.push_back(CurrentFileName(""));
160
2.09k
  ret.push_back(DescriptorFileName("", versions_->manifest_file_number()));
161
162
  // find length of manifest file while holding the mutex lock
163
2.09k
  *manifest_file_size = versions_->manifest_file_size();
164
165
2.09k
  mutex_.Unlock();
166
2.09k
  return Status::OK();
167
2.09k
}
168
169
2.10k
Status DBImpl::GetSortedWalFiles(VectorLogPtr* files) {
170
2.10k
  return wal_manager_.GetSortedWalFiles(files);
171
2.10k
}
172
173
} // namespace rocksdb
174
175
#endif  // ROCKSDB_LITE