]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/transaction_log.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / include / rocksdb / transaction_log.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5
6 #pragma once
7
8 #include "rocksdb/status.h"
9 #include "rocksdb/types.h"
10 #include "rocksdb/write_batch.h"
11 #include <memory>
12 #include <vector>
13
14 namespace rocksdb {
15
16 class LogFile;
17 typedef std::vector<std::unique_ptr<LogFile>> VectorLogPtr;
18
19 enum WalFileType {
20 /* Indicates that WAL file is in archive directory. WAL files are moved from
21 * the main db directory to archive directory once they are not live and stay
22 * there until cleaned up. Files are cleaned depending on archive size
23 * (Options::WAL_size_limit_MB) and time since last cleaning
24 * (Options::WAL_ttl_seconds).
25 */
26 kArchivedLogFile = 0,
27
28 /* Indicates that WAL file is live and resides in the main db directory */
29 kAliveLogFile = 1
30 } ;
31
32 class LogFile {
33 public:
34 LogFile() {}
35 virtual ~LogFile() {}
36
37 // Returns log file's pathname relative to the main db dir
38 // Eg. For a live-log-file = /000003.log
39 // For an archived-log-file = /archive/000003.log
40 virtual std::string PathName() const = 0;
41
42
43 // Primary identifier for log file.
44 // This is directly proportional to creation time of the log file
45 virtual uint64_t LogNumber() const = 0;
46
47 // Log file can be either alive or archived
48 virtual WalFileType Type() const = 0;
49
50 // Starting sequence number of writebatch written in this log file
51 virtual SequenceNumber StartSequence() const = 0;
52
53 // Size of log file on disk in Bytes
54 virtual uint64_t SizeFileBytes() const = 0;
55 };
56
57 struct BatchResult {
58 SequenceNumber sequence = 0;
59 std::unique_ptr<WriteBatch> writeBatchPtr;
60
61 // Add empty __ctor and __dtor for the rule of five
62 // However, preserve the original semantics and prohibit copying
63 // as the unique_ptr member does not copy.
64 BatchResult() {}
65
66 ~BatchResult() {}
67
68 BatchResult(const BatchResult&) = delete;
69
70 BatchResult& operator=(const BatchResult&) = delete;
71
72 BatchResult(BatchResult&& bResult)
73 : sequence(std::move(bResult.sequence)),
74 writeBatchPtr(std::move(bResult.writeBatchPtr)) {}
75
76 BatchResult& operator=(BatchResult&& bResult) {
77 sequence = std::move(bResult.sequence);
78 writeBatchPtr = std::move(bResult.writeBatchPtr);
79 return *this;
80 }
81 };
82
83 // A TransactionLogIterator is used to iterate over the transactions in a db.
84 // One run of the iterator is continuous, i.e. the iterator will stop at the
85 // beginning of any gap in sequences
86 class TransactionLogIterator {
87 public:
88 TransactionLogIterator() {}
89 virtual ~TransactionLogIterator() {}
90
91 // An iterator is either positioned at a WriteBatch or not valid.
92 // This method returns true if the iterator is valid.
93 // Can read data from a valid iterator.
94 virtual bool Valid() = 0;
95
96 // Moves the iterator to the next WriteBatch.
97 // REQUIRES: Valid() to be true.
98 virtual void Next() = 0;
99
100 // Returns ok if the iterator is valid.
101 // Returns the Error when something has gone wrong.
102 virtual Status status() = 0;
103
104 // If valid return's the current write_batch and the sequence number of the
105 // earliest transaction contained in the batch.
106 // ONLY use if Valid() is true and status() is OK.
107 virtual BatchResult GetBatch() = 0;
108
109 // The read options for TransactionLogIterator.
110 struct ReadOptions {
111 // If true, all data read from underlying storage will be
112 // verified against corresponding checksums.
113 // Default: true
114 bool verify_checksums_;
115
116 ReadOptions() : verify_checksums_(true) {}
117
118 explicit ReadOptions(bool verify_checksums)
119 : verify_checksums_(verify_checksums) {}
120 };
121 };
122 } // namespace rocksdb