summaryrefslogtreecommitdiff
path: root/src/mongo/db/index
diff options
context:
space:
mode:
authorHari Khalsa <hkhalsa@10gen.com>2014-04-29 12:39:52 -0400
committerHari Khalsa <hkhalsa@10gen.com>2014-04-29 14:10:28 -0400
commitbfdfc52bd1dc255cabff83109460e13dd272389b (patch)
tree604105d51b72eccdb2201e614b07f37ea4af740c /src/mongo/db/index
parent8e155fdfaeca8d77e19c0adcb570d3a1029cdccb (diff)
downloadmongo-bfdfc52bd1dc255cabff83109460e13dd272389b.tar.gz
SERVER-13641 move dur above index layer
Diffstat (limited to 'src/mongo/db/index')
-rw-r--r--src/mongo/db/index/btree_based_access_method.cpp46
-rw-r--r--src/mongo/db/index/btree_based_access_method.h18
-rw-r--r--src/mongo/db/index/btree_based_bulk_access_method.cpp29
-rw-r--r--src/mongo/db/index/btree_based_bulk_access_method.h23
-rw-r--r--src/mongo/db/index/index_access_method.h19
5 files changed, 88 insertions, 47 deletions
diff --git a/src/mongo/db/index/btree_based_access_method.cpp b/src/mongo/db/index/btree_based_access_method.cpp
index 21bcf638388..a57780def48 100644
--- a/src/mongo/db/index/btree_based_access_method.cpp
+++ b/src/mongo/db/index/btree_based_access_method.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/repl/is_master.h"
#include "mongo/db/repl/rs.h"
#include "mongo/db/server_parameters.h"
+#include "mongo/db/storage/transaction.h"
#include "mongo/db/structure/btree/btree_interface.h"
#include "mongo/util/progress_meter.h"
@@ -63,11 +64,11 @@ namespace mongo {
}
// Find the keys for obj, put them in the tree pointing to loc
- Status BtreeBasedAccessMethod::insert(const BSONObj& obj,
+ Status BtreeBasedAccessMethod::insert(TransactionExperiment* txn,
+ const BSONObj& obj,
const DiskLoc& loc,
const InsertDeleteOptions& options,
int64_t* numInserted) {
-
*numInserted = 0;
BSONObjSet keys;
@@ -76,7 +77,7 @@ namespace mongo {
Status ret = Status::OK();
for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) {
- Status status = _newInterface->insert(*i, loc, options.dupsAllowed);
+ Status status = _newInterface->insert(txn, *i, loc, options.dupsAllowed);
// Everything's OK, carry on.
if (status.isOK()) {
@@ -108,7 +109,7 @@ namespace mongo {
// Clean up after ourselves.
for (BSONObjSet::const_iterator j = keys.begin(); j != i; ++j) {
- removeOneKey(*j, loc);
+ removeOneKey(txn, *j, loc);
*numInserted = 0;
}
@@ -116,17 +117,20 @@ namespace mongo {
}
if (*numInserted > 1) {
+ // XXX: this should use a txn?
_btreeState->setMultikey();
}
return ret;
}
- bool BtreeBasedAccessMethod::removeOneKey(const BSONObj& key, const DiskLoc& loc) {
+ bool BtreeBasedAccessMethod::removeOneKey(TransactionExperiment* txn,
+ const BSONObj& key,
+ const DiskLoc& loc) {
bool ret = false;
try {
- ret = _newInterface->unindex(key, loc);
+ ret = _newInterface->unindex(txn, key, loc);
} catch (AssertionException& e) {
problem() << "Assertion failure: _unindex failed "
<< _descriptor->indexNamespace() << endl;
@@ -147,15 +151,18 @@ namespace mongo {
}
// Remove the provided doc from the index.
- Status BtreeBasedAccessMethod::remove(const BSONObj &obj, const DiskLoc& loc,
- const InsertDeleteOptions &options, int64_t* numDeleted) {
+ Status BtreeBasedAccessMethod::remove(TransactionExperiment* txn,
+ const BSONObj &obj,
+ const DiskLoc& loc,
+ const InsertDeleteOptions &options,
+ int64_t* numDeleted) {
BSONObjSet keys;
getKeys(obj, &keys);
*numDeleted = 0;
for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) {
- bool thisKeyOK = removeOneKey(*i, loc);
+ bool thisKeyOK = removeOneKey(txn, *i, loc);
if (thisKeyOK) {
++*numDeleted;
@@ -189,8 +196,8 @@ namespace mongo {
}
}
- Status BtreeBasedAccessMethod::initializeAsEmpty() {
- return _newInterface->initAsEmpty();
+ Status BtreeBasedAccessMethod::initializeAsEmpty(TransactionExperiment* txn) {
+ return _newInterface->initAsEmpty(txn);
}
Status BtreeBasedAccessMethod::touch(const BSONObj& obj) {
@@ -271,7 +278,9 @@ namespace mongo {
return Status::OK();
}
- Status BtreeBasedAccessMethod::update(const UpdateTicket& ticket, int64_t* numUpdated) {
+ Status BtreeBasedAccessMethod::update(TransactionExperiment* txn,
+ const UpdateTicket& ticket,
+ int64_t* numUpdated) {
if (!ticket._isValid) {
return Status(ErrorCodes::InternalError, "Invalid UpdateTicket in update");
}
@@ -284,11 +293,11 @@ namespace mongo {
}
for (size_t i = 0; i < data->added.size(); ++i) {
- _newInterface->insert(*data->added[i], data->loc, data->dupsAllowed);
+ _newInterface->insert(txn, *data->added[i], data->loc, data->dupsAllowed);
}
for (size_t i = 0; i < data->removed.size(); ++i) {
- _newInterface->unindex(*data->removed[i], data->loc);
+ _newInterface->unindex(txn, *data->removed[i], data->loc);
}
*numUpdated = data->added.size();
@@ -296,14 +305,17 @@ namespace mongo {
return Status::OK();
}
- IndexAccessMethod* BtreeBasedAccessMethod::initiateBulk() {
+ IndexAccessMethod* BtreeBasedAccessMethod::initiateBulk(TransactionExperiment* txn) {
// If there's already data in the index, don't do anything.
if (!_newInterface->isEmpty()) {
return NULL;
}
- return new BtreeBasedBulkAccessMethod(
- this, _newInterface.get(), _descriptor, _btreeState->collection()->numRecords());
+ return new BtreeBasedBulkAccessMethod(txn,
+ this,
+ _newInterface.get(),
+ _descriptor,
+ _btreeState->collection()->numRecords());
}
Status BtreeBasedAccessMethod::commitBulk(IndexAccessMethod* bulkRaw,
diff --git a/src/mongo/db/index/btree_based_access_method.h b/src/mongo/db/index/btree_based_access_method.h
index 094f2ecb313..905dc7746a2 100644
--- a/src/mongo/db/index/btree_based_access_method.h
+++ b/src/mongo/db/index/btree_based_access_method.h
@@ -60,12 +60,14 @@ namespace mongo {
virtual ~BtreeBasedAccessMethod() { }
- virtual Status insert(const BSONObj& obj,
+ virtual Status insert(TransactionExperiment* txn,
+ const BSONObj& obj,
const DiskLoc& loc,
const InsertDeleteOptions& options,
int64_t* numInserted);
- virtual Status remove(const BSONObj& obj,
+ virtual Status remove(TransactionExperiment* txn,
+ const BSONObj& obj,
const DiskLoc& loc,
const InsertDeleteOptions& options,
int64_t* numDeleted);
@@ -76,13 +78,15 @@ namespace mongo {
const InsertDeleteOptions& options,
UpdateTicket* ticket);
- virtual Status update(const UpdateTicket& ticket, int64_t* numUpdated);
+ virtual Status update(TransactionExperiment* txn,
+ const UpdateTicket& ticket,
+ int64_t* numUpdated);
virtual Status newCursor(IndexCursor **out) const;
- virtual Status initializeAsEmpty();
+ virtual Status initializeAsEmpty(TransactionExperiment* txn);
- virtual IndexAccessMethod* initiateBulk() ;
+ virtual IndexAccessMethod* initiateBulk(TransactionExperiment* txn) ;
virtual Status commitBulk( IndexAccessMethod* bulk,
bool mayInterrupt,
@@ -115,7 +119,9 @@ namespace mongo {
}
private:
- bool removeOneKey(const BSONObj& key, const DiskLoc& loc);
+ bool removeOneKey(TransactionExperiment* txn,
+ const BSONObj& key,
+ const DiskLoc& loc);
scoped_ptr<BtreeInterface> _newInterface;
};
diff --git a/src/mongo/db/index/btree_based_bulk_access_method.cpp b/src/mongo/db/index/btree_based_bulk_access_method.cpp
index d4471b2fc7a..fdf288151d0 100644
--- a/src/mongo/db/index/btree_based_bulk_access_method.cpp
+++ b/src/mongo/db/index/btree_based_bulk_access_method.cpp
@@ -31,7 +31,7 @@
#include "mongo/db/kill_current_op.h"
#include "mongo/db/pdfile_private.h" // This is for inDBRepair.
#include "mongo/db/repl/rs.h" // This is for ignoreUniqueIndex.
-#include "mongo/db/storage/mmap_v1/dur_transaction.h"
+#include "mongo/db/storage/transaction.h"
#include "mongo/util/progress_meter.h"
namespace mongo {
@@ -90,13 +90,14 @@ namespace mongo {
return NULL;
}
- BtreeBasedBulkAccessMethod::BtreeBasedBulkAccessMethod(BtreeBasedAccessMethod* real,
- BtreeInterface* interface,
- const IndexDescriptor* descriptor,
- int numRecords) {
-
+ BtreeBasedBulkAccessMethod::BtreeBasedBulkAccessMethod(TransactionExperiment* txn,
+ BtreeBasedAccessMethod* real,
+ BtreeInterface* interface,
+ const IndexDescriptor* descriptor,
+ int numRecords) {
_real = real;
_interface = interface;
+ _txn = txn;
_docsInserted = 0;
_keysInserted = 0;
@@ -107,10 +108,11 @@ namespace mongo {
_sorter->hintNumObjects(numRecords);
}
- Status BtreeBasedBulkAccessMethod::insert(const BSONObj& obj,
- const DiskLoc& loc,
- const InsertDeleteOptions& options,
- int64_t* numInserted) {
+ Status BtreeBasedBulkAccessMethod::insert(TransactionExperiment* txn,
+ const BSONObj& obj,
+ const DiskLoc& loc,
+ const InsertDeleteOptions& options,
+ int64_t* numInserted) {
BSONObjSet keys;
_real->getKeys(obj, &keys);
@@ -132,12 +134,12 @@ namespace mongo {
}
Status BtreeBasedBulkAccessMethod::commit(set<DiskLoc>* dupsToDrop, CurOp* op, bool mayInterrupt) {
- DurTransaction txn; // XXX
DiskLoc oldHead = _real->_btreeState->head();
+
// XXX: do we expect the tree to be empty but have a head set? Looks like so from old code.
invariant(!oldHead.isNull());
_real->_btreeState->setHead(DiskLoc());
- _real->_btreeState->recordStore()->deleteRecord(&txn, oldHead);
+ _real->_btreeState->recordStore()->deleteRecord(_txn, oldHead);
if (_isMultiKey) {
_real->_btreeState->setMultikey();
@@ -162,7 +164,8 @@ namespace mongo {
10);
scoped_ptr<BtreeBuilderInterface> builder;
- builder.reset(_interface->getBulkBuilder(dupsAllowed));
+
+ builder.reset(_interface->getBulkBuilder(_txn, dupsAllowed));
while (i->more()) {
// Get the next datum and add it to the builder.
diff --git a/src/mongo/db/index/btree_based_bulk_access_method.h b/src/mongo/db/index/btree_based_bulk_access_method.h
index e0033a2be5d..79faf4d407b 100644
--- a/src/mongo/db/index/btree_based_bulk_access_method.h
+++ b/src/mongo/db/index/btree_based_bulk_access_method.h
@@ -43,14 +43,20 @@ namespace mongo {
class BtreeBasedBulkAccessMethod : public IndexAccessMethod {
public:
- BtreeBasedBulkAccessMethod(BtreeBasedAccessMethod* real,
+ /**
+ * Does not take ownership of any pointers.
+ * All pointers must outlive 'this'.
+ */
+ BtreeBasedBulkAccessMethod(TransactionExperiment* txn,
+ BtreeBasedAccessMethod* real,
BtreeInterface* interface,
const IndexDescriptor* descriptor,
int numRecords);
~BtreeBasedBulkAccessMethod() {}
- virtual Status insert(const BSONObj& obj,
+ virtual Status insert(TransactionExperiment* txn,
+ const BSONObj& obj,
const DiskLoc& loc,
const InsertDeleteOptions& options,
int64_t* numInserted);
@@ -79,7 +85,8 @@ namespace mongo {
return _notAllowed();
}
- virtual Status remove(const BSONObj& obj,
+ virtual Status remove(TransactionExperiment* txn,
+ const BSONObj& obj,
const DiskLoc& loc,
const InsertDeleteOptions& options,
int64_t* numDeleted) {
@@ -94,7 +101,9 @@ namespace mongo {
return _notAllowed();
}
- virtual Status update(const UpdateTicket& ticket, int64_t* numUpdated) {
+ virtual Status update(TransactionExperiment* txn,
+ const UpdateTicket& ticket,
+ int64_t* numUpdated) {
return _notAllowed();
}
@@ -102,11 +111,11 @@ namespace mongo {
return _notAllowed();
}
- virtual Status initializeAsEmpty() {
+ virtual Status initializeAsEmpty(TransactionExperiment* txn) {
return _notAllowed();
}
- virtual IndexAccessMethod* initiateBulk() {
+ virtual IndexAccessMethod* initiateBulk(TransactionExperiment* txn) {
return NULL;
}
@@ -135,6 +144,8 @@ namespace mongo {
// Does any document have >1 key?
bool _isMultiKey;
+
+ TransactionExperiment* _txn;
};
} // namespace mongo
diff --git a/src/mongo/db/index/index_access_method.h b/src/mongo/db/index/index_access_method.h
index 4f2c2e8650f..6e1b670fe18 100644
--- a/src/mongo/db/index/index_access_method.h
+++ b/src/mongo/db/index/index_access_method.h
@@ -32,6 +32,7 @@
#include "mongo/db/index/index_cursor.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/jsobj.h"
+#include "mongo/db/storage/transaction.h"
namespace mongo {
@@ -64,7 +65,8 @@ namespace mongo {
*
* The behavior of the insertion can be specified through 'options'.
*/
- virtual Status insert(const BSONObj& obj,
+ virtual Status insert(TransactionExperiment* txn,
+ const BSONObj& obj,
const DiskLoc& loc,
const InsertDeleteOptions& options,
int64_t* numInserted) = 0;
@@ -73,7 +75,8 @@ namespace mongo {
* Analogous to above, but remove the records instead of inserting them. If not NULL,
* numDeleted will be set to the number of keys removed from the index for the document.
*/
- virtual Status remove(const BSONObj& obj,
+ virtual Status remove(TransactionExperiment* txn,
+ const BSONObj& obj,
const DiskLoc& loc,
const InsertDeleteOptions& options,
int64_t* numDeleted) = 0;
@@ -102,7 +105,9 @@ namespace mongo {
* called. If the index was changed, we may return an error, as our ticket may have been
* invalidated.
*/
- virtual Status update(const UpdateTicket& ticket, int64_t* numUpdated) = 0;
+ virtual Status update(TransactionExperiment* txn,
+ const UpdateTicket& ticket,
+ int64_t* numUpdated) = 0;
/**
* Fills in '*out' with an IndexCursor. Return a status indicating success or reason of
@@ -118,7 +123,7 @@ namespace mongo {
* only called once for the lifetime of the index
* if called multiple times, is an error
*/
- virtual Status initializeAsEmpty() = 0;
+ virtual Status initializeAsEmpty(TransactionExperiment* txn) = 0;
/**
* Try to page-in the pages that contain the keys generated from 'obj'.
@@ -151,10 +156,14 @@ namespace mongo {
* Long term, you'll eventually be able to mix/match bulk, not bulk,
* have as many as you want, etc..
*
+ * Caller owns the returned IndexAccessMethod.
+ *
+ * The provided TransactionExperiment must outlive the IndexAccessMethod returned.
+ *
* For now (1/8/14) you can only do bulk when the index is empty
* it will fail if you try other times.
*/
- virtual IndexAccessMethod* initiateBulk() = 0;
+ virtual IndexAccessMethod* initiateBulk(TransactionExperiment* txn) = 0;
/**
* Call this when you are ready to finish your bulk work.