YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
1.61k
Status DBImpl::DisableFileDeletions() {
48
1.61k
  InstrumentedMutexLock l(&mutex_);
49
1.61k
  ++disable_delete_obsolete_files_;
50
1.61k
  if (disable_delete_obsolete_files_ == 1) {
51
1.52k
    RLOG(InfoLogLevel::INFO_LEVEL, db_options_.info_log,
52
1.52k
        "File Deletions Disabled");
53
85
  } else {
54
85
    RLOG(InfoLogLevel::WARN_LEVEL, db_options_.info_log,
55
85
        "File Deletions Disabled, but already disabled. Counter: %d",
56
85
        disable_delete_obsolete_files_);
57
85
  }
58
1.61k
  return Status::OK();
59
1.61k
}
60
61
1.55k
Status DBImpl::EnableFileDeletions(bool force) {
62
  // Job id == 0 means that this is not our background process, but rather
63
  // user thread
64
1.55k
  JobContext job_context(0);
65
1.55k
  bool should_purge_files = false;
66
1.55k
  {
67
1.55k
    InstrumentedMutexLock l(&mutex_);
68
1.55k
    if (force) {
69
      // if force, we need to enable file deletions right away
70
30
      disable_delete_obsolete_files_ = 0;
71
1.52k
    } else if (disable_delete_obsolete_files_ > 0) {
72
1.52k
      --disable_delete_obsolete_files_;
73
1.52k
    }
74
1.55k
    if (disable_delete_obsolete_files_ == 0) {
75
1.52k
      RLOG(InfoLogLevel::INFO_LEVEL, db_options_.info_log,
76
1.52k
          "File Deletions Enabled");
77
1.52k
      should_purge_files = true;
78
1.52k
      FindObsoleteFiles(&job_context, true);
79
30
    } 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
1.55k
  }
85
1.55k
  if (should_purge_files) {
86
1.52k
    PurgeObsoleteFiles(job_context);
87
1.52k
  }
88
1.55k
  job_context.Clean();
89
1.55k
  LogFlush(db_options_.info_log);
90
1.55k
  return Status::OK();
91
1.55k
}
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
1.51k
    bool flush_memtable) {
100
101
1.51k
  *manifest_file_size = 0;
102
103
1.51k
  mutex_.Lock();
104
105
1.51k
  if (flush_memtable) {
106
    // flush all dirty data to disk.
107
1.51k
    Status status;
108
1.52k
    for (auto cfd : *versions_->GetColumnFamilySet()) {
109
1.52k
      if (cfd->IsDropped()) {
110
0
        continue;
111
0
      }
112
1.52k
      cfd->Ref();
113
1.52k
      mutex_.Unlock();
114
1.52k
      status = FlushMemTable(cfd, FlushOptions());
115
1.52k
      TEST_SYNC_POINT("DBImpl::GetLiveFiles:1");
116
1.52k
      TEST_SYNC_POINT("DBImpl::GetLiveFiles:2");
117
1.52k
      mutex_.Lock();
118
1.52k
      cfd->Unref();
119
1.52k
      if (!status.ok()) {
120
0
        break;
121
0
      }
122
1.52k
    }
123
1.51k
    versions_->GetColumnFamilySet()->FreeDeadColumnFamilies();
124
125
1.51k
    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
1.51k
  }
132
133
  // Make a set of all of the live *.sst files
134
1.51k
  std::vector<FileDescriptor> live;
135
1.52k
  for (auto cfd : *versions_->GetColumnFamilySet()) {
136
1.52k
    if (cfd->IsDropped()) {
137
0
      continue;
138
0
    }
139
1.52k
    cfd->current()->AddLiveFiles(&live);
140
1.52k
  }
141
142
1.51k
  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
1.51k
  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
1.50k
  for (auto live_file : live) {
152
1.50k
    const std::string base_fname = MakeTableFileName("", live_file.GetNumber());
153
1.50k
    ret.push_back(base_fname);
154
1.50k
    if (live_file.total_file_size > live_file.base_file_size) {
155
1.50k
      ret.push_back(TableBaseToDataFileName(base_fname));
156
1.50k
    }
157
1.50k
  }
158
159
1.51k
  ret.push_back(CurrentFileName(""));
160
1.51k
  ret.push_back(DescriptorFileName("", versions_->manifest_file_number()));
161
162
  // find length of manifest file while holding the mutex lock
163
1.51k
  *manifest_file_size = versions_->manifest_file_size();
164
165
1.51k
  mutex_.Unlock();
166
1.51k
  return Status::OK();
167
1.51k
}
168
169
1.53k
Status DBImpl::GetSortedWalFiles(VectorLogPtr* files) {
170
1.53k
  return wal_manager_.GetSortedWalFiles(files);
171
1.53k
}
172
173
} // namespace rocksdb
174
175
#endif  // ROCKSDB_LITE