]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/db/transaction_log_impl.h
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / db / transaction_log_impl.h
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
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).
7c673cae
FG
5#pragma once
6
7#ifndef ROCKSDB_LITE
8#include <vector>
9
10#include "db/log_reader.h"
11#include "db/version_set.h"
12#include "options/db_options.h"
13#include "port/port.h"
14#include "rocksdb/env.h"
15#include "rocksdb/options.h"
16#include "rocksdb/transaction_log.h"
17#include "rocksdb/types.h"
18#include "util/filename.h"
19
20namespace rocksdb {
21
22class LogFileImpl : public LogFile {
23 public:
24 LogFileImpl(uint64_t logNum, WalFileType logType, SequenceNumber startSeq,
25 uint64_t sizeBytes) :
26 logNumber_(logNum),
27 type_(logType),
28 startSequence_(startSeq),
29 sizeFileBytes_(sizeBytes) {
30 }
31
32 std::string PathName() const override {
33 if (type_ == kArchivedLogFile) {
34 return ArchivedLogFileName("", logNumber_);
35 }
36 return LogFileName("", logNumber_);
37 }
38
39 uint64_t LogNumber() const override { return logNumber_; }
40
41 WalFileType Type() const override { return type_; }
42
43 SequenceNumber StartSequence() const override { return startSequence_; }
44
45 uint64_t SizeFileBytes() const override { return sizeFileBytes_; }
46
47 bool operator < (const LogFile& that) const {
48 return LogNumber() < that.LogNumber();
49 }
50
51 private:
52 uint64_t logNumber_;
53 WalFileType type_;
54 SequenceNumber startSequence_;
55 uint64_t sizeFileBytes_;
56
57};
58
59class TransactionLogIteratorImpl : public TransactionLogIterator {
60 public:
61 TransactionLogIteratorImpl(
62 const std::string& dir, const ImmutableDBOptions* options,
63 const TransactionLogIterator::ReadOptions& read_options,
64 const EnvOptions& soptions, const SequenceNumber seqNum,
11fdf7f2
TL
65 std::unique_ptr<VectorLogPtr> files, VersionSet const* const versions,
66 const bool seq_per_batch);
7c673cae
FG
67
68 virtual bool Valid() override;
69
70 virtual void Next() override;
71
72 virtual Status status() override;
73
74 virtual BatchResult GetBatch() override;
75
76 private:
77 const std::string& dir_;
78 const ImmutableDBOptions* options_;
79 const TransactionLogIterator::ReadOptions read_options_;
80 const EnvOptions& soptions_;
494da23a 81 SequenceNumber starting_sequence_number_;
7c673cae
FG
82 std::unique_ptr<VectorLogPtr> files_;
83 bool started_;
494da23a
TL
84 bool is_valid_; // not valid when it starts of.
85 Status current_status_;
86 size_t current_file_index_;
87 std::unique_ptr<WriteBatch> current_batch_;
88 std::unique_ptr<log::Reader> current_log_reader_;
89 Status OpenLogFile(const LogFile* log_file,
90 std::unique_ptr<SequentialFileReader>* file);
7c673cae
FG
91
92 struct LogReporter : public log::Reader::Reporter {
93 Env* env;
94 Logger* info_log;
95 virtual void Corruption(size_t bytes, const Status& s) override {
96 ROCKS_LOG_ERROR(info_log, "dropping %" ROCKSDB_PRIszt " bytes; %s", bytes,
97 s.ToString().c_str());
98 }
99 virtual void Info(const char* s) { ROCKS_LOG_INFO(info_log, "%s", s); }
100 } reporter_;
101
494da23a
TL
102 SequenceNumber
103 current_batch_seq_; // sequence number at start of current batch
104 SequenceNumber current_last_seq_; // last sequence in the current batch
7c673cae
FG
105 // Used only to get latest seq. num
106 // TODO(icanadi) can this be just a callback?
107 VersionSet const* const versions_;
11fdf7f2 108 const bool seq_per_batch_;
7c673cae
FG
109 // Reads from transaction log only if the writebatch record has been written
110 bool RestrictedRead(Slice* record, std::string* scratch);
111 // Seeks to startingSequenceNumber reading from startFileIndex in files_.
112 // If strict is set,then must get a batch starting with startingSequenceNumber
494da23a 113 void SeekToStartSequence(uint64_t start_file_index = 0, bool strict = false);
7c673cae
FG
114 // Implementation of Next. SeekToStartSequence calls it internally with
115 // internal=true to let it find next entry even if it has to jump gaps because
116 // the iterator may start off from the first available entry but promises to
117 // be continuous after that
118 void NextImpl(bool internal = false);
119 // Check if batch is expected, else return false
494da23a 120 bool IsBatchExpected(const WriteBatch* batch, SequenceNumber expected_seq);
7c673cae
FG
121 // Update current batch if a continuous batch is found, else return false
122 void UpdateCurrentWriteBatch(const Slice& record);
123 Status OpenLogReader(const LogFile* file);
124};
125} // namespace rocksdb
126#endif // ROCKSDB_LITE