add sanity check logic clock in trans state sync

This commit is contained in:
chinaxing 2024-02-08 09:12:19 +00:00 committed by ob-robot
parent 8d60969ced
commit efebb728e6
2 changed files with 15 additions and 4 deletions

View File

@ -719,11 +719,22 @@ int ObTransService::txn_free_route__update_extra_state(const uint32_t session_id
}
#define TXN_ENCODE_LOGIC_CLOCK \
if (OB_FAIL(ret)) { \
} else if (OB_FAIL(encode_i64(buf, len, pos, ObSequence::inc_and_get_max_seq_no()))) { \
TRANS_LOG(WARN, "encode logic clock fail", K(ret)); \
if (OB_SUCC(ret)) { \
const int64_t logic_clock = ObSequence::inc_and_get_max_seq_no(); \
const int64_t one_day_us = 24L * 3600 * 1000 * 1000; \
const int64_t cur_us = ObClockGenerator::getClock(); \
if (cur_us - logic_clock > one_day_us) { \
ret = OB_ERR_UNEXPECTED; \
TRANS_LOG(ERROR, "logic-clock slow than one day", K(ret), K(logic_clock)); \
} else if (logic_clock - cur_us > one_day_us) { \
ret = OB_ERR_UNEXPECTED; \
TRANS_LOG(ERROR, "logic-clock fast than one day", K(ret), K(logic_clock)); \
} else if (OB_FAIL(encode_i64(buf, len, pos, logic_clock))) { \
TRANS_LOG(WARN, "encode logic clock fail", K(ret)); \
} \
}
#define TXN_ENCODE_LOGIC_CLOCK_LENGTH l += encoded_length_i64(INT64_MAX)
#define PRE_ENCODE_(X) TXN_ENCODE_ ## X

View File

@ -210,7 +210,7 @@ TEST_F(ObTestTx, start_trans_expired)
tx_param.isolation_ = ObTxIsolationLevel::RC;
tx_param.cluster_id_ = 100;
ASSERT_EQ(OB_SUCCESS, n1->start_tx(tx, tx_param));
usleep(5000); // 5ms
usleep(100000); // 100ms
// create tx ctx failed caused by trans_timeout
ASSERT_EQ(OB_TRANS_TIMEOUT, n1->write(tx, 100, 112));
ASSERT_EQ(OB_SUCCESS, n1->rollback_tx(tx));