2009-01-31 23:27:25 +01:00
|
|
|
// rec.h
|
|
|
|
|
2009-02-03 20:22:48 +01:00
|
|
|
/* TODO for _RECSTORE
|
|
|
|
|
|
|
|
_ support > 2GB data per file
|
|
|
|
_ multiple files, not just indexes.dat
|
2009-03-13 16:56:28 +01:00
|
|
|
_ lazier writes? (may be done?)
|
2009-02-03 20:22:48 +01:00
|
|
|
_ configurable cache size
|
2009-02-03 20:42:53 +01:00
|
|
|
_ fix on abnormal terminations to be able to restart some
|
2009-02-03 20:22:48 +01:00
|
|
|
*/
|
|
|
|
|
2009-01-31 23:27:25 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "reci.h"
|
2009-02-03 00:18:22 +01:00
|
|
|
#include "reccache.h"
|
2009-01-31 23:27:25 +01:00
|
|
|
|
|
|
|
namespace mongo {
|
|
|
|
|
2009-02-06 19:29:57 +01:00
|
|
|
/* --------------------------------------------------------------------------
|
|
|
|
A RecStoreInterface for the normal mongo mem mapped file (MongoDataFile)
|
|
|
|
storage
|
2009-02-01 01:09:46 +01:00
|
|
|
*/
|
|
|
|
|
2009-01-31 23:27:25 +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) { }
|
2009-03-17 22:02:21 +01:00
|
|
|
|
|
|
|
static void drop(const char *ns) {
|
|
|
|
dropNS(ns);
|
|
|
|
}
|
2009-01-31 23:27:25 +01:00
|
|
|
};
|
|
|
|
|
2009-02-06 19:29:57 +01:00
|
|
|
/* 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) { }
|
2009-03-17 22:02:21 +01:00
|
|
|
|
|
|
|
static void drop(const char *ns) {
|
|
|
|
log() << "warning: drop() not yet implemented for InMem_RecStore" << endl;
|
|
|
|
}
|
2009-02-01 01:09:46 +01:00
|
|
|
};
|
|
|
|
|
2009-03-13 16:56:28 +01:00
|
|
|
/* Glue btree to RecStoreInterface: ---------------------------- */
|
2009-02-01 01:09:46 +01:00
|
|
|
|
|
|
|
// pick your store for indexes by setting this typedef
|
2009-02-03 18:02:22 +01:00
|
|
|
#if defined(_RECSTORE)
|
2009-03-13 16:56:28 +01:00
|
|
|
typedef Cached_RecStore BtreeStore;
|
2009-02-03 18:02:22 +01:00
|
|
|
#else
|
2009-01-31 23:27:25 +01:00
|
|
|
typedef MongoMemMapped_RecStore BtreeStore;
|
2009-02-06 19:29:57 +01:00
|
|
|
#endif
|
2009-01-31 23:27:25 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-31 23:27:25 +01:00
|
|
|
}
|