YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/wal_manager.h
Line
Count
Source
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
#ifndef YB_ROCKSDB_DB_WAL_MANAGER_H
24
#define YB_ROCKSDB_DB_WAL_MANAGER_H
25
26
#pragma once
27
28
#include <algorithm>
29
#include <atomic>
30
#include <cassert>
31
#include <iterator>
32
#include <limits>
33
#include <memory>
34
#include <set>
35
#include <stdexcept>
36
#include <string>
37
#include <unordered_set>
38
#include <utility>
39
#include <vector>
40
41
#include "yb/rocksdb/db/version_edit.h"
42
#include "yb/rocksdb/env.h"
43
#include "yb/rocksdb/options.h"
44
#include "yb/rocksdb/port/port.h"
45
#include "yb/rocksdb/status.h"
46
#include "yb/rocksdb/transaction_log.h"
47
#include "yb/rocksdb/types.h"
48
#include "yb/rocksdb/util/arena.h"
49
#include "yb/rocksdb/util/mutable_cf_options.h"
50
51
namespace rocksdb {
52
53
#ifndef ROCKSDB_LITE
54
class WalManager {
55
 public:
56
  WalManager(const DBOptions& db_options, const EnvOptions& env_options)
57
      : db_options_(db_options),
58
        env_options_(env_options),
59
        env_(db_options.env),
60
341k
        purge_wal_files_last_run_(0) {}
61
62
  Status GetSortedWalFiles(VectorLogPtr* files);
63
64
  Status GetUpdatesSince(
65
      SequenceNumber seq_number, std::unique_ptr<TransactionLogIterator>* iter,
66
      const TransactionLogIterator::ReadOptions& read_options,
67
      VersionSet* version_set);
68
69
  void PurgeObsoleteWALFiles();
70
71
  void ArchiveWALFile(const std::string& fname, uint64_t number);
72
73
  Status TEST_ReadFirstRecord(const WalFileType type, const uint64_t number,
74
3
                              SequenceNumber* sequence) {
75
3
    return ReadFirstRecord(type, number, sequence);
76
3
  }
77
78
  Status TEST_ReadFirstLine(const std::string& fname,
79
1
                            SequenceNumber* sequence) {
80
1
    return ReadFirstLine(fname, sequence);
81
1
  }
82
83
 private:
84
  Status GetSortedWalsOfType(const std::string& path, VectorLogPtr* log_files, WalFileType type);
85
  // Requires: all_logs should be sorted with earliest log file first
86
  // Retains all log files in all_logs which contain updates with seq no.
87
  // Greater Than or Equal to the requested SequenceNumber.
88
  Status RetainProbableWalFiles(VectorLogPtr* all_logs, const SequenceNumber target);
89
90
  Status ReadFirstRecord(const WalFileType type, const uint64_t number,
91
                         SequenceNumber* sequence);
92
93
  Status ReadFirstLine(const std::string& fname, SequenceNumber* sequence);
94
95
  // ------- state from DBImpl ------
96
  const DBOptions& db_options_;
97
  const EnvOptions& env_options_;
98
  Env* env_;
99
100
  // ------- WalManager state -------
101
  // cache for ReadFirstRecord() calls
102
  std::unordered_map<uint64_t, SequenceNumber> read_first_record_cache_;
103
  port::Mutex read_first_record_cache_mutex_;
104
105
  // last time when PurgeObsoleteWALFiles ran.
106
  uint64_t purge_wal_files_last_run_;
107
108
  // obsolete files will be deleted every this seconds if ttl deletion is
109
  // enabled and archive size_limit is disabled.
110
  static const uint64_t kDefaultIntervalToDeleteObsoleteWAL = 600;
111
};
112
113
#endif  // ROCKSDB_LITE
114
}  // namespace rocksdb
115
116
#endif // YB_ROCKSDB_DB_WAL_MANAGER_H