Transaction processing method, device, computer device, and computer program

The transaction processing method and apparatus address the challenge of managing concurrent transactions in distributed databases by using a global timestamp system and decentralized algorithms to adjust consistency levels, enhancing data integrity and performance through efficient anomaly detection and flexible consistency management.

JP7546832B2Active Publication Date: 2024-09-09TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
JP2023524479
Authority / Receiving Office
JP · JP
Patent Type
Patents
Current Assignee / Owner
Priority Date
2021-01-28
Filing Date
2022-01-24
Publication Date
2024-09-09
Estimated Expiration
2042-01-24

AI Technical Summary

Technical Problem

Existing transaction processing systems struggle to efficiently manage concurrent transactions in distributed databases, leading to data anomalies and inconsistent performance due to the lack of a comprehensive consistency model that integrates transaction integrity and distributed consistency, resulting in low accuracy and poor system performance.

Method used

A transaction processing method and apparatus that utilize a global timestamp generation system to determine logical start and commit times for transactions, allowing for dynamic adjustment of concurrent consistency levels, ensuring data integrity and isolation by committing transactions only when the logical start time is less than or equal to the logical commit time, and employing a decentralized algorithm to minimize centralization.

Benefits of technology

This approach enhances data anomaly detection and improves transaction processing efficiency by allowing different transactions within a system to have varying concurrent consistency levels, ensuring accurate data integrity and improved system performance across various business scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007546832000008
    Figure 0007546832000008
  • Figure 0007546832000009
    Figure 0007546832000009
  • Figure 0007546832000010
    Figure 0007546832000010
Patent Text Reader

Abstract

A transaction processing method, device, computer device, and storage medium, relating to the technical field of databases, includes the steps of: acquiring a read set and a write set of a target transaction in response to a read / write operation of the target transaction (401); determining a logical start time and a logical commit time of the target transaction in response to a verification command of the target transaction (402); updating the logical start time based on the write set if the logical start time and the logical commit time match a concurrent consistency level of the target transaction (403); and committing the target transaction if the updated logical start time is less than or equal to the logical commit time (404).
Need to check novelty before this filing date? Find Prior Art

Description

[Technical field]

[0001] The present application relates to the technical field of databases, and in particular to a transaction processing method, device, computer device and storage medium.

[0002] This application claims priority to a Chinese patent application filed on January 28, 2021, bearing application number 202110115847.4 and titled "Transaction processing method, apparatus, computer equipment and storage medium," the entire contents of which are incorporated herein by reference. [Background technology]

[0003] Data processing technology requires transaction semantics, and borrows the four ACID properties of relational databases to ensure the transaction properties of the system and meet the needs of electronic transactions, where A is atomicity, C is consistency, I is isolation, and D is durability. In other words, electronic transactions need to rely on these four properties to ensure the safety and reliability of transactions.

[0004] Distributed transaction processing technology also needs to meet the four ACID characteristics of transactions, and data processing technology needs multiple technologies to meet the four ACID characteristics. The most important thing here is data consistency and isolation. Here, data consistency determines the problem of data correctness, and isolation determines the problem of concurrent system performance. The realization of transaction consistency means discovering and resolving whether transaction concurrent operations will cause data anomalies in data items, and how to resolve the data anomaly problem, which mainly depends on the four types of data anomalies and isolation levels, concurrent access control technology in database transaction processing technology, etc. Summary of the Invention [Problem to be solved by the invention]

[0005] SUMMARY OF THE DISCLOSURE Embodiments of the present application provide a transaction processing method, apparatus, computer device, and storage medium.

[0006] One aspect provides a method of transaction processing, the method comprising: obtaining a read set and a write set of a target transaction in response to read and write operations of the target transaction; determining a logical start time and a logical commit time of the target transaction in response to a verification command for the target transaction; updating the logical begin time based on the write set in response to the logical begin time and the logical commit time matching a concurrency consistency level of the target transaction; committing the target transaction in response to the updated logical begin time being less than or equal to the logical commit time.

[0007] One aspect provides a transaction processing apparatus, the apparatus including: an acquisition module, a decision module, an update module, and a commit module; the acquisition module is used to acquire a read set and a write set of the target transaction in response to a read / write operation of the target transaction; the determination module is adapted to determine a logical start time and a logical commit time of the target transaction in response to a verification command for the target transaction; the update module is adapted to update the logical begin time based on the write set in response to the logical begin time and the logical commit time matching a concurrency consistency level of the target transaction; The commit module is adapted to commit the target transaction in response to the updated logical begin time being less than or equal to the logical commit time.

[0008] One aspect provides a computer device including one or more processors and one or more memories, wherein at least one computer program is stored in the one or more memories, and wherein the at least one computer program is loaded and executed by the one or more processors to implement a transaction processing method of any one of the possible implementations.

[0009] One aspect provides a storage medium having at least one computer program stored therein, the at least one computer program being loaded and executed by a processor to implement a transaction processing method according to any one of the possible implementations.

[0010] An aspect provides a computer program product or computer program, said computer program product or computer program comprising one or more program codes, said one or more program codes being stored on a computer readable storage medium, one or more processors of a computing device being capable of reading said one or more program codes from the computer readable storage medium, said one or more processors executing said one or more program codes to cause the computing device to perform the transaction processing method of any one of said possible embodiments. [Brief description of the drawings]

[0011] [Figure 1] FIG. 1 is a schematic diagram of an implementation environment of a transaction processing method provided by an embodiment of the present application. [Diagram 2] 1 is a schematic diagram of the architecture of a HTAC system provided by an embodiment of the present application. [Diagram 3] FIG. 2 is a diagram illustrating the evolution principle of linearization levels provided by an embodiment of the present application. [Figure 4] 2 is a flowchart of a transaction processing method provided by an embodiment of the present application; [Diagram 5]2 is an interaction flowchart of a transaction processing method provided by an embodiment of the present application; [Figure 6] FIG. 2 is a structural schematic diagram of a transaction processing device provided by an embodiment of the present application; [Figure 7] FIG. 2 is a structural schematic diagram of a computer device provided by an embodiment of the present application; [Figure 8] FIG. 2 is a structural schematic diagram of a computer device provided by an embodiment of the present application; DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

[0012] In order to make the objectives, technical solutions and advantages of the present application clearer, the following describes the embodiments of the present application in more detail in combination with drawings.

[0013] The terms "first", "second", and the like in this application are used to distinguish between the same or similar items having essentially the same actions and functions, and it should be understood that there is no logical or chronological dependency between "first", "second", and "nth", and no limitations are imposed on the numbers and execution order.

[0014] As used herein, the term "at least one" refers to one or more, and "plurality" refers to two or more than two, for example, a plurality of first locations refers to two or more than two first locations.

[0015] Before introducing the embodiments of the present application, some basic concepts in the cloud technology field need to be introduced.

[0016] Cloud Technology: refers to a type of hosting technology that unifies a series of resources such as hardware, software, and network in a wide area network or a local area network to realize data calculation, storage, processing, and sharing. That is, it is a collective term for network technology, information technology, integration technology, management platform technology, application technology, etc. that are applied based on the cloud computing business model, and by forming a resource pool, it can be used as needed, freely and conveniently. Cloud computing technology can be an important support in the field of cloud technology. The background service of the technology network system requires a large amount of calculation and storage resources, such as video websites, image websites, and more portal sites. With the rapid development and application of the Internet industry, in the future, each item may have its own identification mark, but they all need to be transmitted to the background system for logical processing, and data of different levels will be processed separately, so various industrial data all need to be supported by a strong system, which can be realized by cloud computing.

[0017] Cloud Storage is a new concept that has expanded and developed from the concept of cloud computing. A distributed cloud storage system (hereinafter referred to as storage system) refers to a storage system that uses functions such as cluster applications, grid technology, and distributed storage file systems to collectively cooperate a large number of different types of storage devices (storage devices are also called storage nodes) on a network through application software or application interfaces, and jointly provides data storage and business access functions to the outside world.

[0018] Database: Simply put, it can be regarded as a kind of electronic filing cabinet, that is, a place that stores electronic files and supports users to perform operations such as adding, querying, updating, deleting, etc. on the data in the files. The so-called "database" is a set of data that is stored together in a certain way, can be shared by multiple users, has the smallest possible redundancy, and is independent of application programs.

[0019] Full State of Data: For data items in a database system, there are three types of states (current state, transition state and history state) based on different state attributes, and these three types of states are collectively called "full state of data" and abbreviated as full state data. Each different state attribute in the full state data is used to identify the state in which the data exists in its life cycle trajectory.

[0020] 1. Current State: The latest version of a data item, which is the data item currently in the stage.

[0021] 2. Historical State: A state in the history of a data item in which its value is an old value, not the current value. Optionally, multiple historical state data items correspond to the same primary key identifier, and reflect the state transitions of each data item with that primary key identifier. Data items in a historical state are read-only and cannot be modified or deleted.

[0022] 3. Transitional State: A data item that is neither in the current state nor in the history state, but is in the process of changing from the current state to the history state. Data in this transitional state is also called half-depleted data.

[0023] Optionally, different data items have the same primary key identifier (Primary Key, PK), and each data item having the same primary key identifier constitutes one full-state data set, and each data item in the full-state data set is essentially used to indicate the data of the full state. That is, in the process of modifying (or deleting) an initial data item having the primary key identifier multiple times, multiple different versions are generated due to different modification (or deletion) times, that is, they constitute one full-state data set. In one full-state data set, one data item is in a current state, one data item is in a transition state, and one data item is in a history state. The full-state data set here refers to an abstract and virtual collection concept, and each data item in the same full-state data set can be stored in a distributed manner on different physical machines. Optionally, when the database system stores each data item, a pointer is adopted to link each data item corresponding to the same primary key identifier according to a chronological order, which makes it convenient to query the life cycle trajectory of the data of the full state.

[0024] Data item visibility: The visibility of a data item is relative to a transaction, and a data item may be visible to some transactions but invisible to some transactions. In the embodiment of the present application, a parallel consistency level of a database system is proposed, and different transaction concurrency control identification algorithms are provided for different parallel consistency levels based on this. The above algorithms will be described in detail later and will not be described in detail here.

[0025] The database system according to the embodiment of the present application includes, but is not limited to, a standalone database system, a standalone database system mainly for transactions, a standalone database system mainly for analysis but requiring transaction processing capabilities, such as a NoSQL (Non-relational SQL, broadly referring to non-relational databases) system, a distributed database system, a distributed big data processing system, etc.

[0026] The database system includes at least one node device, and a plurality of data tables are stored in the database of each node device, and each data table is used to store one or more data items (also referred to as variable versions). Here, the database of the node device is any type of distributed database, including at least one of a relational database and a non-relational database, such as a SQL (Structured Query Language) database, NoSQL, NewSQL (broadly referring to various new scalable / high-performance databases), etc., and the embodiments of the present application do not specifically limit the type of database.

[0027] In some embodiments, the embodiments of the present application are applied to a database system based on blockchain technology (hereinafter, abbreviated as "blockchain system"), which essentially belongs to a decentralized distributed database system, employs a consensus algorithm to maintain consistency of ledger data recorded in different node devices on the blockchain, uses a password algorithm to ensure that ledger data is encrypted and cannot be tampered with between different node devices, uses a script system to extend ledger functions, and uses network routing to connect different node devices to each other.

[0028] The blockchain system includes one or more blockchains, which are a series of data blocks linked together using cryptographic methods, each of which contains information about a lot of network transactions and is used to verify the validity (anti-counterfeiting) of the information and generate the next block.

[0029] In a blockchain system, node devices form a peer-to-peer (P2P) network, and the P2P protocol is an application layer protocol that runs on top of the Transmission Control Protocol (TCP). In a blockchain system, any one node device has the following functions: (A) Routing: A basic function possessed by node devices, which is used to support communication between node devices. (B) Application: Deployed in a blockchain, it realizes a specific business based on actual business needs, records data related to the realization of the function to form ledger data, indicates the data source by carrying a digital signature in the ledger data, and transmits the ledger data to other node devices in the blockchain system, and when the other node devices successfully verify the ledger data source and integrity, adds the ledger data to a temporary block. Here, the business realized by the application includes wallets, shared ledgers, smart contracts, etc. (C) Blockchain: It includes a series of blocks that are connected to each other according to a time sequence, and once a new block is added to the blockchain, it cannot be removed, and the ledger data committed by the node devices in the blockchain system is recorded in the block.

[0030] In some embodiments, each block includes a hash value (the hash value of the current block) that stores the transaction record of the current block and a hash value of the previous block, and each block is connected by the hash value to form a blockchain. Optionally, the block further includes information such as a timestamp when the block was generated.

[0031] Before introducing the embodiments of the present application, the accuracy of transaction concurrency control in a database system is described by consistency and isolation, so an explanation of consistency and isolation will be given below.

[0032] 1. Isolation Transaction isolation levels are defined by whether certain types of data anomalies can be avoided, and possible data anomalies include: A. Dirty read: A transaction reads a data item that has not been committed by another transaction. B. Non-repeatable read: A transaction reads the same data item twice but obtains different results. C. Phantom read: A transaction performs two predicate queries (range queries) during the course of an operation, and the result of the second query contains a data item that does not appear in the result of the first query, or a data item that appeared in the result of the first query is missing.

[0033] Based on the ability to resolve the above three types of data anomalies, the database international standard ANSI (American National Standards Institute) SQL proposes four isolation levels to distinguish between the above three known types of data anomalies, with the aim of improving transaction processing efficiency when allowing the existence of certain data anomalies.

[0034] These four isolation levels include the following: a. Read Uncommitted: The three types of data anomalies listed above are allowed to occur. b. Read Committed: Dirty reads are not allowed to occur. c. Repeatable Read: Dirty reads and non-repeatable reads are not allowed to occur. d. Serializable: None of the three types of data anomalies listed above should occur.

[0035] It can be understood that none of these four isolation levels allow the occurrence of dirty write anomalies, which refers to two uncommitted transactions modifying the same data item. When ANSI SQL was established, there were not many types of data anomalies known, and new data anomalies are constantly being discovered. In addition to the several types of data anomalies mentioned above, currently known data anomalies also include lost update anomalies, read partial order anomalies, write partial order anomalies, read / write partial order anomalies, sawtooth write partial order anomalies, serial-concurrent-phenomenon anomalies, cross-phenomenon anomalies, causal missing anomalies, causal inversion anomalies, old read anomalies, future read anomalies, etc.

[0036] 2. Integrity In database technology, the word "consistency" has two meanings: the first refers to transactional consistency, and the second refers to distributed consistency. The definition of database transaction integrity is as follows: under the operation of a transaction, the data state of the database transitions from one consistent state to another consistent state. The above "consistent state" refers to a data state that satisfies some rules predefined by the database system, for example, these rules include constraints, cascades, triggers, and any combination of the three (belonging to the logical semantics of data), and what is violated by write partial order anomalies is the constraint between specific data, and the constraint here belongs to the data integrity defined by user semantics.

[0037] Concurrent access control technology in database transaction processing technology aims to discover and resolve whether concurrent transaction operations may cause data anomalies in data items, and how to resolve the data anomaly problem. ANSI SQL proposes four types of data anomalies and isolation levels, and various concurrent access control algorithms have also been developed, such as block-based concurrent access control technology, timestamp-based concurrent access control technology, MVCC (Multi-Version Concurrency Control)-based concurrent access control technology, and OCC (Optimistic Concurrency Control)-based concurrent access control technology.

[0038] The definition of distributed consistency in a database is as follows: Distributed consistency is also called the operational consistency of shared data objects, and has a system-level meaning for the entire database system. In order to ensure that data maintains consistency in a database system, the database system must further match two properties: serializability and recoverability. Serializability is the isolation level of serializability defined in the above isolation property, where serializability ensures that data is not corrupted by concurrent operations, recoverability means that a transaction that has already been committed has not read the data written by a rolled back transaction (meaning that a dirty read anomaly does not occur), and recoverability ensures that data returns to the previous consistent state after a transaction is rolled back. The rolled back transaction has no effect on the consistency of data, and the consistency state of the database system can be recovered.

[0039] In particular, in a distributed database system (but not excluding systems with similar problems such as internal memory systems that update objects and distributed storage), operations based on shared objects aim to solve the semantics problem of read / write sorting on data items between various operations in a distributed environment. For example, regarding various consistency models with different degrees of strength, linear consistency and sequential consistency are examples of relatively strong consistency models, and atomic consistency, snapshot consistency, causal consistency, etc. are examples of relatively weak consistency models.

[0040] Both of the above aspects are related to the concept of consistency, but they belong to different categories. The former, transaction consistency, is the consistency of how to avoid data anomalies related to transactions considered in the database category, while the latter, distributed consistency, is the consistency of how to guarantee the continuity of semantics between operations related to parallel operations and non-concurrent operations considered in the parallel operations category. In a distributed database system, the consistency of these two aspects is combined and integrated to reach one unique combination dimension, which is called Strict Serializability (Strong-1SR).

[0041] The above two types of consistency are analyzed respectively. In terms of transaction consistency, the system is single, the semantics are strong, the flexibility is insufficient, and the whole database system can only have one kind of consistency level, which makes it difficult to meet the actual business needs with different consistency requirements in the application layer. In addition, the requirements of this kind of consistency are very strict, and it needs to meet the real-time mechanism of linear consistency, so the parallelism of the system is relatively low and the performance is relatively poor. In terms of distributed consistency, it separates the system between transaction consistency and distributed consistency, and cannot effectively establish the association relationship between the two, and essentially can only establish one single connection dimension of strict serializability. In addition, the consistency model cannot effectively, comprehensively and integrally unify transaction consistency and distributed consistency, so the theoretical system is incomplete and has little practical value.

[0042] In the related art, the realization of transaction integrity refers to discovering and resolving whether transaction parallel operations cause data anomalies in data items, and how to resolve the data anomaly problem, which mainly depends on the above four types of data anomalies and isolation levels, and the parallel access control technology in database transaction processing technology, such as block-based parallel access control technology, timestamp sorting-based parallel access control technology, Multi-Version Concurrency Control (MVCC)-based parallel access control technology, and Operation Control Center (OCC)-based parallel access control technology, etc. These technologies must ensure that data anomalies do not occur, that is, satisfy serializable scheduling of transactions, thereby ensuring data accuracy.

[0043] The transaction integrity described above is the integrity of how to avoid data anomalies related to transactions defined within the database category. Serializable technology and multiple types of concurrent access control technology within the database field only solve problems related to transaction integrity, and cannot solve other consistency problems (such as the consistency problem of shared data objects), so some anomaly problems cannot be detected by serializable technology. That is, there are transactions that partially meet the requirements for serializability but still have anomalies, which cannot be detected by serializable scheduling technology, that is, data anomaly problems under transaction integrity and other consistency (such as the consistency of shared data objects) cannot be identified, and the accuracy of state detection for the system is low.

[0044] In view of this, the embodiment of the present application can establish a parallel access control algorithm for multiple consistency levels for a parallel consistency model, and can efficiently ensure that user parallel operations meet multiple consistency semantics with different degrees of strength in data objects, and is suitable for the needs of different types of users for accuracy and performance. In addition, multiple consistency levels under a distributed system are systematically proposed, the theoretical system can be completed, and corresponding algorithms for realizing various consistency levels and algorithm rules for enabling decentralization for some levels are proposed. Furthermore, basic rules and realization techniques for multiple consistency levels coexisting in the same system (i.e., different transactions in the same system have the same or different consistency levels) are proposed, and the important problem of multiple consistency levels under a distributed system is considered, defined, and concretely realized. In other words, after ranking the consistency according to the strength and weakness, a timestamp sorting method is used to perform timestamp sorting detection for multiple consistency levels (i.e., to determine whether the logical start time and logical commit time match the consistency level), which can save the time consumed in detecting loops (referring to transaction dependency loops) in related technologies, and can improve transaction processing efficiency.

[0045] 1 is a schematic diagram of an implementation environment of a transaction processing method provided by an embodiment of the present application. As shown in FIG. 1, the embodiment of the present application is applied to a distributed database system, which includes a gateway server 101, a global timestamp generation cluster 102, and a distributed storage cluster 103, in which a data node device and a cooperative node device are included.

[0046] Here, the gateway server 101 is used for receiving external read / write requests and delivering read / write transactions corresponding to the read / write requests to the distributed storage cluster 103. For example, after a user logs in to an application client terminal on a terminal, the user triggers the application client terminal to generate a read / write request, and calls an API (Application Programming Interface) provided by the distributed database system to send the read / write request to the gateway server 101, for example, the API is a MySQL API (an API provided by a kind of relational database system).

[0047] Optionally, the terminal may be, but is not limited to, a smartphone, a tablet computer, a laptop, a desktop computer, a smart speaker, a smart watch, etc. Here, the terminal and the gateway server 101 may be directly or indirectly connected to each other through wired or wireless communication, and the present application is not limited thereto.

[0048] In some embodiments, the gateway server 101 and any one of the data node devices or any one of the cooperative node devices in the distributed storage cluster 103 are merged onto the same physical machine, i.e., one of the data node devices or cooperative node devices functions as the gateway server 101.

[0049] The global timestamp generation cluster 102 is used to generate a global timestamp for a global transaction, the global timestamp including at least a logical start time Bts and a logical commit time Ets, the global transaction is also called a distributed transaction, which refers to a transaction involving multiple data node devices. For example, a global read transaction is related to reading data stored on multiple data node devices, and for example, a global write transaction is related to writing data on multiple data node devices. Although the global timestamp generation cluster 102 is logically regarded as a single point, in some embodiments, a one-master, three-slave architecture is used to provide a service with higher availability, and a cluster format is adopted to realize the generation of the global timestamp, which can prevent single point failure, i.e., avoid the problem of a single point bottleneck.

[0050] Optionally, the global timestamp is a timestamp identifier that is globally unique and monotonically increasing in a distributed database system, and can be used to mark the global commit order of each transaction, thereby reflecting the predecessor-subsequence relationship between transactions in real time (total order relationship of transactions). The global timestamp employs at least one of a physical clock, a logical clock, a hybrid physical clock, or a hybrid logical clock (HLC), and the embodiment of the present application does not specifically limit the type of the global timestamp.

[0051] In one example scenario, the global timestamp includes the logical start time Bts and logical commit time Ets of a transaction, and the global timestamp is generated by adopting the hybrid physical clock method and consists of 8 bytes, where the first 44 bits are the value of the physical timestamp (i.e., a Unix timestamp, accurate to milliseconds, identifying the global system time, denoted by the symbol Gts). Thus, a total of 2 44 unsigned integers, so in theory there are about 2 44 / (1000*60*60*24*365)=557.8 years physical timestamp, where the last 20 bits are a monotonically increasing count within a given millisecond, thus increasing by 2 per millisecond. 20 There are counts of global timestamps (approximately 1 million, identifying relative times on a global time point within a single node, denoted by the symbol Lts). Based on the above data structure, if a standalone (any one data node device) has a transaction throughput of 10w / s, it can theoretically support a distributed storage cluster 103 containing 10,000 node devices. At the same time, the number of global timestamps represents the total number of transactions that the system can theoretically support, and based on the above data structure, the system can theoretically support up to (2 44 -1)*2 20 Supports individual transactions.

[0052] It is necessary to explain that one method of defining a global timestamp is merely described as an example, and the number of bits of the global timestamp can be expanded based on different business needs to meet the support for a larger number of nodes and transaction processing. For example, based on actual demand, the logical start time Bts and logical commit time Ets of a single transaction are configured with data larger than 8 bytes, and are adjusted to, for example, 10 bytes, thereby increasing Lts to handle a larger number of parallel transactions. The embodiment of the present application does not specifically limit the method of defining the global timestamp.

[0053] In some embodiments, the global timestamp generation cluster 102 is physically separate or merged together with the gateway server 101 or the distributed storage cluster 103 .

[0054] Here, the distributed storage cluster 103 includes data node devices and cooperative node devices, each cooperative node device corresponds to at least one data node device, and the distinction between data node devices and cooperative node devices is for different transactions. Taking a global transaction as an example, the initiating node of the global transaction is called a cooperative node device, other node devices related to the global transaction are called data node devices, and the number of data node devices or cooperative node devices is one or more. The embodiment of the present application does not specifically limit the number of data node devices or cooperative node devices in the distributed storage cluster 103.

[0055] Optionally, the system adopts XA (eXtended Architecture, X / Open systematic distributed transaction standard) / 2PC (Two-Phase Commit) technology to support transactions between nodes (global transactions) and ensure the atomicity and consistency of data during write operations between nodes. At this time, the cooperative node devices are used to function as coordinators in the 2PC algorithm, and each data node device corresponding to the cooperative node devices is used to function as a participant in the 2PC algorithm.

[0056] Optionally, each data node device or cooperative node device is a standalone device or adopts a master-standby structure (i.e., a single-master multi-standby cluster). As shown in FIG. 1, for example, a node device (data node device or cooperative node device) is a one-master two-standby cluster. Each node device includes one master device and two standby devices. Optionally, an agent device is disposed corresponding to each master device or standby device. The agent device is physically independent from the master device or standby device, or the agent device is used as an agent module in the master device or standby device. Taking the node device 1 as an example, the node device 1 includes one master database and an agent device (master database+agent, abbreviated as master DB+agent), and further includes two standby databases and agent devices (standby database+agent, abbreviated as standby DB+agent).

[0057] In an exemplary scenario, a set of database instances of each node device and the corresponding master or standby device is referred to as a SET. For example, if a node device is a standalone device, the SET of the node device is only the database instance of the standalone device, and if a node device is a one-master two-standby cluster, the SET of the node device is a set of the database instance of the master device and the database instance of the two standby devices. At this time, based on the strong synchronization technology of the cloud database, the consistency between the data of the master device and the replicated data of the standby device is guaranteed. Optionally, each SET can perform linear capacity expansion to meet the business processing needs under big data scenarios, for example, in the financial business scenario, a global transaction usually refers to a transfer between SETs.

[0058] The above Figure 1 only provides an architecture diagram of one kind of distributed database system. The whole distributed database system can be regarded as one logical large table maintained jointly, and the data stored in this large table is distributed to each node device in the distributed storage cluster 103 by primary key, and the data stored on each node device is independent of other node devices, thereby realizing horizontal partitioning of the logical large table of the node devices. In the above system, each data table in each database can be horizontally partitioned before distributed storage, so such a system can also be regarded as an architecture with "database partition table partitioning".

[0059] The transaction processing method provided by the embodiment of the present application is applicable to a distributed system that adopts the above-mentioned database partitioning table partitioning architecture, for example, the distributed system is a distributed transactional database system or a distributed relational database system. In addition, the transaction processing method provided by the embodiment of the present application can also be applied to a distributed system or a standalone database system of any other architecture, and the distributed system needs distributed transaction processing capability, and needs to provide a richer and more flexible parallel consistency level in order to improve transaction processing efficiency and meet the application needs of different users in different scenarios.

[0060] In some embodiments, the distributed database system composed of the gateway server 101, the global timestamp generation cluster 102 and the distributed storage cluster 103 is regarded as a kind of server providing data services to user terminals, which may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.

[0061] In some embodiments, the distributed database system is a Hybrid Transaction / Analytical Cluster (HTAC) system. Figure 2 is a schematic diagram of an architecture of a kind of HTAC system provided by an embodiment of the present application. As shown in Figure 2, the HTAC system includes a Transaction Processing (TP) cluster 201 and an Analytical Processing (AP) cluster 202.

[0062] The TP cluster 201 is used to provide a transaction processing service, and includes multiple TP node devices, and each TP node device is used to process current state data during the transaction processing process, where each TP node device is a standalone device or a single-master multi-standby cluster, and the embodiment of the present application does not specifically limit the type of TP node device.

[0063] The AP cluster 202 is used to store historical state data and provide historical state data query and analysis services. Optionally, the AP cluster 202 includes a global timestamp generation cluster 102 and a distributed storage cluster 103 in the above embodiment. The distributed storage cluster 103 includes multiple AP node devices, each AP node device being a standalone device or a single-master multi-standby cluster, and the embodiment of the present application does not specifically limit the type of AP node device.

[0064] In the above architecture, a set of database instances of each TP node device and the corresponding master or standby device is called a SET. For example, if a TP node device is a standalone device, the SET of the TP node device is only the database instance of the standalone device, and if the TP node device is a one-master two-standby cluster, the SET of the TP node device is a set of the database instance of the master device and the database instances of the two standby devices. At this time, the consistency between the data of the master device and the replicated data of the standby device is guaranteed based on the strong synchronization technology of the cloud database. Each SET can selectively perform linear capacity expansion to meet the business processing needs under the big data scenario.

[0065] Optionally, each AP node device stores historical state data generated in the TP cluster 201 in a local database, or accesses the distributed file system 203 through a storage interface, thereby providing the function of indefinite storage for historical state data generated in the TP cluster 201 through the distributed file system 203. The distributed file system 203 includes, but is not limited to, HDFS (Hadoop Distributed File System), Ceph (a type of distributed file system under the Linux (registered trademark) system), Alluxio (a type of distributed file system based on internal memory), etc.

[0066] In some embodiments, the multiple TP node devices provide transaction processing services, so that when any one transaction is committed, new current state data is generated and historical state data corresponding to the current state data is also generated, and the historical state data occupies a relatively large storage space. In addition, since the historical state data has storage value, the multiple TP node devices atomically migrate the generated historical state data to the AP cluster 202 according to a predefined historical state data migration strategy. Each AP node device in the AP cluster 202 realizes dumping of historical state data based on a local actuator (Local Executor, LE), and registers meta information of each data migration in a metadata (Metadata, MD) manager, making it convenient for the AP cluster 202 to statistic the meta information of the stored data based on the MD manager.

[0067] In some embodiments, a user queries any one of the data stored in the TP cluster 201 or the AP cluster 202 based on the query statement, the semantics of the query operation and the metadata provided in the SQL routing (Structured Query Language Router, SQL Router, SR) layer, and the routing is performed such that the TP cluster 201 mainly provides query services for the current state data and the AP cluster 202 mainly provides query services for the historical state data.

[0068] Alternatively, in the HTAC system, the TP cluster 201 and the AP cluster 202 are each preceded by the gateway server 101 in the above embodiment.

[0069] The above HTAC system is an exemplary description of a distributed database system, and is also an exemplary description of a distributed transactional database system, which requires the ability of distributed transaction processing and requires a consistency model on shared data. By using the transaction processing method provided by the embodiment of the present application on the above HTAC system, more and more efficient identification of data anomalies can be realized, and an efficient serializable isolation level can be realized, so that the HTAC system can be suitable for multiple business scenarios. For example, when using a strict serializable level, it can be very well applied to the financial field and ensure the reliability of data, but currently, no mainstream distributed database system can provide this consistency level efficiently. Also, for example, when using a relatively weak consistency level, it can be very well applied to the Internet scene, which provides real-time high-concurrency database services and provides Internet users with a good product experience. In addition, it can realize more and more efficient shared data consistency models, and can avoid various inconsistency problems in a distributed environment, such as causality loss, causality inversion, stale read, future read, etc. In addition, in addition to ensuring accuracy, the system performance can be greatly improved, for the following reasons. (a) Multi-level concurrent consistency levels are provided, so that different levels have different correctness and performance expressions. (b) Concurrent access control algorithms under corresponding levels are provided, so that single-point performance bottlenecks are eliminated on the basis of decentralization. (c) Different concurrent access control algorithms have different implementation methods, so that the algorithms become more efficient by addressing efficient structure algorithms. Furthermore, for standalone database systems, the "sequential consistency" and "serializability" of the concurrency levels of the embodiments of the present application are also extremely beneficial to the optimization of serializability theory (the conventional serializability technology does not consider the impact of session causality on concurrent transactions at all).From the above, it can be seen that this transaction processing method and related theory can effectively ensure the accuracy of user data and the precision of user application semantics, and have better system performance, that is, it can improve the technical content of the product, and increase the technical barriers and competitiveness and technical influence, which has very strong practical significance.

[0070] Before introducing the embodiments of the present application, an introduction will first be given to some basic terms and code representations related to database systems.

[0071] Transaction: A transaction is a logical unit in the process of a database management system performing operations. It consists of a limited sequence of database operations and is the smallest execution unit of a database system's operations. Within a system, each sequence of operations is called a transaction, and a single operation is also called a transaction.

[0072] Variable: A transaction is a data unit in a database relational system, and a variable is the actor (or operation object) of a database operation. A variable contains multiple variable versions (hereinafter abbreviated as "versions"). Every time a transaction performs an update on a variable, a new variable version is added. Optionally, each variable version of a variable has a natural number as a version number identifier, and the higher the version number, the newer the variable version.

[0073] Operation: A database operation is composed of three parts: operation type, transaction, and variable version, where operation type includes two kinds: read (R) and write (W). For example, transaction T updates variable x, generating a new version i of variable x, and the read operation is W. T (x i ), and for example, if transaction T reads the value of version i of variable x and the write operation is T (xi ) is written.

[0074] Transaction dataset: A dataset is a set of multiple versions of variables, and each variable in the set contains at most one version. A dataset DS(T) = {x i ,y j ,z k ,...|x, y, z are variables and i, j, k are version numbers}.

[0075] Each transaction in a database system has two transaction data sets, the transaction write set and the transaction read set, which are as follows: W (T) is used to store the new data version written by transaction T, and the read set DS R (T) is used to store the data version that transaction T has read.

[0076] Based on the above, the association relationship between transactions can be divided into two types: associated transactions and unassociated transactions. Associated transactions also include object lifecycle overlap relationships and causal relationships. Unassociated transactions refer to other transactions that do not meet the definition of associated transactions.

[0077] Here, object lifecycle overlapping related transactions refer to two transactions that need to operate on a common data object and have overlapping times. Related transactions are divided into two types. The first type is a direct parallel transaction, which refers to transactions T1 and T2 whose execution times overlap and which operate on a common data item due to a partial order relationship. The second type is an indirect parallel transaction, which refers to transactions T1 and T2 being direct parallel transactions and transactions T2 and T3 being direct parallel transactions, but transactions T1 and T3 not meeting any or all of the two conditions for direct parallel transactions, and therefore transactions T1 and T3 being indirect parallel transactions.

[0078] Here, causally related transactions refer to transactions T1 and T2 that do not overlap in execution time but occur in the same process / session, or if there exists a situation in which transaction T1 writes to the same shared data object first and transaction T2 reads the value written by T1 later. Transactions that satisfy the above two cases are called causally related transactions.

[0079] Here, the term "unrelated transactions" refers to transactions T1 and T2 that do not satisfy the two types of relationships described above (object life cycle overlap relationship or causal relationship), and are therefore unrelated transactions.

[0080] Since the concurrent consistency level in the embodiment of the present application is related to detection of whether a partial order relationship is satisfied, it is necessary to explain the partial order relationship before introducing the concurrent consistency level. The partial order relationship defined based on the shared operation data items is classified into a concurrent partial order relationship (CPO), a causal partial order relationship (PO), and a similar program order relationship (SPO), and each will be explained below.

[0081] 1. We define partial order relations within the scope of concurrent transactions on shared operational data items, and include the following four types of concurrent partial order relations:

[0082] (1-1) RW partial order (read-write partial order relationship): If transaction T1 reads version x0 of data item X, and transaction T2 writes version x1 of data item X, then transactions T1 and T2 constitute a partial order relationship, denoted as (T1->T2|X).

[0083] (1-2) WR partial order (write-read partial order relationship): If transaction T1 writes version x0 of data item X, and transaction T2 reads version x0 of data item X, then transactions T1 and T2 form a partial order relationship, denoted as (T1->T2|X).

[0084] (1-3) WW partial order (concurrent write partial order relationship): If transaction T1 writes version x0 of data item X and transaction T2 writes version x1 of data item X, then transactions T1 and T2 form a partial order relationship, denoted as (T1->T2|X).

[0085] (1-4) WRA partial order (reverse partial order relationship): Transaction T1 writes version x0 of data item X, and transaction T2 reads version x0 of data item X. After that, transaction T1 generates a rollback operation, which generates an undo partial order relationship for transaction T2's read operation. The partial order relationship originates from transaction T2 and is directed to transaction T1, so a reverse partial order relationship is formed between transactions T1 and T2, which is denoted as (T2->T1|X).

[0086] 2. On shared operation data items, partial ordering relations are defined for causally related transactions, including the following three types of partial ordering relations:

[0087] (2-1) RCW partial order (no partial order relationship): Transaction T1 reads data item X and is committed first, and then transaction T2 writes data item X. Since the former has no effect on the latter, there is no partial order relationship between transactions T1 and T2.

[0088] (2-2) WCR partial order (causal write-read partial order relationship): Transaction T1 writes data item X and is committed first, and then transaction T2 occurs which reads data item X. Since what transaction T2 reads must be the value written by transaction T1 which was committed first, there is a causal relationship between transactions T1 and T2, with transaction T1 being the cause and transaction T2 being the effect. If transactions T1 and T2 are in the same process, it is determined that a causal partial order relationship between transactions T1 and T2 is formed in one process, and this is shown as (T1->T2|X).

[0089] (2-3) WCW partial order (causal write partial order relationship): Transaction T1 writes version x0 of data item X and commits, and then transaction T2 writes version x1 of data item X, causing a change in the version. If transactions T1 and T2 are in the same process, it is determined that a causal partial order relationship between transactions T1 and T2 is formed in one process, and is shown as (T1->T2|X).

[0090] 3. On shared operation data items, partial ordering relations within the scope of similar causal related transactions are defined, including the following two types of similar causal partial ordering relations:

[0091] (3-1) Similar causal write-read partial order relationship: Transaction T1 writes data item X and is committed first, and then transaction T2 occurs which reads data item X. Since what transaction T2 reads is the value written by transaction T1 which was committed first, there is a causal relationship between transactions T1 and T2, with transaction T1 being the cause and transaction T2 being the effect. If transactions T1 and T2 are in different processes, it is determined that a causal partial order relationship is formed between transactions T1 and T2 in different processes, and this is shown as (T1->T2|X).

[0092] (3-2) Similar causal write partial order relationship: Transaction T1 writes version x0 of data item X and commits, and then transaction T2 writes version x1 of data item X, causing a change in the version. If transactions T1 and T2 are in the same process, it is determined that a causal partial order relationship between transactions T1 and T2 is formed in one process, and is shown as (T1->T2|X).

[0093] Based on the above description of the concepts of isolation and consistency, the term isolation level originates from the concurrent access control technology of database systems. However, the isolation level is only defined based on limited data anomaly access (e.g., three types of anomaly limited by the ANSI SQL standard), and lacks sensitivity to other various anomaly detection. The concurrent consistency level related to the embodiment of this application is abbreviated as "concurrency level".

[0094] Concurrency levels: All types of transactions in a database (direct concurrent transactions, indirect concurrent transactions, causally related transactions, unrelated transactions) have different behaviors on data items, and the following multiple different concurrency levels are defined from strong to weak. It is important to note that the concurrency levels are defined per transaction, not per system; that is, different transactions are allowed to satisfy different concurrency levels within the same database system.

[0095] In the concurrent consistency level, each transaction has at least two global timestamps, one of which is the transaction's logical start time Bts (Begin Time Stamp, start timestamp value) and the other is the transaction's logical commit time Ets (End Time Stamp, commit timestamp value). Here, the Ets value of a transaction to be rolled back is set to NULL. In addition, each session maintains one Newts indicating the timestamp value of the latest transaction that has already been completed in this session, that is, the timestamp Newts of the latest completed transaction, which is used to ensure a partial order relationship (order consistency). Below, the nine concurrent consistency levels are defined.

[0096] 1) Serialization Consistency: All transactions are queued serially within one logical system and executed. Here, there are one or more executable nodes within the system, that is, it applies to standalone systems and distributed systems. A standalone system can support single processors and multi-processors, and the serialization level is the strongest consistency level, and any data abnormality or inconsistency is not allowed to occur.

[0097] 2) Strict Serializability Consistency: In other words, strict serializability is possible. For all transactions, write transactions are executed serially, but parallel execution of read-only and non-read-only transactions is permitted. For a read-only transaction, "Time Travel" events are not permitted to occur; in other words, reading the latest data from the current time, and two types of inconsistent data anomalies, "old read, future read", are not permitted to occur. This strict level also does not permit the occurrence of two types of inconsistent data anomalies, "causality loss, causality inversion".

[0098] It is important to clarify that the Time Travel event is a single transaction T k When a read is performed on old data (old version of data) across the Bts of at least one transaction that has already been committed, this is called a Time Travel event. When data is obtained without crossing the Bts of any transaction that has already been committed, this is not a Time Travel event, but rather, if the read data is the data version of the latest transaction that has already been committed and the Bts of that transaction is earlier than the Bts of the current transaction, this is called an approximate Time Travel event.

[0099] By defining several types of events as described above, concurrent transactions can read data on a transactional basis by simply moving the Bts of the read-only transaction to the front based on the concurrent reads of the transactions, without reading the results of the write operations of the concurrent transactions.

[0100] 3) Linearizability (Serializability Consistency): In other words, it is linearly serializable. All transactions can be executed in parallel, but for transactions executed in parallel, the read / write relationship between transactions must satisfy the Real-Time requirements, and it must be guaranteed that there are no arbitrary data anomalies. The Real-Time condition ensures that there are no three types of inconsistent data anomalies, namely "causality loss, causality reversal, and stale reads", but allows the occurrence of inconsistent data anomalies such as future reads.

[0101] However, to meet the requirement of serializability, an "approximate time travel" operation is performed for the read operation of one transaction, that is, the latest data is read from the current time (the Bts of this transaction) and "future read" is not possible. In addition, under the requirement of serializability, it is necessary to detect whether there is a data anomaly.

[0102] Therefore, the linearization level is similar to the strictness level in terms of data reading, but the degree of parallelism is slightly higher.

[0103] 4) Sequential Serializability Consistency: In other words, sequential serializability is possible. Within one session, the result value is stable, stale reads are not permitted, and the requirements for serializability are met between concurrent transactions.

[0104] 5) Serializability Consistency: Within a single session, result values ​​are unstable and stale reads may occur. The requirement of serializability is met between concurrent transactions. Compared to the ordering level, the serializability level removes the restriction of partial ordering relationships within the same session. This definition matches the conventional definition of serializability.

[0105] 6) Causal Repeatable Read Consistency: This is a repeatable read that takes causal relationships into account. It satisfies causal relationships within one system, but does not require serializability between parallel transactions. In other words, data anomalies may exist, and various types of inconsistent data anomalies such as "causal loss, causal inversion, old read, future read" may exist. However, it does not allow the occurrence of data anomalies of the type of write partial order or read / write partial order.

[0106] 7) Repeatable Read Consistency: Repeatable read consistency does not consider causality. It does not allow data anomalies of the write partial order or read / write partial order type to occur.

[0107] 8) Read Committed Consistency: This is a read committed consistency that does not consider causality. It allows data anomalies of the type read partial order and write partial order to occur.

[0108] 9) Read Uncommitted Consistency: This is the weakest consistency level and any data anomalies or inconsistencies may occur.

[0109] Table 1 shows the relationship between the above several types of concurrency consistency levels, and more clearly distinguishes the differences and connections between different concurrency levels. Here, "overlap" means that the current concurrency level allows the logical time intervals of two transactions to overlap, and "non-overlap" means that the current concurrency level does not allow the logical time intervals of two transactions to overlap.

[0110] [Table 1]

[0111] The nine types of parallel consistency levels are divided into four types according to the strength of the consistency. The distinction is whether or not it has the ability to maintain global consistency. If it does, it belongs to the strong consistency parallel level, and if it does not, it belongs to the weak consistency parallel level. The first type is a strong consistency level, which corresponds to serialization, strictness, linearization, and ordering, and the second type is an intermediate level, which corresponds to serializable. This level has global guarantees only between parallel transactions. The third type is a weak consistency level, which corresponds to causal repeatable read, repeatable read, and read-committed, and the fourth type is a zero consistency level, which corresponds to read-uncommitted read and write, and this level does not have any consistency guarantee.

[0112] The transaction processing method according to the embodiment of the present application is suitable for all concurrency levels, and the following introduces algorithms for different degrees of concurrency levels based on clocks. Here, the global clock (i.e., global timestamp) is a logical concept that provides a uniform monotonically increasing value throughout the database system. Optionally, the global clock is a global physical clock, or the global clock is a global logical clock.

[0113] In some embodiments, a decentralized distributed clock is constructed using a Truetime mechanism, or is unified in a master-standby system of multiple redundant nodes (e.g., a cluster constructed with a consistency protocol such as Paxos / Raft), or a global clock is constructed based on an algorithm having a precise synchronization mechanism and a collaborative node logout mechanism, but the embodiments of the present application do not place any specific limitations on the construction method of the global clock.

[0114] When comparing two transactions T i and T j Suppose there exists a T i .bts.gts <Tj .bts.gts OR (T i .bts.gts=T j .bts.gts AND T i .bts.lts <T j In the case of .bts.lts), T i .bts <T j In other words, for example, an HLC clock is composed of 8 bytes, and Bts includes a front part Gts and a rear part Lts, and when comparing the size of the Bts of two transactions, Gts is compared first, and when Gts are the same, Lts is compared as well.

[0115] It is necessary to explain that after each transaction is successfully committed, an increment operation needs to be performed on the Lts on the coordinator (i.e., the cooperative node device), and an increment operation needs to be performed on the Newts of each session; only in this way can the increment of the causal order of the system be guaranteed.

[0116] Based on the above definitions of the nine parallel levels, we introduce nine clock-based parallel level algorithms.

[0117] I) Serialization: For any two transactions T i and T j is T i .ets <T j .bts must be satisfied, T i T j The Bts and Ets values ​​are taken from the global clock.

[0118] II) Strictness: For any two concurrent write transactions T i and T j is T i .ets <T j .bts must be satisfied, T i T j If it is not a concurrent transaction, T i .ets <T jNot subject to .bts restrictions.

[0119] In addition, read-only transactions T k is not completed j It can be run in parallel with a transaction, i.e. T j .bts <T k .bts. k T j If it is a concurrent transaction, the read is T i is the data written by T j This is not data that has been written but not yet completed (ensuring you are reading the latest data). What is actually happening here is an "approximate time travel" event.

[0120] In addition, T i and T j The Bts and Ets values ​​of T are obtained from the global clock. k If is a distributed transaction, its Bts must be taken from the global clock, and T k If is a local transaction (single node transaction), its Bts can be obtained from a clock on the node, but the node clock must be kept updated synchronously with the global clock.

[0121] In addition, a read operation of a transaction cannot read future data item values ​​that were committed before this transaction. i .bts <T j If it is .bts, R i (X) ≠ W j (X), i.e. it will not support reading in the future.

[0122] III) Linearization: For any two write transactions T i and T j is T i .ets <T jAlthough .bts does not need to be satisfied, if it is a concurrent transaction, serializability verification must be performed. This is a difference from the definition of the strict level. Other conditions for read-only transactions and clock acquisition methods are the same as the strict level, and the linear level does not support future reads either.

[0123] IV) Ordering: Any type of transaction can be executed concurrently or in parallel. Concurrent transactions need to be verified for serializability.

[0124] In addition, any two transactions P(T i )=P(T j ), where P() represents the process, and the Ets value of each transaction must be incremental, i.e., T i .ets <T j It's .bts.

[0125] In addition, the Bts and Ets of distributed transactions may originate from a global clock or a hybrid logical clock, while the Bts and Ets of local transactions may originate from the clock of the local node, but it is necessary to realize the causal relationship between the clocks. That is, two processes P i and P j , P i is the cause and P j If P has a relation where P is the result, j The clock is P i The adjustment must be made based on the clock of j The clock of P i The clock frequency should be greater than the clock frequency.

[0126] Additionally, the ordering level allows old reads and future reads to occur, and allows causal loss and causal reversal.

[0127] In addition, the ordering level corresponds to serializability taking into account partial order relationships.

[0128] V) Serializable: Similar to the ordering level, but does not consider the effect of partial ordering on serializability. Equivalent to traditional serializable scheduling techniques.

[0129] VI) Causal Repeatable Read: Two transactions T with any causal relationship i and T j So, two processes P i and P j P i is the cause and P j If P has a relation where P is the result, j The clock is P i The adjustment must be made based on the clock of j The clock of P i Here, based on the above definitions of PO, CPO, and SPO relationships, the clock of transaction T i and T j Determine whether there is a causal relationship.

[0130] In addition, when this transaction reads data, it does so in the snapshot established by the Bts of this transaction.

[0131] In addition, the causal repeatable read level does not need to verify serializability, but it does need to ensure that there are no read partial order anomalies. However, it cannot detect data anomalies of the type of write partial order or read / write partial order.

[0132] VII) Repeatable Read: Causal relationships are not taken into account, and everything else is the same as the Causal Repeatable Read level.

[0133] VIII) Read Committed: Read committed without considering causality. It allows future reads to occur, i.e., between any two transactions, i.e., T i .bts <T j .bts, but T j .ets <T i For .ets, use Ti is T j Data item W written by j (X)=R i You can read (X), which indicates that a "Time travel" event has occurred.

[0134] In addition, partial read order and partial write order types of data anomalies are permitted to occur.

[0135] IX) Read Uncommitted Read-Write: This is the weakest consistency level, and any data anomalies or inconsistencies may occur. The Read Uncommitted Read-Write level does not have any restrictions, does not verify data anomalies, and does not restrict inconsistencies.

[0136] When the above clock-based concurrency level algorithm is applied to a distributed database system, when different nodes in the system require synchronous time calibration, the system adopts an algorithm similar to NTP (Network Time Protocol) to perform periodic time calibration. In addition, when a causal event occurs, the time of the node where the cause event is located is time calibrated to the node where the result event is located. In addition, assuming that the concurrency level of a certain transaction is equal to or higher than the serializable level, when a global timestamp is obtained, the obtained global timestamp is used to perform time calibration against the timestamp of the local node. In addition, for the node to be time calibrated, the time calibration must at least maintain the monotonically increasing attribute of the clock value of this node.

[0137] In some embodiments, during the time calibration process, two node devices transmit the latest timestamp message of the local node to another message receiver that is the target of time calibration in a message packet communicated between the node devices, and after receiving the information, if the timestamp value of the message packet is greater than the timestamp value of the local clock, the message receiver corrects the local clock.

[0138] Hereinafter, the embodiment of the present application further provides a proof process for the uniqueness of the linearization level, and in the industry, there are three types of linearization level: Linearizability level, Linearizability-Regular level and Linearizability-Safe level. The detailed definitions of the three types are as follows, and after the above three types of linearization level are combined with transaction integrity, only one level can exist.

[0139] The definition of the Linearizability level is as follows [Equation 1].

[0140]

number

[0141] (Here, F denotes a function used to obtain the return value of the read / write operation, SingleOrder denotes a single global order, RealTime denotes a real-time mechanism, RVal denotes a return value that satisfies the consistency condition, H denotes a set of history operations, H' denotes the existence of one H, op denotes the read / write operations of the current transaction, ar denotes the total order relation of H, vis denotes the visibility of the read / write operations, rb denotes the partial order relation of H, op.oval denotes the return value of the read / write operation, and [equation 2] denotes the time when the return value has been obtained but not yet returned to the user.)

[0142]

number

[0143] The definitions of the Linearizability-Regular level and the Linearizability-Safe level are as follows [Mathematical Formula 3].

[0144]

number

[0145] (Here, F denotes a function used to obtain the return value of a read / write operation, SingleOrder denotes a single global order, RealTimeWrites denotes a real-time write mechanism, RVal denotes a return value that satisfies the consistency condition, SeqRVal denotes that if the history result that exists in any operation op and belongs to the concurrent time is an empty set, it can be inferred that the return value of the operation belongs to the context function in which the operation resides, rb denotes a partial order relation in H, wr denotes a write operation, op denotes the read / write operations of the current transaction, ar denotes a total order relation in H, H denotes a sequence of history operations, Concur denotes concurrent operations, op.oval denotes the return value of a read / write operation, cxt denotes a context, and A denotes a data object.)

[0146] FIG. 3 is a diagram showing the evolution principle of linearization levels provided by an embodiment of the present application. As shown in 300, A , P B , P C shows three processes A, B, and C, which read and write in parallel (driven from left to right according to Real-Time). The variable x is initialized to 0. P C is read according to the semantics of the Linearizability level, where x is allowed to be 0 or 1. According to the semantics of the Linearizability-Regular level, x is allowed to be 0, 1, or 2. According to the semantics of the Linearizability-Safe level, where x is any value.

[0147] Below, by contradiction, under the action of the transaction, P in Figure 3 AIt is impossible to read the value 2 written by P, i.e., multiple types of linear consistency cannot exist in the definition of a transaction. Each operation in Figure 3 is considered as one transaction. Based on the characteristics of a transaction, it is necessary to satisfy recoverability (i.e., read-committed must be guaranteed). C Assuming that the Read operation of can read Write(2), then P C -read-ets <P A -write(2)-ets, i.e., P C At the time when the transaction is executed, A The second transaction in has not yet completed and does not satisfy recoverability in the database, so P C P A cannot read the value 2 written by P A Only write(1) or write(0) of a row can be read. Therefore, in a transactional database, due to the impact of recoverability, the effectiveness of the Linearizability-Regular and Linearizability-Safe levels of consistency is equivalent to linear consistency.

[0148] Based on the definition of each concurrency level above, the concurrency level in the database provided by the embodiment of the present application can be set independently for different concurrent transactions. That is, it is effective only for a single transaction, that is, multiple concurrency levels coexist in a concurrent transaction. In other words, the concurrency level is determined independently as a unit of transaction, and it is supported to configure the same or different concurrency levels for different transactions in the system. The semantics of "isolation" are the semantics that make the transaction maintain the isolation level under a certain isolation level, so that the isolation has a semantics associated with the transaction and is independent of other transactions.

[0149] The various consistency levels of the concurrent consistency model can be distinguished from three perspectives:

[0150] System perspective: Various consistency levels exist within a system, and different transactions can hold different concurrent consistency levels at the same time, which makes the system have multiple consistency states simultaneously. This makes the system "partitioned", and therefore it is not possible to define the semantics of multiple consistency levels for the concurrent consistency model from a system perspective.

[0151] User's perspective: When different users execute transactions, from the viewpoint of different users, the objects they manipulate can maintain a consistent view from the viewpoint of the users, which is a feasible approach. This kind of approach is similar to the semantics of "isolation level", that is, multiple consistency levels of the concurrent consistency model are localized according to the viewpoint of the users, and thus multiple consistency levels of the concurrent consistency model are defined from the viewpoint of the users, and the multiple consistency levels of the concurrent consistency model coexist in concurrent transactions.

[0152] System-based user perspective: In the same period, it is necessary to maintain the system aspect without being in a "disconnected" state, and at the same time, it is necessary to satisfy the consistency of the user's perspective. This situation is a dilemma. Using the system-level parameter pmodel, we define the gradual consistency, and the algorithm to activate the consistency level according to the defined strength level as mentioned above is given as follows.

[0153] Strong consistency is effective: Only strong consistency level is included, where a global clock is required to ensure global consistency, and therefore only the levels under the strong consistency level can coexist within the same period.

[0154] Non-strong consistency is valid: Any level other than the strong consistency level, including serializable and other weaker levels, does not depend on a global clock, so that each level coexists within the same time period.

[0155] pmodel=UM, i.e. user mode, is defined, forcing all consistency levels of the concurrent consistency model to coexist, but there is a practical inconsistency problem.

[0156] We define pmodel=SFM, i.e., strong hybrid mode, which allows each level under strong consistency level to coexist in the same period, and we define pmodel=WFM, i.e., weak hybrid mode, which allows serialization and other weaker levels to coexist.

[0157] The above definition of the system-level parameter pmodel allows for a type of concurrent consistency level to coexist within a database system, where multiple consistency levels of the concurrent consistency model have semantics associated with the transactions and can therefore coexist in concurrent transactions.

[0158] 4 is a flowchart of a transaction processing method provided by an embodiment of the present application. As shown in FIG. 4, the embodiment is applied to a database system, which includes a standalone system or a distributed system, and the embodiment of the present application takes a node device of a standalone system as an example for description, and the embodiment includes the following contents:

[0159] 401: In response to a read / write operation of a target transaction, a node device acquires a read set and a write set of the target transaction.

[0160] Here, the target transaction may be a global transaction or a local transaction, and the embodiment of the present application will be described taking as an example that the target transaction is a local transaction.

[0161] In some embodiments, a node device establishes a session with a terminal, the session is used to process the target transaction, the node device receives an execution request for the target transaction sent by the terminal, and in response to the execution request, executes a read and write operation of the target transaction, and obtains a read set and a write set for the target transaction, where the read set is used to store data items to be read that are visible to the target transaction. In other words, the visible data items related to the read operation of the target transaction constitute the read set of the target transaction, and the write set is used to store data items to be written by the target transaction. In other words, the data items related to the write operation of the target transaction constitute the write set of the target transaction.

[0162] Optionally, the terminal may be any electronic device associated with a user, including but not limited to at least one of a smartphone, a tablet computer, a laptop, a desktop computer, a smart speaker, or a smart watch, and embodiments of the present application do not place any specific limitations on the type of terminal.

[0163] Optionally, an application client terminal is installed on the terminal, and the application client terminal is any one of client terminals capable of providing data services. For example, the application client terminal includes at least one of a payment application client terminal, a food delivery application client terminal, a taxi application client terminal, or a social application client terminal, but the embodiment of the present application does not make a specific limitation on the type of the application client terminal.

[0164] In some embodiments, in the session establishment stage, an application client terminal on a terminal establishes a session with a node device in the following manner:i The meta information system issues a request to execute the application, and checks whether the current client terminal has already established a session with the node device. If a session has already been established, the meta information system multiplexes the currently established session; if a session has not been established, the node device establishes a session relationship with the application client terminal.

[0165] 402: In response to the verification command for the target transaction, the node device determines the logical start time and the logical commit time of the target transaction.

[0166] In some embodiments, after the execution of the target transaction is completed, the verification phase of the target transaction is entered, and the node device reads the logical start time Bts and the logical commit time Ets from the transaction status list of the target transaction in response to the verification command of the target transaction. It has already been introduced that in the above-mentioned implementation environment, each transaction is related to two global clocks, that is, the logical start time Bts and the logical commit time Ets both belong to the global timestamp, and the global timestamp can be generated by the global timestamp generation cluster. The global timestamp adopts at least one of a physical clock, a logical clock, a hybrid physical clock, or a hybrid logical clock, but the embodiment of the present application does not specifically limit the type of the global timestamp. Here, the logical start time Bts characterizes the global clock at which the target transaction logically starts to execute, and the logical commit time Ets characterizes the global clock at which the target transaction logically starts to commit, and in the initialization phase of the target transaction, the logical start time Bts is initialized to 0, and the logical commit time Ets is initialized to +∞. As the target transaction is executed, any of the cooperative node devices, data node devices, etc. may reassign values ​​to the logical start time Bts or logical commit time Ets (i.e., modify the timestamp values ​​in the transaction status list), so that ultimately, in the verification phase triggered by the verification command, the logical start time Bts and logical commit time Ets will no longer have their initial values.

[0167] In some embodiments, during the verification stage, the node device needs to verify whether the logical start time Bts and the logical commit time Ets of the target transaction meet the parallel consistency level of the target transaction. Here, the parallel consistency level refers to the consistency isolation level that takes transactions as units and supports parallel transactions. The parallel consistency level classifies the behavior on the data items of all types of transactions in the database, and allows different transactions to meet different parallel consistency levels within the same database system. Hereinafter, the verification process for each level will be described.

[0168] i) Serialization When the parallel consistency level is serialization, the node device obtains the parallel transaction T i of the target transaction T j . If the logical commit time of the target transaction is earlier than the logical start time of the parallel transaction (T i .ets < T j .bts), or the logical start time of the target transaction is later than the logical commit time of the parallel transaction (T j .ets < Ti.bts), the timestamp Newts of the latest completed transaction of the session to which the target transaction belongs is obtained. If the logical commit time of the target transaction is greater than or equal to the timestamp of the latest completed transaction (T i .ets ≤ Newts), it is determined to match the parallel consistency level.

[0169] At the serialization level, since it is necessary to satisfy that any two transactions are all queued and executed in series, the node device needs to inquire about all concurrent transactions (which may be zero, one, or multiple) of the target transaction. If there are no concurrent transactions, the direct verification is passed, and step 403 is executed. If there is at least one concurrent transaction, it is necessary to verify that the target transaction and each concurrent transaction can be executed in series. Since the logical start time and the logical commit time can constitute one logical time interval, verifying whether they can be executed in series is equivalent to verifying whether there is an intersection between the logical time intervals of the target transaction and each concurrent transaction. If there is no intersection between the logical time intervals of the target transaction and all the concurrent transactions, the verification is passed, and step 403 is executed. If there is an intersection between the logical time intervals of the target transaction and any one of the concurrent transactions, the target transaction is rolled back.

[0170] ii) Strictness When the parallel consistency level is strict and the target transaction is a write transaction, the node device i Concurrent write transactions T j The logical commit time of the target transaction is smaller than the logical start time of the concurrent write transaction (T i .ets <T j .bts), or the logical start time of the target transaction is greater than the logical commit time of the concurrent write transaction (T j .ets <T i .bts), the concurrent read-only transaction T k The logical start time of the concurrent read-only transaction is greater than the logical start time of the concurrent write transaction (T j .bts <Tk If the target transaction belongs to a session, the timestamp Newts of the latest completed transaction is obtained. If the logical commit time of the target transaction is equal to or greater than the timestamp of the latest completed transaction (T i If .ets≦Newts, it is determined that the concurrent consistency level is matched.

[0171] In the strict level, any two parallel write transactions must maintain serial execution, so if the target transaction is a write transaction, it is only necessary to query all the parallel write transactions of the target transaction and verify that serial execution is maintained between the two parallel write transactions. In addition, it is also necessary to obtain the indirect parallel transactions of the target transaction through the parallel read-only transactions of the parallel write transactions, so that future read anomalies can be avoided based on clock verification.

[0172] iii) Linearization When the parallel consistency level is linearization and the target transaction is a write transaction, the node device i Concurrent write transactions T j If the target transaction and the concurrent write transaction pass the serializability verification, a concurrent read-only transaction T k , and the logical start time of the concurrent read-only transaction is greater than the logical start time of the concurrent write transaction (T j .bts <T k If the target transaction belongs to a session, the timestamp Newts of the latest completed transaction is obtained. If the logical commit time of the target transaction is equal to or greater than the timestamp of the latest completed transaction (T iIf .ets≦Newts, it is determined that the concurrent consistency level is matched.

[0173] In the linearization level, serial execution between any two write transactions is not required, but serializability between parallel write transactions needs to be verified, so when the target transaction is a write transaction, it is only necessary to verify whether the target transaction satisfies serializability with the parallel write transaction. The other steps are similar to the strict level, and are not repeated here.

[0174] iv) ordering When the parallel consistency level is ordered, the node device i Concurrent transactions of T j If the target transaction and the concurrent transaction pass the serializability verification, a first transaction T a and determine whether the logical commit time of the target transaction is less than the logical start time of the first transaction (T i .ets <T a If the logical commit time of the target transaction is equal to or greater than the timestamp of the latest completed transaction (T i If the first transaction has a causal relationship with the target transaction, the logical start time of the result transaction in the causal relationship is updated, and the updated logical start time of the result transaction is made greater than the logical commit time of the cause transaction.

[0175] At the ordering level, any type of transaction can be executed concurrently or in parallel, so it is only necessary to verify serializability for concurrent transactions. However, at the ordering level, it is necessary to additionally ensure that transactions within the same session maintain linearity; that is, serializability that takes into account partial ordering can be realized.

[0176] v) Serializable If the parallel consistency level is serializable, the node device i Concurrent transactions of T j If the target transaction and the concurrent transaction pass the serializability verification, a first transaction T a and determining whether the logical commit time of the target transaction is less than the logical start time of the first transaction and whether the logical start time is less than or equal to the logical commit time (T i .ets <T a .bts and T i .bts <T i .ets), it is determined that the parallel consistency level is matched.

[0177] The serializable level is similar to the ordered level, but does not take into account partial ordering relationships and will not be repeated here.

[0178] vi) Causal Repeatable Read When the parallel consistency level is causally repeatable read, the node device i A result transaction T that has a causal relationship with the target transaction and is caused by the target transaction. j , update the logical start time of the resulting transaction, and make the logical start time of the resulting transaction greater than the logical commit time of the target transaction (T i .ets <T j .bts), is determined to match the concurrent consistency level.

[0179] At the repeatable read level, we do not need to verify serializability, but we do need to guarantee that any two transactions that have a causal relationship are ordered, and therefore we need to make an adjustment to the clock of the result transaction based on the clock of the target transaction, thereby ensuring that there are no read partial order anomalies.

[0180] vii) Repeatable Leads, Committed Leads and Uncommitted Leads A node device determines that it matches the parallel consistency level if the parallel consistency level is repeatable read, read committed, or read uncommitted read / write.

[0181] In Repeatable Read, Read Committed, and Read Uncommitted, there is no need to take into account the partial order relationship, and there is no need to verify serializability, so step 403 below can be executed directly.

[0182] 403: The node device updates the logical start time based on the write set in response to the logical start time and the logical commit time matching the concurrency consistency level of the target transaction.

[0183] The above step 403 is that the node device updates the logical start time based on the write set if the logical start time and the logical commit time match the parallel consistency level of the target transaction.

[0184] In some embodiments, the node device obtains at least one write target transaction information WT of at least one data item in the write set, the at least one write target transaction information WT is used to identify a transaction currently modifying the at least one data item, adjusts the logical start time in response to the at least one write target transaction information WT being all empty, and rolls back the target transaction in response to any write target transaction information WT of the at least one write target transaction information WT being not empty.

[0185] In other words, the node device obtains the write target transaction information WT of each data item in the write set, and the write target transaction information WT is used to identify the transaction currently modifying the data item, and updates the logical start time if the write target transaction information WT of each data item is empty, and rolls back the target transaction if any of the write target transaction information WT of the data items is not empty.

[0186] In some embodiments, when the write target transaction information WT of all data items is empty, the node device performs the following update operation on the logical start time: For each data item of the at least one data item, obtain the write target transaction information of the data item as the transaction identifier of the target transaction, and update the logical start time to be greater than the maximum read transaction timestamp of the data item. In other words, update the logical start time, and make the updated logical start time greater than the maximum read transaction timestamp of the data item. In other words, assign a value to the logical start time using a clock value greater than the maximum read transaction timestamp of the data item, and the maximum read transaction timestamp is used to indicate the maximum value of the logical commit times of the transactions that read the data item, and adjust the logical start time based on the active transaction set if the updated logical start time and the logical commit time match the concurrent consistency level of the target transaction. In other words, update the logical start time that has already been updated once again based on the active transaction set. In other words, a new value is reassigned to a logical start time that has already been assigned a value once, the active transaction set is used to identify transactions that have already begun execution but have not yet committed, and if the updated logical start time and the logical commit time do not match the concurrency consistency level of the target transaction, the target transaction is rolled back.

[0187] In some embodiments, for each data item y in the write set, the node device checks whether the write target transaction information WT of the data item y is empty. If the write target transaction information WT of the data item y is not empty, it means that there are other transactions currently modifying the data item y, and the other transactions have already entered the verification phase. At this time, the target transaction Ti is rolled back to resolve the write-write conflict; otherwise, if the write target transaction information WT of the data item y is empty, a lock is first placed on the write target transaction information WT of the data item y to prevent other concurrent transactions from modifying the data item y in parallel, for example, a recommended lock is placed on the data item y. In this way, only the modification operation on the write target transaction information WT of the data item y can be made exclusive, and the read-only operation on the data item y can be normally executed.

[0188] In some embodiments, after the locking is completed, the node device transfers the transaction information WT of the write target of the data item y to the target transaction T i Transaction identifier T i .TID, in other words, the target transaction T i Transaction identifier T i The value of .TID is assigned to the transaction information WT to be written for data item y, and then T i Update .bts to be greater than the maximum read transaction timestamp Rts of data item y. In other words, the logical start time T ibts, so that the updated logical start time is greater than the maximum read transaction timestamp Rts of data item y. In other words, a value is assigned to the logical start time using a clock value greater than the maximum read transaction timestamp Rts of data item y, where Rts records the maximum logical commit time of all transactions that have read data item y, e.g., T i .bts=max(T i .bts,y.cts+1), where Cts is the final logical commit time of the transaction that generates the data item y. In the above process, read / write conflicts can be resolved by adjusting the logical start times.

[0189] In some embodiments, the node device uses a lock-free CAS (Compare And Swap) technique to assign a value to the write target transaction information WT of the data item y, thereby improving system performance.

[0190] In some embodiments, the active transaction set includes a first transaction set and a second transaction set, the first transaction set being used to identify transactions in a committing state or a verification pass state, and the second transaction set being used to identify transactions in a running state. On this basis, the node device uses the following method when updating the logical start time based on the active transaction set: update the logical start time to be greater than the maximum logical commit time in the first transaction set, in other words, update the logical start time and make the updated logical start time greater than the maximum logical commit time in the first transaction set. In other words, assign a value to the logical start time using a clock value greater than the maximum logical commit time in the first transaction set, and adjust the logical commit time of the transaction in the second transaction set to be less than the updated logical start time if the updated logical start time is less than or equal to the logical commit time. In other words, update the logical commit times of the transactions in the second transaction set so that the updated logical commit times of the transactions are less than the updated logical start time of the target transaction, or assign values ​​to the logical commit times of the transactions in the second transaction set using a clock value less than the updated logical start time of the target transaction, and roll back the target transaction if the updated logical start time is greater than the logical commit time.

[0191] In some embodiments, the node device obtains all first transactions T1 that are already in the committing or verify pass state, and i The logical start time T of i Adjust .bts to be larger than T1.ets for each transaction in T1, i.e., T i .bts=max(Ti Next, the node device obtains all second transaction set T2 in the active state, adjusts T2.ets of each transaction in T2, and sets it to the target transaction T i The logical start time T of i .bts, i.e., T2.ets = min(T2.ets,T i .bts-1).

[0192] In the above process, the first transaction set can resolve read / write conflicts between the write of the current transaction and previous reads of other already completed transactions, so that the write operation of the current transaction occurs after the read operation of the transaction that has already completed its read. The second transaction set can resolve read / write conflicts between the write of the current transaction and currently ongoing reads of other transactions, so that other transactions cannot read the data written by the current transaction.

[0193] In some embodiments, if the logical start time of any one transaction in the second transaction set is greater than the updated logical commit time of the transaction, the transaction is rolled back. That is, when validating the target transaction, if a transaction with an invalid logical time interval is found in the adjusted second transaction set, the transaction in the second transaction set is simultaneously and immediately rolled back, which can further improve system performance.

[0194] 404: The node device commits the target transaction in response to the updated logical start time being equal to or less than the logical commit time.

[0195] The above step 404 is for the node device to commit the target transaction if the updated logical start time is equal to or less than the logical commit time.

[0196] In some embodiments, at the commit phase of the target transaction, the node device writes the data in the write-set of the target transaction to disk and persists it in the database, and for each data item x in the read-set, modifies the maximum read transaction timestamp Rts of data item x and sets it to T i .cts or more, i.e., x.rts=max(x.rts,T i .cts), where T i .cts refers to the logical commit time of the target transaction when it finally commits after multiple adjustments (also called value assignments or updates). Next, select the transaction T i For each data item y in the write set, update the wts and rts of the new version of y, and first make the wts of the new version = T i .cts, then the new version of rts=max(x.rtx,T i .cts), persist the new version in the database, and modify Flag (one parameter). Next, clear the active transaction set RTlist(y) for data item y, and clear the write target transaction information WT for data item y. Here, wts is the creation timestamp of the new version of y, and rts is the maximum read transaction timestamp of the new version of y.

[0197] In some embodiments, the node device may i Clear the read and write sets of T, update Bts=T.cts of T in LocalTS (local transaction state list), and set the target transaction T iSet the transaction state to Committed.

[0198] All the above optional technical solutions can be adopted in any combination to form optional embodiments of the present disclosure, and will not be described one by one here.

[0199] In the method provided by the embodiment of the present application, in the execution phase of the target transaction, the read / write set of the target transaction is obtained, and in the verification phase, according to the logical start time and logical commit time of the target transaction, it is verified whether the target transaction matches its own parallel consistency level, and the logical start time is dynamically updated according to a predetermined strategy. If the logical start time and logical commit time after the final update are valid, it is possible to prevent data anomalies that are not allowed in its own parallel consistency level from occurring, and further commit the target transaction, so that different transactions in the entire system can correspond to different parallel consistency levels, which greatly improves the accuracy of data anomaly detection, and improves the transaction processing efficiency and the performance of the database system.

[0200] In the above embodiment, only a standalone system is taken as an example to provide some basic introduction to the concurrency control access algorithm. In the embodiment of the present application, a kind of decentralized distributed system is taken as an example to describe the concurrency access control algorithm of various concurrency levels in detail.

[0201] First, we introduce the decentralized algorithm.

[0202] In the process of transaction processing, there are two centralized components: one is a clock generator and the other is a transaction coordinator.

[0203] Clock generator: the global clock mentioned above, i.e. the global timestamp generation cluster. Correspondingly, the local clocks are a kind of decentralized component.

[0204] Transaction Coordinator: In the transaction verification stage, it is necessary to verify whether a distributed transaction matches transaction integrity, whether it is serializable or has no data anomalies, and therefore it relies on one transaction coordinator, i.e., a cooperative node device or a coordinator.

[0205] A decentralized algorithm refers to one that relies as little as possible on centralized components to drive the algorithmic process.

[0206] Table 2 shows the characteristics and realization of the decentralized algorithm based on the concurrent consistency model, which is shown in Table 2.

[0207] [Table 2]

[0208] The decentralization algorithm process can be divided into four main stages:

[0209] Phase 1: Transaction snapshot establishment phase where a transaction starts to obtain Bts. For strong consistency level and intermediate consistency level, it is necessary to establish a data reading perspective from a global perspective, so the Bts of the target transaction must be obtained from a global clock. Optionally, the global clock, such as a global timestamp generation cluster in the above implementation environment, is a centralized component, and optionally, the global transaction adopts a Truetime mechanism to constitute a decentralized component.

[0210] Phase 2: This is the transaction semantics realization operation phase where a transaction performs reads and writes on data items, regardless of whether the work is centralized or not.

[0211] Phase 3: This is the phase of verifying the validity of the transaction before the transaction is committed. At this point, a decentralized verification method is used, and the DTA (Dynamic Timestamp Allocation) algorithm of the TO (Timestamp Ordering) algorithm is used to realize decentralized transaction verification technology.

[0212] Phase 4: This is the final phase of a transaction commit or rollback operation. For strong and intermediate consistency levels, the transaction commit operation needs to establish the global commit timestamp of the transaction on all data items in the global view. Other consistency levels only need to obtain local timestamps (for distributed transactions, obtain the local timestamp from the transaction coordinator, and for local transactions, obtain the local timestamp from the local node).

[0213] Below, we consider a transaction processing process based on a parallel consistency model in a distributed system according to the four stages of the decentralized algorithm mentioned above.

[0214] (1) The transaction snapshot establishment phase where a transaction starts acquiring BTS

[0215] A target transaction T is sent by a client terminal Client onto a cooperative node device (i.e., a coordinator). The target transaction T completes initialization in the cooperative node device, and the initialization includes the following steps:

[0216] First, the cooperative node device distributes a globally unique transaction identifier TID (i.e., a transaction number) to the target transaction T. The TID indicates that the transaction originates from a specific session, and in a distributed system, this distinguishes whether some transactions originate from the same session (i.e., distinguishes a situation of partial order relationship).

[0217] In some embodiments, there are many ways to use the "TID" to indicate whether transactions come from the same session, for example, indicating the session in the first 96 bits of a single 128-bit TID, or centrally registering sessions in one central node and then unifying unique numbers in the central node, etc.

[0218] Next, the cooperative node device records the state of the target transaction T in the transaction state list, for example, by setting the Status state of the target transaction T to Grunning and initializing Bts and Ets to 0 and +∞, respectively.

[0219] (2) The semantics realization phase of a transaction, in which a transaction performs read and write operations on data items.

[0220] After the target transaction T completes initialization on the cooperative node device, it begins its execution phase.

[0221] In the read phase, the target transaction T reads the required data item according to the execution logic, and updates and writes the read data item to the local internal memory of the target transaction T, i.e., the local internal memory of the cooperative node device. When the target transaction T needs to read the data item x, it executes the following steps.

[0222] 2.1: A cooperative node device of a target transaction T must send a data read request message ReadRequestMessage (abbreviated as rrqm) to a data node device RM (resource manager, a participant in a transaction, i.e., the executor of a subtransaction) where the data item x is located, requesting the reading of the data item x. The values ​​of the four fields of rrqm are shown as follows, 2.1.1 to 2.1.4.

[0223] 2.1.1: TID, the TID of the target transaction T.

[0224] 2.1.2: Bts, if it is a level above the serializable level, the cooperative node device obtains a timestamp value from the global clock; otherwise, it is Bts on the cooperative node device of the target transaction T, and for the serializable and weaker levels, it is a time value determined by the HLC (Hybrid Logical Clock) on the cooperative node device. In some embodiments, the serializable and weaker levels are realized using a global clock, but in consideration of factors of message synchronization efficiency, the embodiment of the present application will be described as an example of a method of adopting the HLC clock. However, this does not mean that the embodiment of the present application completely denies the use of the global clock for the serializable and weaker levels.

[0225] 2.1.3:Ets, and the clock acquisition method is similar to Bts, so it will not be repeated here.

[0226] 2.1.4: ReadPlan, a query plan in which target transaction T reads data item x.

[0227] 2.2: After receiving the message rrqm, the data node device RM where the data item x is located executes the following steps in the order of precedence.

[0228] 2.2.1: RM checks whether the information of target transaction T is included in the local LocalTS (local transaction status table), and if LocalTS does not include the information of target transaction T, it initializes the information of target transaction T on it. That is, it inserts one record in LocalTS, with values ​​of rrqm.TID, rrqm.Bts, rrqm.Ets and rrqm.Running, and LocalTS includes the information of target transaction T. That is, if target transaction T has accessed other data items on the RM before reading data item x, it updates the information of target transaction T, so that T.Bts=max(T.Bts,rrqm.Bts), T.Ets=min(T.Ets,rrqm.Ets). That is, it updates Bts of target transaction T in LocalTS to the maximum value between the existing value and the carry-over value in rrqm, and updates Ets to the minimum value between the existing value and the carry-over value in rrqm.

[0229] 2.2.2: RM checks whether T.Bts is less than or equal to T.Ets, and if T.Bts≦T.Ets, it continues to read data item x, otherwise, i.e., if T.Bts>T.Ets, it updates the status of the target transaction T in LocalTS to Aborted, i.e., T.Status=Aborted and returns a rollback Abort message to the cooperative node device of T, i.e., it sends a read request feedback message rrpm to the host RM (cooperative node device) of the target transaction T, and sets the IsAbort field in the read request feedback message rrpm to 1, i.e., rrpm.IsAbort=1, indicating that the target transaction T is to be rolled back.

[0230] 2.2.3: RM finds an appropriate visible version from the set of version states of data item x according to the logical time interval [Bts, Ets] of the target transaction T, that is, queries the target data item that is visible to the target transaction T. To find the target data item of data item x, the inspection should first start from the latest committed data version (abbreviated as the latest version). If T.ets is greater than the wts of the latest version, the latest version is the target data item. Otherwise, instead of the target data item, it is necessary to search for the version one before the latest version, and by analogy like this, stop until the first data version x.v that satisfies T.ets > wts is found, and obtain the data version x.v as the target data item, where wts is the creation timestamp of x.v.

[0231] 2.2.4: After RM finds the target data item x.v, it is necessary to modify Bts of the target transaction T so that T.Bts > x.v.wts, thereby eliminating read-write anomalies. Also, if the found version is the latest version of x, it is necessary to perform the following several steps of operations. First, check whether the write target transaction information WT corresponding to x.v (WT records the transaction identifier of the transaction that is currently modifying x and has passed the verification) is empty. If the WT corresponding to x.v is not empty (assuming the value is TID1 and the transaction corresponding to TID1 is T1), adjust the Ets of the target transaction T so that it satisfies T.Ets < T1.Bts, thereby eliminating read-write conflicts. Next, add the transaction identifier T.TID of the target transaction T to the active transaction set RTlist of x.v, and finally, add x to the local read set of the target transaction T.

[0232] 2.2.5: The RM returns a read request feedback message ReadReplyMessage (abbreviated as rrpm) to the cooperative node device of the target transaction T, where Bts and Ets of rrpm respectively record the upper and lower bounds of the logical timestamp of the transaction T on the current RM, and Value records the value of the data item being read.

[0233] 2.3: After receiving the read request feedback message rrpm from RM, the cooperative node device of the target transaction T performs the following processes in order.

[0234] 2.3.1: The cooperative node device checks whether the received message is an Abort message, i.e. checks whether rrpm.IsAborts is equal to 1, if so, rrpm.IsAbort=1 and enters the global rollback phase, if not, rrpm.IsAbort≠1 and continues to execute step 2.3.2.

[0235] 2.3.2: The cooperative node device updates the state of the target transaction T in the transaction state list, and updates T.Bts=max(T.Bts,rrpm.Bts) and T.Ets=min(T.Ets,rrpm.Ets) of the target transaction T, i.e., Bts of the target transaction T is updated to the maximum value between the existing value and the carry-over value at rrpm, and Ets is updated to the minimum value between the existing value and the carry-over value at rrpm.

[0236] 2.3.3: The cooperative node device checks whether T.Bts in the transaction state list is greater than T.Ets, if so, T.Bts>T.Ets and enters into a global rollback phase; if not, T.Bts≦T.Ets and continues executing the transaction.

[0237] It is necessary to explain that when a cooperative node device decides to roll back a transaction T, it needs to modify the state of the target transaction T in the transaction state list to Gaborting and notify the relevant subnodes (all RMs related to the target transaction T) to perform a local rollback.

[0238] As can be seen from the analysis, in the read phase of the target transaction T, the communication mainly occurs between the cooperative node equipment of the target transaction T and the associated sub RM. The target transaction T needs two communications for each successful data read, where the cooperative node equipment of the target transaction T sends data read request information rrqm on the associated sub RM, and the associated sub RM sends read request feedback information rrpm on the cooperative node equipment. Therefore, the read phase has a maximum of 2n communications, and the maximum communication amount is n × (size of the request message rrqm + size of the response message rrpm), where n is the number of remote reads.

[0239] In some embodiments, when a target transaction T requires multiple data items from an associated sub-RM, the data read request information rrqm for these data items is packetized and sent, making it possible to read these data items in bulk, thereby reducing the number of communications.

[0240] After the target transaction T finishes reading the required data in the read phase and writes the updated data to the local internal memory, it enters the verify phase.

[0241] (3) Verifying the validity of a transaction before it is committed

[0242] In the verification phase, the target transaction T verifies whether there is a conflict between itself and other transactions, and finally decides whether to commit or roll back the target transaction T based on the result of the verification phase. The verification process of the target transaction T includes the following contents:

[0243] 3.1: A cooperative node device of target transaction T modifies the state of target transaction T in the transaction state list to Gvalidating, and sends a ValidateRequestMessage (abbreviated as vrm) to each relevant sub-RM for target transaction T, where Bts and Ets in vrm record the upper and lower bounds of the transaction logical timestamp in the transaction state list of target transaction T, respectively. Optionally, what is sent to the RM together with the validation request message vrm also includes the local write set of the RM.

[0244] 3.2: After each relevant sub-RM for the target transaction T receives the verification request message vrm, it performs a local verification operation, and the local verification operation needs to perform the following steps in order:

[0245] 3.2.1: RM updates T.Bts=max(T.Bts,vrm.Bts), T.Ets=min(T.Ets,vrm.Ets) of target transaction T in LocalTS, i.e., updates Bts of target transaction T to the maximum value between the existing value and the carry-over value in vrm, and updates Ets to the minimum value between the existing value and the carry-over value in vrm. It should be noted that what is updated here is the logical timestamp information of the transaction in the local transaction status table, which is used for transaction parallel access control, i.e., used to ensure transaction consistency.

[0246] 3.2.2: RM checks the bts and ets values ​​of the target transaction T under various parallel consistency levels based on the definition of each level of parallel consistency level and the current setting status of the pmodel value of the database system. In some embodiments, if the parallel consistency level is stronger than serializable, it is necessary to verify that the bts of the transaction must not be smaller than the newts of this session, and if it is smaller, it is necessary to roll back the target transaction T. For example, this is because the order consistency does not match the causal consistency condition required for the partial order relationship. In some embodiments, if the parallel consistency level is equal to serializable, it checks whether T.Bts is greater than T.Ets, and if so, T.Bts>T.Ets, the verification fails, and returns an Abort message to the cooperative node device of the target transaction T (and causes a global rollback). That is, it sends a local verification feedback message lvm, where lvm.IsAbort=1, and if not, it explains that T.Bts≦T.Ets matches the parallel consistency level, and enters the next step of verification.

[0247] 3.2.3: RM finds each data item y in the write set, and then checks whether the write target transaction information WT of data item y is empty. If the write target transaction information WT of data item y is not empty, it means that other transactions are currently modifying data item y, and the other transactions have already entered the verification stage, and it is necessary to roll back the target transaction T to resolve the write-write conflict, i.e., send an Abort message to the cooperative node device of the target transaction T. If not, the write target transaction information WT of data item y is empty, and the operation of the next step is continued, for example, by locking the write target transaction information WT of data item y, to prevent other concurrent transactions from modifying data item y in parallel. Optionally, RM puts a recommendation lock on the data item, making only the modification operation on the write target transaction information WT of data item y exclusive.

[0248] 3.2.4: RM updates the write target transaction information WT of each data item y in the write set to T.TID (indicating that the target transaction T that has entered the verification phase is going to modify the data item y), and adjusts the logical start time of the target transaction T in the local transaction status table to be greater than the maximum read transaction timestamp rts of the data item y, i.e., T.Bts=max(T.Bts,y.cts+1), to facilitate the resolution of read and write conflicts. Optionally, RM uses a lock-free CAS technique to assign a value to the write target transaction information WT of the data item y, thereby improving system performance, or assigns a value to the write target transaction information WT of the data item y after applying a lock. In this application, the search box does not have a specific limitation on whether to apply a lock to WT.

[0249] 3.2.5: RM checks the bts and ets values ​​of the target transaction T under various parallel consistency levels based on the definition of each level of parallel consistency level and the current setting of the pmodel value of the database system. In some embodiments, if the parallel consistency level is stronger than serializable, it is necessary to verify that the bts of the transaction must not be smaller than the newts of the current session. If the bts of the transaction is smaller than the newts of the current session, it is necessary to roll back the target transaction T, for example, because the order consistency does not match the causal consistency condition required for the partial order relationship. In some embodiments, if the parallel consistency level is equal to serializable, it checks whether T.Bts is larger than T.Ets, and if so, T.Bts>T.Ets, the verification fails, and an Abort message is returned to the cooperative node device of the target transaction T (which further causes a global rollback), i.e., a local verification feedback message lvm is sent. Here, lvm.IsAbort=1. If not, T.Bts≦T.Ets, which means matching the concurrent consistency level, and proceeds to the next step of verification.

[0250] 3.2.6: For each data item y in the write set, the RM resolves read / write conflicts by adjusting the timestamp of the target transaction T or the transactions in the active transaction set RTlist. The adjustment rule includes the following two cases:

[0251] Case 1: For writes by this transaction and reads that have occurred in the past by other transactions that have already completed, the occurrence of the write operations by this transaction is postponed to after the read operations of the transactions whose reads have already completed.

[0252] In some embodiments, the RM finds all transactions T1 (first transaction set) that are already in the committing or local validation pass state, and adjusts the logical start time of the target transaction T itself to be greater than the Ets of each transaction in T1, i.e., T.Bts = max(T.Bts, T1.Ets + 1).

[0253] After adjusting T.Bts, RM checks again whether the logical time interval of the target transaction T is still valid. If the logical time interval of the target transaction T is not valid, it returns an Abort message; otherwise, the logical time interval of the target transaction T is valid, and updates the local transaction status of T to Validated, i.e., T.Status=Validated, and enters the next step of adjustment. It needs to be explained that detecting whether the logical time interval is valid means that if the logical start time T.Bts is less than or equal to the logical commit time T.Ets, the logical time interval is valid; otherwise, if the logical start time T.Bts is greater than the logical commit time T.Ets, the logical time interval is not valid.

[0254] Case 2: Regarding writes by this transaction and reads by other currently running transactions, other transactions are prevented from reading data written by this transaction.

[0255] In some embodiments, the RM finds all transactions T2 (second transaction set) in Running state and adjusts the logical time interval of each transaction in T2 to make its logical commit time smaller than Bts of the target transaction T, i.e. T2.Ets=min(T2.Ets, T.Bts-1).

[0256] In some embodiments, after adjusting the logical time interval, if Bts>Ets of a transaction in T2 exists, a global rollback of this transaction in T2 can be signaled.

[0257] 3.2.7: The RM determines that the target transaction T has already passed local validation and creates a new version of data item y based on the updated value of y, but must set a flag (one parameter) to indicate that the new version will not be globally committed.

[0258] 3.2.8: RM returns a local validation feedback message lvm of T to the cooperative node device of T, where Bts and Ets of lvm record the upper and lower bounds of the logical timestamp of transaction T on the local RM, respectively. Note that if the local validation of target transaction T fails, the status of target transaction T in LocalTS needs to be updated to Aborted, i.e., T.Status=Aborted.

[0259] 3.3: After T’s cooperative node device receives the local validation feedback messages lvm from all RMs, it determines whether the target transaction T can pass global validation based on the received messages, which can be mainly divided into several types of cases:

[0260] 3.3.1: If the IsAbort field contains lvm equal to 1, which indicates that the target transaction T does not pass all local validations, the cooperative node device decides to globally rollback the target transaction T, and at the same time updates the state of the target transaction T in the transaction state list to Gaborting, and notifies all subnode RMs to complete the local rollback, i.e., sends a write commit / rollback message coarm to the associated RMs, where coarm.IsAbort=1.

[0261] 3.3.2: Otherwise, if the IsAbort fields in the lvm returned by all RMs are equal to 0, the cooperative node device calculates the intersection of the logical time intervals of all received target transactions T to obtain one new global logical interval [T.Bts, T.Ets]. If T.Bts>T.Ets, it decides to globally roll back the transaction, updates the state of the target transaction T in the transaction state list to Gaborting, and notifies all subnodes to complete the rollback; otherwise, T.Bts≦T.Ets, and enters the next step.

[0262] 3.3.3: The cooperative node device determines that T passes the verification, and randomly selects a time point from the global logical interval [T.Bts, T.Ets] as the final commit timestamp of T, and assigns a value to cts. For example, select one T.Bts as the logical commit timestamp of T.

[0263] 3.3.4: The cooperative node device updates T.Bts=T.Ets=T.cts in the transaction state list, and updates the state of the transaction in the transaction state list to Gcommitting. In some embodiments, the cooperative node device further marks the global transaction state as Gcommitted and simultaneously requests the global timestamp generating cluster to distribute the final global timestamp and records it in the Gts field of the global transaction state.

[0264] 3.3.5: The cooperative node device notifies the relevant RMs to complete the commit, i.e., sends a write commit / rollback message coarm to the relevant RMs, where coarm.IsAbort=0, and coarm.Cts and coarm.Gts record the final commit timestamp and final global timestamp of the transaction, respectively.

[0265] As can be seen from the analysis, in the verification phase of target transaction T, communication mainly occurs between the cooperative node equipment of target transaction T and the associated sub RMs. The communication mainly includes the following two steps: the cooperative node equipment of target transaction T sends a verification request message vrm and a local write set of RM to each associated sub RM, and each associated sub RM sends a local verification feedback message lvm to the cooperative node equipment of target transaction T.

[0266] Therefore, the verification phase requires a maximum of 2m communications, and the size of the communication volume is m × (size of request verification message + size of verification feedback message) + size of the global write set, where m is the number of sub-RMs associated with T.

[0267] (4) The final stage of a transaction commit or rollback operation.

[0268] In the finishing phase, the target transaction T chooses whether to perform a write commit or a rollback based on the verification result of the verification phase.

[0269] 4.1: If the target transaction T passes the validation, it enters the write commit phase, i.e., persists the updates to the data of the target transaction T in the database and performs some subsequent cleansing operations. During the write commit phase, the local RM needs to perform the following operations:

[0270] 4.1.1: For each read data item x in the read set, RM modifies the rts of x so that it is greater than or equal to T.cts, i.e., x.rtx = max(x.rtx,T.cts), and removes itself from RTlist(x).

[0271] 4.1.2: For each write target data item y in the write set, RM updates the wts and rts of the new version of y, where wts = T.cts and rts = max(x.rtx, T.cts), persists y in the database, modifies flag (one parameter), clears the contents of RTlist of y, and clears the contents of WT of y.

[0272] 4.1.3: The RM clears the local read and write sets of the target transaction T.

[0273] 4.1.4: RM updates Bts=T.cts for T in LocalTS and updates the state to committed (at this time, the local transaction state table is used only for transaction consistency and is not related to synchronizing the global transaction state).

[0274] 4.1.5: The RM returns an ACK (Acknowledge Character) to the cooperative node device of the target transaction T indicating successful commit completion.

[0275] Optionally, the cooperative node device of the target transaction T modifies the global transaction state to Gcommitted after receiving the ACK that all RMs have completed the commit, and notifies each RM to cleanse the state of the target transaction T from its local transaction state table.

[0276] 4.2: If the target transaction T does not pass the verification, enter the global rollback phase, that is, roll back the target transaction T, and perform corresponding cleansing operations, which include the following:

[0277] 4.2.1: For each read target data item x in the read set, the RM removes the target transaction T from RTlist(x).

[0278] 4.2.2: For each write target data item y in the write set, the RM cleanses the newly created version y and clears the contents of the write target transaction information WT of y.

[0279] 4.2.3: The RM clears the local read and write sets of the target transaction T.

[0280] 4.2.4: The RM updates the local transaction state of the target transaction T to Aborted.

[0281] 4.2.5: The RM returns an ACK to the cooperative node device of the target transaction T indicating that the rollback has been completed.

[0282] Optionally, the cooperative node device of the target transaction T modifies the global transaction state to Gaborted after receiving the ACK that all RMs have completed the rollback, and notifies each RM to cleanse the state of the target transaction T from its localTS.

[0283] As can be seen from the analysis, in the commit / rollback phase of transaction T, communication mainly occurs between the cooperative node equipment of target transaction T and the associated sub RMs, and the communication mainly includes the following two steps: the cooperative node equipment of target transaction T sends a commit / rollback request message coarm to each associated sub RM, and each associated sub RM sends a commit / rollback completion response message ACK to the cooperative node equipment.

[0284] Therefore, the commit / rollback phase involves a maximum of 2m communications, and the size of the communication volume is m × (size of the commit / rollback request message + size of the commit / rollback request message), where m is the number of sub-RMs associated with transaction T.

[0285] In some embodiments, cooperative node devices reduce the number of communications by sending cleansing messages to the RM in batches.

[0286] All the above optional technical solutions can be adopted in any combination to form optional embodiments of the present disclosure, and will not be described one by one here.

[0287] In the embodiment of the present application, the DTA technology in the TO algorithm is used to initialize the logical start time and logical commit time of a transaction, and then the logical start time or logical commit time is dynamically adjusted according to different situations, and MVCC, DTA and OCC technologies are hybridized to perform transaction parallel access control for multiple types of consistency in the parallel consistency model. Here, the algorithm framework of OCC is mainly applied and combined with DTA to reduce the transaction data information transmitted over the network and improve the verification efficiency of distributed transactions, thereby enhancing the parallel processing ability of distributed transactions. Combined with MVCC, data reading and writing without locking is realized, thereby enhancing the parallel processing ability of local nodes.

[0288] Table 3 shows the implementation difference of two transactions T1 and T2 at serializable level and stronger consistency level, that is, provides a decentralized algorithm of transaction cooperator verification stage based on DTA. The embodiment of the present application defines a complete multi-consistency calculation framework, including a complete and comprehensive consistency level, a consistency strength and weakness classification method, and a calculation environment and method in which consistency coexists. Through various consistency realization technologies, the concurrent consistency model system is completed and enriched, and the expression method of distributed consistency and transaction consistency is integrated based on the definition of transaction attributes of Bts and Ets, and the distributed consistency and transaction consistency algorithms are organically unified into one, so that transaction theory can be migrated to distributed systems.

[0289] [Table 3] JPEG0007546832000007.jpg194170

[0290] FIG. 5 is an interaction flowchart of a transaction processing method provided by an embodiment of the present application. As shown in FIG. 5, based on the above-mentioned multiple parallel level parallel access control algorithm, a process of how a cooperative node device interacts with a data node device under a distributed system to execute a target transaction is provided.

[0291] In step 501, a terminal establishes a session with a cooperative node device for use in processing a target transaction.

[0292] In step 502, the cooperative node device performs initialization for the target transaction.

[0293] Optionally, the cooperative node device distributes a transaction identifier to the target transaction and sets the transaction status Status to Grunning in the transaction status list, initializes the T.Bts of the target transaction to 0, and initializes the T.Ets of the target transaction to +∞.

[0294] The above steps 501-502 are steps for establishing a snapshot of the target transaction, and will not be described again here.

[0295] In step 503, the cooperative node device transmits a data read request message rrqm of the target transaction to the data node device.

[0296] Optionally, the cooperative node device optimizes the SQL according to the request initiated by the application client terminal, generates a physical execution plan for the target transaction, decomposes the execution plan, and sends it to the data node device for the target transaction respectively. The number of data node devices may be one or more. In the embodiment of the present application, there is no specific limit on the number of data node devices.

[0297] Optionally, the data read request message rrqm includes four fields: TID (transaction identifier), Bts (logical start time), Ets (logical commit time), and ReadPlan (query plan).

[0298] In step 504, in response to the data read request message rrqm, the data node device queries the target data items visible to the target transaction and returns a read request feedback message rrpm for the target transaction to the cooperative node device.

[0299] Optionally, the data node device maintains information of the target transaction T in a local transaction status table LocalTS, and performs validity verification for a logical time interval [T.Bts, T.Ets]. After the verification is passed, starting from the latest version of each data item to be read, it may search for the first data version (i.e., the target data item) whose creation timestamp is smaller than T.Ets, and correct T.Bts according to the creation timestamp of the target data item to resolve the read / write conflict and the write / read anomaly, and return a read request feedback message rrpm to the cooperative node device.

[0300] The above steps 503-504 are the semantics realization operation stage of the target transaction, and will not be described again here.

[0301] In step 505, the cooperative node device summarizes the read request feedback message rrpm returned by the data node device, and transmits a verification request message vrm for the target transaction to the data node device.

[0302] Optionally, the cooperative node device summarizes each read request feedback message rrpm, and then traverses whether the IsAborts field is 1. If it is 1, it enters the global rollback phase; if not, it updates the Bts and Ets of the target transaction and then verifies the validity of the logical time interval again. If the verification is passed, it sends a verification request message vrm (i.e., a verification command) and enters the transaction verification phase.

[0303] In step 506, in response to the verification request message vrm, the data node device performs a contention verification on the target transaction and returns a local verification feedback message lvm of the target transaction to the cooperative node device.

[0304] Optionally, the data node device performs validity verification again on the logical time interval [T.Bts, T.Ets] of the target transaction T, and if the verification is successful, further verifies whether the logical time interval satisfies the conditions of the parallel consistency level. If the verification is successful, the data node device updates Bts of the target transaction T based on the write set of the target transaction T, resolves write-write conflicts and read-write conflicts, and further verifies whether the updated logical time interval is still valid. If it is valid, the data node device returns a local validation feedback message lvm to the cooperative node device.

[0305] In step 507, the cooperative node device summarizes the local validation feedback messages lvm of the data node devices to determine a global validation result of the target transaction.

[0306] Optionally, the cooperative node device summarizes each local validation feedback message lvm, and then traverses whether the IsAborts field is 1. If it is 1, it enters the global rollback phase; if not, it updates the Bts and Ets of the target transaction and then verifies the validity of the logical time interval again. If the validation passes, it sends a commit command and enters the global commit phase; if not, it sends a rollback command and enters the global rollback phase.

[0307] The above steps 505 to 507 are steps for verifying the validity of the transaction, and will not be described again here.

[0308] In step 508, in response to the global verification result being a verification pass, the cooperative node device transmits a commit command for the target transaction to the data node device.

[0309] In step 509, the data node device responds to the commit command by committing the target transaction.

[0310] The above steps 508 to 509 are the transaction commit stage, and will not be described again here.

[0311] In the embodiment of the present application, the DTA technology in the TO algorithm is used to initialize the Bts and Ets of the target transaction, and then the Bts or Ets is dynamically adjusted according to different situations, and MVCC, DTA and OCC technologies are hybridized to perform transaction parallel access control for multiple consistency types in the parallel consistency model. The algorithm framework of OCC is mainly applied and combined with DTA to reduce the transaction data information transmitted in the network and improve the verification efficiency of distributed transactions, thereby enhancing the parallel processing ability of distributed transactions. Combined with MVCC, lock-free data reading and writing is realized, thereby enhancing the parallel processing ability of local nodes.

[0312] FIG. 6 is a structural schematic diagram of a transaction processing device provided by an embodiment of the present application. As shown in FIG. 6, the device includes: an acquisition module 601, a decision module 602, an update module 603, and a commit module 604; The acquisition module 601 is used for acquiring the read set and the write set of the target transaction in response to the read and write operations of the target transaction; The determination module 602 is used to determine a logical start time and a logical commit time of the target transaction in response to a verification command of the target transaction; an update module 603 for updating the logical start time based on the write set if the logical start time and the logical commit time match the concurrency consistency level of the target transaction; The commit module 604 is used to commit the target transaction if the updated logical begin time is less than or equal to the logical commit time.

[0313] The device provided by the embodiment of the present application obtains the read / write set of the target transaction in the execution phase of the target transaction, and verifies whether the target transaction matches its own parallel consistency level according to the logical start time and logical commit time of the target transaction in the verification phase, and dynamically updates the logical start time according to a predetermined strategy. If the logical start time and logical commit time after the final update are valid, it prevents data anomalies that are not allowed by its own parallel consistency level from occurring, and further commits the target transaction, so that different transactions in the entire system can correspond to different parallel consistency levels, greatly improving the accuracy of data anomaly detection, and improving transaction processing efficiency and performance of the database system.

[0314] In one possible embodiment, based on the configuration of the device in FIG. 6, the update module 603 includes: an acquisition submodule, an adjustment submodule, and a rollback submodule; The acquisition submodule is used to acquire write target transaction information for each data item in the write set, and the write target transaction information is used to identify a transaction that is currently modifying the data item; The adjustment submodule is used for updating the logical start time when each of the transaction information to be written is empty; The rollback submodule is used to roll back the target transaction if any of the transaction information to be written is not empty.

[0315] In one possible embodiment, based on the configuration of the device of FIG. 6, the adjustment submodule includes: an acquisition unit, an update unit, and an adjustment unit; The acquiring unit is used for acquiring the transaction information of the write target as a transaction identifier of the target transaction; an update unit is used to update the logical start time so that the updated logical start time is greater than a maximum read transaction timestamp of the data item, and the maximum read transaction timestamp is used to indicate a maximum value among logical commit times of transactions that have read the data item; The reconciliation unit is used to update the logical start time based on the set of active transactions when the updated logical start time and the logical commit time match the concurrency consistency level of the target transaction, and the set of active transactions is used to identify transactions that have started execution but have not yet been committed; The rollback submodule is further used to roll back the target transaction if the updated logical begin time and the logical commit time do not match the concurrency consistency level of the target transaction.

[0316] In one possible embodiment, the active transaction set includes a first transaction set and a second transaction set, the first transaction set being used to identify transactions that are in a committing state or a verify passing state, and the second transaction set being used to identify transactions that are in a running state; the reconciliation unit is used for updating the logical start time to make the updated logical start time greater than the maximum logical commit time in the first transaction set, and updating the logical commit time of the transaction in the second transaction set to make the updated logical commit time less than the updated logical start time if the updated logical start time is less than or equal to the logical commit time; The rollback submodule is further used for rolling back the target transaction if the logical begin time after the update is greater than the logical commit time.

[0317] In one possible embodiment, the rollback submodule further comprises: It is used to roll back any transaction in the second transaction set if its logical begin time is greater than its updated logical commit time.

[0318] In one possible embodiment, based on the configuration of the device of FIG. 6, the device further includes an acquisition determination module: The acquisition determination module is used to acquire a concurrent transaction of the target transaction when the concurrency consistency level is serialized, and when the logical commit time of the target transaction is smaller than the logical start time of the concurrent transaction or the logical start time of the target transaction is greater than the logical commit time of the concurrent transaction, acquire a timestamp of the latest completed transaction of the session to which the target transaction belongs, and determine that the target transaction matches the concurrency consistency level if the logical commit time of the target transaction is greater than or equal to the timestamp of the latest completed transaction.

[0319] In one possible embodiment, based on the configuration of the device of FIG. 6, the device further includes an acquisition determination module: The acquisition determination module is used to acquire a parallel write transaction of the target transaction when the parallel consistency level is strict and the target transaction is a write transaction, acquire a parallel write transaction of the target transaction when the logical commit time of the target transaction is less than the logical start time of the parallel write transaction or the logical start time of the target transaction is greater than the logical commit time of the parallel write transaction, acquire a parallel read-only transaction of the parallel write transaction when the logical start time of the parallel read-only transaction is greater than the logical start time of the parallel write transaction, acquire a timestamp of the latest completed transaction of the session to which the target transaction belongs, and determine that the target transaction matches the parallel consistency level if the logical commit time of the target transaction is greater than or equal to the timestamp of the latest completed transaction.

[0320] In one possible embodiment, based on the configuration of the device of FIG. 6, the device further includes an acquisition determination module: The acquisition determination module is used to acquire a parallel write transaction of the target transaction when the concurrency consistency level is linearization and the target transaction is a write transaction, acquire a parallel read-only transaction of the parallel write transaction when the target transaction and the parallel write transaction pass serializability verification, acquire a timestamp of the latest completed transaction of the session to which the target transaction belongs when the logical start time of the parallel read-only transaction is greater than the logical start time of the parallel write transaction, and determine that the target transaction matches the concurrency consistency level when the logical commit time of the target transaction is greater than or equal to the timestamp of the latest completed transaction.

[0321] In one possible embodiment, based on the configuration of the device of FIG. 6, the device further includes an acquisition determination module: The acquisition determination module is used to acquire a concurrent transaction of the target transaction when the concurrency consistency level is ordered, determine a first transaction belonging to the same session as the target transaction when the target transaction and the concurrent transaction pass serializability verification, acquire a timestamp of the latest completed transaction of the session when the logical commit time of the target transaction is smaller than the logical start time of the first transaction, and determine that the target transaction matches the concurrency consistency level when the logical commit time of the target transaction is equal to or greater than the timestamp of the latest completed transaction, where, when the target transaction has a causal relationship with the first transaction, update the logical start time of a result transaction in the causal relationship, and make the logical start time of the updated result transaction greater than the logical commit time of the cause transaction.

[0322] In one possible embodiment, based on the configuration of the device of FIG. 6, the device further includes an acquisition determination module: The acquisition determination module is used to acquire a concurrent transaction of the target transaction when the concurrency consistency level is serializable, and when the target transaction and the concurrent transaction pass serializability verification, determine a first transaction that belongs to the same session as the target transaction, and determine that the target transaction matches the concurrency consistency level if the logical commit time of the target transaction is less than the logical start time of the first transaction and the logical start time is less than or equal to the logical commit time.

[0323] In one possible embodiment, based on the configuration of the device of FIG. 6, the device further includes an acquisition determination module: The acquisition determination module is used to, when the parallel consistency level is causal repeatable read, acquire a result transaction that has a causal relationship with the target transaction and is caused by the target transaction, update the logical start time of the result transaction, and make the logical start time of the updated result transaction greater than the logical commit time of the target transaction to determine that it matches the parallel consistency level.

[0324] In one possible embodiment, based on the configuration of the device of FIG. 6, the device further includes an acquisition determination module: The acquisition determination module is used to determine whether the parallel consistency level matches the parallel consistency level if the parallel consistency level is repeatable read, read committed, or read uncommitted read / write.

[0325] All the above optional technical solutions can be adopted in any combination to form optional embodiments of the present disclosure, and will not be described one by one here.

[0326] It is necessary to explain that the transaction processing device provided by the above embodiment is merely described by exemplifying the division of each of the above functional modules when processing a transaction, but in actual application, the above functions can be distributed to different functional modules to be completed as necessary, that is, the internal structure of the computer device can be divided into different functional modules to complete all or part of the functions described above. In addition, the transaction processing device provided by the above embodiment belongs to the same idea as the embodiment of the transaction processing method, and the specific realization process thereof can be referred to the embodiment of the transaction processing method, so that it will not be described again here.

[0327] 7 is a structural schematic diagram of a computer device provided by an embodiment of the present application. Referring to FIG. 7, the computer device is taken as a terminal 700 for illustration. The device types of the terminal 700 may include a smart phone, a tablet computer, an MP3 player (Moving Picture Experts Group Audio Layer III, MPEG Audio Layer 3), an MP4 player (Moving Picture Experts Group Audio Layer IV, MPEG Audio Layer 4), a notebook computer or a desktop computer. The terminal 700 may also be referred to as a user device, a portable terminal, a laptop terminal, a desktop terminal, or other names.

[0328] Typically, the terminal 700 includes a processor 701 and a memory 702 .

[0329] Optionally, the processor 701 includes one or more processing cores, such as a 4-core processor, an 8-core processor, etc. Optionally, the processor 701 is implemented using at least one of the following hardware formats: DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). In some embodiments, the processor 701 includes a main processor and a coprocessor, the main processor is a processor used to process data in a wake-up state, also referred to as a CPU (Central Processing Unit), and the coprocessor is a low-power processor used to process data in a standby state. In some embodiments, the processor 701 is integrated with a GPU (Graphics Processing Unit), which is used to render and draw content that needs to be displayed on a display screen. In some embodiments, the processor 701 further includes an AI (Artificial Intelligence) processor, which is used to process computational operations related to machine learning.

[0330] In some embodiments, memory 702 includes one or more computer readable storage media, and optionally the computer readable storage media is non-transitory. Optionally, memory 702 further includes high speed random access memory, and non-volatile memory, such as one or more magnetic disk storage devices, flash storage devices, etc. In some embodiments, the non-transitory computer readable storage media in memory 702 is used to store at least one program code, and the at least one program code is used to execute by processor 701 to implement the transaction processing method provided by the embodiments herein.

[0331] In some embodiments, terminal 700 includes a selectable display screen 703 .

[0332] The display screen 703 is used to display a UI (User Interface). Optionally, the UI includes graphics, text, icons, videos, and any combination thereof. If the display screen 703 is a touch display screen, the display screen 703 is further capable of collecting touch signals on or above the surface of the display screen 703. The touch signals can be input as control signals to the processor 701 for processing. Optionally, the display screen 703 is further used to provide virtual buttons and / or virtual keyboards (also referred to as soft buttons and / or soft keyboards). In some embodiments, the display screen 703 is one and is located on the front panel of the terminal 700, in other embodiments, the display screen 703 is at least two and is located on different surfaces of the terminal 700 or has a folding design, and in still other embodiments, the display screen 703 is a flexible display screen and is located on a curved surface or a folding surface of the terminal 700. Optionally, the display screen 703 is located as a non-rectangular irregular shape, i.e., an irregular screen. Optionally, the display screen 703 is manufactured using materials such as LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode), etc.

[0333] As one skilled in the art will appreciate, the structure shown in FIG. 7 does not constitute a limitation on terminal 700, which may include more or fewer components than shown, or may combine certain components, or may employ different components in its configuration.

[0334] 8 is a structural schematic diagram of a computer device provided by an embodiment of the present application, and the computer device 800 may have a relatively large difference due to different configurations or performances. The computer device 800 includes one or more processors (Central Processing Units, CPU) 801 and one or more memories 802, where at least one computer program is stored in the memory 802, and the at least one computer program is loaded and executed by the one or more processors 801 to realize the transaction processing method provided by each of the above embodiments. Optionally, the computer device 800 further includes components such as a wired or wireless network interface, a keyboard, and an input / output interface, which facilitates input and output, and the computer device 800 further includes other components used to realize the functions of the device, which will not be described again here.

[0335] In an exemplary embodiment, a computer-readable storage medium is further provided, such as a memory containing at least one computer program, which can be executed by a processor in a terminal to complete the transaction processing method in each of the above embodiments. For example, the computer-readable storage medium includes a ROM (Read-Only Memory), a RAM (Random-Access Memory), a CD-ROM (Compact Disc Read-Only Memory), a magnetic tape, a floppy disk, and an optical data storage device, etc.

[0336] In an exemplary embodiment, a computer program product or computer program is further provided, including one or more program codes, the one or more program codes being stored in a computer-readable storage medium, one or more processors of a computing device can read the one or more program codes from the computer-readable storage medium, and the one or more processors can execute the one or more program codes to cause the computing device to execute and complete the transaction processing method in the above embodiment.

[0337] As can be understood by those skilled in the art, the realization of all or part of the steps of the above embodiments can be completed by hardware, or can be completed by issuing instructions to related hardware by a program, optionally the program can be stored in a kind of computer-readable storage medium, optionally the above mentioned storage medium can be a read-only memory, a magnetic disk or an optical disk, etc.

[0338] The above contents are merely optional embodiments of the present application, and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should be included within the scope of protection of the present application. [Explanation of symbols]

[0339] 101 Gateway Server 102 Global Timestamp Generation Cluster 103 Distributed Memory Cluster 201 TP Cluster 202 AP Cluster 203 Distributed File System 601 Acquisition Module 602 Decision Module 603 Update Module 604 Commit Module 700 terminals 701 Processor 702 Memory 703 Display Screen 800 Computer Equipment 801 Processor 802 Memory

Claims

1. 1. A method of transaction processing implemented by a computing device, the method comprising: obtaining a read set and a write set of the target transaction in response to read and write operations of the target transaction; determining a logical start time and a logical commit time of the target transaction in response to a verification command for the target transaction; updating the logical start time based on the write set if a relationship between the logical start time and the logical commit time matches a condition corresponding to a concurrent consistency level of the target transaction; committing the target transaction if the updated logical start time is equal to or earlier than the logical commit time.

2. The step of updating the logical start time based on the write set when the relationship matches the condition, further comprising: obtaining write target transaction information for each data item in the write set, the write target transaction information being used to identify transactions currently modifying the data item; updating the logical start time when each of the pieces of transaction information to be written is empty; and rolling back the target transaction if any of the transaction information to be written is not empty.

3. When each of the pieces of transaction information to be written is empty, the step of updating the logical start time includes: acquiring transaction information of the write target as a transaction identifier of the target transaction; updating the logical start time so that the updated logical start time is later than a maximum read transaction timestamp for the data item, the maximum read transaction timestamp being used to indicate a maximum logical commit time of transactions which have read the data item; updating the logical start time based on a set of active transactions if the relationship matches the condition, the set of active transactions being used to identify transactions that have begun execution but have not yet completed commit; and rolling back the target transaction if the relationship does not match the condition.

4. the active transaction set includes a first transaction set and a second transaction set, the first transaction set being used to identify transactions that are in a committing state or a verify passing state, and the second transaction set being used to identify transactions that are in a running state; updating the logical start time based on a set of active transactions if the relationship matches the condition, updating the logical start time so that the updated logical start time is later than a maximum logical commit time in the first transaction set; if the updated logical start time is equal to or earlier than the logical commit time, updating the logical commit time of the transaction in the second transaction set so that the updated logical commit time is earlier than the updated logical start time; and rolling back the target transaction if the updated logical begin time is later than the logical commit time.

5. The method further comprises:

5. The method of claim 4, further comprising: rolling back any transaction in the second transaction set if the logical begin time of the transaction is later than the updated logical commit time of the transaction.

6. The method further comprises: obtaining a concurrent transaction for the target transaction if the concurrency consistency level is serialized; obtaining a timestamp of a latest completed transaction of a session to which the target transaction belongs, if the logical commit time of the target transaction is earlier than the logical start time of the concurrent transaction, or if the logical start time of the target transaction is later than the logical commit time of the concurrent transaction; determining that the relationship matches the condition if the logical commit time of the target transaction is equal to or greater than the timestamp of the most recent completed transaction.

7. The method further comprises: if the concurrency consistency level is strict and the target transaction is a write transaction, obtaining a concurrency write transaction for the target transaction; acquiring a concurrent read-only transaction of the concurrent write transaction if the logical commit time of the target transaction is earlier than the logical start time of the concurrent write transaction or if the logical start time of the target transaction is later than the logical commit time of the concurrent write transaction; if the logical start time of the concurrent read-only transaction is later than the logical start time of the concurrent write transaction, obtaining a timestamp of a latest completed transaction of the session to which the target transaction belongs; determining that the relationship matches the condition if the logical commit time of the target transaction is equal to or greater than the timestamp of the most recent completed transaction.

8. The method further comprises: if the concurrency consistency level is linearized and the target transaction is a write transaction, obtaining a concurrency write transaction for the target transaction; obtaining a concurrent read-only transaction for the concurrent write transaction if the target transaction and the concurrent write transaction pass serializability verification; if the logical start time of the concurrent read-only transaction is later than the logical start time of the concurrent write transaction, obtaining a timestamp of a latest completed transaction of the session to which the target transaction belongs; determining that the relationship matches the condition if the logical commit time of the target transaction is equal to or greater than the timestamp of the most recent completed transaction.

9. The method further comprises: obtaining a concurrent transaction for the target transaction if the concurrency consistency level is ordered; determining a first transaction that belongs to the same session as the target transaction if the target transaction and the concurrent transaction pass serializability verification; if the logical commit time of the target transaction is earlier than the logical start time of the first transaction, obtaining a timestamp of a most recent completed transaction of the session; determining that the relationship matches the condition if the logical commit time of the target transaction is equal to or later than the timestamp of the latest completed transaction; 2. The method of claim 1, further comprising: updating a logical start time of a resultant transaction in a causal relationship with the first transaction when the target transaction has a causal relationship with the first transaction, so that the logical start time of the updated resultant transaction is later than the logical commit time of the cause transaction.

10. The method further comprises: obtaining a concurrent transaction for the target transaction if the concurrency consistency level is serializable; determining a first transaction that belongs to the same session as the target transaction if the target transaction and the concurrent transaction pass serializability verification; determining that the relationship matches the condition if a logical commit time of the target transaction is earlier than a logical start time of the first transaction and the logical start time is on or before the logical commit time of the first transaction.

11. The method further comprises: obtaining a result transaction that has a causal relationship with and is caused by the target transaction when the concurrency consistency level is causally repeatable read; updating a logical start time of the resulting transaction such that the logical start time of the updated resulting transaction is later than the logical commit time of the target transaction; and determining that the relationship matches the condition.

12. The method further comprises:

2. The method of claim 1, further comprising determining that the relationship matches the condition if the concurrency consistency level is Repeatable Read, Read Committed, or Read Uncommitted Read / Write.

13. 1. A transaction processing apparatus, the apparatus including: an acquisition module, a decision module, an update module, and a commit module; the acquiring module is used to acquire a read set and a write set of the target transaction in response to a read / write operation of the target transaction; the determination module is adapted to determine a logical start time and a logical commit time of the target transaction in response to a verification command for the target transaction; the update module is used for updating the logical start time based on the write set when a relationship between the logical start time and the logical commit time matches a condition corresponding to a parallel consistency level of the target transaction; The commit module is used to commit the target transaction if the updated logical start time is before the logical commit time.

14. A computer device comprising one or more processors and one or more memories, wherein at least one computer program is stored in the one or more memories, and wherein the at least one computer program is loaded and executed by the one or more processors to implement the transaction processing method according to any one of claims 1 to 12.

15. A computer program which, when loaded and executed by a processor, implements the transaction processing method according to any one of claims 1 to 12.

Citation Information

Patent Citations

  • Transaction processing method and device, computer equipment and storage medium

    CN111338766A

  • Transaction processing method and device, computer equipment and storage medium

    CN111736964A