You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-01 06:46:55 +03:00
clang format apply
This commit is contained in:
@ -16,8 +16,8 @@
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/*
|
||||
* $Id: we_columnautoinc.cpp 4450 2013-01-21 14:13:24Z rdempsey $
|
||||
*/
|
||||
* $Id: we_columnautoinc.cpp 4450 2013-01-21 14:13:24Z rdempsey $
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* Implementation of the ColumnAutoInc, ColumnAutoIncJob, and
|
||||
@ -39,14 +39,10 @@
|
||||
|
||||
namespace WriteEngine
|
||||
{
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ColumnAutoInc constructor.
|
||||
//------------------------------------------------------------------------------
|
||||
ColumnAutoInc::ColumnAutoInc( Log* logger ) :
|
||||
fLog(logger),
|
||||
fAutoIncLastValue(0),
|
||||
fColumnOID(0)
|
||||
ColumnAutoInc::ColumnAutoInc(Log* logger) : fLog(logger), fAutoIncLastValue(0), fColumnOID(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -54,7 +50,7 @@ ColumnAutoInc::ColumnAutoInc( Log* logger ) :
|
||||
// ColumnAutoInc destructor.
|
||||
//------------------------------------------------------------------------------
|
||||
/* virtual */
|
||||
ColumnAutoInc::~ColumnAutoInc( )
|
||||
ColumnAutoInc::~ColumnAutoInc()
|
||||
{
|
||||
}
|
||||
|
||||
@ -63,57 +59,53 @@ ColumnAutoInc::~ColumnAutoInc( )
|
||||
// fullTableName - Schema and table name separated by a period.
|
||||
// colInfo - ColumnInfo associated with auto-increment column.
|
||||
//------------------------------------------------------------------------------
|
||||
int ColumnAutoInc::init( const std::string& fullTableName,
|
||||
ColumnInfo* colInfo )
|
||||
int ColumnAutoInc::init(const std::string& fullTableName, ColumnInfo* colInfo)
|
||||
{
|
||||
fMaxIntSat = colInfo->column.fMaxIntSat;
|
||||
fTableName = fullTableName;
|
||||
fColumnName = colInfo->column.colName;
|
||||
fColumnOID = colInfo->column.mapOid;
|
||||
fMaxIntSat = colInfo->column.fMaxIntSat;
|
||||
fTableName = fullTableName;
|
||||
fColumnName = colInfo->column.colName;
|
||||
fColumnOID = colInfo->column.mapOid;
|
||||
|
||||
std::string::size_type periodIdx = fTableName.find('.');
|
||||
std::string::size_type periodIdx = fTableName.find('.');
|
||||
|
||||
if (periodIdx == std::string::npos)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Error parsing full table name to get auto-increment value for "
|
||||
<< fTableName;
|
||||
fLog->logMsg( oss.str(), ERR_AUTOINC_TABLE_NAME, MSGLVL_ERROR );
|
||||
BulkLoad::addErrorMsg2BrmUpdater(fTableName, oss);
|
||||
return ERR_AUTOINC_TABLE_NAME;
|
||||
}
|
||||
if (periodIdx == std::string::npos)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Error parsing full table name to get auto-increment value for " << fTableName;
|
||||
fLog->logMsg(oss.str(), ERR_AUTOINC_TABLE_NAME, MSGLVL_ERROR);
|
||||
BulkLoad::addErrorMsg2BrmUpdater(fTableName, oss);
|
||||
return ERR_AUTOINC_TABLE_NAME;
|
||||
}
|
||||
|
||||
uint64_t nextAuto = 0;
|
||||
int rc = getNextValueFromSysCat( nextAuto );
|
||||
uint64_t nextAuto = 0;
|
||||
int rc = getNextValueFromSysCat(nextAuto);
|
||||
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
std::string errMsg;
|
||||
rc = BRMWrapper::getInstance()->startAutoIncrementSequence(
|
||||
fColumnOID, nextAuto, colInfo->column.width, colInfo->column.dataType, errMsg );
|
||||
std::string errMsg;
|
||||
rc = BRMWrapper::getInstance()->startAutoIncrementSequence(fColumnOID, nextAuto, colInfo->column.width,
|
||||
colInfo->column.dataType, errMsg);
|
||||
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Unable to initialize auto-increment sequence for " <<
|
||||
fTableName << "; " << errMsg;
|
||||
fLog->logMsg( oss.str(), rc, MSGLVL_ERROR );
|
||||
BulkLoad::addErrorMsg2BrmUpdater(fTableName, oss);
|
||||
return rc;
|
||||
}
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Unable to initialize auto-increment sequence for " << fTableName << "; " << errMsg;
|
||||
fLog->logMsg(oss.str(), rc, MSGLVL_ERROR);
|
||||
BulkLoad::addErrorMsg2BrmUpdater(fTableName, oss);
|
||||
return rc;
|
||||
}
|
||||
|
||||
std::ostringstream oss2;
|
||||
oss2 << "Initializing next auto increment for table-" << fTableName <<
|
||||
", column-" << fColumnName <<
|
||||
"; autoincrement " << nextAuto;
|
||||
fLog->logMsg( oss2.str(), MSGLVL_INFO2 );
|
||||
std::ostringstream oss2;
|
||||
oss2 << "Initializing next auto increment for table-" << fTableName << ", column-" << fColumnName
|
||||
<< "; autoincrement " << nextAuto;
|
||||
fLog->logMsg(oss2.str(), MSGLVL_INFO2);
|
||||
|
||||
initNextAutoInc( nextAuto );
|
||||
initNextAutoInc(nextAuto);
|
||||
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -124,15 +116,15 @@ int ColumnAutoInc::init( const std::string& fullTableName,
|
||||
// for completeness. Using the mutex should not affect performance, since this
|
||||
// function is only called once per table.
|
||||
//------------------------------------------------------------------------------
|
||||
void ColumnAutoInc::initNextAutoInc( uint64_t nextValue )
|
||||
void ColumnAutoInc::initNextAutoInc(uint64_t nextValue)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(fAutoIncMutex);
|
||||
boost::mutex::scoped_lock lock(fAutoIncMutex);
|
||||
|
||||
// nextValue is unusable if < 1; probably means we already reached max value
|
||||
if (nextValue < 1)
|
||||
fAutoIncLastValue = fMaxIntSat;
|
||||
else
|
||||
fAutoIncLastValue = nextValue - 1;
|
||||
// nextValue is unusable if < 1; probably means we already reached max value
|
||||
if (nextValue < 1)
|
||||
fAutoIncLastValue = fMaxIntSat;
|
||||
else
|
||||
fAutoIncLastValue = nextValue - 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -140,95 +132,90 @@ void ColumnAutoInc::initNextAutoInc( uint64_t nextValue )
|
||||
// necessary to save or commit changes to the auto-increment nextValue, are
|
||||
// applied here.
|
||||
//------------------------------------------------------------------------------
|
||||
int ColumnAutoInc::finish( )
|
||||
int ColumnAutoInc::finish()
|
||||
{
|
||||
int rc = NO_ERROR;
|
||||
int rc = NO_ERROR;
|
||||
|
||||
// We intentionally use a separate DBRM instance in this function. We don't
|
||||
// use the BRMWrapper singleton. We do this because the BRM call that is
|
||||
// made to issue a lock is a synchronous call that will block till a lock
|
||||
// is acquired. Better to do this in a separate BRM instance, rather than
|
||||
// having this call block any other thread using BRM.
|
||||
BRM::DBRM dbrm;
|
||||
// We intentionally use a separate DBRM instance in this function. We don't
|
||||
// use the BRMWrapper singleton. We do this because the BRM call that is
|
||||
// made to issue a lock is a synchronous call that will block till a lock
|
||||
// is acquired. Better to do this in a separate BRM instance, rather than
|
||||
// having this call block any other thread using BRM.
|
||||
BRM::DBRM dbrm;
|
||||
|
||||
// We grab AI lock in order to access/synchronize DBRM and the system
|
||||
// catalog as a single operation, to avoid race condition between apps.
|
||||
try
|
||||
{
|
||||
dbrm.getAILock( fColumnOID );
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
// We grab AI lock in order to access/synchronize DBRM and the system
|
||||
// catalog as a single operation, to avoid race condition between apps.
|
||||
try
|
||||
{
|
||||
dbrm.getAILock(fColumnOID);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Error locking auto-increment nextValue lock for table " << fTableName << "; column "
|
||||
<< fColumnName << "; " << ex.what();
|
||||
fLog->logMsg(oss.str(), ERR_AUTOINC_GET_LOCK, MSGLVL_ERROR);
|
||||
BulkLoad::addErrorMsg2BrmUpdater(fTableName, oss);
|
||||
return ERR_AUTOINC_GET_LOCK;
|
||||
}
|
||||
|
||||
uint64_t sysCatNextAuto = 0;
|
||||
rc = getNextValueFromSysCat(sysCatNextAuto);
|
||||
|
||||
if (rc == NO_ERROR)
|
||||
{
|
||||
// Update system catalog if my latest AI nextValue is > the current
|
||||
// syscat AI nextValue. max(uint64_t) denotes an AI column that has maxed out.
|
||||
uint64_t myNextValue = getNextAutoIncToSave();
|
||||
|
||||
if ((sysCatNextAuto != AUTOINCR_SATURATED) && // do not update if syscat already at max
|
||||
((myNextValue > sysCatNextAuto) || (myNextValue == AUTOINCR_SATURATED)))
|
||||
{
|
||||
std::ostringstream oss2;
|
||||
oss2 << "Updating next auto increment for table-" << fTableName << ", column-" << fColumnName
|
||||
<< "; autoincrement " << myNextValue;
|
||||
fLog->logMsg(oss2.str(), MSGLVL_INFO2);
|
||||
|
||||
rc = BulkLoad::updateNextValue(fColumnOID, myNextValue);
|
||||
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
WErrorCodes ec;
|
||||
std::ostringstream oss;
|
||||
oss << "Error locking auto-increment nextValue lock for table " <<
|
||||
fTableName << "; column " << fColumnName << "; " << ex.what();
|
||||
fLog->logMsg( oss.str(), ERR_AUTOINC_GET_LOCK, MSGLVL_ERROR );
|
||||
oss << "Error updating auto-increment nextValue for table " << fTableName << "; column "
|
||||
<< fColumnName << "; rc=" << rc << "; " << ec.errorString(ERR_AUTOINC_UPDATE);
|
||||
fLog->logMsg(oss.str(), ERR_AUTOINC_UPDATE, MSGLVL_ERROR);
|
||||
BulkLoad::addErrorMsg2BrmUpdater(fTableName, oss);
|
||||
return ERR_AUTOINC_GET_LOCK;
|
||||
// Don't exit this function yet. We set return code and fall
|
||||
// through to bottom of the function to release the AI lock.
|
||||
rc = ERR_AUTOINC_UPDATE;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t sysCatNextAuto = 0;
|
||||
rc = getNextValueFromSysCat( sysCatNextAuto );
|
||||
|
||||
if (rc == NO_ERROR)
|
||||
else
|
||||
{
|
||||
// Update system catalog if my latest AI nextValue is > the current
|
||||
// syscat AI nextValue. max(uint64_t) denotes an AI column that has maxed out.
|
||||
uint64_t myNextValue = getNextAutoIncToSave();
|
||||
|
||||
if ( (sysCatNextAuto != AUTOINCR_SATURATED) && // do not update if syscat already at max
|
||||
((myNextValue > sysCatNextAuto) ||
|
||||
(myNextValue == AUTOINCR_SATURATED)) )
|
||||
{
|
||||
std::ostringstream oss2;
|
||||
oss2 << "Updating next auto increment for table-" << fTableName <<
|
||||
", column-" << fColumnName <<
|
||||
"; autoincrement " << myNextValue;
|
||||
fLog->logMsg( oss2.str(), MSGLVL_INFO2 );
|
||||
|
||||
rc = BulkLoad::updateNextValue( fColumnOID, myNextValue );
|
||||
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
WErrorCodes ec;
|
||||
std::ostringstream oss;
|
||||
oss << "Error updating auto-increment nextValue for table " <<
|
||||
fTableName << "; column " << fColumnName << "; rc=" << rc <<
|
||||
"; " << ec.errorString(ERR_AUTOINC_UPDATE);
|
||||
fLog->logMsg( oss.str(), ERR_AUTOINC_UPDATE, MSGLVL_ERROR );
|
||||
BulkLoad::addErrorMsg2BrmUpdater(fTableName, oss);
|
||||
// Don't exit this function yet. We set return code and fall
|
||||
// through to bottom of the function to release the AI lock.
|
||||
rc = ERR_AUTOINC_UPDATE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream oss2;
|
||||
oss2 << "Skip updating next auto increment for table-" << fTableName <<
|
||||
", column-" << fColumnName <<
|
||||
"; autoincrement " << myNextValue <<
|
||||
"; syscat AI already at " << sysCatNextAuto;
|
||||
fLog->logMsg( oss2.str(), MSGLVL_INFO2 );
|
||||
}
|
||||
} // end of rc==NO_ERROR from getNextValueFromSysCat()
|
||||
|
||||
try
|
||||
{
|
||||
dbrm.releaseAILock( fColumnOID );
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
// If we have trouble releasing AI lock, we log it, but we don't
|
||||
// consider it fatal to the job; so we don't return bad return code.
|
||||
std::ostringstream oss;
|
||||
oss << "Error releasing auto-increment nextValue lock for table " <<
|
||||
fTableName << "; column " << fColumnName << "; " << ex.what();
|
||||
fLog->logMsg( oss.str(), ERR_AUTOINC_REL_LOCK, MSGLVL_WARNING );
|
||||
//return ERR_AUTOINC_REL_LOCK;
|
||||
std::ostringstream oss2;
|
||||
oss2 << "Skip updating next auto increment for table-" << fTableName << ", column-" << fColumnName
|
||||
<< "; autoincrement " << myNextValue << "; syscat AI already at " << sysCatNextAuto;
|
||||
fLog->logMsg(oss2.str(), MSGLVL_INFO2);
|
||||
}
|
||||
} // end of rc==NO_ERROR from getNextValueFromSysCat()
|
||||
|
||||
return rc;
|
||||
try
|
||||
{
|
||||
dbrm.releaseAILock(fColumnOID);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
// If we have trouble releasing AI lock, we log it, but we don't
|
||||
// consider it fatal to the job; so we don't return bad return code.
|
||||
std::ostringstream oss;
|
||||
oss << "Error releasing auto-increment nextValue lock for table " << fTableName << "; column "
|
||||
<< fColumnName << "; " << ex.what();
|
||||
fLog->logMsg(oss.str(), ERR_AUTOINC_REL_LOCK, MSGLVL_WARNING);
|
||||
// return ERR_AUTOINC_REL_LOCK;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -236,84 +223,79 @@ int ColumnAutoInc::finish( )
|
||||
// value tracked by this ColumnInfo object, that can/should be saved back
|
||||
// into the system catalog at the end of the job.
|
||||
//------------------------------------------------------------------------------
|
||||
uint64_t ColumnAutoInc::getNextAutoIncToSave( )
|
||||
uint64_t ColumnAutoInc::getNextAutoIncToSave()
|
||||
{
|
||||
uint64_t nextValue = AUTOINCR_SATURATED;
|
||||
uint64_t nextValue = AUTOINCR_SATURATED;
|
||||
|
||||
boost::mutex::scoped_lock lock(fAutoIncMutex);
|
||||
boost::mutex::scoped_lock lock(fAutoIncMutex);
|
||||
|
||||
// nextValue is returned as -1 if we reached max value
|
||||
if (fAutoIncLastValue < fMaxIntSat)
|
||||
nextValue = fAutoIncLastValue + 1;
|
||||
// nextValue is returned as -1 if we reached max value
|
||||
if (fAutoIncLastValue < fMaxIntSat)
|
||||
nextValue = fAutoIncLastValue + 1;
|
||||
|
||||
return nextValue;
|
||||
return nextValue;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Get the current AI nextValue from the system catalog.
|
||||
//------------------------------------------------------------------------------
|
||||
int ColumnAutoInc::getNextValueFromSysCat( uint64_t& nextValue )
|
||||
int ColumnAutoInc::getNextValueFromSysCat(uint64_t& nextValue)
|
||||
{
|
||||
std::string::size_type periodIdx = fTableName.find('.');
|
||||
std::string::size_type periodIdx = fTableName.find('.');
|
||||
|
||||
std::string sName;
|
||||
std::string tName;
|
||||
sName.assign(fTableName, 0, periodIdx);
|
||||
tName.assign(fTableName, periodIdx + 1,
|
||||
fTableName.length() - (periodIdx + 1));
|
||||
execplan::CalpontSystemCatalog::TableName tbl(sName, tName);
|
||||
uint64_t nextAuto = 0;
|
||||
std::string sName;
|
||||
std::string tName;
|
||||
sName.assign(fTableName, 0, periodIdx);
|
||||
tName.assign(fTableName, periodIdx + 1, fTableName.length() - (periodIdx + 1));
|
||||
execplan::CalpontSystemCatalog::TableName tbl(sName, tName);
|
||||
uint64_t nextAuto = 0;
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
boost::shared_ptr<execplan::CalpontSystemCatalog> systemCatPtr =
|
||||
execplan::CalpontSystemCatalog::makeCalpontSystemCatalog(BULK_SYSCAT_SESSION_ID);
|
||||
systemCatPtr->identity(execplan::CalpontSystemCatalog::EC);
|
||||
|
||||
// Handle bad return code or thrown exception from
|
||||
// system catalog query.
|
||||
nextAuto = systemCatPtr->nextAutoIncrValue(tbl);
|
||||
|
||||
if (nextAuto == 0)
|
||||
{
|
||||
boost::shared_ptr<execplan::CalpontSystemCatalog> systemCatPtr =
|
||||
execplan::CalpontSystemCatalog::makeCalpontSystemCatalog(
|
||||
BULK_SYSCAT_SESSION_ID);
|
||||
systemCatPtr->identity(execplan::CalpontSystemCatalog::EC);
|
||||
|
||||
// Handle bad return code or thrown exception from
|
||||
// system catalog query.
|
||||
nextAuto = systemCatPtr->nextAutoIncrValue( tbl );
|
||||
|
||||
if (nextAuto == 0)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"Not an auto-increment column, or column not found");
|
||||
}
|
||||
else if (nextAuto == AUTOINCR_SATURATED)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"auto-increment max value already reached");
|
||||
}
|
||||
|
||||
nextValue = nextAuto;
|
||||
throw std::runtime_error("Not an auto-increment column, or column not found");
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
else if (nextAuto == AUTOINCR_SATURATED)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Unable to get current auto-increment value for " <<
|
||||
sName << "." << tName << "; " << ex.what();
|
||||
fLog->logMsg( oss.str(), ERR_AUTOINC_INIT1, MSGLVL_ERROR );
|
||||
BulkLoad::addErrorMsg2BrmUpdater(tName, oss);
|
||||
return ERR_AUTOINC_INIT1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Unable to get current auto-increment value for " <<
|
||||
sName << "." << tName << "; unknown exception";
|
||||
fLog->logMsg( oss.str(), ERR_AUTOINC_INIT2, MSGLVL_ERROR );
|
||||
BulkLoad::addErrorMsg2BrmUpdater(tName, oss);
|
||||
return ERR_AUTOINC_INIT2;
|
||||
throw std::runtime_error("auto-increment max value already reached");
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
nextValue = nextAuto;
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Unable to get current auto-increment value for " << sName << "." << tName << "; " << ex.what();
|
||||
fLog->logMsg(oss.str(), ERR_AUTOINC_INIT1, MSGLVL_ERROR);
|
||||
BulkLoad::addErrorMsg2BrmUpdater(tName, oss);
|
||||
return ERR_AUTOINC_INIT1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Unable to get current auto-increment value for " << sName << "." << tName
|
||||
<< "; unknown exception";
|
||||
fLog->logMsg(oss.str(), ERR_AUTOINC_INIT2, MSGLVL_ERROR);
|
||||
BulkLoad::addErrorMsg2BrmUpdater(tName, oss);
|
||||
return ERR_AUTOINC_INIT2;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ColumnAutoIncJob constructor.
|
||||
//------------------------------------------------------------------------------
|
||||
ColumnAutoIncJob::ColumnAutoIncJob( Log* logger ) : ColumnAutoInc(logger)
|
||||
ColumnAutoIncJob::ColumnAutoIncJob(Log* logger) : ColumnAutoInc(logger)
|
||||
{
|
||||
}
|
||||
|
||||
@ -321,7 +303,7 @@ ColumnAutoIncJob::ColumnAutoIncJob( Log* logger ) : ColumnAutoInc(logger)
|
||||
// ColumnAutoIncJob destructor.
|
||||
//------------------------------------------------------------------------------
|
||||
/* virtual */
|
||||
ColumnAutoIncJob::~ColumnAutoIncJob( )
|
||||
ColumnAutoIncJob::~ColumnAutoIncJob()
|
||||
{
|
||||
}
|
||||
|
||||
@ -330,29 +312,25 @@ ColumnAutoIncJob::~ColumnAutoIncJob( )
|
||||
// Returns starting nextValue associated with the reserved range of numbers.
|
||||
//------------------------------------------------------------------------------
|
||||
/* virtual */
|
||||
int ColumnAutoIncJob::reserveNextRange(
|
||||
uint32_t autoIncCount,
|
||||
uint64_t& nextValue )
|
||||
int ColumnAutoIncJob::reserveNextRange(uint32_t autoIncCount, uint64_t& nextValue)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(fAutoIncMutex);
|
||||
boost::mutex::scoped_lock lock(fAutoIncMutex);
|
||||
|
||||
if ((fMaxIntSat - autoIncCount) < fAutoIncLastValue)
|
||||
{
|
||||
return ERR_AUTOINC_GEN_EXCEED_MAX;
|
||||
}
|
||||
if ((fMaxIntSat - autoIncCount) < fAutoIncLastValue)
|
||||
{
|
||||
return ERR_AUTOINC_GEN_EXCEED_MAX;
|
||||
}
|
||||
|
||||
nextValue = fAutoIncLastValue + 1;
|
||||
fAutoIncLastValue += autoIncCount;
|
||||
nextValue = fAutoIncLastValue + 1;
|
||||
fAutoIncLastValue += autoIncCount;
|
||||
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ColumnAutoIncIncremental constructor.
|
||||
//------------------------------------------------------------------------------
|
||||
ColumnAutoIncIncremental::ColumnAutoIncIncremental( Log* logger ) :
|
||||
ColumnAutoInc(logger)
|
||||
ColumnAutoIncIncremental::ColumnAutoIncIncremental(Log* logger) : ColumnAutoInc(logger)
|
||||
{
|
||||
}
|
||||
|
||||
@ -360,7 +338,7 @@ ColumnAutoIncIncremental::ColumnAutoIncIncremental( Log* logger ) :
|
||||
// ColumnAutoIncIncremental destructor.
|
||||
//------------------------------------------------------------------------------
|
||||
/* virtual */
|
||||
ColumnAutoIncIncremental::~ColumnAutoIncIncremental( )
|
||||
ColumnAutoIncIncremental::~ColumnAutoIncIncremental()
|
||||
{
|
||||
}
|
||||
|
||||
@ -369,45 +347,41 @@ ColumnAutoIncIncremental::~ColumnAutoIncIncremental( )
|
||||
// Returns starting nextValue associated with the reserved range of numbers.
|
||||
//------------------------------------------------------------------------------
|
||||
/* virtual */
|
||||
int ColumnAutoIncIncremental::reserveNextRange(
|
||||
uint32_t autoIncCount,
|
||||
uint64_t& nextValue )
|
||||
int ColumnAutoIncIncremental::reserveNextRange(uint32_t autoIncCount, uint64_t& nextValue)
|
||||
{
|
||||
uint64_t countArg = autoIncCount;
|
||||
uint64_t nextValArg = 0;
|
||||
std::string errMsg;
|
||||
int rc = BRMWrapper::getInstance()->getAutoIncrementRange(
|
||||
fColumnOID, countArg, nextValArg, errMsg );
|
||||
uint64_t countArg = autoIncCount;
|
||||
uint64_t nextValArg = 0;
|
||||
std::string errMsg;
|
||||
int rc = BRMWrapper::getInstance()->getAutoIncrementRange(fColumnOID, countArg, nextValArg, errMsg);
|
||||
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Error reserving auto-increment range (" << countArg <<
|
||||
" numbers) for table " <<
|
||||
fTableName << "; column " << fColumnName << "; " << errMsg;
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Error reserving auto-increment range (" << countArg << " numbers) for table " << fTableName
|
||||
<< "; column " << fColumnName << "; " << errMsg;
|
||||
|
||||
if (rc == ERR_AUTOINC_GEN_EXCEED_MAX)
|
||||
oss << " Max allowed value is " << fMaxIntSat << ".";
|
||||
if (rc == ERR_AUTOINC_GEN_EXCEED_MAX)
|
||||
oss << " Max allowed value is " << fMaxIntSat << ".";
|
||||
|
||||
fLog->logMsg( oss.str(), rc, MSGLVL_ERROR );
|
||||
BulkLoad::addErrorMsg2BrmUpdater(fTableName, oss);
|
||||
return rc;
|
||||
}
|
||||
fLog->logMsg(oss.str(), rc, MSGLVL_ERROR);
|
||||
BulkLoad::addErrorMsg2BrmUpdater(fTableName, oss);
|
||||
return rc;
|
||||
}
|
||||
|
||||
nextValue = nextValArg;
|
||||
uint64_t autoIncLastValue = nextValue + autoIncCount - 1;
|
||||
nextValue = nextValArg;
|
||||
uint64_t autoIncLastValue = nextValue + autoIncCount - 1;
|
||||
|
||||
// For efficiency we delay the mutex till now, instead of before the call
|
||||
// to getAutoIncrementRange(). This means we could theoretically end up
|
||||
// processing AI ranges out of order, so we don't arbitrarily
|
||||
// update fAutoIncLastValue. We only update it if the range in question
|
||||
// exceeds the current value for fAutoIncLastValue.
|
||||
boost::mutex::scoped_lock lock(fAutoIncMutex);
|
||||
// For efficiency we delay the mutex till now, instead of before the call
|
||||
// to getAutoIncrementRange(). This means we could theoretically end up
|
||||
// processing AI ranges out of order, so we don't arbitrarily
|
||||
// update fAutoIncLastValue. We only update it if the range in question
|
||||
// exceeds the current value for fAutoIncLastValue.
|
||||
boost::mutex::scoped_lock lock(fAutoIncMutex);
|
||||
|
||||
if (autoIncLastValue > fAutoIncLastValue)
|
||||
fAutoIncLastValue = autoIncLastValue;
|
||||
if (autoIncLastValue > fAutoIncLastValue)
|
||||
fAutoIncLastValue = autoIncLastValue;
|
||||
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
} // end of namespace
|
||||
} // namespace WriteEngine
|
||||
|
Reference in New Issue
Block a user