| 2982 | Result<int64_t> IoRecordedRandomAccessFile::GetSize() { return file_size_; } |
| 2983 | |
| 2984 | Result<int64_t> IoRecordedRandomAccessFile::ReadAt(int64_t position, int64_t nbytes, |
| 2985 | bool allow_short_read, void* out) { |
| 2986 | auto num_bytes_read = std::min(file_size_, position + nbytes) - position; |
| 2987 | if (!allow_short_read && num_bytes_read != nbytes) { |
| 2988 | return Status::IOError("File too short: expected to be able to read ", nbytes, |
| 2989 | " bytes, got ", num_bytes_read); |
| 2990 | } |
| 2991 | |
| 2992 | if (!read_ranges_.empty() && |
| 2993 | position == read_ranges_.back().offset + read_ranges_.back().length) { |
| 2994 | // merge continuous IOs into one if possible |
| 2995 | read_ranges_.back().length += num_bytes_read; |
| 2996 | } else { |
| 2997 | // no real IO is performed, it is only saved into a vector for replaying later |
| 2998 | read_ranges_.emplace_back(io::ReadRange{position, num_bytes_read}); |
| 2999 | } |
| 3000 | return num_bytes_read; |
| 3001 | } |
| 3002 | |
| 3003 | Result<std::shared_ptr<Buffer>> IoRecordedRandomAccessFile::ReadAt( |
| 3004 | int64_t position, int64_t nbytes, bool allow_short_read) { |