# US 2021/0279254 A1 · Data replication method and apparatus, computer device, and storage medium

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2021/0279254 A1
- Document ID: US20210279254A1
- Status: Published application
- Kind: A1
- Application number: 17/330,276
- Filed: 2021-05-25
- Published: 2021-09-09
- Earliest claimed: 2019-05-05
- Assignees: Tencent Technology (Shenzhen) Company Limited
- Applicants: Tencent Technology (Shenzhen) Company Limited
- Inventors: Haixiang LI
- Web page: https://patentgrep.com/patent/US20210279254A1

## CPC

- G06F 16/273: {Asynchronous replication or reconciliation}
- G06F 16/2282: {Tablespace storage structures; Management thereof}
- G06F 16/2365: {Ensuring data consistency and integrity}
- G06F 16/258: {Data format conversion from or to a database}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

This application discloses a data replication method and apparatus, a computer device, and a storage medium, and belongs to the field of database technologies. The method includes: adding, when a commitment operation of a transaction is detected, historical state data of the transaction to a data queue; adding at least one piece of historical state data in the data queue to a transmission buffer; and replicating, when a first preset condition is met, the at least one piece of historical state data in the transmission buffer to a cluster device. In this application, a node device does not need to convert an original historical state data format into a log format, and the cluster device does not need to parse a log into an original data format for storage, thereby avoiding a cumbersome log replay procedure, and improving the efficiency of the data replication process.

## Claims

### Claim 1

A data replication method, performed by a computer device, the method comprising:
receiving, from a receiving buffer, at least one piece of historical state data transmitted by a node device, the receiving buffer being configured for caching received historical state data;
adding the at least one piece of historical state data in the receiving buffer to a forwarding buffer, and converting, by using the forwarding buffer, the at least one piece of historical state data into data meeting a tuple format, to obtain at least one data item, the forwarding buffer being configured for performing data format conversion on historical state data; and
storing the at least one data item in at least one target data table of a cluster database, one target data table being corresponding to one original data table in which one data item is located in the node device.

### Claim 2 (depends on 1)

The method according to claim 1, wherein the storing the at least one data item in at least one target data table of a cluster database comprises:
storing, for a data item in tuple according to a storage format in an original data table in which the data item is located, the data item in a target data table corresponding to the original data table; or
storing, for a data item indicating a field change status, the data item in a target data table corresponding to an original data table according to a storage format of a key-value pair.

### Claim 3 (depends on 2)

The method according to claim 2, wherein the storing the data item in a target data table corresponding to an original data table according to a storage format of a key-value pair comprises:
determining at least one of a key of the data item in the original data table and a generation time of the data item as a key of the data item in the target data table; and
determining a changed field of the data item in the original data table as a value of the data item in the target data table.

### Claim 4 (depends on 1)

The method according to claim 1, further comprising:
determining a minimum transaction identifier meeting a second preset condition in transaction identifiers of the at least one piece of historical state data, the second preset condition being used for indicating that all data items corresponding to all sub-transactions of a transaction have been stored in the cluster database;
determining a visible data item according to the minimum transaction identifier, a transaction identifier of the visible data item being less than or equal to the minimum transaction identifier; and
providing a data query service based on the visible data item.

### Claim 5 (depends on 4)

The method according to claim 4, wherein the determining a minimum transaction identifier meeting a second preset condition in transaction identifiers of the at least one piece of historical state data comprises:
sorting the at least one piece of historical state data according to transaction commitment timestamps in ascending order, and sorting, when there are a plurality of pieces of historical state data having the same transaction commitment timestamp, the plurality of pieces of historical state data according to transaction identifiers in ascending order, to obtain a target data sequence;
obtaining at least one transaction meeting the second preset condition from the target data sequence; and
determining a transaction identifier of a top-ranked transaction in the at least one transaction as the minimum transaction identifier.

### Claim 6 (depends on 5)

The method according to claim 5, wherein the obtaining at least one transaction meeting the second preset condition from the target data sequence comprises:
traversing the target data sequence, performing a bitwise AND operation on bitmap code of each piece of historical state data, and determining that a transaction corresponding to historical state data having an output of true meets the second preset condition; or
traversing the target data sequence, and decoding a compression dictionary of each piece of historical state data, to obtain a global transaction identifier corresponding to the each piece of historical state data; and determining, when it is determined that all data items of sub-transactions corresponding to the global transaction identifier have been stored in the cluster database, that a transaction corresponding to the global transaction identifier meets the second preset condition.

### Claim 7 (depends on 6)

The method according to claim 6, wherein the case that it is determined that all data items of sub-transactions corresponding to the global transaction identifier have been stored in the cluster database comprises:
obtaining, according to the global transaction identifier, the data items that have been stored in the cluster database and have the global transaction identifier, and determining, when the obtained data items and the historical state data obtained through decoding correspond to all sub-transactions of the transaction, that all the data items of the sub-transactions corresponding to the global transaction identifier have been stored in the cluster database.

### Claim 8 (depends on 1)

The method according to claim 1, wherein the receiving, from a receiving buffer, at least one piece of historical state data transmitted by a node device comprises:
receiving, from the receiving buffer every second preset duration, at least one piece of historical state data transmitted by any node device; or
receiving, from the receiving buffer every third preset duration, at least one piece of historical state data simultaneously transmitted by a plurality of node devices.

### Claim 9

A computer device, comprising a processor and a memory, the memory storing at least one instruction, the at least one instruction being loaded and executed by the processor to perform a plurality of operations comprising:
receiving, from a receiving buffer, at least one piece of historical state data transmitted by a node device, the receiving buffer being configured for caching received historical state data;
adding the at least one piece of historical state data in the receiving buffer to a forwarding buffer, and converting, by using the forwarding buffer, the at least one piece of historical state data into data meeting a tuple format, to obtain at least one data item, the forwarding buffer being configured for performing data format conversion on historical state data; and
storing the at least one data item in at least one target data table of a cluster database, one target data table being corresponding to one original data table in which one data item is located in the node device.

### Claim 10 (depends on 9)

The computer device according to claim 9, wherein the storing the at least one data item in at least one target data table of a cluster database comprises:
storing, for a data item in tuple according to a storage format in an original data table in which the data item is located, the data item in a target data table corresponding to the original data table; or
storing, for a data item indicating a field change status, the data item in a target data table corresponding to an original data table according to a storage format of a key-value pair.

### Claim 11 (depends on 10)

The computer device according to claim 10, wherein the storing the data item in a target data table corresponding to an original data table according to a storage format of a key-value pair comprises:
determining at least one of a key of the data item in the original data table and a generation time of the data item as a key of the data item in the target data table; and
determining a changed field of the data item in the original data table as a value of the data item in the target data table.

### Claim 12 (depends on 9)

The computer device according to claim 9, wherein the plurality of operations further comprise:
determining a minimum transaction identifier meeting a second preset condition in transaction identifiers of the at least one piece of historical state data, the second preset condition being used for indicating that all data items corresponding to all sub-transactions of a transaction have been stored in the cluster database;
determining a visible data item according to the minimum transaction identifier, a transaction identifier of the visible data item being less than or equal to the minimum transaction identifier; and
providing a data query service based on the visible data item.

### Claim 13 (depends on 12)

The computer device according to claim 12, wherein the determining a minimum transaction identifier meeting a second preset condition in transaction identifiers of the at least one piece of historical state data comprises:
sorting the at least one piece of historical state data according to transaction commitment timestamps in ascending order, and sorting, when there are a plurality of pieces of historical state data having the same transaction commitment timestamp, the plurality of pieces of historical state data according to transaction identifiers in ascending order, to obtain a target data sequence;
obtaining at least one transaction meeting the second preset condition from the target data sequence; and
determining a transaction identifier of a top-ranked transaction in the at least one transaction as the minimum transaction identifier.

### Claim 14 (depends on 13)

The computer device according to claim 13, wherein the obtaining at least one transaction meeting the second preset condition from the target data sequence comprises:
traversing the target data sequence, performing a bitwise AND operation on bitmap code of each piece of historical state data, and determining that a transaction corresponding to historical state data having an output of true meets the second preset condition; or
traversing the target data sequence, and decoding a compression dictionary of each piece of historical state data, to obtain a global transaction identifier corresponding to the each piece of historical state data; and determining, when it is determined that all data items of sub-transactions corresponding to the global transaction identifier have been stored in the cluster database, that a transaction corresponding to the global transaction identifier meets the second preset condition.

### Claim 15 (depends on 14)

The computer device according to claim 14, wherein the case that it is determined that all data items of sub-transactions corresponding to the global transaction identifier have been stored in the cluster database comprises:
obtaining, according to the global transaction identifier, the data items that have been stored in the cluster database and have the global transaction identifier, and determining, when the obtained data items and the historical state data obtained through decoding correspond to all sub-transactions of the transaction, that all the data items of the sub-transactions corresponding to the global transaction identifier have been stored in the cluster database.

### Claim 16 (depends on 9)

The computer device according to claim 9, wherein the receiving, from a receiving buffer, at least one piece of historical state data transmitted by a node device comprises:
receiving, from the receiving buffer every second preset duration, at least one piece of historical state data transmitted by any node device; or
receiving, from the receiving buffer every third preset duration, at least one piece of historical state data simultaneously transmitted by a plurality of node devices.

### Claim 17

A non-transitory computer-readable storage medium, storing at least one instruction, the at least one instruction being loaded and executed by a processor of a computer device to perform a plurality of operations comprising:
receiving, from a receiving buffer, at least one piece of historical state data transmitted by a node device, the receiving buffer being configured for caching received historical state data;
adding the at least one piece of historical state data in the receiving buffer to a forwarding buffer, and converting, by using the forwarding buffer, the at least one piece of historical state data into data meeting a tuple format, to obtain at least one data item, the forwarding buffer being configured for performing data format conversion on historical state data; and
storing the at least one data item in at least one target data table of a cluster database, one target data table being corresponding to one original data table in which one data item is located in the node device.

### Claim 18 (depends on 17)

The non-transitory computer-readable storage medium according to claim 17, wherein the storing the at least one data item in at least one target data table of a cluster database comprises:
storing, for a data item in tuple according to a storage format in an original data table in which the data item is located, the data item in a target data table corresponding to the original data table; or
storing, for a data item indicating a field change status, the data item in a target data table corresponding to an original data table according to a storage format of a key-value pair.

### Claim 19 (depends on 18)

The non-transitory computer-readable storage medium according to claim 18, wherein the storing the data item in a target data table corresponding to an original data table according to a storage format of a key-value pair comprises:
determining at least one of a key of the data item in the original data table and a generation time of the data item as a key of the data item in the target data table; and
determining a changed field of the data item in the original data table as a value of the data item in the target data table.

### Claim 20 (depends on 17)

The non-transitory computer-readable storage medium according to claim 17, wherein the plurality of operations further comprise:
determining a minimum transaction identifier meeting a second preset condition in transaction identifiers of the at least one piece of historical state data, the second preset condition being used for indicating that all data items corresponding to all sub-transactions of a transaction have been stored in the cluster database;
determining a visible data item according to the minimum transaction identifier, a transaction identifier of the visible data item being less than or equal to the minimum transaction identifier; and
providing a data query service based on the visible data item.
