diff options
Diffstat (limited to 'src/mongo/db/storage/record_store_test_repairiter.cpp')
-rw-r--r-- | src/mongo/db/storage/record_store_test_repairiter.cpp | 204 |
1 files changed, 101 insertions, 103 deletions
diff --git a/src/mongo/db/storage/record_store_test_repairiter.cpp b/src/mongo/db/storage/record_store_test_repairiter.cpp index b3e11e137d4..56abdcb6b14 100644 --- a/src/mongo/db/storage/record_store_test_repairiter.cpp +++ b/src/mongo/db/storage/record_store_test_repairiter.cpp @@ -43,128 +43,126 @@ using std::stringstream; namespace mongo { - // Create an iterator for repairing an empty record store. - TEST( RecordStoreTestHarness, GetIteratorForRepairEmpty ) { - unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() ); - unique_ptr<RecordStore> rs( harnessHelper->newNonCappedRecordStore() ); +// Create an iterator for repairing an empty record store. +TEST(RecordStoreTestHarness, GetIteratorForRepairEmpty) { + unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); + + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + ASSERT_EQUALS(0, rs->numRecords(opCtx.get())); + } - { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - ASSERT_EQUALS( 0, rs->numRecords( opCtx.get() ) ); + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + auto cursor = rs->getCursorForRepair(opCtx.get()); + // returns NULL if getCursorForRepair is not supported + if (!cursor) { + return; } + ASSERT(!cursor->next()); + } +} + +// Insert multiple records and create an iterator for repairing the record store, +// even though the it has not been corrupted. +TEST(RecordStoreTestHarness, GetIteratorForRepairNonEmpty) { + unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + ASSERT_EQUALS(0, rs->numRecords(opCtx.get())); + } + + const int nToInsert = 10; + RecordId locs[nToInsert]; + for (int i = 0; i < nToInsert; i++) { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - auto cursor = rs->getCursorForRepair( opCtx.get() ); - // returns NULL if getCursorForRepair is not supported - if (!cursor) { - return; - } - ASSERT(!cursor->next()); + stringstream ss; + ss << "record " << i; + string data = ss.str(); + + WriteUnitOfWork uow(opCtx.get()); + StatusWith<RecordId> res = + rs->insertRecord(opCtx.get(), data.c_str(), data.size() + 1, false); + ASSERT_OK(res.getStatus()); + locs[i] = res.getValue(); + uow.commit(); } } - // Insert multiple records and create an iterator for repairing the record store, - // even though the it has not been corrupted. - TEST( RecordStoreTestHarness, GetIteratorForRepairNonEmpty ) { - unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() ); - unique_ptr<RecordStore> rs( harnessHelper->newNonCappedRecordStore() ); + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + ASSERT_EQUALS(nToInsert, rs->numRecords(opCtx.get())); + } - { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - ASSERT_EQUALS( 0, rs->numRecords( opCtx.get() ) ); + set<RecordId> remain(locs, locs + nToInsert); + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + auto cursor = rs->getCursorForRepair(opCtx.get()); + // returns NULL if getCursorForRepair is not supported + if (!cursor) { + return; } - const int nToInsert = 10; - RecordId locs[nToInsert]; - for ( int i = 0; i < nToInsert; i++ ) { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - { - stringstream ss; - ss << "record " << i; - string data = ss.str(); - - WriteUnitOfWork uow( opCtx.get() ); - StatusWith<RecordId> res = rs->insertRecord( opCtx.get(), - data.c_str(), - data.size() + 1, - false ); - ASSERT_OK( res.getStatus() ); - locs[i] = res.getValue(); - uow.commit(); - } + while (auto record = cursor->next()) { + remain.erase(record->id); // can happen more than once per doc } + ASSERT(remain.empty()); - { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - ASSERT_EQUALS( nToInsert, rs->numRecords( opCtx.get() ) ); - } + ASSERT(!cursor->next()); + } +} + +// Insert a single record. Create a repair iterator pointing to that single record. +// Then invalidate the record and ensure that the repair iterator responds correctly. +// See SERVER-16300. +TEST(RecordStoreTestHarness, GetIteratorForRepairInvalidateSingleton) { + unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); + + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + ASSERT_EQ(0, rs->numRecords(opCtx.get())); + } - set<RecordId> remain( locs, locs + nToInsert ); - { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - auto cursor = rs->getCursorForRepair( opCtx.get() ); - // returns NULL if getCursorForRepair is not supported - if (!cursor) { - return; - } - - while (auto record = cursor->next()) { - remain.erase(record->id); // can happen more than once per doc - } - ASSERT( remain.empty() ); - - ASSERT(!cursor->next()); - } + // Insert one record. + RecordId idToInvalidate; + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + WriteUnitOfWork uow(opCtx.get()); + StatusWith<RecordId> res = rs->insertRecord(opCtx.get(), "some data", 10, false); + ASSERT_OK(res.getStatus()); + idToInvalidate = res.getValue(); + uow.commit(); } - // Insert a single record. Create a repair iterator pointing to that single record. - // Then invalidate the record and ensure that the repair iterator responds correctly. - // See SERVER-16300. - TEST(RecordStoreTestHarness, GetIteratorForRepairInvalidateSingleton) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); - unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); + // Double-check that the record store has one record in it now. + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + ASSERT_EQ(1, rs->numRecords(opCtx.get())); + } - { - unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); - ASSERT_EQ(0, rs->numRecords(opCtx.get())); + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + auto cursor = rs->getCursorForRepair(opCtx.get()); + // returns NULL if getCursorForRepair is not supported + if (!cursor) { + return; } - // Insert one record. - RecordId idToInvalidate; - { - unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); - WriteUnitOfWork uow(opCtx.get()); - StatusWith<RecordId> res = rs->insertRecord(opCtx.get(), "some data", 10, false); - ASSERT_OK(res.getStatus()); - idToInvalidate = res.getValue(); - uow.commit(); - } + // We should be pointing at the only record in the store. - // Double-check that the record store has one record in it now. - { - unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); - ASSERT_EQ(1, rs->numRecords(opCtx.get())); - } + // Invalidate the record we're pointing at. + cursor->savePositioned(); + cursor->invalidate(idToInvalidate); + cursor->restore(opCtx.get()); - { - unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); - auto cursor = rs->getCursorForRepair( opCtx.get() ); - // returns NULL if getCursorForRepair is not supported - if (!cursor) { - return; - } - - // We should be pointing at the only record in the store. - - // Invalidate the record we're pointing at. - cursor->savePositioned(); - cursor->invalidate(idToInvalidate); - cursor->restore(opCtx.get()); - - // Iterator should be EOF now because the only thing in the collection got deleted. - ASSERT(!cursor->next()); - } + // Iterator should be EOF now because the only thing in the collection got deleted. + ASSERT(!cursor->next()); } +} -} // namespace mongo +} // namespace mongo |