| 225 | bool WALIterator::Valid() const { return (batch_iter_ && batch_iter_->Valid()) || (iter_ && iter_->Valid()); } |
| 226 | |
| 227 | void WALIterator::nextBatch() { |
| 228 | if (!iter_ || !iter_->Valid()) { |
| 229 | Reset(); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | auto batch = iter_->GetBatch(); |
| 234 | if (batch.sequence != next_batch_seq_ || !batch.writeBatchPtr) { |
| 235 | Reset(); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | extractor_.Clear(); |
| 240 | |
| 241 | auto s = batch.writeBatchPtr->Iterate(&extractor_); |
| 242 | if (!s.ok()) { |
| 243 | Reset(); |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | next_batch_seq_ += batch.writeBatchPtr->Count(); |
| 248 | batch_iter_ = std::make_unique<WALBatchExtractor::Iter>(extractor_.GetIter()); |
| 249 | } |
| 250 | |
| 251 | void WALIterator::Seek(rocksdb::SequenceNumber seq) { |
| 252 | if (slot_range_.IsValid() && !storage_->IsSlotIdEncoded()) { |