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


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

本文整理汇总了C++中LogRecord::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ LogRecord::getType方法的具体用法?C++ LogRecord::getType怎么用?C++ LogRecord::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LogRecord的用法示例。


在下文中一共展示了LogRecord::getType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: printLog

void printLog( const char *path, StoreManager* sm)
{
  int fd;
  off_t fpos;
  int err=0;
  LogRecord* lr;
  WriteRecord* wr;
  fd = ::open( path, O_RDONLY);

  ::lseek(fd, 0 ,SEEK_SET);
  LogIO::getFilePos( fd, fpos );
  printf("\npocztaek czytania : %ld\n",fpos);

  while( (err = LogRecord::readLogRecordForward(lr, fd, sm)) == 0 )
  {
    int lt;
    lr->getType(lt);
    printf("\n|%d| \n",lt);
    if(lt == WRITE_LOG_REC_TYPE)
    {
      wr = (WriteRecord*) lr;
      if(wr->oldVal == NULL)
        printf("oldVal == NULL ");
      else
      {
        printf("oldVal = %s ",((wr->oldVal)->toString()).c_str());
      }
      printf("\n");
    }
    delete lr;
  }
  close(fd);
  printf("\nerr=%d\n",err);
}
开发者ID:ptryfon,项目名称:loxim-stats,代码行数:34,代码来源:TestLogs.cpp

示例2: 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

示例3: 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

示例4: 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

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