提交 27b5f847 编写于 作者: X xiaoyi.yl

Merge branch add_field into master

        Title: add field 

补充oblogmsg 3.3版本字段
        Link: https://code.alibaba-inc.com/oceanbase-ce-publish/oblogmsg/codereview/10439774
......@@ -70,6 +70,9 @@ public:
virtual const char* getName();
virtual int getType();
virtual long getLength();
virtual const char* getOriginType();
virtual long getPrecision();
virtual long getScale();
virtual bool isSigned();
virtual bool isPK();
virtual bool isRuleCol();
......@@ -87,6 +90,9 @@ public:
virtual void setName(const char* name);
virtual void setType(int type);
virtual void setLength(long length);
virtual void setOriginType(const char* origin);
virtual void setPrecision(long precision);
virtual void setScale(long scale);
virtual void setSigned(bool b);
virtual void setIsPK(bool b);
virtual void setIsRuleCol(bool b);
......@@ -170,6 +176,10 @@ public:
const std::string& getSignedData();
const std::string& getDecimalsData();
const std::string& getDefaultData();
const std::string& getColLengthData();
const std::string& getOriginTypeData();
const std::string& getColPrecisionData();
const std::string& getColScaleData();
public:
/**
......@@ -247,6 +257,10 @@ private:
std::string m_colSignedData;
std::string m_colDecimalsData;
std::string m_colDefaultData;
std::string m_colLengthData;
std::string m_colOriginTypeData;
std::string m_colPrecisionData;
std::string m_colScaleData;
pthread_mutex_t m_mdMutex;
bool m_DataOk;
......
......@@ -85,6 +85,12 @@ struct PosOfLogMsg_v3_2 : public PosOfLogMsg_v3_1 {
uint32_t m_posOfObTraceInfo;
int32_t m_sqlNo;
};
struct PosOfLogMsg_v3_3 : public PosOfLogMsg_v3_2 {
uint32_t m_posOfLengthsOffset;
uint32_t m_posOfOriginTypesOffset;
uint32_t m_posOfPrecisionsOffset;
uint32_t m_posOfScalesOffset;
};
struct EndOfLogMsg_v1 {
uint32_t m_threadId;
uint32_t m_usec;
......@@ -93,7 +99,7 @@ struct EndOfLogMsg_v2 : public EndOfLogMsg_v1 {
uint32_t m_crc;
};
/* Currently used version of PosOfLogMsg */
typedef struct PosOfLogMsg_v3_2 PosOfLogMsg_vc;
typedef struct PosOfLogMsg_v3_3 PosOfLogMsg_vc;
/* PosOfLogMsg versions listed */
typedef struct PosOfLogMsg_vb PosOfLogMsg;
......@@ -142,7 +148,7 @@ struct LogRecInfo {
string m_instance;
string m_encoding;
string m_ob_trace_info;
bool useLMB;
bool useLMB;
bool m_reservedMemory;
LogRecInfo(time_t timestamp, ITableMeta* tblMeta)
: m_creatingMode(true),
......@@ -228,7 +234,7 @@ struct LogRecInfo {
m_posInfo->m_srcCategory = SRC_FULL_RECORDED;
this->useLMB = useLMB;
} else {
this->useLMB= false;
this->useLMB = false;
m_lrDataArea = new MsgVarArea(false);
}
m_reservedMemory = false;
......@@ -453,6 +459,11 @@ struct LogRecInfo {
((PosOfLogMsg_v3_2*)v)->m_posOfColDefault = toLeEndianByType(((PosOfLogMsg_v3_2*)v)->m_posOfColDefault);
((PosOfLogMsg_v3_2*)v)->m_posOfObTraceInfo = toLeEndianByType(((PosOfLogMsg_v3_2*)v)->m_posOfObTraceInfo);
((PosOfLogMsg_v3_2*)v)->m_sqlNo = toLeEndianByType(((PosOfLogMsg_v3_2*)v)->m_sqlNo);
((PosOfLogMsg_v3_3*)v)->m_posOfLengthsOffset = toLeEndianByType(((PosOfLogMsg_v3_3*)v)->m_posOfLengthsOffset);
((PosOfLogMsg_v3_3*)v)->m_posOfOriginTypesOffset = toLeEndianByType(((PosOfLogMsg_v3_3*)v)->m_posOfOriginTypesOffset);
((PosOfLogMsg_v3_3*)v)->m_posOfPrecisionsOffset = toLeEndianByType(((PosOfLogMsg_v3_3*)v)->m_posOfPrecisionsOffset);
((PosOfLogMsg_v3_3*)v)->m_posOfScalesOffset = toLeEndianByType(((PosOfLogMsg_v3_3*)v)->m_posOfScalesOffset);
}
int parse(const void* ptr, size_t size)
......@@ -776,6 +787,66 @@ struct LogRecInfo {
}
return NULL;
}
const int64_t* colLengths() const
{
if (m_parsedOK) {
const void* v;
size_t elSize, count;
int ret = m_lrDataArea->getArray((GET_LOGREC_SUB_VERSION(m_posInfo->m_id) >= LOGREC_SUB_VERSION)
? ((PosOfLogMsg_v3_3*)m_posInfo)->m_posOfLengthsOffset
: -1,
v,
elSize,
count);
if (ret != 0 || elSize != sizeof(int64_t))
return NULL;
return (int64_t*)v;
}
return NULL;
}
StrArray* colOriginTypes() const
{
if (m_parsedOK) {
return m_lrDataArea->getStringArray((GET_LOGREC_SUB_VERSION(m_posInfo->m_id) >= LOGREC_SUB_VERSION)
? ((PosOfLogMsg_v3_3*)m_posInfo)->m_posOfOriginTypesOffset
: -1);
}
return NULL;
}
const int64_t* colPrecisions() const
{
if (m_parsedOK) {
const void* v;
size_t elSize, count;
int ret = m_lrDataArea->getArray((GET_LOGREC_SUB_VERSION(m_posInfo->m_id) >= LOGREC_SUB_VERSION)
? ((PosOfLogMsg_v3_3*)m_posInfo)->m_posOfPrecisionsOffset
: -1,
v,
elSize,
count);
if (ret != 0 || elSize != sizeof(int64_t))
return NULL;
return (int64_t*)v;
}
return NULL;
}
const int64_t* colScales() const
{
if (m_parsedOK) {
const void* v;
size_t elSize, count;
int ret = m_lrDataArea->getArray((GET_LOGREC_SUB_VERSION(m_posInfo->m_id) >= LOGREC_SUB_VERSION)
? ((PosOfLogMsg_v3_3*)m_posInfo)->m_posOfScalesOffset
: -1,
v,
elSize,
count);
if (ret != 0 || elSize != sizeof(int64_t))
return NULL;
return (int64_t*)v;
}
return NULL;
}
// get default value for all columns
int setRecordType(int aType)
......@@ -959,6 +1030,22 @@ struct LogRecInfo {
{
((PosOfLogMsg_vc*)m_posInfo)->m_posOfColDecimals = m_lrDataArea->appendData(data);
}
void setColLengths(const std::string& data)
{
((PosOfLogMsg_vc*)m_posInfo)->m_posOfLengthsOffset = m_lrDataArea->appendData(data);
}
void setColOriginTypes(const std::string& data)
{
((PosOfLogMsg_vc*)m_posInfo)->m_posOfOriginTypesOffset = m_lrDataArea->appendData(data);
}
void setColPrecisions(const std::string& data)
{
((PosOfLogMsg_vc*)m_posInfo)->m_posOfPrecisionsOffset = m_lrDataArea->appendData(data);
}
void setColScales(const std::string& data)
{
((PosOfLogMsg_vc*)m_posInfo)->m_posOfScalesOffset = m_lrDataArea->appendData(data);
}
void setColDefault(const std::string& data)
{
((PosOfLogMsg_vc*)m_posInfo)->m_posOfColDefault = m_lrDataArea->appendData(data);
......@@ -1311,6 +1398,10 @@ struct LogRecInfo {
((PosOfLogMsg_vc*)m_posInfo)->m_posOfColNotNull = lmb->appendBuf(m_tblMeta->getNotNullData());
((PosOfLogMsg_vc*)m_posInfo)->m_posOfColSigned = lmb->appendBuf(m_tblMeta->getSignedData());
((PosOfLogMsg_vc*)m_posInfo)->m_posOfColDecimals = lmb->appendBuf(m_tblMeta->getDecimalsData());
((PosOfLogMsg_vc*)m_posInfo)->m_posOfLengthsOffset = lmb->appendBuf(m_tblMeta->getColLengthData());
((PosOfLogMsg_vc*)m_posInfo)->m_posOfOriginTypesOffset = lmb->appendBuf(m_tblMeta->getOriginTypeData());
((PosOfLogMsg_vc*)m_posInfo)->m_posOfPrecisionsOffset = lmb->appendBuf(m_tblMeta->getColPrecisionData());
((PosOfLogMsg_vc*)m_posInfo)->m_posOfScalesOffset = lmb->appendBuf(m_tblMeta->getColScaleData());
if (!m_timemarks.empty())
((PosOfLogMsg_vc*)m_posInfo)->m_posOfTimemark = lmb->appendDataArray(m_timemarks);
} else {
......@@ -1326,6 +1417,10 @@ struct LogRecInfo {
setColNotNull(m_tblMeta->getNotNullData());
setColSigned(m_tblMeta->getSignedData());
setColDecimals(m_tblMeta->getDecimalsData());
setColLengths(m_tblMeta->getColLengthData());
setColOriginTypes(m_tblMeta->getOriginTypeData());
setColPrecisions(m_tblMeta->getColPrecisionData());
setColScales(m_tblMeta->getColScaleData());
/* Serialize timemarks if needed */
if (!m_timemarks.empty())
setTimemarks();
......@@ -1807,6 +1902,10 @@ int LogRecordImpl::getTableMeta(ITableMeta*& tblMeta)
const uint8_t* colNotNull = m_lr->colNotNull();
const uint8_t* colSigned = m_lr->colSigned();
const int32_t* colDecimals = m_lr->colDecimals();
const int64_t* colLengths = m_lr->colLengths();
StrArray* colOriginTypes = m_lr->colOriginTypes();
const int64_t* colPrecisions = m_lr->colPrecisions();
const int64_t* colScales = m_lr->colScales();
const std::vector<int> pkIndice = m_lr->pkKeys();
size_t pkSize = pkIndice.size();
const std::vector<int> ukIndice = m_lr->ukKeys();
......@@ -1838,6 +1937,18 @@ int LogRecordImpl::getTableMeta(ITableMeta*& tblMeta)
if (colDecimals != NULL) {
colMeta->setDecimals(toLeEndianByType(colDecimals[i]));
}
if (colLengths != NULL) {
colMeta->setLength(colLengths[i]);
}
if (colOriginTypes != NULL) {
colMeta->setOriginType((*colOriginTypes)[i]);
}
if (colPrecisions != NULL) {
colMeta->setPrecision(colPrecisions[i]);
}
if (colScales != NULL) {
colMeta->setScale(colScales[i]);
}
/*
if (colDefault != NULL) {
colMeta->setDefault((*colDefault)[i]);
......
......@@ -158,6 +158,9 @@ struct ColMetaHeader {
uint32_t m_encOffset;
uint32_t m_enumSetOffset;
uint8_t m_flag;
int64_t m_precision;
int64_t m_scale;
uint32_t m_originTypeOffset;
};
struct ColMetaInfo : public MetaInfo {
......@@ -173,6 +176,9 @@ struct ColMetaInfo : public MetaInfo {
m_colMetaHeader->m_isUK = false;
m_colMetaHeader->m_notNull = false;
m_colMetaHeader->m_flag = 0;
m_colMetaHeader->m_originTypeOffset = -1;
m_colMetaHeader->m_precision = -1;
m_colMetaHeader->m_scale = -1;
}
ColMetaInfo(const void* ptr, size_t size)
......@@ -228,6 +234,21 @@ long IColMeta::getLength()
return m_col->m_colMetaHeader->m_length;
}
const char* IColMeta::getOriginType()
{
return m_col->m_data.getString(m_col->m_colMetaHeader->m_originTypeOffset);
}
long IColMeta::getPrecision()
{
return m_col->m_colMetaHeader->m_precision;
}
long IColMeta::getScale()
{
return m_col->m_colMetaHeader->m_scale;
}
bool IColMeta::isSigned()
{
return m_col->m_colMetaHeader->m_signed;
......@@ -300,6 +321,21 @@ void IColMeta::setLength(long length)
m_col->m_colMetaHeader->m_length = length;
}
void IColMeta::setOriginType(const char* origin)
{
m_col->m_colMetaHeader->m_originTypeOffset = m_col->m_data.appendString(origin);
}
void IColMeta::setPrecision(long precision)
{
m_col->m_colMetaHeader->m_precision = precision;
}
void IColMeta::setScale(long scale)
{
m_col->m_colMetaHeader->m_scale = scale;
}
void IColMeta::setSigned(bool b)
{
m_col->m_colMetaHeader->m_signed = b;
......@@ -1110,13 +1146,19 @@ void ITableMeta::trySerializeMetaDataAsMsgArea(std::vector<const char*>& extra_i
m_colNameData = MsgVarArea::createStringArrayData(getColNames());
int colcount = getColCount();
std::vector<std::string> colencoding;
std::vector<std::string> originTypes;
for (int i = 0; i < colcount; i++) {
IColMeta* colmeta = getCol(i);
std::string colenc = colmeta->getEncoding();
const char* originType = colmeta->getOriginType();
colencoding.push_back(colenc);
if (originType != NULL) {
originTypes.push_back(originType);
}
}
m_encodingData = MsgVarArea::createStringArrayData(colencoding);
m_colOriginTypeData = MsgVarArea::createStringArrayData(originTypes);
/**
* Set the list of primary keys delimited by comma
......@@ -1161,6 +1203,9 @@ void ITableMeta::trySerializeMetaDataAsMsgArea(std::vector<const char*>& extra_i
uint8_t* col_not_null = new uint8_t[colcount];
uint8_t* col_signed = new uint8_t[colcount];
int32_t* col_decimals = new int32_t[colcount];
int64_t* col_length = new int64_t[colcount];
int64_t* col_precision = new int64_t[colcount];
int64_t* col_scale = new int64_t[colcount];
for (int i = 0; i < getColCount(); i++) {
col_types[i] = (getCol(i)->getType());
......@@ -1168,12 +1213,18 @@ void ITableMeta::trySerializeMetaDataAsMsgArea(std::vector<const char*>& extra_i
col_not_null[i] = getCol(i)->isNotNull();
col_signed[i] = getCol(i)->isSigned();
col_decimals[i] = getCol(i)->getDecimals();
col_length[i] = getCol(i)->getLength();
col_precision[i] = getCol(i)->getPrecision();
col_scale[i] = getCol(i)->getScale();
}
m_colTypeData = MsgVarArea::createArrayData(col_types, colcount);
m_columnFlagData = MsgVarArea::createArrayData(col_flags, colcount);
m_colNotNullData = MsgVarArea::createArrayData(col_not_null, colcount);
m_colSignedData = MsgVarArea::createArrayData(col_signed, colcount);
m_colDecimalsData = MsgVarArea::createArrayData(col_decimals, colcount);
m_colLengthData = MsgVarArea::createArrayData(col_length, colcount);
m_colPrecisionData = MsgVarArea::createArrayData(col_precision, colcount);
m_colScaleData = MsgVarArea::createArrayData(col_scale, colcount);
delete[] col_types;
delete[] col_flags;
......@@ -1230,6 +1281,22 @@ const std::string& ITableMeta::getDefaultData()
{
return m_colDefaultData;
}
const std::string& ITableMeta::getColLengthData()
{
return m_colLengthData;
}
const std::string& ITableMeta::getOriginTypeData()
{
return m_colOriginTypeData;
}
const std::string& ITableMeta::getColPrecisionData()
{
return m_colPrecisionData;
}
const std::string& ITableMeta::getColScaleData()
{
return m_colScaleData;
}
// ------------------DBMeta----------------
struct DBMetaHeader {
......
......@@ -40,6 +40,9 @@ IColMeta* createColMeta(const char* name, int type, int length)
colMeta->setDefault(DEF);
colMeta->setEncoding(ENC);
colMeta->setGenerated(true);
colMeta->setOriginType("varchar");
colMeta->setPrecision(5);
colMeta->setScale(3);
return colMeta;
}
......
......@@ -37,6 +37,9 @@ IColMeta* createColMeta(const char* name, int type, int length)
colMeta->setDefault(DEF);
colMeta->setEncoding(ENC);
colMeta->setGenerated(true);
colMeta->setOriginType("varchar");
colMeta->setPrecision(5);
colMeta->setScale(4);
return colMeta;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册