Status Delete(const std::string& key) { leveldb::Status s = db->Delete(leveldb::WriteOptions(), key); if (s.ok()) { return Status::OK(); } return Status::NotFound(); }
Future<bool> LevelDBStorageProcess::expunge(const Entry& entry) { if (error.isSome()) { return Failure(error.get()); } // We do a read first to make sure the version has not changed. This // could be optimized in the future, for now it will probably hit // the cache anyway. Try<Option<Entry> > option = read(entry.name()); if (option.isError()) { return Failure(option.error()); } if (option.get().isNone()) { return false; } if (UUID::fromBytes(option.get().get().uuid()) != UUID::fromBytes(entry.uuid())) { return false; } // Note that the read (i.e., DB::Get) and DB::Delete are inherently // "atomic" because only one db can be opened at a time, so there // can not be any writes that occur concurrently. leveldb::WriteOptions options; options.sync = true; leveldb::Status status = db->Delete(options, entry.name()); if (!status.ok()) { return Failure(status.ToString()); } return true; }