summaryrefslogtreecommitdiff
path: root/db/reccache.h
diff options
context:
space:
mode:
Diffstat (limited to 'db/reccache.h')
-rw-r--r--db/reccache.h39
1 files changed, 18 insertions, 21 deletions
diff --git a/db/reccache.h b/db/reccache.h
index 871ab582935..157548a5476 100644
--- a/db/reccache.h
+++ b/db/reccache.h
@@ -31,51 +31,48 @@ class RecCache {
char *data;
DiskLoc loc;
bool dirty;
- Node *older, *newer;
+ Node *older, *newer; // lru
};
boost::mutex rcmutex; // mainly to coordinate with the lazy writer thread
unsigned recsize;
- map<DiskLoc, Node*> m;
+ map<DiskLoc, Node*> m; // the cache
Node *newest, *oldest;
unsigned nnodes;
set<DiskLoc> dirtyl;
- vector<BasicRecStore*> stores;
- map<string, BasicRecStore*> storesByNs;
+ vector<BasicRecStore*> stores; // DiskLoc::a() indicates the index into this vector
+ map<string, BasicRecStore*> storesByNsKey; // nskey -> BasicRecStore*
public:
enum { Base = 10000 };
private:
BasicRecStore* _initStore(string fname);
BasicRecStore* initStore(int n);
string findStoreFilename(const char *_ns, bool& found);
- void initStoreByNs(const char *escaped_ns);
+ void initStoreByNs(const char *ns, const string& nskey);
void closeStore(BasicRecStore *rs);
+ static string directory();
+ static string mknskey(const char *ns) {
+ return directory() + ns;
+ }
+
/* get the right file for a given diskloc */
BasicRecStore& store(DiskLoc& d) {
int n = d.a() - Base;
if( (int) stores.size() > n ) {
BasicRecStore *rs = stores[n];
- if( rs )
+ if( rs ) {
+ assert( rs->fileNumber == n );
return *rs;
+ }
}
return *initStore(n);
}
BasicRecStore& store(const char *ns) {
- char buf[256];
- char *p = buf;
- while( 1 ) {
- if( *ns == '$' ) *p = '_';
- else
- *p = *ns;
- if( *ns == 0 )
- break;
- p++; ns++;
- }
- assert( p - buf < (int) sizeof(buf) );
- BasicRecStore *&rs = storesByNs[buf];
+ string nskey = mknskey(ns);
+ BasicRecStore *&rs = storesByNsKey[nskey];
if( rs )
return *rs;
- initStoreByNs(buf);
+ initStoreByNs(ns, nskey);
return *rs;
}
@@ -117,9 +114,9 @@ private:
void dump();
public:
- /* all public functions (except constructor) use the mutex */
+ /* all public functions (except constructor) should use the mutex */
- RecCache(unsigned sz) : recsize(sz) {
+ RecCache(unsigned recsz) : recsize(recsz) {
nnodes = 0;
newest = oldest = 0;
}