X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Ftxdb-leveldb.cpp;h=1f881f1d38d8305f6311ac201bc34edfd593eddd;hp=a52a2300d93e8435591ef48d39672844fa3a3e29;hb=d8f8063eda45b8dec864b28bb98839a2dd3a8170;hpb=68fbc35ade50af7e8b0ec0fe80e9a1372bccba2c diff --git a/src/txdb-leveldb.cpp b/src/txdb-leveldb.cpp index a52a230..1f881f1 100644 --- a/src/txdb-leveldb.cpp +++ b/src/txdb-leveldb.cpp @@ -23,41 +23,28 @@ using namespace std; using namespace boost; -leveldb::DB *txdb; +leveldb::DB *txdb; // global pointer for LevelDB object instance static leveldb::Options GetOptions() { leveldb::Options options; int nCacheSizeMB = GetArg("-dbcache", 25); options.block_cache = leveldb::NewLRUCache(nCacheSizeMB * 1048576); - options.filter_policy = leveldb::NewBloomFilterPolicy(10); + options.filter_policy = leveldb::NewBloomFilterPolicy(10); return options; } -void MakeMockTXDB() { - leveldb::Options options = GetOptions(); - options.create_if_missing = true; - // This will leak but don't care here. - options.env = leveldb::NewMemEnv(leveldb::Env::Default()); - leveldb::Status status = leveldb::DB::Open(options, "txdb", &txdb); - if (!status.ok()) - throw runtime_error(strprintf("Could not create mock LevelDB: %s", status.ToString().c_str())); - CTxDB txdb("w"); - txdb.WriteVersion(CLIENT_VERSION); -} - -// NOTE: CDB subclasses are created and destroyed VERY OFTEN. Therefore we have -// to keep databases in global variables to avoid constantly creating and -// destroying them, which sucks. In future the code should be changed to not -// treat the instantiation of a database as a free operation. +// CDB subclasses are created and destroyed VERY OFTEN. That's why +// we shouldn't treat this it a free operations. CTxDB::CTxDB(const char* pszMode) { assert(pszMode); - pdb = txdb; activeBatch = NULL; fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); - if (txdb) + if (txdb) { + pdb = txdb; return; + } // First time init. filesystem::path directory = GetDataDir() / "txleveldb"; @@ -74,13 +61,19 @@ CTxDB::CTxDB(const char* pszMode) } pdb = txdb; - if (fCreate && !Exists(string("version"))) + if (Exists(string("version"))) + { + ReadVersion(nVersion); + printf("Transaction index version is %d\n", nVersion); + } + else if(fCreate) { bool fTmp = fReadOnly; fReadOnly = false; - WriteVersion(CLIENT_VERSION); + WriteVersion(DATABASE_VERSION); fReadOnly = fTmp; } + printf("Opened LevelDB successfully\n"); }