本文整理汇总了C++中LogRecord::getTxID方法的典型用法代码示例。如果您正苦于以下问题:C++ LogRecord::getTxID方法的具体用法?C++ LogRecord::getTxID怎么用?C++ LogRecord::getTxID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogRecord
的用法示例。
在下文中一共展示了LogRecord::getTxID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
//.........这里部分代码省略.........
示例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)
{
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);
//.........这里部分代码省略.........