src/txdb-leveldb.cpp
// CDB subclasses are created and destroyed VERY OFTEN. That's why
// we shouldn't treat this as free operations.
CDB subclasses are created and destroyed VERY OFTEN. That's why
we shouldn't treat this as free operations.
CDB subclasses are created and destroyed VERY OFTEN . That ' s why we shouldn ' t treat this as free operations .
CTxDB::CTxDB(const char* pszMode)
{
    assert(pszMode);
    activeBatch = NULL;
    fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
    if (txdb) {
        pdb = txdb;
        return;
    }
    bool fCreate = strchr(pszMode, 'c');
    options = GetOptions();
    options.create_if_missing = fCreate;
    options.filter_policy = leveldb::NewBloomFilterPolicy(10);
    init_blockindex(options); 
    pdb = txdb;
    if (Exists(string("version")))
    {
        ReadVersion(nVersion);
        printf("Transaction index version is %d\n", nVersion);
        if (nVersion < DATABASE_VERSION)
        {
            printf("Required index version is %d, removing old database\n", DATABASE_VERSION);
            delete activeBatch;
            activeBatch = NULL;
            delete txdb;
            txdb = pdb = NULL;
            init_blockindex(options, true); 
            pdb = txdb;
            bool fTmp = fReadOnly;
            fReadOnly = false;
            WriteVersion(DATABASE_VERSION); 
            fReadOnly = fTmp;
        }
    }
    else if (fCreate)
    {
        bool fTmp = fReadOnly;
        fReadOnly = false;
        WriteVersion(DATABASE_VERSION);
        fReadOnly = fTmp;
    }
    printf("Opened LevelDB successfully\n");
}
CTxDB :: CTxDB ( const char * pszMode ) { assert ( pszMode ) ; activeBatch = NULL ; fReadOnly = ( ! strchr ( pszMode , ' ' ) && ! strchr ( pszMode , ' ' ) ) ; if ( txdb ) { pdb = txdb ; return ; } bool fCreate = strchr ( pszMode , ' ' ) ; options = GetOptions ( ) ; options . create_if_missing = fCreate ; options . filter_policy = leveldb :: NewBloomFilterPolicy ( 10 ) ; init_blockindex ( options ) ; pdb = txdb ; if ( Exists ( string ( " " ) ) ) { ReadVersion ( nVersion ) ; printf ( " \n " , nVersion ) ; if ( nVersion < DATABASE_VERSION ) { printf ( " \n " , DATABASE_VERSION ) ; delete activeBatch ; activeBatch = NULL ; delete txdb ; txdb = pdb = NULL ; init_blockindex ( options , true ) ; pdb = txdb ; bool fTmp = fReadOnly ; fReadOnly = false ; WriteVersion ( DATABASE_VERSION ) ; fReadOnly = fTmp ; } } else if ( fCreate ) { bool fTmp = fReadOnly ; fReadOnly = false ; WriteVersion ( DATABASE_VERSION ) ; fReadOnly = fTmp ; } printf ( " \n " ) ; }
CDB subclasses are created and destroyed VERY OFTEN.
CDB subclasses are created and destroyed VERY OFTEN .
// Init directory // Leveldb instance destruction // Remove directory and create new database // Save transaction index version