debezium listens to database changes and restores Date type data

debezium is an open source distributed CDC system that supports connecting to various data sources, and writes persistent data changes in the data sources to the message queue after capturing them.

When the data source is mysql, debezium captures committed transaction data in real time through BINLOG.

During the development process, it was accidentally discovered that the data of type Date in the mysql database was read by debezium and consumed by kafka, and the obtained data value was a 5-digit int type.

Through online research, it is known that mysql stores the data of Date type after being compressed by a specific algorithm.

mysql uses a three-byte integer to compress Date in this way: YYYY×16×32 + MM×32 + DD,

That is, the last 5 digits of the three bytes are used to store the number of days, then the next four digits to the left are used to store the month, and finally the year is stored.

However, this algorithm still cannot match the extracted 5-bit integer.

Later, after posting on the forum, I learned that the Date type stored in the binlog should be the difference in days from 1970-01-01 to the stored date.

After different date data verification, it is also correct

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325848217&siteId=291194637
Recommended