0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/db/rec.h

100 lines
2.3 KiB
C
Raw Normal View History

// rec.h
/* TODO for _RECSTORE
_ support > 2GB data per file
_ multiple files, not just indexes.dat
_ lazier writes? (may be done?)
_ configurable cache size
_ fix on abnormal terminations to be able to restart some
*/
#pragma once
#include "reci.h"
2009-02-03 00:18:22 +01:00
#include "reccache.h"
namespace mongo {
/* --------------------------------------------------------------------------
A RecStoreInterface for the normal mongo mem mapped file (MongoDataFile)
storage
2009-02-01 01:09:46 +01:00
*/
class MongoMemMapped_RecStore : public RecStoreInterface {
public:
static char* get(DiskLoc d, unsigned len) { return d.rec()->data; }
static DiskLoc insert(const char *ns, const void *obuf, int len, bool god) {
return theDataFileMgr.insert(ns, obuf, len, god);
}
2009-02-03 00:18:22 +01:00
static void modified(DiskLoc d) { }
static void drop(const char *ns) {
dropNS(ns);
}
};
/* An in memory RecStoreInterface implementation ----------------------------
2009-02-01 01:09:46 +01:00
*/
class InMem_RecStore : public RecStoreInterface {
enum { INMEMFILE = 0x70000000 };
public:
static char* get(DiskLoc d, unsigned len) {
assert( d.a() == INMEMFILE );
2009-02-01 20:53:54 +01:00
#ifdef __LP64__
2009-02-01 03:25:40 +01:00
massert("64 bit not done", false);
return 0;
2009-02-01 20:53:54 +01:00
#else
return (char *) d.getOfs();
#endif
2009-02-01 01:09:46 +01:00
}
static DiskLoc insert(const char *ns, const void *obuf, int len, bool god) {
2009-02-01 06:11:34 +01:00
#ifdef __LP64__
assert( 0 );
throw -1;
#else
2009-02-01 01:09:46 +01:00
char *p = (char *) malloc(len);
assert( p );
memcpy(p, obuf, len);
int b = (int) p;
assert( b > 0 );
return DiskLoc(INMEMFILE, b);
2009-02-01 06:11:34 +01:00
#endif
2009-02-01 01:09:46 +01:00
}
2009-02-03 00:18:22 +01:00
static void modified(DiskLoc d) { }
static void drop(const char *ns) {
log() << "warning: drop() not yet implemented for InMem_RecStore" << endl;
}
2009-02-01 01:09:46 +01:00
};
/* Glue btree to RecStoreInterface: ---------------------------- */
2009-02-01 01:09:46 +01:00
// pick your store for indexes by setting this typedef
#if defined(_RECSTORE)
typedef Cached_RecStore BtreeStore;
#else
typedef MongoMemMapped_RecStore BtreeStore;
#endif
const int BucketSize = 8192;
inline BtreeBucket* DiskLoc::btree() const {
assert( fileNo != -1 );
return (BtreeBucket*) BtreeStore::get(*this, BucketSize);
}
2009-02-03 00:18:22 +01:00
inline BtreeBucket* DiskLoc::btreemod() const {
assert( fileNo != -1 );
BtreeBucket *b = (BtreeBucket*) BtreeStore::get(*this, BucketSize);
BtreeStore::modified(*this);
return b;
}
}