Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 786597 | Differences between
and this patch

Collapse All | Expand All

(-)a/sql/recover_module/btree.cc (-6 / +15 lines)
Lines 135-150 Link Here
135
              "Move the destructor to the .cc file if it's non-trival");
135
              "Move the destructor to the .cc file if it's non-trival");
136
#endif  // !DCHECK_IS_ON()
136
#endif  // !DCHECK_IS_ON()
137
137
138
LeafPageDecoder::LeafPageDecoder(DatabasePageReader* db_reader) noexcept
138
void LeafPageDecoder::Initialize(DatabasePageReader* db_reader) {
139
    : page_id_(db_reader->page_id()),
139
  DCHECK(db_reader);
140
      db_reader_(db_reader),
141
      cell_count_(ComputeCellCount(db_reader)),
142
      next_read_index_(0),
143
      last_record_size_(0) {
144
  DCHECK(IsOnValidPage(db_reader));
140
  DCHECK(IsOnValidPage(db_reader));
141
  page_id_ = db_reader->page_id();
142
  db_reader_ = db_reader;
143
  cell_count_ = ComputeCellCount(db_reader);
144
  next_read_index_ = 0;
145
  last_record_size_ = 0;
145
  DCHECK(DatabasePageReader::IsValidPageId(page_id_));
146
  DCHECK(DatabasePageReader::IsValidPageId(page_id_));
146
}
147
}
147
148
149
void LeafPageDecoder::Reset() {
150
  db_reader_ = nullptr;
151
  page_id_ = 0;
152
  cell_count_ = 0;
153
  next_read_index_ = 0;
154
  last_record_size_ = 0;
155
}
156
148
bool LeafPageDecoder::TryAdvance() {
157
bool LeafPageDecoder::TryAdvance() {
149
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
158
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
150
  DCHECK(CanAdvance());
159
  DCHECK(CanAdvance());
(-)a/sql/recover_module/btree.h (-4 / +13 lines)
Lines 102-108 Link Here
102
  //
102
  //
103
  // |db_reader| must have been used to read an inner page of a table B-tree.
103
  // |db_reader| must have been used to read an inner page of a table B-tree.
104
  // |db_reader| must outlive this instance.
104
  // |db_reader| must outlive this instance.
105
  explicit LeafPageDecoder(DatabasePageReader* db_reader) noexcept;
105
  explicit LeafPageDecoder() noexcept = default;
106
  ~LeafPageDecoder() noexcept = default;
106
  ~LeafPageDecoder() noexcept = default;
107
107
108
  LeafPageDecoder(const LeafPageDecoder&) = delete;
108
  LeafPageDecoder(const LeafPageDecoder&) = delete;
Lines 150-155 Link Here
150
  // read as long as CanAdvance() returns true.
150
  // read as long as CanAdvance() returns true.
151
  bool TryAdvance();
151
  bool TryAdvance();
152
152
153
  // Initialize with DatabasePageReader
154
  void Initialize(DatabasePageReader* db_reader);
155
156
  // Reset internal DatabasePageReader
157
  void Reset();
158
159
  // True if DatabasePageReader is valid
160
  bool IsValid() { return (db_reader_ != nullptr); }
161
153
  // True if the given reader may point to an inner page in a table B-tree.
162
  // True if the given reader may point to an inner page in a table B-tree.
154
  //
163
  //
155
  // The last ReadPage() call on |db_reader| must have succeeded.
164
  // The last ReadPage() call on |db_reader| must have succeeded.
Lines 163-176 Link Here
163
  static int ComputeCellCount(DatabasePageReader* db_reader);
172
  static int ComputeCellCount(DatabasePageReader* db_reader);
164
173
165
  // The number of the B-tree page this reader is reading.
174
  // The number of the B-tree page this reader is reading.
166
  const int64_t page_id_;
175
  int64_t page_id_;
167
  // Used to read the tree page.
176
  // Used to read the tree page.
168
  //
177
  //
169
  // Raw pointer usage is acceptable because this instance's owner is expected
178
  // Raw pointer usage is acceptable because this instance's owner is expected
170
  // to ensure that the DatabasePageReader outlives this.
179
  // to ensure that the DatabasePageReader outlives this.
171
  DatabasePageReader* const db_reader_;
180
  DatabasePageReader* db_reader_;
172
  // Caches the ComputeCellCount() value for this reader's page.
181
  // Caches the ComputeCellCount() value for this reader's page.
173
  const int cell_count_ = ComputeCellCount(db_reader_);
182
  int cell_count_;
174
183
175
  // The reader's cursor state.
184
  // The reader's cursor state.
176
  //
185
  //
(-)a/sql/recover_module/cursor.cc (-12 / +12 lines)
Lines 26-32 Link Here
26
int VirtualCursor::First() {
26
int VirtualCursor::First() {
27
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
27
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
28
  inner_decoders_.clear();
28
  inner_decoders_.clear();
29
  leaf_decoder_ = nullptr;
29
  leaf_decoder_.Reset();
30
30
31
  AppendPageDecoder(table_->root_page_id());
31
  AppendPageDecoder(table_->root_page_id());
32
  return Next();
32
  return Next();
Lines 36-53 Link Here
36
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
36
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
37
  record_reader_.Reset();
37
  record_reader_.Reset();
38
38
39
  while (!inner_decoders_.empty() || leaf_decoder_.get()) {
39
  while (!inner_decoders_.empty() || leaf_decoder_.IsValid()) {
40
    if (leaf_decoder_.get()) {
40
    if (leaf_decoder_.IsValid()) {
41
      if (!leaf_decoder_->CanAdvance()) {
41
      if (!leaf_decoder_.CanAdvance()) {
42
        // The leaf has been exhausted. Remove it from the DFS stack.
42
        // The leaf has been exhausted. Remove it from the DFS stack.
43
        leaf_decoder_ = nullptr;
43
        leaf_decoder_.Reset();
44
        continue;
44
        continue;
45
      }
45
      }
46
      if (!leaf_decoder_->TryAdvance())
46
      if (!leaf_decoder_.TryAdvance())
47
        continue;
47
        continue;
48
48
49
      if (!payload_reader_.Initialize(leaf_decoder_->last_record_size(),
49
      if (!payload_reader_.Initialize(leaf_decoder_.last_record_size(),
50
                                      leaf_decoder_->last_record_offset())) {
50
                                      leaf_decoder_.last_record_offset())) {
51
        continue;
51
        continue;
52
      }
52
      }
53
      if (!record_reader_.Initialize())
53
      if (!record_reader_.Initialize())
Lines 99-111 Link Here
99
int64_t VirtualCursor::RowId() {
99
int64_t VirtualCursor::RowId() {
100
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
100
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
101
  DCHECK(record_reader_.IsInitialized());
101
  DCHECK(record_reader_.IsInitialized());
102
  DCHECK(leaf_decoder_.get());
102
  DCHECK(leaf_decoder_.IsValid());
103
  return leaf_decoder_->last_record_rowid();
103
  return leaf_decoder_.last_record_rowid();
104
}
104
}
105
105
106
void VirtualCursor::AppendPageDecoder(int page_id) {
106
void VirtualCursor::AppendPageDecoder(int page_id) {
107
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
107
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
108
  DCHECK(leaf_decoder_.get() == nullptr)
108
  DCHECK(!leaf_decoder_.IsValid())
109
      << __func__
109
      << __func__
110
      << " must only be called when the current path has no leaf decoder";
110
      << " must only be called when the current path has no leaf decoder";
111
111
Lines 113-119 Link Here
113
    return;
113
    return;
114
114
115
  if (LeafPageDecoder::IsOnValidPage(&db_reader_)) {
115
  if (LeafPageDecoder::IsOnValidPage(&db_reader_)) {
116
    leaf_decoder_ = std::make_unique<LeafPageDecoder>(&db_reader_);
116
    leaf_decoder_.Initialize(&db_reader_);
117
    return;
117
    return;
118
  }
118
  }
119
119
(-)a/sql/recover_module/cursor.h (-1 / +1 lines)
Lines 129-135 Link Here
129
  std::vector<std::unique_ptr<InnerPageDecoder>> inner_decoders_;
129
  std::vector<std::unique_ptr<InnerPageDecoder>> inner_decoders_;
130
130
131
  // Decodes the leaf page containing records.
131
  // Decodes the leaf page containing records.
132
  std::unique_ptr<LeafPageDecoder> leaf_decoder_;
132
  LeafPageDecoder leaf_decoder_;
133
133
134
  SEQUENCE_CHECKER(sequence_checker_);
134
  SEQUENCE_CHECKER(sequence_checker_);
135
};
135
};
(-)a/sql/recover_module/pager.cc (-4 / +3 lines)
Lines 23-30 Link Here
23
              "ints are not appropriate for representing page IDs");
23
              "ints are not appropriate for representing page IDs");
24
24
25
DatabasePageReader::DatabasePageReader(VirtualTable* table)
25
DatabasePageReader::DatabasePageReader(VirtualTable* table)
26
    : page_data_(std::make_unique<uint8_t[]>(table->page_size())),
26
    : page_data_(), table_(table) {
27
      table_(table) {
28
  DCHECK(table != nullptr);
27
  DCHECK(table != nullptr);
29
  DCHECK(IsValidPageSize(table->page_size()));
28
  DCHECK(IsValidPageSize(table->page_size()));
30
}
29
}
Lines 57-64 Link Here
57
                    std::numeric_limits<int64_t>::max(),
56
                    std::numeric_limits<int64_t>::max(),
58
                "The |read_offset| computation above may overflow");
57
                "The |read_offset| computation above may overflow");
59
58
60
  int sqlite_status =
59
  int sqlite_status = RawRead(sqlite_file, read_size, read_offset,
61
      RawRead(sqlite_file, read_size, read_offset, page_data_.get());
60
                              const_cast<uint8_t*>(page_data_.data()));
62
61
63
  // |page_id_| needs to be set to kInvalidPageId if the read failed.
62
  // |page_id_| needs to be set to kInvalidPageId if the read failed.
64
  // Otherwise, future ReadPage() calls with the previous |page_id_| value
63
  // Otherwise, future ReadPage() calls with the previous |page_id_| value
(-)a/sql/recover_module/pager.h (-2 / +3 lines)
Lines 5-10 Link Here
5
#ifndef SQL_RECOVER_MODULE_PAGER_H_
5
#ifndef SQL_RECOVER_MODULE_PAGER_H_
6
#define SQL_RECOVER_MODULE_PAGER_H_
6
#define SQL_RECOVER_MODULE_PAGER_H_
7
7
8
#include <array>
8
#include <cstdint>
9
#include <cstdint>
9
#include <memory>
10
#include <memory>
10
11
Lines 70-76 Link Here
70
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
71
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
71
    DCHECK_NE(page_id_, kInvalidPageId)
72
    DCHECK_NE(page_id_, kInvalidPageId)
72
        << "Successful ReadPage() required before accessing pager state";
73
        << "Successful ReadPage() required before accessing pager state";
73
    return page_data_.get();
74
    return page_data_.data();
74
  }
75
  }
75
76
76
  // The number of bytes in the page read by the last ReadPage() call.
77
  // The number of bytes in the page read by the last ReadPage() call.
Lines 137-143 Link Here
137
  int page_id_ = kInvalidPageId;
138
  int page_id_ = kInvalidPageId;
138
  // Stores the bytes of the last page successfully read by ReadPage().
139
  // Stores the bytes of the last page successfully read by ReadPage().
139
  // The content is undefined if the last call to ReadPage() did not succeed.
140
  // The content is undefined if the last call to ReadPage() did not succeed.
140
  const std::unique_ptr<uint8_t[]> page_data_;
141
  const std::array<uint8_t, kMaxPageSize> page_data_;
141
  // Raw pointer usage is acceptable because this instance's owner is expected
142
  // Raw pointer usage is acceptable because this instance's owner is expected
142
  // to ensure that the VirtualTable outlives this.
143
  // to ensure that the VirtualTable outlives this.
143
  VirtualTable* const table_;
144
  VirtualTable* const table_;

Return to bug 786597