예제 #1
0
파일: xact.c 프로젝트: sunyangkobe/cscd43
/*
 *	CommitTransactionCommand
 */
void
CommitTransactionCommand(void)
{
	TransactionState s = CurrentTransactionState;

	switch (s->blockState)
	{
			/*
			 * If we aren't in a transaction block, just do our usual
			 * transaction commit.
			 */
		case TBLOCK_DEFAULT:
			CommitTransaction();
			break;

			/*
			 * This is the case right after we get a "BEGIN TRANSACTION"
			 * command, but the user hasn't done anything else yet, so we
			 * change to the "transaction block in progress" state and
			 * return.
			 */
		case TBLOCK_BEGIN:
			s->blockState = TBLOCK_INPROGRESS;
			break;

			/*
			 * This is the case when we have finished executing a command
			 * someplace within a transaction block.  We increment the
			 * command counter and return.
			 */
		case TBLOCK_INPROGRESS:
			CommandCounterIncrement();
			break;

			/*
			 * This is the case when we just got the "END TRANSACTION"
			 * statement, so we commit the transaction and go back to the
			 * default state.
			 */
		case TBLOCK_END:
			CommitTransaction();
			s->blockState = TBLOCK_DEFAULT;
			break;

			/*
			 * Here we are in the middle of a transaction block but one of
			 * the commands caused an abort so we do nothing but remain in
			 * the abort state.  Eventually we will get to the "END
			 * TRANSACTION" which will set things straight.
			 */
		case TBLOCK_ABORT:
			break;

			/*
			 * Here we were in an aborted transaction block which just
			 * processed the "END TRANSACTION" command from the user, so
			 * clean up and return to the default state.
			 */
		case TBLOCK_ENDABORT:
			CleanupTransaction();
			s->blockState = TBLOCK_DEFAULT;
			break;
	}
}
//--------------------------------------------------------------------------//
//	CRULogCleanupTaskExecutor::decideOnDeleteMethod()
//
// A heuristic decision on which delete method to use.
// First we use this formula to get the average number of rows er partition:
//        rowCount * SF
//       ---------------
//           P * 100
// Where: rowCount is the number of rows in the IUD log (as an upper bound to 
//                 the number of rows to be deleted).
//        SF       is the safety factor from the defaults table (default is 50%).
//        P        is the number of partitions.
//
// If the number of rows per partition is smaller than the lock escalation 
// limit, we use a simple delete statement.
// Otherwise we use delete with multi commit, unless it is disabled by a CQD.
//--------------------------------------------------------------------------//
CRULogCleanupTaskExecutor::SQL_STATEMENT CRULogCleanupTaskExecutor::decideOnDeleteMethod()
{
  SQL_STATEMENT deleteMethod;

  BeginTransaction();

  CDSString safetyFactorName("MV_LOG_CLEANUP_SAFETY_FACTOR");
  TInt32 safetyFactor = 0;
  CRUCache::FetchSingleDefault( safetyFactorName, safetyFactor);

  CDSString useMultiCommitName("MV_LOG_CLEANUP_USE_MULTI_COMMIT");
  TInt32 useMultiCommit = 1;
  CRUCache::FetchSingleDefault( useMultiCommitName, useMultiCommit);

  if (safetyFactor <= 100)
  {
    // When the safty factor is set to 100 or less, lock escalation is not an issue,
    // so we can use simple delete no matter how many rows are to be deleted.
    deleteMethod = CLEAN_IUD_BASIC;

#ifdef _DEBUG
	// LCOV_EXCL_START :dpb
    CDSString msg("Safety factor set to 100 or less - using simple delete.");
    CRUGlobals::GetInstance()->
		LogDebugMessage(CRUGlobals::DUMP_COMPILED_DYNAMIC_SQL, "", msg, FALSE);
	// LCOV_EXCL_STOP
#endif
  }
  else
  {
    Int64 rowCount = getRowCount();
    TInt64 rowsPerPartition = rowCount * safetyFactor / (noOfPartitions_ * 100);

    if (rowsPerPartition < CRULogCleanupSQLComposer::MAX_ROW_TO_DELETE_IN_SINGLE_TXN)
      deleteMethod = CLEAN_IUD_BASIC;
    else if (useMultiCommit == 1)
      deleteMethod = CLEAN_IUD_MCOMMIT;
    else
      deleteMethod = CLEAN_IUD_FIRSTN;

#ifdef _DEBUG
    CDSString msg;
    char buff[200];
    sprintf(buff, "IUD log has " PF64 " rows, and %d partitions. Safety factor is %d. Using ", 
            rowCount, noOfPartitions_, safetyFactor);
    msg = buff; 

    switch(deleteMethod)
    {
      case CLEAN_IUD_BASIC:
        msg += "simple delete.\n";
        break;
      case CLEAN_IUD_FIRSTN:
        msg += "delete First N.\n";
        break;
      case CLEAN_IUD_MCOMMIT:
        msg += "delete with Multi Commit.\n";
        break;
    }
    CRUGlobals::GetInstance()->
		LogDebugMessage(CRUGlobals::DUMP_COMPILED_DYNAMIC_SQL, "", msg, FALSE);
#endif
  }

  CommitTransaction();

  return deleteMethod;
}
예제 #3
0
파일: xact.c 프로젝트: sunyangkobe/cscd43
/*
 *	StartTransactionCommand
 */
void
StartTransactionCommand(void)
{
	TransactionState s = CurrentTransactionState;

	switch (s->blockState)
	{
			/*
			 * if we aren't in a transaction block, we just do our usual
			 * start transaction.
			 */
		case TBLOCK_DEFAULT:
			StartTransaction();
			break;

			/*
			 * We should never experience this -- if we do it means the
			 * BEGIN state was not changed in the previous
			 * CommitTransactionCommand().	If we get it, we print a
			 * warning and change to the in-progress state.
			 */
		case TBLOCK_BEGIN:
			elog(WARNING, "StartTransactionCommand: unexpected TBLOCK_BEGIN");
			s->blockState = TBLOCK_INPROGRESS;
			break;

			/*
			 * This is the case when are somewhere in a transaction block
			 * and about to start a new command.  For now we do nothing
			 * but someday we may do command-local resource
			 * initialization.
			 */
		case TBLOCK_INPROGRESS:
			break;

			/*
			 * As with BEGIN, we should never experience this if we do it
			 * means the END state was not changed in the previous
			 * CommitTransactionCommand().	If we get it, we print a
			 * warning, commit the transaction, start a new transaction
			 * and change to the default state.
			 */
		case TBLOCK_END:
			elog(WARNING, "StartTransactionCommand: unexpected TBLOCK_END");
			s->blockState = TBLOCK_DEFAULT;
			CommitTransaction();
			StartTransaction();
			break;

			/*
			 * Here we are in the middle of a transaction block but one of
			 * the commands caused an abort so we do nothing but remain in
			 * the abort state.  Eventually we will get to the "END
			 * TRANSACTION" which will set things straight.
			 */
		case TBLOCK_ABORT:
			break;

			/*
			 * This means we somehow aborted and the last call to
			 * CommitTransactionCommand() didn't clear the state so we
			 * remain in the ENDABORT state and maybe next time we get to
			 * CommitTransactionCommand() the state will get reset to
			 * default.
			 */
		case TBLOCK_ENDABORT:
			elog(WARNING, "StartTransactionCommand: unexpected TBLOCK_ENDABORT");
			break;
	}

	/*
	 * We must switch to TopTransactionContext before returning. This is
	 * already done if we called StartTransaction, otherwise not.
	 */
	Assert(TopTransactionContext != NULL);
	MemoryContextSwitchTo(TopTransactionContext);
}
예제 #4
0
///////////////////////////////////////////////////////////////////////////////
/// \brief
/// Terminate the repository manager.
///
void MgRepositoryManager::Terminate()
{
    CommitTransaction();
}