Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Friends

df_BlockProxyWriter Class Reference
[IVD Data format.]

#include <df.h>

Inheritance diagram for df_BlockProxyWriter:
Inheritance graph
[legend]
Collaboration diagram for df_BlockProxyWriter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 df_BlockProxyWriter (UInt32_t a_blkType, UInt32_t a_blkSize)
virtual void EndOfData ()
void NewFRIBuffer (const string &a_id, bool a_createNew=false, bool a_createOnTmp=false)
virtual void NewDiskBuffer (const string &a_id, const string &a_diskBufferFS, const ivd_FileSize_t a_dbFileSize, bool a_append=false)=0
virtual void NewNetBuffer (i_UploadAgent_ptr a_uploadAgt)
virtual void NewStdIOBuffer (const string &a_fName)
virtual void Go ()
UInt32_t GetRawBlockSize () const
UInt32_t GetBlockHeaderSize () const
UInt32_t GetFreeSize () const
UInt32_t GetBlkNum () const
UInt8_tAllocateRawBlock ()
 Allocate space for raw block - return pointer to raw block.
UInt8_tAllocate (UInt32_t a_size)
 Allocate space for new record - return new space.
UInt8_tMove (UInt32_t a_size=0, bool a_flushEmpty=false)
 Mark space as actually used (after being allocate before) If size is 0, then remaing space allocated is used.

Static Public Member Functions

static df_BlockHeader_tWriteBlockHeader (UInt8_t *a_blkBuf, UInt32_t a_blkType, UInt32_t a_blkFlags, UInt32_t a_blkNum)

Protected Member Functions

virtual ~df_BlockProxyWriter (void)
virtual void GetNewBlock ()
virtual void FlushBlock ()

Protected Attributes

UInt32_t m_blkSize
df_DataBlockm_curBlk_p
 the block has to be instantiated by inherited class when GetNewBlock() method is called
bool m_flushedEmpty
df_BlockHeader_tm_blkHdr_p

Private Attributes

 log_CLASSID_m
UInt32_t m_blkType
UInt32_t m_blkNum
UInt32_t m_allocLeft

Friends

class auto_ptr< df_BlockProxyWriter >

Detailed Description

Definition at line 597 of file df.h.


Constructor & Destructor Documentation

df_BlockProxyWriter::df_BlockProxyWriter ( UInt32_t  a_blkType,
UInt32_t  a_blkSize 
)

Definition at line 48 of file df_blockproxyWriter.cpp.

    :
    m_blkSize(a_blkSize),
    m_curBlk_p(NULL),
    m_flushedEmpty(false),
    m_blkHdr_p(NULL),
    m_blkType(a_blkType),
    m_blkNum(0),
    m_allocLeft(0) {

    // empty
}

virtual df_BlockProxyWriter::~df_BlockProxyWriter ( void   )  [inline, protected, virtual]

Definition at line 602 of file df.h.

{ };


Member Function Documentation

UInt8_t * df_BlockProxyWriter::Allocate ( UInt32_t  a_size  ) 

Allocate space for new record - return new space.

Definition at line 153 of file df_blockproxyWriter.cpp.

References cmn_Num2Str(), dbg_DETAIL, dbg_LOW, FlushBlock(), df_DataBlock::GetFreeSize(), GetNewBlock(), df_DataBlock::GetPosition(), ie_DF_BROKEN_PIPE, ie_DF_INV_BLK, ie_DF_INVSTATE, ivd_Error, log_DBG_m, log_FUNC_m, m_allocLeft, m_blkHdr_p, m_blkNum, m_blkType, m_curBlk_p, m_flushedEmpty, df_DataBlock::Move(), NULL, and WriteBlockHeader().

Referenced by df_FRI::BlockWritten(), df_FRIDistiller::CopyRecord(), df_FRI::FlushCurrentSplit(), df_FRI::MediumVolumeEnd(), df_FRI::MediumVolumeStart(), df_FRIDistiller::WriteFRIEnd(), df_FRIDistiller::WriteFRIStart(), and df_FRIDistiller::WriteSplitInfo().

                                                     {
    log_FUNC_m(Allocate);

    if (m_curBlk_p == NULL) {
        if (m_blkNum == 0) {
            log_MARKLINE_m;
            throw ivd_InternalError(ie_DF_INVSTATE,
                "BUG: No current block. Maybe Go() was not called!");
        }
        else {
            log_DBG_m(dbg_LOW, "No blocks to write to. Throw ivd_Error.");
            throw ivd_Error(ie_DF_BROKEN_PIPE,
                "Block not available.", string("m_curBlk_p == NULL"));
        }
    }

    // Check if there is enough space in the current data block
    if ( m_flushedEmpty || (a_size > m_curBlk_p->GetFreeSize()) ) {
        log_DBG_m(dbg_DETAIL, "Not enough space. Flushing block.");
        FlushBlock();

        // Blocks if queue full.
        GetNewBlock();

        if (m_curBlk_p == NULL) {
            log_DBG_m(dbg_LOW, "No blocks to write to. Throw ivd_Error.");
            throw ivd_Error(ie_DF_BROKEN_PIPE,
                "Block not available.", string("m_curBlk_p == NULL"));
        }

        m_blkHdr_p = WriteBlockHeader(m_curBlk_p->GetPosition(),
                                    m_blkType, 0, ++m_blkNum);
        m_curBlk_p->Move(sizeof(*m_blkHdr_p));

        if (a_size > m_curBlk_p->GetFreeSize()) {
            throw ivd_InternalError(
                ie_DF_INV_BLK,
                "Cannot allocate " + cmn_Num2Str(a_size) +
                " bytes in empty block of size " +
                cmn_Num2Str(m_curBlk_p->GetFreeSize()));
        }
    }

    m_allocLeft = a_size;

    return m_curBlk_p->GetPosition();
}

Here is the call graph for this function:

Here is the caller graph for this function:

UInt8_t * df_BlockProxyWriter::AllocateRawBlock (  ) 

Allocate space for raw block - return pointer to raw block.

Definition at line 131 of file df_blockproxyWriter.cpp.

References dbg_LOW, FlushBlock(), df_DataBlock::GetFreeSize(), GetNewBlock(), df_DataBlock::GetPosition(), ie_DF_BROKEN_PIPE, ivd_Error, log_DBG_m, log_FUNC_m, m_allocLeft, m_blkHdr_p, m_blkNum, m_curBlk_p, and NULL.

Referenced by df_FRIDistiller::ProcRecRawData().

                                               {
    log_FUNC_m(AllocateRawBlock);

    FlushBlock();
    GetNewBlock();

    if (m_curBlk_p == NULL) {
        log_DBG_m(dbg_LOW, "No blocks to write to. Throw ivd_Error.");
        throw ivd_Error(ie_DF_BROKEN_PIPE,
            "Block not available.", string("m_curBlk_p == NULL"));
    }

    ++m_blkNum;         // RAW blocks are also counted
    m_blkHdr_p = NULL;

    m_allocLeft = m_curBlk_p->GetFreeSize();

    return m_curBlk_p->GetPosition();
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void df_BlockProxyWriter::EndOfData (  )  [inline, virtual]

Reimplemented in df_Writer.

Definition at line 609 of file df.h.

                                {
        FlushBlock();
    };

void df_BlockProxyWriter::FlushBlock (  )  [protected, virtual]

Reimplemented in df_Writer, and fsc_nsFSrecovery.

Definition at line 75 of file df_blockproxyWriter.cpp.

Referenced by Allocate(), and AllocateRawBlock().

                                     {
    // Empty
}

Here is the caller graph for this function:

UInt32_t df_BlockProxyWriter::GetBlkNum (  )  const [inline]

Definition at line 634 of file df.h.

{ return m_blkNum; };

UInt32_t df_BlockProxyWriter::GetBlockHeaderSize (  )  const

Definition at line 102 of file df_blockproxyWriter.cpp.

References ie_DF_BROKEN_PIPE, ivd_Error, log_FUNC_m, m_curBlk_p, and NULL.

                                                       {
    log_FUNC_m(GetBlockHeaderSize);
    if (m_curBlk_p == NULL) {
        log_FUNC_m(GetBlockHeaderSize);
        throw ivd_Error(ie_DF_BROKEN_PIPE,
            "Block not available.", string("m_curBlk_p == NULL"));
    }
    return sizeof(df_BlockHeader_t);
}

UInt32_t df_BlockProxyWriter::GetFreeSize (  )  const

Definition at line 115 of file df_blockproxyWriter.cpp.

References df_DataBlock::GetFreeSize(), ie_DF_BROKEN_PIPE, ivd_Error, log_FUNC_m, m_curBlk_p, m_flushedEmpty, and NULL.

                                                {
    if (m_curBlk_p == NULL) {
        log_FUNC_m(GetFreeSize);
        throw ivd_Error(ie_DF_BROKEN_PIPE,
            "Block not available.", string("m_curBlk_p == NULL"));
    }
    else if (m_flushedEmpty){
        return 0;
    }
    else {
        return m_curBlk_p->GetFreeSize();
    }
}

Here is the call graph for this function:

void df_BlockProxyWriter::GetNewBlock (  )  [protected, virtual]

Reimplemented in df_Writer, and fsc_nsFSrecovery.

Definition at line 67 of file df_blockproxyWriter.cpp.

References m_flushedEmpty.

Referenced by Allocate(), AllocateRawBlock(), and Go().

                                      {
    m_flushedEmpty = false;
}

Here is the caller graph for this function:

UInt32_t df_BlockProxyWriter::GetRawBlockSize (  )  const [inline]

Definition at line 631 of file df.h.

{ return m_blkSize; };

void df_BlockProxyWriter::Go (  )  [virtual]

Reimplemented in df_Writer.

Definition at line 82 of file df_blockproxyWriter.cpp.

References GetNewBlock(), df_DataBlock::GetPosition(), ie_DF_EOD, ivd_Error, log_FUNC_m, m_blkHdr_p, m_blkNum, m_blkType, m_curBlk_p, df_DataBlock::Move(), NULL, and WriteBlockHeader().

                             {
    log_FUNC_m(Go);

    GetNewBlock();

    // write block header to first block (first block has to have blk header)
    if (m_curBlk_p == NULL) {
        log_MARKLINE_m;
        throw ivd_Error(ie_DF_EOD, "Unexpected EOD.", true);
    }

    m_blkHdr_p = WriteBlockHeader(m_curBlk_p->GetPosition(),
                                m_blkType, 0, ++m_blkNum);

    m_curBlk_p->Move(sizeof(*m_blkHdr_p));
}

Here is the call graph for this function:

UInt8_t * df_BlockProxyWriter::Move ( UInt32_t  a_size = 0,
bool  a_flushEmpty = false 
)

Mark space as actually used (after being allocate before) If size is 0, then remaing space allocated is used.

Parameters:
a_flushEmpty Try to mark the block as empty for optimization purposes

Definition at line 203 of file df_blockproxyWriter.cpp.

References cmn_Num2Str(), dbg_DETAIL, df_DataBlock::GetPosition(), ie_DF_INV_BLK, log_DBG_INT_m, log_FUNC_INT_m, m_allocLeft, m_blkHdr_p, m_curBlk_p, m_flushedEmpty, df_DataBlock::Move(), and NULL.

Referenced by df_FRI::BlockWritten(), df_FRIDistiller::CopyRecord(), df_FRI::FlushCurrentSplit(), df_FRI::MediumVolumeEnd(), df_FRI::MediumVolumeStart(), df_FRIDistiller::ProcRecRawData(), df_FRIDistiller::WriteFRIEnd(), df_FRIDistiller::WriteFRIStart(), and df_FRIDistiller::WriteSplitInfo().

                                                          {
    log_FUNC_INT_m(Move);

    if (a_size > m_allocLeft) {
        throw ivd_InternalError(
            ie_DF_INV_BLK,
            "Try to write more than left allocated: write=" +
            cmn_Num2Str(a_size) + " left=" + cmn_Num2Str(m_allocLeft));
    }

    // if size is 0, then use all remaining allocated space
    if (a_size == 0) {
        a_size = m_allocLeft;
    }

    // If the writer is aborting the contents, then
    // the raw blocks are passed over block manager as empty
    // and the thread on the other side can do some optimizations
    // (sparse files or similar).
    if (a_flushEmpty && m_blkHdr_p == NULL) {
        log_DBG_INT_m(dbg_DETAIL, "Skipping raw block on abort.");
        m_flushedEmpty = true;
    }
    else {
        m_curBlk_p->Move(a_size);
    }
    m_allocLeft -= a_size;

    return m_allocLeft ? m_curBlk_p->GetPosition() : NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void df_BlockProxyWriter::NewDiskBuffer ( const string &  a_id,
const string &  a_diskBufferFS,
const ivd_FileSize_t  a_dbFileSize,
bool  a_append = false 
) [pure virtual]

Implemented in df_Writer, and fsc_nsFSrecovery.

void df_BlockProxyWriter::NewFRIBuffer ( const string &  a_id,
bool  a_createNew = false,
bool  a_createOnTmp = false 
)
virtual void df_BlockProxyWriter::NewNetBuffer ( i_UploadAgent_ptr  a_uploadAgt  )  [inline, virtual]

Reimplemented in df_Writer.

Definition at line 624 of file df.h.

{};

virtual void df_BlockProxyWriter::NewStdIOBuffer ( const string &  a_fName  )  [inline, virtual]

Reimplemented in df_Writer.

Definition at line 625 of file df.h.

{};

df_BlockHeader_t * df_BlockProxyWriter::WriteBlockHeader ( UInt8_t a_blkBuf,
UInt32_t  a_blkType,
UInt32_t  a_blkFlags,
UInt32_t  a_blkNum 
) [static]

Definition at line 237 of file df_blockproxyWriter.cpp.

References df_BlockHeader_t::blkCookie, df_blkCookie_c, df_BlockHeader_t::flags, hton(), log_FUNC_m, df_BlockHeader_t::seqNum, and df_BlockHeader_t::type.

Referenced by Allocate(), df_FRI::df_FRI(), and Go().

                                                                           {
    log_FUNC_m(WriteBlockHeader);

    // Block header is always at the beginning of the block.
    df_BlockHeader_t *blkHdr_p = reinterpret_cast<df_BlockHeader_t*>(a_blkBuf);

    memset(blkHdr_p, 0, sizeof(*blkHdr_p));

    memcpy(
        &(blkHdr_p->blkCookie),
        df_blkCookie_c,
        sizeof(blkHdr_p->blkCookie));

    blkHdr_p->type   = a_blkType;     // note: no byte swap required

    blkHdr_p->flags  = hton(a_blkFlags);

    blkHdr_p->seqNum = hton(a_blkNum);

    return blkHdr_p;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class auto_ptr< df_BlockProxyWriter > [friend]

Definition at line 672 of file df.h.


Member Data Documentation

Reimplemented in df_Writer, and fsc_nsFSrecovery.

Definition at line 666 of file df.h.

Definition at line 670 of file df.h.

Referenced by Allocate(), AllocateRawBlock(), and Move().

Definition at line 669 of file df.h.

Referenced by Allocate(), AllocateRawBlock(), and Go().

Definition at line 656 of file df.h.

Referenced by fsc_nsFSrecovery::FlushBlock(), and fsc_nsFSrecovery::GetNewBlock().

Definition at line 668 of file df.h.

Referenced by Allocate(), and Go().

Definition at line 662 of file df.h.

Referenced by Allocate(), GetFreeSize(), fsc_nsFSrecovery::GetNewBlock(), GetNewBlock(), and Move().


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