Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::BufferedBlockMgr::Block Class Reference

#include <buffered-block-mgr.h>

Inheritance diagram for impala::BufferedBlockMgr::Block:
Collaboration diagram for impala::BufferedBlockMgr::Block:

Public Member Functions

Status Pin (bool *pinned, Block *release_block=NULL, bool unpin=true)
 
Status Unpin ()
 
Status Delete ()
 
void AddRow ()
 
int num_rows () const
 
template<typename T >
T * Allocate (int size)
 Allocates the specified number of bytes from this block. More...
 
int BytesRemaining () const
 Return the number of remaining bytes that can be allocated in this block. More...
 
void ReturnAllocation (int size)
 Return size bytes from the most recent allocation. More...
 
uint8_t * buffer () const
 
int64_t valid_data_len () const
 Return the number of bytes allocated in this block. More...
 
int64_t buffer_len () const
 
bool is_max_size () const
 
bool is_pinned () const
 
std::string DebugString () const
 Debug helper method to print the state of a block. More...
 
T * Next () const
 Returns the Next/Prev node or NULL if this is the end/front. More...
 
T * Prev () const
 

Private Member Functions

 Block (BufferedBlockMgr *block_mgr)
 
void Init ()
 Initialize the state of a block and set the number of bytes allocated to 0. More...
 
bool Validate () const
 

Private Attributes

BufferDescriptorbuffer_desc_
 
BufferedBlockMgrblock_mgr_
 Parent block manager object. Responsible for maintaining the state of the block. More...
 
Clientclient_
 The client that owns this block. More...
 
DiskIoMgr::WriteRangewrite_range_
 
int64_t valid_data_len_
 Length of valid (i.e. allocated) data within the block. More...
 
int num_rows_
 Number of rows in this block. More...
 
boost::scoped_array< uint8_t > encrypted_write_buffer_
 
uint8_t key_ [32]
 If encryption_ is on, a AES 256-bit key. Regenerated on each write. More...
 
uint8_t iv_ [AES_BLOCK_SIZE]
 
uint8_t hash_ [SHA256_DIGEST_LENGTH]
 
bool is_pinned_
 is_pinned_ is true while the block is pinned by a client. More...
 
bool in_write_
 
bool is_deleted_
 True if the block is deleted by the client. More...
 
boost::condition_variable write_complete_cv_
 
bool client_local_
 

Friends

class BufferedBlockMgr
 

Detailed Description

A fixed-size block of data that may be be persisted to disk. The state of the block is maintained by the block manager and is described by 3 bools: is_pinned_ = True if the block is pinned. The block has a non-null buffer_desc_, buffer_desc_ cannot be in the free buffer list and the block cannot be in unused_blocks_ or unpinned_blocks_. Newly allocated blocks are pinned. in_write_ = True if a write has been issued but not completed for this block. The block cannot be in the unpinned_blocks_ and must have a non-null buffer_desc_ that's not in the free buffer list. It may be pinned or unpinned. is_deleted_ = True if Delete() has been called on a block. After this, no API call is valid on the block. Pin() and Unpin() can be invoked on a block any number of times before Delete(). When a pinned block is unpinned for the first time, it is added to the unpinned_blocks_ list and its buffer is removed from the free list. If it is pinned or deleted at any time while it is on the unpinned list, it is simply removed from that list. When it is dequeued from that list and enqueued for writing, in_write_ is set to true. The block may be pinned, unpinned or deleted while in_write_ is true. After the write has completed, the block's buffer will be returned to the free buffer list if it is no longer pinned, and the block itself will be put on the unused blocks list if Delete() was called. A block MUST have a non-null buffer_desc_ if a) is_pinned_ is true (i.e. the client is using it), or b) in_write_ is true, (i.e. IO mgr is using it), or c) It is on the unpinned list (buffer has not been persisted.) In addition to the block manager API, Block exposes Allocate(), ReturnAllocation() and BytesRemaining() to allocate and free memory within a block, and buffer() and valid_data_len() to read/write the contents of a block. These are not thread-safe.

Definition at line 136 of file buffered-block-mgr.h.

Constructor & Destructor Documentation

impala::BufferedBlockMgr::Block::Block ( BufferedBlockMgr block_mgr)
private

Definition at line 113 of file buffered-block-mgr.cc.

Member Function Documentation

void impala::BufferedBlockMgr::Block::AddRow ( )
inline
int64_t impala::BufferedBlockMgr::Block::buffer_len ( ) const
inline

Returns the length of the underlying buffer. Only callable if the block is pinned.

Definition at line 191 of file buffered-block-mgr.h.

References buffer_desc_, is_pinned(), and impala::BufferedBlockMgr::BufferDescriptor::len.

int impala::BufferedBlockMgr::Block::BytesRemaining ( ) const
inline
Status impala::BufferedBlockMgr::Block::Delete ( )
void impala::BufferedBlockMgr::Block::Init ( )
private

Initialize the state of a block and set the number of bytes allocated to 0.

Definition at line 134 of file buffered-block-mgr.cc.

Referenced by impala::BufferedBlockMgr::GetUnusedBlock(), and impala::BufferedBlockMgr::ReturnUnusedBlock().

bool impala::BufferedBlockMgr::Block::is_max_size ( ) const
inline
template<typename T>
T* impala::InternalQueue< T >::Node::Next ( ) const
inlineinherited

Returns the Next/Prev node or NULL if this is the end/front.

Definition at line 48 of file internal-queue.h.

References impala::InternalQueue< T >::lock_, impala::InternalQueue< T >::Node::next, and impala::InternalQueue< T >::Node::parent_queue.

Referenced by impala::TEST(), and impala::BufferedBlockMgr::Validate().

int impala::BufferedBlockMgr::Block::num_rows ( ) const
inline

Definition at line 157 of file buffered-block-mgr.h.

References num_rows_.

Referenced by impala::BufferedTupleStream::NewBlockForWrite().

Status impala::BufferedBlockMgr::Block::Pin ( bool pinned,
Block release_block = NULL,
bool  unpin = true 
)

Pins a block in memory–assigns a free buffer to a block and reads it from disk if necessary. If there are no free blocks and no unpinned blocks, '*pinned' is set to false and the block is not pinned. If 'release_block' is non-NULL, if there is memory pressure, this block will be pinned using the buffer from 'release_block'. If 'unpin' is true, 'release_block' will be unpinned (regardless of whether or not the buffer was used for this block). If 'unpin' is false, 'release_block' is deleted. 'release_block' must be pinned.

Definition at line 122 of file buffered-block-mgr.cc.

Referenced by impala::Sorter::Run::GetNext().

template<typename T>
T* impala::InternalQueue< T >::Node::Prev ( ) const
inlineinherited
void impala::BufferedBlockMgr::Block::ReturnAllocation ( int  size)
inline

Return size bytes from the most recent allocation.

Definition at line 174 of file buffered-block-mgr.h.

References valid_data_len_.

Referenced by impala::Sorter::Run::AddBatch(), and impala::BufferedTupleStream::DeepCopyInternal().

Status impala::BufferedBlockMgr::Block::Unpin ( )

Unpins a block by adding it to the list of unpinned blocks maintained by the block manager. An unpinned block must be flushed before its buffer is released or assigned to a different block. Is non-blocking.

Definition at line 126 of file buffered-block-mgr.cc.

Referenced by impala::BufferedBlockMgr::DeleteOrUnpinBlock(), impala::BufferedBlockMgr::GetNewBlock(), impala::Sorter::MergeIntermediateRuns(), impala::TEST_F(), impala::Sorter::Run::UnpinAllBlocks(), and impala::BufferedTupleStream::UnpinBlock().

int64_t impala::BufferedBlockMgr::Block::valid_data_len ( ) const
inline
bool impala::BufferedBlockMgr::Block::Validate ( ) const
private

Friends And Related Function Documentation

friend class BufferedBlockMgr
friend

Definition at line 209 of file buffered-block-mgr.h.

Member Data Documentation

BufferedBlockMgr* impala::BufferedBlockMgr::Block::block_mgr_
private

Parent block manager object. Responsible for maintaining the state of the block.

Definition at line 225 of file buffered-block-mgr.h.

Referenced by is_max_size().

bool impala::BufferedBlockMgr::Block::client_local_
private

If true, this block is being written out so the underlying buffer can be transferred to another block from the same client. We don't want this buffer getting picked up by another client.

Definition at line 288 of file buffered-block-mgr.h.

Referenced by impala::BufferedBlockMgr::TransferBuffer(), impala::BufferedBlockMgr::WriteComplete(), and impala::BufferedBlockMgr::WriteUnpinnedBlocks().

boost::scoped_array<uint8_t> impala::BufferedBlockMgr::Block::encrypted_write_buffer_
private

If encryption_ is on, in the write path we allocate a new buffer to hold encrypted data while it's being written to disk. The read path, having no references to the data, can be decrypted in place.

Definition at line 247 of file buffered-block-mgr.h.

Referenced by impala::BufferedBlockMgr::Encrypt(), impala::BufferedBlockMgr::EncryptDone(), and impala::BufferedBlockMgr::SetHash().

uint8_t impala::BufferedBlockMgr::Block::hash_[SHA256_DIGEST_LENGTH]
private

If integrity_ is on, our SHA256 hash of the data being written. Filled in on writes; verified on reads. This is calculated after encryption.

Definition at line 263 of file buffered-block-mgr.h.

Referenced by impala::BufferedBlockMgr::SetHash(), and impala::BufferedBlockMgr::VerifyHash().

bool impala::BufferedBlockMgr::Block::is_pinned_
private
uint8_t impala::BufferedBlockMgr::Block::iv_[AES_BLOCK_SIZE]
private

If encryption_ is on, the IV to use. IV stands for Initialization Vector, and is used as an input to the cipher as the "block to supply before the first block of plaintext". This is required because all ciphers (except the weak ECB) are built such that each block depends on the output from the previous block. Since the first block doesn't have a previous block, we supply this IV. Think of it as starting off the chain of encryption. This IV is also regenerated on each write.

Definition at line 259 of file buffered-block-mgr.h.

Referenced by impala::BufferedBlockMgr::Decrypt(), and impala::BufferedBlockMgr::Encrypt().

uint8_t impala::BufferedBlockMgr::Block::key_[32]
private

If encryption_ is on, a AES 256-bit key. Regenerated on each write.

Definition at line 250 of file buffered-block-mgr.h.

Referenced by impala::BufferedBlockMgr::Decrypt(), and impala::BufferedBlockMgr::Encrypt().

int impala::BufferedBlockMgr::Block::num_rows_
private

Number of rows in this block.

Definition at line 242 of file buffered-block-mgr.h.

Referenced by AddRow(), and num_rows().

boost::condition_variable impala::BufferedBlockMgr::Block::write_complete_cv_
private

Condition variable for when there is a specific client waiting for this block. Only used if client_local_ is true. TODO: Currently we use block_mgr_->lock_ for this condvar. There is no reason to use that lock_ that is already overloaded, see IMPALA-1883.

Definition at line 283 of file buffered-block-mgr.h.

Referenced by impala::BufferedBlockMgr::TransferBuffer(), and impala::BufferedBlockMgr::WriteComplete().

DiskIoMgr::WriteRange* impala::BufferedBlockMgr::Block::write_range_
private

WriteRange object representing the on-disk location used to persist a block. Is created the first time a block is persisted, and retained until the block object is destroyed. The file location and offset in write_range_ are valid throughout the lifetime of this object, but the data and length in the write_range_ are only valid while the block is being written. write_range_ instance is owned by the block manager.

Definition at line 236 of file buffered-block-mgr.h.

Referenced by impala::BufferedBlockMgr::PinBlock(), and impala::BufferedBlockMgr::WriteUnpinnedBlock().


The documentation for this class was generated from the following files: