Skip to content

Commit

Permalink
Merge pull request mongodb-partners#102 from denis-protivenskii/oplog…
Browse files Browse the repository at this point in the history
…-hack-fix-master

Proper oplog hack fix
  • Loading branch information
igorsol committed Nov 27, 2017
2 parents 6d18772 + 67e9235 commit 0e02a95
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions src/rocks_record_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,16 +597,16 @@ namespace mongo {
_changeNumRecords(opCtx, -docsRemoved);
_increaseDataSize(opCtx, -sizeSaved);
wuow.commit();
}

if (iter->Valid()) {
auto oldestAliveRecordId = _makeRecordId(iter->key());
// we check if there's outstanding transaction that is older than
// oldestAliveRecordId. If there is, we should not skip deleting that record next
// time we clean up the capped collection. If there isn't, we know for certain this
// is the record we'll start out deletions from next time
if (!_cappedVisibilityManager->isCappedHidden(oldestAliveRecordId)) {
_cappedOldestKeyHint = oldestAliveRecordId;
if (iter->Valid()) {
auto oldestAliveRecordId = _makeRecordId(iter->key());
// we check if there's outstanding transaction that is older than
// oldestAliveRecordId. If there is, we should not skip deleting that record next
// time we clean up the capped collection. If there isn't, we know for certain this
// is the record we'll start out deletions from next time
if (!_cappedVisibilityManager->isCappedHidden(oldestAliveRecordId)) {
_cappedOldestKeyHint = oldestAliveRecordId;
}
}
}
}
Expand Down Expand Up @@ -769,20 +769,16 @@ namespace mongo {
std::unique_ptr<SeekableRecordCursor> RocksRecordStore::getCursor(OperationContext* opCtx,
bool forward) const {
RecordId startIterator;
if (_isOplog) {
if (forward) {
auto ru = RocksRecoveryUnit::getRocksRecoveryUnit(opCtx);
// 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() && !opCtx->lockState()->isNoop() &&
!opCtx->lockState()->isCollectionLockedForMode(_ns, MODE_X)) {
throw WriteConflictException();
}
ru->setOplogReadTill(_cappedVisibilityManager->oplogStartHack());
startIterator = _cappedOldestKeyHint;
} else {
startIterator = _cappedVisibilityManager->oplogStartHack();
if (_isOplog && forward) {
auto ru = RocksRecoveryUnit::getRocksRecoveryUnit(opCtx);
// 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() && !opCtx->lockState()->isNoop() &&
!opCtx->lockState()->isCollectionLockedForMode(_ns, MODE_X)) {
throw WriteConflictException();
}
ru->setOplogReadTill(_cappedVisibilityManager->oplogStartHack());
startIterator = _cappedOldestKeyHint;
}

return stdx::make_unique<Cursor>(opCtx, _db, _prefix, _cappedVisibilityManager, forward,
Expand Down Expand Up @@ -1066,13 +1062,12 @@ namespace mongo {
_currentSequenceNumber =
RocksRecoveryUnit::getRocksRecoveryUnit(opCtx)->snapshot()->GetSequenceNumber();

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

Expand Down

0 comments on commit 0e02a95

Please sign in to comment.