#ifndef _CEGORECOVERYMANAGER_H_INCLUDED_
#define _CEGORECOVERYMANAGER_H_INCLUDED_
///////////////////////////////////////////////////////////////////////////////
//                                                         
// CegoRecoveryManager.h
// ---------------------
// Cego recovery manager class definition
// 
// Design and Implementation by Bjoern Lemke
//
// (C)opyright 2000-2019 Bjoern Lemke
//
// INTERFACE MODULE
//
// Class: CegoRecoveryManager
// 
// Description: Transaction recovery handling
//
// Status: CLEAN
//
///////////////////////////////////////////////////////////////////////////////

// base includes
#include <lfcbase/Chain.h>
#include <lfcbase/ListT.h>
#include <lfcbase/SetT.h>

// xml includes
#include <lfcxml/XMLOutStream.h>

// cego includes
#include "CegoDataType.h"
#include "CegoTupleState.h"
#include "CegoField.h"
#include "CegoPredDesc.h"
#include "CegoQueryHelper.h"
#include "CegoLockHandler.h"
#include "CegoTransactionManager.h"
#include "CegoAlterDesc.h"
#include "CegoDefs.h"
#include "CegoProcedure.h"
#include "CegoView.h"
#include "CegoDistManager.h"
#include "CegoAdminHandler.h"

class CegoRecoveryManager {

public:

    enum RecoveryMode { LOCAL, REMOTE }; 
    enum RecoveryState { RECPITREACHED, RECINCOMPLETE, RECOK };

    CegoRecoveryManager(CegoDistManager *pTabMng, RecoveryMode mode);
    ~CegoRecoveryManager();

    unsigned long long recoverTableSet(const Chain& tableSet, unsigned long long pit, CegoAdminHandler* pAH);
    RecoveryState recoverCurrentTransactionLog(int tabSetId, unsigned long long pit, unsigned long long& lsn, unsigned long long& ts);
    
private:

    unsigned long long dataFileRecovery(const Chain& tableSet, int tabSetId, unsigned long long  lsn, CegoAdminHandler* pAH);
    unsigned long long transactionRecovery(const Chain& tableSet, int tabSetId, unsigned long long cplsn, unsigned long long pit, CegoAdminHandler* pAH);

    int recoverCurrentDataFileLog(int tabSetId, bool& endOfBackup);


    bool restoreLogFile(const Chain& tableSet, unsigned long lsn);
    
    Logger* _pLogger;
    CegoDistManager* _pGTM;
    CegoDatabaseManager* _pDBMng;
    
    Chain _shellCmd;

    SetT<Chain> _invalidatedList;
    
    RecoveryMode _recoveryMode;
    unsigned long _modId;
};

#endif
