@@ -21,7 +21,6 @@ TransactionLogIteratorImpl::TransactionLogIteratorImpl(
21
21
files_(std::move(files)),
22
22
started_(false ),
23
23
isValid_(false ),
24
- is_obsolete_(false ),
25
24
currentFileIndex_(0 ),
26
25
currentBatchSeq_(0 ),
27
26
currentLastSeq_(0 ),
@@ -70,15 +69,14 @@ bool TransactionLogIteratorImpl::Valid() {
70
69
return started_ && isValid_;
71
70
}
72
71
73
- bool TransactionLogIteratorImpl::RestrictedRead (Slice* record,
74
- std::string* scratch) {
75
- bool ret = currentLogReader_-> ReadRecord (record, scratch);
76
-
77
- if (!reporter_. last_status . ok ()) {
78
- currentStatus_ = reporter_. last_status ;
72
+ bool TransactionLogIteratorImpl::RestrictedRead (
73
+ Slice* record,
74
+ std::string* scratch) {
75
+ // Don't read if no more complete entries to read from logs
76
+ if (currentLastSeq_ >= dbimpl_-> GetLatestSequenceNumber ()) {
77
+ return false ;
79
78
}
80
-
81
- return ret;
79
+ return currentLogReader_->ReadRecord (record, scratch);
82
80
}
83
81
84
82
void TransactionLogIteratorImpl::SeekToStartSequence (
@@ -88,7 +86,6 @@ void TransactionLogIteratorImpl::SeekToStartSequence(
88
86
Slice record;
89
87
started_ = false ;
90
88
isValid_ = false ;
91
- is_obsolete_ = false ;
92
89
if (files_->size () <= startFileIndex) {
93
90
return ;
94
91
}
@@ -97,18 +94,6 @@ void TransactionLogIteratorImpl::SeekToStartSequence(
97
94
currentStatus_ = s;
98
95
return ;
99
96
}
100
- auto latest_seq_num = dbimpl_->GetLatestSequenceNumber ();
101
- if (startingSequenceNumber_ > latest_seq_num) {
102
- if (strict) {
103
- currentStatus_ = Status::Corruption (" Gap in sequence number. Could not "
104
- " seek to required sequence number" );
105
- reporter_.Info (currentStatus_.ToString ().c_str ());
106
- } else {
107
- // isValid_ is false;
108
- return ;
109
- }
110
- }
111
-
112
97
while (RestrictedRead (&record, &scratch)) {
113
98
if (record.size () < 12 ) {
114
99
reporter_.Corruption (
@@ -138,11 +123,11 @@ void TransactionLogIteratorImpl::SeekToStartSequence(
138
123
// only file. Otherwise log the error and let the iterator return next entry
139
124
// If strict is set, we want to seek exactly till the start sequence and it
140
125
// should have been present in the file we scanned above
141
- if (strict || files_-> size () == 1 ) {
126
+ if (strict) {
142
127
currentStatus_ = Status::Corruption (" Gap in sequence number. Could not "
143
128
" seek to required sequence number" );
144
129
reporter_.Info (currentStatus_.ToString ().c_str ());
145
- } else {
130
+ } else if (files_-> size () != 1 ) {
146
131
currentStatus_ = Status::Corruption (" Start sequence was not found, "
147
132
" skipping to the next available" );
148
133
reporter_.Info (currentStatus_.ToString ().c_str ());
@@ -164,30 +149,11 @@ void TransactionLogIteratorImpl::NextImpl(bool internal) {
164
149
// Runs every time until we can seek to the start sequence
165
150
return SeekToStartSequence ();
166
151
}
167
-
168
- is_obsolete_ = false ;
169
- auto latest_seq_num = dbimpl_->GetLatestSequenceNumber ();
170
- if (currentLastSeq_ >= latest_seq_num) {
171
- isValid_ = false ;
172
- return ;
173
- }
174
-
175
- bool first = true ;
176
- while (currentFileIndex_ < files_->size ()) {
177
- if (!first) {
178
- Status status =OpenLogReader (files_->at (currentFileIndex_).get ());
179
- if (!status.ok ()) {
180
- isValid_ = false ;
181
- currentStatus_ = status;
182
- return ;
183
- }
184
- }
185
- first = false ;
152
+ while (true ) {
186
153
assert (currentLogReader_);
187
154
if (currentLogReader_->IsEOF ()) {
188
155
currentLogReader_->UnmarkEOF ();
189
156
}
190
-
191
157
while (RestrictedRead (&record, &scratch)) {
192
158
if (record.size () < 12 ) {
193
159
reporter_.Corruption (
@@ -205,14 +171,26 @@ void TransactionLogIteratorImpl::NextImpl(bool internal) {
205
171
return ;
206
172
}
207
173
}
174
+
208
175
// Open the next file
209
- ++currentFileIndex_;
176
+ if (currentFileIndex_ < files_->size () - 1 ) {
177
+ ++currentFileIndex_;
178
+ Status status =OpenLogReader (files_->at (currentFileIndex_).get ());
179
+ if (!status.ok ()) {
180
+ isValid_ = false ;
181
+ currentStatus_ = status;
182
+ return ;
183
+ }
184
+ } else {
185
+ isValid_ = false ;
186
+ if (currentLastSeq_ == dbimpl_->GetLatestSequenceNumber ()) {
187
+ currentStatus_ = Status::OK ();
188
+ } else {
189
+ currentStatus_ = Status::Corruption (" NO MORE DATA LEFT" );
190
+ }
191
+ return ;
192
+ }
210
193
}
211
-
212
- // Read all the files but cannot find next record expected.
213
- // TODO(sdong): support to auto fetch new log files from DB and continue.
214
- isValid_ = false ;
215
- is_obsolete_ = true ;
216
194
}
217
195
218
196
bool TransactionLogIteratorImpl::IsBatchExpected (
0 commit comments