summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/namespace.cpp18
-rw-r--r--db/namespace.h3
-rw-r--r--db/pdfile.cpp4
-rw-r--r--db/pdfile.h19
-rw-r--r--util/hashtab.h13
-rw-r--r--util/mmap.h73
6 files changed, 30 insertions, 100 deletions
diff --git a/db/namespace.cpp b/db/namespace.cpp
index e7cff360425..472feda3a75 100644
--- a/db/namespace.cpp
+++ b/db/namespace.cpp
@@ -132,10 +132,10 @@ namespace mongo {
unsigned long long len = 0;
boost::filesystem::path nsPath = path();
string pathString = nsPath.string();
- MMF::Pointer p;
+ void *p;
if( MMF::exists(nsPath) ) {
p = f.mapWithOptions(pathString.c_str(), durable?MMF::READONLY:0);
- if( !p.isNull() ) {
+ if( p ) {
len = f.length();
if ( len % (1024*1024) != 0 ){
log() << "bad .ns file: " << pathString << endl;
@@ -149,19 +149,20 @@ namespace mongo {
maybeMkdir();
unsigned long long l = lenForNewNsFiles;
p = f.map(pathString.c_str(), l, durable?MMF::READONLY:0);
- if( !p.isNull() ) {
+ if( p ) {
len = l;
assert( len == lenForNewNsFiles );
}
}
- if ( p.isNull() ) {
- problem() << "couldn't open file " << pathString << " terminating" << endl;
+ if ( p == 0 ) {
+ /** TODO: this shouldn't terminate? */
+ log() << "error couldn't open file " << pathString << " terminating" << endl;
dbexit( EXIT_FS );
}
assert( len <= 0x7fffffff );
- ht = new HashTable<Namespace,NamespaceDetails,MMF::Pointer>(p, (int) len, "namespace index");
+ ht = new HashTable<Namespace,NamespaceDetails>(p, (int) len, "namespace index");
if( checkNsFilesOnLoad )
ht->iterAll(namespaceOnLoadCallback);
}
@@ -171,7 +172,6 @@ namespace mongo {
if ( ! k.hasDollarSign() )
l->push_back( (string)k );
}
-
void NamespaceIndex::getNamespaces( list<string>& tofill , bool onlyCollections ) const {
assert( onlyCollections ); // TODO: need to implement this
// need boost::bind or something to make this less ugly
@@ -243,14 +243,14 @@ namespace mongo {
if ( capped == 0 ) {
if ( left < 24 || left < (lenToAlloc >> 3) ) {
// you get the whole thing.
- DataFileMgr::grow(loc, regionlen);
+ //DataFileMgr::grow(loc, regionlen);
return loc;
}
}
/* split off some for further use. */
r->lengthWithHeaders = lenToAlloc;
- DataFileMgr::grow(loc, lenToAlloc);
+ //DataFileMgr::grow(loc, lenToAlloc);
DiskLoc newDelLoc = loc;
newDelLoc.inc(lenToAlloc);
DeletedRecord *newDel = DataFileMgr::makeDeletedRecord(newDelLoc, left);
diff --git a/db/namespace.h b/db/namespace.h
index 48d08b9701a..83ff4cfd491 100644
--- a/db/namespace.h
+++ b/db/namespace.h
@@ -23,7 +23,6 @@
#include "queryutil.h"
#include "diskloc.h"
#include "../util/hashtab.h"
-#include "../util/mmap.h"
namespace mongo {
@@ -534,7 +533,7 @@ namespace mongo {
void maybeMkdir() const;
MMF f;
- HashTable<Namespace,NamespaceDetails,MMF::Pointer> *ht;
+ HashTable<Namespace,NamespaceDetails> *ht;
string dir_;
string database_;
};
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index f52c1962d44..8f63db6176a 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -379,11 +379,11 @@ namespace mongo {
{
unsigned long long sz = size;
- _p = mmf.map(filename, sz);
+ _p = (char *) mmf.map(filename, sz);
assert( sz <= 0x7fffffff );
size = (int) sz;
}
- header = (DataFileHeader *) _p.at(0, DataFileHeader::HeaderSize);
+ header = (DataFileHeader *) _p;
if( sizeof(char *) == 4 )
uassert( 10084 , "can't map file memory - mongo requires 64 bit build for larger datasets", header);
else
diff --git a/db/pdfile.h b/db/pdfile.h
index 900a1259783..2b6c70203cd 100644
--- a/db/pdfile.h
+++ b/db/pdfile.h
@@ -89,7 +89,7 @@ namespace mongo {
void grow(DiskLoc dl, int size);
MMF mmf;
- MMF::Pointer _p;
+ char* _p;
DataFileHeader *header;
int fileNo;
};
@@ -133,7 +133,7 @@ namespace mongo {
static Extent* getExtent(const DiskLoc& dl);
static Record* getRecord(const DiskLoc& dl);
static DeletedRecord* makeDeletedRecord(const DiskLoc& dl, int len);
- static void grow(const DiskLoc& dl, int len);
+ //static void grow(const DiskLoc& dl, int len);
/* does not clean up indexes, etc. : just deletes the record in the pdfile. */
void _deleteRecord(NamespaceDetails *d, const char *ns, Record *todelete, const DiskLoc& dl);
@@ -331,7 +331,7 @@ namespace mongo {
inline Extent* MongoDataFile::_getExtent(DiskLoc loc) {
loc.assertOk();
- Extent *e = (Extent *) _p.at(loc.getOfs(), Extent::HeaderSize());
+ Extent *e = (Extent *) (_p+loc.getOfs());
return e;
}
@@ -350,18 +350,13 @@ namespace mongo {
inline Record* MongoDataFile::recordAt(DiskLoc dl) {
int ofs = dl.getOfs();
if( ofs < DataFileHeader::HeaderSize ) badOfs(ofs); // will uassert - external call to keep out of the normal code path
- return (Record*) _p.at(ofs, -1);
+ return (Record*) (_p+ofs);
}
- inline void MongoDataFile::grow(DiskLoc dl, int size) {
- int ofs = dl.getOfs();
- _p.grow(ofs, size);
- }
-
inline Record* MongoDataFile::makeRecord(DiskLoc dl, int size) {
int ofs = dl.getOfs();
if( ofs < DataFileHeader::HeaderSize ) badOfs(ofs); // will uassert - external call to keep out of the normal code path
- return (Record*) _p.at(ofs, size);
+ return (Record*) (_p+ofs);
}
inline DiskLoc Record::getNext(const DiskLoc& myLoc) {
@@ -457,10 +452,10 @@ namespace mongo {
BOOST_STATIC_ASSERT( 16 == sizeof(DeletedRecord) );
- inline void DataFileMgr::grow(const DiskLoc& dl, int len) {
+ /*inline void DataFileMgr::grow(const DiskLoc& dl, int len) {
assert( dl.a() != -1 );
cc().database()->getFile(dl.a())->grow(dl, len);
- }
+ }*/
inline DeletedRecord* DataFileMgr::makeDeletedRecord(const DiskLoc& dl, int len) {
assert( dl.a() != -1 );
diff --git a/util/hashtab.h b/util/hashtab.h
index 6604864e65a..4805658d6d8 100644
--- a/util/hashtab.h
+++ b/util/hashtab.h
@@ -37,8 +37,7 @@ namespace mongo {
template <
class Key,
- class Type,
- class PTR
+ class Type
>
class HashTable : boost::noncopyable {
public:
@@ -54,13 +53,11 @@ namespace mongo {
hash = 0;
}
};
- PTR _buf;
+ Node *_buf;
int n;
int maxChain;
- Node& nodes(int i) {
- return *((Node*) _buf.at(i * sizeof(Node), sizeof(Node)));
- }
+ Node& nodes(int i) { return _buf[i]; }
int _find(const Key& k, bool& found) {
found = false;
@@ -99,14 +96,14 @@ namespace mongo {
public:
/* buf must be all zeroes on initialization. */
- HashTable(PTR buf, int buflen, const char *_name) : name(_name) {
+ HashTable(void *buf, int buflen, const char *_name) : name(_name) {
int m = sizeof(Node);
// out() << "hashtab init, buflen:" << buflen << " m:" << m << endl;
n = buflen / m;
if ( (n & 1) == 0 )
n--;
maxChain = (int) (n * 0.05);
- _buf = buf;
+ _buf = (Node*) buf;
//nodes = (Node *) buf;
if ( sizeof(Node) != 628 ){
diff --git a/util/mmap.h b/util/mmap.h
index eca6db811fb..870ef85f0fe 100644
--- a/util/mmap.h
+++ b/util/mmap.h
@@ -81,84 +81,21 @@ namespace mongo {
}
};
- /** template for what a new storage engine's class definition must implement
- PRELIMINARY - subject to change.
- */
- class StorageContainerTemplate : public MongoFile {
- protected:
- virtual void close();
- virtual void flush(bool sync);
- public:
- virtual long length();
-
- /** pointer to a range of space in this storage unit */
- class Pointer {
- public:
- /** retried address of buffer at offset 'offset' withing the storage unit. returned range is a contiguous
- buffer reflecting what is in storage. caller will not read or write past 'len'.
-
- note calls may be received that are at different points in a range and different lengths. however
- for now assume that on writes, if a call is made, previously returned addresses are no longer valid. i.e.
- p = at(10000, 500);
- q = at(10000, 600);
- after the second call it is ok if p is invalid.
- */
- void* at(int offset, int len);
-
- void* atAsIndicated(int offset);
-
- /** indicate that we wrote to the range (from a previous at() call) and that it needs
- flushing to disk.
- */
- void written(int offset, int len);
-
- bool isNull() const;
- };
-
- /** commit written() calls from above. */
- void commit();
-
- Pointer open(const char *filename);
- Pointer open(const char *_filename, long &length, /*MongoFile::Options*/ int options=0);
- };
-
class MemoryMappedFile : public MongoFile {
public:
- class Pointer {
- char *_base;
- public:
- Pointer() : _base(0) { }
- Pointer(void *p) : _base((char*) p) { }
- void* at(int offset, int maxLen) { return _base + offset; }
- void* atAsIndicated(int offset) { return _base + offset; }
- void grow(int offset, int len) { /* no action required with mem mapped file */ }
- bool isNull() const { return _base == 0; }
- };
-
MemoryMappedFile();
- ~MemoryMappedFile() {
+ virtual ~MemoryMappedFile() {
destroyed(); // cleans up from the master list of mmaps
close();
}
void close();
- void* testGetCopyOnWriteView();
- void testCloseCopyOnWriteView(void *);
-
// Throws exception if file doesn't exist. (dm may2010: not sure if this is always true?)
void* map(const char *filename);
void* mapWithOptions(const char *filename, int options);
- /*To replace map():
-
- Pointer open( const char *filename ) {
- void *p = map(filename);
- uassert(13077, "couldn't open/map file", p);
- return Pointer(p);
- }*/
-
/* Creates with length if DNE, otherwise uses existing file length,
passed length.
@param options MongoFile::Options bits
@@ -173,15 +110,17 @@ namespace mongo {
void flush(bool sync);
virtual Flushable * prepareFlush();
- long shortLength() const { return (long) len; }
+ long shortLength() const { return (long) len; }
unsigned long long length() const { return len; }
-
- string filename() const { return _filename; }
+ string filename() const { return _filename; }
#if defined(_DURABLE) && defined(_DEBUG)
static void* getWriteViewFor(void *ptr);
#endif
+ void* testGetCopyOnWriteView();
+ void testCloseCopyOnWriteView(void *);
+
private:
static void updateLength( const char *filename, unsigned long long &length );