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.


Detailed Description

Definition at line 583 of file df.h.


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 >

Constructor & Destructor Documentation

df_BlockProxyWriter::df_BlockProxyWriter ( UInt32_t  a_blkType,
UInt32_t  a_blkSize 
)

Definition at line 34 of file df_blockproxyWriter.cpp.

00037     :
00038     m_blkSize(a_blkSize),
00039     m_curBlk_p(NULL),
00040     m_flushedEmpty(false),
00041     m_blkHdr_p(NULL),
00042     m_blkType(a_blkType),
00043     m_blkNum(0),
00044     m_allocLeft(0) {
00045 
00046     // empty
00047 }

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

Definition at line 588 of file df.h.

00588 { };


Member Function Documentation

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

Reimplemented in df_Writer, and fsc_nsFSrecovery.

Definition at line 53 of file df_blockproxyWriter.cpp.

References m_flushedEmpty.

Referenced by Allocate(), AllocateRawBlock(), df_Writer::GetNewBlock(), and Go().

00053                                       {
00054     m_flushedEmpty = false;
00055 }

Here is the caller graph for this function:

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

Reimplemented in df_Writer, and fsc_nsFSrecovery.

Definition at line 61 of file df_blockproxyWriter.cpp.

Referenced by Allocate(), AllocateRawBlock(), and df_Writer::FlushBlock().

00061                                      {
00062     // Empty
00063 }

Here is the caller graph for this function:

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

Reimplemented in df_Writer.

Definition at line 595 of file df.h.

Referenced by df_Writer::EndOfData().

00595                                 {
00596         FlushBlock();
00597     };

Here is the caller graph for this function:

void df_BlockProxyWriter::NewFRIBuffer ( const string &  a_id,
bool  a_createNew = false,
bool  a_createOnTmp = false 
)

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.

virtual void df_BlockProxyWriter::NewNetBuffer ( i_UploadAgent_ptr  a_uploadAgt  )  [inline, virtual]

Reimplemented in df_Writer.

Definition at line 610 of file df.h.

00610 {};

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

Reimplemented in df_Writer.

Definition at line 611 of file df.h.

00611 {};

void df_BlockProxyWriter::Go (  )  [virtual]

Reimplemented in df_Writer.

Definition at line 68 of file df_blockproxyWriter.cpp.

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

Referenced by df_Writer::Go().

00068                              {
00069     log_FUNC_m(Go);
00070 
00071     GetNewBlock();
00072 
00073     // write block header to first block (first block has to have blk header)
00074     if (m_curBlk_p == NULL) {
00075         log_MARKLINE_m;
00076         throw ivd_Error(ie_DF_EOD, "Unexpected EOD.", true);
00077     }
00078 
00079     m_blkHdr_p = WriteBlockHeader(m_curBlk_p->GetPosition(),
00080                                 m_blkType, 0, ++m_blkNum);
00081 
00082     m_curBlk_p->Move(sizeof(*m_blkHdr_p));
00083 }

Here is the call graph for this function:

Here is the caller graph for this function:

UInt32_t df_BlockProxyWriter::GetRawBlockSize (  )  const [inline]

Definition at line 617 of file df.h.

00617 { return m_blkSize; };

UInt32_t df_BlockProxyWriter::GetBlockHeaderSize (  )  const

Definition at line 88 of file df_blockproxyWriter.cpp.

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

00088                                                        {
00089     log_FUNC_m(GetBlockHeaderSize);
00090     if (m_curBlk_p == NULL) {
00091         log_FUNC_m(GetBlockHeaderSize);
00092         throw ivd_Error(ie_DF_BROKEN_PIPE,
00093             "Block not available.", string("m_curBlk_p == NULL"));
00094     }
00095     return sizeof(df_BlockHeader_t);
00096 }

UInt32_t df_BlockProxyWriter::GetFreeSize (  )  const

Definition at line 101 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.

00101                                                 {
00102     if (m_curBlk_p == NULL) {
00103         log_FUNC_m(GetFreeSize);
00104         throw ivd_Error(ie_DF_BROKEN_PIPE,
00105             "Block not available.", string("m_curBlk_p == NULL"));
00106     }
00107     else if (m_flushedEmpty){
00108         return 0;
00109     }
00110     else {
00111         return m_curBlk_p->GetFreeSize();
00112     }
00113 }

Here is the call graph for this function:

UInt32_t df_BlockProxyWriter::GetBlkNum (  )  const [inline]

Definition at line 620 of file df.h.

00620 { return m_blkNum; };

UInt8_t * df_BlockProxyWriter::AllocateRawBlock (  ) 

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

Definition at line 117 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().

00117                                                {
00118     log_FUNC_m(AllocateRawBlock);
00119 
00120     FlushBlock();
00121     GetNewBlock();
00122 
00123     if (m_curBlk_p == NULL) {
00124         log_DBG_m(dbg_LOW, "No blocks to write to. Throw ivd_Error.");
00125         throw ivd_Error(ie_DF_BROKEN_PIPE,
00126             "Block not available.", string("m_curBlk_p == NULL"));
00127     }
00128 
00129     ++m_blkNum;         // RAW blocks are also counted
00130     m_blkHdr_p = NULL;
00131 
00132     m_allocLeft = m_curBlk_p->GetFreeSize();
00133 
00134     return m_curBlk_p->GetPosition();
00135 }

Here is the call graph for this function:

Here is the caller graph for this function:

UInt8_t * df_BlockProxyWriter::Allocate ( UInt32_t  a_size  ) 

Allocate space for new record - return new space.

Definition at line 139 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, log_MARKLINE_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().

00139                                                      {
00140     log_FUNC_m(Allocate);
00141 
00142     if (m_curBlk_p == NULL) {
00143         if (m_blkNum == 0) {
00144             log_MARKLINE_m;
00145             throw ivd_InternalError(ie_DF_INVSTATE,
00146                 "BUG: No current block. Maybe Go() was not called!");
00147         }
00148         else {
00149             log_DBG_m(dbg_LOW, "No blocks to write to. Throw ivd_Error.");
00150             throw ivd_Error(ie_DF_BROKEN_PIPE,
00151                 "Block not available.", string("m_curBlk_p == NULL"));
00152         }
00153     }
00154 
00155     // Check if there is enough space in the current data block
00156     if ( m_flushedEmpty || (a_size > m_curBlk_p->GetFreeSize()) ) {
00157         log_DBG_m(dbg_DETAIL, "Not enough space. Flushing block.");
00158         FlushBlock();
00159 
00160         // Blocks if queue full.
00161         GetNewBlock();
00162 
00163         if (m_curBlk_p == NULL) {
00164             log_DBG_m(dbg_LOW, "No blocks to write to. Throw ivd_Error.");
00165             throw ivd_Error(ie_DF_BROKEN_PIPE,
00166                 "Block not available.", string("m_curBlk_p == NULL"));
00167         }
00168 
00169         m_blkHdr_p = WriteBlockHeader(m_curBlk_p->GetPosition(),
00170                                     m_blkType, 0, ++m_blkNum);
00171         m_curBlk_p->Move(sizeof(*m_blkHdr_p));
00172 
00173         if (a_size > m_curBlk_p->GetFreeSize()) {
00174             throw ivd_InternalError(
00175                 ie_DF_INV_BLK,
00176                 "Cannot allocate " + cmn_Num2Str(a_size) +
00177                 " bytes in empty block of size " +
00178                 cmn_Num2Str(m_curBlk_p->GetFreeSize()));
00179         }
00180     }
00181 
00182     m_allocLeft = a_size;
00183 
00184     return m_curBlk_p->GetPosition();
00185 }

Here is the call graph for this function:

Here is the caller 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 189 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().

00190                                                           {
00191     log_FUNC_INT_m(Move);
00192 
00193     if (a_size > m_allocLeft) {
00194         throw ivd_InternalError(
00195             ie_DF_INV_BLK,
00196             "Try to write more than left allocated: write=" +
00197             cmn_Num2Str(a_size) + " left=" + cmn_Num2Str(m_allocLeft));
00198     }
00199 
00200     // if size is 0, then use all remaining allocated space
00201     if (a_size == 0) {
00202         a_size = m_allocLeft;
00203     }
00204 
00205     // If the writer is aborting the contents, then
00206     // the raw blocks are passed over block manager as empty
00207     // and the thread on the other side can do some optimizations
00208     // (sparse files or similar).
00209     if (a_flushEmpty && m_blkHdr_p == NULL) {
00210         log_DBG_INT_m(dbg_DETAIL, "Skipping raw block on abort.");
00211         m_flushedEmpty = true;
00212     }
00213     else {
00214         m_curBlk_p->Move(a_size);
00215     }
00216     m_allocLeft -= a_size;
00217 
00218     return m_allocLeft ? m_curBlk_p->GetPosition() : NULL;
00219 }

Here is the call graph for this function:

Here is the caller graph for this function:

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 223 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().

00227                                                                            {
00228     log_FUNC_m(WriteBlockHeader);
00229 
00230     // Block header is always at the beginning of the block.
00231     df_BlockHeader_t *blkHdr_p = reinterpret_cast<df_BlockHeader_t*>(a_blkBuf);
00232 
00233     memset(blkHdr_p, 0, sizeof(*blkHdr_p));
00234 
00235     memcpy(
00236         &(blkHdr_p->blkCookie),
00237         df_blkCookie_c,
00238         sizeof(blkHdr_p->blkCookie));
00239 
00240     blkHdr_p->type   = a_blkType;     // note: no byte swap required
00241 
00242     blkHdr_p->flags  = hton(a_blkFlags);
00243 
00244     blkHdr_p->seqNum = hton(a_blkNum);
00245 
00246     return blkHdr_p;
00247 }

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 658 of file df.h.


Member Data Documentation

Definition at line 642 of file df.h.

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

Definition at line 648 of file df.h.

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

Reimplemented in df_Writer, and fsc_nsFSrecovery.

Definition at line 652 of file df.h.

Definition at line 654 of file df.h.

Referenced by Allocate(), and Go().

Definition at line 655 of file df.h.

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

Definition at line 656 of file df.h.

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


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

Generated on Mon Feb 27 19:11:38 2012 for OPENARCHIVE by  doxygen 1.5.6