| 171 | } |
| 172 | |
| 173 | bool SSTableReader::Impl::LoadDataBlock(int block_id, hfile::DataBlock *block) { |
| 174 | CHECK(block_id >= 0 && block_id < data_index_->GetBlockSize()) |
| 175 | << "invalid block_id: " << block_id; |
| 176 | |
| 177 | // Get length for this block |
| 178 | int64_t next_offset = 0; |
| 179 | if (block_id + 1 < data_index_->GetBlockSize()) { |
| 180 | next_offset = data_index_->GetOffset(block_id + 1); |
| 181 | } else { |
| 182 | next_offset = file_trailer_->file_info_offset(); |
| 183 | } |
| 184 | int64_t cur_offset = data_index_->GetOffset(block_id); |
| 185 | int length = next_offset - cur_offset; |
| 186 | |
| 187 | std::string buffer; |
| 188 | { |
| 189 | MutexLocker l(&mutex_); |
| 190 | if (!file_base_->Seek(cur_offset, SEEK_SET)) { |
| 191 | return false; |
| 192 | } |
| 193 | buffer.resize(length); |
| 194 | int64_t size = file_base_->Read((void*) buffer.c_str(), length); |
| 195 | if (size != length) { |
| 196 | return false; |
| 197 | } |
| 198 | } |
| 199 | return block->DecodeFromString(buffer); |
| 200 | } |
| 201 | |
| 202 | } // namespace toft |
no test coverage detected