[4.2.1>master] finetune ENABLE_SERIALIZATION_CHECK

This commit is contained in:
zhjc1124
2024-02-08 13:18:21 +00:00
committed by ob-robot
parent b6a15b6111
commit f636b2fdd1
12 changed files with 47 additions and 26 deletions

View File

@ -291,11 +291,6 @@ const char *to_cstring<int64_t>(const int64_t &v)
return to_cstring<int64_t>(v, BoolType<false>());
}
const char *to_cstring(const int64_t v)
{
return to_cstring<int64_t>(v, BoolType<false>());
}
////////////////////////////////////////////////////////////////
int databuff_printf(char *buf, const int64_t buf_len, const char *fmt, ...)

View File

@ -272,8 +272,6 @@ const char *to_cstring<const char *>(const char *const &str);
template <>
const char *to_cstring<int64_t>(const int64_t &v);
const char *to_cstring(const int64_t v);
template <typename T>
const char *to_cstring(T *obj)
{

View File

@ -22,19 +22,19 @@ void begin_record_serialization()
{
ser_diag_record.count = 0;
ser_diag_record.check_index = 0;
ser_diag_record.flag = 1;
ser_diag_record.flag = CHECK_STATUS_RECORDING;
}
void finish_record_serialization()
{
ser_diag_record.flag = 0;
ser_diag_record.flag = CHECK_STATUS_WATING;
}
void begin_check_serialization()
{
ser_diag_record.check_index = 0;
if (ser_diag_record.count > 0) {
ser_diag_record.flag = 2;
ser_diag_record.flag = CHECK_STATUS_COMPARING;
}
}
@ -42,8 +42,9 @@ void finish_check_serialization()
{
ser_diag_record.count = -1;
ser_diag_record.check_index = -1;
ser_diag_record.flag = 0;
ser_diag_record.flag = CHECK_STATUS_WATING;
}
} // namespace lib
} // namespace oceanbase
#endif

View File

@ -21,13 +21,19 @@ namespace lib
{
#ifdef ENABLE_SERIALIZATION_CHECK
enum ObSerializationCheckStatus
{
CHECK_STATUS_WATING = 0,
CHECK_STATUS_RECORDING = 1,
CHECK_STATUS_COMPARING = 2
};
static constexpr int MAX_SERIALIZE_RECORD_LENGTH = 256;
struct SerializeDiagnoseRecord
{
uint8_t encoded_lens[MAX_SERIALIZE_RECORD_LENGTH];
int count = -1;
int check_index = -1;
int flag = 0;
int flag = CHECK_STATUS_WATING;
};
RLOCAL_EXTERN(SerializeDiagnoseRecord, ser_diag_record);
void begin_record_serialization();
@ -78,21 +84,31 @@ void finish_check_serialization();
}
#ifdef ENABLE_SERIALIZATION_CHECK
#define IF_TYPE_MATCH(obj, type) \
std::is_same<type, decltype(obj)>::value || std::is_same<type &, decltype(obj)>::value
#define IF_NEED_TO_CHECK_SERIALIZATION(obj) \
!(std::is_const<decltype(obj)>::value || \
IF_TYPE_MATCH(obj, uint8_t) || \
IF_TYPE_MATCH(obj, int8_t) || \
IF_TYPE_MATCH(obj, bool) || \
IF_TYPE_MATCH(obj, char))
#define OB_UNIS_ADD_LEN(obj) \
{ \
int64_t this_len = NS_::encoded_length(obj); \
if (!(std::is_same<uint8_t, decltype(obj)>::value || std::is_same<int8_t, decltype(obj)>::value || \
std::is_same<bool, decltype(obj)>::value || std::is_same<char, decltype(obj)>::value)) { \
if (1 == oceanbase::lib::ser_diag_record.flag && \
if (IF_NEED_TO_CHECK_SERIALIZATION(obj)) { \
if (oceanbase::lib::CHECK_STATUS_RECORDING == oceanbase::lib::ser_diag_record.flag && \
oceanbase::lib::ser_diag_record.count < oceanbase::lib::MAX_SERIALIZE_RECORD_LENGTH) { \
oceanbase::lib::ser_diag_record.encoded_lens[oceanbase::lib::ser_diag_record.count++] = \
static_cast<uint8_t>(this_len); \
} else if (2 == oceanbase::lib::ser_diag_record.flag && \
} else if (oceanbase::lib::CHECK_STATUS_COMPARING == oceanbase::lib::ser_diag_record.flag && \
oceanbase::lib::ser_diag_record.check_index < oceanbase::lib::ser_diag_record.count) { \
int ret = OB_ERR_UNEXPECTED; \
int record_len = oceanbase::lib::ser_diag_record.encoded_lens[oceanbase::lib::ser_diag_record.check_index]; \
if (this_len != record_len) { \
OB_LOG(ERROR, "encoded length not match", "name", MSTR(obj), K(this_len), K(record_len), K(obj)); \
OB_LOG(ERROR, "encoded length not match", "name", MSTR(obj), K(this_len), K(record_len), "value", obj); \
} \
oceanbase::lib::ser_diag_record.check_index++; \
} \