diff options
author | Mathias Stearn <mathias@10gen.com> | 2015-01-13 18:03:26 -0500 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2015-01-15 18:08:36 -0500 |
commit | 48deaff5bf31d21807c5dd7e7f5d313c7c96e8dc (patch) | |
tree | 9dddcbe22e34cd0c677ba380ad098e02141df249 /src/mongo/db/repair_database.cpp | |
parent | 44c31ca911125b3b16e5279905a9516f4f05feee (diff) | |
download | mongo-48deaff5bf31d21807c5dd7e7f5d313c7c96e8dc.tar.gz |
Better repair for WT
* Doesn't construct RecordStores or indexes before they've been repaired
* No longer need to skip checking index versions.
* Updates numRecords and dataSize after the repair.
Related issues:
SERVER-16817 Skip checking index versions in WT during --repair
SERVER-16172 --repair fails before repairing collections in WT
A call to flushAllFiles is commented out due to SERVER-16869. Resolving it
should uncomment that line.
Diffstat (limited to 'src/mongo/db/repair_database.cpp')
-rw-r--r-- | src/mongo/db/repair_database.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp index 26f4dc5382e..516827a3715 100644 --- a/src/mongo/db/repair_database.cpp +++ b/src/mongo/db/repair_database.cpp @@ -84,8 +84,7 @@ namespace { // Skip the rest if there are no indexes to rebuild. if (indexSpecs.empty()) return Status::OK(); - boost::scoped_ptr<Database> db; - Collection* collection; + boost::scoped_ptr<Collection> collection; boost::scoped_ptr<MultiIndexBlock> indexer; { // These steps are combined into a single WUOW to ensure there are no commits without @@ -106,11 +105,10 @@ namespace { // Indexes must be dropped before we open the Collection otherwise we could attempt to // open a bad index and fail. // TODO see if MultiIndexBlock can be made to work without a Collection. - db.reset(new Database(txn, dbce->name(), dbce)); - collection = db->getCollection(collectionName); - invariant(collection); + const StringData ns = cce->ns().ns(); + collection.reset(new Collection(txn, ns, cce, dbce->getRecordStore(ns), dbce)); - indexer.reset(new MultiIndexBlock(txn, collection)); + indexer.reset(new MultiIndexBlock(txn, collection.get())); Status status = indexer->init(indexSpecs); if (!status.isOK()) { // The WUOW will handle cleanup, so the indexer shouldn't do its own. @@ -124,6 +122,9 @@ namespace { // Iterate all records in the collection. Delete them if they aren't valid BSON. Index them // if they are. + long long numRecords = 0; + long long dataSize = 0; + RecordStore* rs = collection->getRecordStore(); boost::scoped_ptr<RecordIterator> it(rs->getIterator(txn)); while (!it->isEOF()) { @@ -144,6 +145,9 @@ namespace { continue; } + numRecords++; + dataSize += data.size(); + // Now index the record. // TODO SERVER-14812 add a mode that drops duplicates rather than failing WriteUnitOfWork wunit(txn); @@ -158,6 +162,7 @@ namespace { { WriteUnitOfWork wunit(txn); indexer->commit(); + rs->updateStatsAfterRepair(txn, numRecords, dataSize); wunit.commit(); } @@ -232,6 +237,9 @@ namespace { status = rebuildIndexesOnCollection(txn, dbce, *it); if (!status.isOK()) return status; + + // TODO: uncomment once SERVER-16869 + // engine->flushAllFiles(true); } return Status::OK(); |