| 184 | |
| 185 | |
| 186 | Future<bool> LevelDBStorageProcess::expunge(const Entry& entry) |
| 187 | { |
| 188 | if (error.isSome()) { |
| 189 | return Failure(error.get()); |
| 190 | } |
| 191 | |
| 192 | // We do a read first to make sure the version has not changed. This |
| 193 | // could be optimized in the future, for now it will probably hit |
| 194 | // the cache anyway. |
| 195 | Try<Option<Entry>> option = read(entry.name()); |
| 196 | |
| 197 | if (option.isError()) { |
| 198 | return Failure(option.error()); |
| 199 | } |
| 200 | |
| 201 | if (option->isNone()) { |
| 202 | return false; |
| 203 | } |
| 204 | |
| 205 | if (id::UUID::fromBytes(option.get()->uuid()).get() != |
| 206 | id::UUID::fromBytes(entry.uuid()).get()) { |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | // Note that the read (i.e., DB::Get) and DB::Delete are inherently |
| 211 | // "atomic" because only one db can be opened at a time, so there |
| 212 | // cannot be any writes that occur concurrently. |
| 213 | |
| 214 | leveldb::WriteOptions options; |
| 215 | options.sync = true; |
| 216 | |
| 217 | leveldb::Status status = db->Delete(options, entry.name()); |
| 218 | |
| 219 | if (!status.ok()) { |
| 220 | return Failure(status.ToString()); |
| 221 | } |
| 222 | |
| 223 | return true; |
| 224 | } |
| 225 | |
| 226 | |
| 227 | Try<Option<Entry>> LevelDBStorageProcess::read(const string& name) |