summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2017-01-26 15:01:26 -0500
committerEric Milkie <milkie@10gen.com>2017-02-06 13:34:45 -0500
commit7e198e2d9fbce530b34a6353e2b7af642b6ca971 (patch)
treeeb60d69f43dbb4d144ea794ebc0db3cb8ac1dbbc
parent36d0d2daf79b3b62852ae795e104a74f93e8a9b7 (diff)
downloadmongo-7e198e2d9fbce530b34a6353e2b7af642b6ca971.tar.gz
SERVER-27493 do not enforce oplog visibility hack for reverse cursors
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp4
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp28
2 files changed, 24 insertions, 8 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index 8be255c684c..511b97c2bc5 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -1100,7 +1100,9 @@ void WiredTigerRecordStore::Iterator::_getNext() {
invariantWTOK(ret);
_loc = _curr();
RS_ITERATOR_TRACE("_getNext " << ret << " " << _eof << " " << _loc);
- if (_rs._isCapped) {
+ // Enforce special visibility rules for the end of capped collections.
+ // This is only applicable to forward scanning cursors.
+ if (_forward && _rs._isCapped) {
RecordId loc = _curr();
if (_readUntilForOplog.isNull()) {
// this is the normal capped case
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp
index d8ef96e0dd4..701547fc612 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp
@@ -34,15 +34,15 @@
#include <sstream>
#include <string>
+#include "mongo/base/checked_cast.h"
#include "mongo/base/string_data.h"
#include "mongo/bson/bsonobjbuilder.h"
-#include "mongo/base/checked_cast.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/json.h"
#include "mongo/db/operation_context_noop.h"
#include "mongo/db/storage/record_store_test_harness.h"
-#include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h"
+#include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_size_storer.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
@@ -755,6 +755,8 @@ TEST(WiredTigerRecordStoreTest, OplogOrder) {
}
RecordId loc1;
+ RecordId loc2;
+ RecordId loc3;
{ // first insert a document
scoped_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
@@ -775,17 +777,17 @@ TEST(WiredTigerRecordStoreTest, OplogOrder) {
{
// now we insert 2 docs, but commit the 2nd one fiirst
- // we make sure we can't find the 2nd until the first is commited
+ // we make sure we can't find the 2nd until the first is committed
scoped_ptr<OperationContext> t1(harnessHelper->newOperationContext());
scoped_ptr<WriteUnitOfWork> w1(new WriteUnitOfWork(t1.get()));
- _oplogOrderInsertOplog(t1.get(), rs, 2);
+ loc2 = _oplogOrderInsertOplog(t1.get(), rs, 2);
// do not commit yet
{ // create 2nd doc
scoped_ptr<OperationContext> t2(harnessHelper->newOperationContext());
{
WriteUnitOfWork w2(t2.get());
- _oplogOrderInsertOplog(t2.get(), rs, 3);
+ loc3 = _oplogOrderInsertOplog(t2.get(), rs, 3);
w2.commit();
}
}
@@ -798,6 +800,18 @@ TEST(WiredTigerRecordStoreTest, OplogOrder) {
ASSERT(it->isEOF());
}
+ { // however, reverse iterators should still see all docs except loc2 which is still
+ // uncommitted.
+ scoped_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ scoped_ptr<RecordIterator> it(
+ rs->getIterator(opCtx.get(), RecordId(), CollectionScanParams::BACKWARD));
+ ASSERT(!it->isEOF());
+ ASSERT_EQ(loc3, it->getNext());
+ ASSERT(!it->isEOF());
+ ASSERT_EQ(loc1, it->getNext());
+ ASSERT(it->isEOF());
+ }
+
w1->commit();
}
@@ -807,9 +821,9 @@ TEST(WiredTigerRecordStoreTest, OplogOrder) {
ASSERT(!it->isEOF());
ASSERT_EQ(loc1, it->getNext());
ASSERT(!it->isEOF());
- it->getNext();
+ ASSERT_EQ(loc2, it->getNext());
ASSERT(!it->isEOF());
- it->getNext();
+ ASSERT_EQ(loc3, it->getNext());
ASSERT(it->isEOF());
}
}