Check if there is an available local memory buffer for the specific offset. Caller should hold the physical lock of the disk file in case the object is destroyed. But the caller should not hold the lock of the memory block because the IsStatus() would require the lock.
| 390 | // destroyed. But the caller should not hold the lock of the memory block because the |
| 391 | // IsStatus() would require the lock. |
| 392 | bool CanReadFromReadBuffer( |
| 393 | const boost::shared_lock<boost::shared_mutex>& lock, int64_t offset) { |
| 394 | if (!IsBatchReadEnabled()) return false; |
| 395 | DCHECK(lock.mutex() == &physical_file_lock_ && lock.owns_lock()); |
| 396 | MemBlock* read_buffer_block = GetBufferBlock(GetReadBufferIndex(offset)); |
| 397 | return read_buffer_block != nullptr |
| 398 | && read_buffer_block->IsStatus(MemBlockStatus::WRITTEN); |
| 399 | } |
| 400 | |
| 401 | // Return if batch reading is enabled. |
| 402 | bool IsBatchReadEnabled() { return read_buffer_ != nullptr; } |