本文整理汇总了C++中LogRecord::getLSN方法的典型用法代码示例。如果您正苦于以下问题:C++ LogRecord::getLSN方法的具体用法?C++ LogRecord::getLSN怎么用?C++ LogRecord::getLSN使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogRecord
的用法示例。
在下文中一共展示了LogRecord::getLSN方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: redo
/*
* Run the redo phase of ARIES.
* If the StorageEngine stops responding, return false.
* Else when redo phase is complete, return true.
*/
bool LogMgr::redo(vector <LogRecord*> log)
{
TxType tType;
int lsn, pageID, offset, nextLsn;
string afterImage;
for(auto it = log.begin(); it != log.end(); it++)
{
LogRecord *logPointer = *it;
tType = logPointer->getType();
lsn = logPointer->getLSN();
if ( tType == UPDATE )
{
UpdateLogRecord * updateLogPointer = dynamic_cast<UpdateLogRecord *>(logPointer);
pageID = updateLogPointer->getPageID();
afterImage = updateLogPointer->getAfterImage();
offset = updateLogPointer->getOffset();
}
else if ( tType == CLR )
{
CompensationLogRecord * compensationLogPointer = dynamic_cast<CompensationLogRecord *>(logPointer);
pageID = compensationLogPointer->getPageID();
afterImage = compensationLogPointer->getAfterImage();
offset = compensationLogPointer->getOffset();
}
if ( dirty_page_table.find(pageID) == dirty_page_table.end() )
{
continue;
}
if( dirty_page_table[pageID] <= lsn && se->getLSN(pageID) < lsn )
{
if( !(se->pageWrite(pageID, offset, afterImage, lsn)) )
{
return false;
}
}
}
vector <int> txToErase;
for ( auto it = tx_table.begin(); it != tx_table.end(); it++ )
{
if( it->second.status == C && it->first != NULL_TX )
{
nextLsn = se->nextLSN();
logtail.push_back(new LogRecord(nextLsn, it->second.lastLSN, it->first, END));
txToErase.push_back(it->first);
}
}
for ( int i = 0; i < txToErase.size(); i++ )
{
tx_table.erase(txToErase[i]);
}
return true;
}
示例2: analyze
/*
* Run the analysis phase of ARIES.
*/
void LogMgr::analyze(vector <LogRecord*> log)
{
auto it = log.end();
TxType tType;
int lsn, txID, pageID;
bool foundCheckpoint = false;
tx_table.clear();
dirty_page_table.clear();
if ( log.size() > 0 )
{
it--;
}
else
{
return;
}
while( it >= log.begin() )
{
LogRecord *logPointer = *it;
tType = logPointer->getType();
if ( tType == END_CKPT )
{
ChkptLogRecord *chkptLogPointer = dynamic_cast<ChkptLogRecord *>(logPointer);
tx_table = chkptLogPointer->getTxTable();
dirty_page_table = chkptLogPointer->getDirtyPageTable();
foundCheckpoint = true;
break;
}
it--;
}
if ( !foundCheckpoint )
{
it = log.begin();
}
while( it != log.end() )
{
LogRecord *logPointer = *it;
tType = logPointer->getType();
txID = logPointer->getTxID();
lsn = logPointer->getLSN();
tx_table[txID].lastLSN = lsn;
if ( txID == NULL_TX )
{
it++;
continue;
}
if ( tType == UPDATE)
{
UpdateLogRecord * updateLogPointer = dynamic_cast<UpdateLogRecord *>(logPointer);
tx_table[txID].status = U;
pageID = updateLogPointer->getPageID();
if ( dirty_page_table.find(pageID) == dirty_page_table.end() )
{
// not found
dirty_page_table[pageID] = lsn;
}
}
else if( tType == COMMIT)
{
tx_table[txID].status = C;
}
else if( tType == CLR)
{
CompensationLogRecord * compensationLogPointer = dynamic_cast<CompensationLogRecord *>(logPointer);
tx_table[txID].status = U;
pageID = compensationLogPointer->getPageID();
if ( dirty_page_table.find(pageID) == dirty_page_table.end() )
{
// not found
dirty_page_table[pageID] = lsn;
}
}
else if( tType == END)
{
tx_table.erase(txID);
}
it++;
}
}
示例3: undo
/*
* If no txnum is specified, run the undo phase of ARIES.
* If a txnum is provided, abort that transaction.
* Hint: the logic is very similar for these two tasks!
*/
void LogMgr::undo(vector <LogRecord*> log, int txnum)
{
vector <int> loserTxID;
priority_queue <int> ToUndo;
int lsn, lastLsn, nextLsn, txID, pageID, offset, prevLsn, undoNextLsn;
TxType tType;
string beforeImage;
// If a txnum is provided, abort that transaction.
if ( txnum != NULL_TX )
{
lsn = se->nextLSN();
lastLsn = getLastLSN(txnum);
setLastLSN(txnum, lsn);
logtail.push_back(new LogRecord(lsn, lastLsn, txnum, ABORT));
log.push_back(new LogRecord(lsn, lastLsn, txnum, ABORT));
tx_table[txnum].lastLSN = lsn;
tx_table[txnum].status = U;
loserTxID.push_back(txnum);
}
else
{
for (auto it = tx_table.begin(); it != tx_table.end(); it++)
{
if ( it->second.status != C )
{
loserTxID.push_back(it->first);
}
}
}
auto it = log.end();
if ( log.size() > 0 )
{
it--;
}
else
{
return;
}
for ( int i = 0; i < loserTxID.size(); i++ )
{
ToUndo.push(tx_table[loserTxID[i]].lastLSN);
}
it = log.end();
if ( log.size() > 0 )
{
it--;
}
else
{
return;
}
while ( it >= log.begin() && !(ToUndo.empty()) )
{
LogRecord *logPointer = *it;
tType = logPointer->getType();
lsn = logPointer->getLSN();
if (lsn == ToUndo.top())
{
ToUndo.pop();
if ( tType == UPDATE )
{
UpdateLogRecord * updateLogPointer = dynamic_cast<UpdateLogRecord *>(logPointer);
txID = updateLogPointer->getTxID();
pageID = updateLogPointer->getPageID();
offset = updateLogPointer->getOffset();
beforeImage = updateLogPointer->getBeforeImage();
prevLsn = updateLogPointer->getprevLSN();
lastLsn = getLastLSN(txID);
nextLsn = se->nextLSN();
logtail.push_back(new CompensationLogRecord(nextLsn, lastLsn, txID, pageID, offset, beforeImage, prevLsn));
setLastLSN(txID, nextLsn);
tx_table[txID].status = U;
if ( dirty_page_table.find(pageID) == dirty_page_table.end() )
{
dirty_page_table[pageID] = nextLsn;
}
if( !(se->pageWrite(pageID, offset, beforeImage, nextLsn)) )
{
return;
}
if ( prevLsn == NULL_LSN )
{
logtail.push_back( new LogRecord(se->nextLSN(), nextLsn, txID, END) );
tx_table.erase(txID);
}
else
{
ToUndo.push(prevLsn);
}
}
//.........这里部分代码省略.........
示例4: main
int main()
{
int res;
unsigned int LSN;
LogRecord* record;
SBQLConfig c("ARIESLog");
c.init("example.conf");
ErrorConsole *ec = new ErrorConsole("ARIESLog");
ec->init(1);
*ec << "Starting";
DBStoreManager *sm = new DBStoreManager();
*ec << "Store created";
LogManager *log = new LogManager();
*ec << "LogManager created";
sm->init(log);
*ec << "Store initiated";
log->init();
*ec << "LogManager initiated";
log->start();
*ec << "LogManager started";
*ec << "testing LogRecord...";
record = new BeginLogRecord(0, 2);
record->write(log->fd);
ec->printf("Log record written. LSN = %d, undoNxtLSN = %d\n", record->getLSN(), record->getUndoNxtLSN());
delete record;
record = new UpdateLogRecord(0, 2, new DBLogicalID(7), "ptak", new DBDataValue("kanarek"), new DBDataValue("sroka"));
record->write(log->fd);
ec->printf("Log record written. LSN = %d, undoNxtLSN = %d\n", record->getLSN(), record->getUndoNxtLSN());
delete record;
record = new CompensationLogRecord(16, 2, new DBLogicalID(7), 0);
record->write(log->fd);
ec->printf("Log record written. LSN = %d, undoNxtLSN = %d\n", record->getLSN(), record->getUndoNxtLSN());
delete record;
record = new EndLogRecord(80, 2);
record->write(log->fd);
ec->printf("Log record written. LSN = %d, undoNxtLSN = %d\n", record->getLSN(), record->getUndoNxtLSN());
delete record;
LogRecord::read(log->fd, 16, record);
ec->printf("Log record written. LSN = %d, undoNxtLSN = %d\n", record->getLSN(), record->getUndoNxtLSN());
delete record;
*ec << "testing LogManager...";
log->beginTransaction(2, LSN);
ec->printf("Transaction started. Last LSN = %d\n", LSN);
log->write(2, new DBLogicalID(7), "ptak", new DBDataValue("kanarek"), new DBDataValue("sroka"), LSN);
ec->printf("Update. Last LSN = %d\n", LSN);
log->write(2, new DBLogicalID(7), "ptak", new DBDataValue("kanarek"), NULL, LSN);
ec->printf("Update. Last LSN = %d\n", LSN);
log->rollbackTransaction(2, LSN);
log->beginTransaction(3, LSN);
ec->printf("Transaction started. Last LSN = %d\n", LSN);
log->commitTransaction(3, LSN);
ec->printf("Transaction commited. Last LSN = %d\n", LSN);
unsigned a = 101;
log->shutdown(a);
*ec << "LogManager shut down";
delete log;
*ec << "Finished";
}
示例5: undo
/*
* If no txnum is specified, run the undo phase of ARIES.
* If a txnum is provided, abort that transaction.
* Hint: the logic is very similar for these two tasks!
*/
void LogMgr::undo(vector <LogRecord*> log, int txnum)
{
set<int> ToUndo;
if (txnum == NULL_TX)
{
for (auto txn : tx_table)
{
if (txn.second.status == U && txn.second.lastLSN != -1)
ToUndo.insert(txn.second.lastLSN);
}
}
else
{
ToUndo.insert(tx_table[txnum].lastLSN);
}
while (!ToUndo.empty())
{
int L = *(ToUndo.rbegin());
LogRecord *record = nullptr;
for (auto rec : log)
{
if (rec->getLSN() == L)
{
record = rec;
break;
}
}
if (!record)
{
return;
}
// If it is an update, write a CLR and undo the action
// And add the prevLSN to the set toUndo
if (record->getType() == UPDATE)
{
UpdateLogRecord *upRecord = (UpdateLogRecord*)record;
int pageLSN = se->getLSN(upRecord->getPageID());
int next = se->nextLSN();
logtail.push_back(new CompensationLogRecord(
next,
getLastLSN(upRecord->getTxID()),
upRecord->getTxID(),
upRecord->getPageID(),
upRecord->getOffset(),
upRecord->getBeforeImage(),
record->getprevLSN()));
tx_table[upRecord->getTxID()].lastLSN = next;
// Undo the action
if (dirty_page_table.find(upRecord->getPageID()) != dirty_page_table.end()
&& pageLSN < record->getLSN()
&& dirty_page_table.find(upRecord->getPageID())->second <= record->getLSN())
{
bool unwritten = se->pageWrite(upRecord->getPageID(), upRecord->getOffset(), upRecord->getBeforeImage(), upRecord->getLSN());
// Return false if Storage Engine got stuck
if (!unwritten)
return;
}
if (record->getprevLSN() != NULL_LSN)
ToUndo.insert(record->getprevLSN());
else
{
int next2 = se->nextLSN();
logtail.push_back(new LogRecord(next2, next, record->getTxID(), END));
tx_table.erase(record->getTxID());
}
}
if (record->getType() == ABORT) {
ToUndo.insert(record->getprevLSN());
}
// If it is a CLR
if (record->getType() == CLR)
{
// If the undoNextLSN value is null, write an end record
if (((CompensationLogRecord*)record)->getUndoNextLSN() == NULL_LSN)
{
int next2 = se->nextLSN();
logtail.push_back(new LogRecord(next2, record->getLSN(), record->getTxID(), END));
tx_table.erase(record->getTxID());
}
else
ToUndo.insert(((CompensationLogRecord*)record)->getUndoNextLSN());
}
ToUndo.erase(L);
//.........这里部分代码省略.........