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

rm_DBThread Class Reference

#include <rm_dboperation.h>

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

List of all members.

Public Member Functions

 rm_DBThread (rm_String &username, rm_String &password)
 ~rm_DBThread ()
void Process (rm_DBOperation *a_operation)
 rm_DBThread::Process() Processing one single incoming request
Int32_t Suspend (void)
 rm_DBThread::Suspend() Suspend RMDB activity for backup proposes
Int32_t Resume (void)
 rm_DBThread::Resume() Resume RMDB activity

Public Attributes

rm_Operator m_rmOp
bool m_active
bool m_shutdown
Int32_t m_errNum
string m_errDesc
UInt32_t m_jobNum
 log_CLASSID_m

Private Member Functions

virtual void Run (void *arg)
 Main RMDB request loop.

Private Attributes

cmn_Mutex m_request_x
cmn_Condition m_reqInput_c
cmn_Condition m_reqOutput_c
cmn_Condition m_reqFree_c
rm_DBOperationm_operation
bool m_suspended
rm_String m_username
rm_String m_password

Friends

class i_ResourceManager_i

Detailed Description

Definition at line 36 of file rm_dboperation.h.


Constructor & Destructor Documentation

rm_DBThread::rm_DBThread ( rm_String username,
rm_String password 
)

rm_dbthtread class serializes and processes all RMDB related operations File: rm_dbthread.cpp Author: Toni Pljakoski, HERMES SoftLab Documented: Eberhard Leba GDS Created: 13/3/2002 Package: N/A

Copyright (c) 2009 GRAU DATA

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Definition at line 44 of file rm_dbthread.cpp.

                                                                 :
    
    m_reqInput_c(&m_request_x),
    m_reqOutput_c(&m_request_x),
    m_reqFree_c(&m_request_x),
    m_operation(NULL),
    m_active(false),
    m_suspended(false),
    m_shutdown(false),
    m_errNum(0),
    m_jobNum(0),
    m_rmOp(username, password),
    m_username(username),
    m_password(password)
{
        /*empty*/
}

rm_DBThread::~rm_DBThread (  ) 

Definition at line 62 of file rm_dbthread.cpp.

                         {
    /* empty */
}


Member Function Documentation

void rm_DBThread::Process ( rm_DBOperation a_operation  ) 

rm_DBThread::Process() Processing one single incoming request

A single request passed in a_operation is processed here In case a second process comes in, that one must wait.

In case a second process comes in, that one must wait.

The process passing the m_active gate is processed.

for this proposal we store the operation locally in the rm_DBThread instance.

Once the operation was stored we send a broadcast using m_reqInput_c notifying requestors that some other request may be made.

We then wait in a loop until the operation has cpmpleted.

Finally we open the m_active gate again to let the next operation pass in and check the result. In case of an error we throw ivd_Error.

Definition at line 139 of file rm_dbthread.cpp.

References cmn_Condition::Broadcast(), dbg_DETAIL, ivd_Error, log_DBG_m, log_FUNC_m, m_active, m_errDesc, m_errNum, m_jobNum, m_operation, m_reqFree_c, m_reqInput_c, m_reqOutput_c, m_request_x, NULL, and cmn_Condition::Wait().

Referenced by rm_DBOperation::Execute().

                                                        {
    log_FUNC_m(Process);

    cmn_MutexLock l(m_request_x);
    while (m_active){
        log_DBG_m(dbg_DETAIL,"Waiting for other active job ..");
        m_reqFree_c.Wait();
    }
    m_active = true;
    // EL: Why do we a doulbe lock here ?
    
    log_DBG_m(dbg_DETAIL,"Job:[" << ++m_jobNum << "] Active");
    
    m_operation = a_operation;  
    m_reqInput_c.Broadcast();
    
    while (m_operation != NULL){
        log_DBG_m(dbg_DETAIL,"Waiting for results ...");
        m_reqOutput_c.Wait();
    }
    m_active = false;
    if (m_errNum == 0 ){
        log_DBG_m(dbg_DETAIL,"Job:[" << m_jobNum << "] Finished");
        m_reqFree_c.Broadcast();        
        return;
    } 
    else {
        Int32_t errNum = m_errNum;
        m_errNum = 0;
        string errdesc(m_errDesc);
        log_DBG_m(dbg_DETAIL,"Job:[" << m_jobNum << "] Finished");
        m_reqFree_c.Broadcast();
        throw ivd_Error(errNum, m_errDesc);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Int32_t rm_DBThread::Resume ( void   ) 

rm_DBThread::Resume() Resume RMDB activity

Definition at line 96 of file rm_dbthread.cpp.

References cmn_Condition::Broadcast(), rm_DB::Connect(), dbg_DETAIL, dbg_LOW, ivd_BaseException::GetContext(), ivd_BaseException::GetError(), log_DBG_m, log_ERR_m, log_FUNC_m, m_active, rm_Operator::m_dataBase, m_errDesc, m_errNum, m_password, m_reqFree_c, m_reqInput_c, m_request_x, m_rmOp, m_shutdown, m_suspended, and m_username.

Referenced by i_ResourceManager_i::Resume().

                                 {
    log_FUNC_m(Resume);
    cmn_MutexLock l(m_request_x);

    if (! m_suspended) {
        log_DBG_m(dbg_DETAIL,"RMDB not suspended ! Ignoring call");
        return ie_RMDB_ERROR;
    }

    if ( ! m_active){
        log_DBG_m(dbg_DETAIL,"Resume of already active RMDB skipped");
        return ie_RMDB_ERROR;
    }
    try {
       m_rmOp.m_dataBase.Connect(m_username, m_password);
        m_active = false;
        m_suspended = false;
        log_DBG_m(dbg_LOW, "RMDB Resumed");
        m_reqFree_c.Broadcast(); // notify waiting threads that the gate is free
    } catch (ivd_DBException & e){
        log_DBG_m(dbg_DETAIL,"Exception on Resume" << e);
        m_errNum = e.GetError();
        m_errDesc = e.GetContext();
        log_ERR_m("Exception occured resuming the Database, correct the error"
                  " and restart the system. Details: " << m_errDesc );
        m_active = false;
        m_suspended = false;
        m_shutdown = true;
        log_DBG_m(dbg_LOW, "RMDB Resume: Shutting down RM");
        m_reqInput_c.Broadcast();
        return ie_RMDB_CONNECTPROBLEM;
    }
    return ie_NO_ERROR; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rm_DBThread::Run ( void *  arg  )  [private, virtual]

Main RMDB request loop.

All RMDB operation pass here. They are submitted by a requestor.

We wait in a loop until a valid input request arrives indicated by m_reqInput_c or until we get a shutdown is signal.

In case we have been waked up we try to process the incoming request using m_operation->Process.

ivd exception Error handling is done in case a problem happened inside processing. In such a case we store the problem in m_errNum and m_errDesc

As a general Error handling for uncatched Exceptions we frankly ignore them. This case especialy occures if we have been waked up and there is no request. In such a case m_operation is NULL, so we stay inside the inner loop and no one is bothered.

Once the request has completed, the requestor is notified in the broadcast using m_reqOutput_c .

Reimplemented from cmn_Thread.

Definition at line 189 of file rm_dbthread.cpp.

References cmn_Condition::Broadcast(), dbg_DETAIL, ivd_BaseException::GetContext(), ivd_BaseException::GetError(), log_DBG_m, log_FUNC_m, m_errDesc, m_errNum, m_operation, m_reqInput_c, m_reqOutput_c, m_request_x, m_shutdown, NULL, rm_DBOperation::Process(), and cmn_Condition::Wait().

                              {
    log_FUNC_m(Run);
    cmn_MutexLock l(m_request_x);
    while (!m_shutdown) {
        while (m_operation == NULL){
            log_DBG_m(dbg_DETAIL,"Waiting for next request ...");
            m_reqInput_c.Wait();
            if (m_shutdown) return;            
        }

        try {
            log_DBG_m(dbg_DETAIL,"Processing ...");
            m_operation->Process();
            //log_DBG_m(dbg_DETAIL,"Processed");
        } catch (ivd_Exception & e){
             log_DBG_m(dbg_DETAIL,"Exception on Processed " << e);
             m_errNum = e.GetError();
             m_errDesc = e.GetContext();
        } catch (...){
             //log_DBG_m(dbg_DETAIL,"Unknown on Processed");
             m_errNum = 0;
             m_errDesc = "unknown";
        } 
        
        m_operation = NULL;
        m_reqOutput_c.Broadcast();        
        
    }
}

Here is the call graph for this function:

Int32_t rm_DBThread::Suspend ( void   ) 

rm_DBThread::Suspend() Suspend RMDB activity for backup proposes

Method waits for a running request to complete and intercepts the other pending requests holding m_active.

Definition at line 73 of file rm_dbthread.cpp.

References dbg_DETAIL, dbg_LOW, rm_DB::Disconnect(), log_DBG_m, log_FUNC_m, m_active, rm_Operator::m_dataBase, m_reqFree_c, m_request_x, m_rmOp, m_suspended, and cmn_Condition::Wait().

Referenced by i_ResourceManager_i::Suspend().

                                  {
    log_FUNC_m(Suspend);
    cmn_MutexLock l(m_request_x);
    if (m_suspended) {
        log_DBG_m(dbg_DETAIL,"RMDB already suspended ! Ignoring call");
        return ie_RMDB_ERROR;
    }
    
    while (m_active){
        log_DBG_m(dbg_DETAIL,"Suspend is waiting for other active job ..");
        m_reqFree_c.Wait();
    }
    m_active = true;
    m_suspended = true;
    m_rmOp.m_dataBase.Disconnect();
    log_DBG_m(dbg_LOW, "RMDB Suspended");
    return ie_NO_ERROR; 
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class i_ResourceManager_i [friend]

Definition at line 39 of file rm_dboperation.h.


Member Data Documentation

Reimplemented from cmn_Thread.

Definition at line 73 of file rm_dboperation.h.

Definition at line 66 of file rm_dboperation.h.

Referenced by Process(), Resume(), and Suspend().

Definition at line 70 of file rm_dboperation.h.

Referenced by Process(), Resume(), and Run().

Definition at line 69 of file rm_dboperation.h.

Referenced by Process(), Resume(), and Run().

Definition at line 72 of file rm_dboperation.h.

Referenced by Process().

Definition at line 60 of file rm_dboperation.h.

Referenced by Process(), and Run().

Definition at line 63 of file rm_dboperation.h.

Referenced by Resume().

Definition at line 49 of file rm_dboperation.h.

Referenced by Process(), Resume(), and Suspend().

Definition at line 47 of file rm_dboperation.h.

Referenced by Process(), Resume(), Run(), and i_ResourceManager_i::~i_ResourceManager_i().

Definition at line 48 of file rm_dboperation.h.

Referenced by Process(), and Run().

Definition at line 46 of file rm_dboperation.h.

Referenced by Process(), Resume(), Run(), and Suspend().

Definition at line 56 of file rm_dboperation.h.

Referenced by dbo_ClearReorgScan::Process(), dbo_SetReorgScan::Process(), dbo_PoolInfo::Process(), dbo_ReleaseResources::Process(), dbo_ClearPartitionStatus::Process(), dbo_SetPartitionStatus::Process(), dbo_EnablePartition::Process(), dbo_DisablePartition::Process(), dbo_SelectAllPartition::Process(), dbo_UpdatePartition::Process(), dbo_RemovePartition::Process(), dbo_InsertPartition::Process(), dbo_SelectPartitionByUuid::Process(), dbo_SelectPartition::Process(), dbo_GetHost::Process(), dbo_AllocateAdmin::Process(), dbo_AllocateRec::Process(), dbo_AllocateMig::Process(), dbo_InitAllResource::Process(), dbo_InventoryUpdate::Process(), dbo_LibraryStatusClear::Process(), dbo_LibraryStatusSet::Process(), dbo_DriveStatusClear::Process(), dbo_DriveStatusSet::Process(), dbo_VolumeListStatusSet::Process(), dbo_MedVolStatusClear::Process(), dbo_MedVolStatusSet::Process(), dbo_MediumStatusClear::Process(), dbo_MediumStatusSet::Process(), dbo_MediumUnusable::Process(), dbo_MediumUnreliable::Process(), dbo_DriveError::Process(), dbo_VolumeError::Process(), dbo_VolumeUsage::Process(), dbo_VolumeEmpty::Process(), dbo_VolumeFull::Process(), dbo_MediumUnloaded::Process(), dbo_MediumLoaded::Process(), dbo_GetBestCopy::Process(), dbo_UpdateDataSize::Process(), dbo_ClearRecoveryFlag::Process(), dbo_SetRecoveryFlag::Process(), dbo_GetMediaInfo::Process(), dbo_SelectAllMediumVolByBarcode::Process(), dbo_IsSomeVolumeUsed::Process(), dbo_SelectAllMediaByPart::Process(), dbo_SelectAllMediumVolByPart::Process(), dbo_SelectAllMediumVol::Process(), dbo_RemoveMediumVol::Process(), dbo_AddMediumVol::Process(), dbo_UpdateMediumVol::Process(), dbo_SelectMediumVolByUUID::Process(), dbo_SelectMediumVolByKey::Process(), dbo_SelectMediumVol::Process(), dbo_SelectAllMedium::Process(), dbo_RemoveMedium::Process(), dbo_AddMedium::Process(), dbo_UpdateMedium::Process(), dbo_SelectMediumByDrive::Process(), dbo_SelectMediumByKey::Process(), dbo_SelectMedium::Process(), dbo_SelectAllMediaPool::Process(), dbo_RemoveMediaPool::Process(), dbo_AddMediaPool::Process(), dbo_UpdateMediaPool::Process(), dbo_SelectMediaPoolByKey::Process(), dbo_SelectMediaPoolbyUUID::Process(), dbo_SelectMediaPool::Process(), dbo_SelectAllSlots::Process(), dbo_RemoveSlot::Process(), dbo_AddSlot::Process(), dbo_UpdateSlot::Process(), dbo_SelectSlotByKey::Process(), dbo_SelectSlot::Process(), dbo_SelectAllDiskSubsys::Process(), dbo_RemoveDiskSubsys::Process(), dbo_AddDiskSubsys::Process(), dbo_UpdateDiskSubsys::Process(), dbo_SelectDiskSubsysByKey::Process(), dbo_SelectDiskSubsys::Process(), dbo_SelectAllDriveHosts::Process(), dbo_RemoveDriveHost::Process(), dbo_AddDriveHost::Process(), dbo_UpdateDriveHost::Process(), dbo_SelectDriveHostByKey::Process(), dbo_SelectDriveHost::Process(), dbo_SelectAllDrives::Process(), dbo_RemoveDrive::Process(), dbo_AddDrive::Process(), dbo_UpdateDrive::Process(), dbo_SelectDriveByKey::Process(), dbo_SelectDrive::Process(), dbo_SelectAllColVolumes::Process(), dbo_SelectAllMinorCol::Process(), dbo_SelectAllMajorCol::Process(), dbo_UpdateMinorCol::Process(), dbo_UpdateMajorCol::Process(), dbo_SelectMinColByMajCol::Process(), dbo_SelectMinorCol::Process(), dbo_SelectMajorCol::Process(), dbo_RemoveColIDs::Process(), dbo_RemoveColMediaVol::Process(), dbo_RemoveMinorCol::Process(), dbo_RemoveMajorCol::Process(), dbo_CheckAndAddColMediaVol::Process(), dbo_AddColMediaVol::Process(), dbo_AddMinorCol::Process(), dbo_AddMajorCol::Process(), dbo_RemoveLibrary::Process(), dbo_AddLibrary::Process(), dbo_UpdateLibrary::Process(), dbo_SelectAllLibraries::Process(), dbo_SelectLibraryByKey::Process(), dbo_SelectLibrary::Process(), Resume(), and Suspend().

Definition at line 67 of file rm_dboperation.h.

Referenced by Resume(), Run(), and i_ResourceManager_i::~i_ResourceManager_i().

bool rm_DBThread::m_suspended [private]

Definition at line 61 of file rm_dboperation.h.

Referenced by Resume(), and Suspend().

Definition at line 62 of file rm_dboperation.h.

Referenced by Resume().


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