Allocates a chunk of 'len' bytes in this file. The cache partition's lock 'partition_lock' must be held when calling this function. Returns the byte offset into the file for insertion. 'len' is expected to be multiples of PAGE_SIZE. Returns -1 if the file doesn't have enough space for insertion.
| 240 | // into the file for insertion. 'len' is expected to be multiples of PAGE_SIZE. |
| 241 | // Returns -1 if the file doesn't have enough space for insertion. |
| 242 | int64_t Allocate(int64_t len, const std::unique_lock<SpinLock>& partition_lock) { |
| 243 | DCHECK(partition_lock.owns_lock()); |
| 244 | DCHECK_EQ(len % PAGE_SIZE, 0); |
| 245 | int64_t current_offset = current_offset_.Load(); |
| 246 | DCHECK_EQ(current_offset % PAGE_SIZE, 0); |
| 247 | // Hold the lock in shared mode to check if 'file_' is not closed already. |
| 248 | kudu::shared_lock<rw_spinlock> lock(lock_.get_lock()); |
| 249 | if (!allow_append_ || (current_offset + len > FLAGS_data_cache_file_max_size_bytes && |
| 250 | current_offset > 0)) { |
| 251 | allow_append_ = false; |
| 252 | return -1; |
| 253 | } |
| 254 | DCHECK(file_); |
| 255 | int64_t insertion_offset = current_offset; |
| 256 | current_offset_.Add(len); |
| 257 | return insertion_offset; |
| 258 | } |
| 259 | |
| 260 | // Reads from byte offset 'offset' for 'bytes_to_read' bytes into 'buffer'. |
| 261 | // Returns true iff read succeeded. Returns false on error or if the file |
no test coverage detected