15 #ifndef IMPALA_RUNTIME_BUFFERED_BLOCK_MGR
16 #define IMPALA_RUNTIME_BUFFERED_BLOCK_MGR
18 #include <boost/shared_ptr.hpp>
23 #include <openssl/aes.h>
24 #include <openssl/sha.h>
145 Status Pin(
bool* pinned,
Block* release_block = NULL,
bool unpin =
true);
164 return reinterpret_cast<T*
>(current_location);
259 uint8_t
iv_[AES_BLOCK_SIZE];
263 uint8_t
hash_[SHA256_DIGEST_LENGTH];
297 boost::shared_ptr<BufferedBlockMgr>* block_mgr);
417 MemTracker* parent_tracker, int64_t mem_limit);
425 Status PinBlock(Block* block,
bool* pinned, Block* src,
bool unpin);
464 BufferDescriptor** buffer);
619 typedef boost::unordered_map<TUniqueId, boost::weak_ptr<BufferedBlockMgr> >
uint8_t * buffer
Start of the buffer.
Status FindBufferForBlock(Block *block, bool *in_mem)
bool initialized_
If true, Init() has been called.
const int64_t max_block_size_
Size of the largest/default block in bytes.
Descriptor for a single memory buffer in the pool.
int total_pinned_buffers_
The total number of pinned buffers across all clients.
RuntimeProfile::Counter * integrity_check_timer_
Time spent in disk spill integrity generation and checking.
BufferedBlockMgr * block_mgr_
Parent block manager object. Responsible for maintaining the state of the block.
int num_reserved_buffers_remaining(Client *client) const
int writes_issued() const
int64_t remaining_unreserved_buffers() const
int writes_issued_
Number of writes issued.
boost::condition_variable buffer_available_cv_
Signal availability of free buffers.
Status UnpinBlock(Block *block)
Status MemLimitTooLowError(Client *client)
std::list< BufferDescriptor * >::iterator all_buffers_it
Iterator into all_io_buffers_ for this buffer.
DiskIoMgr::WriteRange * write_range_
Status TransferBuffer(Block *dst, Block *src, bool unpin)
static int num_tmp_devices()
Status Pin(bool *pinned, Block *release_block=NULL, bool unpin=true)
RuntimeProfile::Counter * buffered_pin_counter_
Number of Pin() calls that did not require a disk read.
int available_allocated_buffers() const
RuntimeProfile::Counter * mem_limit_counter_
These have a fixed value for the lifetime of the manager and show memory usage.
T * Allocate(int size)
Allocates the specified number of bytes from this block.
Status DeleteOrUnpinBlock(Block *block, bool unpin)
MemTracker * get_tracker(Client *client) const
const bool disable_spill_
void ReleaseMemory(Client *client, int64_t size)
int num_pinned_buffers(Client *client) const
Status GetNewBlock(Client *client, Block *unpin_block, Block **block, int64_t len=-1)
Status RegisterClient(int num_reserved_buffers, MemTracker *tracker, RuntimeState *state, Client **client)
RuntimeProfile::Counter * created_block_counter_
Total number of blocks created.
bool ConsumeMemory(Client *client, int64_t size)
void Init()
Initialize the state of a block and set the number of bytes allocated to 0.
int64_t max_block_size() const
RuntimeProfile::Counter * disk_read_timer_
Time taken for disk reads.
uint8_t iv_[AES_BLOCK_SIZE]
boost::condition_variable write_complete_cv_
const int block_write_threshold_
RuntimeProfile::Counter * buffer_wait_timer_
Time spent waiting for a free buffer.
RuntimeProfile::Counter * encryption_timer_
Time spent in disk spill encryption and decryption.
BufferedBlockMgr(RuntimeState *state, int64_t block_size)
uint8_t key_[32]
If encryption_ is on, a AES 256-bit key. Regenerated on each write.
static int GetNumReservedBlocks()
Return the number of blocks a block manager will reserve for its I/O buffers.
int num_rows_
Number of rows in this block.
bool is_pinned_
is_pinned_ is true while the block is pinned by a client.
void ClearTmpReservation(Client *client)
Sets tmp reservation to 0 on this client.
int unfullfilled_reserved_buffers_
The total number of reserved buffers across all clients that are not pinned.
RuntimeProfile * profile()
BufferDescriptor * buffer_desc_
int BytesRemaining() const
Return the number of remaining bytes that can be allocated in this block.
int non_local_outstanding_writes_
void ClearReservations(Client *client)
Clears all reservations for this client.
int64_t valid_data_len() const
Return the number of bytes allocated in this block.
DiskIoMgr * io_mgr_
DiskIoMgr handles to read and write blocks.
boost::scoped_ptr< RuntimeProfile > profile_
Counters and timers to track behavior.
Block(BufferedBlockMgr *block_mgr)
void EncryptDone(Block *block)
Deallocates temporary buffer alloced in Encrypt().
InternalQueue< Block > unused_blocks_
std::string DebugInternal() const
static Status Create(RuntimeState *state, MemTracker *parent, RuntimeProfile *profile, int64_t mem_limit, int64_t buffer_size, boost::shared_ptr< BufferedBlockMgr > *block_mgr)
BufferDescriptor(uint8_t *buf, int64_t len)
std::string DebugString() const
Debug helper method to print the state of a block.
int64_t valid_data_len_
Length of valid (i.e. allocated) data within the block.
boost::unordered_map< TUniqueId, boost::weak_ptr< BufferedBlockMgr > > BlockMgrsMap
int64_t available_buffers(Client *client) const
Status Encrypt(Block *block, uint8_t **outbuf)
uint8_t hash_[SHA256_DIGEST_LENGTH]
InternalQueue< BufferDescriptor > free_io_buffers_
This class is thread-safe.
int num_free_buffers() const
const bool check_integrity_
Block * GetUnusedBlock(Client *client)
Status Decrypt(Block *block)
Decrypts the contents of buffer() in place.
Status WriteUnpinnedBlock(Block *block)
Issues the write for this block to the DiskIoMgr.
Status VerifyHash(Block *block)
Verifies that the contents of buffer() match those that were set by SetHash()
bool TryAcquireTmpReservation(Client *client, int num_buffers)
void Init(DiskIoMgr *io_mgr, RuntimeProfile *profile, MemTracker *parent_tracker, int64_t mem_limit)
Initializes the block mgr. Idempotent and thread-safe.
bool is_deleted_
True if the block is deleted by the client.
Status FindBuffer(boost::unique_lock< boost::mutex > &lock, BufferDescriptor **buffer)
static SpinLock static_block_mgrs_lock_
Protects query_to_block_mgrs_.
T must be a subclass of InternalQueue::Node.
boost::ptr_vector< TmpFileMgr::File > tmp_files_
Client * client_
The client that owns this block.
DiskIoMgr::RequestContext * io_request_context_
Block * block
Block that this buffer is assigned to. May be NULL.
Status PinBlock(Block *block, bool *pinned, Block *src, bool unpin)
void WriteComplete(Block *block, const Status &write_status)
RuntimeProfile::Counter * recycled_blocks_counter_
Number of deleted blocks reused.
std::string DebugString(Client *client=NULL)
Dumps block mgr state. Grabs lock. If client is not NULL, also dumps its state.
RuntimeProfile::Counter * block_size_counter_
int64_t bytes_allocated() const
void SetHash(Block *block)
Takes a cryptographic hash of the data and sets hash_ with it.
int64_t len
Length of the buffer.
boost::scoped_ptr< MemTracker > mem_tracker_
Track buffers allocated by the block manager.
const TUniqueId query_id_
Status WriteUnpinnedBlocks()
void ReturnUnusedBlock(Block *block)
RuntimeProfile::Counter * outstanding_writes_counter_
Number of writes outstanding (issued but not completed).
std::list< BufferDescriptor * > all_io_buffers_
All allocated io-sized buffers.
int64_t buffer_len() const
boost::scoped_array< uint8_t > encrypted_write_buffer_
RuntimeProfile::Counter * bytes_written_counter_
Number of bytes written to disk (includes writes still queued in the IO manager). ...
InternalQueue< Block > unpinned_blocks_
Status DeleteBlock(Block *block)
void ReturnAllocation(int size)
Return size bytes from the most recent allocation.
bool Validate() const
Used to debug the state of the block manager. Lock must already be taken.
static BlockMgrsMap query_to_block_mgrs_