private string getDataDir(DataBaseConfig config) { if (config.getTestnet()) { return(config.getDataDir() + '/' + GlobalMembers.TESTNET_DB_NAME); } else { return(config.getDataDir() + '/' + GlobalMembers.DB_NAME); } }
private rocksdb.Options getDBOptions(DataBaseConfig config) { rocksdb.DBOptions dbOptions = new rocksdb.DBOptions(); dbOptions.IncreaseParallelism(config.getBackgroundThreadsCount()); dbOptions.info_log_level = rocksdb.InfoLogLevel.WARN_LEVEL; dbOptions.max_open_files = config.getMaxOpenFiles(); rocksdb.ColumnFamilyOptions fOptions = new rocksdb.ColumnFamilyOptions(); //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created: //ORIGINAL LINE: fOptions.write_buffer_size = static_cast<uint>(config.getWriteBufferSize()); fOptions.write_buffer_size.CopyFrom((uint)config.getWriteBufferSize()); // merge two memtables when flushing to L0 fOptions.min_write_buffer_number_to_merge = 2; // this means we'll use 50% extra memory in the worst case, but will reduce // write stalls. fOptions.max_write_buffer_number = 6; // start flushing L0->L1 as soon as possible. each file on level0 is // (memtable_memory_budget / 2). This will flush level 0 when it's bigger than // memtable_memory_budget. fOptions.level0_file_num_compaction_trigger = 20; fOptions.level0_slowdown_writes_trigger = 30; fOptions.level0_stop_writes_trigger = 40; // doesn't really matter much, but we don't want to create too many files //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created: //ORIGINAL LINE: fOptions.target_file_size_base = config.getWriteBufferSize() / 10; fOptions.target_file_size_base.CopyFrom(config.getWriteBufferSize() / 10); // make Level1 size equal to Level0 size, so that L0->L1 compactions are fast //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created: //ORIGINAL LINE: fOptions.max_bytes_for_level_base = config.getWriteBufferSize(); fOptions.max_bytes_for_level_base.CopyFrom(config.getWriteBufferSize()); fOptions.num_levels = 10; fOptions.target_file_size_multiplier = 2; // level style compaction fOptions.compaction_style = rocksdb.CompactionStyle.kCompactionStyleLevel; fOptions.compression_per_level.Resize(fOptions.num_levels); for (int i = 0; i < fOptions.num_levels; ++i) { fOptions.compression_per_level[i] = rocksdb.CompressionType.kNoCompression; } rocksdb.BlockBasedTableOptions tableOptions = new rocksdb.BlockBasedTableOptions(); tableOptions.block_cache = rocksdb.NewLRUCache(config.getReadCacheSize()); rocksdb.TableFactory tfp = new rocksdb.TableFactory(NewBlockBasedTableFactory(tableOptions)); fOptions.table_factory = tfp; return(new rocksdb.Options(dbOptions, fOptions)); }
//C++ TO C# CONVERTER TODO TASK: C# has no equivalent to ' = delete': // RocksDBWrapper(const RocksDBWrapper&) = delete; //C++ TO C# CONVERTER TODO TASK: C# has no equivalent to ' = delete': // RocksDBWrapper(RocksDBWrapper&&) = delete; //C++ TO C# CONVERTER TODO TASK: C# has no equivalent to ' = delete': // RocksDBWrapper& operator =(const RocksDBWrapper&) = delete; //C++ TO C# CONVERTER TODO TASK: C# has no equivalent to ' = delete': // RocksDBWrapper& operator =(RocksDBWrapper&&) = delete; public void init(DataBaseConfig config) { if (state.load() != State.NOT_INITIALIZED) { throw std::system_error(GlobalMembers.make_error_code(CryptoNote.error.DataBaseErrorCodes.ALREADY_INITIALIZED)); } string dataDir = getDataDir(config); logger(INFO) << "Opening DB in " << dataDir; rocksdb.DB dbPtr; rocksdb.Options dbOptions = getDBOptions(config); rocksdb.Status status = rocksdb.DB.Open(dbOptions, dataDir, dbPtr); if (status.ok()) { logger(INFO) << "DB opened in " << dataDir; } else if (!status.ok() && status.IsInvalidArgument()) { logger(INFO) << "DB not found in " << dataDir << ". Creating new DB..."; dbOptions.create_if_missing = true; rocksdb.Status status = rocksdb.DB.Open(dbOptions, dataDir, dbPtr); if (!status.ok()) { logger(ERROR) << "DB Error. DB can't be created in " << dataDir << ". Error: " << status.ToString(); throw std::system_error(GlobalMembers.make_error_code(CryptoNote.error.DataBaseErrorCodes.INTERNAL_ERROR)); } } else if (status.IsIOError()) { logger(ERROR) << "DB Error. DB can't be opened in " << dataDir << ". Error: " << status.ToString(); throw std::system_error(GlobalMembers.make_error_code(CryptoNote.error.DataBaseErrorCodes.IO_ERROR)); } else { logger(ERROR) << "DB Error. DB can't be opened in " << dataDir << ". Error: " << status.ToString(); throw std::system_error(GlobalMembers.make_error_code(CryptoNote.error.DataBaseErrorCodes.INTERNAL_ERROR)); } db.reset(dbPtr); state.store(State.INITIALIZED); }
public void destroy(DataBaseConfig config) { if (state.load() != State.NOT_INITIALIZED) { throw std::system_error(GlobalMembers.make_error_code(CryptoNote.error.DataBaseErrorCodes.ALREADY_INITIALIZED)); } string dataDir = getDataDir(config); logger(WARNING) << "Destroying DB in " << dataDir; rocksdb.Options dbOptions = getDBOptions(config); rocksdb.Status status = rocksdb.DestroyDB(dataDir, dbOptions); if (status.ok()) { logger(WARNING) << "DB destroyed in " << dataDir; } else { logger(ERROR) << "DB Error. DB can't be destroyed in " << dataDir << ". Error: " << status.ToString(); throw std::system_error(GlobalMembers.make_error_code(CryptoNote.error.DataBaseErrorCodes.INTERNAL_ERROR)); } }