Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wal iterator): Optimized the illusion of triggering "TryAgain" [issue 9948] #9949

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions db/transaction_log_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ bool TransactionLogIteratorImpl::RestrictedRead(Slice* record) {
return current_log_reader_->ReadRecord(record, &scratch_);
}

bool TransactionLogIteratorImpl::RestrictedRead(Slice* record, SequenceNumber *sn) {
// Don't read if no more complete entries to read from logs
*sn = versions_->LastSequence();
if (current_last_seq_ >= *sn) {
return false;
}
return current_log_reader_->ReadRecord(record, &scratch_);
}

void TransactionLogIteratorImpl::SeekToStartSequence(uint64_t start_file_index,
bool strict) {
Slice record;
Expand Down Expand Up @@ -181,12 +190,13 @@ void TransactionLogIteratorImpl::NextImpl(bool internal) {
// Runs every time until we can seek to the start sequence
SeekToStartSequence();
}
SequenceNumber sn;
while(true) {
assert(current_log_reader_);
if (current_log_reader_->IsEOF()) {
current_log_reader_->UnmarkEOF();
}
while (RestrictedRead(&record)) {
while (RestrictedRead(&record, &sn)) {
if (record.size() < WriteBatchInternal::kHeader) {
reporter_.Corruption(
record.size(), Status::Corruption("very small log record"));
Expand Down Expand Up @@ -215,7 +225,7 @@ void TransactionLogIteratorImpl::NextImpl(bool internal) {
}
} else {
is_valid_ = false;
if (current_last_seq_ == versions_->LastSequence()) {
if (current_last_seq_ == sn) {
current_status_ = Status::OK();
} else {
const char* msg = "Create a new iterator to fetch the new tail.";
Expand Down
1 change: 1 addition & 0 deletions db/transaction_log_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class TransactionLogIteratorImpl : public TransactionLogIterator {
SequenceNumber current_last_seq_; // last sequence in the current batch
// Reads from transaction log only if the writebatch record has been written
bool RestrictedRead(Slice* record);
bool RestrictedRead(Slice* record, SequenceNumber* last_seq);
// Seeks to starting_sequence_number_ reading from start_file_index in files_.
// If strict is set, then must get a batch starting with
// starting_sequence_number_.
Expand Down