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

@ -1,97 +1,100 @@
/* Copyright (C) 2014 InfiniDB, Inc.
/* Copyright (C) 2014 InfiniDB, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
// $Id: autoincrementdata.h 525 2010-01-19 23:18:05Z xlou $
//
/** @file */
#include <cassert>
#include <limits>
using namespace std;
#include <boost/thread/mutex.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_array.hpp>
using namespace boost;
#include "autoincrementdata.h"
/*static*/
boost::mutex AutoincrementData::map_mutex;
/*static*/
AutoincrementData::AutoincDataMap AutoincrementData::fAutoincDataMap;
/* static */
AutoincrementData* AutoincrementData::makeAutoincrementData(uint32_t sessionID)
{
boost::mutex::scoped_lock lock(map_mutex);
AutoincrementData* instance;
AutoincDataMap::const_iterator it = fAutoincDataMap.find(sessionID);
if (it == fAutoincDataMap.end())
{
instance = new AutoincrementData();
fAutoincDataMap[sessionID] = instance;
return instance;
}
return it->second;
}
/* static */
void AutoincrementData::removeAutoincrementData(uint32_t sessionID)
{
boost::mutex::scoped_lock lock(map_mutex);
AutoincDataMap::iterator it = fAutoincDataMap.find(sessionID);
if (it != fAutoincDataMap.end())
{
delete (*it).second;
fAutoincDataMap.erase(it);
}
}
AutoincrementData::AutoincrementData()
{
}
AutoincrementData::~AutoincrementData()
{
}
void AutoincrementData::setNextValue(uint32_t columnOid, long long nextValue)
{
boost::mutex::scoped_lock lk(fOIDnextvalLock);
fOidNextValueMap[columnOid] = nextValue;
}
long long AutoincrementData::getNextValue(uint32_t columnOid)
{
boost::mutex::scoped_lock lk(fOIDnextvalLock);
long long nextValue = 0;
OIDNextValue::iterator it = fOidNextValueMap.find(columnOid);
if (it != fOidNextValueMap.end())
{
nextValue = it->second;
}
return nextValue;
}
AutoincrementData::OIDNextValue & AutoincrementData::getOidNextValueMap()
{
boost::mutex::scoped_lock lk(fOIDnextvalLock);
return fOidNextValueMap;
}
// vim:ts=4 sw=4:
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
// $Id: autoincrementdata.h 525 2010-01-19 23:18:05Z xlou $
//
/** @file */
#include <cassert>
#include <limits>
using namespace std;
#include <boost/thread/mutex.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_array.hpp>
using namespace boost;
#include "autoincrementdata.h"
/*static*/
boost::mutex AutoincrementData::map_mutex;
/*static*/
AutoincrementData::AutoincDataMap AutoincrementData::fAutoincDataMap;
/* static */
AutoincrementData* AutoincrementData::makeAutoincrementData(uint32_t sessionID)
{
boost::mutex::scoped_lock lock(map_mutex);
AutoincrementData* instance;
AutoincDataMap::const_iterator it = fAutoincDataMap.find(sessionID);
if (it == fAutoincDataMap.end())
{
instance = new AutoincrementData();
fAutoincDataMap[sessionID] = instance;
return instance;
}
return it->second;
}
/* static */
void AutoincrementData::removeAutoincrementData(uint32_t sessionID)
{
boost::mutex::scoped_lock lock(map_mutex);
AutoincDataMap::iterator it = fAutoincDataMap.find(sessionID);
if (it != fAutoincDataMap.end())
{
delete (*it).second;
fAutoincDataMap.erase(it);
}
}
AutoincrementData::AutoincrementData()
{
}
AutoincrementData::~AutoincrementData()
{
}
void AutoincrementData::setNextValue(uint32_t columnOid, long long nextValue)
{
boost::mutex::scoped_lock lk(fOIDnextvalLock);
fOidNextValueMap[columnOid] = nextValue;
}
long long AutoincrementData::getNextValue(uint32_t columnOid)
{
boost::mutex::scoped_lock lk(fOIDnextvalLock);
long long nextValue = 0;
OIDNextValue::iterator it = fOidNextValueMap.find(columnOid);
if (it != fOidNextValueMap.end())
{
nextValue = it->second;
}
return nextValue;
}
AutoincrementData::OIDNextValue& AutoincrementData::getOidNextValueMap()
{
boost::mutex::scoped_lock lk(fOIDnextvalLock);
return fOidNextValueMap;
}
// vim:ts=4 sw=4:

View File

@ -14,42 +14,42 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
// $Id$
/** @file */
#ifndef AUTOINCREMENTDATA_H__
#define AUTOINCREMENTDATA_H__
#include <stdint.h>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
class AutoincrementData
{
public:
typedef std::map <uint32_t, AutoincrementData*> AutoincDataMap;
typedef std::map<uint32_t, long long> OIDNextValue;
static AutoincrementData* makeAutoincrementData(uint32_t sessionID = 0);
static void removeAutoincrementData(uint32_t sessionID = 0);
void setNextValue(uint32_t columnOid, long long nextValue);
long long getNextValue(uint32_t columnOid);
OIDNextValue & getOidNextValueMap();
private:
/** Constuctors */
explicit AutoincrementData();
explicit AutoincrementData(const AutoincrementData& rhs);
~AutoincrementData();
static boost::mutex map_mutex;
static AutoincDataMap fAutoincDataMap;
OIDNextValue fOidNextValueMap;
boost::mutex fOIDnextvalLock;
};
#endif
// vim:ts=4 sw=4:
// $Id$
/** @file */
#ifndef AUTOINCREMENTDATA_H__
#define AUTOINCREMENTDATA_H__
#include <stdint.h>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
class AutoincrementData
{
public:
typedef std::map <uint32_t, AutoincrementData*> AutoincDataMap;
typedef std::map<uint32_t, long long> OIDNextValue;
static AutoincrementData* makeAutoincrementData(uint32_t sessionID = 0);
static void removeAutoincrementData(uint32_t sessionID = 0);
void setNextValue(uint32_t columnOid, long long nextValue);
long long getNextValue(uint32_t columnOid);
OIDNextValue& getOidNextValueMap();
private:
/** Constuctors */
explicit AutoincrementData();
explicit AutoincrementData(const AutoincrementData& rhs);
~AutoincrementData();
static boost::mutex map_mutex;
static AutoincDataMap fAutoincDataMap;
OIDNextValue fOidNextValueMap;
boost::mutex fOIDnextvalLock;
};
#endif
// vim:ts=4 sw=4:

File diff suppressed because it is too large Load Diff

View File

@ -50,7 +50,7 @@ class CommandPackageProcessor : public DMLPackageProcessor
{
public:
CommandPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid){}
CommandPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid) {}
/** @brief process an CommandDMLPackage
*
* @param cpackage the CommandDMLPackage to process
@ -60,17 +60,17 @@ public:
protected:
private:
void viewTableLock(const dmlpackage::CalpontDMLPackage& cpackage,
DMLResult& result );
void clearTableLock(uint64_t uniqueId,
const dmlpackage::CalpontDMLPackage& cpackage,
DMLResult& result );
void establishTableLockToClear(uint64_t tableLockID,
BRM::TableLockInfo& lockInfo);
void viewTableLock(const dmlpackage::CalpontDMLPackage& cpackage,
DMLResult& result );
void clearTableLock(uint64_t uniqueId,
const dmlpackage::CalpontDMLPackage& cpackage,
DMLResult& result );
void establishTableLockToClear(uint64_t tableLockID,
BRM::TableLockInfo& lockInfo);
// Tracks active cleartablelock commands by storing set of table lock IDs
static std::set<uint64_t> fActiveClearTableLockCmds;
static boost::mutex fActiveClearTableLockCmdMutex;
// Tracks active cleartablelock commands by storing set of table lock IDs
static std::set<uint64_t> fActiveClearTableLockCmds;
static boost::mutex fActiveClearTableLockCmdMutex;
};
}

1560
dbcon/dmlpackageproc/deletepackageprocessor.cpp Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@ -49,40 +49,40 @@ class DeletePackageProcessor : public DMLPackageProcessor
public:
DeletePackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid){}
DeletePackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid) {}
/** @brief process a DeleteDMLPackage
*
* @param cpackage the delete dml package to process
*/
EXPORT DMLResult processPackage(dmlpackage::CalpontDMLPackage& cpackage);
EXPORT DMLResult processPackage(dmlpackage::CalpontDMLPackage& cpackage);
protected:
private:
/** @brief delete a row
*
* @param txnID the transaction id
* @param tablePtr a pointer to the table that is being operated on
* @param rowIDList upon return containts the row ids of the rows deleted
* @param colOldValuesList upon return contains the values the were delete
* @param result upon return will containt the result of the operation
/** @brief delete a row
*
* @param txnID the transaction id
* @param tablePtr a pointer to the table that is being operated on
* @param rowIDList upon return containts the row ids of the rows deleted
* @param colOldValuesList upon return contains the values the were delete
* @param result upon return will containt the result of the operation
bool deleteRows(execplan::CalpontSystemCatalog::SCN txnID, dmlpackage::DMLTable* tablePtr,
WriteEngine::RIDList& rowIDList, WriteEngine::ColValueList& colOldValuesList,
DMLResult& result);
*/
bool processRowgroup(messageqcpp::ByteStream & aRowGroup, DMLResult& result, const uint64_t uniqueId, dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmStateDel,
bool isMeta = false, uint32_t dbroot=1);
WriteEngine::RIDList& rowIDList, WriteEngine::ColValueList& colOldValuesList,
DMLResult& result);
*/
bool processRowgroup(messageqcpp::ByteStream& aRowGroup, DMLResult& result, const uint64_t uniqueId, dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmStateDel,
bool isMeta = false, uint32_t dbroot = 1);
/** @brief add all rows if we have no filter for the delete
*
* @param tablePtr a pointer to the table that is being operated on
*/
uint64_t fixUpRows(dmlpackage::CalpontDMLPackage& cpackage, DMLResult& result, const uint64_t uniqueId, const uint32_t tableOid);
bool receiveAll(DMLResult& result, const uint64_t uniqueId, std::vector<int>& fPMs, std::map<unsigned, bool>& pmStateDel, const uint32_t tableOid);
//bandListsByExtent bandListsMap;
uint64_t fixUpRows(dmlpackage::CalpontDMLPackage& cpackage, DMLResult& result, const uint64_t uniqueId, const uint32_t tableOid);
bool receiveAll(DMLResult& result, const uint64_t uniqueId, std::vector<int>& fPMs, std::map<unsigned, bool>& pmStateDel, const uint32_t tableOid);
//bandListsByExtent bandListsMap;
};

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@
#ifndef DMLPACKAGEPROCESSOR_H
#define DMLPACKAGEPROCESSOR_H
#include <stdexcept>
#include <stdexcept>
#include <string>
#include <sstream>
#include <iostream>
@ -111,65 +111,80 @@ public:
logging::Message message;
/** @brief the rowCount
*/
long long rowCount;
long long rowCount;
std::string tableLockInfo;
// query stats;
std::string queryStats;
std::string extendedStats;
std::string miniStats;
querystats::QueryStats stats;
DMLResult():result(NO_ERROR),rowCount(0){};
DMLResult(): result(NO_ERROR), rowCount(0) {};
};
/** @brief a structure to hold a date
*/
struct Date
{
unsigned spare : 6;
unsigned day : 6;
unsigned month : 4;
unsigned year : 16;
// NULL column value = 0xFFFFFFFE
Date( ) { year = 0xFFFF; month = 0xF; day = 0x3F; spare = 0x3E;}
unsigned spare : 6;
unsigned day : 6;
unsigned month : 4;
unsigned year : 16;
// NULL column value = 0xFFFFFFFE
Date( )
{
year = 0xFFFF;
month = 0xF;
day = 0x3F;
spare = 0x3E;
}
};
/** @brief a structure to hold a datetime
*/
struct dateTime
{
unsigned msecond : 20;
unsigned second : 6;
unsigned minute : 6;
unsigned hour : 6;
unsigned day : 6;
unsigned month : 4;
unsigned year : 16;
// NULL column value = 0xFFFFFFFFFFFFFFFE
dateTime( ) { year = 0xFFFF; month = 0xF; day = 0x3F; hour = 0x3F; minute = 0x3F; second = 0x3F;
msecond = 0xFFFFE; }
unsigned msecond : 20;
unsigned second : 6;
unsigned minute : 6;
unsigned hour : 6;
unsigned day : 6;
unsigned month : 4;
unsigned year : 16;
// NULL column value = 0xFFFFFFFFFFFFFFFE
dateTime( )
{
year = 0xFFFF;
month = 0xF;
day = 0x3F;
hour = 0x3F;
minute = 0x3F;
second = 0x3F;
msecond = 0xFFFFE;
}
};
/** @brief ctor
*/
*/
DMLPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : fEC(0), DMLLoggingId(21), fRollbackPending(false), fDebugLevel(NONE)
{
try {
fWEClient = new WriteEngine::WEClients(WriteEngine::WEClients::DMLPROC);
//std::cout << "In DMLPackageProcessor constructor " << this << std::endl;
fPMCount = fWEClient->getPmCount();
}
catch (...)
{
std::cout << "Cannot make connection to WES" << std::endl;
}
oam::OamCache * oamCache = oam::OamCache::makeOamCache();
fDbRootPMMap = oamCache->getDBRootToPMMap();
fDbrm = aDbrm;
fSessionID = sid;
fExeMgr = new execplan::ClientRotator(fSessionID, "ExeMgr");
//std::cout << " fSessionID is " << fSessionID << std::endl;
fExeMgr->connect(0.005);
}
{
try
{
fWEClient = new WriteEngine::WEClients(WriteEngine::WEClients::DMLPROC);
//std::cout << "In DMLPackageProcessor constructor " << this << std::endl;
fPMCount = fWEClient->getPmCount();
}
catch (...)
{
std::cout << "Cannot make connection to WES" << std::endl;
}
oam::OamCache* oamCache = oam::OamCache::makeOamCache();
fDbRootPMMap = oamCache->getDBRootToPMMap();
fDbrm = aDbrm;
fSessionID = sid;
fExeMgr = new execplan::ClientRotator(fSessionID, "ExeMgr");
//std::cout << " fSessionID is " << fSessionID << std::endl;
fExeMgr->connect(0.005);
}
@ -179,34 +194,49 @@ public:
/** @brief Is it required to debug
*/
inline const bool isDebug( const DebugLevel level ) const { return level <= fDebugLevel; }
inline const bool isDebug( const DebugLevel level ) const
{
return level <= fDebugLevel;
}
/**
* @brief Get debug level
*/
inline const DebugLevel getDebugLevel() const { return fDebugLevel; }
inline const DebugLevel getDebugLevel() const
{
return fDebugLevel;
}
//int rollBackTransaction(uint64_t uniqueId, uint32_t txnID, uint32_t sessionID, std::string & errorMsg);
/**
* @brief Set debug level
*/
inline void setDebugLevel( const DebugLevel level ) { fDebugLevel = level; }
inline void setDebugLevel( const DebugLevel level )
{
fDebugLevel = level;
}
/**
* @brief Set the Distributed Engine Comm object
*/
inline void setEngineComm(joblist::DistributedEngineComm* ec) { fEC = ec; }
inline void setEngineComm(joblist::DistributedEngineComm* ec)
{
fEC = ec;
}
/** @brief process the dml package
*
* @param cpackage the CalpontDMLPackage to process
*/
virtual DMLResult processPackage(dmlpackage::CalpontDMLPackage& cpackage) = 0;
inline void setRM ( joblist::ResourceManager* frm) { fRM = frm; };
EXPORT int rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, std::string & errorMsg);
EXPORT int rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, const uint32_t tableOid, std::string & errorMsg);
inline void setRM ( joblist::ResourceManager* frm)
{
fRM = frm;
};
EXPORT int rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, std::string& errorMsg);
EXPORT int rollBackBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, const uint32_t tableOid, std::string& errorMsg);
/**
* @brief convert a columns data, represnted as a string, to it's native
* data type
@ -222,7 +252,7 @@ public:
* @param type the columns database type
* @param data the columns string representation of it's data
*/
//static std::string dateToString( int datevalue );
//static std::string dateToString( int datevalue );
/** @brief validate numerical string
*
* @param result the result structure
@ -262,11 +292,17 @@ public:
/** @brief Access the rollback pending flag
*/
bool getRollbackPending() {return fRollbackPending;}
bool getRollbackPending()
{
return fRollbackPending;
}
/** @brief Set the rollback pending flag
*/
void setRollbackPending(bool rollback) {fRollbackPending = rollback;}
void setRollbackPending(bool rollback)
{
fRollbackPending = rollback;
}
protected:
/** @brief update the indexes on the target table
@ -279,7 +315,7 @@ protected:
* @param colNameList the updated column names, only valid for update SQL statement
*/
bool updateIndexes( uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, const std::string& schema,
const std::string& table,const dmlpackage::RowList& rows, DMLResult& result,
const std::string& table, const dmlpackage::RowList& rows, DMLResult& result,
std::vector<WriteEngine::RID> ridList,
WriteEngine::ColValueList& colValuesList, std::vector<std::string>& colNameList, const char updateFlag,
std::vector<dicStrValues>& dicStrValCols );
@ -311,19 +347,19 @@ protected:
* @param result the result structure
*/
bool violatesUniqueConstraint( const dmlpackage::RowList& rows,
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
unsigned int sessionID,
DMLResult& result);
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
unsigned int sessionID,
DMLResult& result);
/** @brief validate that the column does not violate a check constraint
*
* @param column the column to validate
* @param result the result structure
*/
bool violatesCheckConstraint( const dmlpackage::RowList& rows,
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
unsigned int sessionID, unsigned int colOffset,
DMLResult& result );
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
unsigned int sessionID, unsigned int colOffset,
DMLResult& result );
/** @brief validate that the column does not violate a not null constraint
*
@ -333,19 +369,19 @@ protected:
*/
bool violatesNotNullConstraint( const dmlpackage::RowList& rows, unsigned int colOffset,
DMLResult& result );
/** @brief validate that the column does not violate a reference (foreign key) constraint
*
* @param rows the row set to validate
* @param colOffset the offset of this column in the row
* @param constraintInfo the column constraint infomation
* @param result the result structure
*/
bool violatesReferenceConstraint( const dmlpackage::RowList& rows,
/** @brief validate that the column does not violate a reference (foreign key) constraint
*
* @param rows the row set to validate
* @param colOffset the offset of this column in the row
* @param constraintInfo the column constraint infomation
* @param result the result structure
*/
bool violatesReferenceConstraint( const dmlpackage::RowList& rows,
unsigned int colOffset,
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
DMLResult& result );
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
DMLResult& result );
/** @brief validate that non of the rows deleted from this table violate a reference
* (foreign key) constraint of the reference table.
*
@ -353,53 +389,53 @@ protected:
* @param table the table name
* @param rows the lists of rows to check column constraints on
* @param result the result structure
*/
bool violatesPKRefConnstraint ( uint32_t sessionID,
const std::string& schema,
const std::string& table,
const dmlpackage::RowList& rows,
const WriteEngine::ColValueList& oldValueList,
DMLResult& result );
bool violatesPKRefConnstraint ( uint32_t sessionID,
const std::string& schema,
const std::string& table,
std::vector<WriteEngine::RID>& rowIDList,
std::vector<void *>& oldValueList,
DMLResult& result );
/** @brief validate that the rows deleted does not violate a reference (foreign key) constraint
*
* @param rows the row set to validate
* @param colOffset the offset of this column in the row
* @param constraintInfo the column constraint infomation
* @param result the result structure
*/
bool violatesReferenceConstraint_PK( const WriteEngine::ColValueList& oldValueList,
const execplan::CalpontSystemCatalog::ColType& colType,
unsigned int colOffset,
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
DMLResult& result );
bool violatesPKRefConnstraint ( uint32_t sessionID,
const std::string& schema,
const std::string& table,
const dmlpackage::RowList& rows,
const WriteEngine::ColValueList& oldValueList,
DMLResult& result );
bool violatesReferenceConstraint_PK( std::vector<void *>& oldValueList,
bool violatesPKRefConnstraint ( uint32_t sessionID,
const std::string& schema,
const std::string& table,
std::vector<WriteEngine::RID>& rowIDList,
std::vector<void*>& oldValueList,
DMLResult& result );
/** @brief validate that the rows deleted does not violate a reference (foreign key) constraint
*
* @param rows the row set to validate
* @param colOffset the offset of this column in the row
* @param constraintInfo the column constraint infomation
* @param result the result structure
*/
bool violatesReferenceConstraint_PK( const WriteEngine::ColValueList& oldValueList,
const execplan::CalpontSystemCatalog::ColType& colType,
unsigned int colOffset,
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
DMLResult& result );
bool violatesReferenceConstraint_PK( std::vector<void*>& oldValueList,
const int totalRows,
const execplan::CalpontSystemCatalog::ColType& colType,
unsigned int colOffset,
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
DMLResult& result );
/** @brief validate that none of the columns in the update row(s) violate
* any reference constraints of the foreign key table
*
* @param schema the schema name
* @param table the table name
* @param rows the lists of rows to check column constraints on
* @param result the result structure
*/
bool violatesUpdtRefConstraints( uint32_t sessionID,
const std::string& schema,
/** @brief validate that none of the columns in the update row(s) violate
* any reference constraints of the foreign key table
*
* @param schema the schema name
* @param table the table name
* @param rows the lists of rows to check column constraints on
* @param result the result structure
*/
bool violatesUpdtRefConstraints( uint32_t sessionID,
const std::string& schema,
const std::string& table,
const dmlpackage::RowList& rows,
const dmlpackage::RowList& rows,
DMLResult& result );
@ -409,13 +445,13 @@ protected:
* @param colOffset the offset of this column in the row
* @param constraintInfo the column constraint infomation
* @param result the result structure
*/
bool violatesReferenceConstraint_updt( const dmlpackage::RowList& rows,
*/
bool violatesReferenceConstraint_updt( const dmlpackage::RowList& rows,
unsigned int colOffset,
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
DMLResult& result );
const execplan::CalpontSystemCatalog::ConstraintInfo& constraintInfo,
DMLResult& result );
/** @brief get the column list for the supplied table
*
* @param schema the schema name
@ -423,8 +459,8 @@ protected:
* @param colList ColumnList to fill with the columns for the supplied table
*/
void getColumnsForTable( uint32_t sessionID, std::string schema, std::string table, dmlpackage::ColumnList& colList );
/** @brief convert absolute rid to relative rid in a segement file
/** @brief convert absolute rid to relative rid in a segement file
*
* @param rid in:the absolute rid out: relative rid in a segement file
* @param dbRoot,partition, segment the extent information obtained from rid
@ -432,25 +468,25 @@ protected:
* @param startDBRoot the dbroot this table starts
* @param dbrootCnt the number of dbroot in db
*/
void convertRidToColumn(uint64_t& rid, unsigned& dbRoot, unsigned& partition,
unsigned& segment, unsigned filesPerColumnPartition,
unsigned extentsPerSegmentFile, unsigned extentRows,
unsigned startDBRoot, unsigned dbrootCnt,
const unsigned startPartitionNum );
void convertRidToColumn(uint64_t& rid, unsigned& dbRoot, unsigned& partition,
unsigned& segment, unsigned filesPerColumnPartition,
unsigned extentsPerSegmentFile, unsigned extentRows,
unsigned startDBRoot, unsigned dbrootCnt,
const unsigned startPartitionNum );
inline bool isDictCol ( execplan::CalpontSystemCatalog::ColType colType )
{
if (((colType.colDataType == execplan::CalpontSystemCatalog::CHAR) && (colType.colWidth > 8))
|| ((colType.colDataType == execplan::CalpontSystemCatalog::VARCHAR) && (colType.colWidth > 7))
|| ((colType.colDataType == execplan::CalpontSystemCatalog::DECIMAL) && (colType.precision > 18))
|| (colType.colDataType == execplan::CalpontSystemCatalog::VARBINARY)
|| (colType.colDataType == execplan::CalpontSystemCatalog::BLOB)
|| (colType.colDataType == execplan::CalpontSystemCatalog::TEXT))
{
return true;
}
else
return false;
if (((colType.colDataType == execplan::CalpontSystemCatalog::CHAR) && (colType.colWidth > 8))
|| ((colType.colDataType == execplan::CalpontSystemCatalog::VARCHAR) && (colType.colWidth > 7))
|| ((colType.colDataType == execplan::CalpontSystemCatalog::DECIMAL) && (colType.precision > 18))
|| (colType.colDataType == execplan::CalpontSystemCatalog::VARBINARY)
|| (colType.colDataType == execplan::CalpontSystemCatalog::BLOB)
|| (colType.colDataType == execplan::CalpontSystemCatalog::TEXT))
{
return true;
}
else
return false;
}
@ -460,21 +496,21 @@ protected:
* @returns error string
*/
std::string projectTableErrCodeToMsg(uint32_t ec);
// bool validateNextValue(execplan::CalpontSystemCatalog::ColType colType, int64_t value, bool & offByOne);
bool validateVarbinaryVal( std::string & inStr);
bool validateVarbinaryVal( std::string& inStr);
int commitTransaction(uint64_t uniqueId, BRM::TxnID txnID);
int commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string & errorMsg);
int commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string & errorMsg);
int rollBackBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, const uint32_t tableOid, std::string & errorMsg);
int flushDataFiles (int rc, std::map<uint32_t,uint32_t> & columnOids, uint64_t uniqueId, BRM::TxnID txnID, uint32_t tableOid);
int endTransaction (uint64_t uniqueId, BRM::TxnID txnID, bool success);
int commitBatchAutoOnTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string& errorMsg);
int commitBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, const uint32_t tableOid, std::string& errorMsg);
int rollBackBatchAutoOffTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID, const uint32_t tableOid, std::string& errorMsg);
int flushDataFiles (int rc, std::map<uint32_t, uint32_t>& columnOids, uint64_t uniqueId, BRM::TxnID txnID, uint32_t tableOid);
int endTransaction (uint64_t uniqueId, BRM::TxnID txnID, bool success);
/** @brief the Session Manager interface
*/
execplan::SessionManager fSessionManager;
joblist::DistributedEngineComm *fEC;
joblist::DistributedEngineComm* fEC;
joblist::ResourceManager* fRM;
char* strlower(char* in);
uint32_t fSessionID;
@ -485,14 +521,14 @@ protected:
boost::shared_ptr<std::map<int, int> > fDbRootPMMap;
oam::Oam fOam;
bool fRollbackPending; // When set, any derived object should stop what it's doing and cleanup in preparation for a Rollback
execplan::ClientRotator* fExeMgr;
execplan::ClientRotator* fExeMgr;
private:
/** @brief clean beginning and ending glitches and spaces from string
*
* @param s string to be cleaned
*/
/** @brief clean beginning and ending glitches and spaces from string
*
* @param s string to be cleaned
*/
void cleanString(std::string& s);
DebugLevel fDebugLevel; // internal use debug level
@ -505,7 +541,7 @@ private:
template <class T>
bool from_string(T& t,
const std::string& s,
std::ios_base& (*f)(std::ios_base&))
std::ios_base & (*f)(std::ios_base&))
{
std::istringstream iss(s);
return !(iss >> f >> t).fail();

View File

@ -31,34 +31,35 @@
using namespace dmlpackage;
namespace dmlpackageprocessor {
namespace dmlpackageprocessor
{
DMLPackageProcessor* DMLPackageProcessorFactory::
makePackageProcessor(int packageType, dmlpackage::CalpontDMLPackage& cpackage)
{
DMLPackageProcessor* dmlProcPtr = 0;
DMLPackageProcessor* dmlProcPtr = 0;
switch( packageType )
{
case DML_INSERT:
dmlProcPtr = new InsertPackageProcessor();
break;
case DML_DELETE:
dmlProcPtr = new DeletePackageProcessor();
break;
switch ( packageType )
{
case DML_INSERT:
dmlProcPtr = new InsertPackageProcessor();
break;
case DML_UPDATE:
dmlProcPtr = new UpdatePackageProcessor();
break;
case DML_COMMAND:
dmlProcPtr = new CommandPackageProcessor();
break;
}
case DML_DELETE:
dmlProcPtr = new DeletePackageProcessor();
break;
return dmlProcPtr;
case DML_UPDATE:
dmlProcPtr = new UpdatePackageProcessor();
break;
case DML_COMMAND:
dmlProcPtr = new CommandPackageProcessor();
break;
}
return dmlProcPtr;
}
} // namespace dmlpackageprocessor

View File

@ -33,22 +33,24 @@
#define EXPORT
#endif
namespace dmlpackageprocessor {
namespace dmlpackageprocessor
{
/** @brief create a DMLPackageProcessor object from a CalpontDMLPackage object
*
*/
class DMLPackageProcessorFactory {
class DMLPackageProcessorFactory
{
public:
/** @brief static DMLPackageProcessor constructor method
*
* @param packageType the DML Package type
* @param cpackage the CalpontDMLPackage from which the DMLPackageProcessor is constructed
*/
EXPORT static DMLPackageProcessor*
makePackageProcessor( int packageType, dmlpackage::CalpontDMLPackage& cpackage );
/** @brief static DMLPackageProcessor constructor method
*
* @param packageType the DML Package type
* @param cpackage the CalpontDMLPackage from which the DMLPackageProcessor is constructed
*/
EXPORT static DMLPackageProcessor*
makePackageProcessor( int packageType, dmlpackage::CalpontDMLPackage& cpackage );
protected:
@ -56,7 +58,7 @@ private:
};
}
}
#undef EXPORT

View File

@ -51,362 +51,383 @@ using namespace messageqcpp;
namespace dmlpackageprocessor
{
DMLPackageProcessor::DMLResult InsertPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage & cpackage)
{
SUMMARY_INFO("InsertPackageProcessor::processPackage");
DMLPackageProcessor::DMLResult InsertPackageProcessor::processPackage(dmlpackage::CalpontDMLPackage& cpackage)
{
SUMMARY_INFO("InsertPackageProcessor::processPackage");
DMLResult result;
result.result = NO_ERROR;
BRM::TxnID txnid;
// set-up the transaction
txnid.id = cpackage.get_TxnID();
txnid.valid = true;
fSessionID = cpackage.get_SessionID();
DMLTable *tablePtr = cpackage.get_Table();
LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
logging::Message::Args args1;
logging::Message msg(1);
args1.add("Start SQL statement: ");
ostringstream oss;
oss << cpackage.get_SQLStatement() << "; |" << tablePtr->get_SchemaName()<<"|";
args1.add(oss.str());
msg.format( args1 );
Logger logger(logid.fSubsysID);
logger.logMessage(LOG_TYPE_DEBUG, msg, logid);
//WriteEngine::ChunkManager* cm = cpackage.get_ChunkManager();
//fWriteEngine.setChunkManager(cm);
//std::map<uint32_t,uint32_t> oids;
VERBOSE_INFO("Processing Insert DML Package...");
uint64_t uniqueId = 0;
//Bug 5070. Added exception handling
try {
uniqueId = fDbrm->getUnique64();
}
catch (std::exception& ex)
{
logging::Message::Args args;
logging::Message message(9);
args.add(ex.what());
message.format(args);
result.result = INSERT_ERROR;
result.message = message;
fSessionManager.rolledback(txnid);
return result;
}
catch ( ... )
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unknown error occured while getting unique number.");
message.format(args);
result.result = INSERT_ERROR;
result.message = message;
fSessionManager.rolledback(txnid);
return result;
}
uint64_t tableLockId = 0;
int rc = 0;
std::string errorMsg;
OamCache * oamcache = OamCache::makeOamCache();
std::vector<int> moduleIds = oamcache->getModuleIds();
std::vector<uint32_t> pms;
try
{
for (unsigned int i=0; i <moduleIds.size(); i++)
{
pms.push_back((uint32_t)moduleIds[i]);
}
//cout << "single insert get transaction id " << txnid.id << endl;
// get the table object from the package
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(fSessionID);
//cout << "DMLProc using syscatptr:sessionid = " << systemCatalogPtr <<":" << fSessionID<< endl;
CalpontSystemCatalog::TableName tableName;
execplan::CalpontSystemCatalog::ROPair roPair;
TablelockData * tablelockData = TablelockData::makeTablelockData(fSessionID);
if (0 != tablePtr)
{
//check table lock
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(fSessionID);
tableName.schema = tablePtr->get_SchemaName();
tableName.table = tablePtr->get_TableName();
roPair = systemCatalogPtr->tableRID( tableName );
DMLResult result;
result.result = NO_ERROR;
BRM::TxnID txnid;
// set-up the transaction
txnid.id = cpackage.get_TxnID();
txnid.valid = true;
fSessionID = cpackage.get_SessionID();
DMLTable* tablePtr = cpackage.get_Table();
tableLockId = tablelockData->getTablelockId(roPair.objnum); //check whether this table is locked already for this session
if (tableLockId == 0)
{
//cout << "tablelock is not found in cache, getting from dbrm" << endl;
uint32_t processID = ::getpid();
int32_t txnId = txnid.id;
int32_t sessionId = fSessionID;
std::string processName("DMLProc");
int i = 0;
try {
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING );
}
catch (std::exception&)
{
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
}
if ( tableLockId == 0 )
{
int waitPeriod = 10;
int sleepTime = 100; // sleep 100 milliseconds between checks
int numTries = 10; // try 10 times per second
waitPeriod = Config::getWaitPeriod();
numTries = waitPeriod * 10;
struct timespec rm_ts;
LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
logging::Message::Args args1;
logging::Message msg(1);
args1.add("Start SQL statement: ");
ostringstream oss;
oss << cpackage.get_SQLStatement() << "; |" << tablePtr->get_SchemaName() << "|";
args1.add(oss.str());
rm_ts.tv_sec = sleepTime/1000;
rm_ts.tv_nsec = sleepTime%1000 *1000000;
msg.format( args1 );
Logger logger(logid.fSubsysID);
logger.logMessage(LOG_TYPE_DEBUG, msg, logid);
//WriteEngine::ChunkManager* cm = cpackage.get_ChunkManager();
//fWriteEngine.setChunkManager(cm);
//std::map<uint32_t,uint32_t> oids;
VERBOSE_INFO("Processing Insert DML Package...");
uint64_t uniqueId = 0;
for (; i < numTries; i++)
{
//Bug 5070. Added exception handling
try
{
uniqueId = fDbrm->getUnique64();
}
catch (std::exception& ex)
{
logging::Message::Args args;
logging::Message message(9);
args.add(ex.what());
message.format(args);
result.result = INSERT_ERROR;
result.message = message;
fSessionManager.rolledback(txnid);
return result;
}
catch ( ... )
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unknown error occured while getting unique number.");
message.format(args);
result.result = INSERT_ERROR;
result.message = message;
fSessionManager.rolledback(txnid);
return result;
}
uint64_t tableLockId = 0;
int rc = 0;
std::string errorMsg;
OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> moduleIds = oamcache->getModuleIds();
std::vector<uint32_t> pms;
try
{
for (unsigned int i = 0; i < moduleIds.size(); i++)
{
pms.push_back((uint32_t)moduleIds[i]);
}
//cout << "single insert get transaction id " << txnid.id << endl;
// get the table object from the package
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(fSessionID);
//cout << "DMLProc using syscatptr:sessionid = " << systemCatalogPtr <<":" << fSessionID<< endl;
CalpontSystemCatalog::TableName tableName;
execplan::CalpontSystemCatalog::ROPair roPair;
TablelockData* tablelockData = TablelockData::makeTablelockData(fSessionID);
if (0 != tablePtr)
{
//check table lock
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(fSessionID);
tableName.schema = tablePtr->get_SchemaName();
tableName.table = tablePtr->get_TableName();
roPair = systemCatalogPtr->tableRID( tableName );
tableLockId = tablelockData->getTablelockId(roPair.objnum); //check whether this table is locked already for this session
if (tableLockId == 0)
{
//cout << "tablelock is not found in cache, getting from dbrm" << endl;
uint32_t processID = ::getpid();
int32_t txnId = txnid.id;
int32_t sessionId = fSessionID;
std::string processName("DMLProc");
int i = 0;
try
{
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING );
}
catch (std::exception&)
{
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
}
if ( tableLockId == 0 )
{
int waitPeriod = 10;
int sleepTime = 100; // sleep 100 milliseconds between checks
int numTries = 10; // try 10 times per second
waitPeriod = Config::getWaitPeriod();
numTries = waitPeriod * 10;
struct timespec rm_ts;
rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++)
{
#ifdef _MSC_VER
Sleep(rm_ts.tv_sec * 1000);
Sleep(rm_ts.tv_sec * 1000);
#else
struct timespec abs_ts;
do
{
abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec;
}
while(nanosleep(&abs_ts,&rm_ts) < 0);
struct timespec abs_ts;
do
{
abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec;
}
while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif
try {
processID = ::getpid();
txnId = txnid.id;
sessionId = fSessionID;
processName = "DMLProc";
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING );
}
catch (std::exception&)
{
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
}
if (tableLockId > 0)
break;
}
if (i >= numTries) //error out
{
result.result = INSERT_ERROR;
logging::Message::Args args;
string strOp("insert");
args.add(strOp);
args.add(processName);
args.add((uint64_t)processID);
args.add(sessionId);
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
}
}
}
try
{
processID = ::getpid();
txnId = txnid.id;
sessionId = fSessionID;
processName = "DMLProc";
tableLockId = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, &sessionId, &txnId, BRM::LOADING );
}
catch (std::exception&)
{
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE));
}
//cout << " tablelock is obtained with id " << tableLockId << endl;
tablelockData->setTablelock(roPair.objnum, tableLockId);
int pmNum = 0;
if (tableLockId > 0)
break;
}
// Select PM to receive the row.
// 1. Get BRM information
// 2. Find the DBRoot with the fewest in-service blocks.
// DBRoots having no blocks are excluded
// 3. Map the selected DBRoot to the corresponding PM
CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName, true);
std::vector<BRM::EmDbRootHWMInfo_v> allInfo (pms.size());
for (unsigned i = 0; i < pms.size(); i++)
{
rc = fDbrm->getDbRootHWMInfo((ridList[0].objnum), pms[i], allInfo[i]);
if ( rc !=0 ) //@Bug 4760.
{
result.result = INSERT_ERROR;
ostringstream oss;
oss << "Error getting extent information for table " << tableName.table;
throw std::runtime_error(oss.str());
}
}
if (i >= numTries) //error out
{
result.result = INSERT_ERROR;
logging::Message::Args args;
string strOp("insert");
args.add(strOp);
args.add(processName);
args.add((uint64_t)processID);
args.add(sessionId);
throw std::runtime_error(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
}
}
}
// Find DBRoot with fewest blocks; if all DBRoots
// have 0 blocks, then we select the first DBRoot
BRM::EmDbRootHWMInfo tmp;
bool tmpSet = false;
for (unsigned i=0; i < allInfo.size(); i++)
{
BRM::EmDbRootHWMInfo_v emDbRootHWMInfos = allInfo[i];
for (unsigned j=0; j < emDbRootHWMInfos.size(); j++)
{
if (!tmpSet)
{
tmp = emDbRootHWMInfos[j];
tmpSet = true;
}
else if (emDbRootHWMInfos[j].totalBlocks > 0)
{
if ((emDbRootHWMInfos[j].totalBlocks < tmp.totalBlocks) ||
(tmp.totalBlocks == 0))
{
tmp = emDbRootHWMInfos[j];
}
}
}
}
//cout << " tablelock is obtained with id " << tableLockId << endl;
tablelockData->setTablelock(roPair.objnum, tableLockId);
// Select the PM to receive the row
uint32_t dbroot;
if (tmpSet)
{
dbroot = tmp.dbRoot;
boost::shared_ptr<std::map<int, int> > dbRootPMMap = oamcache->getDBRootToPMMap();
pmNum = (*dbRootPMMap)[dbroot];
//@Bug 4760. validate pm value
if (pmNum == 0)
{
result.result = INSERT_ERROR;
ostringstream oss;
oss << "Error mapping extent/DBRoot to PM for table " << tableName.table;
throw std::runtime_error(oss.str());
}
}
else
{
result.result = INSERT_ERROR;
ostringstream oss;
oss << "There is no extent information for table " << tableName.table;
throw std::runtime_error(oss.str());
}
int pmNum = 0;
//This is for single insert only. Batch insert is handled in dmlprocessor.
//cout << "fWEClient = " << fWEClient << endl;
fWEClient->addQueue(uniqueId);
ByteStream bytestream;
bytestream << (uint8_t)WE_SVR_SINGLE_INSERT;
bytestream << uniqueId;
bytestream << (uint32_t)txnid.id;
bytestream << dbroot;
cpackage.write(bytestream);
boost::shared_ptr<messageqcpp::ByteStream> bsIn;
ByteStream::byte rc1;
try
{
fWEClient->write(bytestream, (uint32_t)pmNum);
// Select PM to receive the row.
// 1. Get BRM information
// 2. Find the DBRoot with the fewest in-service blocks.
// DBRoots having no blocks are excluded
// 3. Map the selected DBRoot to the corresponding PM
CalpontSystemCatalog::RIDList ridList = systemCatalogPtr->columnRIDs(tableName, true);
std::vector<BRM::EmDbRootHWMInfo_v> allInfo (pms.size());
for (unsigned i = 0; i < pms.size(); i++)
{
rc = fDbrm->getDbRootHWMInfo((ridList[0].objnum), pms[i], allInfo[i]);
if ( rc != 0 ) //@Bug 4760.
{
result.result = INSERT_ERROR;
ostringstream oss;
oss << "Error getting extent information for table " << tableName.table;
throw std::runtime_error(oss.str());
}
}
// Find DBRoot with fewest blocks; if all DBRoots
// have 0 blocks, then we select the first DBRoot
BRM::EmDbRootHWMInfo tmp;
bool tmpSet = false;
for (unsigned i = 0; i < allInfo.size(); i++)
{
BRM::EmDbRootHWMInfo_v emDbRootHWMInfos = allInfo[i];
for (unsigned j = 0; j < emDbRootHWMInfos.size(); j++)
{
if (!tmpSet)
{
tmp = emDbRootHWMInfos[j];
tmpSet = true;
}
else if (emDbRootHWMInfos[j].totalBlocks > 0)
{
if ((emDbRootHWMInfos[j].totalBlocks < tmp.totalBlocks) ||
(tmp.totalBlocks == 0))
{
tmp = emDbRootHWMInfos[j];
}
}
}
}
// Select the PM to receive the row
uint32_t dbroot;
if (tmpSet)
{
dbroot = tmp.dbRoot;
boost::shared_ptr<std::map<int, int> > dbRootPMMap = oamcache->getDBRootToPMMap();
pmNum = (*dbRootPMMap)[dbroot];
//@Bug 4760. validate pm value
if (pmNum == 0)
{
result.result = INSERT_ERROR;
ostringstream oss;
oss << "Error mapping extent/DBRoot to PM for table " << tableName.table;
throw std::runtime_error(oss.str());
}
}
else
{
result.result = INSERT_ERROR;
ostringstream oss;
oss << "There is no extent information for table " << tableName.table;
throw std::runtime_error(oss.str());
}
//This is for single insert only. Batch insert is handled in dmlprocessor.
//cout << "fWEClient = " << fWEClient << endl;
fWEClient->addQueue(uniqueId);
ByteStream bytestream;
bytestream << (uint8_t)WE_SVR_SINGLE_INSERT;
bytestream << uniqueId;
bytestream << (uint32_t)txnid.id;
bytestream << dbroot;
cpackage.write(bytestream);
boost::shared_ptr<messageqcpp::ByteStream> bsIn;
ByteStream::byte rc1;
try
{
fWEClient->write(bytestream, (uint32_t)pmNum);
#ifdef IDB_DML_DEBUG
cout << "Single insert sending WE_SVR_SINGLE_INSERT to pm " << pmNum << endl;
#endif
bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn);
if ( bsIn->length() == 0 ) //read error
{
rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
}
else {
*bsIn >> rc1;
if (rc1 != 0) {
*bsIn >> errorMsg;
rc = rc1;
}
}
}
catch (runtime_error& ex) //write error
{
#ifdef IDB_DML_DEBUG
cout << "Single insert got exception" << ex.what() << endl;
#endif
rc = NETWORK_ERROR;
errorMsg = ex.what();
}
catch (...)
{
errorMsg = "Caught ... exception during single row insert";
rc = NETWORK_ERROR;
#ifdef IDB_DML_DEBUG
cout << "Single insert got unknown exception" << endl;
cout << "Single insert sending WE_SVR_SINGLE_INSERT to pm " << pmNum << endl;
#endif
}
// Log the insert statement.
LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
logging::Message::Args args1;
logging::Message msg(1);
args1.add("End SQL statement");
msg.format( args1 );
Logger logger(logid.fSubsysID);
logger.logMessage(LOG_TYPE_DEBUG, msg, logid);
logging::logDML(cpackage.get_SessionID(), txnid.id, cpackage.get_SQLStatement()+ ";", cpackage.get_SchemaName());
}
}
catch(exception & ex)
{
cerr << "InsertPackageProcessor::processPackage: " << ex.what() << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Insert Failed: ");
args.add(ex.what());
args.add("");
args.add("");
message.format(args);
if ( result.result != VB_OVERFLOW_ERROR )
{
result.result = INSERT_ERROR;
result.message = message;
errorMsg = ex.what();
}
}
catch(...)
{
cerr << "InsertPackageProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Insert Failed: ");
args.add("encountered unkown exception");
args.add("");
args.add("");
message.format(args);
bsIn.reset(new ByteStream());
fWEClient->read(uniqueId, bsIn);
result.result = INSERT_ERROR;
result.message = message;
}
if ( bsIn->length() == 0 ) //read error
{
rc = NETWORK_ERROR;
errorMsg = "Lost connection to Write Engine Server while updating SYSTABLES";
}
else
{
*bsIn >> rc1;
if (( rc !=0) && (rc != IDBRANGE_WARNING))
{
logging::Message::Args args;
logging::Message message(1);
args.add("Insert Failed: ");
args.add(errorMsg);
args.add("");
args.add("");
message.format(args);
result.result = INSERT_ERROR;
result.message = message;
}
else if (rc == IDBRANGE_WARNING)
{
logging::Message::Args args;
logging::Message message(1);
args.add(errorMsg);
args.add("");
args.add("");
message.format(args);
result.result = IDBRANGE_WARNING;
result.message = message;
}
fWEClient->removeQueue(uniqueId);
VERBOSE_INFO("Finished Processing Insert DML Package");
return result;
}
if (rc1 != 0)
{
*bsIn >> errorMsg;
rc = rc1;
}
}
}
catch (runtime_error& ex) //write error
{
#ifdef IDB_DML_DEBUG
cout << "Single insert got exception" << ex.what() << endl;
#endif
rc = NETWORK_ERROR;
errorMsg = ex.what();
}
catch (...)
{
errorMsg = "Caught ... exception during single row insert";
rc = NETWORK_ERROR;
#ifdef IDB_DML_DEBUG
cout << "Single insert got unknown exception" << endl;
#endif
}
// Log the insert statement.
LoggingID logid( DMLLoggingId, fSessionID, txnid.id);
logging::Message::Args args1;
logging::Message msg(1);
args1.add("End SQL statement");
msg.format( args1 );
Logger logger(logid.fSubsysID);
logger.logMessage(LOG_TYPE_DEBUG, msg, logid);
logging::logDML(cpackage.get_SessionID(), txnid.id, cpackage.get_SQLStatement() + ";", cpackage.get_SchemaName());
}
}
catch (exception& ex)
{
cerr << "InsertPackageProcessor::processPackage: " << ex.what() << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Insert Failed: ");
args.add(ex.what());
args.add("");
args.add("");
message.format(args);
if ( result.result != VB_OVERFLOW_ERROR )
{
result.result = INSERT_ERROR;
result.message = message;
errorMsg = ex.what();
}
}
catch (...)
{
cerr << "InsertPackageProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Insert Failed: ");
args.add("encountered unkown exception");
args.add("");
args.add("");
message.format(args);
result.result = INSERT_ERROR;
result.message = message;
}
if (( rc != 0) && (rc != IDBRANGE_WARNING))
{
logging::Message::Args args;
logging::Message message(1);
args.add("Insert Failed: ");
args.add(errorMsg);
args.add("");
args.add("");
message.format(args);
result.result = INSERT_ERROR;
result.message = message;
}
else if (rc == IDBRANGE_WARNING)
{
logging::Message::Args args;
logging::Message message(1);
args.add(errorMsg);
args.add("");
args.add("");
message.format(args);
result.result = IDBRANGE_WARNING;
result.message = message;
}
fWEClient->removeQueue(uniqueId);
VERBOSE_INFO("Finished Processing Insert DML Package");
return result;
}
} // namespace dmlpackageprocessor

View File

@ -48,8 +48,9 @@ class InsertPackageProcessor : public DMLPackageProcessor
{
public:
InsertPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid) {
}
InsertPackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid)
{
}
/** @brief process an InsertDMLPackage
*
* @param cpackage the InsertDMLPackage to process

View File

@ -1,14 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by libdmlpackageproc.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by libdmlpackageproc.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -59,6 +59,7 @@ void TablelockData::removeTablelockData(uint32_t sessionID)
{
boost::mutex::scoped_lock lock(map_mutex);
TablelockDataMap::iterator it = fTablelockDataMap.find(sessionID);
if (it != fTablelockDataMap.end())
{
delete (*it).second;
@ -75,27 +76,29 @@ TablelockData::~TablelockData()
void TablelockData::setTablelock(uint32_t tableOid, uint64_t tablelockId)
{
boost::mutex::scoped_lock lk(fOIDTablelock);
fOIDTablelockMap[tableOid] = tablelockId;
boost::mutex::scoped_lock lk(fOIDTablelock);
fOIDTablelockMap[tableOid] = tablelockId;
}
uint64_t TablelockData::getTablelockId(uint32_t tableOid)
{
boost::mutex::scoped_lock lk(fOIDTablelock);
uint64_t tablelockId = 0;
OIDTablelock::iterator it = fOIDTablelockMap.find(tableOid);
if (it != fOIDTablelockMap.end())
{
tablelockId = it->second;
}
return tablelockId;
boost::mutex::scoped_lock lk(fOIDTablelock);
uint64_t tablelockId = 0;
OIDTablelock::iterator it = fOIDTablelockMap.find(tableOid);
if (it != fOIDTablelockMap.end())
{
tablelockId = it->second;
}
return tablelockId;
}
TablelockData::OIDTablelock & TablelockData::getOidTablelockMap()
TablelockData::OIDTablelock& TablelockData::getOidTablelockMap()
{
boost::mutex::scoped_lock lk(fOIDTablelock);
boost::mutex::scoped_lock lk(fOIDTablelock);
return fOIDTablelockMap;
return fOIDTablelockMap;
}
}

View File

@ -39,22 +39,22 @@ namespace dmlpackageprocessor
class TablelockData
{
public:
typedef std::map <uint32_t, TablelockData*> TablelockDataMap;
typedef std::map<uint32_t, uint64_t> OIDTablelock;
EXPORT static TablelockData* makeTablelockData(uint32_t sessionID = 0);
EXPORT static void removeTablelockData(uint32_t sessionID = 0);
EXPORT void setTablelock(uint32_t tableOid, uint64_t tablelockId);
EXPORT uint64_t getTablelockId(uint32_t tableOid);
OIDTablelock & getOidTablelockMap();
typedef std::map <uint32_t, TablelockData*> TablelockDataMap;
typedef std::map<uint32_t, uint64_t> OIDTablelock;
EXPORT static TablelockData* makeTablelockData(uint32_t sessionID = 0);
EXPORT static void removeTablelockData(uint32_t sessionID = 0);
EXPORT void setTablelock(uint32_t tableOid, uint64_t tablelockId);
EXPORT uint64_t getTablelockId(uint32_t tableOid);
OIDTablelock& getOidTablelockMap();
private:
/** Constuctors */
/** Constuctors */
explicit TablelockData();
explicit TablelockData(const TablelockData& rhs);
~TablelockData();
~TablelockData();
static boost::mutex map_mutex;
static TablelockDataMap fTablelockDataMap;
static boost::mutex map_mutex;
static TablelockDataMap fTablelockDataMap;
OIDTablelock fOIDTablelockMap;
boost::mutex fOIDTablelock;
};

View File

@ -446,9 +446,9 @@ public:
buildTable(createStmt);
createStmt = "create table tpch.supplier( s_suppkey integer NOT NULL, s_name char(25) , s_address varchar(40), s_nationkey integer , s_phone char(15) , s_acctbal integer, s_comment varchar(101))";
buildTable(createStmt);
createStmt = "create table tpch.part( p_partkey integer NOT NULL ,p_name varchar(55) , p_mfgr char(25), p_brand char(10) , p_type varchar(25) , p_size integer , p_container char(10) ,p_retailprice integer , p_comment varchar(23), PRIMARY KEY(p_partkey))";
buildTable(createStmt);
createStmt = "create table tpch.part( p_partkey integer NOT NULL ,p_name varchar(55) , p_mfgr char(25), p_brand char(10) , p_type varchar(25) , p_size integer , p_container char(10) ,p_retailprice integer , p_comment varchar(23), PRIMARY KEY(p_partkey))";
buildTable(createStmt);
}
@ -458,21 +458,23 @@ public:
ddlpackage::SqlParser parser;
parser.Parse(createText.c_str());
if (parser.Good())
{
const ddlpackage::ParseTree &ptree = parser.GetParseTree();
const ddlpackage::ParseTree& ptree = parser.GetParseTree();
try
{
ddlpackageprocessor::CreateTableProcessor processor;
processor.setDebugLevel(ddlpackageprocessor::CreateTableProcessor::VERBOSE);
ddlpackage::SqlStatement &stmt = *ptree.fList[0];
ddlpackage::SqlStatement& stmt = *ptree.fList[0];
ddlpackageprocessor::CreateTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<ddlpackage::CreateTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
throw;
@ -493,9 +495,11 @@ void destroySemaphores()
semkey = 0x2149bdd2;
sems = semget(semkey, 2, 0666);
if (sems != -1)
{
err = semctl(sems, 0, IPC_RMID);
if (err == -1)
perror("tdriver: semctl");
}
@ -508,9 +512,11 @@ void destroyShmseg()
shmkey = 0x2149bdd2;
shms = shmget(shmkey, 0, 0666);
if (shms != -1)
{
err = shmctl(shms, IPC_RMID, NULL);
if (err == -1 && errno != EINVAL)
{
perror("tdriver: shmctl");
@ -555,7 +561,7 @@ class DMLPackageProcessorTest : public CppUnit::TestFixture
CPPUNIT_TEST( test_insert_package_fail);
CPPUNIT_TEST( test_update_package_fail);
CPPUNIT_TEST( test_delete_package_fail);
CPPUNIT_TEST( test_command_package );
CPPUNIT_TEST( test_command_package );
*/
CPPUNIT_TEST_SUITE_END();
@ -650,7 +656,7 @@ public:
cout << "\nDML statement:" << dmlStatement.c_str() << endl;
VendorDMLStatement dmlStmt(dmlStatement,1);
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
@ -676,7 +682,7 @@ public:
cout << "\nDML statement:" << dmlStatement.c_str() << endl;
VendorDMLStatement dmlStmt(dmlStatement,1);
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
@ -708,7 +714,7 @@ public:
CPPUNIT_ASSERT( DML_INSERT == package_type );
InsertDMLPackage *pObject = new InsertDMLPackage();
InsertDMLPackage* pObject = new InsertDMLPackage();
pObject->read( bs );
@ -720,6 +726,7 @@ public:
pkgProcPtr->setDebugLevel(DMLPackageProcessor::VERBOSE);
DMLPackageProcessor::DMLResult result = pkgProcPtr->processPackage( *pObject );
if ( DMLPackageProcessor::NO_ERROR != result.result )
{
cout << "Insert failed!" << endl;
@ -770,7 +777,7 @@ public:
cout << "\nDML statement:" << dmlStatement.c_str() << endl;
VendorDMLStatement dmlStmt(dmlStatement,1);
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
@ -801,7 +808,7 @@ public:
CPPUNIT_ASSERT( DML_DELETE == package_type );
DeleteDMLPackage *pObject = new DeleteDMLPackage();
DeleteDMLPackage* pObject = new DeleteDMLPackage();
pObject->read( bs );
@ -822,6 +829,7 @@ public:
ml.logDebugMessage( result.message );
}
delete pkgProcPtr;
delete pObject;
@ -837,7 +845,7 @@ public:
cout << "\nDML statement:" << dmlStatement.c_str() << endl;
VendorDMLStatement dmlStmt(dmlStatement,1);
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
@ -866,6 +874,7 @@ public:
ByteStream bytestream;
std::vector<std::string>::const_iterator iter = commands.begin();
while (iter != commands.end())
{
std::string command = *iter;
@ -873,6 +882,7 @@ public:
VendorDMLStatement dml_command(command, 1);
CalpontDMLPackage* dmlCommandPkgPtr = CalpontDMLFactory::makeCalpontDMLPackage(dml_command);
if (dmlCommandPkgPtr)
{
cout << "CalpontDMLFactory::makeCalpontDMLPackage: success" << endl;
@ -900,7 +910,7 @@ public:
CPPUNIT_ASSERT( DML_COMMAND == package_type );
CommandDMLPackage *pObject = new CommandDMLPackage();
CommandDMLPackage* pObject = new CommandDMLPackage();
pObject->read( bs );
@ -921,6 +931,7 @@ public:
ml.logDebugMessage( result.message );
}
delete pkgProcPtr;
delete pObject;
}
@ -967,7 +978,7 @@ public:
CPPUNIT_ASSERT( DML_UPDATE == package_type );
UpdateDMLPackage *pObject = new UpdateDMLPackage();
UpdateDMLPackage* pObject = new UpdateDMLPackage();
pObject->read( bs );
@ -1002,13 +1013,13 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DMLPackageProcessorTest );
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main( int argc, char **argv)
int main( int argc, char** argv)
{
// Uncomment before running tests
//setUp();
//setUp();
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false );

1667
dbcon/dmlpackageproc/updatepackageprocessor.cpp Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@ -45,21 +45,22 @@ class UpdatePackageProcessor : public DMLPackageProcessor
{
public:
UpdatePackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid) {
}
UpdatePackageProcessor(BRM::DBRM* aDbrm, uint32_t sid) : DMLPackageProcessor(aDbrm, sid)
{
}
/** @brief process an UpdateDMLPackage
*
* @param cpackage the UpdateDMLPackage to process
*/
EXPORT DMLResult processPackage(dmlpackage::CalpontDMLPackage& cpackage);
protected:
private:
/** @brief send execution plan to ExeMgr and fetch rows
*
* @param cpackage the UpdateDMLPackage to process
* @param result the result of the operation
* @param cpackage the UpdateDMLPackage to process
* @param result the result of the operation
* @return rows processed
*/
uint64_t fixUpRows(dmlpackage::CalpontDMLPackage& cpackage, DMLResult& result, const uint64_t uniqueId, const uint32_t tableOid);
@ -67,13 +68,13 @@ private:
/** @brief send row group to the PM to process
*
* @param aRowGroup the row group to be sent
* @param result the result of the operation
* @param aRowGroup the row group to be sent
* @param result the result of the operation
* @return the error code
*/
bool processRowgroup(messageqcpp::ByteStream & aRowGroup, DMLResult& result, const uint64_t uniqueId, dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmState, bool isMeta = false, uint32_t dbroot=1);
bool receiveAll(DMLResult& result, const uint64_t uniqueId, std::vector<int>& fPMs, std::map<unsigned, bool>& pmState, const uint32_t tableOid);
};
bool processRowgroup(messageqcpp::ByteStream& aRowGroup, DMLResult& result, const uint64_t uniqueId, dmlpackage::CalpontDMLPackage& cpackage, std::map<unsigned, bool>& pmState, bool isMeta = false, uint32_t dbroot = 1);
bool receiveAll(DMLResult& result, const uint64_t uniqueId, std::vector<int>& fPMs, std::map<unsigned, bool>& pmState, const uint32_t tableOid);
};
}