Skip to content

Commit

Permalink
V3.2 - Reinserting oplog hack for last record retrieval (#91)
Browse files Browse the repository at this point in the history
* Reinserting oplog hack for first record retrieval.

* Removed extra space.

* Added oplog hack for backward cursors as well.
  • Loading branch information
Roy Reznik authored and igorcanadi committed Aug 1, 2017
1 parent 038daba commit 422336c
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/rocks_record_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,19 +763,25 @@ namespace mongo {

std::unique_ptr<SeekableRecordCursor> RocksRecordStore::getCursor(OperationContext* txn,
bool forward) const {
if (_isOplog && forward) {
auto ru = RocksRecoveryUnit::getRocksRecoveryUnit(txn);
// If we already have a snapshot we don't know what it can see, unless we know no
// one else could be writing (because we hold an exclusive lock).
if (ru->hasSnapshot() && !txn->lockState()->isNoop() &&
!txn->lockState()->isCollectionLockedForMode(_ns, MODE_X)) {
throw WriteConflictException();
RecordId startIterator;
if (_isOplog) {
if (forward) {
auto ru = RocksRecoveryUnit::getRocksRecoveryUnit(txn);
// If we already have a snapshot we don't know what it can see, unless we know no
// one else could be writing (because we hold an exclusive lock).
if (ru->hasSnapshot() && !txn->lockState()->isNoop() &&
!txn->lockState()->isCollectionLockedForMode(_ns, MODE_X)) {
throw WriteConflictException();
}
ru->setOplogReadTill(_cappedVisibilityManager->oplogStartHack());
startIterator = _cappedOldestKeyHint;
} else {
startIterator = _cappedVisibilityManager->oplogStartHack();
}
ru->setOplogReadTill(_cappedVisibilityManager->oplogStartHack());
}

return stdx::make_unique<Cursor>(txn, _db, _prefix, _cappedVisibilityManager, forward,
_isCapped, _cappedOldestKeyHint);
_isCapped, startIterator);
}

Status RocksRecordStore::truncate(OperationContext* txn) {
Expand Down Expand Up @@ -1060,8 +1066,8 @@ namespace mongo {
_currentSequenceNumber =
RocksRecoveryUnit::getRocksRecoveryUnit(txn)->snapshot()->GetSequenceNumber();

if (!startIterator.isNull() && !_readUntilForOplog.isNull() && forward) {
// This is a hack to speed up first record retrieval from the oplog
if (!startIterator.isNull()) {
// This is a hack to speed up first/last record retrieval from the oplog
_needFirstSeek = false;
_lastLoc = startIterator;
iterator();
Expand Down

0 comments on commit 422336c

Please sign in to comment.