summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/collection_compact.cpp
diff options
context:
space:
mode:
authorKyle Suarez <ksuarz@gmail.com>2016-03-10 14:46:39 -0500
committerKyle Suarez <ksuarz@gmail.com>2016-03-10 16:41:14 -0500
commit7676d097f1dde12c0a7ca9faa9f3e2f8e11a4b76 (patch)
tree10ca7d9d91c1f84f6b6461a88293415855e4a1f4 /src/mongo/db/catalog/collection_compact.cpp
parent1d7516e470bc5194bff6b772663a818d067de046 (diff)
downloadmongo-7676d097f1dde12c0a7ca9faa9f3e2f8e11a4b76.tar.gz
SERVER-16856 compact method in SortedDataInterface
Add a compact() method to the SortedDataInterface to allow for compaction if the indexed record store supports compaction-in-place.
Diffstat (limited to 'src/mongo/db/catalog/collection_compact.cpp')
-rw-r--r--src/mongo/db/catalog/collection_compact.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/mongo/db/catalog/collection_compact.cpp b/src/mongo/db/catalog/collection_compact.cpp
index 7d0a9e266f6..b9ea06a2aef 100644
--- a/src/mongo/db/catalog/collection_compact.cpp
+++ b/src/mongo/db/catalog/collection_compact.cpp
@@ -111,13 +111,25 @@ StatusWith<CompactStats> Collection::compact(OperationContext* txn,
<< _recordStore->name());
if (_recordStore->compactsInPlace()) {
- // Since we are compacting in-place, we don't need to touch the indexes.
- // TODO SERVER-16856 compact indexes
CompactStats stats;
Status status = _recordStore->compact(txn, NULL, compactOptions, &stats);
if (!status.isOK())
return StatusWith<CompactStats>(status);
+ // Compact all indexes (not including unfinished indexes)
+ IndexCatalog::IndexIterator ii(_indexCatalog.getIndexIterator(txn, false));
+ while (ii.more()) {
+ IndexDescriptor* descriptor = ii.next();
+ IndexAccessMethod* index = _indexCatalog.getIndex(descriptor);
+
+ LOG(1) << "compacting index: " << descriptor->toString();
+ Status status = index->compact(txn);
+ if (!status.isOK()) {
+ error() << "failed to compact index: " << descriptor->toString();
+ return status;
+ }
+ }
+
return StatusWith<CompactStats>(stats);
}