当前位置: 首页>>代码示例>>C++>>正文


C++ LogRecord::getLSN方法代码示例

本文整理汇总了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;
}
开发者ID:guangsha,项目名称:Database,代码行数:62,代码来源:LogMgr_xiabao5.cpp

示例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++;
    }
}
开发者ID:guangsha,项目名称:Database,代码行数:89,代码来源:LogMgr_xiabao5.cpp

示例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);
		}
	    }
//.........这里部分代码省略.........
开发者ID:guangsha,项目名称:Database,代码行数:101,代码来源:LogMgr_xiabao5.cpp

示例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";
}
开发者ID:ptryfon,项目名称:loxim-stats,代码行数:65,代码来源:TestLogs.cpp

示例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);
//.........这里部分代码省略.........
开发者ID:mrachael,项目名称:484P4,代码行数:101,代码来源:LogMgr.cpp


注:本文中的LogRecord::getLSN方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。