summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2009-03-19 15:38:49 -0400
committerDwight <dmerriman@gmail.com>2009-03-19 15:38:49 -0400
commite35ffd32ddf0d5b0481563016eabee3b47602abb (patch)
tree1561d6206e09307dd7407c41c594bf3e7784f3bd /db
parent19125066b35c11cbf6c501289e43191d5ed570dc (diff)
downloadmongo-e35ffd32ddf0d5b0481563016eabee3b47602abb.tar.gz
improved dropIndex for new recstore
Diffstat (limited to 'db')
-rw-r--r--db/pdfile.cpp27
-rw-r--r--db/reccache.cpp54
-rw-r--r--db/reccache.h3
3 files changed, 54 insertions, 30 deletions
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index c0470a4a8c9..7dc6cecf946 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -573,24 +573,23 @@ assert( !eloc.isNull() );
void IndexDetails::kill() {
string ns = indexNamespace(); // e.g. foo.coll.$ts_1
- {
- // clean up parent namespace index cache
- NamespaceDetailsTransient::get( parentNS().c_str() ).deletedIndex();
- // clean up in system.indexes
- BSONObjBuilder b;
- b.append("name", indexName().c_str());
- b.append("ns", parentNS().c_str());
- BSONObj cond = b.done(); // e.g.: { name: "ts_1", ns: "foo.coll" }
- string system_indexes = database->name + ".system.indexes";
- int n = deleteObjects(system_indexes.c_str(), cond, false, 0, true);
- wassert( n == 1 );
- }
+ // clean up parent namespace index cache
+ NamespaceDetailsTransient::get( parentNS().c_str() ).deletedIndex();
+
+ BSONObjBuilder b;
+ b.append("name", indexName().c_str());
+ b.append("ns", parentNS().c_str());
+ BSONObj cond = b.done(); // e.g.: { name: "ts_1", ns: "foo.coll" }
BtreeStore::drop(ns.c_str());
- // dropNS(ns);
- // database->namespaceIndex.kill(ns.c_str());
head.setInvalid();
info.setInvalid();
+
+ // clean up in system.indexes. we do this last on purpose. note we have
+ // to make the cond object before the drop() above though.
+ string system_indexes = database->name + ".system.indexes";
+ int n = deleteObjects(system_indexes.c_str(), cond, false, 0, true);
+ wassert( n == 1 );
}
diff --git a/db/reccache.cpp b/db/reccache.cpp
index 9f95c385945..41fbd8f13a4 100644
--- a/db/reccache.cpp
+++ b/db/reccache.cpp
@@ -110,7 +110,13 @@ BasicRecStore* RecCache::initStore(int n) {
return 0;
}
-void RecCache::initStoreByNs(const char *_ns) {
+/* find the filename for a given ns.
+ format is
+ <n>-<escaped_ns>.idx
+ returns filename. found is true if found. If false, a proposed name is returned for (optional) creation
+ of the file.
+*/
+string RecCache::findStoreFilename(const char *_ns, bool& found) {
string namefrag;
{
stringstream ss;
@@ -130,8 +136,8 @@ void RecCache::initStoreByNs(const char *_ns) {
string s = i->leaf();
const char *p = strstr(s.c_str(), namefrag.c_str());
if( p ) {
- _initStore(s);
- return;
+ found = true;
+ return s;
}
if( strstr(s.c_str(), ".idx") ) {
stringstream ss(s);
@@ -148,10 +154,17 @@ void RecCache::initStoreByNs(const char *_ns) {
massert(s, false);
}
- // DNE. create it.
+ // DNE. return a name that would work.
stringstream ss;
ss << nmax+1 << namefrag;
- _initStore(ss.str());
+ found = false;
+ return ss.str();
+}
+
+void RecCache::initStoreByNs(const char *_ns) {
+ bool found;
+ string fn = findStoreFilename(_ns, found);
+ _initStore(fn);
}
inline void RecCache::writeIfDirty(Node *n) {
@@ -284,12 +297,13 @@ void RecCache::closeStore(BasicRecStore *rs) {
delete rs; // closes file
}
-void RecCache::drop(const char *ns) {
+void RecCache::drop(const char *_ns) {
// todo: test with a non clean shutdown file
boostlock lk(rcmutex);
char buf[256];
{
+ const char *ns = _ns;
char *p = buf;
while( 1 ) {
if( *ns == '$' ) *p = '_';
@@ -302,18 +316,28 @@ void RecCache::drop(const char *ns) {
assert( p - buf < (int) sizeof(buf) );
}
BasicRecStore *&rs = storesByNs[buf];
- if( rs == 0 )
- initStoreByNs(buf); // load -- creates if DNE which is slightly bad.
- {
- string fname = rs->filename;
+ string fname;
+ if( rs ) {
+ fname = rs->filename;
closeStore(rs);
rs = 0;
- try {
- boost::filesystem::remove(fname);
- }
- catch(...) {
- log() << "couldn't remove file " << fname << endl;
+ }
+ else {
+ bool found;
+ fname = findStoreFilename(buf, found);
+ if( !found ) {
+ log() << "RecCache::drop: no idx file found for " << _ns << endl;
+ return;
}
+ path pf(dbpath);
+ pf /= fname;
+ fname = pf.string();
+ }
+ try {
+ boost::filesystem::remove(fname);
+ }
+ catch(...) {
+ log() << "RecCache::drop: exception removing file " << fname << endl;
}
}
diff --git a/db/reccache.h b/db/reccache.h
index 7b886ae3eab..ed2214fa5ad 100644
--- a/db/reccache.h
+++ b/db/reccache.h
@@ -45,7 +45,8 @@ class RecCache {
BasicRecStore* _initStore(string fname);
BasicRecStore* initStore(int n);
- void initStoreByNs(const char *ns);
+ string findStoreFilename(const char *_ns, bool& found);
+ void initStoreByNs(const char *escaped_ns);
void closeStore(BasicRecStore *rs);
/* get the right file for a given diskloc */