Skip to content

Commit b67d792

Browse files
committed
Revert "SERVER-19564: Vectorize index write"
This reverts commit 53559aa.
1 parent 53559aa commit b67d792

File tree

4 files changed

+25
-56
lines changed

4 files changed

+25
-56
lines changed

src/mongo/db/catalog/collection.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -434,21 +434,20 @@ Status Collection::_insertDocuments(OperationContext* txn,
434434
// under the RecordStore, this feels broken since that should be a
435435
// collection access method probably
436436

437-
// insertRecord(s) will be vectorized in a future patch
438-
std::vector<BsonRecord> bsonRecords;
437+
// These will be vectorized (insertRecords, indexRecords) in a future patch
439438
for (vector<BSONObj>::iterator it = begin; it != end; it++) {
440439
StatusWith<RecordId> loc = _recordStore->insertRecord(
441440
txn, it->objdata(), it->objsize(), _enforceQuota(enforceQuota));
442441
if (!loc.isOK())
443442
return loc.getStatus();
444-
BsonRecord bsonRecord = {loc.getValue(), &(*it)};
445-
bsonRecords.push_back(bsonRecord);
446-
447443
invariant(RecordId::min() < loc.getValue());
448444
invariant(loc.getValue() < RecordId::max());
449-
}
450445

451-
return _indexCatalog.indexRecords(txn, bsonRecords);
446+
Status status = _indexCatalog.indexRecord(txn, *it, loc.getValue());
447+
if (!status.isOK())
448+
return status;
449+
}
450+
return Status::OK();
452451
}
453452

454453
Status Collection::aboutToDeleteCapped(OperationContext* txn,
@@ -581,10 +580,7 @@ StatusWith<RecordId> Collection::updateDocument(OperationContext* txn,
581580
debug->nmoved += 1;
582581
}
583582

584-
std::vector<BsonRecord> bsonRecords;
585-
BsonRecord bsonRecord = {newLocation.getValue(), &newDoc};
586-
bsonRecords.push_back(bsonRecord);
587-
Status s = _indexCatalog.indexRecords(txn, bsonRecords);
583+
Status s = _indexCatalog.indexRecord(txn, newDoc, newLocation.getValue());
588584
if (!s.isOK())
589585
return StatusWith<RecordId>(s);
590586
invariant(sid == txn->recoveryUnit()->getSnapshotId());

src/mongo/db/catalog/index_catalog.cpp

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,38 +1109,21 @@ bool isDupsAllowed(IndexDescriptor* desc) {
11091109
}
11101110
}
11111111

1112-
Status IndexCatalog::_indexFilteredRecords(OperationContext* txn,
1113-
IndexCatalogEntry* index,
1114-
const std::vector<BsonRecord>& bsonRecords) {
1112+
Status IndexCatalog::_indexRecord(OperationContext* txn,
1113+
IndexCatalogEntry* index,
1114+
const BSONObj& obj,
1115+
const RecordId& loc) {
1116+
const MatchExpression* filter = index->getFilterExpression();
1117+
if (filter && !filter->matchesBSON(obj)) {
1118+
return Status::OK();
1119+
}
1120+
11151121
InsertDeleteOptions options;
11161122
options.logIfError = false;
11171123
options.dupsAllowed = isDupsAllowed(index->descriptor());
11181124

1119-
for (auto bsonRecord : bsonRecords) {
1120-
int64_t inserted;
1121-
invariant(bsonRecord.id != RecordId());
1122-
Status status = index->accessMethod()->insert(
1123-
txn, *bsonRecord.docPtr, bsonRecord.id, options, &inserted);
1124-
if (!status.isOK())
1125-
return status;
1126-
}
1127-
return Status::OK();
1128-
}
1129-
1130-
Status IndexCatalog::_indexRecords(OperationContext* txn,
1131-
IndexCatalogEntry* index,
1132-
const std::vector<BsonRecord>& bsonRecords) {
1133-
const MatchExpression* filter = index->getFilterExpression();
1134-
if (!filter)
1135-
return _indexFilteredRecords(txn, index, bsonRecords);
1136-
1137-
std::vector<BsonRecord> filteredBsonRecords;
1138-
for (auto bsonRecord : bsonRecords) {
1139-
if (filter->matchesBSON(*(bsonRecord.docPtr)))
1140-
filteredBsonRecords.push_back(bsonRecord);
1141-
}
1142-
1143-
return _indexFilteredRecords(txn, index, filteredBsonRecords);
1125+
int64_t inserted;
1126+
return index->accessMethod()->insert(txn, obj, loc, options, &inserted);
11441127
}
11451128

11461129
Status IndexCatalog::_unindexRecord(OperationContext* txn,
@@ -1169,11 +1152,10 @@ Status IndexCatalog::_unindexRecord(OperationContext* txn,
11691152
}
11701153

11711154

1172-
Status IndexCatalog::indexRecords(OperationContext* txn,
1173-
const std::vector<BsonRecord>& bsonRecords) {
1155+
Status IndexCatalog::indexRecord(OperationContext* txn, const BSONObj& obj, const RecordId& loc) {
11741156
for (IndexCatalogEntryContainer::const_iterator i = _entries.begin(); i != _entries.end();
11751157
++i) {
1176-
Status s = _indexRecords(txn, *i, bsonRecords);
1158+
Status s = _indexRecord(txn, *i, obj, loc);
11771159
if (!s.isOK())
11781160
return s;
11791161
}

src/mongo/db/catalog/index_catalog.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "mongo/db/jsobj.h"
3737
#include "mongo/db/operation_context.h"
3838
#include "mongo/db/record_id.h"
39-
#include "mongo/db/storage/record_store.h"
4039
#include "mongo/platform/unordered_map.h"
4140

4241
namespace mongo {
@@ -264,7 +263,7 @@ class IndexCatalog {
264263
// ----- data modifiers ------
265264

266265
// this throws for now
267-
Status indexRecords(OperationContext* txn, const std::vector<BsonRecord>& bsonRecords);
266+
Status indexRecord(OperationContext* txn, const BSONObj& obj, const RecordId& loc);
268267

269268
void unindexRecord(OperationContext* txn, const BSONObj& obj, const RecordId& loc, bool noWarn);
270269

@@ -295,13 +294,10 @@ class IndexCatalog {
295294

296295
void _checkMagic() const;
297296

298-
Status _indexFilteredRecords(OperationContext* txn,
299-
IndexCatalogEntry* index,
300-
const std::vector<BsonRecord>& bsonRecords);
301-
302-
Status _indexRecords(OperationContext* txn,
303-
IndexCatalogEntry* index,
304-
const std::vector<BsonRecord>& bsonRecords);
297+
Status _indexRecord(OperationContext* txn,
298+
IndexCatalogEntry* index,
299+
const BSONObj& obj,
300+
const RecordId& loc);
305301

306302
Status _unindexRecord(OperationContext* txn,
307303
IndexCatalogEntry* index,

src/mongo/db/storage/record_store.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ struct Record {
9191
RecordData data;
9292
};
9393

94-
struct BsonRecord {
95-
RecordId id;
96-
const BSONObj* docPtr;
97-
};
98-
9994
/**
10095
* Retrieves Records from a RecordStore.
10196
*

0 commit comments

Comments
 (0)