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

rm_DiskBuffer Class Reference

#include <rm_diskbuffer.h>

List of all members.

Public Member Functions

 rm_DiskBuffer (string a_dbFileSystem)
virtual ~rm_DiskBuffer ()
UInt64_t GetAvailable ()
UInt64_t GetSize ()
void InsertJob (rm_JobStat a_jobStat)
void RemoveJob (UInt64_t a_jobID)
bool FindJob (UInt64_t a_jobID)
string DumpState ()
string GetFSName ()

Public Attributes

 log_CLASSID_m

Private Member Functions

void ReportContent () const
void Clear ()

Private Attributes

string m_dbFileSystem
UInt64_t m_size
vector< rm_JobStatm_jobVect

Detailed Description

Definition at line 58 of file rm_diskbuffer.h.


Constructor & Destructor Documentation

rm_DiskBuffer::rm_DiskBuffer ( string  a_dbFileSystem  ) 

Definition at line 56 of file rm_diskbuffer.cpp.

References ivd_FileSystemSize_t::bytesAvail, ivd_FileSystemSize_t::bytesTotal, cfg_MEGABYTE, Clear(), dbg_LOW, dbg_NORM, cmn_Global::dirs, ivd_Directories::diskbuf, g_cmn, cmn_File::GetFileSystemSize(), log_DBG_m, log_ERR_m, log_FUNC_m, log_WriteEvent(), m_dbFileSystem, m_size, path, and ReportContent().

: m_dbFileSystem(a_dbFileSystem),
  m_size(0)
{
    log_FUNC_m(rm_DiskBuffer);
    //set file system size
    cmn_Path path = g_cmn.dirs.diskbuf + m_dbFileSystem;
    
    ReportContent();
    Clear();

    try {

        cmn_File fileSystem(path);
        ivd_FileSystemSize_t info;
        fileSystem.GetFileSystemSize(info);

        log_DBG_m(dbg_NORM,"path: " << path <<
            ", info.bytesTotal: " << info.bytesTotal <<
            ", info.bytesAvail: " << info.bytesAvail);

        m_size = (info.bytesAvail * rm_DISKBUFFER_BUFFER) / 100;

        log_DBG_m(dbg_LOW, "path: " << path << ", m_size: " << m_size);

        ostringstream evtMsg;
        evtMsg << "Using diskbuffer: " << g_cmn.dirs.diskbuf <<
            m_dbFileSystem << ", " << m_size/cfg_MEGABYTE << " MB.";

        log_WriteEvent(evtMsg.str());
    }
    catch (ivd_Exception &e) {
        log_ERR_m("GetFileSystemInfo failed: " << e);
        throw;
    }
}

Here is the call graph for this function:

rm_DiskBuffer::~rm_DiskBuffer (  )  [virtual]

Definition at line 94 of file rm_diskbuffer.cpp.

References log_FUNC_m.

                             {
    log_FUNC_m(~rm_DiskBuffer);
    //empty
}


Member Function Documentation

void rm_DiskBuffer::Clear ( void   )  [private]

Definition at line 229 of file rm_diskbuffer.cpp.

References cmn_ListDir(), dbg_LOW, dbg_NORM, cmn_Global::dirs, ivd_Directories::diskbuf, g_cmn, cmn_Path::GetFileName(), ift_FILE, log_DBG_m, log_FUNC_m, log_WriteEvent(), m_dbFileSystem, and path.

Referenced by rm_DiskBuffer().

                          {
    log_FUNC_m(Clear);
    
    cmn_Path path = g_cmn.dirs.diskbuf + m_dbFileSystem;

    try {
        cmn_FileInfo_t_v fileList;

        cmn_ListDir(path, fileList);
 
        cmn_FileInfo_t_v::iterator iter;
        if (!fileList.empty()) {

            for (iter = fileList.begin();
                iter != fileList.end();
                ++iter) {

                     cmn_Path fullFileName(g_cmn.dirs.diskbuf +
                                         m_dbFileSystem +
                                         iter->name);
                    
                     if (iter->type == ift_FILE) {
                          try {
                               ostringstream evtMsg;
                               evtMsg << "Deleting file: " << fullFileName;

                               log_WriteEvent(evtMsg.str());
                               cmn_File f(fullFileName);
                               f.DeleteFile(fullFileName);
                          }
                          catch(...) {
                              log_DBG_m(dbg_NORM, "Can not delete." << fullFileName.GetFileName());
                              continue;
                          }
                     }
                     else  {
                         log_DBG_m(dbg_NORM, "Ignoring: " << fullFileName.GetFileName());
                     }
             }
        }
     }
     catch (ivd_SysError& ise) {
         log_DBG_m(dbg_LOW,
             ise << " ignored while deleting files from " <<
             path);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string rm_DiskBuffer::DumpState (  ) 

Definition at line 166 of file rm_diskbuffer.cpp.

References GetAvailable(), ivd_JobTypeToText(), m_dbFileSystem, m_jobVect, and m_size.

                               {


    ostringstream msg;
    msg << "Disk buffer file system name: " << m_dbFileSystem <<
        ", size:" << m_size << ", available:" << GetAvailable() << endl;

    for (UInt32_t i(0); i < m_jobVect.size(); i++){
        msg <<  "jobID: " << m_jobVect[i].m_jobID <<
                            ", size: " << m_jobVect[i].m_allocatedJobSize <<
                            ", jobType " <<
                            ivd_JobTypeToText(static_cast<ivd_JobType_e>(m_jobVect[i].m_jobType)) << endl;
    }
    msg << "------------------------------------------" << endl;
    return msg.str();
}

Here is the call graph for this function:

bool rm_DiskBuffer::FindJob ( UInt64_t  a_jobID  ) 

Definition at line 155 of file rm_diskbuffer.cpp.

References log_FUNC_m, and m_jobVect.

                                           {
    log_FUNC_m(FindJob);

    for (UInt32_t i(0); i < m_jobVect.size(); i++){
        if (m_jobVect[i].m_jobID == a_jobID) {
            return true;
        }
    }
    return false;
}

UInt64_t rm_DiskBuffer::GetAvailable (  ) 

Definition at line 100 of file rm_diskbuffer.cpp.

References dbg_DETAIL, ie_IMPOSSIBLE, log_DBG_m, log_FUNC_m, m_jobVect, and m_size.

Referenced by DumpState().

                                    {
    log_FUNC_m(GetAvailable);
    //make sum of all jobs

    UInt64_t sum(0);
    log_DBG_m(dbg_DETAIL, "m_jobVect.size():" << m_jobVect.size());
    for (UInt32_t i(0); i < m_jobVect.size(); i++){
        sum += m_jobVect[i].m_allocatedJobSize;
    }
    log_DBG_m(dbg_DETAIL, "sum:" << sum);
    if (sum > m_size){
        log_DBG_m(dbg_DETAIL, "m_size:" << m_size);
        throw ivd_InternalError(ie_IMPOSSIBLE,
            "Size of all jobs should be smaller then size of fs");
    }
    //return all-sum
    return (m_size - sum);
}

Here is the caller graph for this function:

string rm_DiskBuffer::GetFSName (  )  [inline]

Definition at line 78 of file rm_diskbuffer.h.

References m_dbFileSystem.

                      { 
        return m_dbFileSystem; 
    }

UInt64_t rm_DiskBuffer::GetSize (  ) 

Definition at line 119 of file rm_diskbuffer.cpp.

References log_FUNC_m, and m_size.

                               {
    log_FUNC_m(GetSize);

    return m_size;
}

void rm_DiskBuffer::InsertJob ( rm_JobStat  a_jobStat  ) 

Definition at line 125 of file rm_diskbuffer.cpp.

References log_FUNC_m, and m_jobVect.

                                                 {
    log_FUNC_m(InsertJob);
    m_jobVect.push_back(a_jobStat);
}

void rm_DiskBuffer::RemoveJob ( UInt64_t  a_jobID  ) 

Definition at line 130 of file rm_diskbuffer.cpp.

References ie_NOTFOUND, ivd_Error, log_FUNC_m, m_jobVect, and ReportContent().

                                             {
    log_FUNC_m(RemoveJob);
    //find job first
    bool found(false);
    UInt32_t pos(0);
    for (UInt32_t i(0); i < m_jobVect.size(); i++){
        if (m_jobVect[i].m_jobID == a_jobID) {
            found = true;
            pos = i;
            break;
        }
    }
    if (found){
        //copy last member to the place of i
        m_jobVect[pos] = m_jobVect[m_jobVect.size()-1];
        //remove last member
        m_jobVect.pop_back();
    } else {
        throw ivd_Error(ie_NOTFOUND, "Job not in list for diskbuffer.");
    }
    if (m_jobVect.empty()) {
        ReportContent();
    }
}

Here is the call graph for this function:

void rm_DiskBuffer::ReportContent (  )  const [private]

Definition at line 183 of file rm_diskbuffer.cpp.

References cmn_IsMounted(), cmn_ListDir(), dbg_DETAIL, dbg_LOW, cmn_Global::dirs, ivd_Directories::diskbuf, evt_WARNING, g_cmn, ift_DIR, log_DBG_m, log_FUNC_m, log_WriteEvent(), m_dbFileSystem, and path.

Referenced by RemoveJob(), and rm_DiskBuffer().

                                        {
    log_FUNC_m(ReportContent);

    cmn_Path path = g_cmn.dirs.diskbuf + m_dbFileSystem;

    try {
        cmn_FileInfo_t_v fileList;

        cmn_ListDir(path, fileList);

        cmn_FileInfo_t_v::iterator iter;
        if (!fileList.empty()) {

            for (iter = fileList.begin();
                iter != fileList.end();
                ++iter) {

                    cmn_Path fullFileName(g_cmn.dirs.diskbuf +
                                         m_dbFileSystem +
                                         iter->name);

                    if (iter->type == ift_DIR && cmn_IsMounted(fullFileName)) {
                        // Ignore, it is another disk buffer
                    }
                    else {
                        log_DBG_m(dbg_DETAIL, "Content of disk buffer: " <<
                                               path <<
                                               fileList);

                        ostringstream evtMsg;
                        evtMsg << "Filesystem: " << g_cmn.dirs.diskbuf <<
                                  m_dbFileSystem << " contains some data. " <<
                                  "This filesystem should be empty. ";
                        log_WriteEvent(evt_WARNING, evtMsg.str());
                        break;
                    }
             }
        }
    }
    catch (ivd_SysError& ise) {
        log_DBG_m(dbg_LOW,
            ise << " ignored while listing files from " <<
            path);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 83 of file rm_diskbuffer.h.

Definition at line 64 of file rm_diskbuffer.h.

Referenced by Clear(), DumpState(), GetFSName(), ReportContent(), and rm_DiskBuffer().

Definition at line 66 of file rm_diskbuffer.h.

Referenced by DumpState(), FindJob(), GetAvailable(), InsertJob(), and RemoveJob().

Definition at line 65 of file rm_diskbuffer.h.

Referenced by DumpState(), GetAvailable(), GetSize(), and rm_DiskBuffer().


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