Skip to content

Commit 2b95dc1

Browse files
committed
Revert "Fix bad merge of D16791 and D16767"
This reverts commit 839c8ec.
1 parent 5ba028c commit 2b95dc1

File tree

5 files changed

+32
-107
lines changed

5 files changed

+32
-107
lines changed

db/db_test.cc

+3-30
Original file line numberDiff line numberDiff line change
@@ -4543,43 +4543,16 @@ TEST(DBTest, TransactionLogIterator) {
45434543
{
45444544
auto iter = OpenTransactionLogIter(0);
45454545
ExpectRecords(3, iter);
4546-
assert(!iter->IsObsolete());
4547-
iter->Next();
4548-
assert(!iter->Valid());
4549-
assert(!iter->IsObsolete());
4550-
assert(iter->status().ok());
4551-
4552-
Reopen(&options);
4553-
env_->SleepForMicroseconds(2 * 1000 * 1000);
4546+
}
4547+
Reopen(&options);
4548+
env_->SleepForMicroseconds(2 * 1000 * 1000);{
45544549
Put("key4", DummyString(1024));
45554550
Put("key5", DummyString(1024));
45564551
Put("key6", DummyString(1024));
4557-
4558-
iter->Next();
4559-
assert(!iter->Valid());
4560-
assert(iter->IsObsolete());
4561-
assert(iter->status().ok());
45624552
}
45634553
{
45644554
auto iter = OpenTransactionLogIter(0);
45654555
ExpectRecords(6, iter);
4566-
assert(!iter->IsObsolete());
4567-
iter->Next();
4568-
assert(!iter->Valid());
4569-
assert(!iter->IsObsolete());
4570-
assert(iter->status().ok());
4571-
4572-
Put("key7", DummyString(1024));
4573-
iter->Next();
4574-
assert(iter->Valid());
4575-
assert(iter->status().ok());
4576-
4577-
dbfull()->Flush(FlushOptions());
4578-
Put("key8", DummyString(1024));
4579-
iter->Next();
4580-
assert(!iter->Valid());
4581-
assert(iter->IsObsolete());
4582-
assert(iter->status().ok());
45834556
}
45844557
} while (ChangeCompactOptions());
45854558
}

db/transaction_log_impl.cc

+28-50
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ TransactionLogIteratorImpl::TransactionLogIteratorImpl(
2121
files_(std::move(files)),
2222
started_(false),
2323
isValid_(false),
24-
is_obsolete_(false),
2524
currentFileIndex_(0),
2625
currentBatchSeq_(0),
2726
currentLastSeq_(0),
@@ -70,15 +69,14 @@ bool TransactionLogIteratorImpl::Valid() {
7069
return started_ && isValid_;
7170
}
7271

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;
7978
}
80-
81-
return ret;
79+
return currentLogReader_->ReadRecord(record, scratch);
8280
}
8381

8482
void TransactionLogIteratorImpl::SeekToStartSequence(
@@ -88,7 +86,6 @@ void TransactionLogIteratorImpl::SeekToStartSequence(
8886
Slice record;
8987
started_ = false;
9088
isValid_ = false;
91-
is_obsolete_ = false;
9289
if (files_->size() <= startFileIndex) {
9390
return;
9491
}
@@ -97,18 +94,6 @@ void TransactionLogIteratorImpl::SeekToStartSequence(
9794
currentStatus_ = s;
9895
return;
9996
}
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-
11297
while (RestrictedRead(&record, &scratch)) {
11398
if (record.size() < 12) {
11499
reporter_.Corruption(
@@ -138,11 +123,11 @@ void TransactionLogIteratorImpl::SeekToStartSequence(
138123
// only file. Otherwise log the error and let the iterator return next entry
139124
// If strict is set, we want to seek exactly till the start sequence and it
140125
// should have been present in the file we scanned above
141-
if (strict || files_->size() == 1) {
126+
if (strict) {
142127
currentStatus_ = Status::Corruption("Gap in sequence number. Could not "
143128
"seek to required sequence number");
144129
reporter_.Info(currentStatus_.ToString().c_str());
145-
} else {
130+
} else if (files_->size() != 1) {
146131
currentStatus_ = Status::Corruption("Start sequence was not found, "
147132
"skipping to the next available");
148133
reporter_.Info(currentStatus_.ToString().c_str());
@@ -164,30 +149,11 @@ void TransactionLogIteratorImpl::NextImpl(bool internal) {
164149
// Runs every time until we can seek to the start sequence
165150
return SeekToStartSequence();
166151
}
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) {
186153
assert(currentLogReader_);
187154
if (currentLogReader_->IsEOF()) {
188155
currentLogReader_->UnmarkEOF();
189156
}
190-
191157
while (RestrictedRead(&record, &scratch)) {
192158
if (record.size() < 12) {
193159
reporter_.Corruption(
@@ -205,14 +171,26 @@ void TransactionLogIteratorImpl::NextImpl(bool internal) {
205171
return;
206172
}
207173
}
174+
208175
// 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+
}
210193
}
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;
216194
}
217195

218196
bool TransactionLogIteratorImpl::IsBatchExpected(

db/transaction_log_impl.h

-5
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ namespace rocksdb {
1919
struct LogReporter : public log::Reader::Reporter {
2020
Env* env;
2121
Logger* info_log;
22-
Status last_status;
2322
virtual void Corruption(size_t bytes, const Status& s) {
24-
last_status = s;
2523
Log(info_log, "dropping %zu bytes; %s", bytes, s.ToString().c_str());
2624
}
2725
virtual void Info(const char* s) {
@@ -76,8 +74,6 @@ class TransactionLogIteratorImpl : public TransactionLogIterator {
7674

7775
virtual bool Valid();
7876

79-
virtual bool IsObsolete() override { return is_obsolete_; }
80-
8177
virtual void Next();
8278

8379
virtual Status status();
@@ -93,7 +89,6 @@ class TransactionLogIteratorImpl : public TransactionLogIterator {
9389
std::unique_ptr<VectorLogPtr> files_;
9490
bool started_;
9591
bool isValid_; // not valid when it starts of.
96-
bool is_obsolete_;
9792
Status currentStatus_;
9893
size_t currentFileIndex_;
9994
std::unique_ptr<WriteBatch> currentBatch_;

include/rocksdb/transaction_log.h

-6
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ class TransactionLogIterator {
7373
// Can read data from a valid iterator.
7474
virtual bool Valid() = 0;
7575

76-
// IsObsolete() returns true if new log files were created. This usually
77-
// means that the user needs to close the current iterator and create a new
78-
// one to get the newest updates. It should happen only when mem tables are
79-
// flushed.
80-
virtual bool IsObsolete() = 0;
81-
8276
// Moves the iterator to the next WriteBatch.
8377
// REQUIRES: Valid() to be true.
8478
virtual void Next() = 0;

tools/db_repl_stress.cc

+1-16
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,15 @@ static void ReplicationThreadBody(void* arg) {
6767
}
6868
}
6969
fprintf(stderr, "Refreshing iterator\n");
70-
for (; !iter->IsObsolete(); iter->Next()) {
71-
if (!iter->Valid()) {
72-
if (t->stop.Acquire_Load() == nullptr) {
73-
return;
74-
}
75-
// need to wait for new rows.
76-
continue;
77-
}
78-
70+
for(;iter->Valid(); iter->Next(), t->no_read++, currentSeqNum++) {
7971
BatchResult res = iter->GetBatch();
80-
if (!iter->status().ok()) {
81-
fprintf(stderr, "Corruption reported when reading seq no. b/w %ld",
82-
static_cast<uint64_t>(currentSeqNum));
83-
exit(1);
84-
}
8572
if (res.sequence != currentSeqNum) {
8673
fprintf(stderr,
8774
"Missed a seq no. b/w %ld and %ld\n",
8875
(long)currentSeqNum,
8976
(long)res.sequence);
9077
exit(1);
9178
}
92-
t->no_read++;
93-
currentSeqNum++;
9479
}
9580
}
9681
}

0 commit comments

Comments
 (0)