1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@ -42,37 +42,40 @@ namespace batchloader
// Mutex lock not needed in this function as it is only called from main thread
//------------------------------------------------------------------------------
BatchLoader::BatchLoader ( uint32_t tableOid,
execplan::CalpontSystemCatalog::SCN sessionId,
std::vector<uint32_t>& PMs )
execplan::CalpontSystemCatalog::SCN sessionId,
std::vector<uint32_t>& PMs )
{
fFirstPm=0;
fNextIdx=0;
fFirstPm = 0;
fNextIdx = 0;
fPMs = PMs;
fSessionId = sessionId;
fTableOid = tableOid;
OamCache * oamcache = OamCache::makeOamCache();
oam::OamCache::PMDbrootsMap_t systemPmDbrootMap = oamcache->getPMToDbrootsMap();
std::map<int, OamCache::dbRoots>::iterator iter = systemPmDbrootMap->begin();
//cout << "fPMs size is " << fPMs.size() << endl;
fPmDbrootMap.reset(new OamCache::PMDbrootsMap_t::element_type());
fDbrootPMmap.reset(new map<int, int>());
for (uint32_t i=0; i < fPMs.size(); i++)
{
iter = systemPmDbrootMap->find(fPMs[i]);
if (iter != systemPmDbrootMap->end())
{
fDbRoots.insert(fDbRoots.end(), (iter->second).begin(), (iter->second).end());
(*fPmDbrootMap)[fPMs[i]] = iter->second;
}
}
//Build dbroot to PM map
for (iter = fPmDbrootMap->begin(); iter != fPmDbrootMap->end(); iter++)
{
for ( uint32_t i = 0; i < iter->second.size(); i++)
{
(*fDbrootPMmap)[iter->second[i]] = iter->first;
}
}
fSessionId = sessionId;
fTableOid = tableOid;
OamCache* oamcache = OamCache::makeOamCache();
oam::OamCache::PMDbrootsMap_t systemPmDbrootMap = oamcache->getPMToDbrootsMap();
std::map<int, OamCache::dbRoots>::iterator iter = systemPmDbrootMap->begin();
//cout << "fPMs size is " << fPMs.size() << endl;
fPmDbrootMap.reset(new OamCache::PMDbrootsMap_t::element_type());
fDbrootPMmap.reset(new map<int, int>());
for (uint32_t i = 0; i < fPMs.size(); i++)
{
iter = systemPmDbrootMap->find(fPMs[i]);
if (iter != systemPmDbrootMap->end())
{
fDbRoots.insert(fDbRoots.end(), (iter->second).begin(), (iter->second).end());
(*fPmDbrootMap)[fPMs[i]] = iter->second;
}
}
//Build dbroot to PM map
for (iter = fPmDbrootMap->begin(); iter != fPmDbrootMap->end(); iter++)
{
for ( uint32_t i = 0; i < iter->second.size(); i++)
{
(*fDbrootPMmap)[iter->second[i]] = iter->first;
}
}
}
//------------------------------------------------------------------------------
// Select the first PM to send the first batch of rows.
@ -88,288 +91,310 @@ BatchLoader::BatchLoader ( uint32_t tableOid,
//------------------------------------------------------------------------------
void BatchLoader::selectFirstPM ( uint32_t& PMId)
{
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(fSessionId);
//cout << "calling tableName for oid " << fTableOid << endl;
CalpontSystemCatalog::TableName aTableName = systemCatalogPtr->tableName(fTableOid);
CalpontSystemCatalog::RIDList ridList;
ridList = systemCatalogPtr->columnRIDs(aTableName, true); //exception will be handled in caller program.
scoped_ptr<DBRM> dbrmp(new DBRM());
//Build distVec, start from the PM where the table is created. If not in the PM list, 0 will be used.
uint16_t createdDbroot = 0;
int rc = 0;
std::vector<BRM::EmDbRootHWMInfo_v> allInfo (fPMs.size());
for (unsigned i = 0; i < fPMs.size(); i++)
{
rc = dbrmp->getDbRootHWMInfo((ridList[0].objnum), fPMs[i], allInfo[i]);
if ( rc !=0 ) //@Bug 4760
break;
}
if ( rc != 0 ) {
ostringstream oss;
oss << "There is no extent information for table " << aTableName.table;
throw std::runtime_error(oss.str());
}
uint32_t numDbroot = fDbRoots.size();
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(fSessionId);
//cout << "calling tableName for oid " << fTableOid << endl;
CalpontSystemCatalog::TableName aTableName = systemCatalogPtr->tableName(fTableOid);
CalpontSystemCatalog::RIDList ridList;
ridList = systemCatalogPtr->columnRIDs(aTableName, true); //exception will be handled in caller program.
scoped_ptr<DBRM> dbrmp(new DBRM());
//Build distVec, start from the PM where the table is created. If not in the PM list, 0 will be used.
uint16_t createdDbroot = 0;
int rc = 0;
std::vector<BRM::EmDbRootHWMInfo_v> allInfo (fPMs.size());
for (unsigned i = 0; i < fPMs.size(); i++)
{
rc = dbrmp->getDbRootHWMInfo((ridList[0].objnum), fPMs[i], allInfo[i]);
if ( rc != 0 ) //@Bug 4760
break;
}
if ( rc != 0 )
{
ostringstream oss;
oss << "There is no extent information for table " << aTableName.table;
throw std::runtime_error(oss.str());
}
uint32_t numDbroot = fDbRoots.size();
if (numDbroot == 0)
{
throw std::runtime_error("There are no dbroots found during selectFirstPM");
throw std::runtime_error("There are no dbroots found during selectFirstPM");
}
uint64_t* rootExtents = (uint64_t*)alloca((numDbroot + 1) * sizeof(uint64_t)); //array of number extents for each dbroot
for (unsigned i = 0; i < fDbRoots.size(); i++)
{
uint64_t numExtents;
dbrmp->getExtentCount_dbroot((ridList[0].objnum), fDbRoots[i],
false, numExtents);
rootExtents[fDbRoots[i]] = numExtents;
}
bool startDBRootSet = false;
uint64_t* rootBlocks = (uint64_t*)alloca((numDbroot + 1) * sizeof(uint64_t)); //array of number of blocks for the last partition for each dbroot
//cout << "allInfo size is " << allInfo.size() << endl;
//--------------------------------------------------------------------------
// Load rootBlocks to carry total blocks for each DBRoot
// Set startDBRootSet if the partition 0 segment 0 extent is empty
// Set createdDbroot for the DBRoot that carries the partition 0
// segment 0 extent (used to set the default PMId)
//--------------------------------------------------------------------------
for (unsigned i=0; i < allInfo.size(); i++) //All PMs
{
BRM::EmDbRootHWMInfo_v emDbRootHWMInfos = allInfo[i]; //one pm
for (unsigned j=0; j < emDbRootHWMInfos.size(); j++)
{
if (emDbRootHWMInfos[j].totalBlocks == 0) {
//cout << "totalBlocks is 0" << endl;
continue; }
uint64_t* rootExtents = (uint64_t*)alloca((numDbroot + 1) * sizeof(uint64_t)); //array of number extents for each dbroot
//------------------------------------------------------------------
// Ignore partition 0, segment 0 HWM extent if it is disabled
//------------------------------------------------------------------
if ((emDbRootHWMInfos[j].partitionNum == 0) &&
(emDbRootHWMInfos[j].segmentNum ==0) &&
(emDbRootHWMInfos[j].status != BRM::EXTENTOUTOFSERVICE))
{
if (emDbRootHWMInfos[j].localHWM == 0)
{
//newly created table
//cout << " This is newly created table. PM id is " << PMId;
startDBRootSet = true;
createdDbroot = emDbRootHWMInfos[j].dbRoot;
break;
}
else
{
createdDbroot = emDbRootHWMInfos[j].dbRoot;
//cout << " and createdDbroot is " << createdDbroot << endl;
rootBlocks[emDbRootHWMInfos[j].dbRoot] = emDbRootHWMInfos[j].totalBlocks;
}
}
else
{
rootBlocks[emDbRootHWMInfos[j].dbRoot] = emDbRootHWMInfos[j].totalBlocks;
}
}
if (startDBRootSet)
break;
}
//--------------------------------------------------------------------------
// Set the default PMId to the PM with the partition 0 segment 0 extent
//--------------------------------------------------------------------------
PMId = 0;
if ( createdDbroot != 0)
{
std::map<int, int>::iterator iter = fDbrootPMmap->begin();
iter = fDbrootPMmap->find(createdDbroot);
if (iter != fDbrootPMmap->end())
PMId = iter->second;
}
for (unsigned i = 0; i < fDbRoots.size(); i++)
{
uint64_t numExtents;
dbrmp->getExtentCount_dbroot((ridList[0].objnum), fDbRoots[i],
false, numExtents);
rootExtents[fDbRoots[i]] = numExtents;
}
// This will build the batch distribution sequence
//cout << "Building BatchDistSeqVector with PMId " << PMId << endl;
buildBatchDistSeqVector(PMId);
bool startDBRootSet = false;
uint64_t* rootBlocks = (uint64_t*)alloca((numDbroot + 1) * sizeof(uint64_t)); //array of number of blocks for the last partition for each dbroot
//cout << "allInfo size is " << allInfo.size() << endl;
//cout << "startDBRootSet = " << startDBRootSet << endl;
bool allEqual = true;
bool allOtherDbrootEmpty = true;
//--------------------------------------------------------------------------
// Load rootBlocks to carry total blocks for each DBRoot
// Set startDBRootSet if the partition 0 segment 0 extent is empty
// Set createdDbroot for the DBRoot that carries the partition 0
// segment 0 extent (used to set the default PMId)
//--------------------------------------------------------------------------
for (unsigned i = 0; i < allInfo.size(); i++) //All PMs
{
BRM::EmDbRootHWMInfo_v emDbRootHWMInfos = allInfo[i]; //one pm
//--------------------------------------------------------------------------
// startDBRootSet == false
// We don't have an empty partition 0, segment 0 extent to load;
// so evaluate more selection criteria.
//--------------------------------------------------------------------------
if (!startDBRootSet)
{
std::vector<PMRootInfo> rootsExtentsBlocks;
std::map<int, OamCache::dbRoots>::iterator iter;
for (unsigned j = 0; j < emDbRootHWMInfos.size(); j++)
{
if (emDbRootHWMInfos[j].totalBlocks == 0)
{
//cout << "totalBlocks is 0" << endl;
continue;
}
//----------------------------------------------------------------------
// Load rootsExtentsBlocks to carry the number of extents and blocks
// for each DBRoot.
//----------------------------------------------------------------------
for (unsigned j=0; j < fPmDistSeq.size(); j++)
{
PMRootInfo aEntry;
aEntry.PMId = fPmDistSeq[j];
iter = fPmDbrootMap->find(aEntry.PMId);
for (unsigned k=0; k < (iter->second).size(); k++)
{
RootExtentsBlocks aRootInfo;
aRootInfo.DBRoot = (iter->second)[k];
aRootInfo.numExtents = rootExtents[aRootInfo.DBRoot];
aRootInfo.numBlocks = rootBlocks[aRootInfo.DBRoot];
//cout << "aRootInfo DBRoot:numExtents:numBlocks = " << aRootInfo.DBRoot<<":"<<aRootInfo.numExtents<<":"<<aRootInfo.numBlocks<<endl;
aEntry.rootInfo.push_back(aRootInfo);
}
rootsExtentsBlocks.push_back(aEntry);
}
//cout << "rootsExtentsBlocks size is " << rootsExtentsBlocks.size() << " and allOtherDbrootEmpty is " << allOtherDbrootEmpty<< endl;
//------------------------------------------------------------------
// Ignore partition 0, segment 0 HWM extent if it is disabled
//------------------------------------------------------------------
if ((emDbRootHWMInfos[j].partitionNum == 0) &&
(emDbRootHWMInfos[j].segmentNum == 0) &&
(emDbRootHWMInfos[j].status != BRM::EXTENTOUTOFSERVICE))
{
if (emDbRootHWMInfos[j].localHWM == 0)
{
//newly created table
//cout << " This is newly created table. PM id is " << PMId;
startDBRootSet = true;
createdDbroot = emDbRootHWMInfos[j].dbRoot;
break;
}
else
{
createdDbroot = emDbRootHWMInfos[j].dbRoot;
//cout << " and createdDbroot is " << createdDbroot << endl;
rootBlocks[emDbRootHWMInfos[j].dbRoot] = emDbRootHWMInfos[j].totalBlocks;
}
}
else
{
rootBlocks[emDbRootHWMInfos[j].dbRoot] = emDbRootHWMInfos[j].totalBlocks;
}
}
//----------------------------------------------------------------------
// See if all other DBRoots other than the createdDbroot have 0 extents
//----------------------------------------------------------------------
for (unsigned i=1; i < rootsExtentsBlocks.size(); i++)
{
if (!allOtherDbrootEmpty)
break;
//cout << "createdDbroot is " << createdDbroot << endl;
if (i != createdDbroot)
{
for ( unsigned j=0; j < rootsExtentsBlocks[i].rootInfo.size(); j++)
{
if (rootsExtentsBlocks[i].rootInfo[j].numExtents != 0)
{
//cout << "setting allOtherDbrootEmpty to false and i:j = " << i<<":"<<j<<endl;
//cout << "numExtents = " << rootsExtentsBlocks[i].rootInfo[j].numExtents << endl;
allOtherDbrootEmpty = false;
break;
}
}
}
}
//cout << "allOtherDbrootEmpty is " << allOtherDbrootEmpty << endl;
if (startDBRootSet)
break;
}
//----------------------------------------------------------------------
// allOtherDbrootEmpty == true
// No DBRoots (other than the DBRoot having the partition 0,
// segment 0 extent) have extents
//----------------------------------------------------------------------
if (allOtherDbrootEmpty)
{
//find the next PM id on the list
startDBRootSet = true;
buildBatchDistSeqVector();
allEqual = false;
}
//----------------------------------------------------------------------
// allOtherDbrootEmpty == false
// Some DBRoots (other than the DBRoot having the partition 0,
// segment 0 extent) have extents. More evaluation necessary.
//----------------------------------------------------------------------
else //find the dbroot which has the least extents to start
{
//cout << "finding least dbroot to start." << endl;
//------------------------------------------------------------------
// Select PM with DBRoot having the fewest extents.
//------------------------------------------------------------------
uint32_t tmpLeastExtents = rootsExtentsBlocks[0].rootInfo[0].numExtents;
PMId = rootsExtentsBlocks[0].PMId; //@Bug 4809.
for ( unsigned j=1; j < rootsExtentsBlocks[0].rootInfo.size(); j++)
{
if (tmpLeastExtents > rootsExtentsBlocks[0].rootInfo[j].numExtents)
tmpLeastExtents = rootsExtentsBlocks[0].rootInfo[j].numExtents;
}
for (unsigned i=1; i < rootsExtentsBlocks.size(); i++)
{
uint32_t leastExtents = rootsExtentsBlocks[i].rootInfo[0].numExtents;
for ( unsigned j=0; j < rootsExtentsBlocks[i].rootInfo.size(); j++)
{
if (leastExtents > rootsExtentsBlocks[i].rootInfo[j].numExtents)
leastExtents = rootsExtentsBlocks[i].rootInfo[j].numExtents;
}
if (leastExtents < tmpLeastExtents)
{
tmpLeastExtents = leastExtents;
PMId = rootsExtentsBlocks[i].PMId;
allEqual = false;
}
else if (leastExtents > tmpLeastExtents)
allEqual = false;
}
//cout << "allEqual is " << allEqual << endl;
//--------------------------------------------------------------------------
// Set the default PMId to the PM with the partition 0 segment 0 extent
//--------------------------------------------------------------------------
PMId = 0;
//------------------------------------------------------------------
// All DBRoots have the same number of extents.
// Select PM with DBRoot having the fewest number of blocks.
//------------------------------------------------------------------
if (allEqual) //Find the dbroot which has least number of blocks
{
//cout << "All PMs have equal # of least extents" << endl;
uint32_t tmpBloks = rootsExtentsBlocks[0].rootInfo[0].numBlocks;
PMId = rootsExtentsBlocks[0].PMId;
//cout << "tmpBloks:PMId = " << tmpBloks <<":"<<PMId<<endl;
for ( unsigned j=1; j < rootsExtentsBlocks[0].rootInfo.size(); j++)
{
if (tmpBloks > rootsExtentsBlocks[0].rootInfo[j].numBlocks)
tmpBloks = rootsExtentsBlocks[0].rootInfo[j].numBlocks;
}
for (unsigned i=1; i < rootsExtentsBlocks.size(); i++)
{
uint32_t leastBlocks = rootsExtentsBlocks[i].rootInfo[0].numBlocks;
//cout << "leastBlocks = " << leastBlocks << endl;
for ( unsigned j=0; j < rootsExtentsBlocks[i].rootInfo.size(); j++)
{
if (leastBlocks > rootsExtentsBlocks[i].rootInfo[j].numBlocks)
leastBlocks = rootsExtentsBlocks[i].rootInfo[j].numBlocks;
}
if (leastBlocks < tmpBloks)
{
tmpBloks = leastBlocks;
//cout << "tmpBloks changed to " << tmpBloks << endl;
PMId = rootsExtentsBlocks[i].PMId;
//cout << "setting allEqual to false now" << endl;
allEqual = false;
}
}
}
}
}
//--------------------------------------------------------------------------
// startDBRootSet == true
// We select the empty partition 0, segment 0 extent to load
//--------------------------------------------------------------------------
else
{
allEqual = false;
}
fFirstPm = PMId;
if (!allOtherDbrootEmpty || (PMId == 0))
{
prepareForSecondPM();
//cout << "prepareForSecondPM is called. " << endl;
}
if ((allEqual && (PMId == 0)) || allOtherDbrootEmpty)
{
PMId = selectNextPM();
fFirstPm = PMId;
//cout << "PMId is now " << PMId << endl;
}
if ( createdDbroot != 0)
{
std::map<int, int>::iterator iter = fDbrootPMmap->begin();
iter = fDbrootPMmap->find(createdDbroot);
if (iter != fDbrootPMmap->end())
PMId = iter->second;
}
// This will build the batch distribution sequence
//cout << "Building BatchDistSeqVector with PMId " << PMId << endl;
buildBatchDistSeqVector(PMId);
//cout << "startDBRootSet = " << startDBRootSet << endl;
bool allEqual = true;
bool allOtherDbrootEmpty = true;
//--------------------------------------------------------------------------
// startDBRootSet == false
// We don't have an empty partition 0, segment 0 extent to load;
// so evaluate more selection criteria.
//--------------------------------------------------------------------------
if (!startDBRootSet)
{
std::vector<PMRootInfo> rootsExtentsBlocks;
std::map<int, OamCache::dbRoots>::iterator iter;
//----------------------------------------------------------------------
// Load rootsExtentsBlocks to carry the number of extents and blocks
// for each DBRoot.
//----------------------------------------------------------------------
for (unsigned j = 0; j < fPmDistSeq.size(); j++)
{
PMRootInfo aEntry;
aEntry.PMId = fPmDistSeq[j];
iter = fPmDbrootMap->find(aEntry.PMId);
for (unsigned k = 0; k < (iter->second).size(); k++)
{
RootExtentsBlocks aRootInfo;
aRootInfo.DBRoot = (iter->second)[k];
aRootInfo.numExtents = rootExtents[aRootInfo.DBRoot];
aRootInfo.numBlocks = rootBlocks[aRootInfo.DBRoot];
//cout << "aRootInfo DBRoot:numExtents:numBlocks = " << aRootInfo.DBRoot<<":"<<aRootInfo.numExtents<<":"<<aRootInfo.numBlocks<<endl;
aEntry.rootInfo.push_back(aRootInfo);
}
rootsExtentsBlocks.push_back(aEntry);
}
//cout << "rootsExtentsBlocks size is " << rootsExtentsBlocks.size() << " and allOtherDbrootEmpty is " << allOtherDbrootEmpty<< endl;
//----------------------------------------------------------------------
// See if all other DBRoots other than the createdDbroot have 0 extents
//----------------------------------------------------------------------
for (unsigned i = 1; i < rootsExtentsBlocks.size(); i++)
{
if (!allOtherDbrootEmpty)
break;
//cout << "createdDbroot is " << createdDbroot << endl;
if (i != createdDbroot)
{
for ( unsigned j = 0; j < rootsExtentsBlocks[i].rootInfo.size(); j++)
{
if (rootsExtentsBlocks[i].rootInfo[j].numExtents != 0)
{
//cout << "setting allOtherDbrootEmpty to false and i:j = " << i<<":"<<j<<endl;
//cout << "numExtents = " << rootsExtentsBlocks[i].rootInfo[j].numExtents << endl;
allOtherDbrootEmpty = false;
break;
}
}
}
}
//cout << "allOtherDbrootEmpty is " << allOtherDbrootEmpty << endl;
//----------------------------------------------------------------------
// allOtherDbrootEmpty == true
// No DBRoots (other than the DBRoot having the partition 0,
// segment 0 extent) have extents
//----------------------------------------------------------------------
if (allOtherDbrootEmpty)
{
//find the next PM id on the list
startDBRootSet = true;
buildBatchDistSeqVector();
allEqual = false;
}
//----------------------------------------------------------------------
// allOtherDbrootEmpty == false
// Some DBRoots (other than the DBRoot having the partition 0,
// segment 0 extent) have extents. More evaluation necessary.
//----------------------------------------------------------------------
else //find the dbroot which has the least extents to start
{
//cout << "finding least dbroot to start." << endl;
//------------------------------------------------------------------
// Select PM with DBRoot having the fewest extents.
//------------------------------------------------------------------
uint32_t tmpLeastExtents = rootsExtentsBlocks[0].rootInfo[0].numExtents;
PMId = rootsExtentsBlocks[0].PMId; //@Bug 4809.
for ( unsigned j = 1; j < rootsExtentsBlocks[0].rootInfo.size(); j++)
{
if (tmpLeastExtents > rootsExtentsBlocks[0].rootInfo[j].numExtents)
tmpLeastExtents = rootsExtentsBlocks[0].rootInfo[j].numExtents;
}
for (unsigned i = 1; i < rootsExtentsBlocks.size(); i++)
{
uint32_t leastExtents = rootsExtentsBlocks[i].rootInfo[0].numExtents;
for ( unsigned j = 0; j < rootsExtentsBlocks[i].rootInfo.size(); j++)
{
if (leastExtents > rootsExtentsBlocks[i].rootInfo[j].numExtents)
leastExtents = rootsExtentsBlocks[i].rootInfo[j].numExtents;
}
if (leastExtents < tmpLeastExtents)
{
tmpLeastExtents = leastExtents;
PMId = rootsExtentsBlocks[i].PMId;
allEqual = false;
}
else if (leastExtents > tmpLeastExtents)
allEqual = false;
}
//cout << "allEqual is " << allEqual << endl;
//------------------------------------------------------------------
// All DBRoots have the same number of extents.
// Select PM with DBRoot having the fewest number of blocks.
//------------------------------------------------------------------
if (allEqual) //Find the dbroot which has least number of blocks
{
//cout << "All PMs have equal # of least extents" << endl;
uint32_t tmpBloks = rootsExtentsBlocks[0].rootInfo[0].numBlocks;
PMId = rootsExtentsBlocks[0].PMId;
//cout << "tmpBloks:PMId = " << tmpBloks <<":"<<PMId<<endl;
for ( unsigned j = 1; j < rootsExtentsBlocks[0].rootInfo.size(); j++)
{
if (tmpBloks > rootsExtentsBlocks[0].rootInfo[j].numBlocks)
tmpBloks = rootsExtentsBlocks[0].rootInfo[j].numBlocks;
}
for (unsigned i = 1; i < rootsExtentsBlocks.size(); i++)
{
uint32_t leastBlocks = rootsExtentsBlocks[i].rootInfo[0].numBlocks;
//cout << "leastBlocks = " << leastBlocks << endl;
for ( unsigned j = 0; j < rootsExtentsBlocks[i].rootInfo.size(); j++)
{
if (leastBlocks > rootsExtentsBlocks[i].rootInfo[j].numBlocks)
leastBlocks = rootsExtentsBlocks[i].rootInfo[j].numBlocks;
}
if (leastBlocks < tmpBloks)
{
tmpBloks = leastBlocks;
//cout << "tmpBloks changed to " << tmpBloks << endl;
PMId = rootsExtentsBlocks[i].PMId;
//cout << "setting allEqual to false now" << endl;
allEqual = false;
}
}
}
}
}
//--------------------------------------------------------------------------
// startDBRootSet == true
// We select the empty partition 0, segment 0 extent to load
//--------------------------------------------------------------------------
else
{
allEqual = false;
}
fFirstPm = PMId;
if (!allOtherDbrootEmpty || (PMId == 0))
{
prepareForSecondPM();
//cout << "prepareForSecondPM is called. " << endl;
}
if ((allEqual && (PMId == 0)) || allOtherDbrootEmpty)
{
PMId = selectNextPM();
fFirstPm = PMId;
//cout << "PMId is now " << PMId << endl;
}
}
//------------------------------------------------------------------------------
@ -380,54 +405,61 @@ void BatchLoader::selectFirstPM ( uint32_t& PMId)
//------------------------------------------------------------------------------
void BatchLoader::buildBatchDistSeqVector()
{
fPmDistSeq.clear();
BlIntVec aDbCntVec(fPMs.size());
fPmDistSeq.clear();
BlIntVec aDbCntVec(fPMs.size());
std::map<int, OamCache::dbRoots>::iterator iter = fPmDbrootMap->begin();
for (uint32_t i=0; i < fPMs.size(); i++)
{
iter = fPmDbrootMap->find(fPMs[i]);
if ((iter != fPmDbrootMap->end()) && ((iter->second).begin()!=(iter->second).end()))
{
try
{
aDbCntVec[i] = (iter->second).size();
//cout << "PM - "<<fPMs[i] << " Size = " << aDbCntVec[i] << endl;
}
catch(std::exception& exp)
{
throw runtime_error(exp.what());
}
}
else
aDbCntVec[i] = 0;
}
std::map<int, OamCache::dbRoots>::iterator iter = fPmDbrootMap->begin();
int aTotDbRoots = 0;
for (uint32_t i=0; i<aDbCntVec.size(); i++) aTotDbRoots+=aDbCntVec[i];
for (uint32_t i = 0; i < fPMs.size(); i++)
{
iter = fPmDbrootMap->find(fPMs[i]);
int aIdx=0;
while(aIdx < aTotDbRoots)
{
uint32_t aMax=0;
uint32_t aPmId=0;
uint32_t aRefIdx=0;
for (uint32_t i=0; i<aDbCntVec.size(); i++)
{
if(aDbCntVec[i] > aMax)
{
aMax = aDbCntVec[i];
aPmId = fPMs[i];
aRefIdx = i;
}
}
if(aMax>0)
{
fPmDistSeq.push_back(aPmId);
aDbCntVec[aRefIdx]--;
}
aIdx++;
}
if ((iter != fPmDbrootMap->end()) && ((iter->second).begin() != (iter->second).end()))
{
try
{
aDbCntVec[i] = (iter->second).size();
//cout << "PM - "<<fPMs[i] << " Size = " << aDbCntVec[i] << endl;
}
catch (std::exception& exp)
{
throw runtime_error(exp.what());
}
}
else
aDbCntVec[i] = 0;
}
int aTotDbRoots = 0;
for (uint32_t i = 0; i < aDbCntVec.size(); i++) aTotDbRoots += aDbCntVec[i];
int aIdx = 0;
while (aIdx < aTotDbRoots)
{
uint32_t aMax = 0;
uint32_t aPmId = 0;
uint32_t aRefIdx = 0;
for (uint32_t i = 0; i < aDbCntVec.size(); i++)
{
if (aDbCntVec[i] > aMax)
{
aMax = aDbCntVec[i];
aPmId = fPMs[i];
aRefIdx = i;
}
}
if (aMax > 0)
{
fPmDistSeq.push_back(aPmId);
aDbCntVec[aRefIdx]--;
}
aIdx++;
}
}
@ -440,81 +472,90 @@ void BatchLoader::buildBatchDistSeqVector()
//------------------------------------------------------------------------------
void BatchLoader::buildBatchDistSeqVector(uint32_t StartPm)
{
fPmDistSeq.clear();
BlIntVec aDbCntVec(fPMs.size());
BlIntVec aPms;
fPmDistSeq.clear();
BlIntVec aDbCntVec(fPMs.size());
BlIntVec aPms;
if((fPMs.size()==0)&&(StartPm!=0))
throw runtime_error("ERROR : PM list empty while Start != 0");
if ((fPMs.size() == 0) && (StartPm != 0))
throw runtime_error("ERROR : PM list empty while Start != 0");
//for (uint32_t i=0; i<fPMs.size(); i++)
// cout <<"fPM list "<<i <<" = " << fPMs[i] << endl;
//cout << "StartPm = "<< StartPm << endl;
//for (uint32_t i=0; i<fPMs.size(); i++)
// cout <<"fPM list "<<i <<" = " << fPMs[i] << endl;
//cout << "StartPm = "<< StartPm << endl;
if (StartPm == 0)
aPms = fPMs;
else
{
aPms.push_back(StartPm);
uint32_t aLast = fPMs.back();
uint32_t aFirst = fPMs.front();
// Add all the PMs with index more than "StartPm"
for(uint32_t i=0; i<fPMs.size(); i++)
{
if((fPMs[i]>StartPm)&&(fPMs[i]<=aLast)) aPms.push_back(fPMs[i]);
}
// Add all the PMs with index less than "StartPm"
for(uint32_t i=0; i<fPMs.size(); i++)
{
if((fPMs[i]<StartPm)&&(fPMs[i]>=aFirst)) aPms.push_back(fPMs[i]);
}
}
if (StartPm == 0)
aPms = fPMs;
else
{
aPms.push_back(StartPm);
uint32_t aLast = fPMs.back();
uint32_t aFirst = fPMs.front();
// Add all the PMs with index more than "StartPm"
for (uint32_t i = 0; i < fPMs.size(); i++)
{
if ((fPMs[i] > StartPm) && (fPMs[i] <= aLast)) aPms.push_back(fPMs[i]);
}
// Add all the PMs with index less than "StartPm"
for (uint32_t i = 0; i < fPMs.size(); i++)
{
if ((fPMs[i] < StartPm) && (fPMs[i] >= aFirst)) aPms.push_back(fPMs[i]);
}
}
std::map<int, OamCache::dbRoots>::iterator iter = fPmDbrootMap->begin();
for (uint32_t i=0; i < aPms.size(); i++)
{
iter = fPmDbrootMap->find(aPms[i]);
if ((iter != fPmDbrootMap->end()) && ((iter->second).begin()!=(iter->second).end()))
{
aDbCntVec[i] = (iter->second).size();
//cout << "PM - "<<aPms[i] << " Size = " << aDbCntVec[i] << endl;
}
else
aDbCntVec[i] = 0;
}
std::map<int, OamCache::dbRoots>::iterator iter = fPmDbrootMap->begin();
int aTotDbRoots = 0;
for (uint32_t i=0; i<aDbCntVec.size(); i++) aTotDbRoots+=aDbCntVec[i];
for (uint32_t i = 0; i < aPms.size(); i++)
{
iter = fPmDbrootMap->find(aPms[i]);
//cout << "DbCntVec Size = " << aDbCntVec.size() << " TotDbRoots = "<<aTotDbRoots << endl;
if ((iter != fPmDbrootMap->end()) && ((iter->second).begin() != (iter->second).end()))
{
aDbCntVec[i] = (iter->second).size();
//cout << "PM - "<<aPms[i] << " Size = " << aDbCntVec[i] << endl;
}
else
aDbCntVec[i] = 0;
}
int aIdx=0;
while(aIdx < aTotDbRoots)
{
uint32_t aMax=0;
uint32_t aPmId=0;
uint32_t aRefIdx=0;
for (uint32_t i=0; i<aDbCntVec.size(); i++)
{
if(aDbCntVec[i] > aMax)
{
aMax = aDbCntVec[i];
aPmId = aPms[i];
aRefIdx = i;
}
}
if(aMax>0)
{
fPmDistSeq.push_back(aPmId);
aDbCntVec[aRefIdx]--;
}
aIdx++;
}
int aTotDbRoots = 0;
//cout <<"PM Distribution vector size "<< fPmDistSeq.size() << endl;
//for (uint32_t i=0; i<fPmDistSeq.size(); i++)
// cout <<"PM Distribution vector "<<i <<" = " << fPmDistSeq[i] << endl;
for (uint32_t i = 0; i < aDbCntVec.size(); i++) aTotDbRoots += aDbCntVec[i];
//cout << "DbCntVec Size = " << aDbCntVec.size() << " TotDbRoots = "<<aTotDbRoots << endl;
int aIdx = 0;
while (aIdx < aTotDbRoots)
{
uint32_t aMax = 0;
uint32_t aPmId = 0;
uint32_t aRefIdx = 0;
for (uint32_t i = 0; i < aDbCntVec.size(); i++)
{
if (aDbCntVec[i] > aMax)
{
aMax = aDbCntVec[i];
aPmId = aPms[i];
aRefIdx = i;
}
}
if (aMax > 0)
{
fPmDistSeq.push_back(aPmId);
aDbCntVec[aRefIdx]--;
}
aIdx++;
}
//cout <<"PM Distribution vector size "<< fPmDistSeq.size() << endl;
//for (uint32_t i=0; i<fPmDistSeq.size(); i++)
// cout <<"PM Distribution vector "<<i <<" = " << fPmDistSeq[i] << endl;
}
@ -522,38 +563,40 @@ void BatchLoader::buildBatchDistSeqVector(uint32_t StartPm)
uint32_t BatchLoader::selectNextPM()
{
if(0 == fPmDistSeq.size()) //Dist sequence not ready. First time the function is called
{
uint32_t PMId = 0;
//cout << "selectNextPM: size is 0. " << endl;
selectFirstPM(PMId);
return PMId;
}
if(fNextIdx >= fPmDistSeq.size()) fNextIdx=0; //reset it
return fPmDistSeq[fNextIdx++];
if (0 == fPmDistSeq.size()) //Dist sequence not ready. First time the function is called
{
uint32_t PMId = 0;
//cout << "selectNextPM: size is 0. " << endl;
selectFirstPM(PMId);
return PMId;
}
if (fNextIdx >= fPmDistSeq.size()) fNextIdx = 0; //reset it
return fPmDistSeq[fNextIdx++];
}
//------------------------------------------------------------------------------
void BatchLoader::reverseSequence()
{
if(0 == fNextIdx) fNextIdx = fPmDistSeq.size()-1;
else fNextIdx--;
if (0 == fNextIdx) fNextIdx = fPmDistSeq.size() - 1;
else fNextIdx--;
}
//------------------------------------------------------------------------------
void BatchLoader::prepareForSecondPM()
{
// We loop thru by calling the selectNextPM()
// When we get the aSecPm == aFirstPM, we will break so that when
// we call the same function again when we come back get the next PM
if((fFirstPm != 0)&&(fPMs.size()>1))
{
unsigned int aSecPm = selectNextPM();
while(fFirstPm!=aSecPm ) aSecPm = selectNextPM();
}
// We loop thru by calling the selectNextPM()
// When we get the aSecPm == aFirstPM, we will break so that when
// we call the same function again when we come back get the next PM
if ((fFirstPm != 0) && (fPMs.size() > 1))
{
unsigned int aSecPm = selectNextPM();
while (fFirstPm != aSecPm ) aSecPm = selectNextPM();
}
}
} // end of namespace

View File

@ -34,7 +34,7 @@
namespace batchloader
{
//------------------------------------------------------------------------------
/** @brief Class to find the PM id to send a batch of row
*/
@ -58,22 +58,22 @@ public:
uint32_t selectNextPM();
/**
* @brief Move to previous Sequence in the array.
* This can be used when we find that we cannot use the PM right now
* and want to use it later. for example the queue is full of the
* current PM and we want to get the same PM Id when we call selectNextPM()
* next time also.
*/
* @brief Move to previous Sequence in the array.
* This can be used when we find that we cannot use the PM right now
* and want to use it later. for example the queue is full of the
* current PM and we want to get the same PM Id when we call selectNextPM()
* next time also.
*/
void reverseSequence();
/*
/*
* @brief After calling selectFirstPM(), if we need to keep continuing to
* the next PM in the list, we need to call this. If we just want to start
* distributing from dbroot 1 onwards, no need to call this function.
*/
void prepareForSecondPM();
struct RootExtentsBlocks
struct RootExtentsBlocks
{
/** @brief the dbroot
*/
@ -81,20 +81,20 @@ public:
/** @brief the number of extents
*/
uint64_t numExtents;
/** @brief the number of blocks in the last partition
*/
uint64_t numBlocks;
/** @brief the number of blocks in the last partition
*/
uint64_t numBlocks;
};
struct PMRootInfo
{
/** @brief the module id
struct PMRootInfo
{
/** @brief the module id
*/
uint32_t PMId;
/** @brief the dbroot info
*/
std::vector<RootExtentsBlocks> rootInfo;
};
/** @brief the dbroot info
*/
std::vector<RootExtentsBlocks> rootInfo;
};
private:
/** @brief Select the first PM to send the first batch of rows.
@ -104,9 +104,9 @@ private:
*/
void selectFirstPM ( uint32_t& PMId);
/** @brief build the batch distribution sequence in a vector
* return void
*/
/** @brief build the batch distribution sequence in a vector
* return void
*/
void buildBatchDistSeqVector();
/** @brief build the batch distribution sequence in a vector
@ -115,15 +115,15 @@ private:
void buildBatchDistSeqVector(uint32_t StartPm);
typedef std::vector<uint32_t> BlIntVec;
BlIntVec fPMs;
BlIntVec fDbRoots;
BlIntVec fPmDistSeq;
uint32_t fNextIdx;
uint32_t fFirstPm;
execplan::CalpontSystemCatalog::SCN fSessionId;
uint32_t fTableOid;
oam::OamCache::PMDbrootsMap_t fPmDbrootMap;
oam::OamCache::dbRootPMMap_t fDbrootPMmap;
BlIntVec fPMs;
BlIntVec fDbRoots;
BlIntVec fPmDistSeq;
uint32_t fNextIdx;
uint32_t fFirstPm;
execplan::CalpontSystemCatalog::SCN fSessionId;
uint32_t fTableOid;
oam::OamCache::PMDbrootsMap_t fPmDbrootMap;
oam::OamCache::dbRootPMMap_t fDbrootPMmap;
};
} //end of namespace