Methods, apparatus, electronic devices and storage media for determining version numbers
By determining the minimum version number and consecutive replay points in the target node, the weakly consistent read version number can be quickly determined, which solves the problem of high resource consumption in the prior art and improves system performance.
Patent Information
- Application Number
- CN202311524293.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-15
- Publication Date
- 2026-11-10
- Estimated Expiration
- 2043-11-15
AI Technical Summary
Existing technologies consume significant system resources when determining weakly consistent read version numbers, leading to a decrease in system performance.
By determining the target node pointed to by the frozen pointer, the minimum version number and continuous replay points contained in the target node are obtained. Based on this information, the weak consistency read version number is quickly determined, reducing system overhead.
It improves system performance, enables rapid determination of weakly consistent read version numbers, and reduces system resource consumption.
Smart Images

Figure CN117573738B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, specifically to a method, apparatus, electronic device, and storage medium for determining a version number. Background Technology
[0002] Databases typically offer two levels of query handling: strong consistency reads and weak consistency reads. Strong consistency reads usually route requests to the primary replica to retrieve the latest data. Weak consistency reads typically prioritize routing requests to the backup replica and do not require access to the latest data.
[0003] When performing weakly consistent reads, it is necessary to ensure that the data read is data that has been successfully committed. This requires generating a safe and readable version number, i.e., the weakly consistent read version number.
[0004] In current technology, a hash table is typically used to store the log replay version number (prepare version) of all active transactions during the prepare phase. The weakly consistent read version number is determined by traversing the hash table based on the prepare version of each active transaction. However, traversing the hash table consumes a significant amount of system resources. Summary of the Invention
[0005] The purpose of this application is to provide a method, apparatus, electronic device, and storage medium for determining version numbers, so as to reduce the system resources consumed when determining weakly consistent read version numbers.
[0006] On the one hand, embodiments of this application provide a method for determining a version number, including:
[0007] Determine the target node that the freeze pointer points to; the target node is a node in the array; the freeze pointer moves according to the number of transactions in the node of the array; the number of transactions is the number of transactions in the node;
[0008] Obtain the minimum version number and consecutive replay position contained in the target node; the minimum version number is the minimum value of the first-stage replay version number corresponding to at least one transaction in the node; the first-stage replay version number is the version number of the first-stage log corresponding to the transaction; the consecutive replay position is determined based on the maximum value of the version number of at least one consecutively replayed log in the log stream when the node is frozen.
[0009] The weak consistency read version number is determined based on the minimum version number contained in the target node and the consecutive replay points.
[0010] In one embodiment, the method further includes:
[0011] Replay the logs in the log stream; the log stream contains at least one log.
[0012] If the first-stage log is replayed in the log stream, then based on the first transaction corresponding to the first-stage log, update the node information of the active node pointed to by the active pointer in the array, and establish the correspondence between the first transaction and the active node time; the active pointer moves according to the number of transactions in the nodes of the array;
[0013] If a second-stage log is replayed in the log stream, the second transaction corresponding to the second-stage log is determined, and the node information of the corresponding node in the array for the second transaction is updated based on the correspondence.
[0014] In one implementation, based on the first transaction corresponding to the first phase log, the node information of the active node pointed to by the active pointer in the array is updated, including:
[0015] Determine the active node that the active pointer points to in the array;
[0016] Increment the number of transactions in the active nodes by one;
[0017] Obtain the first phase replay version number of the first transaction;
[0018] If the first-stage replay version number is lower than the minimum version number contained in the active nodes, then the minimum version number will be updated to the first-stage replay version number.
[0019] In one implementation, after establishing the correspondence between the first transaction and the active node time, the method further includes:
[0020] If the number of transactions of an active node reaches the set number for the active node, the maximum value of the version number of at least one log that is continuously replayed in the log stream will be determined as the continuous replay point of the active node.
[0021] Set the node status of the active nodes to frozen;
[0022] Increment the active pointer by one.
[0023] In one implementation, based on the correspondence, the node information of the node corresponding to the second transaction in the array is updated, including:
[0024] Based on the correspondence, obtain the node corresponding to the second transaction;
[0025] Decrease the number of transactions in the node corresponding to the second transaction by one.
[0026] In one embodiment, the method further includes:
[0027] If it is determined that the number of transactions in the node currently pointed to by the freeze pointer is zero, then increment the freeze pointer by one;
[0028] If it is determined that the pointer value of the frozen pointer is the same as the pointer value of the active pointer, then the active pointer is incremented by one.
[0029] In one implementation, the weak consistency read version number is determined based on the minimum version number contained in the target node and the consecutive replay points, including:
[0030] Subtract one from the consecutive replay points contained in the target node to obtain a new consecutive replay point;
[0031] The minimum version number contained in the target node and the minimum value in the new consecutive replay points are determined as the weakly consistent read version number.
[0032] On one hand, embodiments of this application provide a version number determination apparatus, including:
[0033] The first determining unit is used to determine the target node pointed to by the frozen pointer; the target node is a node in the array; the frozen pointer moves according to the number of transactions in the node of the array; the number of transactions is the number of transactions in the node;
[0034] The acquisition unit is used to acquire the minimum version number and continuous replay position contained in the target node; the minimum version number is the minimum value of the first-stage replay version number corresponding to at least one transaction in the node; the first-stage replay version number is the version number of the first-stage log corresponding to the transaction; the continuous replay position is determined based on the maximum value of the version number of at least one continuously replayed log in the log stream when the node is frozen.
[0035] The second determining unit is used to determine the weakly consistent read version number based on the minimum version number contained in the target node and the continuous replay points.
[0036] In one embodiment, the first determining unit is further configured to:
[0037] Replay the logs in the log stream; the log stream contains at least one log.
[0038] If the first-stage log is replayed in the log stream, then based on the first transaction corresponding to the first-stage log, update the node information of the active node pointed to by the active pointer in the array, and establish the correspondence between the first transaction and the active node time; the active pointer moves according to the number of transactions in the nodes of the array;
[0039] If a second-stage log is replayed in the log stream, the second transaction corresponding to the second-stage log is determined, and the node information of the corresponding node in the array for the second transaction is updated based on the correspondence.
[0040] In one embodiment, the first determining unit is further configured to:
[0041] Determine the active node that the active pointer points to in the array;
[0042] Increment the number of transactions in the active nodes by one;
[0043] Obtain the first phase replay version number of the first transaction;
[0044] If the first-stage replay version number is lower than the minimum version number contained in the active nodes, then the minimum version number will be updated to the first-stage replay version number.
[0045] In one embodiment, the first determining unit is further configured to:
[0046] If the number of transactions of an active node reaches the set number for the active node, the maximum value of the version number of at least one log that is continuously replayed in the log stream will be determined as the continuous replay point of the active node.
[0047] Set the node status of the active nodes to frozen;
[0048] Increment the active pointer by one.
[0049] In one embodiment, the first determining unit is further configured to:
[0050] Based on the correspondence, obtain the node corresponding to the second transaction;
[0051] Decrease the number of transactions in the node corresponding to the second transaction by one.
[0052] In one embodiment, the first determining unit is further configured to:
[0053] If it is determined that the number of transactions in the node currently pointed to by the freeze pointer is zero, then increment the freeze pointer by one;
[0054] If it is determined that the pointer value of the frozen pointer is the same as the pointer value of the active pointer, then the active pointer is incremented by one.
[0055] In one embodiment, the second determining unit is used to:
[0056] Subtract one from the consecutive replay points contained in the target node to obtain a new consecutive replay point;
[0057] The minimum version number contained in the target node and the minimum value in the new consecutive replay points are determined as the weakly consistent read version number.
[0058] On one hand, embodiments of this application provide an electronic device, including:
[0059] Processor; and
[0060] The memory stores computer instructions that cause the processor to perform the steps of the methods provided in the various alternative implementations as determined by any of the version numbers above.
[0061] On one hand, embodiments of this application provide a storage medium storing computer instructions for causing a computer to perform the steps of the methods provided in various optional implementations as determined by any of the version numbers above.
[0062] The method, apparatus, electronic device, and storage medium for determining version numbers provided in this application embodiment determine the target node pointed to by the freeze pointer; the target node is a node in an array; the freeze pointer moves according to the number of transactions in the node of the array; the number of transactions is the number of transactions in the node; the minimum version number and consecutive replay positions contained in the target node are obtained; the minimum version number is the minimum value of the first-stage replay version number corresponding to at least one transaction in the node; the first-stage replay version number is the version number of the first-stage log corresponding to the transaction; the consecutive replay positions are determined according to the maximum value of the version number of at least one consecutively replayed log in the log stream when the node is frozen; the weak consistency read version number is determined according to the minimum version number and consecutive replay positions contained in the target node. Thus, determining the weak consistency read version number based on the minimum version number and consecutive replay positions contained in the target node reduces system overhead, improves system performance, and allows for rapid determination of the weak consistency read version number. Attached Figure Description
[0063] To more clearly illustrate the technical solutions in the specific embodiments of this application or the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0064] Figure 1 This is a flowchart of a log playback method according to an embodiment of this application.
[0065] Figure 2 This is an example diagram of an array in an embodiment of this application.
[0066] Figure 3 This is an example diagram of log playback in an embodiment of this application.
[0067] Figure 4 This is a flowchart illustrating a method for determining a version number in an embodiment of this application.
[0068] Figure 5 This is a structural block diagram of the device whose version number is determined in the embodiments of this application.
[0069] Figure 6 This is a schematic diagram of the structure of the electronic device in the embodiments of this application. Detailed Implementation
[0070] The technical solution of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application. Furthermore, the technical features involved in the different embodiments of this application described below can be combined with each other as long as they do not conflict with each other.
[0071] First, some of the terms used in the embodiments of this application will be explained to facilitate understanding by those skilled in the art.
[0072] Terminal devices can be mobile terminals, fixed terminals, or portable terminals, such as mobile phones, sites, units, devices, multimedia computers, multimedia tablets, internet nodes, communicators, desktop computers, laptop computers, notebook computers, netbook computers, tablet computers, personal communication system devices, personal navigation devices, personal digital assistants, audio / video players, digital cameras / camcorders, positioning devices, television receivers, radio broadcast receivers, e-book devices, gaming devices, or any combination thereof, including accessories and peripherals of these devices, or any combination thereof. It is also foreseeable that terminal devices can support any type of user-facing interface (e.g., wearable devices).
[0073] Servers can be independent physical servers, server clusters or distributed systems composed of multiple physical servers, or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, and big data and artificial intelligence platforms.
[0074] ACID properties refer to the four properties that a database management system typically requires to ensure that transactions are correct and reliable during the writing or updating of data: atomicity, consistency, isolation, and durability.
[0075] Two-phase replay is a protocol that guarantees the ACID properties of transactions. It typically consists of a prepare phase and a commit phase. The prepare phase generates a prepare log and a prepare version, while the commit phase generates a commit log and a commit version. A transaction is considered successfully committed only after both the prepare and commit phases are completed sequentially. This transaction can be a distributed transaction.
[0076] Distributed transactions refer to transactions in a distributed system that require operations on multiple participants. These participants can be different processes, different computers, different databases, etc. Distributed transactions must possess ACID properties to guarantee their correct execution.
[0077] A log stream is a dynamic data stream containing at least one log. Each piece of data in a log stream is a log entry. Each log entry in a log stream has its own timestamp, and the timestamps of all log entries in the stream are incremented. Logs in a log stream can be categorized by log type into transaction prepare logs and commit logs; that is, each transaction typically corresponds to one prepare log and one commit log.
[0078] Log replay refers to synchronizing data from the leader replica's log stream to the follower replicas and re-executing the operations recorded in the log on the followers to ensure data consistency with the leader. In databases (e.g., distributed databases), a single piece of data typically has multiple replicas, which can be categorized as leader replicas and follower replicas. Each replica has its own log stream. For example, during a system restart after a crash, modifications made by uncommitted transactions need to be rolled back; this process of reverting changes is called log replay.
[0079] Continuous replay point: This is the largest version number of each consecutively replayed log entry in the log stream. It's important to note that multiple replay threads typically act as consumer threads, consuming data from the log stream. Each replay thread selects a log entry for replay, and each log entry is replayed only once. These replay threads execute concurrently. Logs from a single transaction are replayed sequentially, while logs from different transactions are usually replayed out of order. Therefore, the largest version number of consecutively replayed log entries in the log stream is determined as the continuous replay point.
[0080] Based on the deficiencies of the aforementioned related technologies, this application provides a method, apparatus, electronic device, and storage medium for determining version numbers, aiming to reduce the system resources consumed when determining weakly consistent read version numbers.
[0081] This application provides a method for determining a version number. This method can be applied to electronic devices. This application does not limit the type of electronic device; it can be any suitable device type, such as smartphones, tablets, and databases, etc., which will not be elaborated further. In one application scenario, it is applied to a distributed database, which can be OceanBase.
[0082] It should be noted that the determined weak consistency read version number needs to meet two conditions: 1. The data read through the weak consistency read version number must be committed data; 2. The weak consistency read version number cannot be rolled back. Therefore, in this embodiment, an array containing at least one node is first generated based on log replay. Then, the weak consistency read version number is determined based on the node information in the array.
[0083] See Figure 1 The diagram shown is a flowchart of a log playback method according to an embodiment of this application. The following is a summary of the process. Figure 1 The method is described below, and the specific implementation process is as follows:
[0084] Step 100: Replay the logs in the log stream.
[0085] In one implementation, logs in the log stream are replayed through one or more log replay processes.
[0086] Each log replay process replays one log entry, and the logs replayed by different log replay processes are different, resulting in out-of-order replay of logs in the log stream.
[0087] It's important to note that the log stream can be viewed as a dynamic data stream, where each piece of data is a log entry. Before the device applies (i.e., consumes) the log stream, the log entries are sequential; however, during the application of the log stream, the log entries become out of order.
[0088] It should be noted that the logs replayed in the log stream may be either first-stage logs or second-stage logs. First-stage logs are the transaction's prepare logs. Second-stage logs are the transaction's commit logs. Each transaction corresponds to one prepare log and one commit log. If first-stage logs are replayed in the log stream, proceed to step 101; if second-stage logs are replayed, proceed to step 103.
[0089] Step 101: If the first-stage log is replayed in the log stream, then update the node information of the active node pointed to by the active pointer in the array according to the first transaction corresponding to the first-stage log.
[0090] The active pointer moves based on the number of transactions in a node of the array.
[0091] In one implementation, the following steps may be performed before executing step 101:
[0092] S1011: If the first-stage log is replayed in the log stream, then determine the active node that the active pointer points to in the array.
[0093] The array contains at least one node. Optionally, the array can be a circular array, and its length can be fixed or variable. A node can be a Node structure. Node information can include the number of transactions (cnt), the minimum version number (min_version), the continuous replay checkpoint, and the node state (state).
[0094] The minimum version number is the minimum value of the first-stage replay version numbers corresponding to all transactions within the node; node status includes frozen and active. An active node has an active status. The continuous replay point is determined based on the maximum version number of all continuously replayed logs in the log stream when the node is frozen. In one implementation, checkpoint = the aforementioned maximum value + 1.
[0095] See Figure 2 The image shown is an example diagram of an array. The array contains multiple nodes. The node information for each node includes min_version, cnt, state, and checkpoint.
[0096] S1012: Increment the number of transactions in the active node by one.
[0097] In this way, if the first-stage log corresponding to a transaction is replayed, the transaction is loaded into an active node, and the number of active nodes is incremented by one.
[0098] S1013: Get the first phase replay version number of the first transaction.
[0099] It should be noted that each log has a corresponding version number, and the version number of the first stage replay is the version number of the first stage log.
[0100] S1014: If the first-stage replay version number is lower than the minimum version number contained in the active nodes, then update the minimum version number to the first-stage replay version number.
[0101] The following example illustrates the update process for active nodes.
[0102] When a transaction's prepare log is replayed, perform the following steps:
[0103] Find the Node pointed to by the active pointer active_index and represent it as node_A; increment the cnt field of node_A by one, and compare the min_version of node_A with the first stage replay version number prepared version of the prepared log above. If prepared version is less than min_version, then update the min_version of node_A to prepared version.
[0104] In this way, when the transaction's prepare log is replayed, the number of transactions and the minimum version number in the active node pointed to by active_index can be updated.
[0105] Step 102: Establish the correspondence between the first transaction and the active node time.
[0106] In one implementation, an index can be used to establish the correspondence between the first transaction and the active node time.
[0107] Specifically, the index table can store the first transaction and the current pointer value of the active pointer, and use this pointer value as the index of the first transaction, with each pointer value corresponding to a node. In this way, in subsequent steps, the node of each transaction in the array can be determined based on the transaction index.
[0108] Furthermore, when the number of transactions in a node reaches the set number m corresponding to the active node, the current active node can be frozen and the active pointer can be pointed to the next node.
[0109] In practical applications, the set quantity can be set according to the actual application scenario. The set quantity for different nodes can be the same or different. For example, the set quantity can be 1000, and there is no restriction here.
[0110] In one implementation, step 102 may be performed using the following steps:
[0111] S1021: If the number of transactions of an active node reaches the set number corresponding to the active node, the maximum value of the version number of at least one log that is continuously replayed in the log stream is determined as the continuous replay point of the active node.
[0112] See Figure 3 The image shown is an example diagram of log playback. Figure 3 This is the log stream for the follower replicas of a specific partition. The log stream contains six logs: three prepare logs and three commit logs. Log replay is performed by replay thread 1 and replay thread 2 respectively.
[0113] After logs with log_id 1 and 3 are replayed, since logs with log_id 2 have not yet been replayed, logs with log_id 1 and 3 are not consecutively replayed. Therefore, the version number of logs with log_id 1 is determined as the consecutive replay point. After logs with log_id 2 are replayed, since logs with log_id 1, 2, and 3 are all replayed, they are consecutively replayed. Therefore, the maximum value of 300, corresponding to the version numbers of logs with log_id 1, 2, and 3, is determined as the current consecutive replay point.
[0114] S1022: Set the node status of the active node to frozen.
[0115] It's important to note that each node has a node status field to record its state. Node status includes two types: frozen and active. When a node is frozen, it means that the node is inactive. The node pointed to by the active pointer is active, while the other nodes are frozen. When a node is frozen, the current continuous replay point of the log stream is filled into the node's checkpoint field.
[0116] S1023: Increment the active pointer.
[0117] Specifically, after a node is full of transactions, the active_index is incremented by one, and then active_index points to the next node, so that the next node can be used as an active node to continue loading transactions.
[0118] Step 103: If the second-stage log is replayed in the log stream, then determine the second transaction corresponding to the second-stage log.
[0119] Step 104: Based on the correspondence, update the node information of the node corresponding to the second transaction in the array.
[0120] In one implementation, step 104 may be performed using the following steps:
[0121] S1041: Based on the correspondence, obtain the node corresponding to the second transaction.
[0122] In one implementation, the pointer value corresponding to the second transaction is obtained from the index table, and the node corresponding to the second transaction is found based on the pointer value.
[0123] S1042: Decrease the number of transactions in the node corresponding to the second transaction by one.
[0124] In one implementation, the cnt value of the node is decreased by one.
[0125] Thus, when the second-stage log is replayed, the second transaction is removed from the node, and the number of transactions in the node is reduced by one.
[0126] In this embodiment, when the prepare log of a transaction is replayed, the active node pointed to by active_index is found, and the transaction is "loaded" into the active node. Simultaneously, the min_version and cnt of the active node are updated, with min_version recording the minimum prepare version of all transactions in the active node. Furthermore, if it is determined that cnt reaches a set number m, the current consecutive replay position in the log stream is stored in the active node, the active node is frozen, and active_index is set to point to the next node, making the next node the new active node.
[0127] When a transaction's commit log is replayed, the transaction is "retrieved" from its node, and therefore, the cnt count of that node is decremented. Further, if the frozen pointer currently points to that node, and the number of transactions in that node has decreased to zero (meaning all transactions on that node have been committed), the frozen pointer is incremented to determine the weakly consistent read version number based on the transactions on the next node. If the frozen pointer's value is the same as the active pointer's value, the active pointer is incremented. The frozen and active pointers point to different nodes.
[0128] See Figure 4 The diagram shown is a flowchart of a version number determination method according to an embodiment of this application. The following is a detailed explanation. Figure 4 The method is described below, and the specific implementation process is as follows:
[0129] Step 401: Determine the target node pointed to by the freeze pointer.
[0130] The target node is a node in the array; the frozen pointer moves according to the number of transactions in the node of the array; the number of transactions is the number of transactions in the node.
[0131] Step 402: Obtain the minimum version number and consecutive replay points contained in the target node.
[0132] The minimum version number is the minimum value of the first-stage replay version number corresponding to at least one transaction in the node; the first-stage replay version number is the version number of the first-stage log corresponding to the transaction; the continuous replay point is determined based on the maximum value of the version number of at least one continuously replayed log in the log stream when the node is frozen.
[0133] Step 403: Determine the weak consistency read version number based on the minimum version number and consecutive replay points contained in the target node.
[0134] In one implementation, when performing step 403, the following steps may be adopted:
[0135] S4031: Decrease the number of consecutive replay points in the target node by one to obtain a new consecutive replay point.
[0136] It should be noted that each frozen node contains consecutive replay points, but only the consecutive replay points in the target node pointed to by the frozen pointer are valid.
[0137] S4032: The minimum version number contained in the target node and the minimum value in the new consecutive replay points are determined as the weakly consistent read version number.
[0138] Furthermore, the frozen pointer can be moved based on the number of transactions in a node.
[0139] In one implementation, if it is determined that the number of transactions in the node currently pointed to by the freeze pointer is zero, the freeze pointer is incremented by one.
[0140] Furthermore, the active pointer can be moved based on the frozen pointer.
[0141] In one implementation, if it is determined that the pointer value of the frozen pointer is the same as the pointer value of the active pointer, then the active pointer is incremented by one. Figure 2 In this array, the active pointer and the frozen pointer point to different nodes. The active pointer and the frozen pointer maintain a sliding window on the array.
[0142] The following explanation demonstrates the correctness of reading version numbers with weak consistency.
[0143] Assume that Node1 is frozen earlier than Node2, and the freezing pointer frozen_index points to Node1. At the current moment, the minimum value of the version of the transaction for which all prepare logs in the log stream have been replayed and the commit log has not been replayed yet is actual_min_version. If the generated weak consistency read version number satisfies both of the following two conditions at the same time, it indicates that the weak consistency read version number is correct: 1. The weak consistency read version number is not only less than or equal to actual_min_version, but also less than the continuous replay position; 2. The weak consistency read version number does not roll back.
[0144] If the min_version in Node1 is equal to actual_min_version, the continuous replay position when Node1 is frozen is definitely greater than or equal to min_version. Therefore, directly returning min_version as the weak consistency read version number is sufficient, which satisfies the first condition described above.
[0145] If the min_version in Node1 is greater than actual_min_version, the transaction corresponding to actual_min_version must have been loaded into Node2, that is, when Node1 is frozen, the prepare log of the transaction corresponding to actual_min_version has not been replayed yet. Because if both the transaction corresponding to actual_min_version and the transaction corresponding to min_version are loaded into Node1, and actual_min_version is smaller than min_version, min_version will be updated to the smaller actual_min_version, which contradicts that the min_version in Node1 is greater than actual_min_version.
[0146] That is to say, when Node1 is frozen, the continuous replay position is definitely less than actual_min_version, and this continuous replay position smaller than actual_min_version will be written into Node1 when Node1 is frozen. At this time, the weak consistency read version number = min(min_version of Node1, continuous replay position of Node1 - 1) < actual_min_version, which satisfies the first condition described above.
[0147] Regarding the second condition above, since both the consecutive replay positions in Node1 and min_version are increasing, using the minimum value between the consecutive replay positions and min_version as the weakly consistent read version number will not backtrack.
[0148] Traditionally, it's necessary to traverse every transaction in the hash table to determine the weakly consistent read version number, resulting in a time complexity of O(n), where n is the number of active transactions. Clearly, the more transactions there are, the higher the complexity, the greater the system overhead, and the lower the efficiency. However, in this embodiment, the weakly consistent read version number is determined based on the minimum version number contained in the target node and the consecutive replay points, achieving a time complexity of O(1). The complexity does not increase with the number of transactions, reducing system overhead, improving system performance, and allowing for rapid determination of the weakly consistent read version number.
[0149] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0150] Based on the same inventive concept, this application also provides a version number determination device. Since the principle of the above-described device and apparatus in solving the problem is similar to that of a version number determination method, the implementation of the above-described device can refer to the implementation of the method, and repeated details will not be described again. This device can be applied to electronic devices. This application does not limit the type of electronic device; it can be any suitable type of device, such as smartphones, tablet computers, etc., which will not be described again in this application.
[0151] See Figure 5 The diagram shown is a structural block diagram of the device for determining the version number in an embodiment of this application. In some embodiments, the device for determining the version number exemplified in this application includes:
[0152] The first determining unit 501 is used to determine the target node pointed to by the frozen pointer; the target node is a node in the array; the frozen pointer moves according to the number of transactions in the node of the array; the number of transactions is the number of transactions in the node;
[0153] The acquisition unit 502 is used to acquire the minimum version number and continuous replay position contained in the target node; the minimum version number is the minimum value of the first-stage replay version number corresponding to at least one transaction in the node; the first-stage replay version number is the version number of the first-stage log corresponding to the transaction; the continuous replay position is determined based on the maximum value of the version number of at least one continuously replayed log in the log stream when the node is frozen.
[0154] The second determining unit 503 is used to determine the weakly consistent read version number based on the minimum version number contained in the target node and the continuous replay position.
[0155] In one embodiment, the first determining unit 501 is further configured to:
[0156] Replay the logs in the log stream; the log stream contains at least one log.
[0157] If the first-stage log is replayed in the log stream, then based on the first transaction corresponding to the first-stage log, update the node information of the active node pointed to by the active pointer in the array, and establish the correspondence between the first transaction and the active node time; the active pointer moves according to the number of transactions in the nodes of the array;
[0158] If a second-stage log is replayed in the log stream, the second transaction corresponding to the second-stage log is determined, and the node information of the corresponding node in the array for the second transaction is updated based on the correspondence.
[0159] In one embodiment, the first determining unit 501 is further configured to:
[0160] Determine the active node that the active pointer points to in the array;
[0161] Increment the number of transactions in the active nodes by one;
[0162] Obtain the first phase replay version number of the first transaction;
[0163] If the first-stage replay version number is lower than the minimum version number contained in the active nodes, then the minimum version number will be updated to the first-stage replay version number.
[0164] In one embodiment, the first determining unit 501 is further configured to:
[0165] If the number of transactions of an active node reaches the set number for the active node, the maximum value of the version number of at least one log that is continuously replayed in the log stream will be determined as the continuous replay point of the active node.
[0166] Set the node status of the active nodes to frozen;
[0167] Increment the active pointer by one.
[0168] In one embodiment, the first determining unit 501 is further configured to:
[0169] Based on the correspondence, obtain the node corresponding to the second transaction;
[0170] Decrease the number of transactions in the node corresponding to the second transaction by one.
[0171] In one embodiment, the first determining unit 501 is further configured to:
[0172] If it is determined that the number of transactions in the node currently pointed to by the freeze pointer is zero, then increment the freeze pointer by one;
[0173] If it is determined that the pointer value of the frozen pointer is the same as the pointer value of the active pointer, then the active pointer is incremented by one.
[0174] In one embodiment, the second determining unit 503 is used to:
[0175] Subtract one from the consecutive replay points contained in the target node to obtain a new consecutive replay point;
[0176] The minimum version number contained in the target node and the minimum value in the new consecutive replay points are determined as the weakly consistent read version number.
[0177] The method, apparatus, electronic device, and storage medium for determining version numbers provided in this application embodiment determine the target node pointed to by the freeze pointer; the target node is a node in an array; the freeze pointer moves according to the number of transactions in the node of the array; the number of transactions is the number of transactions in the node; the minimum version number and consecutive replay positions contained in the target node are obtained; the minimum version number is the minimum value of the first-stage replay version number corresponding to at least one transaction in the node; the first-stage replay version number is the version number of the first-stage log corresponding to the transaction; the consecutive replay positions are determined according to the maximum value of the version number of at least one consecutively replayed log in the log stream when the node is frozen; the weak consistency read version number is determined according to the minimum version number and consecutive replay positions contained in the target node. Thus, determining the weak consistency read version number based on the minimum version number and consecutive replay positions contained in the target node reduces system overhead, improves system performance, and allows for rapid determination of the weak consistency read version number.
[0178] This application provides an electronic device, including:
[0179] Processor; and
[0180] The memory stores computer instructions that cause the processor to execute the methods of any of the above-described embodiments.
[0181] This application provides a storage medium storing computer instructions for causing a computer to execute the methods of any of the above embodiments.
[0182] Figure 6 A schematic diagram of the structure of an electronic device 6000 is shown. (See also...) Figure 6 As shown, the electronic device 6000 includes a processor 6010 and a memory 6020, and optionally may also include a power supply 6030, a display unit 6040, and an input unit 6050.
[0183] The processor 6010 is the control center of the electronic device 6000. It connects various components through various interfaces and lines, and performs various functions of the electronic device 6000 by running or executing software programs and / or data stored in the memory 6020.
[0184] In this embodiment, when the processor 6010 calls the computer program stored in the memory 6020, it executes the steps in the above embodiments.
[0185] Optionally, the processor 6010 may include one or more processing units; preferably, the processor 6010 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 6010. In some embodiments, the processor and memory may be implemented on a single chip; in some embodiments, they may also be implemented separately on independent chips.
[0186] The memory 6020 may primarily include a program storage area and a data storage area. The program storage area may store the operating system, various applications, etc.; the data storage area may store data created based on the use of the electronic device 6000, etc. In addition, the memory 6020 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device, etc.
[0187] Electronic device 6000 also includes a power supply 6030 (such as a battery) that supplies power to various components. The power supply can be logically connected to processor 6010 through a power management system, thereby enabling the management of charging, discharging, and power consumption.
[0188] The display unit 6040 can be used to display information input by the user or information provided to the user, as well as various menus of the electronic device 6000. In this embodiment, it is mainly used to display the display interfaces of various applications in the electronic device 6000, as well as text, images, and other objects displayed on the display interfaces. The display unit 6040 may include a display panel 6041. The display panel 6041 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
[0189] The input unit 6050 can be used to receive information such as numbers or characters input by the user. The input unit 6050 may include a touch panel 6051 and other input devices 6052. The touch panel 6051, also known as a touch screen, can collect touch operations on or near the touch panel 6051 by the user (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel 6051).
[0190] Specifically, the touch panel 6051 can detect user touch operations and the signals generated by these operations, convert them into touch point coordinates, send them to the processor 6010, and receive and execute commands from the processor 6010. Furthermore, the touch panel 6051 can be implemented using various types of touch technologies, including resistive, capacitive, infrared, and surface acoustic wave. Other input devices 6052 can include, but are not limited to, one or more of the following: physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.
[0191] Of course, the touch panel 6051 can cover the display panel 6041. When the touch panel 6051 detects a touch operation on or near it, it transmits the information to the processor 6010 to determine the type of touch event. Subsequently, the processor 6010 provides corresponding visual output on the display panel 6041 based on the type of touch event. Although in Figure 6 In this embodiment, the touch panel 6051 and the display panel 6041 are two separate components to realize the input and output functions of the electronic device 6000. However, in some embodiments, the touch panel 6051 and the display panel 6041 can be integrated to realize the input and output functions of the electronic device 6000.
[0192] The electronic device 6000 may also include one or more sensors, such as a pressure sensor, a gravity acceleration sensor, a proximity sensor, etc. Of course, depending on the specific application, the electronic device 6000 may also include other components such as a camera. Since these components are not the focus of this application embodiment, therefore... Figure 6It is not shown in the text and will not be described in detail here.
[0193] Those skilled in the art will understand that Figure 6 This is merely an example of an electronic device and does not constitute a limitation on the electronic device. It may include more or fewer components than shown, or a combination of certain components, or different components.
[0194] For ease of description, the above sections are divided into modules (or units) according to their functions and described separately. Of course, in implementing this application, the functions of each module (or unit) can be implemented in one or more software or hardware components.
[0195] Obviously, the above embodiments are merely examples for clear illustration and are not intended to limit the embodiments. Those skilled in the art can make other variations or modifications based on the above description. It is neither necessary nor possible to exhaustively list all embodiments here. However, obvious variations or modifications derived therefrom are still within the scope of protection of this application.
Claims
1. A method for determining a version number, the method comprising: Replay the logs in the log stream; The log stream contains at least one log; If the log stream contains a first-stage log that is replayed, then based on the first transaction corresponding to the first-stage log, update the node information of the active node pointed to by the active pointer in the array, and establish the correspondence between the first transaction and the time of the active node. The active pointer moves within the array based on the number of transactions in the nodes of the array; If the number of transactions of the active node reaches the set number corresponding to the active node, then the maximum value of the version number of at least one log that is continuously replayed in the log stream is determined as the continuous replay point of the active node. Set the node status of the active nodes to frozen; increment the active pointer by one; The target node to which the freeze pointer points is determined; the target node is a node in the array; the freeze pointer moves within the array based on the number of transactions in the nodes of the array, and is used to point to the most recently frozen node in the array; the number of transactions is the number of transactions in the node; Obtain the minimum version number and consecutive replay points contained in the target node; The minimum version number is the minimum value of the first-stage replay version number corresponding to at least one transaction in the target node; The first-stage replay version number is the version number of the first-stage log corresponding to the transaction; The consecutive replay point is determined based on the maximum value of the version number of at least one log that is continuously replayed in the log stream when the target node is frozen; The weak consistency read version number is determined based on the minimum version number and consecutive replay points contained in the target node.
2. The method according to claim 1, further comprising: If a second-stage log is replayed in the log stream, the second transaction corresponding to the second-stage log is determined, and based on the correspondence, the node information of the node corresponding to the second transaction in the array is updated.
3. The method according to claim 2, wherein updating the node information of the active node pointed to by the active pointer in the array according to the first transaction corresponding to the first stage log includes: Determine the active node that the active pointer points to in the array; Increment the number of transactions in the active node by one; Obtain the first phase replay version number of the first transaction; If the first stage replay version number is lower than the minimum version number contained in the active node, then the minimum version number is updated to the first stage replay version number.
4. The method according to claim 2, wherein updating the node information of the node corresponding to the second transaction in the array based on the correspondence includes: Based on the aforementioned correspondence, obtain the node corresponding to the second transaction; Decrease the number of transactions in the node corresponding to the second transaction by one.
5. The method according to claim 4, further comprising: If it is determined that the number of transactions in the node currently pointed to by the frozen pointer is zero, then the frozen pointer is incremented by one; If it is determined that the pointer value of the frozen pointer is the same as the pointer value of the active pointer, then the active pointer is incremented by one.
6. The method according to any one of claims 1-5, wherein determining the weak consistency read version number based on the minimum version number and consecutive replay points contained in the target node includes: Subtract one from the consecutive replay points contained in the target node to obtain a new consecutive replay point; The minimum version number contained in the target node and the minimum value in the new continuous replay site are determined as the weakly consistent read version number.
7. A version number determination device, the device comprising: The first determining unit is used to replay the logs in the log stream; The log stream contains at least one log; If the log stream contains a first-stage log that is replayed, then based on the first transaction corresponding to the first-stage log, update the node information of the active node pointed to by the active pointer in the array, and establish the correspondence between the first transaction and the time of the active node. The active pointer moves within the array based on the number of transactions in the nodes of the array; If the number of transactions of the active node reaches the set number corresponding to the active node, then the maximum value of the version number of at least one log that is continuously replayed in the log stream is determined as the continuous replay point of the active node. Set the node status of the active nodes to frozen; increment the active pointer by one; The target node to which the freeze pointer points is determined; the target node is a node in the array; the freeze pointer moves within the array based on the number of transactions in the nodes of the array, and is used to point to the most recently frozen node in the array; the number of transactions is the number of transactions in the node; The acquisition unit is used to acquire the minimum version number and continuous replay points contained in the target node; The minimum version number is the minimum value of the first-stage replay version number corresponding to at least one transaction in the target node; The first-stage replay version number is the version number of the first-stage log corresponding to the transaction; The consecutive replay point is determined based on the maximum value of the version number of at least one log that is continuously replayed in the log stream when the target node is frozen; The second determining unit is used to determine the weakly consistent read version number based on the minimum version number and continuous replay points contained in the target node.
8. An electronic device, comprising: processor; as well as A memory storing computer instructions for causing the processor to perform the method according to any one of claims 1-6.
9. A storage medium storing computer instructions for causing a computer to perform the method according to any one of claims 1-6.
Citation Information
Patent Citations
Cache operation method, device and system, storage medium and operation equipment
CN113312385A
