1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-01 06:46:55 +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

File diff suppressed because it is too large Load Diff

View File

@ -34,125 +34,125 @@
namespace ddlpackageprocessor
{
/** @brief specialization of a DDLPackageProcessor
* for interacting with the Write Engine
* to process alter table ddl statements.
/** @brief specialization of a DDLPackageProcessor
* for interacting with the Write Engine
* to process alter table ddl statements.
*/
class AlterTableProcessor : public DDLPackageProcessor
{
public:
AlterTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process an alter table statement
*
* @param alterTableStmt the AlterTableStatement
*/
class AlterTableProcessor : public DDLPackageProcessor
{
public:
AlterTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
/** @brief process an alter table statement
*
* @param alterTableStmt the AlterTableStatement
*/
EXPORT DDLResult processPackage(ddlpackage::AlterTableStatement& alterTableStmt);
/** @brief add a physical column file
*
* @param result the result of the operation
* @param addColumn the AtaAddColumn object
* @param fTableName the QualifiedName of the table
*/
EXPORT void addColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::ColumnDef* columnDefPtr,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
EXPORT DDLResult processPackage(ddlpackage::AlterTableStatement& alterTableStmt);
/** @brief add a physical column file
*
* @param result the result of the operation
* @param addColumn the AtaAddColumn object
* @param fTableName the QualifiedName of the table
*/
EXPORT void addColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::ColumnDef* columnDefPtr,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief drop a column
*
* @param result the result of the operation
* @param ataDropColumn the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumn& ataDropColumn,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief drop a column
*
* @param result the result of the operation
* @param ataDropColumn the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumn& ataDropColumn,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief drop columns
*
* @param result the result of the operation
* @param ataDropColumns the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumns(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumns& ataDropColumns,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId );
/** @brief drop columns
*
* @param result the result of the operation
* @param ataDropColumns the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumns(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumns& ataDropColumns,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId );
/** @brief add table constraint
*
* @param result the result of the operation
* @param ataAddTableConstraint the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void addTableConstraint(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaAddTableConstraint& ataAddTableConstraint,
ddlpackage::QualifiedName& fTableName );
/** @brief add table constraint
*
* @param result the result of the operation
* @param ataAddTableConstraint the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void addTableConstraint(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaAddTableConstraint& ataAddTableConstraint,
ddlpackage::QualifiedName& fTableName );
/** @brief set column default
*
* @param result the result of the operation
* @param ataSetColumnDefault the AtaSetColumnDefault object
* @param fTableName the QualifiedName for the table
*/
EXPORT void setColumnDefault(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaSetColumnDefault& ataSetColumnDefault,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId );
/** @brief set column default
*
* @param result the result of the operation
* @param ataSetColumnDefault the AtaSetColumnDefault object
* @param fTableName the QualifiedName for the table
*/
EXPORT void setColumnDefault(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaSetColumnDefault& ataSetColumnDefault,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId );
/** @brief drop column default
*
* @param result the result of the operation
* @param ataDropColumnDefault the AtaDropColumnDefault object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumnDefault(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumnDefault& ataDropColumnDefault,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId );
/** @brief drop column default
*
* @param result the result of the operation
* @param ataDropColumnDefault the AtaDropColumnDefault object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumnDefault(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumnDefault& ataDropColumnDefault,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId );
/** @brief drop table constraint
*
* @param result the result of the operation
* @param ataDropTableConstraint the AtaDropTableConstraint object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropTableConstraint(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropTableConstraint& ataDropTableConstraint,
ddlpackage::QualifiedName& fTableName );
/** @brief rename a table
*
* @param result the result of the operation
* @param ataRenameTable the AtaRenameTable object
* @param fTableName the QualifiedName for the table
*/
EXPORT void renameTable(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
DDLResult& result, ddlpackage::AtaRenameTable& ataRenameTable,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief drop table constraint
*
* @param result the result of the operation
* @param ataDropTableConstraint the AtaDropTableConstraint object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropTableConstraint(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropTableConstraint& ataDropTableConstraint,
ddlpackage::QualifiedName& fTableName );
/** @brief rename a table
*
* @param result the result of the operation
* @param ataRenameTable the AtaRenameTable object
* @param fTableName the QualifiedName for the table
*/
EXPORT void renameTable(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
DDLResult& result, ddlpackage::AtaRenameTable& ataRenameTable,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief rename a column
*
* @param result the result of the operation
* @param ataRenameColumn the AtaRenameColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void renameColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaRenameColumn& ataRenameColumn,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief rename a column
*
* @param result the result of the operation
* @param ataRenameColumn the AtaRenameColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void renameColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaRenameColumn& ataRenameColumn,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief change a table autoincrement via a comment
*
* @param result the result of the operation
* @param ataTableComment the AtaTableComment object
* @param fTableName the QualifiedName for the table
*/
EXPORT void tableComment(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaTableComment& ataTableComment,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief change a table autoincrement via a comment
*
* @param result the result of the operation
* @param ataTableComment the AtaTableComment object
* @param fTableName the QualifiedName for the table
*/
EXPORT void tableComment(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaTableComment& ataTableComment,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
protected:
void rollBackAlter(const std::string& error, BRM::TxnID txnID, int sessionId, DDLResult& result, uint64_t uniqueId);
protected:
void rollBackAlter(const std::string& error, BRM::TxnID txnID, int sessionId, DDLResult& result, uint64_t uniqueId);
private:
private:
};
};
} //namespace ddlpackageprocessor

View File

@ -56,8 +56,8 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
DETAIL_INFO(createIndexStmt);
BRM::TxnID txnID;
txnID.id= fTxnid.id;
txnID.valid= fTxnid.valid;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
/*Check whether the table exists already. If not, it is assumed from primary key creating.
This is based on the assumption that Front end is already error out if the user trys to
create index on non-existing table. */
@ -66,13 +66,15 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
tableName.table = (createIndexStmt.fTableName)->fName;
CalpontSystemCatalog::ROPair roPair;
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog( createIndexStmt.fSessionID );
try {
roPair = systemCatalogPtr->tableRID( tableName );
try
{
roPair = systemCatalogPtr->tableRID( tableName );
}
catch (exception& ex)
{
// store primary key name in fPKName
fPKName = createIndexStmt.fIndexName->fName;
// store primary key name in fPKName
fPKName = createIndexStmt.fIndexName->fName;
return result;
}
@ -80,10 +82,12 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
{
return result;
}
if ( roPair.objnum < 3000 )
{
return result;
return result;
}
fPKName = createIndexStmt.fIndexName->fName;
int err = 0;
@ -103,10 +107,12 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
VERBOSE_INFO("Writing meta data to SYSINDEX");
bool multicol = false;
if ( createIndexStmt.fColumnNames.size() > 1 )
{
multicol = true;
multicol = true;
}
//validate index columns
CalpontSystemCatalog::TableColName tableColName;
tableColName.schema = (createIndexStmt.fTableName)->fSchema;
@ -116,25 +122,27 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
ColumnNameList::const_iterator colIter;
int totalWidth = 0;
DDLIndexPopulator pop(&fWriteEngine, &fSessionManager, createIndexStmt.fSessionID, txnID.id, result,
fIdxOID, createIndexStmt.fColumnNames, *createIndexStmt.fTableName,
type, getDebugLevel());
fIdxOID, createIndexStmt.fColumnNames, *createIndexStmt.fTableName,
type, getDebugLevel());
if ( multicol)
{
for ( colIter = createIndexStmt.fColumnNames.begin(); colIter != createIndexStmt.fColumnNames.end(); colIter++)
{
tableColName.column = *colIter;
roPair = systemCatalogPtr->columnRID( tableColName );
oid = systemCatalogPtr->lookupOID( tableColName );
colType = systemCatalogPtr->colType (oid );
totalWidth += (pop.isDictionaryType(colType)) ? 8 : colType.colWidth;
}
if ( totalWidth > 32 )
{
stringstream ss;
ss << totalWidth;
DETAIL_INFO("Total indexed column width greater than 32: " + ss.str());
logging::Message::Args args;
for ( colIter = createIndexStmt.fColumnNames.begin(); colIter != createIndexStmt.fColumnNames.end(); colIter++)
{
tableColName.column = *colIter;
roPair = systemCatalogPtr->columnRID( tableColName );
oid = systemCatalogPtr->lookupOID( tableColName );
colType = systemCatalogPtr->colType (oid );
totalWidth += (pop.isDictionaryType(colType)) ? 8 : colType.colWidth;
}
if ( totalWidth > 32 )
{
stringstream ss;
ss << totalWidth;
DETAIL_INFO("Total indexed column width greater than 32: " + ss.str());
logging::Message::Args args;
logging::Message message(9);
args.add("Error creating index: ");
args.add("Total indexed column width");
@ -144,71 +152,73 @@ CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage:
result.result = CREATE_ERROR;
result.message = message;
return result;
}
}
try
{
//writeSysIndexMetaData(createIndexStmt.fSessionID, txnID.id, result, *createIndexStmt.fTableName, type, createIndexStmt.fIndexName->fName, multicol);
//fIdxOID values are set in writeSysIndexMetaData.
pop.setIdxOID(fIdxOID);
}
}
VERBOSE_INFO("Writing meta data to SYSINDEXCOL");
//writeSysIndexColMetaData(createIndexStmt.fSessionID, txnID.id, result,*createIndexStmt.fTableName, createIndexStmt.fColumnNames, createIndexStmt.fIndexName->fName );
if (createIndexStmt.fUnique)
try
{
VERBOSE_INFO("Writing column constraint meta data to SYSCONSTRAINT");
WriteEngine::ColStruct colStruct;
WriteEngine::ColTuple colTuple;
WriteEngine::ColStructList colStructs;
WriteEngine::ColTupleList colTuples;
WriteEngine::ColValueList colValuesList;
WriteEngine::RIDList ridList;
//writeSysIndexMetaData(createIndexStmt.fSessionID, txnID.id, result, *createIndexStmt.fTableName, type, createIndexStmt.fIndexName->fName, multicol);
DDLColumn column;
//fIdxOID values are set in writeSysIndexMetaData.
pop.setIdxOID(fIdxOID);
CalpontSystemCatalog::TableName sysConsTableName;
sysConsTableName.schema = CALPONT_SCHEMA;
sysConsTableName.table = SYSCONSTRAINT_TABLE;
VERBOSE_INFO("Writing meta data to SYSINDEXCOL");
//writeSysIndexColMetaData(createIndexStmt.fSessionID, txnID.id, result,*createIndexStmt.fTableName, createIndexStmt.fColumnNames, createIndexStmt.fIndexName->fName );
bool isNull = false;
int error = 0;
// get the columns for the SYSCONSTRAINT table
ColumnList sysConsColumns;
ColumnList::const_iterator sysCons_iterator;
getColumnsForTable(createIndexStmt.fSessionID, sysConsTableName.schema,sysConsTableName.table, sysConsColumns);
sysCons_iterator = sysConsColumns.begin();
std::string idxData;
while ( sysCons_iterator != sysConsColumns.end() )
if (createIndexStmt.fUnique)
{
column = *sysCons_iterator;
VERBOSE_INFO("Writing column constraint meta data to SYSCONSTRAINT");
WriteEngine::ColStruct colStruct;
WriteEngine::ColTuple colTuple;
WriteEngine::ColStructList colStructs;
WriteEngine::ColTupleList colTuples;
WriteEngine::ColValueList colValuesList;
WriteEngine::RIDList ridList;
DDLColumn column;
CalpontSystemCatalog::TableName sysConsTableName;
sysConsTableName.schema = CALPONT_SCHEMA;
sysConsTableName.table = SYSCONSTRAINT_TABLE;
bool isNull = false;
int error = 0;
// get the columns for the SYSCONSTRAINT table
ColumnList sysConsColumns;
ColumnList::const_iterator sysCons_iterator;
getColumnsForTable(createIndexStmt.fSessionID, sysConsTableName.schema, sysConsTableName.table, sysConsColumns);
sysCons_iterator = sysConsColumns.begin();
std::string idxData;
while ( sysCons_iterator != sysConsColumns.end() )
{
column = *sysCons_iterator;
boost::algorithm::to_lower(column.tableColName.column);
isNull = false;
if (CONSTRAINTNAME_COL == column.tableColName.column)
{
idxData = createIndexStmt.fIndexName->fName;
boost::algorithm::to_lower(idxData);
idxData = createIndexStmt.fIndexName->fName;
boost::algorithm::to_lower(idxData);
colTuple.data = idxData;
}
else if (SCHEMA_COL == column.tableColName.column)
{
{
idxData = (createIndexStmt.fTableName)->fSchema;
boost::algorithm::to_lower(idxData);
boost::algorithm::to_lower(idxData);
colTuple.data = idxData;
}
else if (TABLENAME_COL == column.tableColName.column)
{
idxData = (createIndexStmt.fTableName)->fName;
boost::algorithm::to_lower(idxData);
boost::algorithm::to_lower(idxData);
colTuple.data = idxData;
}
else if (CONSTRAINTTYPE_COL == column.tableColName.column)
{
std::string consType;
char constraint_type = getConstraintCode(type);
char constraint_type = getConstraintCode(type);
consType += constraint_type;
colTuple.data = consType;
}
@ -219,14 +229,14 @@ try
}
else if (CONSTRAINTTEXT_COL == column.tableColName.column)
{
colTuple.data = getNullValueForType(column.colType);
isNull = true;
colTuple.data = getNullValueForType(column.colType);
isNull = true;
}
else if (INDEXNAME_COL == column.tableColName.column)
{
idxData = createIndexStmt.fIndexName->fName;
boost::algorithm::to_lower(idxData);
colTuple.data = idxData;
idxData = createIndexStmt.fIndexName->fName;
boost::algorithm::to_lower(idxData);
colTuple.data = idxData;
}
else
{
@ -235,7 +245,7 @@ try
}
colStruct.dataOid = column.oid;
colStruct.colWidth = column.colType.colWidth > 8 ? 8 : column.colType.colWidth;
colStruct.tokenFlag = false;
colStruct.tokenFlag = column.colType.colWidth > 8 ? true : false;
@ -245,8 +255,9 @@ try
{
colTuple.data = tokenizeData(txnID.id, result, column.colType, colTuple.data);
}
colStructs.push_back( colStruct );
colTuples.push_back( colTuple );
colValuesList.push_back( colTuples );
@ -255,14 +266,14 @@ try
++sysCons_iterator;
}
if (colStructs.size() != 0)
if (colStructs.size() != 0)
{
//fWriteEngine.setDebugLevel(WriteEngine::DEBUG_3);
//error = fWriteEngine.insertColumnRec( txnID.id, colStructs, colValuesList, ridList );
if ( error != WriteEngine::NO_ERROR )
{
//fWriteEngine.setDebugLevel(WriteEngine::DEBUG_3);
//error = fWriteEngine.insertColumnRec( txnID.id, colStructs, colValuesList, ridList );
if ( error != WriteEngine::NO_ERROR )
{
return rollBackCreateIndex(errorString( "WE: Error inserting Column Record: ", error), txnID, createIndexStmt.fSessionID);
return rollBackCreateIndex(errorString( "WE: Error inserting Column Record: ", error), txnID, createIndexStmt.fSessionID);
// logging::Message::Args args;
// logging::Message message(9);
// args.add("Error updating: ");
@ -270,38 +281,39 @@ try
// args.add("error number: ");
// args.add( error );
// message.format( args );
//
//
// result.result = CREATE_ERROR;
// result.message = message;
}
else
{
result.result = NO_ERROR;
}
}
VERBOSE_INFO("Writing column constraint meta data to SYSCONSTRAINTCOL");
WriteEngine::ColStruct colStructCol;
WriteEngine::ColTuple colTupleCol;
WriteEngine::ColStructList colStructsCol;
WriteEngine::ColTupleList colTuplesCol;
WriteEngine::ColValueList colValuesListCol;
CalpontSystemCatalog::TableName sysConsColTableName;
sysConsColTableName.schema = CALPONT_SCHEMA;
sysConsColTableName.table = SYSCONSTRAINTCOL_TABLE;
colValuesList.clear();
colTuples.clear();
isNull = false;
error = 0;
// get the columns for the SYSCONSTRAINTCOL table
ColumnList sysConsColColumns;
ColumnList::const_iterator sysConsCol_iterator;
getColumnsForTable(createIndexStmt.fSessionID, sysConsColTableName.schema,sysConsColTableName.table, sysConsColColumns);
// write sysconstraintcol
sysConsCol_iterator = sysConsColColumns.begin();
std::string colData;
while ( sysConsCol_iterator != sysConsColColumns.end() )
{
}
else
{
result.result = NO_ERROR;
}
}
VERBOSE_INFO("Writing column constraint meta data to SYSCONSTRAINTCOL");
WriteEngine::ColStruct colStructCol;
WriteEngine::ColTuple colTupleCol;
WriteEngine::ColStructList colStructsCol;
WriteEngine::ColTupleList colTuplesCol;
WriteEngine::ColValueList colValuesListCol;
CalpontSystemCatalog::TableName sysConsColTableName;
sysConsColTableName.schema = CALPONT_SCHEMA;
sysConsColTableName.table = SYSCONSTRAINTCOL_TABLE;
colValuesList.clear();
colTuples.clear();
isNull = false;
error = 0;
// get the columns for the SYSCONSTRAINTCOL table
ColumnList sysConsColColumns;
ColumnList::const_iterator sysConsCol_iterator;
getColumnsForTable(createIndexStmt.fSessionID, sysConsColTableName.schema, sysConsColTableName.table, sysConsColColumns);
// write sysconstraintcol
sysConsCol_iterator = sysConsColColumns.begin();
std::string colData;
while ( sysConsCol_iterator != sysConsColColumns.end() )
{
column = *sysConsCol_iterator;
boost::algorithm::to_lower(column.tableColName.column);
@ -311,20 +323,20 @@ try
{
colData = (createIndexStmt.fTableName)->fSchema;
boost::algorithm::to_lower(colData);
colTupleCol.data = colData;
colTupleCol.data = colData;
}
else if (TABLENAME_COL == column.tableColName.column)
{
colData = (createIndexStmt.fTableName)->fName;
colData = (createIndexStmt.fTableName)->fName;
boost::algorithm::to_lower(colData);
colTupleCol.data = colData;
colTupleCol.data = colData;
}
else if (COLNAME_COL == column.tableColName.column)
{
colData = createIndexStmt.fColumnNames[0];
boost::algorithm::to_lower(colData);
colData = createIndexStmt.fColumnNames[0];
boost::algorithm::to_lower(colData);
colTupleCol.data = colData;
}
else if (CONSTRAINTNAME_COL == column.tableColName.column)
{
@ -348,9 +360,9 @@ try
{
colTupleCol.data = tokenizeData(txnID.id, result, column.colType, colTupleCol.data);
}
colStructsCol.push_back( colStructCol );
colTuplesCol.push_back( colTupleCol );
colValuesListCol.push_back( colTuplesCol );
@ -359,69 +371,73 @@ try
++sysConsCol_iterator;
}
if (colStructsCol.size() != 0)
if (colStructsCol.size() != 0)
{
//fWriteEngine.setDebugLevel(WriteEngine::DEBUG_3);
//error = fWriteEngine.insertColumnRec( txnID.id, colStructsCol, colValuesListCol, ridList );
if ( error != WriteEngine::NO_ERROR )
{
return rollBackCreateIndex(errorString( "WE: Error inserting Column Record: ", error), txnID, createIndexStmt.fSessionID);
/* logging::Message::Args args;
logging::Message message(9);
args.add("Error updating: ");
args.add("calpont.sysconstraintcol");
args.add("error number: ");
args.add( error );
message.format( args );
//fWriteEngine.setDebugLevel(WriteEngine::DEBUG_3);
//error = fWriteEngine.insertColumnRec( txnID.id, colStructsCol, colValuesListCol, ridList );
if ( error != WriteEngine::NO_ERROR )
{
return rollBackCreateIndex(errorString( "WE: Error inserting Column Record: ", error), txnID, createIndexStmt.fSessionID);
result.result = CREATE_ERROR;
result.message = message;*/
}
else
{
result.result = NO_ERROR;
}
}
}
VERBOSE_INFO("Creating index files");
err = fWriteEngine.createIndex( txnID.id, fIdxOID.treeOID, fIdxOID.listOID );
if (err)
{
return rollBackCreateIndex(errorString("Write engine failed to create the new index. ", err), txnID, createIndexStmt.fSessionID);
}
// new if BULK_LOAD close
err = pop.populateIndex(result);
if ( err )
{
return rollBackCreateIndex(errorString("Failed to populate index with current data. ", err), txnID, createIndexStmt.fSessionID);
}
/* logging::Message::Args args;
logging::Message message(9);
args.add("Error updating: ");
args.add("calpont.sysconstraintcol");
args.add("error number: ");
args.add( error );
message.format( args );
result.result = CREATE_ERROR;
result.message = message;*/
}
else
{
result.result = NO_ERROR;
}
}
}
VERBOSE_INFO("Creating index files");
err = fWriteEngine.createIndex( txnID.id, fIdxOID.treeOID, fIdxOID.listOID );
if (err)
{
return rollBackCreateIndex(errorString("Write engine failed to create the new index. ", err), txnID, createIndexStmt.fSessionID);
}
// new if BULK_LOAD close
err = pop.populateIndex(result);
if ( err )
{
return rollBackCreateIndex(errorString("Failed to populate index with current data. ", err), txnID, createIndexStmt.fSessionID);
}
// Log the DDL statement.
logging::logDDL(createIndexStmt.fSessionID, txnID.id, createIndexStmt.fSql, createIndexStmt.fOwner);
// Log the DDL statement.
logging::logDDL(createIndexStmt.fSessionID, txnID.id, createIndexStmt.fSql, createIndexStmt.fOwner);
DETAIL_INFO("Commiting transaction");
err = fWriteEngine.commit( txnID.id );
if (err)
{
return rollBackCreateIndex(errorString("Failed to commit the create index transaction. ", err), txnID, createIndexStmt.fSessionID);
}
DETAIL_INFO("Commiting transaction");
err = fWriteEngine.commit( txnID.id );
fSessionManager.committed(txnID);
if (err)
{
return rollBackCreateIndex(errorString("Failed to commit the create index transaction. ", err), txnID, createIndexStmt.fSessionID);
}
fSessionManager.committed(txnID);
// original if BULK_LOAD close }
} // try
} // try
catch (exception& ex)
{
result = rollBackCreateIndex(ex.what(), txnID, createIndexStmt.fSessionID);
result = rollBackCreateIndex(ex.what(), txnID, createIndexStmt.fSessionID);
}
catch (...)
{
string msg("CreateIndexProcessor::processPackage: caught unknown exception!");
result = rollBackCreateIndex(msg, txnID, createIndexStmt.fSessionID);
string msg("CreateIndexProcessor::processPackage: caught unknown exception!");
result = rollBackCreateIndex(msg, txnID, createIndexStmt.fSessionID);
}
return result;
@ -429,44 +445,47 @@ try
string CreateIndexProcessor::errorString(const string& msg, int error)
{
WriteEngine::WErrorCodes ec;
return string(msg + ec.errorString(error));
WriteEngine::WErrorCodes ec;
return string(msg + ec.errorString(error));
}
CreateIndexProcessor::DDLResult CreateIndexProcessor::rollBackCreateIndex(const string& error, BRM::TxnID& txnID, int sessionId)
{
cerr << "CreatetableProcessor::processPackage: " << error << endl;
DETAIL_INFO(error);
logging::Message::Args args;
logging::Message message(1);
args.add("Create Index Failed: ");
args.add( error );
args.add("");
args.add("");
message.format( args );
DDLResult result;
cerr << "CreatetableProcessor::processPackage: " << error << endl;
DETAIL_INFO(error);
logging::Message::Args args;
logging::Message message(1);
args.add("Create Index Failed: ");
args.add( error );
args.add("");
args.add("");
message.format( args );
DDLResult result;
result.result = CREATE_ERROR;
result.message = message;
rollBackIndex(txnID, sessionId);
return result;
rollBackIndex(txnID, sessionId);
return result;
}
void CreateIndexProcessor::rollBackIndex(BRM::TxnID& txnID, int sessionId)
{
fWriteEngine.rollbackTran(txnID.id, sessionId);
fWriteEngine.dropIndex(txnID.id,fIdxOID.listOID, fIdxOID.treeOID);
try {
//execplan::ObjectIDManager fObjectIDManager;
//fObjectIDManager.returnOIDs(fIdxOID.treeOID, fIdxOID.listOID);
}
catch ( exception& ex )
{
}
catch (... )
{ }
fSessionManager.rolledback(txnID);
fWriteEngine.rollbackTran(txnID.id, sessionId);
fWriteEngine.dropIndex(txnID.id, fIdxOID.listOID, fIdxOID.treeOID);
try
{
//execplan::ObjectIDManager fObjectIDManager;
//fObjectIDManager.returnOIDs(fIdxOID.treeOID, fIdxOID.listOID);
}
catch ( exception& ex )
{
}
catch (... )
{ }
fSessionManager.rolledback(txnID);
}

View File

@ -29,26 +29,26 @@
const int BULK_LOAD = 1;
namespace ddlpackageprocessor
{
/** @brief specialization of a DDLPackageProcessor
* for interacting with the Write Engine to process
* create index ddl statements
/** @brief specialization of a DDLPackageProcessor
* for interacting with the Write Engine to process
* create index ddl statements
*/
class CreateIndexProcessor : public DDLPackageProcessor
{
public:
/** @brief process a create index statement
*
* @param createIndexStmt the create index statement
*/
class CreateIndexProcessor : public DDLPackageProcessor
{
public:
/** @brief process a create index statement
*
* @param createIndexStmt the create index statement
*/
DDLResult processPackage(ddlpackage::CreateIndexStatement& createIndexStmt);
DDLResult processPackage(ddlpackage::CreateIndexStatement& createIndexStmt);
protected:
DDLResult rollBackCreateIndex(const std::string& error, BRM::TxnID& txnID, int sessionId);
void rollBackIndex(BRM::TxnID& txnID);
std::string errorString(const std::string& msg, int error);
private:
protected:
DDLResult rollBackCreateIndex(const std::string& error, BRM::TxnID& txnID, int sessionId);
void rollBackIndex(BRM::TxnID& txnID);
std::string errorString(const std::string& msg, int error);
private:
};
};
} //namespace ddlpackageprocessor
#endif //CREATEINDEXPROCESSOR_H

File diff suppressed because it is too large Load Diff

View File

@ -42,8 +42,8 @@ namespace ddlpackageprocessor
class CreateTableProcessor : public DDLPackageProcessor
{
public:
CreateTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
CreateTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a create table statement
*
* @param createTableStmt the CreateTableStatement
@ -51,7 +51,7 @@ public:
EXPORT DDLResult processPackage(ddlpackage::CreateTableStatement& createTableStmt);
protected:
void rollBackCreateTable(const std::string& error, BRM::TxnID txnID, int sessionId, ddlpackage::TableDef& tableDef, DDLResult& result);
void rollBackCreateTable(const std::string& error, BRM::TxnID txnID, int sessionId, ddlpackage::TableDef& tableDef, DDLResult& result);
private:

File diff suppressed because it is too large Load Diff

View File

@ -43,62 +43,78 @@
#include "joblistfactory.h"
namespace joblist {
namespace joblist
{
class DistributedEngineComm;
}
namespace ddlpackageprocessor
{
/** @brief Populate an new Index
/** @brief Populate an new Index
* implementation of a DDLPopulator
*/
class DDLIndexPopulator
class DDLIndexPopulator
{
public:
/** @brief constructor
*
*/
DDLIndexPopulator(WriteEngine::WriteEngineWrapper* writeEngine,
execplan::SessionManager* sessionManager,
uint32_t sessionID,
execplan::CalpontSystemCatalog::SCN txnID,
DDLPackageProcessor::DDLResult& result,
const DDLPackageProcessor::IndexOID& idxOID,
const ddlpackage::ColumnNameList& colNames,
const ddlpackage::QualifiedName& table,
const ddlpackage::DDL_CONSTRAINTS constraint,
const DDLPackageProcessor::DebugLevel debug):
fWriteEngine(writeEngine), fSessionManager(sessionManager),
fSessionID(sessionID), fTxnID(txnID), fResult(result),
fIdxOID(idxOID), fColNames(colNames), fTable(table), fDebugLevel(debug),
fEC(0), fRidList(), fIdxStructList(), fIdxValueList(),
/* fTOKENSIZE(sizeof(WriteEngine::Token) ) {}*/
fConstraint(constraint), fUniqueColResultList() {}
/** @brief constructor
*
*/
DDLIndexPopulator(WriteEngine::WriteEngineWrapper* writeEngine,
execplan::SessionManager* sessionManager,
uint32_t sessionID,
execplan::CalpontSystemCatalog::SCN txnID,
DDLPackageProcessor::DDLResult& result,
const DDLPackageProcessor::IndexOID& idxOID,
const ddlpackage::ColumnNameList& colNames,
const ddlpackage::QualifiedName& table,
const ddlpackage::DDL_CONSTRAINTS constraint,
const DDLPackageProcessor::DebugLevel debug):
fWriteEngine(writeEngine), fSessionManager(sessionManager),
fSessionID(sessionID), fTxnID(txnID), fResult(result),
fIdxOID(idxOID), fColNames(colNames), fTable(table), fDebugLevel(debug),
fEC(0), fRidList(), fIdxStructList(), fIdxValueList(),
/* fTOKENSIZE(sizeof(WriteEngine::Token) ) {}*/
fConstraint(constraint), fUniqueColResultList() {}
/** @brief destructor
*/
virtual ~DDLIndexPopulator() { };
/** @brief Is it required to debug
*/
const bool isDebug( const DDLPackageProcessor::DebugLevel level ) const { return level <= fDebugLevel; }
const bool isDebug( const DDLPackageProcessor::DebugLevel level ) const
{
return level <= fDebugLevel;
}
/** @brief Get debug level
*/
const DDLPackageProcessor::DebugLevel getDebugLevel() const { return fDebugLevel; }
const DDLPackageProcessor::DebugLevel getDebugLevel() const
{
return fDebugLevel;
}
/** @brief set distributedEngineComm pointer ( for
* loading index).
*/
void setEngineComm(joblist::DistributedEngineComm* ec) { fEC = ec; }
void setIdxOID(const DDLPackageProcessor::IndexOID& idxOID) { fIdxOID = idxOID; }
DDLPackageProcessor::DDLResult getResult() const { return fResult; }
void setEngineComm(joblist::DistributedEngineComm* ec)
{
fEC = ec;
}
void setIdxOID(const DDLPackageProcessor::IndexOID& idxOID)
{
fIdxOID = idxOID;
}
DDLPackageProcessor::DDLResult getResult() const
{
return fResult;
}
/** @brief add data to the index from the statement
@ -107,16 +123,16 @@ public:
* returns if there was an error.
*/
bool populateIndex(DDLPackageProcessor::DDLResult& result);
/** @brief returns if dictionary type
/** @brief returns if dictionary type
*
* determines if coltype is dictionary type based on type and size
*/
bool isDictionaryType(const execplan::CalpontSystemCatalog::ColType& ctype);
bool isDictionaryType(const execplan::CalpontSystemCatalog::ColType& ctype);
void setConstraint(ddlpackage::DDL_CONSTRAINTS constraint);
protected:
protected:
/** @brief make the structures to update the index
*
* builds and executes a query to retrieve all the data from the index columns
@ -131,7 +147,7 @@ public:
* the WriteEngine::IdxStruct
*/
execplan::CalpontSystemCatalog::ColType makeIdxStruct(const execplan::ColumnResult* cr, size_t cols, boost::shared_ptr<execplan::CalpontSystemCatalog> csc );
/** @brief add the column result data to the value list
*
* Check contraints on each data item and adds it to a tuple list.
@ -142,15 +158,15 @@ public:
/** @brief insert data into index.
*
* updates the index with the data using the appropriate write engine method
* updates the index with the data using the appropriate write engine method
* based on multi column. Sets result to error if there is one.
*/
void insertIndex();
void insertIndex();
private:
DDLIndexPopulator(const DDLIndexPopulator& );
void operator=(const DDLIndexPopulator& );
private:
DDLIndexPopulator(const DDLIndexPopulator& );
void operator=(const DDLIndexPopulator& );
/** @brief makes Calpont Select Execution Plan
*
* builds csep to select data from all columns from fColNames
@ -165,12 +181,12 @@ public:
bool isStringType(int type) const
{
return (type == execplan::CalpontSystemCatalog::CHAR
|| type == execplan::CalpontSystemCatalog::VARCHAR
|| type == execplan::CalpontSystemCatalog::FLOAT
|| type == execplan::CalpontSystemCatalog::DOUBLE
|| type == execplan::CalpontSystemCatalog::UFLOAT
|| type == execplan::CalpontSystemCatalog::UDOUBLE );
return (type == execplan::CalpontSystemCatalog::CHAR
|| type == execplan::CalpontSystemCatalog::VARCHAR
|| type == execplan::CalpontSystemCatalog::FLOAT
|| type == execplan::CalpontSystemCatalog::DOUBLE
|| type == execplan::CalpontSystemCatalog::UFLOAT
|| type == execplan::CalpontSystemCatalog::UDOUBLE );
}
/** @brief converts column result data
@ -182,32 +198,32 @@ public:
/** @brief converts non token data to its original type
*/
boost::any convertData(const execplan::CalpontSystemCatalog::ColType& colType, const execplan::ColumnResult* cr, int idx );
/** @brief returns token for string data
*
* There are two methods, the one using the rid is a workaround.
* Use the method that passes string data when WriteEngine::tokenize is
* able to return an existing token for a string. The rid method reads
* the column file directly.
*/
/** @brief returns token for string data
*
* There are two methods, the one using the rid is a workaround.
* Use the method that passes string data when WriteEngine::tokenize is
* able to return an existing token for a string. The rid method reads
* the column file directly.
*/
boost::any tokenizeData( const execplan::CalpontSystemCatalog::ColType& colType, const std::string& data );
boost::any tokenizeData( WriteEngine::RID rid );
/** @brief convert token data
*
* Indexes will use the first 8 bytes of a token type value instead
* of a token.
*/
/** @brief convert token data
*
* Indexes will use the first 8 bytes of a token type value instead
* of a token.
*/
boost::any convertTokenData( const std::string& data );
/** @brief opens the column file for the oid
*
* This method is needed only as long as the class is using the rid
* tokenizeData method. The fColumnFile and this method are no longer
* needed when the WriteEngine::tokenize method can be used.
*/
/** @brief opens the column file for the oid
*
* This method is needed only as long as the class is using the rid
* tokenizeData method. The fColumnFile and this method are no longer
* needed when the WriteEngine::tokenize method can be used.
*/
//bool openColumnFile(WriteEngine::OID oid);
/** @brief returns if data violated its constraint
@ -215,7 +231,7 @@ public:
* checks data according to contraint in coltype and sets result to error
* if constraint violated. Returns if no error.
*/
bool checkConstraints(const WriteEngine::IdxTuple& data, const execplan::CalpontSystemCatalog::ColType& ctype, int i, int column);
bool checkConstraints(const WriteEngine::IdxTuple& data, const execplan::CalpontSystemCatalog::ColType& ctype, int i, int column);
/** @brief returns if data not null
*
@ -229,19 +245,25 @@ public:
*/
bool checkUnique(int i, const execplan::CalpontSystemCatalog::ColType& colType );
bool checkCheck( const WriteEngine::IdxTuple& data, const execplan::CalpontSystemCatalog::ColType& ctype) const { return true; }
bool checkCheck( const WriteEngine::IdxTuple& data, const execplan::CalpontSystemCatalog::ColType& ctype) const
{
return true;
}
bool isUnique() { return ddlpackage::DDL_PRIMARY_KEY == fConstraint || ddlpackage::DDL_UNIQUE == fConstraint; }
bool isUnique()
{
return ddlpackage::DDL_PRIMARY_KEY == fConstraint || ddlpackage::DDL_UNIQUE == fConstraint;
}
/** @brief logs error and message
*
* Updates result with message and sets it to CREATE_ERROR
*/
void logError(const std::string& msg, int error = 0);
void logError(const std::string& msg, int error = 0);
bool compareToken(const WriteEngine::Token& first, const WriteEngine::Token& second) const
{
return (first.op == second.op && first.fbo == second.fbo && first.spare == second.spare);
}
return (first.op == second.op && first.fbo == second.fbo && first.spare == second.spare);
}
WriteEngine::WriteEngineWrapper* fWriteEngine;
execplan::SessionManager* fSessionManager;
@ -251,8 +273,8 @@ public:
DDLPackageProcessor::IndexOID fIdxOID;
ddlpackage::ColumnNameList fColNames;
ddlpackage::QualifiedName fTable;
DDLPackageProcessor::DebugLevel fDebugLevel;
joblist::DistributedEngineComm* fEC;
DDLPackageProcessor::DebugLevel fDebugLevel;
joblist::DistributedEngineComm* fEC;
WriteEngine::RIDList fRidList;
WriteEngine::IdxStructList fIdxStructList;
WriteEngine::IdxValueList fIdxValueList;
@ -265,16 +287,16 @@ public:
struct DDLNullValueForType : DDLPackageProcessor
{
DDLNullValueForType(const execplan::CalpontSystemCatalog::ColType& ctype)
: DDLPackageProcessor(), fType(ctype) {}
boost::any operator()(execplan::CalpontSystemCatalog::ColType& ctype)
{
return getNullValueForType(fType);
}
const execplan::CalpontSystemCatalog::ColType& fType;
DDLNullValueForType(const execplan::CalpontSystemCatalog::ColType& ctype)
: DDLPackageProcessor(), fType(ctype) {}
boost::any operator()(execplan::CalpontSystemCatalog::ColType& ctype)
{
return getNullValueForType(fType);
}
const execplan::CalpontSystemCatalog::ColType& fType;
};
};
}
#endif //DDLPINDEXPOPULATOR_H

File diff suppressed because it is too large Load Diff

View File

@ -88,26 +88,28 @@ public:
*/
enum ResultCode { NO_ERROR, CREATE_ERROR, ALTER_ERROR, DROP_ERROR, TRUNC_ERROR,
TOKENIZATION_ERROR, NOT_ACCEPTING_PACKAGES, PK_NOTNULL_ERROR, WARNING, USER_ERROR, NETWORK_ERROR, PARTITION_WARNING,
WARN_NO_PARTITION};
WARN_NO_PARTITION
};
enum DebugLevel { /** @brief Debug level type enumeration */
enum DebugLevel /** @brief Debug level type enumeration */
{
NONE = 0, /** @brief No debug info */
SUMMARY = 1, /** @brief Summary level debug info */
DETAIL = 2, /** @brief A little detail debug info */
VERBOSE = 3, /** @brief Detailed debug info */
};
enum LogFileType { DROPTABLE_LOG, DROPPART_LOG, TRUNCATE_LOG};
typedef std::vector<execplan::CalpontSystemCatalog::OID> OidList;
typedef std::set<BRM::LogicalPartition> PartitionNums;
struct LogInfo
{
LogFileType fileType;
OidList oids;
PartitionNums partitionNums;
};
typedef std::map<execplan::CalpontSystemCatalog::OID, LogInfo> TableLogInfo;
enum LogFileType { DROPTABLE_LOG, DROPPART_LOG, TRUNCATE_LOG};
typedef std::vector<execplan::CalpontSystemCatalog::OID> OidList;
typedef std::set<BRM::LogicalPartition> PartitionNums;
struct LogInfo
{
LogFileType fileType;
OidList oids;
PartitionNums partitionNums;
};
typedef std::map<execplan::CalpontSystemCatalog::OID, LogInfo> TableLogInfo;
/** @brief the result of dml operations
*/
struct DDLResult
@ -153,95 +155,124 @@ public:
int dictOID;
int listOID;
int treeOID;
int colWidth;
int compressionType;
int colWidth;
int compressionType;
};
/** @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
EXPORT 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
EXPORT Date( )
{
year = 0xFFFF;
month = 0xF;
day = 0x3F;
spare = 0x3E;
}
};
/*
struct Date
{
int year : 16;
int month : 4;
int day : 6;
int spare : 6;
Date( ) { year = 0; month = 0; day = 0; spare = 0;}
}; */
/*
struct Date
{
int year : 16;
int month : 4;
int day : 6;
int spare : 6;
Date( ) { year = 0; month = 0; day = 0; spare = 0;}
}; */
/** @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
EXPORT 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
EXPORT dateTime( )
{
year = 0xFFFF;
month = 0xF;
day = 0x3F;
hour = 0x3F;
minute = 0x3F;
second = 0x3F;
msecond = 0xFFFFE;
}
};
/*
struct dateTime
{
int year : 16;
int month : 4;
int day : 6;
int hour : 6;
int minute : 6;
int second : 6;
int msecond : 20;
dateTime( ) { year = 0; month = 0; day = 0; hour = 0; minute = 0; second = 0; msecond = 0; }
}
; */
/*
struct dateTime
{
int year : 16;
int month : 4;
int day : 6;
int hour : 6;
int minute : 6;
int second : 6;
int msecond : 20;
dateTime( ) { year = 0; month = 0; day = 0; hour = 0; minute = 0; second = 0; msecond = 0; }
}
; */
/** @brief a vector of dictionary object ids
*/
typedef std::vector<DictOID> DictionaryOIDList;
/** the type of a list of ColumnResult as returned from getSysData
*/
typedef std::vector <execplan::ColumnResult*> NJLSysDataVector;
struct NJLSysDataList
{
NJLSysDataVector sysDataVec;
EXPORT NJLSysDataList(){};
EXPORT NJLSysDataList() {};
EXPORT ~NJLSysDataList();
NJLSysDataVector::const_iterator begin() {return sysDataVec.begin();}
NJLSysDataVector::const_iterator end() {return sysDataVec.end();}
void push_back(execplan::ColumnResult* cr) {sysDataVec.push_back(cr);}
unsigned int size() {return static_cast<unsigned int>(sysDataVec.size());}
int findColumn(const execplan::CalpontSystemCatalog::OID& columnOID)
{
for(uint32_t i = 0; i < sysDataVec.size(); i++) {
if(sysDataVec[i]->ColumnOID() == columnOID) {
return i;
}
}
return -1;
}
NJLSysDataVector::const_iterator begin()
{
return sysDataVec.begin();
}
NJLSysDataVector::const_iterator end()
{
return sysDataVec.end();
}
void push_back(execplan::ColumnResult* cr)
{
sysDataVec.push_back(cr);
}
unsigned int size()
{
return static_cast<unsigned int>(sysDataVec.size());
}
int findColumn(const execplan::CalpontSystemCatalog::OID& columnOID)
{
for (uint32_t i = 0; i < sysDataVec.size(); i++)
{
if (sysDataVec[i]->ColumnOID() == columnOID)
{
return i;
}
}
return -1;
}
};
/** @brief constructor
*/
DDLPackageProcessor(BRM::DBRM* aDbrm) : fStartingColOID(0), fDDLLoggingId(23), fDebugLevel( NONE )
{
fWEClient = new WriteEngine::WEClients(WriteEngine::WEClients::DDLPROC);
fPMCount = fWEClient->getPmCount();
fDbrm = aDbrm;
//std::cout << "in DDLPackageProcessor constructor " << this << std::endl;
}
{
fWEClient = new WriteEngine::WEClients(WriteEngine::WEClients::DDLPROC);
fPMCount = fWEClient->getPmCount();
fDbrm = aDbrm;
//std::cout << "in DDLPackageProcessor constructor " << this << std::endl;
}
/** @brief destructor
*/
@ -250,56 +281,77 @@ public:
/** @brief Is it required to debug
*/
const bool isDebug( const DebugLevel level ) const { return level <= fDebugLevel; }
const bool isDebug( const DebugLevel level ) const
{
return level <= fDebugLevel;
}
/** @brief Get debug level
*/
const DebugLevel getDebugLevel() const { return fDebugLevel; }
const DebugLevel getDebugLevel() const
{
return fDebugLevel;
}
/** @brief Set debug level
*/
void setDebugLevel( const DebugLevel level ) { fDebugLevel = level; }
void setDebugLevel( const DebugLevel level )
{
fDebugLevel = level;
}
/** @brief Get index oid that was allocated during index creation
*/
IndexOID getIndexOID() const { return fIdxOID; }
IndexOID getIndexOID() const
{
return fIdxOID;
}
/** @brief Get starting column oid that was allocated during table
* creation.
*/
int getStartingColumnOID() const { return fStartingColOID; }
/** @brief access and mutator of fPKName */
const std::string PKName() const {return fPKName;}
void PKName (const std::string PKName) {fPKName = PKName;}
/** @brief Flush primproc cache for associated lbids.
*
* @param oidList the list of OIDs for
* which the lbids for those files will be removed
*/
EXPORT void flushPrimprocCache( std::vector<execplan::CalpontSystemCatalog::OID>& oidList );
/** @brief remove the physical files
*
* @param txnID the transaction id
* @param oidList the list of OIDs for
* which the files should be removed
*/
EXPORT void removeFiles(const uint64_t uniqueId, std::vector<execplan::CalpontSystemCatalog::OID>& oidList);
EXPORT void createFiles(execplan::CalpontSystemCatalog::TableName aTableName, const int useDBRoot, const uint64_t uniqueId, const uint32_t numOids);
/** @brief remove the physical files for the specified partition
*
* @param oidList the list of OIDs for
* which the files should be removed
* @param partition number
*/
EXPORT void removePartitionFiles(std::vector<execplan::CalpontSystemCatalog::OID>& oidList,
const PartitionNums& partitions,
uint64_t uniqueId);
int getStartingColumnOID() const
{
return fStartingColOID;
}
/** @brief remove the extents from extent map
/** @brief access and mutator of fPKName */
const std::string PKName() const
{
return fPKName;
}
void PKName (const std::string PKName)
{
fPKName = PKName;
}
/** @brief Flush primproc cache for associated lbids.
*
* @param oidList the list of OIDs for
* which the lbids for those files will be removed
*/
EXPORT void flushPrimprocCache( std::vector<execplan::CalpontSystemCatalog::OID>& oidList );
/** @brief remove the physical files
*
* @param txnID the transaction id
* @param oidList the list of OIDs for
* which the files should be removed
*/
EXPORT void removeFiles(const uint64_t uniqueId, std::vector<execplan::CalpontSystemCatalog::OID>& oidList);
EXPORT void createFiles(execplan::CalpontSystemCatalog::TableName aTableName, const int useDBRoot, const uint64_t uniqueId, const uint32_t numOids);
/** @brief remove the physical files for the specified partition
*
* @param oidList the list of OIDs for
* which the files should be removed
* @param partition number
*/
EXPORT void removePartitionFiles(std::vector<execplan::CalpontSystemCatalog::OID>& oidList,
const PartitionNums& partitions,
uint64_t uniqueId);
/** @brief remove the extents from extent map
*
* @param txnID the transaction id
* @param result the result of the operation
@ -309,47 +361,47 @@ public:
EXPORT void removeExtents(std::vector<execplan::CalpontSystemCatalog::OID>& oidList);
/** @brief create and open log file to log a table information
*
* @param tableOid the oid of the table
* @param tableName the shcema, table name
*/
EXPORT void createWriteDropLogFile(execplan::CalpontSystemCatalog::OID tableOid,
uint64_t uniqueId, std::vector<execplan::CalpontSystemCatalog::OID>& oidList);
/** @brief create and open log file to log a table information
*
* @param tableOid the oid of the table
* @param tableName the shcema, table name
*/
EXPORT void createWriteDropLogFile(execplan::CalpontSystemCatalog::OID tableOid,
uint64_t uniqueId, std::vector<execplan::CalpontSystemCatalog::OID>& oidList);
/** @brief create and open log file to log a table partition information
/** @brief create and open log file to log a table partition information
*
* @param tableOid the oid of the table
* @param tableName the shcema, table name
* @param partition the partition number to be dropped
* @param tableName the shcema, table name
* @param partition the partition number to be dropped
*/
EXPORT void createWritePartitionLogFile(execplan::CalpontSystemCatalog::OID tableOid,
const PartitionNums& partitionNums,
std::vector<execplan::CalpontSystemCatalog::OID>& oidList,
uint64_t uniqueId);
EXPORT void createWritePartitionLogFile(execplan::CalpontSystemCatalog::OID tableOid,
const PartitionNums& partitionNums,
std::vector<execplan::CalpontSystemCatalog::OID>& oidList,
uint64_t uniqueId);
// EXPORT void createOpenTruncateTableLogFile(execplan::CalpontSystemCatalog::OID tableOid, execplan::CalpontSystemCatalog::TableName tableName);
/** @brief create and open log file to log a truncae table information
/** @brief create and open log file to log a truncae table information
*
* @param tableOid the oid of the table
* @param tableName the shcema, table name
* @param tableName the shcema, table name
*/
EXPORT void createWriteTruncateTableLogFile(execplan::CalpontSystemCatalog::OID tableOid, uint64_t uniqueId, std::vector<execplan::CalpontSystemCatalog::OID>& oidList);
/** @brief delete log file
*
/** @brief delete log file
*
*/
EXPORT void deleteLogFile(LogFileType fileType, execplan::CalpontSystemCatalog::OID tableOid, uint64_t uniqueId);
/** @brief fetch log file infomation
*
*/
EXPORT void fetchLogFile(TableLogInfo & tableLogInfos, uint64_t uniqueId);
BRM::TxnID fTxnid;
/** @brief fetch log file infomation
*
*/
EXPORT void fetchLogFile(TableLogInfo& tableLogInfos, uint64_t uniqueId);
BRM::TxnID fTxnid;
protected:
/** @brief get a list of DDLColumns for the given schema.table
*
@ -357,8 +409,8 @@ protected:
* @param table the table name
* @param colList will contain the list of columns on return
*/
EXPORT void getColumnsForTable( uint32_t sessionID, std::string schema,std::string table,
ColumnList& colList );
EXPORT void getColumnsForTable( uint32_t sessionID, std::string schema, std::string table,
ColumnList& colList );
/** @brief convert parsed ddl data type to a system catalog data type
*
@ -407,7 +459,7 @@ protected:
* @param schema the schema the table belongs to
* @param table the name of the table
* @param constraintNumber the constraint number
* @param type the constraint type
* @param type the constraint type
*/
std::string buildTableConstraintName(int oid,
ddlpackage::DDL_CONSTRAINTS type);
@ -417,7 +469,7 @@ protected:
* @param schema the schema the table belongs to
* @param table the name of the table
* @param column the column name
* @param type the constraint type
* @param type the constraint type
*/
std::string buildColumnConstraintName(const std::string& schema,
const std::string& table,
@ -452,19 +504,19 @@ protected:
* @param constraintList the table constrain list
* @param qualifiedName the name of catalog, schema, object names
*/
// void writeTableSysConstraintMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::TableConstraintDefList& constraintList, ddlpackage::QualifiedName&
// qualifiedName, bool alterFlag=false );
// void writeTableSysConstraintMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::TableConstraintDefList& constraintList, ddlpackage::QualifiedName&
// qualifiedName, bool alterFlag=false );
/** @brief write the table constraint meta data to the SYSCONSTRAINTCOL table
*
*
* @param txnID the transaction id
* @param result the result of the operation
* @param constraintList the table constrain list
* @param qualifiedName the name of catalog, schema, object names
*/
// void writeTableSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
// const DDLResult& result, ddlpackage::TableConstraintDefList& constraintList,
// ddlpackage::QualifiedName& qualifiedName, bool alterFlag=false );
// void writeTableSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
// const DDLResult& result, ddlpackage::TableConstraintDefList& constraintList,
// ddlpackage::QualifiedName& qualifiedName, bool alterFlag=false );
/** @brief write the column constraint meta data to the SYSCONTRAINT table
*
@ -485,7 +537,7 @@ protected:
*/
// void writeColumnSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
// const DDLResult& result, ddlpackage::ColumnDefList& tableDefCols,
// ddlpackage::QualifiedName& qualifiedName);
// ddlpackage::QualifiedName& qualifiedName);
/** @brief write the index meta data to the SYSINDEX table
@ -496,10 +548,10 @@ protected:
* @param consDef the table constraint
* @param indexName name of the index
*/
// void writeSysIndexMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, const DDLResult& result,
// ddlpackage::QualifiedName& qualifiedName,
// ddlpackage::DDL_CONSTRAINTS type,
// std::string& indexName, bool multicol, bool alterFlag=false);
// void writeSysIndexMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, const DDLResult& result,
// ddlpackage::QualifiedName& qualifiedName,
// ddlpackage::DDL_CONSTRAINTS type,
// std::string& indexName, bool multicol, bool alterFlag=false);
/** @brief write the index meta data to the SYSINDEXCOL table
*
@ -509,10 +561,10 @@ protected:
* @param constraintCols the list of columns in this index
* @param indexName name of the index
*/
// void writeSysIndexColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, const DDLResult& result,
// void writeSysIndexColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, const DDLResult& result,
//ddlpackage::QualifiedName& qualifiedName,
// ddlpackage::ColumnNameList& constraintCols,
// std::string& indexName, bool alterFlag=false);
// ddlpackage::ColumnNameList& constraintCols,
// std::string& indexName, bool alterFlag=false);
/** @brief remove all indexes for the supplied table from the SYSINDEX table
*
@ -521,7 +573,7 @@ protected:
* @param tableName the qualified name of the table
*/
//void removeSysIndexMetaDataForTable(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
// DDLResult& result, ddlpackage::QualifiedName& tableName);
// DDLResult& result, ddlpackage::QualifiedName& tableName);
/** @brief remove all index columns for the supplied table from the SYSINDEXCOL table
*
@ -529,8 +581,8 @@ protected:
* @param result the result of the operation
* @param tableName the qualified name of the table
*/
// void removeSysIndexColMetaDataForTable(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
// DDLResult& result, ddlpackage::QualifiedName& tableName);
// void removeSysIndexColMetaDataForTable(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
// DDLResult& result, ddlpackage::QualifiedName& tableName);
/** @brief remove an index from the SYSINDEX table
*
@ -538,7 +590,7 @@ protected:
* @param result the result of the operation
* @param indexName the qualified name of the index
*/
// void removeSysIndexMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// void removeSysIndexMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& indexName);
/** @brief remove index columns from the SYSINDEXCOL table
@ -547,8 +599,8 @@ protected:
* @param result the result of the operation
* @param indexName the qualified name of the index
*/
// void removeSysIndexColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& indexName);
// void removeSysIndexColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& indexName);
/** @brief remove the table meta data from the SYSTABLE table
*
@ -556,29 +608,29 @@ protected:
* @param result the result of the operation
* @param tableName the qualified name of the table to remove
*/
// void removeSysTableMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& tableName);
// void removeSysTableMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& tableName);
/** @brief remove the column meta data from the SYSCOLUMN table
*
* @param txnID the transaction id
* @param result the result of the operation
* @param tableName the qualified name of the table whose columns
* @param tableName the qualified name of the table whose columns
* are to be removed
*/
// void removeSysColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& tableName);
// void removeSysColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& tableName);
/** @brief remove the column meta data from the SYSCOLUMN table
*
* @param txnID the transaction id
* @param result the result of the operation
* @param columnInfo the qualified name of the column
* @param columnInfo the qualified name of the column
* to be removed
*/
// void removeColSysColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& columnInfo);
// void removeColSysColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& columnInfo);
/** @brief remove the constraint meta data from the SYSCONSTRAINT table
*
* @param txnID the transaction id
@ -586,18 +638,18 @@ protected:
* @param tableName the qualified name of the table whose constraints
* are to be removed
*/
// void removeSysContraintMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& tableName);
// void removeSysContraintMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& tableName);
/** @brief remove the constraint meta data from the SYSCONSTRAINT table
*
* @param txnID the transaction id
* @param result the result of the operation
* @param indexName the index name to be removed
*/
// void removeSysIndexMetaDataForIndex(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
// DDLResult& result,
// execplan::CalpontSystemCatalog::IndexNameList& indexNameList);
*/
// void removeSysIndexMetaDataForIndex(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
// DDLResult& result,
// execplan::CalpontSystemCatalog::IndexNameList& indexNameList);
/** @brief remove the column constraint meta data from the SYSCONSTRAINTCOL table
*
@ -606,19 +658,19 @@ protected:
* @param tableName the qualified name of the table whose column constraints
* are to be removed
*/
// void removeSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& tableName);
/** @brief remove the column constraint meta data from the SYSCONSTRAINT table
*
* @param txnID the transaction id
* @param result the result of the operation
* @param constrintNames the names of the constraints
* are to be removed
*/
#if 0
// void removeSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
// ddlpackage::QualifiedName& tableName);
/** @brief remove the column constraint meta data from the SYSCONSTRAINT table
*
* @param txnID the transaction id
* @param result the result of the operation
* @param constrintNames the names of the constraints
* are to be removed
*/
#if 0
void removeSysContraintMetaDataForConstraint(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
DDLResult& result,
execplan::CalpontSystemCatalog::IndexNameList& constrintNames);
DDLResult& result,
execplan::CalpontSystemCatalog::IndexNameList& constrintNames);
/** @brief remove the column constraint meta data from the SYSCONSTRAINTCOL table
*
* @param txnID the transaction id
@ -627,10 +679,10 @@ protected:
* are to be removed
*/
void removeColSysConstraintColMetaData(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::QualifiedName& columnInfo);
ddlpackage::QualifiedName& columnInfo);
/** @brief create the physical dictionary files
*
*
* @param txnID the transaction id
* @param result the result of the operation
*/
@ -643,7 +695,7 @@ protected:
* @param tableDefCols the table column definition list
*/
void createColumnFiles(execplan::CalpontSystemCatalog::SCN txnID, const DDLResult& result,
ddlpackage::ColumnDefList& tableDefCols, const int useDBRoot, const uint32_t partitionNum=0);
ddlpackage::ColumnDefList& tableDefCols, const int useDBRoot, const uint32_t partitionNum = 0);
/** @brief update the SYSCOLUMN table
*
@ -651,12 +703,12 @@ protected:
* @param result the result of the operation
* @param ridList the list of OIDs for
* which the column file should be removed
*/
*/
void updateSyscolumns( execplan::CalpontSystemCatalog::SCN txnID,
DDLResult& result, WriteEngine::RIDList& ridList,
WriteEngine::ColValueList& colValuesList,
WriteEngine::ColValueList& colOldValuesList);
DDLResult& result, WriteEngine::RIDList& ridList,
WriteEngine::ColValueList& colValuesList,
WriteEngine::ColValueList& colOldValuesList);
/** @brief remove the physical index files
*
* @param txnID the transaction id
@ -666,7 +718,7 @@ protected:
*/
void removeIndexFiles(execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
execplan::CalpontSystemCatalog::IndexOIDList& idxOIDList);
#endif
#endif
/** @brief return the OIDs used by the database objects
*
@ -705,7 +757,7 @@ protected:
*/
void removeRowFromSysCatalog(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, const DDLResult& result,
ddlpackage::QualifiedName& sysCatalogTableName, WriteEngine::RID& rid);
/** @brief validate reference constraint for altering existing table
*
* @param sessionID session ID
@ -713,12 +765,12 @@ protected:
* @param tcn the column which has the foreign key constraint
* @param refIndexName the index name of the referenced primary key constraint
* @return true if violation
*/
bool referenceConstraintViolation(uint32_t sessionID,
*/
bool referenceConstraintViolation(uint32_t sessionID,
DDLResult& result,
execplan::CalpontSystemCatalog::TableColName tcn,
execplan::CalpontSystemCatalog::TableColName tcn,
execplan::CalpontSystemCatalog::IndexName refIndexName);
/** @brief validate PK constraint (not null part) for altering existing table
*
* @param sessionID session ID
@ -727,7 +779,7 @@ protected:
* @param constraintCols the columns associated with the primary key
* @return true if violation
*/
bool PKConstraintViolation(uint32_t sessionID,
bool PKConstraintViolation(uint32_t sessionID,
DDLResult& result,
ddlpackage::QualifiedName& qualifiedName,
ddlpackage::ColumnNameList& constraintCols);
@ -738,13 +790,13 @@ protected:
* @param qualifiedName schema.table name
* @param checkConstraint the constraint text string
* @return true if violation
*/
bool checkConstraintViolation(uint32_t sessionID,
DDLResult& result,
ddlpackage::QualifiedName& qualifiedName,
std::string& checkConstraint);
*/
bool checkConstraintViolation(uint32_t sessionID,
DDLResult& result,
ddlpackage::QualifiedName& qualifiedName,
std::string& checkConstraint);
/** @brief remove the supplied rows from the supplied system catalog table
*
* @param result the result of the operation
@ -757,12 +809,12 @@ protected:
WriteEngine::WriteEngineWrapper fWriteEngine;
BRM::DBRM* fDbrm;
BRM::DBRM* fDbrm;
execplan::SessionManager fSessionManager;
uint32_t fPMCount;
WriteEngine::WEClients* fWEClient;
uint32_t fPMCount;
WriteEngine::WEClients* fWEClient;
DictionaryOIDList fDictionaryOIDList;
@ -773,49 +825,49 @@ protected:
int fStartingColOID;
int fColumnNum;
IndexOID fIdxOID;
std::ofstream fDDLLogFile;
std::string fDDLLogFileName;
std::ofstream fDDLLogFile;
std::string fDDLLogFileName;
std::string fPKName; // primary key name supplied by Oracle. Oracle will issue
// two separate DDL statements for a create table with primary
// key DDL, with the 1st one being create index and the 2nd
// one being create table. This PK name will be stored here
// when creatindexprocessor gets the create index statement. This
// is to make sure Calpont use the same system primary key name as Oracle
// two separate DDL statements for a create table with primary
// key DDL, with the 1st one being create index and the 2nd
// one being create table. This PK name will be stored here
// when creatindexprocessor gets the create index statement. This
// is to make sure Calpont use the same system primary key name as Oracle
unsigned const fDDLLoggingId;
//std::ofstream fDDLLogFile;
//std::string fDDLLogFileName;
/** @brief convert absolute rid to relative rid in a segement file
//std::ofstream fDDLLogFile;
//std::string fDDLLogFileName;
/** @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
* @param filesPerColumnPartition,extentRows, extentsPerSegmentFile the extent map parameters
* @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);
int rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID);
int commitTransaction(uint64_t uniqueId, BRM::TxnID txnID);
// MCOL-66 The DBRM can't handle concurrent DDL
* @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);
int rollBackTransaction(uint64_t uniqueId, BRM::TxnID txnID, uint32_t sessionID);
int commitTransaction(uint64_t uniqueId, BRM::TxnID txnID);
// MCOL-66 The DBRM can't handle concurrent DDL
static boost::mutex dbrmMutex;
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);
//std::string fDDLLogFileName;
//std::string fDDLLogFileName;
DebugLevel fDebugLevel; // internal use debug level
};
/** @brief helper template function to do safe from string to type conversions
*
@ -823,7 +875,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

@ -28,30 +28,31 @@
using namespace ddlpackage;
namespace ddlpackageprocessor {
namespace ddlpackageprocessor
{
DDLPackageProcessor* DDLPackageProcessorFactory::
makePackageProcessor(int packageType, ddlpackage::CalpontDDLPackage& cpackage)
{
DDLPackageProcessor* ddlProcPtr = 0;
DDLPackageProcessor* ddlProcPtr = 0;
switch( packageType )
{
case DDL_CREATE:
ddlProcPtr = new CreatePackageProcessor();
break;
case DDL_ALTER:
ddlProcPtr = new AlterPackageProcessor();
break;
switch ( packageType )
{
case DDL_CREATE:
ddlProcPtr = new CreatePackageProcessor();
break;
case DDL_DROP:
ddlProcPtr = new DropPackageProcessor();
break;
case DDL_ALTER:
ddlProcPtr = new AlterPackageProcessor();
break;
}
case DDL_DROP:
ddlProcPtr = new DropPackageProcessor();
break;
return ddlProcPtr;
}
return ddlProcPtr;
}
} // namespace ddlpackageprocessor

View File

@ -28,28 +28,30 @@
#include "ddlpackageprocessor.h"
namespace ddlpackageprocessor {
namespace ddlpackageprocessor
{
/** @brief create a ddlPackageProcessor object from a CalpontddlPackage object
*
*/
class DDLPackageProcessorFactory {
class DDLPackageProcessorFactory
{
public:
/** @brief static ddlPackageProcessor constructor method
*
* @param packageType the ddl Package type
* @param cpackage the CalpontddlPackage from which the ddlPackageProcessor is constructed
*/
static DDLPackageProcessor*
makePackageProcessor( int packageType, ddlpackage::CalpontDDLPackage& cpackage );
/** @brief static ddlPackageProcessor constructor method
*
* @param packageType the ddl Package type
* @param cpackage the CalpontddlPackage from which the ddlPackageProcessor is constructed
*/
static DDLPackageProcessor*
makePackageProcessor( int packageType, ddlpackage::CalpontDDLPackage& cpackage );
protected:
private:
};
}
}
#endif //DDLPACKAGEPROCESSORFACTORY_H

View File

@ -39,9 +39,9 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
CalpontSystemCatalog::IndexOID indexOID;
BRM::TxnID txnID;
txnID.id= fTxnid.id;
txnID.valid= fTxnid.valid;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
DDLResult result;
result.result = NO_ERROR;
@ -49,17 +49,18 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
VERBOSE_INFO(dropIndexStmt);
SQLLogger logger(dropIndexStmt.fSql, fDDLLoggingId, dropIndexStmt.fSessionID, txnID.id);
SQLLogger logger(dropIndexStmt.fSql, fDDLLoggingId, dropIndexStmt.fSessionID, txnID.id);
indexName.schema = dropIndexStmt.fIndexName->fSchema;
indexName.schema = dropIndexStmt.fIndexName->fSchema;
indexName.index = dropIndexStmt.fIndexName->fName;
//Look up table name from indexname. Oracle will error out if same constraintname or indexname exists.
CalpontSystemCatalog::TableName tableName = sysCatalogPtr->lookupTableForIndex (dropIndexStmt.fIndexName->fName, dropIndexStmt.fIndexName->fSchema );
indexName.table = tableName.table;
indexOID = sysCatalogPtr->lookupIndexNbr(indexName);
VERBOSE_INFO("Removing the SYSINDEX meta data");
removeSysIndexMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName);
if (result.result != NO_ERROR)
{
DETAIL_INFO("writeSysIndexMetaData failed");
@ -68,6 +69,7 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
VERBOSE_INFO("Removing the SYSINDEXCOL meta data");
removeSysIndexColMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName);
if (result.result != NO_ERROR)
{
DETAIL_INFO("writeSysIndexMetaData failed");
@ -76,7 +78,8 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
VERBOSE_INFO("Removing the index files");
err = fWriteEngine.dropIndex(txnID.id, indexOID.objnum,indexOID.listOID);
err = fWriteEngine.dropIndex(txnID.id, indexOID.objnum, indexOID.listOID);
if (err)
{
DETAIL_INFO("WriteEngine dropIndex failed");
@ -88,11 +91,13 @@ DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::Dro
// register the changes
err = fWriteEngine.commit( txnID.id );
if (err)
{
DETAIL_INFO("Failed to commit the drop index transaction");
goto rollback;
}
fSessionManager.committed(txnID);
//fObjectIDManager.returnOID(indexOID.objnum);
//fObjectIDManager.returnOID(indexOID.listOID);

View File

@ -28,24 +28,24 @@
namespace ddlpackageprocessor
{
/** @brief specialization of a DDLPacakageProcessor
* for interaction with the Write Engine to process
* drop index statements.
/** @brief specialization of a DDLPacakageProcessor
* for interaction with the Write Engine to process
* drop index statements.
*/
class DropIndexProcessor : public DDLPackageProcessor
{
public:
/** @brief process a drop index statement
*
* @param dropIndexStmt the drop index statement
*/
class DropIndexProcessor : public DDLPackageProcessor
{
public:
/** @brief process a drop index statement
*
* @param dropIndexStmt the drop index statement
*/
DDLResult processPackage(ddlpackage::DropIndexStatement& dropIndexStmt);
DDLResult processPackage(ddlpackage::DropIndexStatement& dropIndexStmt);
protected:
protected:
private:
private:
};
};
} //namespace ddlpackageprocessor
#endif //DROPINDEXPROCESSOR_H

View File

@ -38,316 +38,343 @@ using namespace oam;
namespace ddlpackageprocessor
{
DropPartitionProcessor::DDLResult DropPartitionProcessor::processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt)
{
SUMMARY_INFO("DropPartitionProcessor::processPackage");
DropPartitionProcessor::DDLResult DropPartitionProcessor::processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt)
{
SUMMARY_INFO("DropPartitionProcessor::processPackage");
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(dropPartitionStmt);
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(dropPartitionStmt);
// Commit current transaction.
// all DDL statements cause an implicit commit
VERBOSE_INFO("Getting current txnID");
int rc = 0;
rc = fDbrm->isReadWrite();
BRM::TxnID txnID;
txnID.id= fTxnid.id;
txnID.valid= fTxnid.valid;
if (rc != 0 )
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
// Commit current transaction.
// all DDL statements cause an implicit commit
VERBOSE_INFO("Getting current txnID");
std::vector <CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
execplan::CalpontSystemCatalog::ROPair roPair;
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = dropPartitionStmt.fSessionID;
std::string processName("DDLProc");
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 = ALTER_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 = ALTER_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
string stmt = dropPartitionStmt.fSql + "|" + dropPartitionStmt.fTableName->fSchema +"|";
SQLLogger logger(stmt, fDDLLoggingId, sessionID, txnID.id);
int rc = 0;
rc = fDbrm->isReadWrite();
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
try
{
//check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(dropPartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(dropPartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = dropPartitionStmt.fTableName->fSchema;
tableName.table = dropPartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 )
{
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
int i = 0;
processID = ::getpid();
oam::OamCache * oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
for (unsigned i=0; i < pmList.size(); i++)
{
pms.push_back((uint32_t)pmList[i]);
}
try {
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
// no need to release lock. dbrm un-hold the lock
fSessionManager.rolledback(txnID);
return result;
}
if ( uniqueID == 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;
if (rc != 0 )
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
rm_ts.tv_sec = sleepTime/1000;
rm_ts.tv_nsec = sleepTime%1000 *1000000;
for (; i < numTries; i++)
{
std::vector <CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
execplan::CalpontSystemCatalog::ROPair roPair;
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = dropPartitionStmt.fSessionID;
std::string processName("DDLProc");
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 = ALTER_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 = ALTER_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
string stmt = dropPartitionStmt.fSql + "|" + dropPartitionStmt.fTableName->fSchema + "|";
SQLLogger logger(stmt, fDDLLoggingId, sessionID, txnID.id);
try
{
//check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(dropPartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(dropPartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = dropPartitionStmt.fTableName->fSchema;
tableName.table = dropPartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 )
{
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
int i = 0;
processID = ::getpid();
oam::OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
for (unsigned i = 0; i < pmList.size(); i++)
{
pms.push_back((uint32_t)pmList[i]);
}
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
// no need to release lock. dbrm un-hold the lock
fSessionManager.rolledback(txnID);
return result;
}
if ( uniqueID == 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
// reset
sessionID = dropPartitionStmt.fSessionID;
txnID.id= fTxnid.id;
txnID.valid= fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
// reset
sessionID = dropPartitionStmt.fSessionID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
if (uniqueID > 0)
break;
}
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if (i >= numTries) //error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
string strOp("drop partition");
args.add(strOp);
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
fSessionManager.rolledback(txnID);
return result;
}
}
if (uniqueID > 0)
break;
}
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Disable the extents from extentmap for the partition
// 5. Remove the column and dictionary files for the partition
// 6. Flush PrimProc Cache
// 7. Remove the extents from extentmap for the partition
if (i >= numTries) //error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
string strOp("drop partition");
args.add(strOp);
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
fSessionManager.rolledback(txnID);
return result;
}
}
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = dropPartitionStmt.fTableName->fSchema;
userTableName.table = dropPartitionStmt.fTableName->fName;
tableColRidList = systemCatalogPtr->columnRIDs( userTableName );
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Disable the extents from extentmap for the partition
// 5. Remove the column and dictionary files for the partition
// 6. Flush PrimProc Cache
// 7. Remove the extents from extentmap for the partition
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for ( unsigned i=0; i < tableColRidList.size(); i++ )
{
if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum );
}
for ( unsigned i=0; i < dictOIDList.size(); i++ )
{
if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID );
}
//Mark the partition disabled from extent map
string emsg;
rc = fDbrm->markPartitionForDeletion( oidList, dropPartitionStmt.fPartitions, emsg);
if (rc != 0 && rc !=BRM::ERR_PARTITION_DISABLED &&
rc != BRM::ERR_INVALID_OP_LAST_PARTITION &&
rc != BRM::ERR_NOT_EXIST_PARTITION)
{
throw std::runtime_error(emsg);
}
set<BRM::LogicalPartition> markedPartitions;
set<BRM::LogicalPartition> outOfServicePartitions;
// only log partitions that are successfully marked disabled.
rc = fDbrm->getOutOfServicePartitions(oidList[0], outOfServicePartitions);
if (rc != 0)
{
string errorMsg;
BRM::errString(rc, errorMsg);
ostringstream oss;
oss << "getOutOfServicePartitions failed due to " << errorMsg;
throw std::runtime_error(oss.str());
}
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = dropPartitionStmt.fTableName->fSchema;
userTableName.table = dropPartitionStmt.fTableName->fName;
set<BRM::LogicalPartition>::iterator it;
for (it = dropPartitionStmt.fPartitions.begin(); it != dropPartitionStmt.fPartitions.end(); ++it)
{
if (outOfServicePartitions.find(*it) != outOfServicePartitions.end())
markedPartitions.insert(*it);
}
//Save the oids to a file
createWritePartitionLogFile( roPair.objnum, markedPartitions, oidList, uniqueId);
tableColRidList = systemCatalogPtr->columnRIDs( userTableName );
VERBOSE_INFO("Removing files");
removePartitionFiles( oidList, markedPartitions, uniqueId );
//Flush PrimProc cache for those lbids
rc = cacheutils::flushPartition( oidList, markedPartitions );
//Remove the partition from extent map
emsg.clear();
rc = fDbrm->deletePartition( oidList, dropPartitionStmt.fPartitions, emsg);
if ( rc != 0 )
throw std::runtime_error(emsg);
}
catch (exception& ex)
{
cerr << "DropPartitionProcessor::processPackage: " << ex.what() << endl;
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
logging::Message::Args args;
logging::Message message(ex.what());
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for ( unsigned i = 0; i < tableColRidList.size(); i++ )
{
if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum );
}
if (rc == BRM::ERR_TABLE_NOT_LOCKED)
result.result = USER_ERROR;
else if (rc == BRM::ERR_NOT_EXIST_PARTITION || rc == BRM::ERR_INVALID_OP_LAST_PARTITION)
result.result = PARTITION_WARNING;
else if (rc == BRM::ERR_NO_PARTITION_PERFORMED)
result.result = WARN_NO_PARTITION;
else
result.result = DROP_ERROR;
result.message = message;
try {
fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
cerr << "DropPartitionProcessor::processPackage: caught unknown exception!" << endl;
for ( unsigned i = 0; i < dictOIDList.size(); i++ )
{
if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID );
}
logging::Message::Args args;
logging::Message message(1);
args.add("Drop partition failed: ");
args.add( "encountered unkown exception" );
args.add("");
args.add("");
message.format( args );
result.result = DROP_ERROR;
result.message = message;
try {
fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(dropPartitionStmt.fSessionID, txnID.id, dropPartitionStmt.fSql, dropPartitionStmt.fOwner);
//Remove the log file
//release the transaction
try {
fDbrm->releaseTableLock(uniqueID);
deleteLogFile(DROPPART_LOG, roPair.objnum, uniqueId);
} catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
return result;
}
//Mark the partition disabled from extent map
string emsg;
rc = fDbrm->markPartitionForDeletion( oidList, dropPartitionStmt.fPartitions, emsg);
if (rc != 0 && rc != BRM::ERR_PARTITION_DISABLED &&
rc != BRM::ERR_INVALID_OP_LAST_PARTITION &&
rc != BRM::ERR_NOT_EXIST_PARTITION)
{
throw std::runtime_error(emsg);
}
set<BRM::LogicalPartition> markedPartitions;
set<BRM::LogicalPartition> outOfServicePartitions;
// only log partitions that are successfully marked disabled.
rc = fDbrm->getOutOfServicePartitions(oidList[0], outOfServicePartitions);
if (rc != 0)
{
string errorMsg;
BRM::errString(rc, errorMsg);
ostringstream oss;
oss << "getOutOfServicePartitions failed due to " << errorMsg;
throw std::runtime_error(oss.str());
}
set<BRM::LogicalPartition>::iterator it;
for (it = dropPartitionStmt.fPartitions.begin(); it != dropPartitionStmt.fPartitions.end(); ++it)
{
if (outOfServicePartitions.find(*it) != outOfServicePartitions.end())
markedPartitions.insert(*it);
}
//Save the oids to a file
createWritePartitionLogFile( roPair.objnum, markedPartitions, oidList, uniqueId);
VERBOSE_INFO("Removing files");
removePartitionFiles( oidList, markedPartitions, uniqueId );
//Flush PrimProc cache for those lbids
rc = cacheutils::flushPartition( oidList, markedPartitions );
//Remove the partition from extent map
emsg.clear();
rc = fDbrm->deletePartition( oidList, dropPartitionStmt.fPartitions, emsg);
if ( rc != 0 )
throw std::runtime_error(emsg);
}
catch (exception& ex)
{
cerr << "DropPartitionProcessor::processPackage: " << ex.what() << endl;
logging::Message::Args args;
logging::Message message(ex.what());
if (rc == BRM::ERR_TABLE_NOT_LOCKED)
result.result = USER_ERROR;
else if (rc == BRM::ERR_NOT_EXIST_PARTITION || rc == BRM::ERR_INVALID_OP_LAST_PARTITION)
result.result = PARTITION_WARNING;
else if (rc == BRM::ERR_NO_PARTITION_PERFORMED)
result.result = WARN_NO_PARTITION;
else
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
cerr << "DropPartitionProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Drop partition failed: ");
args.add( "encountered unkown exception" );
args.add("");
args.add("");
message.format( args );
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(dropPartitionStmt.fSessionID, txnID.id, dropPartitionStmt.fSql, dropPartitionStmt.fOwner);
//Remove the log file
//release the transaction
try
{
fDbrm->releaseTableLock(uniqueID);
deleteLogFile(DROPPART_LOG, roPair.objnum, uniqueId);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
return result;
}
}

View File

@ -34,25 +34,25 @@
namespace ddlpackageprocessor
{
/** @brief specialization of a DDLPacakageProcessor
* for interacting with the Write Engine to process
* drop table ddl statements.
/** @brief specialization of a DDLPacakageProcessor
* for interacting with the Write Engine to process
* drop table ddl statements.
*/
class DropPartitionProcessor : public DDLPackageProcessor
{
public:
DropPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
class DropPartitionProcessor : public DDLPackageProcessor
{
public:
DropPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
EXPORT DDLResult processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt);
EXPORT DDLResult processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt);
protected:
protected:
private:
private:
};
};
} // namespace ddlpackageprocessor
#undef EXPORT

File diff suppressed because it is too large Load Diff

View File

@ -34,45 +34,45 @@
namespace ddlpackageprocessor
{
/** @brief specialization of a DDLPacakageProcessor
* for interacting with the Write Engine to process
* drop table ddl statements.
/** @brief specialization of a DDLPacakageProcessor
* for interacting with the Write Engine to process
* drop table ddl statements.
*/
class DropTableProcessor : public DDLPackageProcessor
{
public:
DropTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
class DropTableProcessor : public DDLPackageProcessor
{
public:
DropTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
EXPORT DDLResult processPackage(ddlpackage::DropTableStatement& dropTableStmt);
EXPORT DDLResult processPackage(ddlpackage::DropTableStatement& dropTableStmt);
protected:
protected:
private:
private:
};
};
/** @brief specialization of a DDLPacakageProcessor
* for interacting with the Write Engine to process
* truncate table ddl statements.
/** @brief specialization of a DDLPacakageProcessor
* for interacting with the Write Engine to process
* truncate table ddl statements.
*/
class TruncTableProcessor : public DDLPackageProcessor
{
public:
TruncTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a truncate table statement
*
* @param truncTableStmt the truncate table statement
*/
class TruncTableProcessor : public DDLPackageProcessor
{
public:
TruncTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
/** @brief process a truncate table statement
*
* @param truncTableStmt the truncate table statement
*/
EXPORT DDLResult processPackage(ddlpackage::TruncTableStatement& truncTableStmt);
EXPORT DDLResult processPackage(ddlpackage::TruncTableStatement& truncTableStmt);
protected:
protected:
private:
private:
};
};
} // namespace ddlpackageprocessor

View File

@ -37,237 +37,261 @@ namespace ddlpackageprocessor
MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpackage::MarkPartitionStatement& markPartitionStmt)
{
SUMMARY_INFO("RestorePartitionProcessor::processPackage");
SUMMARY_INFO("RestorePartitionProcessor::processPackage");
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(markPartitionStmt);
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(markPartitionStmt);
BRM::TxnID txnID;
txnID.id= fTxnid.id;
txnID.valid= fTxnid.valid;
int rc = 0;
rc = fDbrm->isReadWrite();
if (rc != 0 )
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
std::vector <CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
std::string processName("DDLProc");
string stmt = markPartitionStmt.fSql + "|" + markPartitionStmt.fTableName->fSchema +"|";
SQLLogger logger(stmt, fDDLLoggingId, markPartitionStmt.fSessionID, txnID.id);
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = markPartitionStmt.fSessionID;
execplan::CalpontSystemCatalog::ROPair roPair;
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
try
{
//check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(markPartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(markPartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = markPartitionStmt.fTableName->fSchema;
tableName.table = markPartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 )
{
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
int i = 0;
processID = ::getpid();
oam::OamCache * oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
for (unsigned i=0; i < pmList.size(); i++)
{
pms.push_back((uint32_t)pmList[i]);
}
try {
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if ( uniqueID == 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;
int rc = 0;
rc = fDbrm->isReadWrite();
rm_ts.tv_sec = sleepTime/1000;
rm_ts.tv_nsec = sleepTime%1000 *1000000;
if (rc != 0 )
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
for (; i < numTries; i++)
{
std::vector <CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
std::string processName("DDLProc");
string stmt = markPartitionStmt.fSql + "|" + markPartitionStmt.fTableName->fSchema + "|";
SQLLogger logger(stmt, fDDLLoggingId, markPartitionStmt.fSessionID, txnID.id);
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = markPartitionStmt.fSessionID;
execplan::CalpontSystemCatalog::ROPair roPair;
try
{
//check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(markPartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(markPartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = markPartitionStmt.fTableName->fSchema;
tableName.table = markPartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 )
{
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
int i = 0;
processID = ::getpid();
oam::OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
for (unsigned i = 0; i < pmList.size(); i++)
{
pms.push_back((uint32_t)pmList[i]);
}
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if ( uniqueID == 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
// reset
sessionID = markPartitionStmt.fSessionID;
txnID.id= fTxnid.id;
txnID.valid= fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
// reset
sessionID = markPartitionStmt.fSessionID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
try {
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if (uniqueID > 0)
break;
}
if (uniqueID > 0)
break;
}
if (i >= numTries) //error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
fSessionManager.rolledback(txnID);
return result;
}
}
if (i >= numTries) //error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
fSessionManager.rolledback(txnID);
return result;
}
}
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Remove the extents from extentmap
// 5. Flush PrimProc Cache
// 6. Remove the column and dictionary files for the partition
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Remove the extents from extentmap
// 5. Flush PrimProc Cache
// 6. Remove the column and dictionary files for the partition
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = markPartitionStmt.fTableName->fSchema;
userTableName.table = markPartitionStmt.fTableName->fName;
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = markPartitionStmt.fTableName->fSchema;
userTableName.table = markPartitionStmt.fTableName->fName;
tableColRidList = systemCatalogPtr->columnRIDs( userTableName );
tableColRidList = systemCatalogPtr->columnRIDs( userTableName );
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for ( unsigned i=0; i < tableColRidList.size(); i++ )
{
if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum );
}
for ( unsigned i=0; i < dictOIDList.size(); i++ )
{
if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID );
}
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for ( unsigned i = 0; i < tableColRidList.size(); i++ )
{
if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum );
}
//Remove the partition from extent map
string emsg;
rc = fDbrm->markPartitionForDeletion( oidList, markPartitionStmt.fPartitions, emsg);
if ( rc != 0 )
{
throw std::runtime_error(emsg);
}
}
catch (exception& ex)
{
logging::Message::Args args;
logging::Message message(ex.what());
for ( unsigned i = 0; i < dictOIDList.size(); i++ )
{
if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID );
}
if (rc == BRM::ERR_TABLE_NOT_LOCKED)
result.result = USER_ERROR;
else if (rc == BRM::ERR_PARTITION_DISABLED || rc == BRM::ERR_INVALID_OP_LAST_PARTITION ||
rc == BRM::ERR_NOT_EXIST_PARTITION)
result.result = PARTITION_WARNING;
else if (rc == BRM::ERR_NO_PARTITION_PERFORMED)
result.result = WARN_NO_PARTITION;
else
result.result = DROP_ERROR;
result.message = message;
try {
fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
//cerr << "MarkPartitionProcessor::processPackage: caught unknown exception!" << endl;
//Remove the partition from extent map
string emsg;
rc = fDbrm->markPartitionForDeletion( oidList, markPartitionStmt.fPartitions, emsg);
logging::Message::Args args;
logging::Message message(1);
args.add("Disable partition failed: ");
args.add( "encountered unkown exception" );
args.add("");
args.add("");
message.format( args );
if ( rc != 0 )
{
throw std::runtime_error(emsg);
}
}
catch (exception& ex)
{
logging::Message::Args args;
logging::Message message(ex.what());
result.result = DROP_ERROR;
result.message = message;
try {
fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(markPartitionStmt.fSessionID, 0, markPartitionStmt.fSql, markPartitionStmt.fOwner);
try {
fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
return result;
if (rc == BRM::ERR_TABLE_NOT_LOCKED)
result.result = USER_ERROR;
else if (rc == BRM::ERR_PARTITION_DISABLED || rc == BRM::ERR_INVALID_OP_LAST_PARTITION ||
rc == BRM::ERR_NOT_EXIST_PARTITION)
result.result = PARTITION_WARNING;
else if (rc == BRM::ERR_NO_PARTITION_PERFORMED)
result.result = WARN_NO_PARTITION;
else
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
//cerr << "MarkPartitionProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Disable partition failed: ");
args.add( "encountered unkown exception" );
args.add("");
args.add("");
message.format( args );
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(markPartitionStmt.fSessionID, 0, markPartitionStmt.fSql, markPartitionStmt.fOwner);
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
return result;
}
}

View File

@ -42,7 +42,7 @@ namespace ddlpackageprocessor
class MarkPartitionProcessor : public DDLPackageProcessor
{
public:
MarkPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
MarkPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a create table statement
*
* @param createTableStmt the CreateTableStatement
@ -50,7 +50,7 @@ public:
EXPORT DDLResult processPackage(ddlpackage::MarkPartitionStatement& MarkPartitionStmt);
protected:
private:

View File

@ -62,532 +62,543 @@ class PopulateIndexTest
{
public:
PopulateIndexTest(DistributedEngineComm* ec) : fEC(ec) { }
DistributedEngineComm *fEC;
PopulateIndexTest(DistributedEngineComm* ec) : fEC(ec) { }
DistributedEngineComm* fEC;
void test_createindex()
{
cout << "Begining create index test ... " << endl;
std::string sqlbuf = "CREATE INDEX test1_idx ON tpch.nation (n_nationkey)";
cout << sqlbuf << endl;
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl;
cout << ptree.fSqlText << endl;
try
{
CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result;
DISPLAY(stmt.fSessionID);
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
{
throw;
}
}
}
void test_createuniqueindex()
{
cout << "Begining create unique index test ..." << endl;
std::string sqlbuf = "CREATE UNIQUE INDEX test2_idx ON tpch.nation (n_name)";
cout << sqlbuf << endl;
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl;
try
{
CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
{
throw;
}
}
}
void test_createindextest(std::string& sqlbuf)
{
cout << "Begining create index test ..." << endl;
cout << sqlbuf << endl;
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl;
try
{
CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
{
throw;
}
}
}
void test_createtabletest(const string& sqlbuf)
void test_createindex()
{
cout << "Begining create table test: " << sqlbuf << endl;
cout << "Begining create index test ... " << endl;
std::string sqlbuf = "CREATE INDEX test1_idx ON tpch.nation (n_nationkey)";
cout << sqlbuf << endl;
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl;
const ParseTree& ptree = parser.GetParseTree();
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl;
cout << ptree.fSqlText << endl;
try
{
CreateTableProcessor processor;
processor.setDebugLevel(CreateTableProcessor::VERBOSE);
CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement& stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result;
DISPLAY(stmt.fSessionID);
SqlStatement &stmt = *ptree.fList[0];
CreateTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
result = processor.processPackage(dynamic_cast<CreateTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
throw;
}
}
}
void test_altertable_addtableconstraint(std::string& sqlbuf)
{
cout << "Begining Alter Table add table constraint test ... " << endl;
cout << sqlbuf << endl;
void test_createuniqueindex()
{
cout << "Begining create unique index test ..." << endl;
std::string sqlbuf = "CREATE UNIQUE INDEX test2_idx ON tpch.nation (n_name)";
cout << sqlbuf << endl;
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl;
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlParser parser;
parser.Parse(sqlbuf.c_str());
SqlStatement &stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
{
throw;
}
}
}
if (parser.Good())
{
const ParseTree& ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl;
void test_altertable_addtablenullconstraint()
{
try
{
CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement& stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch (...)
{
throw;
}
}
}
void test_createindextest(std::string& sqlbuf)
{
cout << "Begining create index test ..." << endl;
cout << sqlbuf << endl;
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree& ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl;
try
{
CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement& stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch (...)
{
throw;
}
}
}
void test_createtabletest(const string& sqlbuf)
{
cout << "Begining create table test: " << sqlbuf << endl;
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree& ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl;
try
{
CreateTableProcessor processor;
processor.setDebugLevel(CreateTableProcessor::VERBOSE);
SqlStatement& stmt = *ptree.fList[0];
CreateTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch (...)
{
throw;
}
}
}
void test_altertable_addtableconstraint(std::string& sqlbuf)
{
cout << "Begining Alter Table add table constraint test ... " << endl;
cout << sqlbuf << endl;
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree& ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl;
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch (...)
{
throw;
}
}
}
void test_altertable_addtablenullconstraint()
{
//sql syntax error? (Does not build index test.)
cout << "Begining Alter Table add table not null constraint test ... " << endl;
std::string sqlbuf = "ALTER TABLE tpch.region add CONSTRAINT not null(r_regionkey);";
cout << sqlbuf << endl;
cout << "Begining Alter Table add table not null constraint test ... " << endl;
std::string sqlbuf = "ALTER TABLE tpch.region add CONSTRAINT not null(r_regionkey);";
cout << sqlbuf << endl;
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl;
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlParser parser;
parser.Parse(sqlbuf.c_str());
SqlStatement &stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
if (parser.Good())
{
const ParseTree& ptree = parser.GetParseTree();
cout << ptree.fSqlText << endl;
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch (...)
{
throw;
}
}
}
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
{
throw;
}
}
}
};
int main( int argc, char **argv)
int main( int argc, char** argv)
{
int DoAll = 0;
int Do1 = 0;
int Do2 = 0;
int Do3 = 0;
int Do4 = 0;
int Do5 = 0;
int Do6 = 0;
int Do7 = 0;
int Do8 = 0;
int Do9 = 0;
int Do10 = 0;
int Do11 = 0;
int Do12 = 0;
int Do13 = 0;
int Do14 = 0;
int Do15 = 0;
int Do16 = 0;
int Do17 = 0;
int Do18 = 0;
int Do19 = 0;
int Do20 = 0;
int Do21 = 0;
int Do22 = 0;
int Do23 = 0;
int Do24 = 0;
int Do25 = 0;
int Do26 = 0;
int Do27 = 0;
int Do28 = 0;
int Do29 = 0;
int Do30 = 0;
int Do31 = 0;
int Do32 = 0;
int Do33 = 0;
int Do34 = 0;
int Do35 = 0;
int Do36 = 0;
cout << "Driver Test starting with " << argc << " parameters." << endl;
int DoAll = 0;
int Do1 = 0;
int Do2 = 0;
int Do3 = 0;
int Do4 = 0;
int Do5 = 0;
int Do6 = 0;
int Do7 = 0;
int Do8 = 0;
int Do9 = 0;
int Do10 = 0;
int Do11 = 0;
int Do12 = 0;
int Do13 = 0;
int Do14 = 0;
int Do15 = 0;
int Do16 = 0;
int Do17 = 0;
int Do18 = 0;
int Do19 = 0;
int Do20 = 0;
int Do21 = 0;
int Do22 = 0;
int Do23 = 0;
int Do24 = 0;
int Do25 = 0;
int Do26 = 0;
int Do27 = 0;
int Do28 = 0;
int Do29 = 0;
int Do30 = 0;
int Do31 = 0;
int Do32 = 0;
int Do33 = 0;
int Do34 = 0;
int Do35 = 0;
int Do36 = 0;
for (int i=0; i<argc; i++)
cout << "Driver Test starting with " << argc << " parameters." << endl;
for (int i = 0; i < argc; i++)
{
cout << "Arg " << i << ": " << argv[i] << endl;
cout << "Arg " << i << ": " << argv[i] << endl;
}
if (argc > 1)
if (argc > 1)
{
if (strcmp(argv[1],"All") == 0) DoAll = 1;
else if (strcmp(argv[1],"t1") == 0) Do1 = 1;
else if (strcmp(argv[1],"t2") == 0) Do2 = 1;
else if (strcmp(argv[1],"t3") == 0) Do3 = 1;
else if (strcmp(argv[1],"t4") == 0) Do4 = 1;
else if (strcmp(argv[1],"t5") == 0) Do5 = 1;
else if (strcmp(argv[1],"t6") == 0) Do6 = 1;
else if (strcmp(argv[1],"t7") == 0) Do7 = 1;
else if (strcmp(argv[1],"t8") == 0) Do8 = 1;
else if (strcmp(argv[1],"t9") == 0) Do9 = 1;
else if (strcmp(argv[1],"t10") == 0) Do10 = 1;
else if (strcmp(argv[1],"t11") == 0) Do11= 1;
else if (strcmp(argv[1],"t12") == 0) Do12= 1;
else if (strcmp(argv[1],"t13") == 0) Do13= 1;
else if (strcmp(argv[1],"t14") == 0) Do14= 1;
else if (strcmp(argv[1],"t15") == 0) Do15= 1;
else if (strcmp(argv[1],"t16") == 0) Do16= 1;
else if (strcmp(argv[1],"t17") == 0) Do17= 1;
else if (strcmp(argv[1],"t18") == 0) Do18= 1;
else if (strcmp(argv[1],"t19") == 0) Do19= 1;
else if (strcmp(argv[1],"t20") == 0) Do20= 1;
else if (strcmp(argv[1],"t21") == 0) Do21= 1;
else if (strcmp(argv[1],"t22") == 0) Do22= 1;
else if (strcmp(argv[1],"t23") == 0) Do23= 1;
else if (strcmp(argv[1],"t24") == 0) Do24= 1;
else if (strcmp(argv[1],"t25") == 0) Do25= 1;
else if (strcmp(argv[1],"t26") == 0) Do26= 1;
else if (strcmp(argv[1],"t27") == 0) Do27= 1;
else if (strcmp(argv[1],"t28") == 0) Do28= 1;
else if (strcmp(argv[1],"t29") == 0) Do29= 1;
else if (strcmp(argv[1],"t30") == 0) Do30= 1;
else if (strcmp(argv[1],"t31") == 0) Do31= 1;
else if (strcmp(argv[1],"t32") == 0) Do32= 1;
else if (strcmp(argv[1],"t33") == 0) Do33= 1;
else if (strcmp(argv[1],"t34") == 0) Do34= 1;
else if (strcmp(argv[1],"t35") == 0) Do35= 1;
else if (strcmp(argv[1],"t36") == 0) Do35= 1;
if (strcmp(argv[1], "All") == 0) DoAll = 1;
else if (strcmp(argv[1], "t1") == 0) Do1 = 1;
else if (strcmp(argv[1], "t2") == 0) Do2 = 1;
else if (strcmp(argv[1], "t3") == 0) Do3 = 1;
else if (strcmp(argv[1], "t4") == 0) Do4 = 1;
else if (strcmp(argv[1], "t5") == 0) Do5 = 1;
else if (strcmp(argv[1], "t6") == 0) Do6 = 1;
else if (strcmp(argv[1], "t7") == 0) Do7 = 1;
else if (strcmp(argv[1], "t8") == 0) Do8 = 1;
else if (strcmp(argv[1], "t9") == 0) Do9 = 1;
else if (strcmp(argv[1], "t10") == 0) Do10 = 1;
else if (strcmp(argv[1], "t11") == 0) Do11 = 1;
else if (strcmp(argv[1], "t12") == 0) Do12 = 1;
else if (strcmp(argv[1], "t13") == 0) Do13 = 1;
else if (strcmp(argv[1], "t14") == 0) Do14 = 1;
else if (strcmp(argv[1], "t15") == 0) Do15 = 1;
else if (strcmp(argv[1], "t16") == 0) Do16 = 1;
else if (strcmp(argv[1], "t17") == 0) Do17 = 1;
else if (strcmp(argv[1], "t18") == 0) Do18 = 1;
else if (strcmp(argv[1], "t19") == 0) Do19 = 1;
else if (strcmp(argv[1], "t20") == 0) Do20 = 1;
else if (strcmp(argv[1], "t21") == 0) Do21 = 1;
else if (strcmp(argv[1], "t22") == 0) Do22 = 1;
else if (strcmp(argv[1], "t23") == 0) Do23 = 1;
else if (strcmp(argv[1], "t24") == 0) Do24 = 1;
else if (strcmp(argv[1], "t25") == 0) Do25 = 1;
else if (strcmp(argv[1], "t26") == 0) Do26 = 1;
else if (strcmp(argv[1], "t27") == 0) Do27 = 1;
else if (strcmp(argv[1], "t28") == 0) Do28 = 1;
else if (strcmp(argv[1], "t29") == 0) Do29 = 1;
else if (strcmp(argv[1], "t30") == 0) Do30 = 1;
else if (strcmp(argv[1], "t31") == 0) Do31 = 1;
else if (strcmp(argv[1], "t32") == 0) Do32 = 1;
else if (strcmp(argv[1], "t33") == 0) Do33 = 1;
else if (strcmp(argv[1], "t34") == 0) Do34 = 1;
else if (strcmp(argv[1], "t35") == 0) Do35 = 1;
else if (strcmp(argv[1], "t36") == 0) Do35 = 1;
}
PopulateIndexTest pit(DistributedEngineComm::instance());
boost::timer theTimer;
if (DoAll)
PopulateIndexTest pit(DistributedEngineComm::instance());
boost::timer theTimer;
if (DoAll)
{
cout << "Starting all tests" << endl;
pit.test_createindex();
pit.test_createuniqueindex();
std::string altsql = "ALTER TABLE tpch.region add CONSTRAINT test1_cstr unique(r_name);";
pit.test_altertable_addtableconstraint(altsql);
pit.test_altertable_addtablenullconstraint();
cout << "Finished all tests" << endl;
cout << "Starting all tests" << endl;
pit.test_createindex();
pit.test_createuniqueindex();
std::string altsql = "ALTER TABLE tpch.region add CONSTRAINT test1_cstr unique(r_name);";
pit.test_altertable_addtableconstraint(altsql);
pit.test_altertable_addtablenullconstraint();
cout << "Finished all tests" << endl;
}
else if (Do1)
{
pit.test_createindex();
cout << "Finished create index test" << endl;
}
else if (Do2)
{
pit.test_createuniqueindex();
cout << "Finished create unique index test" << endl;
}
else if (Do3)
else if (Do1)
{
std::string sqlbuf = "ALTER TABLE tpch.region add CONSTRAINT test1r5_cstr unique(r_name);";
pit.test_altertable_addtableconstraint(sqlbuf);
cout << "Finished add table constraint test" << endl;
pit.test_createindex();
cout << "Finished create index test" << endl;
}
else if (Do4)
else if (Do2)
{
std::string sql("CREATE INDEX test4_idx ON tpch.part (p_size)");
pit.test_createindextest(sql);
cout << "Finished " << sql << endl;
pit.test_createuniqueindex();
cout << "Finished create unique index test" << endl;
}
else if (Do5)
else if (Do3)
{
std::string sql("CREATE INDEX test5_idx ON tpch.part (p_name)");
pit.test_createindextest(sql);
cout << "Finished " << sql << endl;
std::string sqlbuf = "ALTER TABLE tpch.region add CONSTRAINT test1r5_cstr unique(r_name);";
pit.test_altertable_addtableconstraint(sqlbuf);
cout << "Finished add table constraint test" << endl;
}
else if (Do6)
else if (Do4)
{
std::string sql("CREATE INDEX test6_idx ON tpch.orders (o_orderkey, o_custkey)");
pit.test_createindextest(sql);
cout << "Finished " << sql << endl;
std::string sql("CREATE INDEX test4_idx ON tpch.part (p_size)");
pit.test_createindextest(sql);
cout << "Finished " << sql << endl;
}
else if (Do7)
else if (Do5)
{
std::string sqlbuf = "ALTER TABLE tpch.supplier add CONSTRAINT tests2_cstr unique(s_name);";
pit.test_altertable_addtableconstraint(sqlbuf);
cout << "Finished add table constraint test" << endl;
std::string sql("CREATE INDEX test5_idx ON tpch.part (p_name)");
pit.test_createindextest(sql);
cout << "Finished " << sql << endl;
}
else if (Do8)
else if (Do6)
{
std::string sqlbuf = "ALTER TABLE tpch.partsupp add CONSTRAINT testps1_cstr unique(ps_partkey);";
pit.test_altertable_addtableconstraint(sqlbuf);
cout << "Finished add table constraint test: should fail ps_partkey is not unique" << endl;
std::string sql("CREATE INDEX test6_idx ON tpch.orders (o_orderkey, o_custkey)");
pit.test_createindextest(sql);
cout << "Finished " << sql << endl;
}
else if (Do7)
{
std::string sqlbuf = "ALTER TABLE tpch.supplier add CONSTRAINT tests2_cstr unique(s_name);";
pit.test_altertable_addtableconstraint(sqlbuf);
cout << "Finished add table constraint test" << endl;
}
else if (Do8)
{
std::string sqlbuf = "ALTER TABLE tpch.partsupp add CONSTRAINT testps1_cstr unique(ps_partkey);";
pit.test_altertable_addtableconstraint(sqlbuf);
cout << "Finished add table constraint test: should fail ps_partkey is not unique" << endl;
}
else if (Do9)
{
std::string sql("CREATE INDEX test7_idx ON tpch.customer (c_custkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
std::string sql("CREATE INDEX test7_idx ON tpch.customer (c_custkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do10)
{
std::string sql("CREATE INDEX test8_idx ON tpch.supplier(s_phone)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
std::string sql("CREATE INDEX test8_idx ON tpch.supplier(s_phone)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do11)
{
std::string sql("CREATE INDEX test9_idx ON tpch.part (p_retailprice)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
std::string sql("CREATE INDEX test9_idx ON tpch.part (p_retailprice)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do12)
{
std::string sql("CREATE INDEX test10_idx ON tpch.customer (c_acctbal)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
std::string sql("CREATE INDEX test10_idx ON tpch.customer (c_acctbal)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do13)
{
std::string sql("CREATE UNIQUE INDEX test11_idx ON tpch.orders (o_clerk)");
pit.test_createindextest(sql);
cout << "Finished add table index test: should fail" << endl;
std::string sql("CREATE UNIQUE INDEX test11_idx ON tpch.orders (o_clerk)");
pit.test_createindextest(sql);
cout << "Finished add table index test: should fail" << endl;
}
else if (Do14)
{
std::string sql("CREATE INDEX test12_idx ON tpch.lineitem (l_returnflag)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
std::string sql("CREATE INDEX test12_idx ON tpch.lineitem (l_returnflag)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do15)
{
std::string sql("CREATE INDEX test13_idx ON tpch.lineitem (l_linestatus)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
std::string sql("CREATE INDEX test13_idx ON tpch.lineitem (l_linestatus)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do16)
{
std::string sql("CREATE INDEX multi_4idx ON tpch.region (r_regionkey, r_name)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
std::string sql("CREATE INDEX multi_4idx ON tpch.region (r_regionkey, r_name)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do17)
{
std::string sql("CREATE INDEX multi_5idx ON tpch.orders (o_orderkey, o_orderstatus)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
std::string sql("CREATE INDEX multi_5idx ON tpch.orders (o_orderkey, o_orderstatus)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do18)
{
std::string sql("CREATE UNIQUE INDEX orderkey_idx ON tpch.orders (o_orderkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
std::string sql("CREATE UNIQUE INDEX orderkey_idx ON tpch.orders (o_orderkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do19)
{
std::string sql("CREATE UNIQUE INDEX partkey_idx ON tpch.part (p_partkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
std::string sql("CREATE UNIQUE INDEX partkey_idx ON tpch.part (p_partkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do20)
{
std::string sql("CREATE INDEX lorderkey_idx ON tpch.lineitem (l_orderkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
std::string sql("CREATE INDEX lorderkey_idx ON tpch.lineitem (l_orderkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do21)
{
std::string sql("CREATE INDEX lpartkey1_idx ON tpch.lineitem (l_partkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
std::string sql("CREATE INDEX lpartkey1_idx ON tpch.lineitem (l_partkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do22)
{
std::string sql("CREATE INDEX suppkey1_idx ON tpch.lineitem (l_suppkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do23)
std::string sql("CREATE INDEX suppkey1_idx ON tpch.lineitem (l_suppkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do23)
{
std::string sql("CREATE INDEX n_regionkey_id ON tpch.nation (n_regionkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
std::string sql("CREATE INDEX n_regionkey_id ON tpch.nation (n_regionkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do24)
{
std::string sql("CREATE INDEX multi_cust_idx ON tpch.customer (c_name, c_address, c_phone, c_mktsegment)");
pit.test_createindextest(sql);
cout << "Finished add table index test: " << sql << endl;
}
std::string sql("CREATE INDEX multi_cust_idx ON tpch.customer (c_name, c_address, c_phone, c_mktsegment)");
pit.test_createindextest(sql);
cout << "Finished add table index test: " << sql << endl;
}
else if (Do25)
{
std::string sql("CREATE INDEX multi_part_no_idx ON tpch.part (p_name, p_mfgr, p_brand, p_container, p_size)");
pit.test_createindextest(sql);
cout << "Finished add table index test: " << sql << endl;
}
std::string sql("CREATE INDEX multi_part_no_idx ON tpch.part (p_name, p_mfgr, p_brand, p_container, p_size)");
pit.test_createindextest(sql);
cout << "Finished add table index test: " << sql << endl;
}
else if (Do26)
{
std::string sql("CREATE INDEX o_date_idx ON tpch.orders (o_orderdate)");
pit.test_createindextest(sql);
cout << "Finished add table index test: " << sql << endl;
}
std::string sql("CREATE INDEX o_date_idx ON tpch.orders (o_orderdate)");
pit.test_createindextest(sql);
cout << "Finished add table index test: " << sql << endl;
}
else if (Do27)
{
std::string sql("CREATE INDEX multi_order_idx ON tpch.orders (o_orderkey, o_orderstatus, o_orderdate)");
pit.test_createindextest(sql);
cout << "Finished add table index test: " << sql << endl;
}
std::string sql("CREATE INDEX multi_order_idx ON tpch.orders (o_orderkey, o_orderstatus, o_orderdate)");
pit.test_createindextest(sql);
cout << "Finished add table index test: " << sql << endl;
}
else if (Do28)
{
string sql("create table tpch.tablea( c1 integer, c2 char);");
pit.test_createtabletest(sql);
std::string sqlbuf = "ALTER TABLE tpch.tablea add CONSTRAINT tablea_cstr1 unique(c2);";
pit.test_altertable_addtableconstraint(sqlbuf);
cout << "Finished add table constraint test" << endl;
string sql("create table tpch.tablea( c1 integer, c2 char);");
pit.test_createtabletest(sql);
std::string sqlbuf = "ALTER TABLE tpch.tablea add CONSTRAINT tablea_cstr1 unique(c2);";
pit.test_altertable_addtableconstraint(sqlbuf);
cout << "Finished add table constraint test" << endl;
}
}
else if (Do29)
{
std::string sqlbuf = "ALTER TABLE tpch.nation add CONSTRAINT testn1_cstr unique(n_regionkey);";
pit.test_altertable_addtableconstraint(sqlbuf);
cout << "Finished add table constraint test: should fail n_regionkey is not unique" << endl;
}
std::string sqlbuf = "ALTER TABLE tpch.nation add CONSTRAINT testn1_cstr unique(n_regionkey);";
pit.test_altertable_addtableconstraint(sqlbuf);
cout << "Finished add table constraint test: should fail n_regionkey is not unique" << endl;
}
else if (Do30)
{
std::string sql("CREATE UNIQUE INDEX multicstr_1idx ON tpch.region (r_regionkey, r_name)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
std::string sql("CREATE UNIQUE INDEX multicstr_1idx ON tpch.region (r_regionkey, r_name)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do31)
{
std::string sql("CREATE UNIQUE INDEX multicsto_1idx ON tpch.orders (o_orderkey, o_orderstatus)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
std::string sql("CREATE UNIQUE INDEX multicsto_1idx ON tpch.orders (o_orderkey, o_orderstatus)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do32)
{
std::string sql("CREATE UNIQUE INDEX multicstn_1idx ON tpch.nation (n_nationkey, n_regionkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do33)
std::string sql("CREATE UNIQUE INDEX multicstn_1idx ON tpch.nation (n_nationkey, n_regionkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do33)
{
std::string sql("CREATE UNIQUE INDEX multicstps_1idx ON tpch.partsupp (ps_partkey, ps_suppkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do34)
std::string sql("CREATE UNIQUE INDEX multicstps_1idx ON tpch.partsupp (ps_partkey, ps_suppkey)");
pit.test_createindextest(sql);
cout << "Finished add table index test" << endl;
}
else if (Do34)
{
std::string sql("CREATE UNIQUE INDEX multicsto_2idx ON tpch.orders (o_orderstatus, o_orderpriority)");
pit.test_createindextest(sql);
cout << "Finished add table index test: should fail" << endl;
}
std::string sql("CREATE UNIQUE INDEX multicsto_2idx ON tpch.orders (o_orderstatus, o_orderpriority)");
pit.test_createindextest(sql);
cout << "Finished add table index test: should fail" << endl;
}
else if (Do35)
{
std::string sql("ALTER TABLE tpch.nation add CONSTRAINT testn2_cstr unique(n_nationkey);");
pit.test_altertable_addtableconstraint(sql);
cout << "Finished add table constraint test" << endl;
}
std::string sql("ALTER TABLE tpch.nation add CONSTRAINT testn2_cstr unique(n_nationkey);");
pit.test_altertable_addtableconstraint(sql);
cout << "Finished add table constraint test" << endl;
}
else if (Do36)
{
pit.test_altertable_addtablenullconstraint();
cout << "Finished add table not null constraint test" << endl;
}
else
{
cout << "No Test Selected!" << endl << endl;
pit.test_altertable_addtablenullconstraint();
cout << "All" << endl;
cout << "t1" << endl;
cout << "t2" << endl;
cout << "t3" << endl;
cout << "t4" << endl;
cout << endl;
cout << "Finished add table not null constraint test" << endl;
}
else
{
cout << "No Test Selected!" << endl << endl;
cout << "All" << endl;
cout << "t1" << endl;
cout << "t2" << endl;
cout << "t3" << endl;
cout << "t4" << endl;
cout << endl;
}
cout << "Create index test took :" << theTimer.elapsed() << " seconds to complete." << endl;

View File

@ -1,14 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by libddlpackageproc.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 libddlpackageproc.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

@ -35,238 +35,262 @@ using namespace WriteEngine;
namespace ddlpackageprocessor
{
RestorePartitionProcessor::DDLResult RestorePartitionProcessor::processPackage(ddlpackage::RestorePartitionStatement& restorePartitionStmt)
{
SUMMARY_INFO("RestorePartitionProcessor::processPackage");
RestorePartitionProcessor::DDLResult RestorePartitionProcessor::processPackage(ddlpackage::RestorePartitionStatement& restorePartitionStmt)
{
SUMMARY_INFO("RestorePartitionProcessor::processPackage");
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(restorePartitionStmt);
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(restorePartitionStmt);
BRM::TxnID txnID;
txnID.id= fTxnid.id;
txnID.valid= fTxnid.valid;
int rc = 0;
rc = fDbrm->isReadWrite();
if (rc != 0 )
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
std::vector <CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
std::string processName("DDLProc");
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
string stmt = restorePartitionStmt.fSql + "|" + restorePartitionStmt.fTableName->fSchema +"|";
SQLLogger logger(stmt, fDDLLoggingId, restorePartitionStmt.fSessionID, txnID.id);
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = restorePartitionStmt.fSessionID;
execplan::CalpontSystemCatalog::ROPair roPair;
try
{
//check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(restorePartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(restorePartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = restorePartitionStmt.fTableName->fSchema;
tableName.table = restorePartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 )
{
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
int i = 0;
processID = ::getpid();
oam::OamCache * oamcache = oam::OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
for (unsigned i=0; i < pmList.size(); i++)
{
pms.push_back((uint32_t)pmList[i]);
}
try {
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if ( uniqueID == 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++)
{
int rc = 0;
rc = fDbrm->isReadWrite();
if (rc != 0 )
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
std::vector <CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
std::string processName("DDLProc");
string stmt = restorePartitionStmt.fSql + "|" + restorePartitionStmt.fTableName->fSchema + "|";
SQLLogger logger(stmt, fDDLLoggingId, restorePartitionStmt.fSessionID, txnID.id);
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = restorePartitionStmt.fSessionID;
execplan::CalpontSystemCatalog::ROPair roPair;
try
{
//check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(restorePartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(restorePartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = restorePartitionStmt.fTableName->fSchema;
tableName.table = restorePartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 )
{
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
int i = 0;
processID = ::getpid();
oam::OamCache* oamcache = oam::OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
for (unsigned i = 0; i < pmList.size(); i++)
{
pms.push_back((uint32_t)pmList[i]);
}
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if ( uniqueID == 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);
#endif
// reset
sessionID = restorePartitionStmt.fSessionID;
txnID.id= fTxnid.id;
txnID.valid= fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
try {
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if (uniqueID > 0)
break;
}
if (i >= numTries) //error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
string strOp("restore partition");
args.add(strOp);
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED,args));
fSessionManager.rolledback(txnID);
return result;
}
}
struct timespec abs_ts;
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Remove the extents from extentmap
// 5. Flush PrimProc Cache
// 6. Remove the column and dictionary files for the partition
do
{
abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec;
}
while (nanosleep(&abs_ts, &rm_ts) < 0);
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = restorePartitionStmt.fTableName->fSchema;
userTableName.table = restorePartitionStmt.fTableName->fName;
tableColRidList = systemCatalogPtr->columnRIDs( userTableName );
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
#endif
// reset
sessionID = restorePartitionStmt.fSessionID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for ( unsigned i=0; i < tableColRidList.size(); i++ )
{
if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum );
}
for ( unsigned i=0; i < dictOIDList.size(); i++ )
{
if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID );
}
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
//Remove the partition from extent map
string emsg;
rc = fDbrm->restorePartition( oidList, restorePartitionStmt.fPartitions, emsg);
if ( rc != 0 )
{
throw std::runtime_error(emsg);
}
}
catch (exception& ex)
{
logging::Message::Args args;
logging::Message message(ex.what());
if (uniqueID > 0)
break;
}
if (( rc == BRM::ERR_NOT_EXIST_PARTITION) || (rc == BRM::ERR_INVALID_OP_LAST_PARTITION) ||
(rc == BRM::ERR_PARTITION_DISABLED) || (rc == BRM::ERR_TABLE_NOT_LOCKED))
result.result = USER_ERROR;
else if (rc == BRM::ERR_PARTITION_ENABLED)
result.result = PARTITION_WARNING;
else
result.result = DROP_ERROR;
if (i >= numTries) //error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
string strOp("restore partition");
args.add(strOp);
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
fSessionManager.rolledback(txnID);
return result;
}
}
result.message = message;
try {
fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
//cerr << "RestorePartitionProcessor::processPackage: caught unknown exception!" << endl;
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Remove the extents from extentmap
// 5. Flush PrimProc Cache
// 6. Remove the column and dictionary files for the partition
logging::Message::Args args;
logging::Message message(1);
args.add("Enable partition: ");
args.add( "encountered unkown exception" );
args.add("");
args.add("");
message.format( args );
result.result = DROP_ERROR;
result.message = message;
try {
fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(restorePartitionStmt.fSessionID, txnID.id, restorePartitionStmt.fSql, restorePartitionStmt.fOwner);
try {
fDbrm->releaseTableLock(uniqueID);
} catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
return result;
}
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = restorePartitionStmt.fTableName->fSchema;
userTableName.table = restorePartitionStmt.fTableName->fName;
tableColRidList = systemCatalogPtr->columnRIDs( userTableName );
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for ( unsigned i = 0; i < tableColRidList.size(); i++ )
{
if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum );
}
for ( unsigned i = 0; i < dictOIDList.size(); i++ )
{
if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID );
}
//Remove the partition from extent map
string emsg;
rc = fDbrm->restorePartition( oidList, restorePartitionStmt.fPartitions, emsg);
if ( rc != 0 )
{
throw std::runtime_error(emsg);
}
}
catch (exception& ex)
{
logging::Message::Args args;
logging::Message message(ex.what());
if (( rc == BRM::ERR_NOT_EXIST_PARTITION) || (rc == BRM::ERR_INVALID_OP_LAST_PARTITION) ||
(rc == BRM::ERR_PARTITION_DISABLED) || (rc == BRM::ERR_TABLE_NOT_LOCKED))
result.result = USER_ERROR;
else if (rc == BRM::ERR_PARTITION_ENABLED)
result.result = PARTITION_WARNING;
else
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
//cerr << "RestorePartitionProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Enable partition: ");
args.add( "encountered unkown exception" );
args.add("");
args.add("");
message.format( args );
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(restorePartitionStmt.fSessionID, txnID.id, restorePartitionStmt.fSql, restorePartitionStmt.fOwner);
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
return result;
}
}

View File

@ -34,25 +34,25 @@
namespace ddlpackageprocessor
{
/** @brief specialization of a DDLPacakageProcessor
* for interacting with the Write Engine to process
* drop table ddl statements.
/** @brief specialization of a DDLPacakageProcessor
* for interacting with the Write Engine to process
* drop table ddl statements.
*/
class RestorePartitionProcessor : public DDLPackageProcessor
{
public:
RestorePartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
class RestorePartitionProcessor : public DDLPackageProcessor
{
public:
RestorePartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm){}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
EXPORT DDLResult processPackage(ddlpackage::RestorePartitionStatement& RestorePartitionStmt);
EXPORT DDLResult processPackage(ddlpackage::RestorePartitionStatement& RestorePartitionStmt);
protected:
protected:
private:
private:
};
};
} // namespace ddlpackageprocessor
#undef EXPORT

View File

@ -404,60 +404,64 @@ public:
};
void destroySemaphores()
{
key_t semkey;
int sems, err;
void destroySemaphores()
{
key_t semkey;
int sems, err;
semkey = 0x2149bdd2;
sems = semget(semkey, 2, 0666);
if (sems != -1)
semkey = 0x2149bdd2;
sems = semget(semkey, 2, 0666);
if (sems != -1)
{
err = semctl(sems, 0, IPC_RMID);
if (err == -1)
perror("tdriver: semctl");
}
}
void destroyShmseg()
{
key_t shmkey;
int shms, err;
shmkey = 0x2149bdd2;
shms = shmget(shmkey, 0, 0666);
if (shms != -1)
{
err = shmctl(shms, IPC_RMID, NULL);
if (err == -1 && errno != EINVAL)
{
err = semctl(sems, 0, IPC_RMID);
if (err == -1)
perror("tdriver: semctl");
perror("tdriver: shmctl");
return;
}
}
}
void setUp()
{
destroySemaphores();
destroyShmseg();
unlink("/tmp/oidbitmap");
SystemCatalogBuilder::build();
}
void destroyShmseg()
{
key_t shmkey;
int shms, err;
shmkey = 0x2149bdd2;
shms = shmget(shmkey, 0, 0666);
if (shms != -1)
{
err = shmctl(shms, IPC_RMID, NULL);
if (err == -1 && errno != EINVAL)
{
perror("tdriver: shmctl");
return;
}
}
}
void setUp()
{
destroySemaphores();
destroyShmseg();
unlink("/tmp/oidbitmap");
SystemCatalogBuilder::build();
}
void tearDown()
{
destroySemaphores();
destroyShmseg();
unlink("/tmp/oidbitmap");
}
void tearDown()
{
destroySemaphores();
destroyShmseg();
unlink("/tmp/oidbitmap");
}
class DDLPackageProcessorTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(DDLPackageProcessorTest);
/*
CPPUNIT_TEST( test_createtable );
CPPUNIT_TEST( test_createtable_region );
@ -474,10 +478,10 @@ class DDLPackageProcessorTest : public CppUnit::TestFixture
CPPUNIT_TEST( test_altertable_dropcolumns );
CPPUNIT_TEST( test_altertable_addcolumns );
CPPUNIT_TEST( test_altertable_addtableconstraint );
CPPUNIT_TEST( test_altertable_droptableconstraint );
CPPUNIT_TEST( test_altertable_droptableconstraint );
CPPUNIT_TEST( test_altertable_setcolumndefault );
CPPUNIT_TEST( test_altertable_dropcolumndefault );
CPPUNIT_TEST( test_altertable_renametable );
CPPUNIT_TEST( test_altertable_dropcolumndefault );
CPPUNIT_TEST( test_altertable_renametable );
CPPUNIT_TEST( test_dropindex );
CPPUNIT_TEST( test_droptable ); */
@ -492,30 +496,33 @@ public:
*/
void test_createtable_region()
{
cout << "Begining create region table testing..." << endl;
std::string sqlbuf = "create table region( r_regionkey integer NOT NULL, r_name char(25) ,r_comment varchar(152));";
cout << "Begining create region table testing..." << endl;
std::string sqlbuf = "create table region( r_regionkey integer NOT NULL, r_name char(25) ,r_comment varchar(152));";
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
CreateTableProcessor processor;
processor.setDebugLevel(CreateTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
CreateTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
@ -524,36 +531,39 @@ public:
//setUp();
//removeSystemCatalog();
//createSystemCatalog();
cout << "Begining create table testing..." << endl;
std::string sqlbuf = "create table tpch.part( p_partkey integer NOT NULL ,p_name varchar(55) default 'helloworld', p_mfgr char(6), p_brand char(10) , p_type varchar(25) default 'foobar' , p_size integer , p_container char(10) ,p_retailprice integer , p_comment varchar(23), CONSTRAINT PK_PART PRIMARY KEY(p_partkey) )";
cout << "Begining create table testing..." << endl;
std::string sqlbuf = "create table tpch.part( p_partkey integer NOT NULL ,p_name varchar(55) default 'helloworld', p_mfgr char(6), p_brand char(10) , p_type varchar(25) default 'foobar' , p_size integer , p_container char(10) ,p_retailprice integer , p_comment varchar(23), CONSTRAINT PK_PART PRIMARY KEY(p_partkey) )";
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
CreateTableProcessor processor;
processor.setDebugLevel(CreateTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
CreateTableStatement& ct = dynamic_cast<CreateTableStatement&>(stmt);
cout << "Parsed CreateTable:" << endl;
cout << ct << endl;
SqlStatement& stmt = *ptree.fList[0];
CreateTableStatement& ct = dynamic_cast<CreateTableStatement&>(stmt);
cout << "Parsed CreateTable:" << endl;
cout << ct << endl;
CreateTableProcessor::DDLResult result;
result = processor.processPackage(ct);
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
@ -563,86 +573,93 @@ public:
std::string sqlbuf = "CREATE INDEX test_idx ON tpch.part (p_size)";
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
void test_createuniqueindex()
{
cout << "Begining create unique index test ..." << endl;
cout << "Begining create unique index test ..." << endl;
std::string sqlbuf = "CREATE UNIQUE INDEX test_idx ON tpch.part (p_mfgr)";
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
CreateIndexProcessor processor;
processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
CreateIndexProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
void test_altertable_addacolumn()
{
cout << "Begoning Alter Table Add column test ..." << endl;
cout << "Begoning Alter Table Add column test ..." << endl;
std::string sqlbuf = "ALTER TABLE tpch.part ADD COLUMN c3 char(50)";
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
@ -653,56 +670,62 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
void test_altertable_addacolumnunique()
void test_altertable_addacolumnunique()
{
cout << "Begining Alter Table add column with constraint test ..." << endl;
std::string sqlbuf = "ALTER TABLE tpch.part ADD COLUMN c3 char(50) UNIQUE";
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
void test_altertable_dropacolumn()
@ -712,26 +735,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
@ -742,26 +768,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
@ -772,26 +801,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
void test_dropindex()
@ -801,27 +833,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
DropIndexProcessor processor;
processor.setDebugLevel(DropIndexProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
DropIndexProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<DropIndexStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
void test_altertable_renamecolumn()
@ -831,26 +865,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
@ -862,26 +899,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
void test_altertable_addtableconstraint()
@ -891,26 +931,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
@ -921,26 +964,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
@ -951,26 +997,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
void test_altertable_dropcolumndefault()
@ -980,26 +1029,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
@ -1010,26 +1062,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
AlterTableProcessor processor;
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
processor.setDebugLevel(AlterTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
AlterTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
@ -1040,27 +1095,29 @@ public:
SqlParser parser;
parser.Parse(sqlbuf.c_str());
if (parser.Good())
{
const ParseTree &ptree = parser.GetParseTree();
const ParseTree& ptree = parser.GetParseTree();
try
{
DropTableProcessor processor;
processor.setDebugLevel(DropTableProcessor::VERBOSE);
SqlStatement &stmt = *ptree.fList[0];
SqlStatement& stmt = *ptree.fList[0];
DropTableProcessor::DDLResult result;
result = processor.processPackage(dynamic_cast<DropTableStatement&>(stmt));
std::cout << "return: " << result.result << std::endl;
}
catch(...)
catch (...)
{
tearDown();
throw;
}
}
tearDown();
}
@ -1071,12 +1128,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DDLPackageProcessorTest );
#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();
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 );
return (wasSuccessful ? 0 : 1);