Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes

blk_DiskFRIWriter Class Reference
[IVD Data format.]

#include <df.h>

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

List of all members.

Public Member Functions

 blk_DiskFRIWriter (df_BlockManager &a_mgr, const string &a_medVolID, bool a_createOnTmp=false, bool a_createNew=false, bool a_createInto=false, cmn_Path a_intoPath="", const string &a_extension="")
 blk_DiskFRIWriter (df_BlockManager &a_mgr, const string &a_medVolID, ivd_MigrationID_t a_migID, UInt32_t a_copyID, UInt32_t a_mediumKey, UInt32_t a_medVolNum, i_FSC_ptr a_fsc)
virtual ~blk_DiskFRIWriter ()

Protected Member Functions

virtual void Write (const UInt8_t *a_data, const UInt32_t a_size)

Protected Attributes

cmn_File m_diskFRI

Private Member Functions

void OpenFRIFile (const string &a_medVolID, bool a_createOnTmp, bool a_createNew, bool a_createInto=false, cmn_Path a_intoPath="", const string &a_extension="")

Private Attributes

 log_CLASSID_m
ivd_MigrationID_t m_migID
UInt32_t m_copyID
UInt32_t m_mediumKey
UInt32_t m_medVolNum
i_FSC_var m_fsc

Detailed Description

Definition at line 403 of file df.h.


Constructor & Destructor Documentation

blk_DiskFRIWriter::blk_DiskFRIWriter ( df_BlockManager a_mgr,
const string &  a_medVolID,
bool  a_createOnTmp = false,
bool  a_createNew = false,
bool  a_createInto = false,
cmn_Path  a_intoPath = "",
const string &  a_extension = "" 
)

Definition at line 58 of file blk_diskfriwriter.cpp.

References log_FUNC_A_m, and OpenFRIFile().

    : blk_BufferWriter(a_mgr),
      m_migID(0),
      m_copyID(0),
      m_mediumKey(0),
      m_medVolNum(0) {

    log_FUNC_A_m(blk_DiskFRIWriter,
        "a_medVolID=" << a_medVolID <<
        " createOnTmp = " << boolalpha << a_createOnTmp <<
        " create = " << boolalpha << a_createNew <<
        " a_createInto = " << boolalpha << a_createInto <<
        " a_intoPath = " << boolalpha << a_intoPath );

    OpenFRIFile(    a_medVolID, 
                    a_createOnTmp, 
                    a_createNew, 
                    a_createInto,
                    a_intoPath,
                    a_extension);
}

Here is the call graph for this function:

blk_DiskFRIWriter::blk_DiskFRIWriter ( df_BlockManager a_mgr,
const string &  a_medVolID,
ivd_MigrationID_t  a_migID,
UInt32_t  a_copyID,
UInt32_t  a_mediumKey,
UInt32_t  a_medVolNum,
i_FSC_ptr  a_fsc 
)

Definition at line 87 of file blk_diskfriwriter.cpp.

References ie_INVALID_ARG, log_FUNC_A_m, m_fsc, and OpenFRIFile().

    : blk_BufferWriter(a_mgr),
      m_migID(a_migID),
      m_copyID(a_copyID),
      m_mediumKey(a_mediumKey),
      m_medVolNum(a_medVolNum),
      m_fsc(i_FSC::_duplicate(a_fsc))  {

    log_FUNC_A_m(blk_DiskFRIWriter,
        "a_medVolID=" << a_medVolID <<
        " a_migID = " << a_migID <<
        " a_copyID = " << a_copyID <<
        " a_mediumKey = " << a_mediumKey <<
        " a_medVolNum = " << a_medVolNum);

    if (CORBA::is_nil(m_fsc)) {
        throw ivd_InternalError(ie_INVALID_ARG, "a_fsc is nil.");
    };

    OpenFRIFile(a_medVolID, false, false);
}

Here is the call graph for this function:

blk_DiskFRIWriter::~blk_DiskFRIWriter (  )  [virtual]

Definition at line 117 of file blk_diskfriwriter.cpp.

References cmn_File::GetFullPathRef(), log_ERR_m, log_FUNC_m, m_diskFRI, and cmn_File::SyncF().

                                      {
    log_FUNC_m(~blk_DiskFRIWriter);

    try {
        m_diskFRI.SyncF();
    }
    catch (ivd_Exception &ie) {
        log_ERR_m(
            "SyncF failed for file: " << m_diskFRI.GetFullPathRef() <<
            " . Ignored. Error: " << ie);
    }
}

Here is the call graph for this function:


Member Function Documentation

void blk_DiskFRIWriter::OpenFRIFile ( const string &  a_medVolID,
bool  a_createOnTmp,
bool  a_createNew,
bool  a_createInto = false,
cmn_Path  a_intoPath = "",
const string &  a_extension = "" 
) [private]

Definition at line 216 of file blk_diskfriwriter.cpp.

References cmn_Global::dirs, fom_CREATE_ALWAYS, fom_OPEN_ALWAYS, fom_WRITE, ivd_Directories::fri, g_cmn, m_diskFRI, cmn_File::OpenF(), cmn_File::SeekEndF(), cmn_File::SetFullPath(), and ivd_Directories::tmp.

Referenced by blk_DiskFRIWriter().

                                  {

    if (a_createOnTmp) {
        m_diskFRI.SetFullPath(g_cmn.dirs.tmp + string("fri") + a_medVolID);
/*
        m_diskFRI.OpenF(
            O_BINARY | O_WRONLY | O_CREAT |
            (a_createNew? O_TRUNC : O_APPEND) );
*/
    }
    else if (a_createInto) {
        string filename(a_medVolID + "." + a_extension);
        m_diskFRI.SetFullPath(a_intoPath + filename);    
    }
    else {
        m_diskFRI.SetFullPath(g_cmn.dirs.fri + a_medVolID);
/*
    It would be better that create new would not overwrite the file
    if it exists when creating file for non-recovery purposes.
        m_diskFRI.OpenF(
            O_BINARY | O_WRONLY |
            (a_createNew? (O_CREAT | O_EXCL) : O_APPEND) );
*/
    }
    m_diskFRI.OpenF(fom_WRITE |(a_createNew ? fom_CREATE_ALWAYS :
                                              fom_OPEN_ALWAYS));

    if (!a_createNew) {
        // append to exiting FRI file
        m_diskFRI.SeekEndF();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void blk_DiskFRIWriter::Write ( const UInt8_t a_data,
const UInt32_t  a_size 
) [protected, virtual]

Implements blk_BufferWriter.

Definition at line 130 of file blk_diskfriwriter.cpp.

References dbg_DETAIL, dbg_LOW, dbg_NORM, i_MinorCol_t::flags, cmn_File::GetCurrentPosF(), ivd_BaseException::GetError(), cmn_File::GetFullPathRef(), ie_NO_DISK_SPACE, ipc_EXEC_m, ivd_Error, log_DBG_m, log_FUNC_m, log_WRN_m, m_copyID, m_diskFRI, m_fsc, m_mediumKey, m_medVolNum, m_migID, ipc_Corba::ResolveRM(), size, cmn_File::TruncF(), and cmn_File::WriteF().

                                                                          {
    log_FUNC_m(Write);

    //
    // Atomic append to the file.
    // TODO: Shall this functionality be moved to cmn_File?
    //
    ivd_FileRetSize_t wrote = m_diskFRI.WriteF(a_data, a_size);

    if (static_cast<UInt32_t>(wrote) < a_size) {
        log_WRN_m(
            "Writing failed. Truncating file to last full block: " <<
            m_diskFRI.GetFullPathRef() );

        ivd_FilePosition_t filePos = m_diskFRI.GetCurrentPosF();
        m_diskFRI.TruncF(filePos - wrote);

        throw ivd_Error(ie_NO_DISK_SPACE, "FRI disk out of space.");
    }

    if (!CORBA::is_nil(m_fsc)) {

        log_DBG_m(dbg_DETAIL, "Sending block to FSC.");

        i_CollocationIDs_t_var colIds;
        ipc_EXEC_m(
            i_FRIBlockInfo_t friInfo;

            friInfo.migID = m_migID;
            friInfo.copyID = m_copyID;
            friInfo.medVolNum = m_medVolNum;
            friInfo.mediaKey = m_mediumKey;

            i_DataBlock_t friBlock(
                a_size, a_size, const_cast<CORBA::Octet*>(a_data), 0);

            colIds = m_fsc->InsertSplitFromFRIBlock(friInfo, friBlock);
        );
        UInt32_t size = colIds->length();
        log_DBG_m(dbg_DETAIL, "Number of minor collocation IDs: " << size);

        if (size > 0) {
            // Get RM reference.
            i_ResourceManager_var rm;
            ipc_EXEC_m(
                CORBA::Object_var obj = ipc_Corba::ResolveRM();
                rm = i_ResourceManager::_narrow(obj);
                log_DBG_m(dbg_DETAIL,"Sucessfully resolved RM");
            );
            i_ColMediaVol_t entry;
            for (UInt32_t i(0); i < size; i++) {
                entry.minColId = colIds[i];
                entry.mediaKey = m_mediumKey;
                entry.medVolNr = m_medVolNum;
                log_DBG_m(dbg_DETAIL, "Adding minorColID " << entry.minColId 
                    << " to medium " << entry.mediaKey 
                    << " volume " << entry.medVolNr);

                i_MinorCol_t minorCol;
                try {
                    ipc_EXEC_m(
                        minorCol = rm->SelectMinorCol(entry.minColId);
                    );
                    log_DBG_m(dbg_DETAIL, "Flags: " << minorCol.flags); 
                    ipc_EXEC_m(
                        rm->AddColMediaVol(entry, minorCol.flags);
                    );
                    log_DBG_m(dbg_NORM, "Added.");
                }
                catch (ivd_Exception &e) {
                    if (e.GetError() == ie_RMDB_NOTFOUND){
                        log_DBG_m(dbg_LOW, "Minor collocation ID " << entry.minColId 
                                            << " is missing in RMDB for target medium key=" << m_mediumKey
                                            << " vol=" << m_medVolNum
                                            << " migID=" << m_migID
                                            << " copyID=" << m_copyID);
                    }
                    else {
                        throw;
                    }
                }
            }
        } // if (size > 0)
    } // if (!CORBA::is_nil(m_fsc))
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from blk_BufferWriter.

Definition at line 435 of file df.h.

Definition at line 446 of file df.h.

Referenced by Write().

Definition at line 430 of file df.h.

Referenced by OpenFRIFile(), Write(), and ~blk_DiskFRIWriter().

i_FSC_var blk_DiskFRIWriter::m_fsc [private]

Definition at line 449 of file df.h.

Referenced by blk_DiskFRIWriter(), and Write().

Definition at line 447 of file df.h.

Referenced by Write().

Definition at line 448 of file df.h.

Referenced by Write().

Definition at line 445 of file df.h.

Referenced by Write().


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