A method for ensuring data consistency and related devices
By using a node management server to elect a new master node in the distributed database and setting the data to read-only mode, the data consistency problem when there are fewer than half of the nodes is solved, and efficient data consistency guarantee is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
- Filing Date
- 2019-10-31
- Publication Date
- 2026-07-14
AI Technical Summary
In distributed databases, existing technologies struggle to guarantee data consistency without sacrificing database performance, especially when fewer than half of the nodes in the cluster are alive, making it impossible to elect a master node. Furthermore, the use of distributed locks results in significant performance degradation.
A new master node is elected directly through the node management server, and the root metadata and user data are set to read-only mode during the upgrade process to ensure that only one node can write data and avoid data conflicts.
To ensure data consistency, avoid data conflicts, and improve system performance without sacrificing database performance.
Smart Images

Figure CN112749178B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer distributed storage system technology, and in particular to a method and related equipment for ensuring data consistency. Background Technology
[0002] Currently, in the application of distributed databases, in order to ensure the uniqueness of data writing, it is necessary to ensure that only one node can write data at the same time in the entire database cluster. That is, at any given moment, it is necessary to ensure that there is only one master node in the database cluster.
[0003] Raft is a distributed consensus protocol that employs an elite-led global strategy. Only the master node in the entire cluster can handle requests from clients; other nodes, even if they receive a request, must forward it to the master node for processing. Raft strongly relies on the master node to ensure cluster data consistency.
[0004] In cloud computing environments, distributed locks have a wide range of applications. For example, in distributed systems, when different devices access a shared resource, the system often needs distributed locks to support mutual exclusion of access to the shared resource to ensure consistency. That is, only one node can hold the lock, and the uniqueness of the master node can be guaranteed through lock preemption.
[0005] However, both the Raft protocol and distributed locks have certain drawbacks. Using the Raft protocol for master node election requires that the number of surviving nodes in the cluster be greater than half of the total number of nodes; otherwise, a master node cannot be elected. On the other hand, using distributed locks, to strictly guarantee data consistency (i.e., no conflicting write operations), requires adding a lock on every write operation, which severely impacts database performance. Therefore, how to ensure data consistency without sacrificing database performance is a pressing issue that needs to be addressed. Summary of the Invention
[0006] This invention discloses a method and related equipment for ensuring data consistency, which can guarantee data consistency and avoid data conflicts without sacrificing database performance.
[0007] In a first aspect, this application provides a method for ensuring data consistency, comprising: a first node receiving an upgrade message sent by a node management server, the node management server being used to manage a node cluster, the node cluster including the first node; the first node updating term management data, the term management data including a root metadata identifier and a term identifier, the root metadata identifier being used to determine root metadata, the root metadata being used to manage the metadata corresponding to the node cluster, and the term identifier being used to indicate that the first node has been upgraded to the master node of the node cluster; the first node setting the data corresponding to the node cluster to read-only mode, the data including the root metadata.
[0008] In the solution provided in this application, after receiving the upgrade message sent by the node management server, the first node is upgraded to the master node, updates the term management data, and sets the data corresponding to the node cluster to read-only mode, ensuring that only one node can write data at any given time, thereby ensuring data consistency and avoiding data conflicts. In addition, since the whole process does not require negotiation with other nodes, the system performance is guaranteed.
[0009] In conjunction with the first aspect, in one possible implementation of the first aspect, the first node updates the term identifier while reading the root metadata identifier.
[0010] In this embodiment, the first node ensures that reading the root metadata identifier and updating the term identifier are atomic, which can prevent other nodes, such as the original master node, from concurrently modifying the root metadata identifier during this process, leading to data conflicts and inconsistencies.
[0011] In conjunction with the first aspect, in one possible implementation of the first aspect, the node cluster further includes a second node, which is used to read and write data corresponding to the node cluster and update the root metadata identifier; after the first node updates the term management data, the root metadata identifier is locked, and the root metadata identifier is prohibited from being updated by the second node.
[0012] In this embodiment of the application, before the first node updates the term management data, the second node (e.g., the original master node) can read and write the data corresponding to the node cluster and can update the root metadata identifier. However, after the first node updates the term management data, the root metadata identifier will be locked. Although the second node can continue to read and write data, it is not allowed to modify the root metadata identifier. This ensures that in the subsequent process, at any given time, only one node can write data, thus ensuring data consistency.
[0013] In conjunction with the first aspect, in one possible implementation of the first aspect, the data corresponding to the node cluster includes root metadata, metadata, and user data. The metadata is used to manage the user data, and the user data is data written to the node cluster. After the first node sets the data corresponding to the node cluster to read-only mode, it sets the metadata to read-only mode, and finally sets the user data to read-only mode.
[0014] In this embodiment, the first node is configured hierarchically, with the root metadata, metadata, and user data set to read-only mode in sequence to ensure the consistency of the data corresponding to the node cluster and to ensure that the first node can accurately find all user data written to the node cluster.
[0015] In conjunction with the first aspect, in one possible implementation of the first aspect, the first node updates the root metadata identifier and writes data to the node cluster.
[0016] In this embodiment of the application, after the first node is upgraded to become a new master node, it can write user data to the node cluster and manage the written user data by updating the root metadata identifier.
[0017] Secondly, this application provides a first node, comprising: a receiving module for receiving an upgrade message sent by a node management server, the node management server being used to manage a node cluster, the node cluster including the first node; an updating module for updating term management data, the term management data including a root metadata identifier and a term identifier, the root metadata identifier being used to determine root metadata, the root metadata being used to manage the metadata corresponding to the node cluster, and the term identifier being used to indicate that the first node has been upgraded to the master node of the node cluster; and a processing module for setting the data corresponding to the node cluster to read-only mode, the data including the root metadata.
[0018] In conjunction with the second aspect, in one possible implementation of the second aspect, the update module is further configured to update the term identifier while reading the root metadata identifier.
[0019] In conjunction with the second aspect, in one possible implementation of the second aspect, the node cluster further includes a second node, which is used to read and write data corresponding to the node cluster and update the root metadata identifier; after the update module updates the term management data, the root metadata identifier is prohibited from being updated by the second node.
[0020] In conjunction with the second aspect, in one possible implementation of the second aspect, the data corresponding to the node cluster includes root metadata, metadata, and user data. The metadata is used to manage the user data, and the user data is data written to the node cluster. The processing module is further configured to set the root metadata to read-only mode, then set the metadata to read-only mode, and finally set the user data to read-only mode.
[0021] In conjunction with the second aspect, in one possible implementation of the second aspect, the processing module is further configured to update the root metadata identifier and write data to the node cluster.
[0022] Thirdly, this application provides a computing device, the computing device including a processor and a memory, the memory being used to store program code, and the processor being used to call the program code in the memory to execute the method described in the first aspect and any implementation thereof.
[0023] Fourthly, this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, can implement the process of the method provided in the first aspect and in combination with any of the implementations of the first aspect.
[0024] Fifthly, this application provides a computer program product including instructions that, when executed by a computer, enable the computer to perform the process of the method provided in the first aspect and in combination with any implementation of the first aspect. Attached Figure Description
[0025] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0026] Figure 1 This is a schematic diagram of a node state switching provided in an embodiment of this application;
[0027] Figure 2 This is a schematic diagram of an application scenario provided by an embodiment of this application;
[0028] Figure 3 This is a flowchart illustrating a method for ensuring data consistency provided in an embodiment of this application;
[0029] Figure 4This is a schematic diagram of a data storage relationship provided in an embodiment of this application;
[0030] Figure 5 This is a schematic diagram of the structure of a first node provided in an embodiment of this application;
[0031] Figure 6 This is a schematic diagram of the structure of a computing device provided in an embodiment of this application. Detailed Implementation
[0032] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0033] First, some of the terms and related technologies used in this application will be explained in conjunction with the accompanying drawings to facilitate understanding by those skilled in the art.
[0034] Cloud databases are stable, reliable, and elastically scalable online database services. These databases are deployed in a virtual computing environment and managed through a unified management system, effectively reducing maintenance costs. Cloud databases separate computation and storage; the computation layer does not store user data, only performs calculations, while the storage layer uses a new type of shared storage system.
[0035] An atomic write is a single, indivisible transaction in which all write operations must complete or roll back together. Traditional storage systems manage data in blocks (e.g., a 512-byte block). Without atomic writes, a write operation might partially succeed and partially fail; or in concurrent scenarios, data written by two threads could overwrite each other. For example, if one thread needs to write "123" and another needs to write "456," concurrency could lead to a write of only "126". Atomic writes guarantee that a single write operation either succeeds entirely or fails entirely, thus preventing these issues.
[0036] Append-only storage is a file system customized for new storage hardware such as solid-state drives (SSDs). This file system provides basic operations such as append, delete, and seal, but does not support modification operations. The seal operation is a unique operation of the append-only storage system, which sets a file to a read-only state and prevents it from being added to.
[0037] In a distributed storage system, data is divided into user data and metadata. User data refers to the data that users actually need to read and write, stored in fixed-size folders, each folder corresponding to a unique identifier (ID). Metadata is system data used to describe and manage the characteristics of a file, such as access permissions, file owner, and file data block distribution information. In a clustered file system, distribution information includes the file's location on the disk and the disk's location within the cluster. Users must obtain a file's metadata before they can locate the file and retrieve its content or related attributes.
[0038] Generally, in distributed scenarios, to ensure the uniqueness of data writing, a distributed consensus protocol can be used to elect a master node, which then writes the data, thus ensuring that at any given time, only one node can write the data, guaranteeing data consistency.
[0039] See Figure 1 ,like Figure 1 As shown, each node has three states: standby, election, and master. All nodes start in standby. If a node does not receive a message (e.g., heartbeat) from the master node within a preset time (e.g., two heartbeat cycles), it will switch from standby to election. When a node is in election, it first votes for itself and then solicits votes from other nodes to become the master. If a node receives more than half the votes of all nodes in the cluster, it becomes the new master, and the other nodes switch to standby. The node in master state is the master node of the entire cluster; all operations such as adding, modifying, and deleting system data can only be performed through the master node.
[0040] Understandably, under the algorithmic logic of this distributed consensus protocol, it can be guaranteed that there is only one master node at any given time, thus ensuring data consistency. However, when the number of surviving nodes in the cluster is less than or equal to half of the total number of nodes, it is impossible to elect a new master node.
[0041] Furthermore, in distributed scenarios, the uniqueness of a host can be guaranteed through lock preemption. For example, when using a ZooKeeper cluster for distributed lock management, each node requests a distributed lock from ZooKeeper. ZooKeeper can then authorize a single node to use the lock based on a first-come, first-served basis or weighted allocation, and the node that ultimately obtains the lock can write data.
[0042] It should be understood that distributed locks require a long time and consume a large amount of bandwidth. In actual use, negotiation often needs to be carried out between multiple nodes, which will severely damage the performance of the entire system.
[0043] To address the aforementioned issues, this application provides a method and related equipment for ensuring data consistency, which can guarantee data consistency and avoid data conflicts without sacrificing database performance. The nodes can be containers, virtual machines, physical machines, etc., and this application does not limit their use.
[0044] See Figure 2 , Figure 2 This illustration shows a possible application scenario of an embodiment of this application. In this scenario, the distributed storage system 200 includes a node management server 210, a node cluster 220, and a storage device 230. The node cluster 220 includes a primary node 221, a backup node 222, a backup node 223, and a backup node 224. It should be understood that the node cluster 220 may also include more or fewer nodes; here, four nodes are used as an example. The storage device 230 includes a term management data storage unit 2310 and other data storage units 2320. The term management data storage unit 2310 stores the term identifier and root metadata identifier of the primary node; the other data storage units 2320 store root metadata, metadata, and user data. The node management server 210 monitors the nodes in the node cluster 220. When an anomaly is detected in the primary node 221, a backup node, such as backup node 222, is selected and promoted to the new primary node. The primary node 221 operates in both read and write modes, meaning it can read and write data to storage device 230. The backup nodes 222, 223, and 224 operate in read mode, meaning they can only read data from storage device 230 and cannot write data. Specifically, after backup node 222 is upgraded to the new primary node, it can update the primary node's term identifier in the term management data storage unit 2310 and write data to other data storage units 2320. After backup node 222 updates its term identifier, the original primary node 221 can determine that a new primary node already exists. Therefore, the original primary node 221 can no longer write data and can either terminate itself or switch its operating mode to read-only mode.
[0045] It's easy to understand that by setting up a node management server 210 to manage the node cluster 220, a new master node can be directly elected when the master node 221 fails, without needing to use distributed locks to determine the new master node, thus improving system performance. Furthermore, the storage device 230 stores a tenure identifier, ensuring that the original master node can recognize the emergence of a new master node. The original master node can avoid writing data simultaneously with the new master node by self-destructing or switching working modes, preventing data conflicts and ensuring data consistency.
[0046] Combination Figure 2 The application scenarios shown will be discussed below. Figure 3 The method for ensuring data consistency provided in the embodiments of this application is described, such as... Figure 3 As shown, the method includes, but is not limited to, the following steps:
[0047] S301: The first node receives the upgrade message sent by the node management server.
[0048] Specifically, the first node can be a virtual machine or container, running on a physical machine. Multiple nodes form a cluster, such as the node cluster 220 mentioned above. Under normal operating conditions, this cluster has only one master node, and the other nodes are backup nodes. The master node can write data, while the other backup nodes cannot write data to ensure data consistency. Clusters composed of multiple nodes can be deployed in a cloud environment, specifically on one or more computing devices (e.g., a central server) within the cloud environment; or they can be deployed in an edge environment, specifically on one or more computing devices (edge computing devices) within the edge environment. Edge computing devices can be servers. Here, a cloud environment refers to a cluster of central computing devices owned by a cloud service provider, used to provide computing, storage, and communication resources; an edge environment refers to a cluster of edge computing devices geographically far from the central cloud environment, used to provide computing, storage, and communication resources.
[0049] Furthermore, the first node can be any standby node in the node cluster, such as standby node 222 mentioned above. If the first node receives an upgrade message from the node management server during operation, it indicates that the current master node may have a fault or abnormality, and the first node needs to be upgraded to a new master node.
[0050] S302: The first node updates the term management data.
[0051] Specifically, after the first node is determined to be upgraded to the new master node, it needs to update its term management data. The term management data includes a root metadata identifier and a term identifier. The root metadata identifier is used to identify the root metadata, meaning it determines the specific location of the data stored on the storage device. The term identifier indicates that the first node has been upgraded to the new master node; that is, the term identifier changes with the change of master node. Whenever the node management server determines a new master node, the determined new master node will update its term identifier. For example, before the node management server determines the new master node, the term identifier is 5, meaning the cluster has previously had 5 master nodes. After the node management server determines the new master node, the new master node updates the term identifier to 6, indicating that the new master node is the 6th master node generated in the cluster.
[0052] It's important to note that in a distributed storage system, user-written data is ultimately written to fixed-size files, each assigned a unique identifier. As the amount of written data increases, the number of files required grows. To manage these files, specific data is needed; this data is called metadata, and the metadata includes the identifiers of these files. Each piece of metadata also has a unique identifier. Similarly, to facilitate metadata management, a root file, also called root metadata, is used. The root metadata contains the identifiers of all metadata.
[0053] For example, see Figure 4 ,like Figure 4 As shown, all user data is stored in different files, such as file 1.1, file 1.2, etc. One metadata manages multiple files. For example, metadata 1 manages file 1.1, file 1.2, ... file 1.N, and metadata 2 manages file 2.1, file 2.2, ... file 2.N. All metadata is managed by root metadata. There is only one root metadata, and the root metadata also corresponds to an identifier. This identifier and the term identifier belong to the term management data and are stored together in the term management data unit.
[0054] As can be seen, by updating the term identifier, the first node can enable the original master node to identify and determine that a new master node has been generated, thus avoiding data writing again, preventing data conflicts, and ensuring data consistency.
[0055] In one possible implementation, the first node reads the root metadata identifier while updating the term identifier.
[0056] Specifically, the first node must ensure that reading the root metadata and updating the term identifier occur simultaneously, i.e., the operation is atomic; otherwise, the operation is abandoned and re-executed.
[0057] It's easy to understand that the original master node might malfunction due to network fluctuations, causing the node management server to determine it as a failure and elect a new first node as the new master node. However, the original master node might recover after a period of time, but it wouldn't be aware of the new master node. In this situation, concurrency can occur, meaning the original master node might continue writing data and updating the root metadata identifier. If the first node doesn't simultaneously read the root metadata and update the term identifier—for example, if the first node reads the root metadata identifier first and then updates the term identifier—data inconsistency could result.
[0058] For example, if the first node reads the root metadata identifier while the original master node needs to modify its root metadata identifier, the root metadata identifier read by the first node will be inconsistent with the root metadata identifier actually stored on the storage device. Since the first node relies on the root metadata identifier to read or write data, this will ultimately lead to data loss or inconsistency. However, if the first node reads the root metadata identifier and modifies the term identifier simultaneously, because the root metadata identifier and term identifier are bound, the original master node needs to ensure that the term identifier matches the term it wrote when modifying the root metadata identifier; otherwise, the modification will fail. Therefore, in this case, the original master node will not be able to successfully modify the root metadata identifier. At this point, the original master node can determine that a new master node exists, and it will stop modifying the root metadata identifier to avoid data conflicts and ensure data consistency.
[0059] S303: The first node sets the root metadata to read-only mode.
[0060] Specifically, after updating the term management data, the first node sets the root metadata to read-only mode, meaning that the root metadata will not be allowed to be modified.
[0061] It should be understood that when the original master node is unaware that a new master node already exists and continues to write data to the storage device, as described above... Figure 4As can be seen, the written data will be stored in a fixed-size file. If the storage space of this file is insufficient to support further storage, a new file will be created for storage. At this time, the metadata needs to be modified, and the identifier and other relevant information of the newly created file will be added to the metadata. Similarly, when the storage space of the metadata is also full, a new metadata needs to be created, and the identifier and other relevant information of the newly created metadata need to be added to the root metadata. However, since the first node has already set the root metadata to read-only mode, the original master node will not be able to successfully modify the relevant information in the root metadata. At this point, the original master node will be able to determine that a new master node already exists, and the original master node will abandon this operation, stop writing data to the storage device, and use methods such as self-destruction to avoid data conflicts and ensure data consistency.
[0062] S304: The first node sets all metadata to read-only mode.
[0063] Specifically, after setting the root metadata to read-only mode, the first node sets all metadata to read-only mode, meaning that all metadata will not be allowed to be modified.
[0064] It's easy to understand that if data is written to the original master node without it being aware of the new node, and the written data causes the metadata to need to be modified, the original master node will fail to modify the metadata because the first node has already set all the metadata to read-only mode. At this point, it can be confirmed that a new master node already exists, so the original master node will abandon this operation, stop writing data to the storage device, and use methods such as self-destruction to avoid data conflicts and ensure data consistency.
[0065] S305: The first node sets all user data to read-only mode.
[0066] Specifically, after setting all metadata to read-only mode, the first node sets all files storing user data to read-only mode, meaning that no more data will be allowed to be written to any of the files.
[0067] As described in S303 and S304 above, if the original master node needs to write data, it needs to write the data to the corresponding file. However, the first node sets all files to read-only mode, causing the original master node to be unable to write data to the storage device, i.e., the write fails. At this time, the original master node can confirm that a new master node already exists. Therefore, the original master node will abandon this operation, stop writing data to the storage device, and use methods such as self-destruction to avoid data conflicts and ensure data consistency.
[0068] It is understandable that the first node is configured in a hierarchical manner, setting the root metadata, metadata, and user data to read-only mode in sequence. This can prevent data loss, ensure data consistency, and ensure that all data that has been written to the storage device can be accurately located.
[0069] S306: The first node updates the root metadata identifier and writes data to the storage device.
[0070] Specifically, after setting all files storing user data to read-only mode, the first node begins executing the functions of the master node. If the first node needs to write user data, since it has already set all files to read-only mode, it needs to rebuild a file to store the data to be written. Because a new file has been created, metadata needs to be updated, which in turn requires updating the root metadata and root metadata identifier. Other nodes can only access the data in the storage device and cannot write data to ensure data consistency.
[0071] It should be understood that steps S301 to S306 in the above method embodiments are only illustrative descriptions and should not constitute specific limitations. The steps involved can be added, reduced or combined as needed.
[0072] The methods of the embodiments of this application have been described in detail above. In order to facilitate better implementation of the above solutions of the embodiments of this application, relevant equipment for cooperating in implementing the above solutions is also provided below.
[0073] See Figure 5 , Figure 5 This is a schematic diagram of the structure of a first node provided in an embodiment of this application. The first node can be as described above. Figure 3 The first node in the method embodiment can be executed. Figure 3 The methods and steps described in the embodiment of the data consistency guarantee method take the first node as the execution subject. For example... Figure 5 As shown, the first node 500 includes a receiving module 510, an updating module 520, and a processing module 530. Among them,
[0074] The receiving module 510 is used to receive an upgrade message sent by the node management server, the node management server being used to manage a node cluster, the node cluster including the first node;
[0075] Update module 520 is used to update term management data, the term management data includes root metadata identifier and term identifier, the root metadata identifier is used to determine root metadata, the root metadata is used to manage the metadata corresponding to the node cluster, and the term identifier is used to indicate that the first node is upgraded to the master node of the node cluster;
[0076] Processing module 530 is used to set the data corresponding to the node cluster to read-only mode, the data including the root metadata.
[0077] As an example, the update module 520 is also used to update the term identifier while reading the root metadata identifier.
[0078] As an example, the node cluster further includes a second node, which is used to read and write data corresponding to the node cluster and update the root metadata identifier; after the update module 520 updates the term management data, the root metadata identifier is prohibited from being updated by the second node.
[0079] As an example, the data corresponding to the node cluster includes root metadata, metadata, and user data. The metadata is used to manage the user data, and the user data is the data written to the node cluster. The processing module 530 is further configured to set the root metadata to read-only mode, then set the metadata to read-only mode, and finally set the user data to read-only mode.
[0080] As an example, the processing module 530 is also used to update the root metadata identifier and write data to the node cluster.
[0081] It is understood that the receiving module 510 in the embodiments of this application can be implemented by a transceiver or transceiver-related circuit components, and the updating module 520 and processing module 530 can be implemented by a processor or processor-related circuit components.
[0082] It should be noted that the structure of the first node described above is merely an example and should not constitute a specific limitation. The modules within the first node can be added, removed, or merged as needed. Furthermore, the operations and / or functions of each module in the first node are designed to achieve the above... Figure 3 For the sake of brevity, the corresponding process of the described method will not be elaborated here.
[0083] See Figure 6 , Figure 6 This is a schematic diagram of the structure of a computing device provided in an embodiment of this application. Figure 6 As shown, the computing device 600 includes a processor 610, a communication interface 620, and a memory 630, which are interconnected via an internal bus 640. It should be understood that the computing device 600 can be a computing device in cloud computing or a computing device in an edge environment.
[0084] The processor 610 may consist of one or more general-purpose processors, such as a central processing unit (CPU), or a combination of a CPU and hardware chips. The hardware chips may be application-specific integrated circuits (ASICs), programmable logic devices (PLDs), or combinations thereof. The PLDs may be complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), generic array logic (GALs), or any combination thereof.
[0085] Bus 640 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Bus 640 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 6 The symbol is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0086] Memory 630 may include volatile memory, such as random access memory (RAM); memory 630 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); memory 630 may also include combinations of the above types. Memory 730 can be used to store programs and data so that processor 610 can call the program code stored in memory 630 to implement the above-described method for ensuring data consistency. The program code can be used to implement... Figure 5 The first node shown is a functional module, or is used to implement Figure 3 The method steps shown in the embodiment are executed with the first node as the main body.
[0087] This application also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program that, when executed by a processor, can implement some or all of the steps described in any of the above method embodiments.
[0088] This invention also provides a computer program that includes instructions that, when executed by a computer, enable the computer to perform some or all of the steps of any method for ensuring data consistency.
[0089] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0090] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0091] In the several embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical or other forms.
[0092] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0093] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
Claims
1. A method for ensuring data consistency, characterized in that, The method includes: The first node receives an upgrade message sent by the node management server, which manages a node cluster, including the first node; the upgrade message is used to instruct the first node to be upgraded to a new master node. The first node updates the term management data, which includes a root metadata identifier and a term identifier. The root metadata identifier is used to determine the root metadata, which is used to manage the metadata corresponding to the node cluster. The term identifier is used to indicate that the first node has been upgraded to the master node of the node cluster. The first node updating the term management data includes: the first node reading the root metadata identifier and updating the term identifier at the same time. After the first node sets the root metadata corresponding to the node cluster to read-only mode, it sets the metadata corresponding to the node cluster to read-only mode, and finally sets the user data corresponding to the node cluster to read-only mode.
2. The method as described in claim 1, characterized in that, The node cluster also includes a second node, which is used to read and write data corresponding to the node cluster and update the root metadata identifier; after the first node updates the term management data: The root metadata identifier is locked, and the root metadata identifier is prohibited from being updated by the second node.
3. The method as described in claim 1 or 2, characterized in that, After the first node sets the data corresponding to the node cluster to read-only mode, the method further includes: The first node updates the root metadata identifier and writes user data to the node cluster.
4. A first node, characterized in that, include: A receiving module is used to receive upgrade messages sent by a node management server, wherein the node management server is used to manage a node cluster, and the node cluster includes the first node; The upgrade message is used to instruct the first node to be upgraded to a new master node; The update module is used to update the term management data, which includes a root metadata identifier and a term identifier. The root metadata identifier is used to determine the root metadata, which is used to manage the metadata corresponding to the node cluster. The term identifier is used to indicate that the first node has been upgraded to the master node of the node cluster. The update module is also used to update the term identifier while reading the root metadata identifier; The processing module is used to set the root metadata corresponding to the node cluster to read-only mode, then set the metadata corresponding to the node cluster to read-only mode, and finally set the user data corresponding to the node cluster to read-only mode.
5. The first node as described in claim 4, characterized in that, The node cluster also includes a second node, which is used to read and write data corresponding to the node cluster and update the root metadata identifier. After the update module updates the term management data, the root metadata identifier is prohibited from being updated by the second node.
6. The first node as described in claim 4 or 5, characterized in that, The processing module is also used to update the root metadata identifier and write data to the node cluster.
7. A computing device, characterized in that, The computing device includes at least one storage unit and at least one processor, the at least one storage unit being used to store at least one instruction, and the at least one processor executing the at least one instruction to implement the method as described in any one of claims 1-3.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1-3.
9. A computer program product, characterized in that, The computer program product includes instructions that, when executed by a computer, implement the method as described in any one of claims 1-3.