| 431 | |
| 432 | |
| 433 | Try<Action> LevelDBStorage::read(uint64_t position) |
| 434 | { |
| 435 | Stopwatch stopwatch; |
| 436 | stopwatch.start(); |
| 437 | |
| 438 | leveldb::ReadOptions options; |
| 439 | |
| 440 | string value; |
| 441 | |
| 442 | leveldb::Status status = db->Get(options, encode(position), &value); |
| 443 | |
| 444 | if (!status.ok()) { |
| 445 | return Error(status.ToString()); |
| 446 | } |
| 447 | |
| 448 | google::protobuf::io::ArrayInputStream stream(value.data(), value.size()); |
| 449 | |
| 450 | Record record; |
| 451 | |
| 452 | if (!record.ParseFromZeroCopyStream(&stream)) { |
| 453 | return Error("Failed to deserialize record"); |
| 454 | } |
| 455 | |
| 456 | if (record.type() != Record::ACTION) { |
| 457 | return Error("Bad record"); |
| 458 | } |
| 459 | |
| 460 | VLOG(1) << "Reading position from leveldb took " << stopwatch.elapsed(); |
| 461 | |
| 462 | return record.action(); |
| 463 | } |
| 464 | |
| 465 | } // namespace log { |
| 466 | } // namespace internal { |