Exemplo n.º 1
0
    /* db - database name
       path - db directory
    */
    /*static*/ void Database::closeDatabase( const char *db, const string& path ) {
        assertInWriteLock();
        
        Client::Context * ctx = cc().getContext();
        assert( ctx );
        assert( ctx->inDB( db , path ) );
        Database *database = ctx->db();
        assert( database->name == db );
        
        oplogCheckCloseDatabase( database ); // oplog caches some things, dirty its caches

        if( BackgroundOperation::inProgForDb(db) ) { 
            log() << "warning: bg op in prog during close db? " << db << endl;
        }

        /* important: kill all open cursors on the database */
        string prefix(db);
        prefix += '.';
        ClientCursor::invalidate(prefix.c_str());

        NamespaceDetailsTransient::clearForPrefix( prefix.c_str() );

        dbHolder.erase( db, path );
        ctx->clear();
        delete database; // closes files
    }
Exemplo n.º 2
0
        Base() : lk(ns()), _context( ns() ) {
            _database = _context.db();
            _collection = _database->getCollection( ns() );
            if ( _collection ) {
                _database->dropCollection( &_txn, ns() );
            }
            _collection = _database->createCollection( &_txn, ns() );

            addIndex( fromjson( "{\"a\":1}" ) );
        }
Exemplo n.º 3
0
 string getDbContext() {
     stringstream ss;
     Client * c = currentClient.get();
     if ( c ) {
         Client::Context * cx = c->getContext();
         if ( cx ) {
             Database *database = cx->db();
             if ( database ) {
                 ss << database->name() << ' ';
                 ss << cx->ns() << ' ';
             }
         }
     }
     return ss.str();
 }
Exemplo n.º 4
0
 Status IndexBuilder::build( Client::Context& context ) const {
     string ns = _index["ns"].String();
     Database* db = context.db();
     Collection* c = db->getCollection( ns );
     if ( !c ) {
         c = db->getOrCreateCollection( ns );
         verify(c);
     }
     Status status = c->getIndexCatalog()->createIndex( _index, 
                                                        true, 
                                                        IndexCatalog::SHUTDOWN_LEAVE_DIRTY );
     if ( status.code() == ErrorCodes::IndexAlreadyExists )
         return Status::OK();
     return status;
 }
Exemplo n.º 5
0
    Status IndexBuilder::build(TransactionExperiment* txn,
                               Client::Context& context ) const {

        string ns = _index["ns"].String();
        Database* db = context.db();
        Collection* c = db->getCollection( ns );
        if ( !c ) {
            c = db->getOrCreateCollection( ns );
            verify(c);
        }

        // Show which index we're building in the curop display.
        context.getClient()->curop()->setQuery(_index);

        Status status = c->getIndexCatalog()->createIndex( txn,
                                                           _index, 
                                                           true, 
                                                           IndexCatalog::SHUTDOWN_LEAVE_DIRTY );
        if ( status.code() == ErrorCodes::IndexAlreadyExists )
            return Status::OK();
        return status;
    }
Exemplo n.º 6
0
 Database* db() const {
     return _context.db();
 }
Exemplo n.º 7
0
 virtual ~Base() {
     DurTransaction txn;
     if ( !nsd() )
         return;
     _context.db()->dropCollection( &txn, ns() );
 }
Exemplo n.º 8
0
 virtual ~Base() {
     OperationContextImpl txn;
     if ( !nsd() )
         return;
     _context.db()->dropCollection( &txn, ns() );
 }