summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2014-04-21 17:33:59 -0400
committerEliot Horowitz <eliot@10gen.com>2014-04-21 23:43:24 -0400
commitfe4113f77ef77a79741ed557be866df0e4a5272b (patch)
tree4904300609a505c738eccb375f25850de6f350e5
parent177d92b10d8447eb09cca8c6bd8eed0d9f04bc54 (diff)
downloadmongo-fe4113f77ef77a79741ed557be866df0e4a5272b.tar.gz
SERVER-13638: add hidden interface for NamespaceDetails in RecordStoreV1
-rw-r--r--src/mongo/db/catalog/collection.cpp5
-rw-r--r--src/mongo/db/catalog/index_catalog.cpp3
-rw-r--r--src/mongo/db/structure/catalog/namespace_details.cpp2
-rw-r--r--src/mongo/db/structure/catalog/namespace_details.h2
-rw-r--r--src/mongo/db/structure/catalog/namespace_details_rsv1_metadata.h129
-rw-r--r--src/mongo/db/structure/record_store_v1_base.cpp3
-rw-r--r--src/mongo/db/structure/record_store_v1_base.h58
-rw-r--r--src/mongo/db/structure/record_store_v1_capped.cpp6
-rw-r--r--src/mongo/db/structure/record_store_v1_capped.h2
-rw-r--r--src/mongo/db/structure/record_store_v1_capped_iterator.cpp4
-rw-r--r--src/mongo/db/structure/record_store_v1_simple.cpp4
-rw-r--r--src/mongo/db/structure/record_store_v1_simple.h2
-rw-r--r--src/mongo/dbtests/namespacetests.cpp8
13 files changed, 203 insertions, 25 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp
index af7ec5e1aa8..aefe4c3a82d 100644
--- a/src/mongo/db/catalog/collection.cpp
+++ b/src/mongo/db/catalog/collection.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/catalog/index_create.h"
#include "mongo/db/index/index_access_method.h"
#include "mongo/db/structure/catalog/namespace_details.h"
+#include "mongo/db/structure/catalog/namespace_details_rsv1_metadata.h"
#include "mongo/db/structure/record_store_v1_capped.h"
#include "mongo/db/structure/record_store_v1_simple.h"
#include "mongo/db/repl/rs.h"
@@ -83,13 +84,13 @@ namespace mongo {
if ( details->isCapped() ) {
_recordStore.reset( new CappedRecordStoreV1( this,
_ns.ns(),
- details,
+ new NamespaceDetailsRSV1MetaData( details ),
&database->getExtentManager(),
_ns.coll() == "system.indexes" ) );
}
else {
_recordStore.reset( new SimpleRecordStoreV1( _ns.ns(),
- details,
+ new NamespaceDetailsRSV1MetaData( details ),
&database->getExtentManager(),
_ns.coll() == "system.indexes" ) );
}
diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp
index 6376ea048d7..ed3e687e405 100644
--- a/src/mongo/db/catalog/index_catalog.cpp
+++ b/src/mongo/db/catalog/index_catalog.cpp
@@ -61,6 +61,7 @@
#include "mongo/db/repl/rs.h" // this is ugly
#include "mongo/db/storage/data_file.h"
#include "mongo/db/structure/catalog/namespace_details.h"
+#include "mongo/db/structure/catalog/namespace_details_rsv1_metadata.h"
#include "mongo/db/structure/record_store_v1_simple.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -133,7 +134,7 @@ namespace mongo {
indexMetadata );
auto_ptr<RecordStore> recordStore( new SimpleRecordStoreV1( descriptor->indexNamespace(),
- indexMetadata,
+ new NamespaceDetailsRSV1MetaData( indexMetadata ),
_collection->getExtentManager(),
false ) );
diff --git a/src/mongo/db/structure/catalog/namespace_details.cpp b/src/mongo/db/structure/catalog/namespace_details.cpp
index 0ad772b0cef..f281d266d70 100644
--- a/src/mongo/db/structure/catalog/namespace_details.cpp
+++ b/src/mongo/db/structure/catalog/namespace_details.cpp
@@ -68,6 +68,8 @@ namespace mongo {
};
NamespaceDetails::NamespaceDetails( const DiskLoc &loc, bool capped ) {
+ BOOST_STATIC_ASSERT( sizeof(NamespaceDetails::Extra) <= sizeof(NamespaceDetails) );
+
/* be sure to initialize new fields here -- doesn't default to zeroes the way we use it */
_firstExtent = _lastExtent = _capExtent = loc;
_stats.datasize = _stats.nrecords = 0;
diff --git a/src/mongo/db/structure/catalog/namespace_details.h b/src/mongo/db/structure/catalog/namespace_details.h
index 68e563f8f47..80bacc669d9 100644
--- a/src/mongo/db/structure/catalog/namespace_details.h
+++ b/src/mongo/db/structure/catalog/namespace_details.h
@@ -155,7 +155,7 @@ namespace mongo {
const DiskLoc& capExtent() const { return _capExtent; }
void setCapExtent( const DiskLoc& loc );
- const DiskLoc capFirstNewRecord() const { return _capFirstNewRecord; }
+ const DiskLoc& capFirstNewRecord() const { return _capFirstNewRecord; }
void setCapFirstNewRecord( const DiskLoc& loc );
bool capLooped() const { return _capFirstNewRecord.isValid(); }
diff --git a/src/mongo/db/structure/catalog/namespace_details_rsv1_metadata.h b/src/mongo/db/structure/catalog/namespace_details_rsv1_metadata.h
new file mode 100644
index 00000000000..eba482a99a6
--- /dev/null
+++ b/src/mongo/db/structure/catalog/namespace_details_rsv1_metadata.h
@@ -0,0 +1,129 @@
+// namespace_details_rsv1_metadata.h
+
+#include "mongo/db/structure/record_store_v1_base.h"
+
+namespace mongo {
+
+ /*
+ * NOTE: NamespaceDetails will become a struct
+ * all dur, etc... will move here
+ */
+ class NamespaceDetailsRSV1MetaData : public RecordStoreV1MetaData {
+ public:
+ explicit NamespaceDetailsRSV1MetaData( NamespaceDetails* details ) {
+ _details = details;
+ }
+
+ virtual ~NamespaceDetailsRSV1MetaData(){}
+
+ virtual int bucket(int size) const {
+ return _details->bucket( size );
+ }
+
+ virtual const DiskLoc& capExtent() const {
+ return _details->capExtent();
+ }
+
+ virtual void setCapExtent( const DiskLoc& loc ) {
+ _details->setCapExtent( loc );
+ }
+
+ virtual const DiskLoc& capFirstNewRecord() const {
+ return _details->capFirstNewRecord();
+ }
+
+ virtual void setCapFirstNewRecord( const DiskLoc& loc ) {
+ _details->setCapFirstNewRecord( loc );
+ }
+
+ virtual bool capLooped() const {
+ return _details->capLooped();
+ }
+
+ virtual void clearSystemFlags() {
+ _details->clearSystemFlags();
+ }
+
+ virtual long long dataSize() const {
+ return _details->dataSize();
+ }
+ virtual long long numRecords() const {
+ return _details->numRecords();
+ }
+
+ virtual void incrementStats( long long dataSizeIncrement,
+ long long numRecordsIncrement ) {
+ _details->incrementStats( dataSizeIncrement, numRecordsIncrement );
+ }
+
+ virtual void setStats( long long dataSizeIncrement,
+ long long numRecordsIncrement ) {
+ _details->setStats( dataSizeIncrement,
+ numRecordsIncrement );
+ }
+
+ virtual const DiskLoc& deletedListEntry( int bucket ) const {
+ return _details->deletedListEntry( bucket );
+ }
+
+ virtual void setDeletedListEntry( int bucket, const DiskLoc& loc ) {
+ _details->setDeletedListEntry( bucket, loc );
+ }
+
+ virtual void orphanDeletedList() {
+ _details->orphanDeletedList();
+ }
+
+ virtual const DiskLoc& firstExtent() const {
+ return _details->firstExtent();
+ }
+
+ virtual void setFirstExtent( const DiskLoc& loc ) {
+ _details->setFirstExtent( loc );
+ }
+
+ virtual const DiskLoc& lastExtent() const {
+ return _details->lastExtent();
+ }
+
+ virtual void setLastExtent( const DiskLoc& loc ) {
+ _details->setLastExtent( loc );
+ }
+
+ virtual bool isCapped() const {
+ return _details->isCapped();
+ }
+
+ virtual bool isUserFlagSet( int flag ) const {
+ return _details->isUserFlagSet( flag );
+ }
+
+ virtual int lastExtentSize() const {
+ return _details->lastExtentSize();
+ }
+
+ virtual void setLastExtentSize( int newMax ) {
+ _details->setLastExtentSize( newMax );
+ }
+
+ virtual long long maxCappedDocs() const {
+ return _details->maxCappedDocs();
+ }
+
+ virtual double paddingFactor() const {
+ return _details->paddingFactor();
+ }
+
+ virtual void setPaddingFactor( double paddingFactor ) {
+ _details->setPaddingFactor( paddingFactor );
+ }
+
+ virtual int quantizePowerOf2AllocationSpace(int allocSize) const {
+ return _details->quantizePowerOf2AllocationSpace( allocSize );
+ }
+
+ private:
+ NamespaceDetails* _details;
+ };
+
+}
diff --git a/src/mongo/db/structure/record_store_v1_base.cpp b/src/mongo/db/structure/record_store_v1_base.cpp
index cc619015b91..fa38ebb3e58 100644
--- a/src/mongo/db/structure/record_store_v1_base.cpp
+++ b/src/mongo/db/structure/record_store_v1_base.cpp
@@ -37,12 +37,11 @@
#include "mongo/db/storage/extent_manager.h"
#include "mongo/db/storage/record.h"
#include "mongo/db/structure/catalog/namespace_details.h"
-#include "mongo/util/mmap.h"
namespace mongo {
RecordStoreV1Base::RecordStoreV1Base( const StringData& ns,
- NamespaceDetails* details,
+ RecordStoreV1MetaData* details,
ExtentManager* em,
bool isSystemIndexes )
: RecordStore( ns ),
diff --git a/src/mongo/db/structure/record_store_v1_base.h b/src/mongo/db/structure/record_store_v1_base.h
index 510016b650f..230a2657124 100644
--- a/src/mongo/db/structure/record_store_v1_base.h
+++ b/src/mongo/db/structure/record_store_v1_base.h
@@ -38,13 +38,63 @@ namespace mongo {
class CappedRecordStoreV1Iterator;
class DocWriter;
class ExtentManager;
- class NamespaceDetails;
class Record;
+ class RecordStoreV1MetaData {
+ public:
+ virtual ~RecordStoreV1MetaData(){}
+
+ virtual int bucket(int size) const = 0;
+
+ virtual const DiskLoc& capExtent() const = 0;
+ virtual void setCapExtent( const DiskLoc& loc ) = 0;
+
+ virtual const DiskLoc& capFirstNewRecord() const = 0;
+ virtual void setCapFirstNewRecord( const DiskLoc& loc ) = 0;
+
+ virtual bool capLooped() const = 0;
+ virtual void clearSystemFlags() = 0;
+
+ virtual long long dataSize() const = 0;
+ virtual long long numRecords() const = 0;
+
+ virtual void incrementStats( long long dataSizeIncrement,
+ long long numRecordsIncrement ) = 0;
+
+ virtual void setStats( long long dataSizeIncrement,
+ long long numRecordsIncrement ) = 0;
+
+ virtual const DiskLoc& deletedListEntry( int bucket ) const = 0;
+ virtual void setDeletedListEntry( int bucket, const DiskLoc& loc ) = 0;
+ virtual void orphanDeletedList() = 0;
+
+ virtual const DiskLoc& firstExtent() const = 0;
+ virtual void setFirstExtent( const DiskLoc& loc ) = 0;
+
+ virtual const DiskLoc& lastExtent() const = 0;
+ virtual void setLastExtent( const DiskLoc& loc ) = 0;
+
+ virtual bool isCapped() const = 0;
+
+ virtual bool isUserFlagSet( int flag ) const = 0;
+
+ virtual int lastExtentSize() const = 0;
+ virtual void setLastExtentSize( int newMax ) = 0;
+
+ virtual long long maxCappedDocs() const = 0;
+
+ virtual double paddingFactor() const = 0;
+
+ virtual void setPaddingFactor( double paddingFactor ) = 0;
+
+ virtual int quantizePowerOf2AllocationSpace(int allocSize) const = 0;
+
+ };
+
class RecordStoreV1Base : public RecordStore {
public:
RecordStoreV1Base( const StringData& ns,
- NamespaceDetails* details,
+ RecordStoreV1MetaData* details,
ExtentManager* em,
bool isSystemIndexes );
@@ -67,7 +117,7 @@ namespace mongo {
// TODO: another sad one
virtual const DeletedRecord* deletedRecordFor( const DiskLoc& loc ) const;
- const NamespaceDetails* details() const { return _details; }
+ const RecordStoreV1MetaData* details() const { return _details.get(); }
/**
* @return the actual size to create
@@ -112,7 +162,7 @@ namespace mongo {
*/
void _addRecordToRecListInExtent(Record* r, DiskLoc loc);
- NamespaceDetails* _details;
+ scoped_ptr<RecordStoreV1MetaData> _details;
ExtentManager* _extentManager;
bool _isSystemIndexes;
diff --git a/src/mongo/db/structure/record_store_v1_capped.cpp b/src/mongo/db/structure/record_store_v1_capped.cpp
index 20c6933c2ba..add403210f7 100644
--- a/src/mongo/db/structure/record_store_v1_capped.cpp
+++ b/src/mongo/db/structure/record_store_v1_capped.cpp
@@ -60,7 +60,7 @@ namespace mongo {
CappedRecordStoreV1::CappedRecordStoreV1( Collection* collection,
const StringData& ns,
- NamespaceDetails* details,
+ RecordStoreV1MetaData* details,
ExtentManager* em,
bool isSystemIndexes )
: RecordStoreV1Base( ns, details, em, isSystemIndexes ),
@@ -315,7 +315,7 @@ namespace mongo {
}
void CappedRecordStoreV1::cappedCheckMigrate() {
- // migrate old NamespaceDetails format
+ // migrate old RecordStoreV1MetaData format
if ( _details->capExtent().a() == 0 && _details->capExtent().getOfs() == 0 ) {
_details->setCapFirstNewRecord( DiskLoc().setInvalid() );
// put all the DeletedRecords in cappedListOfAllDeletedRecords()
@@ -554,8 +554,6 @@ namespace mongo {
void CappedRecordStoreV1::addDeletedRec( const DiskLoc& dloc ) {
DeletedRecord* d = drec( dloc );
- BOOST_STATIC_ASSERT( sizeof(NamespaceDetails::Extra) <= sizeof(NamespaceDetails) );
-
{
Record *r = (Record *) getDur().writingPtr(d, sizeof(Record));
d = &r->asDeleted();
diff --git a/src/mongo/db/structure/record_store_v1_capped.h b/src/mongo/db/structure/record_store_v1_capped.h
index d8a0252817a..52610ba97b0 100644
--- a/src/mongo/db/structure/record_store_v1_capped.h
+++ b/src/mongo/db/structure/record_store_v1_capped.h
@@ -43,7 +43,7 @@ namespace mongo {
public:
CappedRecordStoreV1( Collection* collection,
const StringData& ns,
- NamespaceDetails* details,
+ RecordStoreV1MetaData* details,
ExtentManager* em,
bool isSystemIndexes );
diff --git a/src/mongo/db/structure/record_store_v1_capped_iterator.cpp b/src/mongo/db/structure/record_store_v1_capped_iterator.cpp
index 2d5c4b64bc3..44be4685adf 100644
--- a/src/mongo/db/structure/record_store_v1_capped_iterator.cpp
+++ b/src/mongo/db/structure/record_store_v1_capped_iterator.cpp
@@ -48,7 +48,7 @@ namespace mongo {
if (_curr.isNull()) {
- const NamespaceDetails* nsd = _recordStore->details();
+ const RecordStoreV1MetaData* nsd = _recordStore->details();
// If a start position isn't specified, we fill one out from the start of the
// collection.
@@ -140,7 +140,7 @@ namespace mongo {
DiskLoc CappedRecordStoreV1Iterator::getNextCapped(const DiskLoc& dl) {
invariant(!dl.isNull());
- NamespaceDetails* details = _recordStore->_details;
+ const RecordStoreV1MetaData* details = _recordStore->details();
if (CollectionScanParams::FORWARD == _direction) {
// If it's not looped, it's easy.
diff --git a/src/mongo/db/structure/record_store_v1_simple.cpp b/src/mongo/db/structure/record_store_v1_simple.cpp
index 0964821b646..8a64e735d3d 100644
--- a/src/mongo/db/structure/record_store_v1_simple.cpp
+++ b/src/mongo/db/structure/record_store_v1_simple.cpp
@@ -42,7 +42,6 @@
#include "mongo/db/storage/record.h"
#include "mongo/db/structure/catalog/namespace_details.h"
#include "mongo/db/structure/record_store_v1_simple_iterator.h"
-#include "mongo/util/mmap.h"
#include "mongo/util/progress_meter.h"
#include "mongo/util/touch_pages.h"
@@ -62,7 +61,7 @@ namespace mongo {
&freelistIterations );
SimpleRecordStoreV1::SimpleRecordStoreV1( const StringData& ns,
- NamespaceDetails* details,
+ RecordStoreV1MetaData* details,
ExtentManager* em,
bool isSystemIndexes )
: RecordStoreV1Base( ns, details, em, isSystemIndexes ) {
@@ -263,7 +262,6 @@ namespace mongo {
void SimpleRecordStoreV1::addDeletedRec( const DiskLoc& dloc ) {
DeletedRecord* d = drec( dloc );
- BOOST_STATIC_ASSERT( sizeof(NamespaceDetails::Extra) <= sizeof(NamespaceDetails) );
{
Record *r = (Record *) getDur().writingPtr(d, sizeof(Record));
diff --git a/src/mongo/db/structure/record_store_v1_simple.h b/src/mongo/db/structure/record_store_v1_simple.h
index b921b410493..e653cf75cb2 100644
--- a/src/mongo/db/structure/record_store_v1_simple.h
+++ b/src/mongo/db/structure/record_store_v1_simple.h
@@ -41,7 +41,7 @@ namespace mongo {
class SimpleRecordStoreV1 : public RecordStoreV1Base {
public:
SimpleRecordStoreV1( const StringData& ns,
- NamespaceDetails* details,
+ RecordStoreV1MetaData* details,
ExtentManager* em,
bool isSystemIndexes );
diff --git a/src/mongo/dbtests/namespacetests.cpp b/src/mongo/dbtests/namespacetests.cpp
index 17455edc906..72cea76576b 100644
--- a/src/mongo/dbtests/namespacetests.cpp
+++ b/src/mongo/dbtests/namespacetests.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/structure/record_store_v1_simple.h"
#include "mongo/db/structure/catalog/namespace.h"
#include "mongo/db/structure/catalog/namespace_details.h"
+#include "mongo/db/structure/catalog/namespace_details_rsv1_metadata.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/dbtests/dbtests.h"
@@ -537,10 +538,9 @@ namespace NamespaceTests {
void run() {
string myns = (string)ns() + "AllocQuantized";
-
db()->namespaceIndex().add_ns( myns, DiskLoc(), false );
SimpleRecordStoreV1 rs( myns,
- db()->namespaceIndex().details( myns ),
+ new NamespaceDetailsRSV1MetaData( db()->namespaceIndex().details( myns ) ),
&db()->getExtentManager(),
false );
@@ -583,7 +583,7 @@ namespace NamespaceTests {
db()->namespaceIndex().add_ns( myns, DiskLoc(), false );
SimpleRecordStoreV1 rs( myns + ".$x",
- db()->namespaceIndex().details( myns ),
+ new NamespaceDetailsRSV1MetaData( db()->namespaceIndex().details( myns ) ),
&db()->getExtentManager(),
false );
@@ -605,7 +605,7 @@ namespace NamespaceTests {
db()->namespaceIndex().add_ns( myns, DiskLoc(), false );
SimpleRecordStoreV1 rs( myns + ".$x",
- db()->namespaceIndex().details( myns ),
+ new NamespaceDetailsRSV1MetaData( db()->namespaceIndex().details( myns ) ),
&db()->getExtentManager(),
true );