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

reuse scratch buffer in transaction_log_reader #5702

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions db/transaction_log_impl.cc
Expand Up @@ -78,19 +78,16 @@ Status TransactionLogIteratorImpl::status() { return current_status_; }

bool TransactionLogIteratorImpl::Valid() { return started_ && is_valid_; }

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

void TransactionLogIteratorImpl::SeekToStartSequence(uint64_t start_file_index,
bool strict) {
std::string scratch;
Slice record;
started_ = false;
is_valid_ = false;
Expand All @@ -104,7 +101,7 @@ void TransactionLogIteratorImpl::SeekToStartSequence(uint64_t start_file_index,
reporter_.Info(current_status_.ToString().c_str());
return;
}
while (RestrictedRead(&record, &scratch)) {
while (RestrictedRead(&record)) {
if (record.size() < WriteBatchInternal::kHeader) {
reporter_.Corruption(
record.size(), Status::Corruption("very small log record"));
Expand Down Expand Up @@ -155,7 +152,6 @@ void TransactionLogIteratorImpl::Next() {
}

void TransactionLogIteratorImpl::NextImpl(bool internal) {
std::string scratch;
Slice record;
is_valid_ = false;
if (!internal && !started_) {
Expand All @@ -167,7 +163,7 @@ void TransactionLogIteratorImpl::NextImpl(bool internal) {
if (current_log_reader_->IsEOF()) {
current_log_reader_->UnmarkEOF();
}
while (RestrictedRead(&record, &scratch)) {
while (RestrictedRead(&record)) {
if (record.size() < WriteBatchInternal::kHeader) {
reporter_.Corruption(
record.size(), Status::Corruption("very small log record"));
Expand Down
3 changes: 2 additions & 1 deletion db/transaction_log_impl.h
Expand Up @@ -86,6 +86,7 @@ class TransactionLogIteratorImpl : public TransactionLogIterator {
size_t current_file_index_;
std::unique_ptr<WriteBatch> current_batch_;
std::unique_ptr<log::Reader> current_log_reader_;
std::string scratch_;
Status OpenLogFile(const LogFile* log_file,
std::unique_ptr<SequentialFileReader>* file);

Expand All @@ -107,7 +108,7 @@ class TransactionLogIteratorImpl : public TransactionLogIterator {
VersionSet const* const versions_;
const bool seq_per_batch_;
// Reads from transaction log only if the writebatch record has been written
bool RestrictedRead(Slice* record, std::string* scratch);
bool RestrictedRead(Slice* record);
// Seeks to startingSequenceNumber reading from startFileIndex in files_.
// If strict is set,then must get a batch starting with startingSequenceNumber
void SeekToStartSequence(uint64_t start_file_index = 0, bool strict = false);
Expand Down