void open( const fc::path& dir, bool create = true, size_t cache_size = 0 ) { try { FC_ASSERT( !is_open(), "Database is already open!" ); ldb::Options opts; opts.comparator = &_comparer; opts.create_if_missing = create; opts.max_open_files = 64; opts.compression = leveldb::kNoCompression; if( cache_size > 0 ) { opts.write_buffer_size = cache_size / 4; // up to two write buffers may be held in memory simultaneously _cache.reset( leveldb::NewLRUCache( cache_size / 2 ) ); opts.block_cache = _cache.get(); } if( ldb::kMajorVersion > 1 || ( leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16 ) ) { // LevelDB versions before 1.16 consider short writes to be corruption. Only trigger error // on corruption in later versions. opts.paranoid_checks = true; } _read_options.verify_checksums = true; _iter_options.verify_checksums = true; _iter_options.fill_cache = false; _sync_options.sync = true; // Given path must exist to succeed toNativeAnsiPath fc::create_directories( dir ); std::string ldbPath = dir.to_native_ansi_path(); ldb::DB* ndb = nullptr; const auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb ); if( !ntrxstat.ok() ) { elog( "Failure opening database: ${db}\nStatus: ${msg}", ("db",dir)("msg",ntrxstat.ToString()) ); FC_THROW_EXCEPTION( level_pod_map_open_failure, "Failure opening database: ${db}\nStatus: ${msg}", ("db",dir)("msg",ntrxstat.ToString()) ); } _db.reset( ndb ); try_upgrade_db( dir, ndb, fc::get_typename<Value>::name(), sizeof( Value ) ); } FC_CAPTURE_AND_RETHROW( (dir)(create)(cache_size) ) }
void open( const fc::path& dir, bool create = true, size_t cache_size = 0 ) { try { ldb::Options opts; opts.comparator = &_comparer; opts.create_if_missing = create; if (cache_size) { _cache.reset(leveldb::NewLRUCache(cache_size)); opts.block_cache = _cache.get(); } /* if( ldb::kMajorVersion > 1 || ( leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16 ) ) { // LevelDB versions before 1.16 consider short writes to be corruption. Only trigger error // on corruption in later versions. opts.paranoid_checks = true; } opts.max_open_files = 64; _read_options.verify_checksums = true; _iter_options.verify_checksums = true; _iter_options.fill_cache = false; _sync_options.sync = true; */ /// \warning Given path must exist to succeed toNativeAnsiPath fc::create_directories(dir); std::string ldbPath = dir.to_native_ansi_path(); ldb::DB* ndb = nullptr; auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb ); if( !ntrxstat.ok() ) { FC_THROW_EXCEPTION( db_in_use_exception, "Unable to open database ${db}\n\t${msg}", ("db",dir) ("msg",ntrxstat.ToString()) ); } _db.reset(ndb); try_upgrade_db( dir,ndb, fc::get_typename<Value>::name(),sizeof(Value) ); } FC_RETHROW_EXCEPTIONS( warn, "" ) }
void open( const fc::path& dir, bool create = true ) { ldb::Options opts; opts.create_if_missing = create; opts.comparator = & _comparer; /// \waring Given path must exist to succeed toNativeAnsiPath fc::create_directories(dir); std::string ldbPath = dir.to_native_ansi_path(); ldb::DB* ndb = nullptr; auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb ); if( !ntrxstat.ok() ) { FC_THROW_EXCEPTION( db_in_use_exception, "Unable to open database ${db}\n\t${msg}", ("db",dir) ("msg",ntrxstat.ToString()) ); } _db.reset(ndb); try_upgrade_db( dir,ndb, fc::get_typename<Value>::name(),sizeof(Value) ); }