A method, product, medium and device for logical replication of a cluster database

By generating a node history snapshot for each node in the cluster database and having the coordinator node build a global history snapshot, the accuracy problem of logical replication in multi-node clusters is solved, achieving stable and efficient logical replication of the cluster database.

CN122132489APending Publication Date: 2026-06-02CETC JINCANG (BEIJING) TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CETC JINCANG (BEIJING) TECH CO LTD
Filing Date
2026-02-28
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing technologies cannot build global historical snapshots when scaling a single-machine database to a multi-node cluster, leading to data corruption, loss, or inconsistency issues during logical replication, thus affecting the accuracy of logical replication.

Method used

Each node generates a node history snapshot and enters a waiting state. A pre-designated coordinator node monitors the status of all nodes and notifies them to enter the snapshot completion state. The coordinator node constructs a global history snapshot based on the history snapshots of all nodes, realizing independent generation of nodes and synchronous coordination with the coordinator.

Benefits of technology

This ensures a unified point in time for the global historical snapshots across the cluster database, improving the accuracy and consistency of logical decoding operations and guaranteeing the accuracy and stability of logical replication operations within the cluster database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122132489A_ABST
    Figure CN122132489A_ABST
Patent Text Reader

Abstract

This invention relates to database technology, and particularly to a logical replication method, product, medium, and device for clustered databases. The logical replication method includes: each node in the clustered database generating its own node historical snapshot and entering a waiting state; a pre-designated coordinator node monitoring the status of each node and, in response to all nodes having entered the waiting state, notifying all nodes to enter a snapshot completion state; and the coordinator node constructing a global historical snapshot of the clustered database based on the node historical snapshots of all nodes, so that each node can perform logical decoding operations based on the global historical snapshot. This invention, by having a pre-designated coordinator node monitor the status of all nodes and then construct a global historical snapshot based on the historical snapshots of all nodes after all nodes have entered the waiting state, ensures that the global historical snapshot corresponds to a unified point in time in the clustered database, thereby improving the accuracy of logical replication operations in the clustered database.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to database technology, in particular to a logical replication method, product, medium and equipment of a cluster database. BACKGROUND

[0002] Logical replication is a widely used data synchronization mechanism in database systems, and the key link is logical decoding, which needs to convert physical logs into logical logs for specific table and field operations to support cross-node data synchronization and other key businesses.

[0003] In a database supporting the MVCC (Multi-Version Concurrency Control) mechanism, logical decoding relies on historical snapshots to determine the visibility of metadata versions. The historical snapshot usually contains three parts of content: the minimum transaction identification number currently active, the maximum transaction identification number to be allocated, and the list of committed transaction identification numbers in the interval. In the prior art, the historical snapshot construction scheme of a single machine database usually parses the active transaction log and the transaction commit log continuously, and combines the state machine migration process to complete the initialization and dynamic update of the historical snapshot.

[0004] However, when the database architecture is expanded from a single machine to a multi-node cluster, the existing historical snapshot construction scheme cannot directly adapt to the logical replication requirements of the cluster database due to the lack of consideration of the coordination problem of the multi-node cluster. For a cluster database, if each node independently constructs its own node historical snapshot and simply splices the snapshots of each node to form a global historical snapshot at the cluster level, the global historical snapshot obtained by splicing may not correspond to the state of the cluster database at any real and consistent time point due to the differences in the progress of transaction processing and the time sequence of log recording of each node, thereby causing data confusion, loss or consistency problems in the logical decoding process, and affecting the accuracy of logical replication. SUMMARY

[0005] In view of the above problems, a logical replication method, product, medium and equipment of a cluster database are proposed to overcome the above problems or at least partially solve the above problems.

[0006] An object of the present application is to provide a logical replication method of a cluster database to ensure the accuracy of logical replication of the cluster database.

[0007] A further object of the present application is to realize the standardized selection of the coordinator node.

[0008] Another further object of the present application is to ensure the timeliness of the construction of the global historical snapshot.

[0009] Specifically, the present invention provides a logical replication method for a clustered database, comprising: Each node in the cluster database generates its own node history snapshot and enters a waiting state; The pre-designated coordinator node monitors the status of each node and, in response to all nodes having entered the waiting state, notifies all nodes to enter the snapshot completion state. The coordinator node constructs a global historical snapshot of the cluster database based on the node historical snapshots of all nodes, so that each node can perform logical decoding operations based on the global historical snapshot.

[0010] Optionally, the coordinator node is pre-specified through the following steps: When the cluster database starts up, it assigns a node as the coordinator node based on the identifier of each node.

[0011] Optionally, the step of designating a node as the coordinator node based on the identifiers of each node includes: The node with the smallest identifier among all nodes is selected as the coordinator node.

[0012] Optionally, the steps for a pre-designated coordinator node to monitor the status of each node include: The coordinator node periodically queries the status of each node.

[0013] Optionally, the steps for each node in the cluster database to generate its own node history snapshot include: Each node parses the node's active transaction log and transaction commit log until all of the node's active transactions have been committed or rolled back. The node obtains the minimum and maximum transaction IDs based on the active transaction log, and obtains the list of committed transaction IDs based on the transaction commit log; A node's historical snapshot is constructed based on a list of the minimum transaction ID, the maximum transaction ID, and committed transaction IDs.

[0014] Optionally, after entering the waiting state, the logical copy method further includes: The node updates the list of minimum transaction IDs, maximum transaction IDs, and committed transaction IDs based on the active transaction log and transaction commit log to update the node's historical snapshot.

[0015] Optionally, the coordinator node constructs a global historical snapshot of the cluster database based on the node historical snapshots of all nodes, including the following steps: The coordinator node obtains the node history snapshots held by all nodes when they enter the snapshot completion state; Combine all the historical snapshots of the nodes to obtain a global historical snapshot.

[0016] According to another aspect of the present invention, a computer program product is also provided, comprising a computer program that, when executed by a processor, implements the steps of any of the above-described logical copying methods.

[0017] According to another aspect of the present invention, a computer-readable storage medium is also provided, on which a computer program is stored, wherein the computer program, when executed by a processor, implements the steps of any of the above-described logical copying methods.

[0018] According to another aspect of the present invention, a computer device is also provided, which includes a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of any of the above-described logical copying methods.

[0019] The logical replication method of this invention involves each node in the cluster database generating its own node historical snapshot and entering a waiting state. A pre-designated coordinator node monitors the status of all nodes and notifies them to enter the snapshot completion state after all nodes have entered the waiting state. Then, the coordinator node constructs a global historical snapshot based on the historical snapshots of all nodes. This combines the independent snapshot generation of each node in the cluster with the synchronous coordination of the coordinator, ensuring that the global historical snapshot corresponds to a unified point in time in the cluster database. It solves the problem of incomplete and incorrect global historical snapshots caused by simply splicing the historical snapshots of each node, thereby improving the accuracy and consistency of subsequent logical decoding operations and ensuring the accuracy of logical replication operations in the cluster database.

[0020] Furthermore, the logical replication method of the present invention, by specifying a node as the coordinator node according to the identifier of each node when the cluster database starts, realizes the standardized selection of the coordinator node, avoids the uncertainty of the selection of the coordinator node during the operation of the cluster database, thereby ensuring the stable start of the global historical snapshot construction coordination mechanism in the cluster database, and thus laying the foundation for the accurate construction of subsequent global historical snapshots.

[0021] Furthermore, the logical replication method of the present invention enables real-time monitoring of the snapshot status of all nodes in the cluster by having the coordinator node periodically query the status of each node. This avoids delays in global snapshot construction or omissions of nodes due to untimely status monitoring, thereby ensuring the timeliness of global historical snapshot construction and improving the coordination accuracy of the cluster database.

[0022] The above and other objects, advantages and features of the present invention will become more apparent to those skilled in the art from the following detailed description of specific embodiments of the invention in conjunction with the accompanying drawings. Attached Figure Description

[0023] The following sections will describe some specific embodiments of the invention in detail by way of example and not limitation, with reference to the accompanying drawings. The same reference numerals in the drawings denote the same or similar parts or portions. Those skilled in the art should understand that these drawings are not necessarily drawn to scale. In the drawings: Figure 1 This is a schematic diagram of a historical snapshot construction scheme for a single-machine database in existing technology; Figure 2 This is a schematic diagram of a logical replication method for a clustered database according to an embodiment of the present invention; Figure 3 This is a schematic diagram of a global historical snapshot construction scheme in a logical replication method for a clustered database according to an embodiment of the present invention; Figure 4 This is a control flowchart of a logical replication method for a clustered database according to an embodiment of the present invention; Figure 5 This is a schematic diagram of a computer program product according to an embodiment of the present invention; Figure 6 This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention; Figure 7 This is a schematic block diagram of a computer device according to an embodiment of the present invention. Detailed Implementation

[0024] Exemplary embodiments of the invention will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the invention are shown in the drawings, it should be understood that the invention may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.

[0025] Figure 1 This is a schematic diagram of a current technology for constructing historical snapshots of a single-machine database. For example... Figure 1 As shown, in an existing single-machine database, the process of building a historical snapshot may include the following steps: When creating a logical replication slot, the historical snapshot state machine is initialized to the snapshot start state (which can be denoted as Start_snapshot) to start the construction of the historical snapshot. At this time, the historical snapshot is empty. Parse the active transaction log, and the historical snapshot state machine is transitioned to the build snapshot state (which can be denoted as Build_snapshot). Update the minimum transaction ID (which can be denoted as xmin) and maximum transaction ID (which can be denoted as xmax) of the historical snapshot according to the active transaction log. At this time, the historical snapshot is incomplete and cannot be decoded. Wait for active transactions to commit or roll back for the first time until all active transactions have been committed or rolled back. During the waiting process, record the transaction identification number (which can be denoted as xid) of the committed transactions into the list of committed transaction identification numbers (which can be denoted as commitxidlist) of the historical snapshot; Continuously parse the active transaction log and the transaction commit log until the first waiting ends. The historical snapshot state machine migrates to the snapshot completion state (which can be denoted as Full_snapshot). At this time, update the xmin and xmax of the historical snapshot, and at the same time update commitxidlist to delete the xid of the committed transaction with xid < xmin; Start building the first complete historical snapshot belonging to this logical replication slot from Full_snapshot, and correct logical decoding operations can be performed on the transactions started after the Full_snapshot point; After the first complete historical snapshot is built, the historical snapshot can continue to be updated according to the active transaction log and the transaction commit log.至此,本次流程结束。

[0026] Using the above method, the historical snapshot construction scheme is only designed for single-node scenarios and does not consider the coordination problem of multiple nodes in a cluster. It cannot directly adapt to the logical replication requirements of cluster databases. Since the time points for each node to generate the node historical snapshot are inconsistent, the globally historical snapshot obtained by simple splicing cannot correspond to the unified time point of the cluster, neither can it completely cover the transaction status within the cluster nor accurately judge the commit situation of each transaction, thus leading to the problem of incorrect metadata version visibility judgment during the logical decoding process and affecting the accuracy of logical replication.

[0027] To solve the above problems, an embodiment of the present invention proposes a logical replication method for a cluster database. Figure 2 It is a schematic diagram of a logical replication method according to an embodiment of the present invention. As Figure 2 shown, the logical replication method of this embodiment generally may include: Step S202, each node of the cluster database generates its own node historical snapshot and enters a waiting state. It should be noted that the cluster database can be a RAC cluster, which includes multiple nodes. Each node can adopt a relatively independent node historical snapshot construction mechanism based on its logical replication slot to build its own node historical snapshot (which can be denoted as historysnapshot), and switch its historical snapshot state machine to the waiting state (which can be denoted as Wait_full_snapshot). In addition, Wait_full_snapshot of each node means that the node itself enters the local ready state.

[0028] Step S204: The pre-specified coordinator node monitors the status of each node, and in response to all nodes having entered the waiting state, notifies all nodes to enter the snapshot completion state. That is, when all nodes enter Wait_full_snapshot, the coordinator node notifies all nodes to enter the snapshot completion state (which can be denoted as Full_snapshot). It should be noted that Full_snapshot of all nodes means that all nodes of the cluster database synchronously enter the global ready state.

[0029] Step S206: The coordinator node constructs a global historical snapshot of the cluster database based on the node historical snapshots of all nodes, so that each node can perform logical decoding operations based on the global historical snapshot. That is, the coordinator node obtains the node historical snapshots after all nodes enter Full_snapshot and constructs a global historical snapshot of the entire RAC cluster (which can be denoted as global historysnapshot). In addition, transactions started after the Full_snapshot point can all perform logical decoding operations.

[0030] The logical replication method of the embodiment of the present invention enables each node of the cluster database to generate its own node historical snapshot and enter the waiting state. The pre-specified coordinator node monitors the status of all nodes, and after all nodes have entered the waiting state, notifies them to enter the snapshot completion state. Then, the coordinator node constructs a global historical snapshot based on the node historical snapshots of all nodes, realizing the combination of independent snapshot generation by each node of the cluster and synchronous coordination by the coordinator, ensuring that the global historical snapshot corresponds to the unified time point of the cluster database, and solving the problem of incomplete and incorrect global historical snapshots caused by simply splicing the node historical snapshots of each node. Thereby, the accuracy and consistency of subsequent logical decoding operations are improved, and further, the accuracy of logical replication operations in the cluster database is ensured.

[0031] In some embodiments, in the above step S202, the historical snapshot may include xmin, xmax, and the commitxidlist within the range of [xmin, xmax]. The historical snapshot can be used to determine the commit status of all transactions in the cluster database at a certain moment in history. For example, transactions with xid < xmin have all been committed, transactions with xid > xmax have not been committed, and transactions with xid within the range of [xmin, xmax] and recorded in the Commitxidlist have all been committed, while transactions with xid within the range of [xmin, xmax] and not recorded in the Commitxidlist have not been committed.

[0032] Based on this, the steps for each node in the cluster database to generate its own node history snapshot may include the following: each node parses the node's active transaction log and transaction commit log until all of the node's active transactions have been committed or rolled back; the node obtains the minimum transaction identifier and the maximum transaction identifier based on the active transaction log, and obtains a list of committed transaction identifiers based on the transaction commit log; the node constructs its node history snapshot based on the minimum transaction identifier, the maximum transaction identifier, and the list of committed transaction identifiers.

[0033] It should be noted that the active transaction log can be the RunningXcating log recorded by the database system at regular intervals. Its contents include the ID of the oldest currently active transaction (which can be denoted as `oldestrunningxid`) and the ID of the transaction to be assigned (which can be denoted as `nextxid`). Based on the contents of the RunningXcating log, the `xmin` and `xmax` of the historical snapshot at the current moment can be constructed. Specifically, `xmin = oldestrunningxid`, and `xmax = nextxid`.

[0034] Additionally, the transaction commit log is a Committed log recorded by the database system when a transaction is committed. Its contents include the committing transaction's xid (which can be denoted as commitxid), and it can continuously update the historical snapshot's Commitxidlist and advance xmax based on the committing transaction's xid. Specifically, if commitxid > xmax, then update xmax = commitxid.

[0035] The logical replication method of this invention enables each node to parse its own active transaction logs and transaction commit logs until all active transactions have been committed or rolled back before generating a node historical snapshot. This achieves an accurate depiction of the transaction state of a node at a specific moment in the node historical snapshot, thereby providing reliable basic data for the global historical snapshot and ensuring the accuracy of the global historical snapshot.

[0036] In some embodiments, the steps of S202 may be specifically executed as the following steps: Create a logical replication slot, initialize the historical snapshot state machine to Start_snapshot; Parse the RunningXcating log, migrate the historical snapshot state machine to Build_snapshot, and update the xmin and xmax of the node historical snapshot according to the RunningXcating log; Wait for active transactions to commit or roll back for the first time until all active transactions have been committed or rolled back, and record the commitxid into the commitxidlist of the node historical snapshot during the waiting process; Continuously parse the RunningXcating log and the Commitedlog log until the end of the first wait, migrate the historical snapshot state machine to Full_snapshot, and continuously update the xmin and xmax of the node historical snapshot, and at the same time update the commitxidlist to delete the xid of the committed transaction with xid < xmin; Build the first complete node historical snapshot of the logical replication slot belonging to this node starting from Full_snapshot, and correct logical decoding operations can be performed on the transactions started after the Full_snapshot point.

[0037] Thus, in the logical replication method of the embodiments of the present invention, each node adopts a relatively independent node historical snapshot construction mechanism based on its logical replication slot to construct its own historysnapshot, laying a foundation for the construction of the global historical snapshot at the cluster level, thereby ensuring the accuracy and reliability of subsequent logical decoding operations.

[0038] In some embodiments, after the above step S202, the logical replication method of the present invention may further include the following steps: The node updates the minimum transaction identification number, the maximum transaction identification number, and the list of committed transaction identification numbers based on the active transaction log and the transaction commit log to update the node historical snapshot.

[0039] Thus, in the logical replication method of the embodiments of the present invention, after the node enters the waiting state, the node historical snapshot is dynamically updated based on the active transaction log and the transaction commit log, avoiding the problem of node snapshot failure caused by the change of transaction state during the waiting process, thereby improving the accuracy of the node historical snapshot, and further guaranteeing the integrity of the global historical snapshot.

[0040] In some embodiments, the coordinator node in the above step S204 may be specified in advance through the following steps: When the cluster database starts, a node is specified as the coordinator node according to the identifiers of each node (which can be denoted as Nodeid). That is to say, the coordinator node can be a node specified according to Nodeid when the RAC cluster starts.

[0041] Therefore, the logical replication method of this invention achieves standardized selection of the coordinator node by designating a node as the coordinator node according to the specifications of each node when the cluster database starts. This avoids the uncertainty of coordinator node selection during the operation of the cluster database, thereby ensuring the stable start of the global historical snapshot construction coordination mechanism in the cluster database, and laying the foundation for the accurate construction of subsequent global historical snapshots.

[0042] Furthermore, the step of designating a node as the coordinator node based on the Nodeid of each node can include the following steps: selecting the node with the smallest identifier among all nodes as the coordinator node. In other words, the coordinator node is the node with the smallest Nodeid among all nodes in the cluster database.

[0043] Therefore, the logical replication method of this invention standardizes and automates the selection of coordinator nodes by selecting the node with the smallest identifier among all nodes as the coordinator node. This eliminates the need for additional manual configuration or complex election algorithms, thereby reducing the deployment and maintenance costs of the cluster database and improving the efficiency of the coordinator node selection mechanism.

[0044] In some embodiments, the step of the pre-specified coordinator node monitoring the status of each node in step S204 above may include the following steps: the coordinator node periodically queries the status of each node. Specifically, the step of the coordinator node periodically querying the status of each node can be specifically executed as follows: the coordinator node sends a status query request to each node in the cluster database at a preset time interval; after receiving the query request, each node reports back the status of its current historical snapshot state machine; the coordinator node summarizes and records the status of all nodes.

[0045] In this embodiment, the preset time interval can be pre-set to a configurable fixed duration based on the number of cluster nodes and hardware performance, or the preset time interval can be dynamically adjusted based on the busy level of transaction processing in the cluster database and / or the frequency of node status changes.

[0046] Therefore, the logical replication method of this invention realizes real-time monitoring of the snapshot status of all nodes in the cluster by having the coordinator node periodically query the status of each node. This avoids delays in global snapshot construction or omissions of nodes due to untimely status monitoring, thereby ensuring the timeliness of global historical snapshot construction and improving the coordination accuracy of the cluster database.

[0047] In some embodiments, the step of notifying all nodes to enter the snapshot completion state in response to all nodes having entered the waiting state in step S204 above may include the following steps: in response to all nodes having entered the Wait_full_snapshot, sending a snapshot ready notification to all nodes; each node enters the Full_snapshot state after receiving the snapshot ready notification.

[0048] Therefore, the logical replication method of this invention achieves synchronization of the historical snapshot state machine switching of each node by waiting for the snapshot ready notification issued by the coordinator node before entering Full_snapshot. This ensures that all nodes complete the final confirmation of the node's historical snapshot based on the same time base, thereby avoiding the problem of global historical snapshot time base confusion caused by asynchronous node state switching, and thus improving the integrity and consistency of the global historical snapshot at the cluster level.

[0049] In some embodiments, step S206 may include the following steps: the coordinator node obtains the node history snapshots held by all nodes when entering the snapshot completion state; and combines all node history snapshots to obtain a global history snapshot.

[0050] It should be noted that during the logical replication process of a RAC cluster, each node can construct its own history snapshot based on its independent WAL log stream. The global history snapshot of the RAC cluster is composed of the history snapshots of each node, and the combination formula is as follows: global history snapshot={ {Node1,[xmin1:xmax1:committed txns1]}, {Node2,[xmin2:xmax2:committed txns2]}, {Node3,[xmin3:xmax3:committed txns3]}, {Node4,[xmin4:xmax4:committed txns4]},} In the above formula, Node1 is the first node of the RAC cluster, xmin1, xmax1, and committedtxns1 are the node history snapshots of the first node; Node2 is the second node of the RAC cluster, xmin2, xmax2, and committedtxns2 are the node history snapshots of the second node; Node3 is the third node of the RAC cluster, xmin3, xmax3, and committedtxns3 are the node history snapshots of the third node; and Node4 is the fourth node of the RAC cluster, xmin4, xmax4, and committedtxns4 are the node history snapshots of the fourth node.

[0051] Therefore, the logical replication method of this invention obtains the node historical snapshots of all nodes when they enter the snapshot completion state through the coordinator node, and combines these node historical snapshots to obtain the global historical snapshot. This realizes that the global historical snapshot is composed of snapshot data of each node in the same state, ensuring the unified time point of the cluster database corresponding to the global historical snapshot, thereby ensuring the integrity and correctness of the global historical snapshot, and laying the foundation for the correct execution of subsequent logical decoding operations.

[0052] Figure 3 This is a schematic diagram of a global historical snapshot construction scheme in a logical replication method for a clustered database according to an embodiment of the present invention. Figure 3 As shown, in this embodiment, ignoring the order in which Node1 and Node2 enter Build_snapshot, the logical replication process of the cluster database may include the following steps: After Node1 enters Build_snapshot, it will first enter the Wait_full_snapshot state until all active transactions have been committed or rolled back. After Node2 enters the Build_snapshot state, it will remain in the Wait_full_snapshot state until all active transactions have been committed or rolled back. Select the node with the smallest Nodeid, which is Node1 by default, as the coordinator node. When Node1 finds that all nodes have entered the Wait_full_snapshot state, it generates a global history snapshot and then notifies all nodes to switch to the Full_snapshot state. Everything after the Full_snapshot (such as TXN13 and TXN22) can be correctly decoded by logic.

[0053] Using the above method, each node in the cluster database independently generates its own node historical snapshot and enters a waiting state. A pre-designated coordinator node monitors the status of all nodes and notifies them to enter the snapshot completion state after all nodes have entered the waiting state. Then, the coordinator node constructs a global historical snapshot based on the historical snapshots of all nodes. This achieves the combination of independent snapshot generation by each node in the cluster and synchronous coordination by the coordinator, ensuring that the global historical snapshot corresponds to a unified point in time in the cluster database. It solves the problem of incomplete and incorrect global historical snapshots caused by simply splicing the historical snapshots of each node, thereby improving the accuracy and consistency of subsequent logical decoding operations, and thus ensuring the accuracy of logical replication operations in the cluster database.

[0054] Figure 4 This is a control flow diagram of a logical replication method for a clustered database according to an embodiment of the present invention. The following is in conjunction with... Figure 4 The process steps of this embodiment will be described in detail below.

[0055] In step S402, when the cluster database starts up, it selects the node with the smallest Nodeid among all nodes as the coordinator node. It should be noted that the cluster database can be a RAC cluster, which includes multiple nodes.

[0056] In step S404, each node in the cluster database generates its own history snapshot and enters the Wait_full_snapshot state. It should be noted that each node can use a relatively independent node history snapshot construction mechanism based on its logical replication slot to build its own history snapshot and switch its history snapshot state machine to Wait_full_snapshot.

[0057] In step S406, each node updates xmin, xmax, and commitxidlist based on the RunningXcating log and the Committedlog log to update the history snapshot.

[0058] Step S408: The coordinator node periodically queries the status of each node.

[0059] In step S410, the coordinator node responds to the fact that all nodes have entered Wait_full_snapshot by notifying all nodes to enter Full_snapshot.

[0060] Step S412: The coordinator node obtains the history snapshot held by all nodes when entering the Full_snapshot.

[0061] Step S414: Combine all history snapshots to obtain the global history snapshot of the cluster database.

[0062] In step S416, transactions following the Full_snapshot on each node can undergo logical decoding. This completes the logical replication process of the cluster database, and this workflow ends.

[0063] Therefore, the logical replication method of this invention monitors the status of all nodes through a pre-designated coordinator node, and constructs a global historical snapshot based on the historical snapshots of all nodes when all nodes have entered the waiting state. This achieves a combination of independent snapshot generation by each node in the cluster and synchronous coordination by the coordinator, ensuring that the global historical snapshot corresponds to a unified point in time in the cluster database. It solves the problem of incomplete and incorrect global historical snapshots caused by simply splicing the historical snapshots of each node, thereby improving the accuracy and consistency of subsequent logical decoding operations, and thus ensuring the accuracy of logical replication operations in the cluster database.

[0064] Furthermore, the logical replication method of this embodiment of the invention, by specifying a node as the coordinator node according to the identifier of each node when the cluster database starts, realizes the standardized selection of the coordinator node, avoids the uncertainty of the selection of the coordinator node during the operation of the cluster database, thereby ensuring the stable start of the global historical snapshot construction coordination mechanism in the cluster database, and thus laying the foundation for the accurate construction of subsequent global historical snapshots.

[0065] Furthermore, the logical replication method of this embodiment of the invention realizes real-time monitoring of the snapshot status of all nodes in the cluster by periodically querying the status of each node by the coordinator node. This avoids the situation of delay in global snapshot construction or omission of nodes due to untimely status monitoring, thereby ensuring the timeliness of global historical snapshot construction and improving the coordination accuracy of the cluster database.

[0066] This embodiment also provides a computer program product 10, a computer-readable storage medium 20, and a computer device 30. Figure 5 This is a schematic diagram of a computer program product 10 according to an embodiment of the present invention. Figure 6 This is a schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention. Figure 7 This is a schematic block diagram of a computer device 30 according to an embodiment of the present invention.

[0067] Computer program product 10 includes computer program 11, which, when executed by processor 32, implements the steps of any of the above-described logical copying methods. Computer-readable storage medium 20 stores the computer program 11 thereon, which, when executed by processor 32, implements the steps of the logical copying method of any of the above embodiments. Computer device 30 may include memory 31, processor 32, and computer program 11 stored in memory 31 and running on processor 32.

[0068] The computer program 11 used to perform the operations of the present invention may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, status setting data, integrated circuit configuration data, or source code or object code written in any combination of one or more programming languages ​​and procedural programming languages.

[0069] Computer program 11 may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, to perform aspects of the invention, electronic circuitry including, for example, programmable logic circuitry, a Field-Programmable Gate Array (FPGA), or a Programmable Logic Array (PLA) may execute computer-readable program instructions to personalize the electronic circuitry by utilizing state information of the computer-readable program instructions.

[0070] For the purposes of this embodiment, computer program product 10 is a related product that includes computer program 11.

[0071] For the purposes of this embodiment, computer-readable storage medium 20 is a tangible device capable of holding and storing computer program 11. It can be any device capable of containing, storing, communicating, propagating, or transmitting program 811 for use by or in conjunction with an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable storage medium 20 include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable optical disc read-only memory (CD-ROM), digital versatile disc (DVD), memory stick, floppy disk, mechanical encoding device, and any suitable combination thereof.

[0072] Therefore, those skilled in the art should recognize that although numerous exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications conforming to the principles of the present invention can be directly determined or derived from the disclosure of the present invention without departing from the spirit and scope of the invention. Thus, the scope of the present invention should be understood and construed as covering all such other variations or modifications.

Claims

1. A logical replication method for a clustered database, comprising: Each node in the cluster database generates its own node history snapshot and enters a waiting state; A pre-designated coordinator node monitors the status of each of the nodes and, in response to all of the nodes having entered a waiting state, notifies all of the nodes to enter a snapshot completion state. The coordinator node constructs a global historical snapshot of the cluster database based on the node historical snapshots of all the nodes, so that each node can perform logical decoding operations based on the global historical snapshot.

2. The logical replication method for a clustered database according to claim 1, wherein, The coordinator node is pre-specified through the following steps: When the cluster database starts up, it designates one of the nodes as the coordinator node based on the identifier of each node.

3. The logical replication method for a clustered database according to claim 2, wherein, The step of designating a node as the coordinator node based on the identifiers of each of the nodes includes: The node with the smallest identifier among all the nodes is selected as the coordinator node.

4. The logical replication method for a clustered database according to claim 1, wherein, The step of the pre-designated coordinator node monitoring the status of each of the nodes includes: The coordinator node periodically queries the status of each node.

5. The logical replication method for a clustered database according to claim 1, wherein, The steps for each node in the cluster database to generate its own node history snapshot include: Each node parses the node's active transaction log and transaction commit log until all of the node's active transactions have been committed or rolled back; The node obtains the minimum transaction identifier and the maximum transaction identifier based on the active transaction log, and obtains the list of committed transaction identifiers based on the transaction commit log; The node's historical snapshot is constructed based on the minimum transaction identifier, the maximum transaction identifier, and the list of committed transaction identifiers.

6. The logical replication method for a clustered database according to claim 5, wherein, Following the step of entering the waiting state, the logical replication method further includes: The node updates the list of minimum transaction identifiers, maximum transaction identifiers, and committed transaction identifiers based on the active transaction log and the transaction commit log, in order to update the node's historical snapshot.

7. The logical replication method for a clustered database according to claim 6, wherein, The steps by which the coordinator node constructs a global historical snapshot of the cluster database based on the node historical snapshots of all the nodes include: The coordinator node obtains the node history snapshots held by all the nodes when they enter the snapshot completion state; The global historical snapshot is obtained by combining all the historical snapshots of the nodes.

8. A computer program product comprising a computer program, wherein, When executed by a processor, the computer program implements the steps of the logical replication method for the clustered database as described in any one of claims 1 to 7.

9. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the logical replication method for a clustered database according to any one of claims 1 to 7.

10. A computer device comprising a memory, a processor, and a computer program stored in the memory, wherein, The processor executes the computer program to implement the steps of the logical replication method for the clustered database according to any one of claims 1 to 7.