mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-30 04:41:49 +00:00
eae832740b
Summary: There are a number of fixes in this PR (with most bugs found via the added stress tests): 1. Re-enable reseek optimization. This was initially disabled to avoid infinite loops in https://github.com/facebook/rocksdb/pull/3955 but this can be resolved by remembering not to reseek after a reseek has already been done. This problem only affects forward iteration in `DBIter::FindNextUserEntryInternal`, as we already disable reseeking in `DBIter::FindValueForCurrentKeyUsingSeek`. 2. Verify that ReadOption.snapshot can be safely used for iterator creation. Some snapshots would not give correct results because snaphsot validation would not be enforced, breaking some assumptions in Prev() iteration. 3. In the non-snapshot Get() case, reads done at `LastPublishedSequence` may not be enough, because unprepared sequence numbers are not published. Use `std::max(published_seq, max_visible_seq)` to do lookups instead. 4. Add stress test to test reading own writes. 5. Minor bug in the allow_concurrent_memtable_write case where we forgot to pass in batch_per_txn_. 6. Minor performance optimization in `CalcMaxUnpreparedSequenceNumber` by assigning by reference instead of value. 7. Add some more comments everywhere. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5573 Differential Revision: D16276089 Pulled By: lth fbshipit-source-id: 18029c944eb427a90a87dee76ac1b23f37ec1ccb
54 lines
1.8 KiB
C++
54 lines
1.8 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#pragma once
|
|
|
|
#include "rocksdb/types.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
class ReadCallback {
|
|
public:
|
|
ReadCallback(SequenceNumber last_visible_seq)
|
|
: max_visible_seq_(last_visible_seq) {}
|
|
ReadCallback(SequenceNumber last_visible_seq, SequenceNumber min_uncommitted)
|
|
: max_visible_seq_(last_visible_seq), min_uncommitted_(min_uncommitted) {}
|
|
|
|
virtual ~ReadCallback() {}
|
|
|
|
// Will be called to see if the seq number visible; if not it moves on to
|
|
// the next seq number.
|
|
virtual bool IsVisibleFullCheck(SequenceNumber seq) = 0;
|
|
|
|
inline bool IsVisible(SequenceNumber seq) {
|
|
assert(min_uncommitted_ > 0);
|
|
assert(min_uncommitted_ >= kMinUnCommittedSeq);
|
|
if (seq < min_uncommitted_) { // handles seq == 0 as well
|
|
assert(seq <= max_visible_seq_);
|
|
return true;
|
|
} else if (max_visible_seq_ < seq) {
|
|
assert(seq != 0);
|
|
return false;
|
|
} else {
|
|
assert(seq != 0); // already handled in the first if-then clause
|
|
return IsVisibleFullCheck(seq);
|
|
}
|
|
}
|
|
|
|
inline SequenceNumber max_visible_seq() { return max_visible_seq_; }
|
|
|
|
// Refresh to a more recent visible seq
|
|
virtual void Refresh(SequenceNumber seq) { max_visible_seq_ = seq; }
|
|
|
|
protected:
|
|
// The max visible seq, it is usually the snapshot but could be larger if
|
|
// transaction has its own writes written to db.
|
|
SequenceNumber max_visible_seq_ = kMaxSequenceNumber;
|
|
// Any seq less than min_uncommitted_ is committed.
|
|
const SequenceNumber min_uncommitted_ = kMinUnCommittedSeq;
|
|
};
|
|
|
|
} // namespace rocksdb
|