]>
git.proxmox.com Git - ceph.git/blob - 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).
10 #include "rocksdb/status.h"
11 #include "rocksdb/types.h"
12 #include "rocksdb/write_batch.h"
14 namespace ROCKSDB_NAMESPACE
{
17 typedef std::vector
<std::unique_ptr
<LogFile
>> VectorLogPtr
;
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).
28 /* Indicates that WAL file is live and resides in the main db directory */
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;
42 // Primary identifier for log file.
43 // This is directly proportional to creation time of the log file
44 virtual uint64_t LogNumber() const = 0;
46 // Log file can be either alive or archived
47 virtual WalFileType
Type() const = 0;
49 // Starting sequence number of writebatch written in this log file
50 virtual SequenceNumber
StartSequence() const = 0;
52 // Size of log file on disk in Bytes
53 virtual uint64_t SizeFileBytes() const = 0;
57 SequenceNumber sequence
= 0;
58 std::unique_ptr
<WriteBatch
> writeBatchPtr
;
60 // Add empty __ctor and __dtor for the rule of five
61 // However, preserve the original semantics and prohibit copying
62 // as the std::unique_ptr member does not copy.
67 BatchResult(const BatchResult
&) = delete;
69 BatchResult
& operator=(const BatchResult
&) = delete;
71 BatchResult(BatchResult
&& bResult
)
72 : sequence(std::move(bResult
.sequence
)),
73 writeBatchPtr(std::move(bResult
.writeBatchPtr
)) {}
75 BatchResult
& operator=(BatchResult
&& bResult
) {
76 sequence
= std::move(bResult
.sequence
);
77 writeBatchPtr
= std::move(bResult
.writeBatchPtr
);
82 // A TransactionLogIterator is used to iterate over the transactions in a db.
83 // One run of the iterator is continuous, i.e. the iterator will stop at the
84 // beginning of any gap in sequences
85 class TransactionLogIterator
{
87 TransactionLogIterator() {}
88 virtual ~TransactionLogIterator() {}
90 // An iterator is either positioned at a WriteBatch or not valid.
91 // This method returns true if the iterator is valid.
92 // Can read data from a valid iterator.
93 virtual bool Valid() = 0;
95 // Moves the iterator to the next WriteBatch.
96 // REQUIRES: Valid() to be true.
97 virtual void Next() = 0;
99 // Returns ok if the iterator is valid.
100 // Returns the Error when something has gone wrong.
101 virtual Status
status() = 0;
103 // If valid return's the current write_batch and the sequence number of the
104 // earliest transaction contained in the batch.
105 // ONLY use if Valid() is true and status() is OK.
106 virtual BatchResult
GetBatch() = 0;
108 // The read options for TransactionLogIterator.
110 // If true, all data read from underlying storage will be
111 // verified against corresponding checksums.
113 bool verify_checksums_
;
115 ReadOptions() : verify_checksums_(true) {}
117 explicit ReadOptions(bool verify_checksums
)
118 : verify_checksums_(verify_checksums
) {}
121 } // namespace ROCKSDB_NAMESPACE