YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/transaction_log.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
21
#ifndef STORAGE_ROCKSDB_INCLUDE_TRANSACTION_LOG_ITERATOR_H_
22
#define STORAGE_ROCKSDB_INCLUDE_TRANSACTION_LOG_ITERATOR_H_
23
24
#include "yb/rocksdb/status.h"
25
#include "yb/rocksdb/types.h"
26
#include "yb/rocksdb/write_batch.h"
27
#include <memory>
28
#include <vector>
29
30
namespace rocksdb {
31
32
class LogFile;
33
typedef std::vector<std::unique_ptr<LogFile>> VectorLogPtr;
34
35
enum  WalFileType {
36
  /* Indicates that WAL file is in archive directory. WAL files are moved from
37
   * the main db directory to archive directory once they are not live and stay
38
   * there until cleaned up. Files are cleaned depending on archive size
39
   * (Options::WAL_size_limit_MB) and time since last cleaning
40
   * (Options::WAL_ttl_seconds).
41
   */
42
  kArchivedLogFile = 0,
43
44
  /* Indicates that WAL file is live and resides in the main db directory */
45
  kAliveLogFile = 1
46
} ;
47
48
class LogFile {
49
 public:
50
305
  LogFile() {}
51
305
  virtual ~LogFile() {}
52
53
  // Returns log file's pathname relative to the main db dir
54
  // Eg. For a live-log-file = /000003.log
55
  //     For an archived-log-file = /archive/000003.log
56
  virtual std::string PathName() const = 0;
57
58
59
  // Primary identifier for log file.
60
  // This is directly proportional to creation time of the log file
61
  virtual uint64_t LogNumber() const = 0;
62
63
  // Log file can be either alive or archived
64
  virtual WalFileType Type() const = 0;
65
66
  // Starting sequence number of writebatch written in this log file
67
  virtual SequenceNumber StartSequence() const = 0;
68
69
  // Size of log file on disk in Bytes
70
  virtual uint64_t SizeFileBytes() const = 0;
71
};
72
73
struct BatchResult {
74
  SequenceNumber sequence = 0;
75
  std::unique_ptr<WriteBatch> writeBatchPtr;
76
77
  // Add empty __ctor and __dtor for the rule of five
78
  // However, preserve the original semantics and prohibit copying
79
  // as the unique_ptr member does not copy.
80
2.73k
  BatchResult() {}
81
82
2.73k
  ~BatchResult() {}
83
84
  BatchResult(const BatchResult&) = delete;
85
86
  BatchResult& operator=(const BatchResult&) = delete;
87
88
  BatchResult(BatchResult&& bResult)
89
      : sequence(std::move(bResult.sequence)),
90
0
        writeBatchPtr(std::move(bResult.writeBatchPtr)) {}
91
92
2.69k
  BatchResult& operator=(BatchResult&& bResult) {
93
2.69k
    sequence = std::move(bResult.sequence);
94
2.69k
    writeBatchPtr = std::move(bResult.writeBatchPtr);
95
2.69k
    return *this;
96
2.69k
  }
97
};
98
99
// A TransactionLogIterator is used to iterate over the transactions in a db.
100
// One run of the iterator is continuous, i.e. the iterator will stop at the
101
// beginning of any gap in sequences
102
class TransactionLogIterator {
103
 public:
104
50
  TransactionLogIterator() {}
105
50
  virtual ~TransactionLogIterator() {}
106
107
  // An iterator is either positioned at a WriteBatch or not valid.
108
  // This method returns true if the iterator is valid.
109
  // Can read data from a valid iterator.
110
  virtual bool Valid() = 0;
111
112
  // Moves the iterator to the next WriteBatch.
113
  // REQUIRES: Valid() to be true.
114
  virtual void Next() = 0;
115
116
  // Returns ok if the iterator is valid.
117
  // Returns the Error when something has gone wrong.
118
  virtual Status status() = 0;
119
120
  // If valid return's the current write_batch and the sequence number of the
121
  // earliest transaction contained in the batch.
122
  // ONLY use if Valid() is true and status() is OK.
123
  virtual BatchResult GetBatch() = 0;
124
125
  // The read options for TransactionLogIterator.
126
  struct ReadOptions {
127
    // If true, all data read from underlying storage will be
128
    // verified against corresponding checksums.
129
    // Default: true
130
    bool verify_checksums_;
131
132
50
    ReadOptions() : verify_checksums_(true) {}
133
134
    explicit ReadOptions(bool verify_checksums)
135
0
        : verify_checksums_(verify_checksums) {}
136
  };
137
};
138
} //  namespace rocksdb
139
140
#endif  // STORAGE_ROCKSDB_INCLUDE_TRANSACTION_LOG_ITERATOR_H_