Update the metadata of read buffer if the file is batch read enabled. The metadata of read buffer is set when the file is written, because each page may have different sizes, so for each read buffer block, the number of pages and the start offset of a block could be different. By updating the metadata, these information would be recorded.
| 316 | // start offset of a block could be different. By updating the metadata, these |
| 317 | // information would be recorded. |
| 318 | void UpdateReadBufferMetaDataIfNeeded(int64_t offset) { |
| 319 | if (!IsBatchReadEnabled()) return; |
| 320 | int64_t par_idx = GetReadBufferIndex(offset); |
| 321 | DCheckReadBufferIdx(par_idx); |
| 322 | std::lock_guard<SpinLock> lock(read_buffer_->read_buffer_ctrl_lock_); |
| 323 | read_buffer_->page_cnts_per_block_[par_idx]++; |
| 324 | int64_t cur_offset = read_buffer_->read_buffer_block_offsets_[par_idx]; |
| 325 | if (cur_offset == DISK_FILE_INVALID_FILE_OFFSET || offset < cur_offset) { |
| 326 | read_buffer_->read_buffer_block_offsets_[par_idx] = offset; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | // Return the index of the buffer block by the file offset. |
| 331 | int GetReadBufferIndex(int64_t offset) { |