summaryrefslogtreecommitdiff
path: root/src/mongo/db/index
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2014-01-06 22:50:20 -0500
committerEliot Horowitz <eliot@10gen.com>2014-01-09 14:21:50 -0500
commit79de42e8eff5236b09ab074127e422494087c2ab (patch)
tree0da4ae2dfe167b340e2ad2d898761e3c45953d39 /src/mongo/db/index
parent87a5e280ae24bb1283b6e55378eee00ee088fb54 (diff)
downloadmongo-79de42e8eff5236b09ab074127e422494087c2ab.tar.gz
SERVER-12213: IndexAccessMethod::initializeAsEmpty is way to start new index
Diffstat (limited to 'src/mongo/db/index')
-rw-r--r--src/mongo/db/index/btree_based_access_method.cpp20
-rw-r--r--src/mongo/db/index/btree_based_access_method.h2
-rw-r--r--src/mongo/db/index/btree_based_builder.cpp8
-rw-r--r--src/mongo/db/index/btree_based_builder.h2
-rw-r--r--src/mongo/db/index/index_access_method.h10
5 files changed, 32 insertions, 10 deletions
diff --git a/src/mongo/db/index/btree_based_access_method.cpp b/src/mongo/db/index/btree_based_access_method.cpp
index 8af96bbadbf..a15729a1339 100644
--- a/src/mongo/db/index/btree_based_access_method.cpp
+++ b/src/mongo/db/index/btree_based_access_method.cpp
@@ -159,6 +159,26 @@ namespace mongo {
}
}
+ Status BtreeBasedAccessMethod::initializeAsEmpty() {
+ if ( !_btreeState->head().isNull() )
+ return Status( ErrorCodes::InternalError, "index already initialized" );
+
+ DiskLoc newHead;
+ if ( 0 == _descriptor->version() ) {
+ newHead = BtreeBucket<V0>::addBucket( _btreeState );
+ }
+ else if ( 1 == _descriptor->version() ) {
+ newHead = BtreeBucket<V1>::addBucket( _btreeState );
+ }
+ else {
+ return Status( ErrorCodes::InternalError, "invalid index number" );
+ }
+ _btreeState->setHead( newHead );
+
+ return Status::OK();
+ }
+
+
Status BtreeBasedAccessMethod::touch(const BSONObj& obj) {
BSONObjSet keys;
getKeys(obj, &keys);
diff --git a/src/mongo/db/index/btree_based_access_method.h b/src/mongo/db/index/btree_based_access_method.h
index 320c1de8944..f541d302f60 100644
--- a/src/mongo/db/index/btree_based_access_method.h
+++ b/src/mongo/db/index/btree_based_access_method.h
@@ -75,6 +75,8 @@ namespace mongo {
virtual Status newCursor(IndexCursor **out) const = 0;
+ virtual Status initializeAsEmpty();
+
virtual Status touch(const BSONObj& obj);
virtual Status validate(int64_t* numKeys);
diff --git a/src/mongo/db/index/btree_based_builder.cpp b/src/mongo/db/index/btree_based_builder.cpp
index 1a321f43b4e..c2e452fcc7d 100644
--- a/src/mongo/db/index/btree_based_builder.cpp
+++ b/src/mongo/db/index/btree_based_builder.cpp
@@ -136,14 +136,6 @@ namespace mongo {
}
}
- DiskLoc BtreeBasedBuilder::makeEmptyIndex(IndexCatalogEntry* idx) {
- if (0 == idx->descriptor()->version()) {
- return BtreeBucket<V0>::addBucket(idx);
- } else {
- return BtreeBucket<V1>::addBucket(idx);
- }
- }
-
ExternalSortComparison* BtreeBasedBuilder::getComparison(int version,
const BSONObj& keyPattern) {
if (0 == version) {
diff --git a/src/mongo/db/index/btree_based_builder.h b/src/mongo/db/index/btree_based_builder.h
index d9515c3f6de..967c17bb2b5 100644
--- a/src/mongo/db/index/btree_based_builder.h
+++ b/src/mongo/db/index/btree_based_builder.h
@@ -62,8 +62,6 @@ namespace mongo {
IndexCatalogEntry* descriptor,
bool mayInterrupt);
- static DiskLoc makeEmptyIndex(IndexCatalogEntry* idx);
-
static ExternalSortComparison* getComparison(int version,
const BSONObj& keyPattern);
diff --git a/src/mongo/db/index/index_access_method.h b/src/mongo/db/index/index_access_method.h
index 303b09d9ed2..a04e54610ab 100644
--- a/src/mongo/db/index/index_access_method.h
+++ b/src/mongo/db/index/index_access_method.h
@@ -110,6 +110,16 @@ namespace mongo {
*/
virtual Status newCursor(IndexCursor **out) const = 0;
+ // ------ index level operations ------
+
+
+ /**
+ * initializes this index
+ * only called once for the lifetime of the index
+ * if called multiple times, is an error
+ */
+ virtual Status initializeAsEmpty() = 0;
+
/**
* Try to page-in the pages that contain the keys generated from 'obj'.
* This can be used to speed up future accesses to an index by trying to ensure the