private std::error_code write(IWriteBatch batch, bool sync) { rocksdb.WriteOptions writeOptions = new rocksdb.WriteOptions(); writeOptions.sync = sync; rocksdb.WriteBatch rocksdbBatch = new rocksdb.WriteBatch(); List <Tuple <string, string> > rawData = new List <Tuple <string, string> >(batch.extractRawDataToInsert()); foreach (Tuple <string, string> kvPair in rawData) { rocksdbBatch.Put(new rocksdb.Slice(kvPair.Item1), new rocksdb.Slice(kvPair.Item2)); } List <string> rawKeys = new List <string>(batch.extractRawKeysToRemove()); foreach (string key in rawKeys) { rocksdbBatch.Delete(new rocksdb.Slice(key)); } rocksdb.Status status = db.Write(writeOptions, rocksdbBatch); if (!status.ok()) { logger(ERROR) << "Can't write to DB. " << status.ToString(); return(GlobalMembers.make_error_code(CryptoNote.error.DataBaseErrorCodes.INTERNAL_ERROR)); } else { return(std::error_code()); } }
//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)); } }