Skip to content

Commit

Permalink
implemented dropIndexes for alt rec store
Browse files Browse the repository at this point in the history
  • Loading branch information
dwight committed Mar 17, 2009
1 parent 5cd0f0e commit 7165d73
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 6 deletions.
7 changes: 6 additions & 1 deletion db/btree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,12 @@ namespace mongo {
_KeyNode& kn = k(pos);
if ( kn.isUnused() ) {
DEBUGGING out() << "reusing unused key" << endl;
massert( "btree reuse unused key error?", kn.prevChildBucket == lChild );
if( kn.prevChildBucket != lChild ) {
/* is it ok if they don't match, and we just need to update??? */
log() << "pcb:" << kn.prevChildBucket.toString() << " lChild:" << lChild.toString() << '\n';
log() << "rChild:" << rChild.toString() << '\n';
massert( "btree reuse unused key error?", false);
}
// check rchild too?
kn.setUsed();
return 0;
Expand Down
1 change: 1 addition & 0 deletions db/dbcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ namespace mongo {

d->aboutToDeleteAnIndex();

/* there may be pointers pointing at keys in the btree(s). kill them. */
ClientCursor::invalidate(toDeleteNs.c_str());

// delete a specific index or all?
Expand Down
3 changes: 1 addition & 2 deletions db/javajs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,6 @@ namespace mongo {

}

} // namespace mongo

#if defined(_MAIN)
int main() {
return javajstest();
Expand All @@ -738,3 +736,4 @@ int main() {

#endif

} // namespace mongo
3 changes: 2 additions & 1 deletion db/pdfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ assert( !eloc.isNull() );
wassert( n == 1 );
}

dropNS(ns);
BtreeStore::drop(ns.c_str());
// dropNS(ns);
// database->namespaceIndex.kill(ns.c_str());
head.setInvalid();
info.setInvalid();
Expand Down
2 changes: 1 addition & 1 deletion db/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ namespace mongo {
try {
return _runCommands(ns, jsobj, ss, b, anObjBuilder, fromRepl, queryOptions);
}
catch ( AssertionException e ) {
catch ( AssertionException& e ) {
if ( !e.msg.empty() )
anObjBuilder.append("assertion", e.msg);
}
Expand Down
8 changes: 8 additions & 0 deletions db/rec.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class MongoMemMapped_RecStore : public RecStoreInterface {
}

static void modified(DiskLoc d) { }

static void drop(const char *ns) {
dropNS(ns);
}
};

/* An in memory RecStoreInterface implementation ----------------------------
Expand Down Expand Up @@ -63,6 +67,10 @@ class InMem_RecStore : public RecStoreInterface {
}

static void modified(DiskLoc d) { }

static void drop(const char *ns) {
log() << "warning: drop() not yet implemented for InMem_RecStore" << endl;
}
};

/* Glue btree to RecStoreInterface: ---------------------------- */
Expand Down
57 changes: 57 additions & 0 deletions db/reccache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ void RecCache::writeDirty( set<DiskLoc>::iterator startAt, bool rawLog ) {
}
catch(...) {
const char *message = "Problem: bad() in RecCache::writeDirty, file io error\n";

if ( rawLog )
rawOut( message );
else
Expand Down Expand Up @@ -260,6 +261,62 @@ void RecCache::dump() {
// cout << endl;
}

void RecCache::closeStore(BasicRecStore *rs) {
for( set<DiskLoc>::iterator i = dirtyl.begin(); i != dirtyl.end(); ) {
DiskLoc k = *i++;
if( k.a() == rs->fileNumber )
dirtyl.erase(k);
}

for( map<DiskLoc,Node*>::iterator i = m.begin(); i != m.end(); ) {
DiskLoc k = i->first;
i++;
if( k.a() == rs->fileNumber )
m.erase(k);
}

for( unsigned i = 0; i < stores.size(); i++ ) {
if( stores[i] == rs ) {
stores[i] = 0;
break;
}
}
delete rs; // closes file
}

void RecCache::drop(const char *ns) {
// todo: test with a non clean shutdown file
boostlock lk(rcmutex);

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];
if( rs == 0 )
initStoreByNs(buf); // load -- creates if DNE which is slightly bad.
{
string fname = rs->filename;
closeStore(rs);
rs = 0;
try {
boost::filesystem::remove(fname);
}
catch(...) {
log() << "couldn't remove file " << fname << endl;
}
}
}

void dbunlocking() {
dassert( dbMutexInfo.isLocked() );
theRecCache.ejectOld();
Expand Down
7 changes: 7 additions & 0 deletions db/reccache.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class RecCache {
BasicRecStore* _initStore(string fname);
BasicRecStore* initStore(int n);
void initStoreByNs(const char *ns);
void closeStore(BasicRecStore *rs);

/* get the right file for a given diskloc */
BasicRecStore& store(DiskLoc& d) {
Expand Down Expand Up @@ -164,6 +165,8 @@ class RecCache {
return n->data;
}

void drop(const char *ns);

DiskLoc insert(const char *ns, const void *obuf, int len, bool god) {
boostlock lk(rcmutex);
BasicRecStore& rs = store(ns);
Expand Down Expand Up @@ -197,6 +200,10 @@ class Cached_RecStore : public RecStoreInterface {
static void modified(DiskLoc d) {
theRecCache.dirty(d);
}

static void drop(const char *ns) {
theRecCache.drop(ns);
}
};

} /*namespace*/
2 changes: 2 additions & 0 deletions db/reci.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class RecStoreInterface {
/* insert specified data as a record */
static DiskLoc insert(const char *ns, const void *obuf, int len, bool god) { assert(false); return DiskLoc(); }

/* drop the collection */
static void drop(const char *ns) { assert(false); }
};

}
2 changes: 2 additions & 0 deletions db/recstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class BasicRecStore {

int fileNumber; // this goes in DiskLoc::a

string filename;

private:

void writeHeader();
Expand Down
1 change: 1 addition & 0 deletions db/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static int inited;
void BasicRecStore::init(const char *fn, unsigned recsize)
{
massert( "compile packing problem recstore?", sizeof(RecStoreHeader) == 8192);
filename = fn;
f.open(fn);
uassert( string("couldn't open file:")+fn, f.is_open() );
len = f.len();
Expand Down
8 changes: 8 additions & 0 deletions s/dbgrid.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,14 @@
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="release_nojni|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug Recstore|Win32"
>
Expand Down
2 changes: 1 addition & 1 deletion tools/importJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ImportJSON : public Tool {
BSONObj o = fromjson( line );
_conn.insert( ns.c_str() , o );
}
catch ( MsgAssertionException ma ){
catch ( MsgAssertionException& ma ){
cout << "exception:" << ma.toString() << endl;
cout << line << endl;
}
Expand Down

0 comments on commit 7165d73

Please sign in to comment.