1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

clang format apply

This commit is contained in:
Leonid Fedorov
2022-01-21 16:43:49 +00:00
parent 6b6411229f
commit 04752ec546
1376 changed files with 393460 additions and 412662 deletions

View File

@ -28,72 +28,79 @@ using namespace std;
namespace logging
{
ErrorCodes::ErrorCodes(): fErrorCodes(), fPreamble("An unexpected condition within the query caused an internal processing error within Columnstore. Please check the log files for more details. Additional Information: ")
ErrorCodes::ErrorCodes()
: fErrorCodes()
, fPreamble(
"An unexpected condition within the query caused an internal processing error within Columnstore. "
"Please check the log files for more details. Additional Information: ")
{
fErrorCodes[batchPrimitiveStepErr] = "error in BatchPrimitiveStep.";
fErrorCodes[tupleBPSErr] = "error in TupleBPS.";
fErrorCodes[batchPrimitiveStepLargeDataListFileErr] = "error in BatchPrimitiveStep LargeDataList File handling.";
fErrorCodes[bucketReuseStepErr] = "error in BucketReuseStep.";
fErrorCodes[bucketReuseStepLargeDataListFileErr] = "error in bucketReuseStep LargeDataList File handling.";
fErrorCodes[aggregateFilterStepErr] = "error in AggregateFilterStep.";
fErrorCodes[filterStepErr] = "error in FilterStep.";
fErrorCodes[functionStepErr] = "error in FunctionStep.";
fErrorCodes[hashJoinStepErr] = "error in HashJoinStep.";
fErrorCodes[hashJoinStepLargeDataListFileErr] = "error in HashJoinStep LargeDataList File handling.";
fErrorCodes[largeHashJoinErr] = "error in LargeHashJoin.";
fErrorCodes[largeHashJoinLargeDataListFileErr] = "error in LargeHashJoin LargeDataList File handling.";
fErrorCodes[stringHashJoinStepErr] = "error in StringHashJoinStep.";
fErrorCodes[stringHashJoinStepLargeDataListFileErr] = "error in StringHashJoinStep LargeDataList File handling.";
fErrorCodes[tupleHashJoinTooBigErr] = "error in TupleHashJoin: join is too big.";
fErrorCodes[threadResourceErr] = "error in ExeMgr: too many threads on the system.";
fErrorCodes[pDictionaryScanErr] = "error in pDictionaryScan.";
fErrorCodes[pDictionaryScanLargeDataListFileErr] = "error in pDictionaryScan LargeDataList File handling.";
fErrorCodes[pIdxListErr] = "error in pIdxList.";
fErrorCodes[pIdxWalkErr] = "error in pIdxWalk.";
fErrorCodes[pnlJoinErr] = "error in PNLJoinErr.";
fErrorCodes[reduceStepErr] = "error in ReduceStep.";
fErrorCodes[reduceStepLargeDataListFileErr] = "error in ReduceStep LargeDataList File handling.";
fErrorCodes[unionStepErr] = "error in UnionStep.";
fErrorCodes[unionStepLargeDataListFileErr] = "error in UnionStep LargeDataList File handling.";
fErrorCodes[unionStepTooBigErr] = "the union required too much memory.";
fErrorCodes[tupleAggregateStepErr] = "error in TupleAggregateStep.";
fErrorCodes[tupleConstantStepErr] = "error in TupleConstantStep.";
fErrorCodes[tupleHavingStepErr] = "error in TupleHavingStep.";
fErrorCodes[aggregateResourceErr] = "Memory required to perform aggregation exceeds the RowAggregation/MaxMemory setting.";
fErrorCodes[makeJobListErr] = "error in MakeJobList.";
fErrorCodes[aggregateFuncErr] = "unsupported aggregation function.";
fErrorCodes[aggregateDataErr] = "aggregation data overflow.";
fErrorCodes[batchPrimitiveProcessorErr] = "error in BatchPrimitiveProcessor.";
fErrorCodes[bppSeederErr] = "error in bppSeeder.";
fErrorCodes[primitiveServerErr] = "error in PrimitiveServer.";
fErrorCodes[projectResultErr] = "error in BatchPrimitiveProcessor projectResult. Please check crit.log for more details.";
fErrorCodes[hwmRangeSizeErr] = "error in PrimitiveServer load block with HWM. Please check crit.log for more details.";
fErrorCodes[formatErr] = "format mismatch.";
fErrorCodes[dataTypeErr] = "data type unknown.";
fErrorCodes[incompatJoinCols] = "incompatible column types specified for join condition.";
fErrorCodes[incompatFilterCols] = "incompatible column types specified for filter condition.";
fErrorCodes[batchPrimitiveStepErr] = "error in BatchPrimitiveStep.";
fErrorCodes[tupleBPSErr] = "error in TupleBPS.";
fErrorCodes[batchPrimitiveStepLargeDataListFileErr] =
"error in BatchPrimitiveStep LargeDataList File handling.";
fErrorCodes[bucketReuseStepErr] = "error in BucketReuseStep.";
fErrorCodes[bucketReuseStepLargeDataListFileErr] = "error in bucketReuseStep LargeDataList File handling.";
fErrorCodes[aggregateFilterStepErr] = "error in AggregateFilterStep.";
fErrorCodes[filterStepErr] = "error in FilterStep.";
fErrorCodes[functionStepErr] = "error in FunctionStep.";
fErrorCodes[hashJoinStepErr] = "error in HashJoinStep.";
fErrorCodes[hashJoinStepLargeDataListFileErr] = "error in HashJoinStep LargeDataList File handling.";
fErrorCodes[largeHashJoinErr] = "error in LargeHashJoin.";
fErrorCodes[largeHashJoinLargeDataListFileErr] = "error in LargeHashJoin LargeDataList File handling.";
fErrorCodes[stringHashJoinStepErr] = "error in StringHashJoinStep.";
fErrorCodes[stringHashJoinStepLargeDataListFileErr] =
"error in StringHashJoinStep LargeDataList File handling.";
fErrorCodes[tupleHashJoinTooBigErr] = "error in TupleHashJoin: join is too big.";
fErrorCodes[threadResourceErr] = "error in ExeMgr: too many threads on the system.";
fErrorCodes[pDictionaryScanErr] = "error in pDictionaryScan.";
fErrorCodes[pDictionaryScanLargeDataListFileErr] = "error in pDictionaryScan LargeDataList File handling.";
fErrorCodes[pIdxListErr] = "error in pIdxList.";
fErrorCodes[pIdxWalkErr] = "error in pIdxWalk.";
fErrorCodes[pnlJoinErr] = "error in PNLJoinErr.";
fErrorCodes[reduceStepErr] = "error in ReduceStep.";
fErrorCodes[reduceStepLargeDataListFileErr] = "error in ReduceStep LargeDataList File handling.";
fErrorCodes[unionStepErr] = "error in UnionStep.";
fErrorCodes[unionStepLargeDataListFileErr] = "error in UnionStep LargeDataList File handling.";
fErrorCodes[unionStepTooBigErr] = "the union required too much memory.";
fErrorCodes[tupleAggregateStepErr] = "error in TupleAggregateStep.";
fErrorCodes[tupleConstantStepErr] = "error in TupleConstantStep.";
fErrorCodes[tupleHavingStepErr] = "error in TupleHavingStep.";
fErrorCodes[aggregateResourceErr] =
"Memory required to perform aggregation exceeds the RowAggregation/MaxMemory setting.";
fErrorCodes[makeJobListErr] = "error in MakeJobList.";
fErrorCodes[aggregateFuncErr] = "unsupported aggregation function.";
fErrorCodes[aggregateDataErr] = "aggregation data overflow.";
fErrorCodes[batchPrimitiveProcessorErr] = "error in BatchPrimitiveProcessor.";
fErrorCodes[bppSeederErr] = "error in bppSeeder.";
fErrorCodes[primitiveServerErr] = "error in PrimitiveServer.";
fErrorCodes[projectResultErr] =
"error in BatchPrimitiveProcessor projectResult. Please check crit.log for more details.";
fErrorCodes[hwmRangeSizeErr] =
"error in PrimitiveServer load block with HWM. Please check crit.log for more details.";
fErrorCodes[formatErr] = "format mismatch.";
fErrorCodes[dataTypeErr] = "data type unknown.";
fErrorCodes[incompatJoinCols] = "incompatible column types specified for join condition.";
fErrorCodes[incompatFilterCols] = "incompatible column types specified for filter condition.";
}
string ErrorCodes::errorString(uint16_t code) const
{
CodeMap::const_iterator iter;
CodeMap::key_type key = static_cast<CodeMap::key_type>(code);
CodeMap::mapped_type msg;
CodeMap::const_iterator iter;
CodeMap::key_type key = static_cast<CodeMap::key_type>(code);
CodeMap::mapped_type msg;
iter = fErrorCodes.find(key);
iter = fErrorCodes.find(key);
if (iter == fErrorCodes.end())
{
msg = "was an unknown internal error.";
}
else
{
msg = iter->second;
}
if (iter == fErrorCodes.end())
{
msg = "was an unknown internal error.";
}
else
{
msg = iter->second;
}
return (fPreamble + msg);
return (fPreamble + msg);
}
} //namespace logging
} // namespace logging
// vim:ts=4 sw=4:

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: errorcodes.h 3495 2013-01-21 14:09:51Z rdempsey $
*
*
***********************************************************************/
* $Id: errorcodes.h 3495 2013-01-21 14:09:51Z rdempsey $
*
*
***********************************************************************/
/** @file */
#pragma once
@ -30,70 +30,69 @@
namespace logging
{
enum ErrorCodeValues
{
batchPrimitiveStepErr = 1,
tupleBPSErr,
batchPrimitiveStepLargeDataListFileErr,
bucketReuseStepErr,
bucketReuseStepLargeDataListFileErr,
aggregateFilterStepErr,
filterStepErr,
functionStepErr,
hashJoinStepErr,
hashJoinStepLargeDataListFileErr,
largeHashJoinErr,
largeHashJoinLargeDataListFileErr,
stringHashJoinStepErr,
stringHashJoinStepLargeDataListFileErr,
tupleHashJoinTooBigErr,
threadResourceErr,
pDictionaryScanErr,
pDictionaryScanLargeDataListFileErr,
pIdxListErr,
pIdxWalkErr,
pnlJoinErr,
reduceStepErr,
reduceStepLargeDataListFileErr,
unionStepErr,
unionStepLargeDataListFileErr,
unionStepTooBigErr,
tupleAggregateStepErr,
tupleConstantStepErr,
tupleHavingStepErr,
makeJobListErr,
aggregateFuncErr,
aggregateDataErr,
//don't use 100, same as SQL_NOT_FOUND
batchPrimitiveProcessorErr = 101,
bppSeederErr,
primitiveServerErr,
projectResultErr,
hwmRangeSizeErr,
// user input data error
formatErr = 201,
dataTypeErr,
incompatJoinCols,
incompatFilterCols,
aggregateResourceErr,
statisticsJobListEmpty = 301
batchPrimitiveStepErr = 1,
tupleBPSErr,
batchPrimitiveStepLargeDataListFileErr,
bucketReuseStepErr,
bucketReuseStepLargeDataListFileErr,
aggregateFilterStepErr,
filterStepErr,
functionStepErr,
hashJoinStepErr,
hashJoinStepLargeDataListFileErr,
largeHashJoinErr,
largeHashJoinLargeDataListFileErr,
stringHashJoinStepErr,
stringHashJoinStepLargeDataListFileErr,
tupleHashJoinTooBigErr,
threadResourceErr,
pDictionaryScanErr,
pDictionaryScanLargeDataListFileErr,
pIdxListErr,
pIdxWalkErr,
pnlJoinErr,
reduceStepErr,
reduceStepLargeDataListFileErr,
unionStepErr,
unionStepLargeDataListFileErr,
unionStepTooBigErr,
tupleAggregateStepErr,
tupleConstantStepErr,
tupleHavingStepErr,
makeJobListErr,
aggregateFuncErr,
aggregateDataErr,
// don't use 100, same as SQL_NOT_FOUND
batchPrimitiveProcessorErr = 101,
bppSeederErr,
primitiveServerErr,
projectResultErr,
hwmRangeSizeErr,
// user input data error
formatErr = 201,
dataTypeErr,
incompatJoinCols,
incompatFilterCols,
aggregateResourceErr,
statisticsJobListEmpty = 301
};
struct ErrorCodes
{
ErrorCodes();
std::string errorString(uint16_t code) const;
private:
typedef std::map<ErrorCodeValues, std::string> CodeMap;
ErrorCodes();
std::string errorString(uint16_t code) const;
//defaults okay
//ErrorCodes(const ErrorCodes& rhs);
//ErrorCodes& operator=(const ErrorCodes& rhs);
private:
typedef std::map<ErrorCodeValues, std::string> CodeMap;
CodeMap fErrorCodes;
const std::string fPreamble;
// defaults okay
// ErrorCodes(const ErrorCodes& rhs);
// ErrorCodes& operator=(const ErrorCodes& rhs);
CodeMap fErrorCodes;
const std::string fPreamble;
};
}
} // namespace logging

View File

@ -36,121 +36,136 @@
namespace logging
{
/** @brief specific error exception class
*
*
*/
*
*
*/
class IDBExcept : public std::runtime_error
{
public:
IDBExcept(uint16_t code) :
std::runtime_error(IDBErrorInfo::instance()->errorMsg(code)), fErrCode(code) {}
IDBExcept(uint16_t code, const Message::Args& args) :
std::runtime_error(IDBErrorInfo::instance()->errorMsg(code, args)), fErrCode(code) {}
IDBExcept(const std::string& msg, uint16_t code) :
std::runtime_error(msg), fErrCode(code) { }
void errorCode(uint16_t code)
{
fErrCode = code;
}
uint16_t errorCode() const
{
return fErrCode;
}
protected:
unsigned fErrCode;
public:
IDBExcept(uint16_t code) : std::runtime_error(IDBErrorInfo::instance()->errorMsg(code)), fErrCode(code)
{
}
IDBExcept(uint16_t code, const Message::Args& args)
: std::runtime_error(IDBErrorInfo::instance()->errorMsg(code, args)), fErrCode(code)
{
}
IDBExcept(const std::string& msg, uint16_t code) : std::runtime_error(msg), fErrCode(code)
{
}
void errorCode(uint16_t code)
{
fErrCode = code;
}
uint16_t errorCode() const
{
return fErrCode;
}
protected:
unsigned fErrCode;
};
class DictionaryBufferOverflow : public IDBExcept
{
public:
DictionaryBufferOverflow() : IDBExcept(ERR_DICTBUFFER_OVERFLOW)
{ }
public:
DictionaryBufferOverflow() : IDBExcept(ERR_DICTBUFFER_OVERFLOW)
{
}
};
class LargeDataListExcept : public std::runtime_error
{
public:
/** Takes a character string describing the error. */
explicit LargeDataListExcept(const std::string& msg) : std::runtime_error(msg) { }
public:
/** Takes a character string describing the error. */
explicit LargeDataListExcept(const std::string& msg) : std::runtime_error(msg)
{
}
virtual ~LargeDataListExcept() throw() { }
virtual ~LargeDataListExcept() throw()
{
}
};
/** @brief specific error exception class for query data
* @bug 1155
*
*/
* @bug 1155
*
*/
class QueryDataExcept : public IDBExcept
{
public:
/** Takes a character string describing the error. */
QueryDataExcept(const std::string& msg, uint16_t code) :
IDBExcept(msg, code) { }
public:
/** Takes a character string describing the error. */
QueryDataExcept(const std::string& msg, uint16_t code) : IDBExcept(msg, code)
{
}
virtual ~QueryDataExcept() throw() { }
private:
//defaults okay
//QueryDataExcept(const QueryDataExcept& rhs);
//QueryDataExcept& operator=(const QueryDataExcept& rhs);
virtual ~QueryDataExcept() throw()
{
}
private:
// defaults okay
// QueryDataExcept(const QueryDataExcept& rhs);
// QueryDataExcept& operator=(const QueryDataExcept& rhs);
};
/** @brief specific error exception class for VBBM Version Buffer overflow
* @bug 1949
*
*/
* @bug 1949
*
*/
class VBBMBufferOverFlowExcept : public std::runtime_error
{
public:
/** Takes a character string describing the error. */
VBBMBufferOverFlowExcept(const std::string& msg) :
std::runtime_error(msg), fErrorCode(8) { }
//ERR_VBBM_OVERFLOW = 8 defined in brmtypes.h
int8_t errorCode() const
{
return fErrorCode;
}
public:
/** Takes a character string describing the error. */
VBBMBufferOverFlowExcept(const std::string& msg) : std::runtime_error(msg), fErrorCode(8)
{
}
// ERR_VBBM_OVERFLOW = 8 defined in brmtypes.h
int8_t errorCode() const
{
return fErrorCode;
}
private:
int8_t fErrorCode;
private:
int8_t fErrorCode;
};
/** @brief specific error exception class for VBBM Version Buffer overflow
* @bug 1949
*
*/
* @bug 1949
*
*/
class PrimitiveColumnProjectResultExcept : public QueryDataExcept
{
public:
/** Takes a character string describing the error. */
PrimitiveColumnProjectResultExcept(const std::string& msg) :
QueryDataExcept(msg, projectResultErr) { }
public:
/** Takes a character string describing the error. */
PrimitiveColumnProjectResultExcept(const std::string& msg) : QueryDataExcept(msg, projectResultErr)
{
}
};
/** @brief specific error exception class for PrimProc invalid HWM
* @bug 2173
*
*/
* @bug 2173
*
*/
class InvalidRangeHWMExcept : public QueryDataExcept
{
public:
/** Takes a character string describing the error. */
InvalidRangeHWMExcept(const std::string& msg) :
QueryDataExcept(msg, hwmRangeSizeErr) { }
public:
/** Takes a character string describing the error. */
InvalidRangeHWMExcept(const std::string& msg) : QueryDataExcept(msg, hwmRangeSizeErr)
{
}
};
/** @brief Exception for F&E framework to throw
* Invalid Operation Exception
*/
class InvalidOperationExcept : public std::runtime_error
{
public:
/** Takes a character string describing the error. */
InvalidOperationExcept(const std::string& msg) :
std::runtime_error(msg) { }
public:
/** Takes a character string describing the error. */
InvalidOperationExcept(const std::string& msg) : std::runtime_error(msg)
{
}
};
/** @brief Exception for F&E framework to throw
@ -158,10 +173,11 @@ public:
*/
class InvalidConversionExcept : public std::runtime_error
{
public:
/** Takes a character string describing the error. */
InvalidConversionExcept(const std::string& msg) :
std::runtime_error(msg) { }
public:
/** Takes a character string describing the error. */
InvalidConversionExcept(const std::string& msg) : std::runtime_error(msg)
{
}
};
/** @brief Exception for F&E framework -- function evaluation to throw
@ -169,10 +185,11 @@ public:
*/
class InvalidArgumentExcept : public std::runtime_error
{
public:
/** Takes a character string describing the error. */
InvalidArgumentExcept(const std::string& msg) :
std::runtime_error(msg) { }
public:
/** Takes a character string describing the error. */
InvalidArgumentExcept(const std::string& msg) : std::runtime_error(msg)
{
}
};
/** @brief Exception for F&E framework -- function evaluation to throw
@ -180,10 +197,11 @@ public:
*/
class NotImplementedExcept : public std::runtime_error
{
public:
/** Takes a character string describing the error. */
NotImplementedExcept(const std::string& msg) :
std::runtime_error(msg) { }
public:
/** Takes a character string describing the error. */
NotImplementedExcept(const std::string& msg) : std::runtime_error(msg)
{
}
};
/** @brief Exception for F&E framework to throw on op overflow
@ -191,90 +209,101 @@ public:
*/
class OperationOverflowExcept : public std::runtime_error
{
public:
/** Takes a character string describing the error. */
OperationOverflowExcept(const std::string& msg) :
std::runtime_error(msg) { }
public:
/** Takes a character string describing the error. */
OperationOverflowExcept(const std::string& msg) : std::runtime_error(msg)
{
}
};
/** @brief specific error exception class for getSysData in Calpontsystemcatalog.
* @bug 2574
*
*/
* @bug 2574
*
*/
class NoTableExcept : public std::runtime_error
{
public:
/** Takes a character string describing the error. */
NoTableExcept(const std::string& msg) :
std::runtime_error(msg) { }
public:
/** Takes a character string describing the error. */
NoTableExcept(const std::string& msg) : std::runtime_error(msg)
{
}
};
class MoreThan1RowExcept : public IDBExcept
{
public:
MoreThan1RowExcept() :
IDBExcept(ERR_MORE_THAN_1_ROW)
{ }
public:
MoreThan1RowExcept() : IDBExcept(ERR_MORE_THAN_1_ROW)
{
}
};
class CorrelateFailExcept : public IDBExcept
{
public:
CorrelateFailExcept() :
IDBExcept(ERR_CORRELATE_FAIL)
{ }
public:
CorrelateFailExcept() : IDBExcept(ERR_CORRELATE_FAIL)
{
}
};
class DBRMException : public std::runtime_error
{
public:
DBRMException(const std::string& emsg) :
std::runtime_error(emsg) {}
public:
DBRMException(const std::string& emsg) : std::runtime_error(emsg)
{
}
};
class ProtocolError : public std::logic_error
{
public:
ProtocolError(const std::string& emsg) : std::logic_error(emsg) { }
public:
ProtocolError(const std::string& emsg) : std::logic_error(emsg)
{
}
};
#ifndef __STRING
#define __STRING(x) #x
#endif
#define idbassert(x) do { \
if (!(x)) { \
std::ostringstream os; \
\
os << __FILE__ << "@" << __LINE__ << ": assertion \'" << __STRING(x) << "\' failed"; \
std::cerr << os.str() << std::endl; \
logging::MessageLog logger((logging::LoggingID())); \
logging::Message message; \
logging::Message::Args args; \
\
args.add(os.str()); \
message.format(args); \
logger.logErrorMessage(message); \
throw logging::IDBExcept(logging::ERR_ASSERTION_FAILURE); \
} \
} while (0)
#define idbassert(x) \
do \
{ \
if (!(x)) \
{ \
std::ostringstream os; \
\
os << __FILE__ << "@" << __LINE__ << ": assertion \'" << __STRING(x) << "\' failed"; \
std::cerr << os.str() << std::endl; \
logging::MessageLog logger((logging::LoggingID())); \
logging::Message message; \
logging::Message::Args args; \
\
args.add(os.str()); \
message.format(args); \
logger.logErrorMessage(message); \
throw logging::IDBExcept(logging::ERR_ASSERTION_FAILURE); \
} \
} while (0)
#define idbassert_s(x, s) do { \
if (!(x)) { \
std::ostringstream os; \
\
os << __FILE__ << "@" << __LINE__ << ": assertion \'" << __STRING(x) << "\' failed. Error msg \'" << s << "\'"; \
std::cerr << os.str() << std::endl; \
logging::MessageLog logger((logging::LoggingID())); \
logging::Message message; \
logging::Message::Args args; \
\
args.add(os.str()); \
message.format(args); \
logger.logErrorMessage(message); \
throw logging::IDBExcept(logging::ERR_ASSERTION_FAILURE); \
} \
} while (0)
}
#define idbassert_s(x, s) \
do \
{ \
if (!(x)) \
{ \
std::ostringstream os; \
\
os << __FILE__ << "@" << __LINE__ << ": assertion \'" << __STRING(x) << "\' failed. Error msg \'" \
<< s << "\'"; \
std::cerr << os.str() << std::endl; \
logging::MessageLog logger((logging::LoggingID())); \
logging::Message message; \
logging::Message::Args args; \
\
args.add(os.str()); \
message.format(args); \
logger.logErrorMessage(message); \
throw logging::IDBExcept(logging::ERR_ASSERTION_FAILURE); \
} \
} while (0)
} // namespace logging
// vim:ts=4 sw=4:

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id: idberrorinfo.cpp 3626 2013-03-11 15:36:08Z xlou $
*
******************************************************************************************/
* $Id: idberrorinfo.cpp 3626 2013-03-11 15:36:08Z xlou $
*
******************************************************************************************/
#include <iostream>
#include <iomanip>
#include <string>
@ -45,69 +45,68 @@ using namespace config;
namespace logging
{
IDBErrorInfo* IDBErrorInfo::fInstance = 0;
boost::mutex mx;
IDBErrorInfo* IDBErrorInfo::instance()
{
boost::mutex::scoped_lock lk(mx);
boost::mutex::scoped_lock lk(mx);
if (!fInstance)
fInstance = new IDBErrorInfo();
if (!fInstance)
fInstance = new IDBErrorInfo();
return fInstance;
return fInstance;
}
IDBErrorInfo::IDBErrorInfo()
{
Config* cf = Config::makeConfig();
string configFile(cf->getConfig("SystemConfig", "ErrorMessageFile"));
Config* cf = Config::makeConfig();
string configFile(cf->getConfig("SystemConfig", "ErrorMessageFile"));
if (configFile.length() == 0)
configFile = std::string(MCSSYSCONFDIR) + "/columnstore/ErrorMessage.txt";
if (configFile.length() == 0)
configFile = std::string(MCSSYSCONFDIR) + "/columnstore/ErrorMessage.txt";
ifstream msgFile(configFile.c_str());
ifstream msgFile(configFile.c_str());
while (msgFile.good())
while (msgFile.good())
{
stringbuf* sb = new stringbuf;
msgFile.get(*sb);
string m = sb->str();
delete sb;
if (m.length() > 0 && m[0] != '#')
{
stringbuf* sb = new stringbuf;
msgFile.get(*sb);
string m = sb->str();
delete sb;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep("\t");
tokenizer tokens(m, sep);
tokenizer::iterator tok_iter = tokens.begin();
if (m.length() > 0 && m[0] != '#')
if (tok_iter != tokens.end())
{
int msgid = atoi(tok_iter->c_str());
++tok_iter;
if (tok_iter != tokens.end())
{
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep("\t");
tokenizer tokens(m, sep);
tokenizer::iterator tok_iter = tokens.begin();
++tok_iter;
if (tok_iter != tokens.end())
{
int msgid = atoi(tok_iter->c_str());
++tok_iter;
if (tok_iter != tokens.end())
{
++tok_iter;
if (tok_iter != tokens.end())
{
string msgtext = *tok_iter;
fErrMap[msgid] = msgtext;
}
}
}
if (tok_iter != tokens.end())
{
string msgtext = *tok_iter;
fErrMap[msgid] = msgtext;
}
}
ios_base::iostate st = msgFile.rdstate();
if ((st & ios_base::failbit) && !(st & ios_base::eofbit))
msgFile.clear();
(void)msgFile.get();
}
}
ios_base::iostate st = msgFile.rdstate();
if ((st & ios_base::failbit) && !(st & ios_base::eofbit))
msgFile.clear();
(void)msgFile.get();
}
}
IDBErrorInfo::~IDBErrorInfo()
@ -116,104 +115,100 @@ IDBErrorInfo::~IDBErrorInfo()
string IDBErrorInfo::errorMsg(const unsigned eid, const Message::Args& args)
{
string errMsg = lookupError(eid);
format(errMsg, args);
return errMsg;
string errMsg = lookupError(eid);
format(errMsg, args);
return errMsg;
}
string IDBErrorInfo::errorMsg(const unsigned eid)
{
string errMsg = lookupError(eid);
Message::Args args; // empty args
format(errMsg, args);
return errMsg;
string errMsg = lookupError(eid);
Message::Args args; // empty args
format(errMsg, args);
return errMsg;
}
string IDBErrorInfo::errorMsg(const unsigned eid, int i)
{
string errMsg = lookupError(eid);
Message::Args args;
args.add(i);
format(errMsg, args);
return errMsg;
string errMsg = lookupError(eid);
Message::Args args;
args.add(i);
format(errMsg, args);
return errMsg;
}
string IDBErrorInfo::errorMsg(const unsigned eid, const string& s)
{
string errMsg = lookupError(eid);
Message::Args args;
args.add(s);
format(errMsg, args);
return errMsg;
string errMsg = lookupError(eid);
Message::Args args;
args.add(s);
format(errMsg, args);
return errMsg;
}
string IDBErrorInfo::logError(const logging::LOG_TYPE logLevel,
const logging::LoggingID logid,
const unsigned eid,
const logging::Message::Args& args)
string IDBErrorInfo::logError(const logging::LOG_TYPE logLevel, const logging::LoggingID logid,
const unsigned eid, const logging::Message::Args& args)
{
Logger logger(logid.fSubsysID);
Message message(errorMsg(eid, args));
return logger.logMessage(logLevel, message, logid);
Logger logger(logid.fSubsysID);
Message message(errorMsg(eid, args));
return logger.logMessage(logLevel, message, logid);
}
void IDBErrorInfo::format(string& errMsg, const Message::Args& args)
{
Message::Args::AnyVec::const_iterator iter = args.args().begin();
Message::Args::AnyVec::const_iterator end = args.args().end();
Message::Args::AnyVec::const_iterator iter = args.args().begin();
Message::Args::AnyVec::const_iterator end = args.args().end();
boost::format fmt(errMsg);
fmt.exceptions(boost::io::no_error_bits);
boost::format fmt(errMsg);
fmt.exceptions(boost::io::no_error_bits);
while (iter != end)
while (iter != end)
{
if (iter->type() == typeid(long))
{
if (iter->type() == typeid(long))
{
long l = any_cast<long>(*iter);
fmt % l;
}
else if (iter->type() == typeid(uint64_t))
{
uint64_t u64 = any_cast<uint64_t>(*iter);
fmt % u64;
}
else if (iter->type() == typeid(double))
{
double d = any_cast<double>(*iter);
fmt % d;
}
else if (iter->type() == typeid(string))
{
string s = any_cast<string>(*iter);
fmt % s;
}
else
{
throw logic_error("IDBErrorInfo::format: unexpected type in argslist");
}
++iter;
long l = any_cast<long>(*iter);
fmt % l;
}
else if (iter->type() == typeid(uint64_t))
{
uint64_t u64 = any_cast<uint64_t>(*iter);
fmt % u64;
}
else if (iter->type() == typeid(double))
{
double d = any_cast<double>(*iter);
fmt % d;
}
else if (iter->type() == typeid(string))
{
string s = any_cast<string>(*iter);
fmt % s;
}
else
{
throw logic_error("IDBErrorInfo::format: unexpected type in argslist");
}
errMsg = fmt.str();
++iter;
}
errMsg = fmt.str();
}
/* static */
string IDBErrorInfo::lookupError(const unsigned eid)
{
string msgstr;
ErrorMap::const_iterator iter = fErrMap.find(eid);
string msgstr;
ErrorMap::const_iterator iter = fErrMap.find(eid);
if (iter == fErrMap.end())
msgstr = "Unknown Error %1% %2% %3% %4% %5%";
else
msgstr = iter->second;
if (iter == fErrMap.end())
msgstr = "Unknown Error %1% %2% %3% %4% %5%";
else
msgstr = iter->second;
ostringstream oss;
oss << "MCS-" << setw(4) << setfill('0') << eid << ": " << msgstr;
return oss.str();
ostringstream oss;
oss << "MCS-" << setw(4) << setfill('0') << eid << ": " << msgstr;
return oss.str();
}
}
} // namespace logging

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id: idberrorinfo.h 3626 2013-03-11 15:36:08Z xlou $
*
******************************************************************************************/
* $Id: idberrorinfo.h 3626 2013-03-11 15:36:08Z xlou $
*
******************************************************************************************/
/**
* @file
*/
@ -32,7 +32,6 @@
namespace logging
{
/** @brief an IDB error info class
*
* Contains a error message map for looking up and constructing formatted message
@ -42,25 +41,22 @@ typedef std::map<unsigned, std::string> ErrorMap;
class IDBErrorInfo
{
public:
static IDBErrorInfo* instance();
std::string errorMsg(const unsigned eid, const Message::Args& args);
std::string errorMsg(const unsigned eid);
std::string errorMsg(const unsigned eid, int i);
std::string errorMsg(const unsigned eid, const std::string& s);
std::string logError(const logging::LOG_TYPE logLevel,
const LoggingID logid,
const unsigned eid,
const Message::Args& args);
~IDBErrorInfo();
public:
static IDBErrorInfo* instance();
std::string errorMsg(const unsigned eid, const Message::Args& args);
std::string errorMsg(const unsigned eid);
std::string errorMsg(const unsigned eid, int i);
std::string errorMsg(const unsigned eid, const std::string& s);
std::string logError(const logging::LOG_TYPE logLevel, const LoggingID logid, const unsigned eid,
const Message::Args& args);
~IDBErrorInfo();
private:
static IDBErrorInfo* fInstance;
ErrorMap fErrMap;
IDBErrorInfo();
void format(std::string& messageFormat, const Message::Args& args);
std::string lookupError(const unsigned eid);
private:
static IDBErrorInfo* fInstance;
ErrorMap fErrMap;
IDBErrorInfo();
void format(std::string& messageFormat, const Message::Args& args);
std::string lookupError(const unsigned eid);
};
}//namespace logging
} // namespace logging

View File

@ -28,86 +28,73 @@ using namespace boost;
namespace logging
{
Logger::Logger(unsigned subsys) :
fMl1(LoggingID(subsys))
Logger::Logger(unsigned subsys) : fMl1(LoggingID(subsys))
{
}
const string Logger::logMessage(LOG_TYPE logLevel, Message::MessageID mid, const Message::Args& args,
const LoggingID& logInfo)
{
MsgMap::mapped_type msg;
MsgMap::const_iterator msgIter = fMsgMap.find(mid);
MsgMap::mapped_type msg;
MsgMap::const_iterator msgIter = fMsgMap.find(mid);
//Default message if specified # not found
if (msgIter == fMsgMap.end())
msg = Message(M0000);
else
msg = msgIter->second;
// Default message if specified # not found
if (msgIter == fMsgMap.end())
msg = Message(M0000);
else
msg = msgIter->second;
msg.reset();
msg.format(args);
msg.reset();
msg.format(args);
return logMessage(logLevel, msg, logInfo);
/*
boost::mutex::scoped_lock lk(fLogLock);
fMl1.logData(logInfo);
return logMessage(logLevel, msg, logInfo);
/*
boost::mutex::scoped_lock lk(fLogLock);
fMl1.logData(logInfo);
switch (logLevel)
{
case LOG_TYPE_DEBUG:
default:
fMl1.logDebugMessage(msg);
break;
case LOG_TYPE_INFO:
fMl1.logInfoMessage(msg);
break;
case LOG_TYPE_WARNING:
fMl1.logWarningMessage(msg);
break;
case LOG_TYPE_ERROR:
fMl1.logErrorMessage(msg);
break;
case LOG_TYPE_CRITICAL:
fMl1.logCriticalMessage(msg);
break;
}
switch (logLevel)
{
case LOG_TYPE_DEBUG:
default:
fMl1.logDebugMessage(msg);
break;
case LOG_TYPE_INFO:
fMl1.logInfoMessage(msg);
break;
case LOG_TYPE_WARNING:
fMl1.logWarningMessage(msg);
break;
case LOG_TYPE_ERROR:
fMl1.logErrorMessage(msg);
break;
case LOG_TYPE_CRITICAL:
fMl1.logCriticalMessage(msg);
break;
}
return msg.msg();*/
return msg.msg();*/
}
const std::string Logger::logMessage(LOG_TYPE logLevel, const Message& msg, const LoggingID& logInfo)
{
boost::mutex::scoped_lock lk(fLogLock);
fMl1.logData(logInfo);
boost::mutex::scoped_lock lk(fLogLock);
fMl1.logData(logInfo);
switch (logLevel)
{
case LOG_TYPE_DEBUG:
default:
fMl1.logDebugMessage(msg);
break;
switch (logLevel)
{
case LOG_TYPE_DEBUG:
default: fMl1.logDebugMessage(msg); break;
case LOG_TYPE_INFO:
fMl1.logInfoMessage(msg);
break;
case LOG_TYPE_INFO: fMl1.logInfoMessage(msg); break;
case LOG_TYPE_WARNING:
fMl1.logWarningMessage(msg);
break;
case LOG_TYPE_WARNING: fMl1.logWarningMessage(msg); break;
case LOG_TYPE_ERROR:
fMl1.logErrorMessage(msg);
break;
case LOG_TYPE_ERROR: fMl1.logErrorMessage(msg); break;
case LOG_TYPE_CRITICAL:
fMl1.logCriticalMessage(msg);
break;
}
return msg.msg();
}
case LOG_TYPE_CRITICAL: fMl1.logCriticalMessage(msg); break;
}
return msg.msg();
}
} // namespace logging

View File

@ -34,61 +34,58 @@
namespace logging
{
typedef std::map<Message::MessageID, Message> MsgMap;
/** @brief message log wrapper class */
class Logger
{
public:
/** @brief ctor
*
* @param subsys the subsystem id
*/
explicit Logger(unsigned subsys);
public:
/** @brief ctor
*
* @param subsys the subsystem id
*/
explicit Logger(unsigned subsys);
/** @brief log a message
*
* Log a message at a certain debug level
*/
const std::string logMessage(LOG_TYPE logLevel, Message::MessageID mid,
const Message::Args& args, const LoggingID& logInfo);
/** @brief log a message
*
* Log a message at a certain debug level
*/
const std::string logMessage(LOG_TYPE logLevel, Message::MessageID mid, const Message::Args& args,
const LoggingID& logInfo);
/** @brief log a formated message
*
* For the error framework to use
*/
const std::string logMessage(LOG_TYPE logLevel, const Message& message, const LoggingID& logInfo);
/** @brief log a formated message
*
* For the error framework to use
*/
const std::string logMessage(LOG_TYPE logLevel, const Message& message, const LoggingID& logInfo);
/** @brief set the message map for this logger
*
* This method sets the message map for this logger. You need to call this (once and only once) before
* using the class. The map needs to be constructed before and given to this class.
*/
void msgMap(const MsgMap& msgMap)
{
fMsgMap = msgMap;
}
/** @brief set the message map for this logger
*
* This method sets the message map for this logger. You need to call this (once and only once) before
* using the class. The map needs to be constructed before and given to this class.
*/
void msgMap(const MsgMap& msgMap)
{
fMsgMap = msgMap;
}
/** @brief get the message map from this logger
*/
const MsgMap& msgMap() const
{
return fMsgMap;
}
/** @brief get the message map from this logger
*/
const MsgMap& msgMap() const
{
return fMsgMap;
}
private:
// not copyable (because of the mutex)
Logger(const Logger& rhs);
Logger& operator=(const Logger& rhs);
private:
// not copyable (because of the mutex)
Logger(const Logger& rhs);
Logger& operator=(const Logger& rhs);
MsgMap fMsgMap;
MessageLog fMl1;
boost::mutex fLogLock;
MsgMap fMsgMap;
MessageLog fMl1;
boost::mutex fLogLock;
};
typedef boost::shared_ptr<Logger> SPL;
}
} // namespace logging

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id: loggingid.h 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
* $Id: loggingid.h 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
/**
* @file
*/
@ -28,24 +28,23 @@
namespace logging
{
/** @brief a logging context structure
*
*/
struct LoggingID
{
/** @brief LoggingID ctor
*
*/
explicit LoggingID(unsigned subsysID = 0, unsigned sessionID = 0, unsigned txnID = 0, unsigned ThdID = 0)
: fSubsysID(subsysID), fSessionID(sessionID), fTxnID(txnID), fThdID(ThdID)
{}
/** @brief LoggingID ctor
*
*/
explicit LoggingID(unsigned subsysID = 0, unsigned sessionID = 0, unsigned txnID = 0, unsigned ThdID = 0)
: fSubsysID(subsysID), fSessionID(sessionID), fTxnID(txnID), fThdID(ThdID)
{
}
unsigned fSubsysID; /// subsystem ID
unsigned fSessionID; /// session ID
unsigned fTxnID; /// transaction ID
unsigned fThdID; /// thread ID
unsigned fSubsysID; /// subsystem ID
unsigned fSessionID; /// session ID
unsigned fTxnID; /// transaction ID
unsigned fThdID; /// thread ID
};
}
} // namespace logging

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id: message.cpp 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
* $Id: message.cpp 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
#include <iostream>
#include <iomanip>
#include <string>
@ -43,7 +43,6 @@ using namespace config;
namespace
{
boost::mutex mx;
bool catalogLoaded = false;
@ -53,182 +52,179 @@ CatMap catmap;
void loadCatalog()
{
Config* cf = Config::makeConfig();
string configFile(cf->getConfig("MessageLog", "MessageLogFile"));
Config* cf = Config::makeConfig();
string configFile(cf->getConfig("MessageLog", "MessageLogFile"));
if (configFile.length() == 0)
configFile = std::string(MCSSYSCONFDIR) + "/columnstore/MessageFile.txt";
if (configFile.length() == 0)
configFile = std::string(MCSSYSCONFDIR) + "/columnstore/MessageFile.txt";
ifstream msgFile(configFile.c_str());
ifstream msgFile(configFile.c_str());
while (msgFile.good())
while (msgFile.good())
{
stringbuf* sb = new stringbuf;
msgFile.get(*sb);
string m = sb->str();
delete sb;
if (m.length() > 0 && m[0] != '#')
{
stringbuf* sb = new stringbuf;
msgFile.get(*sb);
string m = sb->str();
delete sb;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep("\t");
tokenizer tokens(m, sep);
tokenizer::iterator tok_iter = tokens.begin();
if (m.length() > 0 && m[0] != '#')
if (tok_iter != tokens.end())
{
int msgid = atoi(tok_iter->c_str());
++tok_iter;
if (tok_iter != tokens.end())
{
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep("\t");
tokenizer tokens(m, sep);
tokenizer::iterator tok_iter = tokens.begin();
if (tok_iter != tokens.end())
{
int msgid = atoi(tok_iter->c_str());
++tok_iter;
if (tok_iter != tokens.end())
{
string msgtext = *tok_iter;
catmap[msgid] = msgtext;
}
}
string msgtext = *tok_iter;
catmap[msgid] = msgtext;
}
ios_base::iostate st = msgFile.rdstate();
if ((st & ios_base::failbit) && !(st & ios_base::eofbit))
msgFile.clear();
(void)msgFile.get();
}
}
ios_base::iostate st = msgFile.rdstate();
if ((st & ios_base::failbit) && !(st & ios_base::eofbit))
msgFile.clear();
(void)msgFile.get();
}
}
}
} // namespace
namespace logging
{
Message::Message(const MessageID msgid) :
fMsgID(msgid), fMsg(lookupMessage(msgid)), fConfig(Config::makeConfig())
Message::Message(const MessageID msgid)
: fMsgID(msgid), fMsg(lookupMessage(msgid)), fConfig(Config::makeConfig())
{
}
Message::Message(const string msg):
fMsgID(0), fMsg(msg), fConfig(Config::makeConfig())
Message::Message(const string msg) : fMsgID(0), fMsg(msg), fConfig(Config::makeConfig())
{
}
void Message::swap(Message& rhs)
{
std::swap(fMsgID, rhs.fMsgID);
std::swap(fMsg, rhs.fMsg);
std::swap(fConfig, rhs.fConfig);
std::swap(fMsgID, rhs.fMsgID);
std::swap(fMsg, rhs.fMsg);
std::swap(fConfig, rhs.fConfig);
}
void Message::Args::add(int i)
{
fArgs.push_back(long(i));
fArgs.push_back(long(i));
}
void Message::Args::add(uint64_t u64)
{
fArgs.push_back(u64);
fArgs.push_back(u64);
}
void Message::Args::add(const string& s)
{
fArgs.push_back(s);
fArgs.push_back(s);
}
void Message::Args::add(double d)
{
fArgs.push_back(d);
fArgs.push_back(d);
}
void Message::Args::reset()
{
fArgs.clear();
fArgs.clear();
}
void Message::format(const Args& args)
{
Args::AnyVec::const_iterator iter = args.args().begin();
Args::AnyVec::const_iterator end = args.args().end();
Args::AnyVec::const_iterator iter = args.args().begin();
Args::AnyVec::const_iterator end = args.args().end();
boost::format fmt(fMsg);
fmt.exceptions(boost::io::no_error_bits);
boost::format fmt(fMsg);
fmt.exceptions(boost::io::no_error_bits);
while (iter != end)
while (iter != end)
{
if (iter->type() == typeid(long))
{
if (iter->type() == typeid(long))
{
long l = any_cast<long>(*iter);
fmt % l;
}
else if (iter->type() == typeid(uint64_t))
{
uint64_t u64 = any_cast<uint64_t>(*iter);
fmt % u64;
}
else if (iter->type() == typeid(double))
{
double d = any_cast<double>(*iter);
fmt % d;
}
else if (iter->type() == typeid(string))
{
string s = any_cast<string>(*iter);
fmt % s;
}
else
{
throw logic_error("Message::format: unexpected type in argslist");
}
++iter;
long l = any_cast<long>(*iter);
fmt % l;
}
else if (iter->type() == typeid(uint64_t))
{
uint64_t u64 = any_cast<uint64_t>(*iter);
fmt % u64;
}
else if (iter->type() == typeid(double))
{
double d = any_cast<double>(*iter);
fmt % d;
}
else if (iter->type() == typeid(string))
{
string s = any_cast<string>(*iter);
fmt % s;
}
else
{
throw logic_error("Message::format: unexpected type in argslist");
}
fMsg = fmt.str();
++iter;
}
fMsg = fmt.str();
}
/* static */
const string Message::lookupMessage(const MessageID& msgid)
{
if (!catalogLoaded)
{
boost::mutex::scoped_lock lock(mx);
if (!catalogLoaded)
{
boost::mutex::scoped_lock lock(mx);
if (!catalogLoaded)
{
loadCatalog();
catalogLoaded = true;
}
loadCatalog();
catalogLoaded = true;
}
}
string msgstr;
CatMap::const_iterator iter = catmap.find(msgid);
string msgstr;
CatMap::const_iterator iter = catmap.find(msgid);
if (iter == catmap.end())
{
iter = catmap.find(0);
if (iter == catmap.end())
{
iter = catmap.find(0);
if (iter == catmap.end())
{
msgstr = "%1% %2% %3% %4% %5%";
}
else
{
msgstr = iter->second;
}
msgstr = "%1% %2% %3% %4% %5%";
}
else
{
msgstr = iter->second;
msgstr = iter->second;
}
}
else
{
msgstr = iter->second;
}
ostringstream oss;
oss << "CAL" << setw(4) << setfill('0') << msgid << ": " << msgstr;
return oss.str();
ostringstream oss;
oss << "CAL" << setw(4) << setfill('0') << msgid << ": " << msgstr;
return oss.str();
}
void Message::reset()
{
fMsg = lookupMessage(fMsgID);
}
fMsg = lookupMessage(fMsgID);
}
} // namespace logging

View File

@ -17,9 +17,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id: messagelog.cpp 3658 2013-03-22 20:26:02Z chao $
*
******************************************************************************************/
* $Id: messagelog.cpp 3658 2013-03-22 20:26:02Z chao $
*
******************************************************************************************/
#include <sstream>
#include <iomanip>
#include <ctime>
@ -46,69 +46,64 @@ using namespace logging;
/*
* This list matches SubsystemIDs.txt, but has names matching Process Config DB
*/
const vector<string> SubsystemID = ba::list_of
("Calpont") // id = 0 default
("ddljoblist") // id = 1
("ddlpackage") // id = 2
("dmlpackage") // id = 3
("execplan") // id = 4
("joblist") // id = 5
("resultset") // id = 6
("mcsadmin") // id = 7
("oamcpp") // id = 8
("ServerMonitor") // id = 9
("traphandler") // id = 10
("alarmmanager") // id = 11
("configcpp") // id = 12
("loggingcpp") // id = 13
("messageqcpp") // id = 14
("DDLProc") // id = 15
("ExeMgr") // id = 16
("ProcessManager") // id = 17
("ProcessMonitor") // id = 18
("writeengine") // id = 19
("DMLProc") // id = 20
("dmlpackageproc") // id = 21
("threadpool") // id = 22
("ddlpackageproc") // id = 23
("dbcon") // id = 24
("DiskManager") // id = 25
("RouteMsg") // id = 26
("SQLBuffMgr") // id = 27
("PrimProc") // id = 28
("controllernode") // id = 29
("workernode") // id = 30
("messagequeue") // id = 31
("writeengineserver")//id = 32
("writeenginesplit")// id = 33
("cpimport.bin") // id = 34
("IDBFile") // id = 35
;
const vector<string> SubsystemID = ba::list_of("Calpont") // id = 0 default
("ddljoblist") // id = 1
("ddlpackage") // id = 2
("dmlpackage") // id = 3
("execplan") // id = 4
("joblist") // id = 5
("resultset") // id = 6
("mcsadmin") // id = 7
("oamcpp") // id = 8
("ServerMonitor") // id = 9
("traphandler") // id = 10
("alarmmanager") // id = 11
("configcpp") // id = 12
("loggingcpp") // id = 13
("messageqcpp") // id = 14
("DDLProc") // id = 15
("ExeMgr") // id = 16
("ProcessManager") // id = 17
("ProcessMonitor") // id = 18
("writeengine") // id = 19
("DMLProc") // id = 20
("dmlpackageproc") // id = 21
("threadpool") // id = 22
("ddlpackageproc") // id = 23
("dbcon") // id = 24
("DiskManager") // id = 25
("RouteMsg") // id = 26
("SQLBuffMgr") // id = 27
("PrimProc") // id = 28
("controllernode") // id = 29
("workernode") // id = 30
("messagequeue") // id = 31
("writeengineserver") // id = 32
("writeenginesplit") // id = 33
("cpimport.bin") // id = 34
("IDBFile") // id = 35
;
string timestr()
{
struct tm tm;
struct timeval tv;
gettimeofday(&tv, 0);
struct tm tm;
struct timeval tv;
gettimeofday(&tv, 0);
#ifdef _MSC_VER
errno_t p = 0;
time_t t = (time_t)tv.tv_sec;
p = localtime_s(&tm, &t);
errno_t p = 0;
time_t t = (time_t)tv.tv_sec;
p = localtime_s(&tm, &t);
if (p != 0)
memset(&tm, 0, sizeof(tm));
if (p != 0)
memset(&tm, 0, sizeof(tm));
#else
localtime_r(&tv.tv_sec, &tm);
localtime_r(&tv.tv_sec, &tm);
#endif
ostringstream oss;
oss << setfill('0')
<< setw(2) << tm.tm_sec
<< '.'
<< setw(6) << tv.tv_usec
;
return oss.str();
ostringstream oss;
oss << setfill('0') << setw(2) << tm.tm_sec << '.' << setw(6) << tv.tv_usec;
return oss.str();
}
void closeLog()
@ -117,162 +112,156 @@ void closeLog()
void openLog(unsigned subsystemid, int localLogNum)
{
if (subsystemid >= SubsystemID.size())
subsystemid = 0;
if (subsystemid >= SubsystemID.size())
subsystemid = 0;
}
const string escape_pct(const string& in)
{
string out(in);
string::size_type pos;
pos = out.find('%', 0);
string out(in);
string::size_type pos;
pos = out.find('%', 0);
while (pos != string::npos)
{
out.replace(pos, 1, "%%");
pos = out.find('%', pos + 2);
}
while (pos != string::npos)
{
out.replace(pos, 1, "%%");
pos = out.find('%', pos + 2);
}
return out;
return out;
}
}
} // namespace
namespace logging
{
MessageLog::MessageLog(const LoggingID& initData, int localLogNum) :
fLogData(initData), fFacility(localLogNum)
MessageLog::MessageLog(const LoggingID& initData, int localLogNum)
: fLogData(initData), fFacility(localLogNum)
{
openLog(fLogData.fSubsysID, fFacility);
openLog(fLogData.fSubsysID, fFacility);
}
void MessageLog::logData(const LoggingID& logData)
{
if (fLogData.fSubsysID != logData.fSubsysID)
{
closeLog();
openLog(logData.fSubsysID, fFacility);
}
if (fLogData.fSubsysID != logData.fSubsysID)
{
closeLog();
openLog(logData.fSubsysID, fFacility);
}
fLogData = logData;
fLogData = logData;
}
MessageLog::~MessageLog()
{
closeLog();
closeLog();
}
const string MessageLog::format(const Message& msg, const char prefix)
{
ostringstream oss;
oss << timestr() << " |"
<< fLogData.fSessionID
<< '|' << fLogData.fTxnID
<< '|' << fLogData.fThdID
<< "| "
<< prefix << ' ' << setw(2) << setfill('0') << fLogData.fSubsysID
<< ' ' << msg.msg()
;
return escape_pct(oss.str());
ostringstream oss;
oss << timestr() << " |" << fLogData.fSessionID << '|' << fLogData.fTxnID << '|' << fLogData.fThdID << "| "
<< prefix << ' ' << setw(2) << setfill('0') << fLogData.fSubsysID << ' ' << msg.msg();
return escape_pct(oss.str());
}
void MessageLog::logDebugMessage(const Message& msg)
{
::openlog(SubsystemID[fLogData.fSubsysID].c_str(), 0 | LOG_PID | LOG_CONS, fFacility);
::syslog(LOG_DEBUG, "%s", format(msg, 'D').c_str());
::closelog();
::openlog(SubsystemID[fLogData.fSubsysID].c_str(), 0 | LOG_PID | LOG_CONS, fFacility);
::syslog(LOG_DEBUG, "%s", format(msg, 'D').c_str());
::closelog();
}
void MessageLog::logInfoMessage(const Message& msg)
{
::openlog(SubsystemID[fLogData.fSubsysID].c_str(), 0 | LOG_PID | LOG_CONS, fFacility);
::syslog(LOG_INFO, "%s", format(msg, 'I').c_str());
::closelog();
::openlog(SubsystemID[fLogData.fSubsysID].c_str(), 0 | LOG_PID | LOG_CONS, fFacility);
::syslog(LOG_INFO, "%s", format(msg, 'I').c_str());
::closelog();
}
void MessageLog::logWarningMessage(const Message& msg)
{
::openlog(SubsystemID[fLogData.fSubsysID].c_str(), 0 | LOG_PID | LOG_CONS, fFacility);
::syslog(LOG_WARNING, "%s", format(msg, 'W').c_str());
::closelog();
::openlog(SubsystemID[fLogData.fSubsysID].c_str(), 0 | LOG_PID | LOG_CONS, fFacility);
::syslog(LOG_WARNING, "%s", format(msg, 'W').c_str());
::closelog();
}
void MessageLog::logErrorMessage(const Message& msg)
{
// @bug 24 use 'E' instead of 'S'
::openlog(SubsystemID[fLogData.fSubsysID].c_str(), 0 | LOG_PID | LOG_PERROR | LOG_CONS, fFacility);
::syslog(LOG_ERR, "%s", format(msg, 'E').c_str());
::closelog();
// @bug 24 use 'E' instead of 'S'
::openlog(SubsystemID[fLogData.fSubsysID].c_str(), 0 | LOG_PID | LOG_PERROR | LOG_CONS, fFacility);
::syslog(LOG_ERR, "%s", format(msg, 'E').c_str());
::closelog();
}
void MessageLog::logCriticalMessage(const Message& msg)
{
::openlog(SubsystemID[fLogData.fSubsysID].c_str(), 0 | LOG_PID | LOG_PERROR | LOG_CONS, fFacility);
::syslog(LOG_CRIT, "%s", format(msg, 'C').c_str());
::closelog();
::openlog(SubsystemID[fLogData.fSubsysID].c_str(), 0 | LOG_PID | LOG_PERROR | LOG_CONS, fFacility);
::syslog(LOG_CRIT, "%s", format(msg, 'C').c_str());
::closelog();
}
//Bug 5218. comment out the following functions to alleviate issue where dml messages show up in crit.log. This
// Bug 5218. comment out the following functions to alleviate issue where dml messages show up in crit.log.
// This
// will turn off data_mods.log.
void logDML(unsigned sessionId, unsigned txnId, const string& statement, const string& owner)
{
/* logging::Message::Args args;
/* logging::Message::Args args;
unsigned subsystemId = 20; // DMLProc
unsigned threadId = 0; // 0 for now
unsigned subsystemId = 20; // DMLProc
unsigned threadId = 0; // 0 for now
logging::LoggingID loggingId(subsystemId, sessionId, txnId, threadId);
logging::MessageLog messageLog(loggingId, LOG_LOCAL2);
logging::Message m(M0017);
args.add("|" + owner + "|" + statement);
m.format(args);
messageLog.logCriticalMessage(m); */
logging::LoggingID loggingId(subsystemId, sessionId, txnId, threadId);
logging::MessageLog messageLog(loggingId, LOG_LOCAL2);
logging::Message m(M0017);
args.add("|" + owner + "|" + statement);
m.format(args);
messageLog.logCriticalMessage(m); */
}
void logDDL(unsigned sessionId, unsigned txnId, const string& statement, const string& owner)
{
/*
logging::Message::Args args;
/*
logging::Message::Args args;
unsigned subsystemId = 15; // DDLProc
unsigned threadId = 0; // 0 for now
unsigned subsystemId = 15; // DDLProc
unsigned threadId = 0; // 0 for now
logging::LoggingID loggingId(subsystemId, sessionId, txnId, threadId);
logging::MessageLog messageLog(loggingId, LOG_LOCAL2);
logging::Message m(M0018);
args.add("|" + owner + "|" + statement);
m.format(args);
messageLog.logCriticalMessage(m); */
logging::LoggingID loggingId(subsystemId, sessionId, txnId, threadId);
logging::MessageLog messageLog(loggingId, LOG_LOCAL2);
logging::Message m(M0018);
args.add("|" + owner + "|" + statement);
m.format(args);
messageLog.logCriticalMessage(m); */
}
void logCommand(unsigned sessionId, unsigned txnId, const string& statement)
{
/* logging::Message::Args args;
/* logging::Message::Args args;
unsigned subsystemId = 20; // DMLProc
unsigned threadId = 0; // 0 for now
unsigned subsystemId = 20; // DMLProc
unsigned threadId = 0; // 0 for now
logging::LoggingID loggingId(subsystemId, sessionId, txnId, threadId);
logging::MessageLog messageLog(loggingId, LOG_LOCAL2);
logging::Message m(M0019);
args.add("|" + statement);
m.format(args);
messageLog.logCriticalMessage(m); */
logging::LoggingID loggingId(subsystemId, sessionId, txnId, threadId);
logging::MessageLog messageLog(loggingId, LOG_LOCAL2);
logging::Message m(M0019);
args.add("|" + statement);
m.format(args);
messageLog.logCriticalMessage(m); */
}
void logEventToDataLog(unsigned messageId, const string& messageText)
{
/* logging::Message::Args args;
/* logging::Message::Args args;
unsigned subsystemId = 20; // DMLProc
unsigned threadId = 0; // 0 for now
unsigned subsystemId = 20; // DMLProc
unsigned threadId = 0; // 0 for now
logging::LoggingID loggingId(subsystemId, 0, 0, threadId);
logging::MessageLog messageLog(loggingId, LOG_LOCAL2);
logging::Message m(messageId);
args.add(messageText);
m.format(args);
messageLog.logCriticalMessage(m); */
logging::LoggingID loggingId(subsystemId, 0, 0, threadId);
logging::MessageLog messageLog(loggingId, LOG_LOCAL2);
logging::Message m(messageId);
args.add(messageText);
m.format(args);
messageLog.logCriticalMessage(m); */
}
} //namespace logging
} // namespace logging

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id: messagelog.h 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
* $Id: messagelog.h 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
/**
* @file
*/
@ -32,19 +32,17 @@ class MessageLoggingTest;
namespace logging
{
/** @brief Log Types
*/
*/
enum LOG_TYPE
{
LOG_TYPE_DEBUG, // 0 = debug
LOG_TYPE_INFO, // 1 = info
LOG_TYPE_WARNING, // 2 = warning
LOG_TYPE_ERROR, // 3 = error
LOG_TYPE_CRITICAL // 4 = critical
LOG_TYPE_DEBUG, // 0 = debug
LOG_TYPE_INFO, // 1 = info
LOG_TYPE_WARNING, // 2 = warning
LOG_TYPE_ERROR, // 3 = error
LOG_TYPE_CRITICAL // 4 = critical
};
class Message;
/** @brief a message log class
@ -52,104 +50,102 @@ class Message;
*/
class MessageLog
{
public:
/** @brief ctor
* @param initData the LogginID object.
* @param facility openLog will be called using this as the third parm.
*/
MessageLog(const LoggingID& initData, int facility = LOG_LOCAL1);
public:
/** @brief ctor
* @param initData the LogginID object.
* @param facility openLog will be called using this as the third parm.
*/
MessageLog(const LoggingID& initData, int facility = LOG_LOCAL1);
/** @brief dtor
*
*/
~MessageLog();
/** @brief dtor
*
*/
~MessageLog();
/** @brief log a debug message
*
* @param msg the message to log
*/
void logDebugMessage(const Message& msg);
/** @brief log a debug message
*
* @param msg the message to log
*/
void logDebugMessage(const Message& msg);
/** @brief log an info message
*
* @param msg the message to log
*/
void logInfoMessage(const Message& msg);
/** @brief log an info message
*
* @param msg the message to log
*/
void logInfoMessage(const Message& msg);
/** @brief log a warning message
*
* @param msg the message to log
*/
void logWarningMessage(const Message& msg);
/** @brief log a warning message
*
* @param msg the message to log
*/
void logWarningMessage(const Message& msg);
/** @brief log an error message
*
* @param msg the message to log
*/
void logErrorMessage(const Message& msg);
/** @brief log an error message
*
* @param msg the message to log
*/
void logErrorMessage(const Message& msg);
/** @brief log a serious message
*
* @param msg the message to log
* @note this is the same as calling logErrorMessage()
* @bug 24 add logErrorMessage() and make logSeriousMessage() call it
*/
void logSeriousMessage(const Message& msg)
{
logErrorMessage(msg);
}
/** @brief log a serious message
*
* @param msg the message to log
* @note this is the same as calling logErrorMessage()
* @bug 24 add logErrorMessage() and make logSeriousMessage() call it
*/
void logSeriousMessage(const Message& msg)
{
logErrorMessage(msg);
}
/** @brief log a critial message
*
* @param msg the message to log
*/
void logCriticalMessage(const Message& msg);
/** @brief log a critial message
*
* @param msg the message to log
*/
void logCriticalMessage(const Message& msg);
/** @brief LoggingID mutator
*
* @param logData the new LoggingID. If the subsystem id is changed, the syslog connection will be closed
* and reopened.
*/
void logData(const LoggingID& logData);
/** @brief LoggingID mutator
*
* @param logData the new LoggingID. If the subsystem id is changed, the syslog connection will be closed
* and reopened.
*/
void logData(const LoggingID& logData);
/** @brief LoggingID accessor
*
*/
const LoggingID& logData() const
{
return fLogData;
}
/** @brief LoggingID accessor
*
*/
const LoggingID& logData() const
{
return fLogData;
}
friend class ::MessageLoggingTest;
friend class ::MessageLoggingTest;
protected:
protected:
const std::string format(const Message& msg, const char prefix = 'U');
const std::string format(const Message& msg, const char prefix = 'U');
private:
// defaults okay
// MessageLog(const MessageLog& rhs);
// MessageLog& operator=(const MessageLog& rhs);
private:
//defaults okay
//MessageLog(const MessageLog& rhs);
//MessageLog& operator=(const MessageLog& rhs);
LoggingID fLogData; /// the logging context data
int fFacility; /// the syslog facility number
LoggingID fLogData; /// the logging context data
int fFacility; /// the syslog facility number
};
/** @brief logs the DML statement using a Syslog critical message to LOG_LOCAL2.
*/
*/
void logDML(unsigned sessionId, unsigned txnId, const std::string& statement, const std::string& owner);
/** @brief logs the DDL statement using a Syslog critical message to LOG_LOCAL2.
*/
*/
void logDDL(unsigned sessionId, unsigned txnId, const std::string& statement, const std::string& owner);
/** @brief logs the commit or rollback statement using a Syslog critical message to LOG_LOCAL2.
*/
*/
void logCommand(unsigned sessionId, unsigned txnId, const std::string& statement);
/** @brief logs the event using a Syslog critical message to LOG_LOCAL2. Used for messages 19..24.
*/
*/
void logEventToDataLog(unsigned messageId, const std::string& messageText);
}
} // namespace logging

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id: messageobj.h 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
* $Id: messageobj.h 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
/**
* @file
*/
@ -39,126 +39,123 @@ class MessageLoggingTest;
namespace logging
{
/** @brief a message class
*
* Contains a message to be logged
*/
class Message
{
public:
/** @brief the args to a formatted message
*/
class Args
public:
/** @brief the args to a formatted message
*/
class Args
{
public:
/** @brief the args vector
*/
typedef std::vector<boost::any> AnyVec;
// default ctors & dtors okay
/** @brief add an int arg to the message
*/
void add(int i);
/** @brief add an unsigned 64 bit int arg to the message
*/
void add(uint64_t i);
/** @brief add a float arg to the message
*/
void add(double d);
/** @brief add a string arg to the message
*/
void add(const std::string& s);
/** @brief args accessor
*/
const AnyVec& args() const
{
public:
/** @brief the args vector
*/
typedef std::vector<boost::any> AnyVec;
// default ctors & dtors okay
/** @brief add an int arg to the message
*/
void add(int i);
/** @brief add an unsigned 64 bit int arg to the message
*/
void add(uint64_t i);
/** @brief add a float arg to the message
*/
void add(double d);
/** @brief add a string arg to the message
*/
void add(const std::string& s);
/** @brief args accessor
*/
const AnyVec& args() const
{
return fArgs;
}
/** @brief reset the args list
*
*/
void reset();
friend class ::MessageLoggingTest;
private:
AnyVec fArgs; /// the args vector
};
/** @brief the MessageID type
*/
typedef unsigned MessageID;
/** @brief default ctor
*/
explicit Message(const MessageID msgid = 0);
/** @brief ctor turn a message string to a Message
*
* For error handling framework use to log error
*/
Message(const std::string msg);
/** @brief format message with args
*/
void format(const Args& args);
/** @brief msg accessor
*/
const std::string& msg() const
{
return fMsg;
return fArgs;
}
/** @brief swap
*/
void swap(Message& rhs);
/** @brief lookup the message format string
*
* looks up the message format string for msgid. Returns a reasonable
* default if one can't be found.
*/
static const std::string lookupMessage(const MessageID& msgid);
/** @brief reset the formated string
*
* The original, unformated string is restored, and this Message
* is then ready for a new call to format().
*/
/** @brief reset the args list
*
*/
void reset();
/** @brief msgID accessor
*/
const MessageID& msgID() const
{
return fMsgID;
}
friend class ::MessageLoggingTest;
private:
//defaults okay
//Message(const Message& rhs);
//Message& operator=(const Message& rhs);
private:
AnyVec fArgs; /// the args vector
};
MessageID fMsgID; /// the msgID
std::string fMsg; /// the formated or unformated message
config::Config* fConfig; /// config file ptr
/** @brief the MessageID type
*/
typedef unsigned MessageID;
/** @brief default ctor
*/
explicit Message(const MessageID msgid = 0);
/** @brief ctor turn a message string to a Message
*
* For error handling framework use to log error
*/
Message(const std::string msg);
/** @brief format message with args
*/
void format(const Args& args);
/** @brief msg accessor
*/
const std::string& msg() const
{
return fMsg;
}
/** @brief swap
*/
void swap(Message& rhs);
/** @brief lookup the message format string
*
* looks up the message format string for msgid. Returns a reasonable
* default if one can't be found.
*/
static const std::string lookupMessage(const MessageID& msgid);
/** @brief reset the formated string
*
* The original, unformated string is restored, and this Message
* is then ready for a new call to format().
*/
void reset();
/** @brief msgID accessor
*/
const MessageID& msgID() const
{
return fMsgID;
}
friend class ::MessageLoggingTest;
private:
// defaults okay
// Message(const Message& rhs);
// Message& operator=(const Message& rhs);
MessageID fMsgID; /// the msgID
std::string fMsg; /// the formated or unformated message
config::Config* fConfig; /// config file ptr
};
inline void swap(logging::Message& lhs, logging::Message& rhs)
{
lhs.swap(rhs);
lhs.swap(rhs);
}
}//namespace logging
} // namespace logging

View File

@ -31,47 +31,51 @@ using namespace std;
namespace logging
{
const unsigned LogDefaultMsg = M0000;
const unsigned LogStartSql = M0041;
const unsigned LogEndSql = M0042;
//We can't use a member Logger here. When used with DML and DDL, the syslog gets closed by calls to DMLLog and DDLLog.
// We can't use a member Logger here. When used with DML and DDL, the syslog gets closed by calls to DMLLog
// and DDLLog.
SQLLogger::SQLLogger(const std::string sql, unsigned subsys, unsigned session, unsigned txn, unsigned thread)
: fLogId(subsys, session, txn, thread), fLog(!sql.empty())
: fLogId(subsys, session, txn, thread), fLog(!sql.empty())
{
makeMsgMap();
makeMsgMap();
if (fLog) logMessage(LOG_TYPE_DEBUG, sql, LogStartSql);
if (fLog)
logMessage(LOG_TYPE_DEBUG, sql, LogStartSql);
}
SQLLogger::SQLLogger(const std::string sql, const LoggingID& logId)
: fLogId(logId.fSubsysID, logId.fSessionID, logId.fTxnID, logId.fThdID), fLog(!sql.empty())
: fLogId(logId.fSubsysID, logId.fSessionID, logId.fTxnID, logId.fThdID), fLog(!sql.empty())
{
makeMsgMap();
makeMsgMap();
if (fLog) logMessage(LOG_TYPE_DEBUG, sql, LogStartSql);
if (fLog)
logMessage(LOG_TYPE_DEBUG, sql, LogStartSql);
}
void SQLLogger::makeMsgMap()
{
fMsgMap[LogDefaultMsg] = Message(LogDefaultMsg);
fMsgMap[LogStartSql] = Message(LogStartSql);
fMsgMap[LogEndSql] = Message(LogEndSql);
fMsgMap[LogDefaultMsg] = Message(LogDefaultMsg);
fMsgMap[LogStartSql] = Message(LogStartSql);
fMsgMap[LogEndSql] = Message(LogEndSql);
}
SQLLogger::~SQLLogger()
{
if (fLog) logMessage(LOG_TYPE_DEBUG, "", LogEndSql);
if (fLog)
logMessage(LOG_TYPE_DEBUG, "", LogEndSql);
}
std::string SQLLogger::logMessage(logging::LOG_TYPE logLevel, const std::string& msg, logging::Message::MessageID mid )
std::string SQLLogger::logMessage(logging::LOG_TYPE logLevel, const std::string& msg,
logging::Message::MessageID mid)
{
logging::Message::Args args;
args.add(msg);
Logger logger(fLogId.fSubsysID);
logger.msgMap(fMsgMap);
return logger.logMessage(logLevel, mid, args, fLogId);
logging::Message::Args args;
args.add(msg);
Logger logger(fLogId.fSubsysID);
logger.msgMap(fMsgMap);
return logger.logMessage(logLevel, mid, args, fLogId);
}
}
} // namespace logging

View File

@ -39,24 +39,24 @@ extern const unsigned LogStartSql;
extern const unsigned LogEndSql;
/** @brief writes sql start with sql statement in constructor and sql end in destructor in debug.log
if the sql text is not empty
if the sql text is not empty
*/
class SQLLogger
{
public:
SQLLogger(const std::string sql, unsigned subsys, unsigned session, unsigned txn = 0, unsigned thread = 0);
SQLLogger(const std::string sql, const LoggingID& logId);
public:
SQLLogger(const std::string sql, unsigned subsys, unsigned session, unsigned txn = 0, unsigned thread = 0);
SQLLogger(const std::string sql, const LoggingID& logId);
~SQLLogger();
~SQLLogger();
std::string logMessage(logging::LOG_TYPE logLevel, const std::string& msg, logging::Message::MessageID mid = LogDefaultMsg );
std::string logMessage(logging::LOG_TYPE logLevel, const std::string& msg,
logging::Message::MessageID mid = LogDefaultMsg);
private:
void makeMsgMap();
MsgMap fMsgMap;
LoggingID fLogId;
bool fLog;
private:
void makeMsgMap();
MsgMap fMsgMap;
LoggingID fLogId;
bool fLog;
};
}
} // namespace logging

View File

@ -75,172 +75,167 @@ using namespace std;
namespace logging
{
void StopWatch::stop(const string& message)
{
stop(message, 1);
stop(message, 1);
}
bool StopWatch::stop(const string& message, const int limit)
{
gettimeofday(&fTvLast, 0);
fOpenCalls--;
bool found = false;
uint32_t idx = 0;
gettimeofday(&fTvLast, 0);
fOpenCalls--;
bool found = false;
uint32_t idx = 0;
for (uint32_t i = 0; i < fProcessStats.size(); i++)
for (uint32_t i = 0; i < fProcessStats.size(); i++)
{
if (fProcessStats[i].fProcess == message)
{
if (fProcessStats[i].fProcess == message)
{
idx = i;
found = true;
break;
}
idx = i;
found = true;
break;
}
}
if (!found)
{
//throw std::runtime_error("StopWatch::stop " + message + " called without calling start first.");
std::cerr << "StopWatch receiving STOP for unknown event: " << message << std::endl;
return false;
}
fProcessStats[idx].processStop();
if (fProcessStats[idx].fStopCount >= limit)
return true;
if (!found)
{
// throw std::runtime_error("StopWatch::stop " + message + " called without calling start first.");
std::cerr << "StopWatch receiving STOP for unknown event: " << message << std::endl;
return false;
}
fProcessStats[idx].processStop();
if (fProcessStats[idx].fStopCount >= limit)
return true;
return false;
}
void StopWatch::start(const string& message)
{
fOpenCalls++;
gettimeofday(&fTvLast, 0);
bool found = false;
uint32_t idx = 0;
ProcessStats processStats;
fOpenCalls++;
gettimeofday(&fTvLast, 0);
bool found = false;
uint32_t idx = 0;
ProcessStats processStats;
if (!fStarted)
if (!fStarted)
{
fStarted = true;
gettimeofday(&fTvStart, 0);
}
for (uint32_t i = 0; i < fProcessStats.size(); i++)
{
if (fProcessStats[i].fProcess == message)
{
fStarted = true;
gettimeofday(&fTvStart, 0);
idx = i;
found = true;
break;
}
}
for (uint32_t i = 0; i < fProcessStats.size(); i++)
{
if (fProcessStats[i].fProcess == message)
{
idx = i;
found = true;
break;
}
}
if (!found)
{
fProcessStats.push_back(processStats);
idx = fProcessStats.size() - 1;
}
if (!found)
{
fProcessStats.push_back(processStats);
idx = fProcessStats.size() - 1;
}
fProcessStats[idx].fProcess = message;
fProcessStats[idx].processStart();
fProcessStats[idx].fProcess = message;
fProcessStats[idx].processStart();
}
void StopWatch::finish()
{
ostringstream oss;
ostringstream oss;
oss << endl;
oss << "Seconds Percentage Calls Description" << endl;
oss << endl;
oss << "Seconds Percentage Calls Description" << endl;
// total seconds elapsed
double totalSeconds = 1.0;
// total seconds elapsed
double totalSeconds = 1.0;
// Add a last entry into the vector for total.
ProcessStats total;
total.fProcess = "Total";
// Add a last entry into the vector for total.
ProcessStats total;
total.fProcess = "Total";
if (fProcessStats.size() > 0)
if (fProcessStats.size() > 0)
{
// Calculate the total seconds elapsed.
totalSeconds =
(fTvLast.tv_sec + (fTvLast.tv_usec / 1000000.0)) - (fTvStart.tv_sec + (fTvStart.tv_usec / 1000000.0));
total.fTotalSeconds = totalSeconds;
total.fStartCount = 1;
}
else
{
total.fTotalSeconds = 0.0;
total.fStartCount = 0;
}
fProcessStats.push_back(total);
for (uint32_t i = 0; i < fProcessStats.size(); i++)
{
if (i == (fProcessStats.size() - 1))
{
// Calculate the total seconds elapsed.
totalSeconds =
(fTvLast.tv_sec + (fTvLast.tv_usec / 1000000.0)) -
(fTvStart.tv_sec + (fTvStart.tv_usec / 1000000.0));
total.fTotalSeconds = totalSeconds;
total.fStartCount = 1;
oss << endl;
}
// Seconds.
string seconds;
ostringstream ossTemp;
ossTemp << fProcessStats[i].fTotalSeconds;
seconds = ossTemp.str();
seconds.resize(11, ' ');
oss << seconds << " ";
// Percentage.
string percentage;
ossTemp.str(""); // clear the stream.
ossTemp << (fProcessStats[i].fTotalSeconds / totalSeconds) * 100.0;
percentage = ossTemp.str();
percentage.resize(11, ' ');
oss << percentage << "% ";
// Times Initiated.
ossTemp.str(""); // clear the stream.
ossTemp << fProcessStats[i].fStartCount;
string timesInitiated = ossTemp.str();
timesInitiated.resize(10, ' ');
oss << timesInitiated << " ";
// Description.
if (fId >= 0)
oss << fId << ": " << fProcessStats[i].fProcess << endl;
else
{
total.fTotalSeconds = 0.0;
total.fStartCount = 0;
}
oss << fProcessStats[i].fProcess << endl;
}
fProcessStats.push_back(total);
if (fOutputToFile)
{
ofstream profLog;
profLog.open(fLogFile.c_str(), std::ios::app);
for (uint32_t i = 0; i < fProcessStats.size(); i++)
{
// Output the date and time.
time_t t = time(0);
char timeString[50];
ctime_r(&t, timeString);
timeString[strlen(timeString) - 1] = '\0';
profLog << endl << timeString;
if (i == (fProcessStats.size() - 1))
{
oss << endl;
}
// Seconds.
string seconds;
ostringstream ossTemp;
ossTemp << fProcessStats[i].fTotalSeconds;
seconds = ossTemp.str();
seconds.resize(11, ' ');
oss << seconds << " ";
// Percentage.
string percentage;
ossTemp.str(""); // clear the stream.
ossTemp << (fProcessStats[i].fTotalSeconds / totalSeconds) * 100.0;
percentage = ossTemp.str();
percentage.resize(11, ' ');
oss << percentage << "% ";
// Times Initiated.
ossTemp.str(""); // clear the stream.
ossTemp << fProcessStats[i].fStartCount;
string timesInitiated = ossTemp.str();
timesInitiated.resize(10, ' ');
oss << timesInitiated << " ";
// Description.
if (fId >= 0)
oss << fId << ": " << fProcessStats[i].fProcess << endl;
else
oss << fProcessStats[i].fProcess << endl;
}
if (fOutputToFile)
{
ofstream profLog;
profLog.open(fLogFile.c_str(), std::ios::app);
// Output the date and time.
time_t t = time(0);
char timeString[50];
ctime_r(&t, timeString);
timeString[ strlen(timeString) - 1 ] = '\0';
profLog << endl << timeString;
// Output the stopwatch info.
profLog << oss.str();
}
else
{
cout << oss.str();
}
// Clear everything out.
fStarted = false;
fProcessStats.clear();
// Output the stopwatch info.
profLog << oss.str();
}
else
{
cout << oss.str();
}
// Clear everything out.
fStarted = false;
fProcessStats.clear();
}
} // end of logging namespace
} // namespace logging

View File

@ -73,67 +73,65 @@
namespace logging
{
class StopWatch
{
public:
void start(const std::string& message);
bool stop(const std::string& message, const int limit);
void stop(const std::string& message);
void finish();
public:
void start(const std::string& message);
bool stop(const std::string& message, const int limit);
void stop(const std::string& message);
void finish();
bool isActive()
bool isActive()
{
return fOpenCalls > 0;
}
StopWatch() : fStarted(false), fId(-1), fOpenCalls(0), fOutputToFile(false), fLogFile(""){};
StopWatch(int id) : fStarted(false), fId(id), fOpenCalls(0), fOutputToFile(false), fLogFile(""){};
StopWatch(const std::string& fileName)
: fStarted(false), fId(-1), fOpenCalls(0), fOutputToFile(true), fLogFile(fileName)
{
}
struct ::timeval fTvLast;
int getId()
{
return fId;
}
private:
class ProcessStats
{
public:
std::string fProcess;
struct timeval fTvProcessStarted;
double fTotalSeconds;
int64_t fStartCount;
int64_t fStopCount;
ProcessStats() : fProcess(""), fTotalSeconds(0.0), fStartCount(0), fStopCount(0){};
void processStart()
{
return fOpenCalls > 0;
}
StopWatch() : fStarted(false), fId(-1), fOpenCalls(0), fOutputToFile(false), fLogFile("") {};
StopWatch(int id) : fStarted(false), fId(id), fOpenCalls(0), fOutputToFile(false), fLogFile("") {};
StopWatch(const std::string& fileName) : fStarted(false), fId(-1), fOpenCalls(0), fOutputToFile(true), fLogFile(fileName) {}
struct ::timeval fTvLast;
int getId()
{
return fId;
gettimeofday(&fTvProcessStarted, 0);
fStartCount++;
}
private:
class ProcessStats
void processStop()
{
public:
struct timeval tvStop;
gettimeofday(&tvStop, 0);
fStopCount++;
fTotalSeconds += (tvStop.tv_sec + (tvStop.tv_usec / 1000000.0)) -
(fTvProcessStarted.tv_sec + (fTvProcessStarted.tv_usec / 1000000.0));
}
};
std::string fProcess;
struct timeval fTvProcessStarted;
double fTotalSeconds;
int64_t fStartCount;
int64_t fStopCount;
ProcessStats() : fProcess(""), fTotalSeconds(0.0), fStartCount(0), fStopCount(0) {};
void processStart()
{
gettimeofday(&fTvProcessStarted, 0);
fStartCount++;
}
void processStop()
{
struct timeval tvStop;
gettimeofday(&tvStop, 0);
fStopCount++;
fTotalSeconds +=
(tvStop.tv_sec + (tvStop.tv_usec / 1000000.0)) -
(fTvProcessStarted.tv_sec + (fTvProcessStarted.tv_usec / 1000000.0));
}
};
struct timeval fTvStart;
std::vector <ProcessStats> fProcessStats;
bool fStarted;
int fId;
int fOpenCalls;
bool fOutputToFile;
std::string fLogFile;
struct timeval fTvStart;
std::vector<ProcessStats> fProcessStats;
bool fStarted;
int fId;
int fOpenCalls;
bool fOutputToFile;
std::string fLogFile;
};
} // end of logging namespace
} // namespace logging

View File

@ -30,348 +30,343 @@ using namespace config;
class MessageLoggingTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(MessageLoggingTest);
CPPUNIT_TEST_SUITE( MessageLoggingTest );
CPPUNIT_TEST(m1);
CPPUNIT_TEST(m2);
CPPUNIT_TEST(m3);
CPPUNIT_TEST(m4);
CPPUNIT_TEST(m5);
CPPUNIT_TEST( m1 );
CPPUNIT_TEST( m2 );
CPPUNIT_TEST( m3 );
CPPUNIT_TEST( m4 );
CPPUNIT_TEST( m5 );
CPPUNIT_TEST_SUITE_END();
CPPUNIT_TEST_SUITE_END();
private:
LoggingID lid;
private:
LoggingID lid;
public:
void setUp()
{
setenv("CALPONT_CONFIG_FILE", "./Columnstore.xml", 1);
}
public:
void setUp()
void tearDown()
{
}
void m1()
{
Message::Args args;
args.add("hello");
args.add("world");
args.add(123);
args.add(1234.55);
Message m(100);
m.fMsg = "%1% %2% %3% %4%";
m.format(args);
// CPPUNIT_ASSERT(m.msg() == "hello world 123 1234.55");
m.reset();
m.fMsg = "%1% %2% %3% %4%";
args.reset();
m.format(args);
// CPPUNIT_ASSERT(m.msg() == " ");
LoggingID lid(7);
MessageLog ml(lid);
m.reset();
args.add("hello");
args.add("world");
args.add(123);
args.add(1234.55);
m.format(args);
ml.logDebugMessage(m);
args.reset();
args.add("begin CEP generation");
m.reset();
m.format(args);
ml.logInfoMessage(m);
args.reset();
args.add("end CEP generation");
m.reset();
m.format(args);
ml.logInfoMessage(m);
args.reset();
args.add("something took too long");
m.reset();
m.format(args);
ml.logWarningMessage(m);
args.reset();
args.add("something seriously took too long");
m.reset();
m.format(args);
ml.logSeriousMessage(m);
ml.logErrorMessage(m);
args.reset();
args.add("something critical took too long");
m.reset();
m.format(args);
ml.logCriticalMessage(m);
LoggingID lid1;
MessageLog ml1(lid1);
args.reset();
m.reset();
args.add("subsystem 0 = Calpont test");
m.format(args);
ml1.logDebugMessage(m);
LoggingID lid2(1000);
MessageLog ml2(lid2);
args.reset();
m.reset();
args.add("subsystem above MAX = Calpont test");
m.format(args);
ml2.logDebugMessage(m);
LoggingID lid3(7);
MessageLog ml3(lid3);
args.reset();
m.reset();
args.add("subsystem 7 = mcsadmin test");
m.format(args);
ml3.logDebugMessage(m);
Config::deleteInstanceMap();
}
void m2()
{
Message m1(100);
CPPUNIT_ASSERT(m1.msgID() == 100);
Message m2(10);
CPPUNIT_ASSERT(m2.msgID() == 10);
m2 = m1;
CPPUNIT_ASSERT(m2.msgID() == 100);
Message m3(m2);
CPPUNIT_ASSERT(m3.msgID() == m2.msgID());
Message m4(99);
Message m5(199);
CPPUNIT_ASSERT(m4.msgID() == 99);
CPPUNIT_ASSERT(m5.msgID() == 199);
m4.swap(m5);
CPPUNIT_ASSERT(m5.msgID() == 99);
CPPUNIT_ASSERT(m4.msgID() == 199);
Config::deleteInstanceMap();
}
void m3()
{
LoggingID lid1(1, 2, 3, 4);
MessageLog ml1(lid1);
CPPUNIT_ASSERT(ml1.fLogData.fSubsysID == 1);
LoggingID lid2(10, 20, 30, 40);
MessageLog ml2(lid2);
CPPUNIT_ASSERT(ml2.fLogData.fSubsysID == 10);
ml2 = ml1;
CPPUNIT_ASSERT(ml2.fLogData.fSubsysID == 1);
MessageLog ml3(ml2);
CPPUNIT_ASSERT(ml3.fLogData.fSubsysID == 1);
Config::deleteInstanceMap();
}
void m4()
{
LoggingID lid1(100, 200, 300, 400);
MessageLog ml1(lid1);
Message::Args args;
Message* m;
args.add("hello");
args.add("world");
args.add(123);
args.add(1234.55);
for (int i = 0; i < 4; i++)
{
setenv("CALPONT_CONFIG_FILE", "./Columnstore.xml", 1);
m = new Message(i);
m->format(args);
ml1.logDebugMessage(*m);
delete m;
}
void tearDown()
Config::deleteInstanceMap();
}
//------------------------------------------------------------------------------
// This method is intended to test the messages used to profile db performance.
// The method also provides an example on how to use these log messages.
// Test can be verified by viewing /var/log/mariadb/columnstore/debug.log.
//
// Message types are:
//
// 26 Start Transaction
// 27 End Transaction
// 28 Start Statement
// 29 End Statement
// 30 Start Step
// 31 End Step
// 32 I/O Reads
//
// The messages should be logged in the following way:
//
// 1. The application should log a StartTransaction message at the beginning
// of a database transaction.
// 2. When the application begins processing a statement, the StartStatement
// message should be logged.
// 3. As each primitive step is executed, it's start time should be recorded
// by logging a StartStep message.
// 4. During the execution of a step, 1 or more I/O Read messages should be
// logged to record the I/O block count used in accessing each object. If
// necessary, more than 1 message can be logged for the same object and
// step. In these cases, the script that post-processes the syslog will
// add up the block counts for the same object and step.
// 5. Upon completion of each primitive step, an EndStep message should be
// logged. If multiple steps are executing in parallel, the EndStep msg
// should be logged as each step completes. After all these stpes are
// completed and logged, if needed, a new set of StartStep messages can
// be logged (for the same statement), for a new set of parallel steps.
// 6. Upon completion of each statement, an EndStatement msg should be logged.
// 7. Upon completion of each transaction, an EndTransaction msg should
// be logged.
//
// Some possible enhancements to simplify this profile logging for the
// application programmer:
//
// 1. Define enum or const ints in a common header file to represent the
// list of valid subSystem ids.
//
// 2. Add set of helper methods to MessageLog class to reduce the
// amount of work for the application. For example a method like:
//
// void logStartStatement ( int statement, int ver, string SQL );
//
// would allow the application to log a StartStatement by simply doing;
//
// Message msgStartStatement ( M0028 );
// int statementId = 11;
// int versionId = 22;
// string sql ("SELECT column1, column2 FROM table1 WHERE ...
// msgStartStatement.logStartStatement ( statementId, versionId, sql);
//
// 3. Could also do something similar to #2 except instead of adding helper
// methods to MessageLog, we could add specialized classes that derive
// from MessageLog or contain a MessageLog. One advantage of doing it
// this way is that a derived class like MessageLogStatement "could" be
// implemented to log the StartStatement, and its desctructor could then
// log the EndStatement automatically, on behalf of the application.
//
//------------------------------------------------------------------------------
void m5()
{
int subSystem = 5; // joblist subSystem
int session = 100;
int transaction = 1;
int thread = 0;
LoggingID lid1(subSystem, session, transaction, thread);
MessageLog msgLog(lid1);
Message::Args args;
// Log the start time of a transaction
Message msgStartTrans(M0026);
msgStartTrans.format(args);
msgLog.logDebugMessage(msgStartTrans);
// Log the start of execution time for a SQL statement
Message msgStartStatement(M0028);
int statementId = 11;
int versionId = 22;
string sql("SELECT column1, column2 FROM table1 WHERE column1 = 345");
args.reset();
args.add(statementId);
args.add(versionId);
args.add(sql);
msgStartStatement.format(args);
msgLog.logDebugMessage(msgStartStatement);
const string stepNames[] = {"steponeA", "steptwoA", "stepthreeA", "stepfourB", "stepfiveB", "stepsixB"};
// To process this SQL statement, simulate executing 2 job steps,
// with each job step consisting of of 3 parallel primitive steps
for (int jobStep = 0; jobStep < 2; jobStep++)
{
int primStep1 = jobStep * 3;
// Log 3 parallel steps starting to execute
for (int i = primStep1; i < (primStep1 + 3); i++)
{
Message msgStartStep(M0030); // Start Step
int stepId = i + 1;
string stepName = stepNames[i];
args.reset();
args.add(statementId);
args.add(stepId);
args.add(stepName);
msgStartStep.format(args);
msgLog.logDebugMessage(msgStartStep);
}
// Record I/O block count for 0 or more objects per step;
// for this example we just record I/O for 1 object per step.
// Then log the completion of each step.
for (int i = primStep1; i < (primStep1 + 3); i++)
{
Message msgBlockCount(M0032); // I/O block count
int stepId = i + 1;
int objectId = stepId * 20;
int phyCount = stepId * 30;
int logCount = phyCount + 5;
args.reset();
args.add(statementId);
args.add(stepId);
args.add(objectId);
args.add(phyCount);
args.add(logCount);
msgBlockCount.format(args);
msgLog.logDebugMessage(msgBlockCount);
Message msgEndStep(M0031); // End Step
args.reset();
args.add(statementId);
args.add(stepId);
msgEndStep.format(args);
msgLog.logDebugMessage(msgEndStep);
}
}
void m1()
{
Message::Args args;
args.add("hello");
args.add("world");
args.add(123);
args.add(1234.55);
Message m(100);
m.fMsg = "%1% %2% %3% %4%";
m.format(args);
//CPPUNIT_ASSERT(m.msg() == "hello world 123 1234.55");
m.reset();
m.fMsg = "%1% %2% %3% %4%";
args.reset();
m.format(args);
//CPPUNIT_ASSERT(m.msg() == " ");
LoggingID lid(7);
MessageLog ml(lid);
m.reset();
args.add("hello");
args.add("world");
args.add(123);
args.add(1234.55);
m.format(args);
ml.logDebugMessage(m);
// Log the completion time of the SQL statement
Message msgEndStatement(M0029);
args.reset();
args.add(statementId);
msgEndStatement.format(args);
msgLog.logDebugMessage(msgEndStatement);
args.reset();
args.add("begin CEP generation");
m.reset();
m.format(args);
ml.logInfoMessage(m);
// Log the completion time of the transaction
Message msgEndTrans(M0027);
args.reset();
args.add(string("COMMIT"));
msgEndTrans.format(args);
msgLog.logDebugMessage(msgEndTrans);
Config::deleteInstanceMap();
}
args.reset();
args.add("end CEP generation");
m.reset();
m.format(args);
ml.logInfoMessage(m);
}; // end of CppUnit::TestFixture class
args.reset();
args.add("something took too long");
m.reset();
m.format(args);
ml.logWarningMessage(m);
args.reset();
args.add("something seriously took too long");
m.reset();
m.format(args);
ml.logSeriousMessage(m);
ml.logErrorMessage(m);
args.reset();
args.add("something critical took too long");
m.reset();
m.format(args);
ml.logCriticalMessage(m);
LoggingID lid1;
MessageLog ml1(lid1);
args.reset();
m.reset();
args.add("subsystem 0 = Calpont test");
m.format(args);
ml1.logDebugMessage(m);
LoggingID lid2(1000);
MessageLog ml2(lid2);
args.reset();
m.reset();
args.add("subsystem above MAX = Calpont test");
m.format(args);
ml2.logDebugMessage(m);
LoggingID lid3(7);
MessageLog ml3(lid3);
args.reset();
m.reset();
args.add("subsystem 7 = mcsadmin test");
m.format(args);
ml3.logDebugMessage(m);
Config::deleteInstanceMap();
}
void m2()
{
Message m1(100);
CPPUNIT_ASSERT(m1.msgID() == 100);
Message m2(10);
CPPUNIT_ASSERT(m2.msgID() == 10);
m2 = m1;
CPPUNIT_ASSERT(m2.msgID() == 100);
Message m3(m2);
CPPUNIT_ASSERT(m3.msgID() == m2.msgID());
Message m4(99);
Message m5(199);
CPPUNIT_ASSERT(m4.msgID() == 99);
CPPUNIT_ASSERT(m5.msgID() == 199);
m4.swap(m5);
CPPUNIT_ASSERT(m5.msgID() == 99);
CPPUNIT_ASSERT(m4.msgID() == 199);
Config::deleteInstanceMap();
}
void m3()
{
LoggingID lid1(1, 2, 3, 4);
MessageLog ml1(lid1);
CPPUNIT_ASSERT(ml1.fLogData.fSubsysID == 1);
LoggingID lid2(10, 20, 30, 40);
MessageLog ml2(lid2);
CPPUNIT_ASSERT(ml2.fLogData.fSubsysID == 10);
ml2 = ml1;
CPPUNIT_ASSERT(ml2.fLogData.fSubsysID == 1);
MessageLog ml3(ml2);
CPPUNIT_ASSERT(ml3.fLogData.fSubsysID == 1);
Config::deleteInstanceMap();
}
void m4()
{
LoggingID lid1(100, 200, 300, 400);
MessageLog ml1(lid1);
Message::Args args;
Message* m;
args.add("hello");
args.add("world");
args.add(123);
args.add(1234.55);
for (int i = 0; i < 4; i++)
{
m = new Message(i);
m->format(args);
ml1.logDebugMessage(*m);
delete m;
}
Config::deleteInstanceMap();
}
//------------------------------------------------------------------------------
// This method is intended to test the messages used to profile db performance.
// The method also provides an example on how to use these log messages.
// Test can be verified by viewing /var/log/mariadb/columnstore/debug.log.
//
// Message types are:
//
// 26 Start Transaction
// 27 End Transaction
// 28 Start Statement
// 29 End Statement
// 30 Start Step
// 31 End Step
// 32 I/O Reads
//
// The messages should be logged in the following way:
//
// 1. The application should log a StartTransaction message at the beginning
// of a database transaction.
// 2. When the application begins processing a statement, the StartStatement
// message should be logged.
// 3. As each primitive step is executed, it's start time should be recorded
// by logging a StartStep message.
// 4. During the execution of a step, 1 or more I/O Read messages should be
// logged to record the I/O block count used in accessing each object. If
// necessary, more than 1 message can be logged for the same object and
// step. In these cases, the script that post-processes the syslog will
// add up the block counts for the same object and step.
// 5. Upon completion of each primitive step, an EndStep message should be
// logged. If multiple steps are executing in parallel, the EndStep msg
// should be logged as each step completes. After all these stpes are
// completed and logged, if needed, a new set of StartStep messages can
// be logged (for the same statement), for a new set of parallel steps.
// 6. Upon completion of each statement, an EndStatement msg should be logged.
// 7. Upon completion of each transaction, an EndTransaction msg should
// be logged.
//
// Some possible enhancements to simplify this profile logging for the
// application programmer:
//
// 1. Define enum or const ints in a common header file to represent the
// list of valid subSystem ids.
//
// 2. Add set of helper methods to MessageLog class to reduce the
// amount of work for the application. For example a method like:
//
// void logStartStatement ( int statement, int ver, string SQL );
//
// would allow the application to log a StartStatement by simply doing;
//
// Message msgStartStatement ( M0028 );
// int statementId = 11;
// int versionId = 22;
// string sql ("SELECT column1, column2 FROM table1 WHERE ...
// msgStartStatement.logStartStatement ( statementId, versionId, sql);
//
// 3. Could also do something similar to #2 except instead of adding helper
// methods to MessageLog, we could add specialized classes that derive
// from MessageLog or contain a MessageLog. One advantage of doing it
// this way is that a derived class like MessageLogStatement "could" be
// implemented to log the StartStatement, and its desctructor could then
// log the EndStatement automatically, on behalf of the application.
//
//------------------------------------------------------------------------------
void m5()
{
int subSystem = 5; // joblist subSystem
int session = 100;
int transaction = 1;
int thread = 0;
LoggingID lid1 ( subSystem, session, transaction, thread );
MessageLog msgLog ( lid1 );
Message::Args args;
// Log the start time of a transaction
Message msgStartTrans ( M0026 );
msgStartTrans.format ( args );
msgLog.logDebugMessage ( msgStartTrans );
// Log the start of execution time for a SQL statement
Message msgStartStatement ( M0028 );
int statementId = 11;
int versionId = 22;
string sql ("SELECT column1, column2 FROM table1 WHERE column1 = 345");
args.reset ( );
args.add ( statementId );
args.add ( versionId );
args.add ( sql );
msgStartStatement.format ( args );
msgLog.logDebugMessage ( msgStartStatement );
const string stepNames[] = { "steponeA", "steptwoA", "stepthreeA",
"stepfourB", "stepfiveB", "stepsixB"
};
// To process this SQL statement, simulate executing 2 job steps,
// with each job step consisting of of 3 parallel primitive steps
for (int jobStep = 0; jobStep < 2; jobStep++)
{
int primStep1 = jobStep * 3;
// Log 3 parallel steps starting to execute
for (int i = primStep1; i < (primStep1 + 3); i++)
{
Message msgStartStep ( M0030 ); // Start Step
int stepId = i + 1;
string stepName = stepNames[i];
args.reset ( );
args.add ( statementId );
args.add ( stepId );
args.add ( stepName );
msgStartStep.format ( args );
msgLog.logDebugMessage ( msgStartStep );
}
// Record I/O block count for 0 or more objects per step;
// for this example we just record I/O for 1 object per step.
// Then log the completion of each step.
for (int i = primStep1; i < (primStep1 + 3); i++)
{
Message msgBlockCount ( M0032 ); // I/O block count
int stepId = i + 1;
int objectId = stepId * 20;
int phyCount = stepId * 30;
int logCount = phyCount + 5;
args.reset ( );
args.add ( statementId );
args.add ( stepId );
args.add ( objectId );
args.add ( phyCount );
args.add ( logCount );
msgBlockCount.format ( args );
msgLog.logDebugMessage ( msgBlockCount );
Message msgEndStep ( M0031 ); // End Step
args.reset ( );
args.add ( statementId );
args.add ( stepId );
msgEndStep.format ( args );
msgLog.logDebugMessage ( msgEndStep );
}
}
// Log the completion time of the SQL statement
Message msgEndStatement ( M0029 );
args.reset ( );
args.add ( statementId );
msgEndStatement.format ( args );
msgLog.logDebugMessage ( msgEndStatement );
// Log the completion time of the transaction
Message msgEndTrans ( M0027 );
args.reset ( );
args.add ( string("COMMIT") );
msgEndTrans.format ( args );
msgLog.logDebugMessage ( msgEndTrans );
Config::deleteInstanceMap();
}
}; // end of CppUnit::TestFixture class
CPPUNIT_TEST_SUITE_REGISTRATION( MessageLoggingTest );
CPPUNIT_TEST_SUITE_REGISTRATION(MessageLoggingTest);
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main( int argc, char** argv)
int main(int argc, char** argv)
{
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false );
return (wasSuccessful ? 0 : 1);
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest(registry.makeTest());
bool wasSuccessful = runner.run("", false);
return (wasSuccessful ? 0 : 1);
}