YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/job_context.h
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) 2011 The LevelDB Authors. All rights reserved.
21
// Use of this source code is governed by a BSD-style license that can be
22
// found in the LICENSE file. See the AUTHORS file for names of contributors.
23
24
#ifndef YB_ROCKSDB_DB_JOB_CONTEXT_H
25
#define YB_ROCKSDB_DB_JOB_CONTEXT_H
26
27
#pragma once
28
29
#include <string>
30
#include <vector>
31
32
#include "yb/rocksdb/db/column_family.h"
33
#include "yb/rocksdb/db/log_writer.h"
34
35
namespace rocksdb {
36
37
class MemTable;
38
39
struct JobContext {
40
3.28M
  inline bool HaveSomethingToDelete() const {
41
3.28M
    return full_scan_candidate_files.size() || 
sst_delete_files.size()1.59M
||
42
3.28M
           
log_delete_files.size()1.52M
||
manifest_delete_files.size()1.46M
||
43
3.28M
           
new_superversion != nullptr950k
||
superversions_to_free.size() > 0700k
||
44
3.28M
           
memtables_to_free.size() > 0582k
||
logs_to_free.size() > 0582k
;
45
3.28M
  }
46
47
  // Structure to store information for candidate files to delete.
48
  struct CandidateFileInfo {
49
    std::string file_name;
50
    uint32_t path_id;
51
    CandidateFileInfo(std::string name, uint32_t path)
52
6.05M
        : file_name(std::move(name)), path_id(path) {}
53
4.90M
    bool operator==(const CandidateFileInfo& other) const {
54
4.90M
      return file_name == other.file_name && 
path_id == other.path_id8.02k
;
55
4.90M
    }
56
  };
57
58
  // Unique job id
59
  int job_id;
60
61
  // a list of all files that we'll consider deleting
62
  // (every once in a while this is filled up with all files
63
  // in the DB directory)
64
  // (filled only if we're doing full scan)
65
  std::vector<CandidateFileInfo> full_scan_candidate_files;
66
67
  // the list of all live sst files that cannot be deleted
68
  std::vector<FileDescriptor> sst_live;
69
70
  // a list of sst files that we need to delete
71
  std::vector<FileMetaData*> sst_delete_files;
72
73
  // a list of log files that we need to delete
74
  std::vector<uint64_t> log_delete_files;
75
76
  // a list of manifest files that we need to delete
77
  std::vector<std::string> manifest_delete_files;
78
79
  // a list of memtables to be free
80
  autovector<MemTable*> memtables_to_free;
81
82
  autovector<SuperVersion*> superversions_to_free;
83
84
  autovector<log::Writer*> logs_to_free;
85
86
  SuperVersion* new_superversion;  // if nullptr no new superversion
87
88
  // the current manifest_file_number, log_number and prev_log_number
89
  // that corresponds to the set of files in 'live'.
90
  uint64_t manifest_file_number;
91
  uint64_t pending_manifest_file_number;
92
  uint64_t log_number;
93
  uint64_t prev_log_number;
94
95
1.85M
  explicit JobContext(int _job_id, bool create_superversion = false) {
96
1.85M
    job_id = _job_id;
97
1.85M
    manifest_file_number = 0;
98
1.85M
    pending_manifest_file_number = 0;
99
1.85M
    log_number = 0;
100
1.85M
    prev_log_number = 0;
101
1.85M
    new_superversion = create_superversion ? 
new SuperVersion()167k
:
nullptr1.69M
;
102
1.85M
  }
103
104
  // For non-empty JobContext Clean() has to be called at least once before
105
  // before destruction (see asserts in ~JobContext()). Should be called with
106
  // unlocked DB mutex. Destructor doesn't call Clean() to avoid accidentally
107
  // doing potentially slow Clean() with locked DB mutex.
108
1.85M
  void Clean() {
109
    // free pending memtables
110
1.85M
    for (auto m : memtables_to_free) {
111
2
      delete m;
112
2
    }
113
    // free superversions
114
1.85M
    for (auto s : superversions_to_free) {
115
83.5k
      delete s;
116
83.5k
    }
117
1.85M
    for (auto l : logs_to_free) {
118
20.1k
      delete l;
119
20.1k
    }
120
    // if new_superversion was not used, it will be non-nullptr and needs
121
    // to be freed here
122
1.85M
    delete new_superversion;
123
124
1.85M
    memtables_to_free.clear();
125
1.85M
    superversions_to_free.clear();
126
1.85M
    logs_to_free.clear();
127
1.85M
    new_superversion = nullptr;
128
1.85M
  }
129
130
1.85M
  ~JobContext() {
131
1.85M
    assert(memtables_to_free.size() == 0);
132
0
    assert(superversions_to_free.size() == 0);
133
0
    assert(new_superversion == nullptr);
134
0
    assert(logs_to_free.size() == 0);
135
1.85M
  }
136
};
137
138
}  // namespace rocksdb
139
140
#endif // YB_ROCKSDB_DB_JOB_CONTEXT_H