CN115185957A - Lightweight real-time memory database transaction concurrency control method and device - Google Patents

Lightweight real-time memory database transaction concurrency control method and device Download PDF

Info

Publication number
CN115185957A
CN115185957A CN202210621956.8A CN202210621956A CN115185957A CN 115185957 A CN115185957 A CN 115185957A CN 202210621956 A CN202210621956 A CN 202210621956A CN 115185957 A CN115185957 A CN 115185957A
Authority
CN
China
Prior art keywords
transaction
processed
data
processed transaction
cluster
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210621956.8A
Other languages
Chinese (zh)
Inventor
王鹏
郭屾
白帅涛
张冀川
林佳颖
张明宇
张治明
谭传玉
秦四军
孙浩洋
姚志国
张永芳
吕琦
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
State Grid Corp of China SGCC
China Electric Power Research Institute Co Ltd CEPRI
State Grid Shandong Electric Power Co Ltd
Original Assignee
State Grid Corp of China SGCC
China Electric Power Research Institute Co Ltd CEPRI
State Grid Shandong Electric Power Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by State Grid Corp of China SGCC, China Electric Power Research Institute Co Ltd CEPRI, State Grid Shandong Electric Power Co Ltd filed Critical State Grid Corp of China SGCC
Priority to CN202210621956.8A priority Critical patent/CN115185957A/en
Publication of CN115185957A publication Critical patent/CN115185957A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/466Transaction processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/526Mutual exclusion algorithms

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to the technical field of flexible direct current power transmission, and particularly provides a lightweight real-time memory database transaction concurrency control method and device, wherein the method comprises the following steps: s101, classifying the to-be-processed transaction through cluster analysis, and determining a cluster to which the to-be-processed transaction belongs; s102, acquiring a corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction calling data, and executing the step S103 under the condition that the acquisition state is successful; s103, performing conflict verification on the to-be-processed transaction, if a conflict exists, stopping the to-be-processed transaction, and if not, executing the to-be-processed transaction. The technical scheme provided by the invention aims at the requirement of high-efficiency data access of the Internet of things and improves the transaction execution performance of the real-time memory database.

Description

Lightweight real-time memory database transaction concurrency control method and device
Technical Field
The invention relates to the technical field of flexible direct current power transmission, in particular to a lightweight real-time memory database transaction concurrency control method and device.
Background
With the popularity of computer applications in recent years, disk-based databases (DRDBs) have been developed sufficiently for widespread use in business and transactional applications. In long-term use, some of the problems of disk-type databases are gradually emerging, and the use of disk-type databases for applications with high real-time requirements is not satisfactory. The main reason for these problems is that under the condition of relatively high real-time property, a large number of transactions are established in the same time period, and the transactions interact with the disk, so that a great number of input and output operations are performed. However, the buffer management related to the transaction execution operation has unpredictability, and the real-time performance of the management is not very strong, and the same problems exist when the events such as page violations and the like are executed, and the problems can cause the transaction not to have very good real-time performance and predictability. With the continuous development of modern science and technology, the integration level of a Memory chip is continuously improved, the Main Memory capacity of a computer is remarkably improved, the cost of the current computer system is continuously reduced while the current computer system has very large Main Memory capacity, on the basis of the conditions, the data operation in a Database is put into a Memory to be carried out, and the realization value is achieved, and a Memory Database (MMDB) is generated along the way. Meanwhile, with the deep integration of industry and information technology, the Internet of things becomes a novel economic industry and application ecology, and is an economic and technical reform for promoting industrial upgrading and transformation by taking the Internet information technology and high-tech intelligent technology as means. The Internet of things can not be separated from data, in the industrial automatic production process, the data generated, collected and processed by industrial equipment is far larger than the data volume processed by a computer, the data type presents the non-structural characteristic, and the high-speed operation of a production line requires strict real-time performance. And the requirements of storage, processing and analysis of mass data generated in the industrial production control process, high timeliness of the data and the like cannot be met only by relying on the traditional relational memory database. Real-time database (RTDB) technology is therefore used in the industry as a new branch of database system development. RTDB is a new database created by combining real-time processing technology and database technology. The real-time database transaction fusion method integrates real-time tasks and traditional database transactions, and takes real-time as the remarkable characteristic, wherein the real-time characteristic comprises data real-time property and transaction real-time property. Most RTDBs still suffer from a deficiency in the efficiency of transaction processing, which makes the use of the relevant RTDB products somewhat limited. Under the background of the continuous and vigorous development of the internet of things, the RTD is also gradually developed, but most of the RTD only supports the storage, processing and analysis of data values with few data types, and cannot fully meet the requirements of the existing industrial process control system, such as various data types, complex sources, high updating speed and the like. Therefore, the business requirements of efficient data acquisition, access and the like of the Internet of things are met, the concurrency control method for the transactions of the lightweight real-time memory database is realized by optimizing the transaction of the memory database in the aspect of high concurrency processing efficiency, the reliability and the efficiency of the database are improved, and the method has a wide prospect.
At present, in the patent of "implementation method and apparatus for memory database lock and computer readable storage medium" with patent number CN109376165a in the prior art, applicable to the technical field of databases, there are provided implementation method and apparatus for memory database lock and computer readable storage medium, the method includes: receiving a transaction processing request aiming at a memory database; the transaction processing request comprises information of a transaction to be processed; acquiring a value of a lock zone of an element corresponding to the transaction in the memory database based on the information of the transaction, and determining the lock holding condition of the element according to the value of the lock zone; wherein the elements include index total nodes and row data; based on the condition of the holding lock and the type of operation the transaction contains for the element, locking the element with a read lock or a write lock; based on the method, high-concurrency transaction processing in the memory database can be realized, and the method is suitable for single-stroke delay and overall throughput; the scheme is relatively simple to implement, but the management relation among all the transactions is not considered, the granularity of the added lock is too large, and the concurrency is easily reduced.
Disclosure of Invention
In order to overcome the defects, the invention provides a lightweight real-time memory database transaction concurrency control method and device.
In a first aspect, a method for controlling concurrence of transactions in a lightweight real-time memory database is provided, where the method for controlling concurrence of transactions in a lightweight real-time memory database includes:
s101, classifying the to-be-processed transaction through cluster analysis, and determining a cluster to which the to-be-processed transaction belongs;
s102, acquiring a corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction calling data, and executing the step S103 under the condition that the acquisition state is successful;
s103, performing conflict verification on the to-be-processed transaction, if a conflict exists, stopping the to-be-processed transaction, and if not, executing the to-be-processed transaction.
Preferably, the step S101 includes:
acquiring a to-be-processed transaction, and extracting a working set corresponding to the to-be-processed transaction;
determining the hash value of the working set by utilizing a MinHash algorithm;
searching in a pre-constructed hash table based on the hash value of the working set to obtain a target cluster;
and taking the target cluster as the cluster to which the to-be-processed transaction belongs.
Further, the obtaining the to-be-processed transaction and extracting the working set corresponding to the to-be-processed transaction includes:
performing static pre-compilation on the transaction to be processed;
extracting at least one task and a data record required to be accessed by each task in the statically precompiled to-be-processed transaction;
and generating a working set corresponding to the to-be-processed transaction based on all the tasks and the data records required to be accessed by each task.
Preferably, the acquiring a transaction lock corresponding to the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction call data includes:
judging whether the data corresponding to the to-be-processed transaction is locked or not;
and if the data corresponding to the to-be-processed transaction is not locked, acquiring a transaction lock corresponding to the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction call data, and marking the acquisition state as successful.
Further, after the step of determining whether the data corresponding to the to-be-processed transaction is locked, the method further includes:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if so, the acquisition status is marked as failed.
Further, after the step of determining whether the data corresponding to the to-be-processed transaction is locked, the method further includes:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if not, acquiring the corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and the data lock of the to-be-processed transaction calling data, and marking the acquisition state as successful.
Preferably, in step S103, the conflict verification is a conflict verification in an optimistic concurrency control algorithm.
In a second aspect, a lightweight real-time memory database transaction concurrency control device is provided, where the lightweight real-time memory database transaction concurrency control device includes:
the classification module is used for classifying the to-be-processed transaction through cluster analysis and determining a cluster to which the to-be-processed transaction belongs;
the acquisition module is used for acquiring a corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction calling data, and entering the verification module under the condition that the acquisition state is successful;
and the verification module is used for performing conflict verification on the to-be-processed transaction, if the conflict exists, the to-be-processed transaction is stopped, and otherwise, the to-be-processed transaction is executed.
Preferably, the classification module is specifically configured to:
acquiring a to-be-processed transaction, and extracting a working set corresponding to the to-be-processed transaction;
determining the hash value of the working set by utilizing a MinHash algorithm;
searching in a pre-constructed hash table based on the hash value of the working set to obtain a target cluster;
and taking the target cluster as the cluster to which the to-be-processed transaction belongs.
Further, the obtaining the to-be-processed transaction and extracting the working set corresponding to the to-be-processed transaction includes:
performing static pre-compilation on the transaction to be processed;
extracting at least one task and a data record required to be accessed by each task in the statically precompiled to-be-processed transaction;
and generating a working set corresponding to the to-be-processed transaction based on all the tasks and the data records required to be accessed by each task.
Preferably, the obtaining module is specifically configured to:
judging whether the data corresponding to the to-be-processed transaction is locked or not;
and if the data corresponding to the to-be-processed transaction is not locked, acquiring a transaction lock corresponding to the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction call data, and marking the acquisition state as successful.
Further, after the step of determining, by the obtaining module, whether the data corresponding to the to-be-processed transaction is locked, the apparatus further includes:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if so, the acquisition status is marked as failed.
Further, after the step of determining, by the obtaining module, whether the data corresponding to the to-be-processed transaction is locked, the apparatus further includes:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if not, acquiring the corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and the data lock of the to-be-processed transaction call data, and marking the acquisition state as successful.
Preferably, in the verification module, the conflict verification is a conflict verification in an optimistic concurrency control algorithm.
In a third aspect, a lightweight real-time memory database is provided, where the lightweight real-time memory database at least includes the lightweight real-time memory database transaction concurrency control device.
In a fourth aspect, there is provided a computer device comprising: one or more processors;
the processor to store one or more programs;
when the one or more programs are executed by the one or more processors, the method for controlling the transaction concurrency of the lightweight real-time memory database is realized.
In a fifth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed, the method for controlling transaction concurrency of a lightweight real-time memory database is implemented.
One or more technical schemes of the invention at least have one or more of the following beneficial effects:
the invention provides a lightweight real-time memory database transaction concurrency control method and a device, comprising the following steps: s101, classifying the to-be-processed transaction through cluster analysis, and determining a cluster to which the to-be-processed transaction belongs; s102, acquiring a corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction calling data, and executing the step S103 under the condition that the acquisition state is successful; s103, performing conflict verification on the to-be-processed transaction, if a conflict exists, stopping the to-be-processed transaction, and if not, executing the to-be-processed transaction. According to the scheme, a transaction clustering analysis process is designed firstly, powerful support is provided for accurate isolation partitioning of database transactions, the probability of conflict among transactions can be effectively reduced, and the success rate of transaction execution is improved. Secondly, a transaction lock mechanism based on cluster locking is provided, the granularity of common transaction locks is optimized, the waiting time required by transaction contention locks is reduced, the transaction execution efficiency is improved while the data consistency is ensured, and finally, on the basis of the algorithm and the mechanism, a concurrency control mechanism combined with an optimistic control algorithm is provided, the transaction concurrency control capability of a real-time memory database is improved, and the efficient and stable operation of the memory database is ensured. The effective application of the concurrency control method in the real-time memory database of the Internet of things is described through a specific application example, and the operation efficiency and reliability of the production system of the Internet of things are effectively improved.
Drawings
Fig. 1 is a flowchart illustrating main steps of a lightweight real-time memory database transaction concurrency control method according to an embodiment of the present invention;
FIG. 2 is a flow chart of transaction clustering based on locality sensitive hashing according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating a lock acquisition process and a lock release process of a cluster locking based transaction lock mechanism according to an embodiment of the present invention;
FIG. 4 is a process diagram of a concurrency control technique based on transaction clustering according to an embodiment of the present invention;
fig. 5 is a main structural block diagram of a lightweight real-time memory database transaction concurrency control device according to an embodiment of the present invention.
Detailed Description
The following provides a more detailed description of embodiments of the present invention, with reference to the accompanying drawings.
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Example 1
Referring to fig. 1, fig. 1 is a flow chart illustrating main steps of a lightweight real-time memory database transaction concurrency control method according to an embodiment of the present invention. As shown in fig. 1, the method for controlling transaction concurrency of a lightweight real-time memory database according to the embodiment of the present invention mainly includes the following steps:
s101, classifying the to-be-processed transaction through cluster analysis, and determining a cluster to which the to-be-processed transaction belongs;
s102, acquiring a corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction calling data, and executing the step S103 under the condition that the acquisition state is successful;
s103, performing conflict verification on the to-be-processed transaction, if a conflict exists, stopping the to-be-processed transaction, and if not, executing the to-be-processed transaction.
In this embodiment, in order to establish an optimal isolation mechanism for any given transaction and reduce the probability of a collision occurring during the execution of a real-time database transaction, a transaction clustering algorithm based on locality sensitive hashing is proposed, in the method, the similarity of the transactions is measured by using the locality sensitive hashing algorithm, and a hash table mechanism is combined to cluster and partition a transaction set in advance, so that the collision between the transactions can be significantly reduced under a high contention load condition, the transaction abort is avoided, and the transaction execution performance is improved, specifically, step S101 includes:
acquiring a to-be-processed transaction, and extracting a working set corresponding to the to-be-processed transaction;
determining a hash value of the working set by utilizing a MinHash algorithm;
searching in a pre-constructed hash table based on the hash value of the working set to obtain a target cluster;
and taking the target cluster as the cluster to which the to-be-processed transaction belongs. In one embodiment, the obtaining the to-be-processed transaction and extracting the working set corresponding to the to-be-processed transaction includes:
performing static pre-compilation on the transaction to be processed;
extracting at least one task and a data record required to be accessed by each task in the statically precompiled to-be-processed transaction;
and generating a working set corresponding to the to-be-processed transaction based on all the tasks and the data records required to be accessed by each task.
In a preferred embodiment, the application in the real-time memory database contains rich data, transaction semantics and complex structures, has many different characteristics from the traditional application, and must consider the conflict of data and resources and the interdependency between transactions when processing the transactions. If the real-time database can consciously cluster and isolate the affairs according to the possibility of mutual conflict of the two affairs, support can be provided for reasonably arranging an affair execution sequence and a management mode, and the success rate of affair execution is improved, so that the execution efficiency of the system is improved. Since the probability of two transactions colliding is higher if the two transactions access more data sets together, the task of clustering transactions can be completed through the Jaccard similarity between the working sets of the two transactions, where the working set of the transactions is defined as the set of all data records accessed by the transaction, and the MinHash algorithm can compare two hash values to reveal the similarity of the sets a and B, and the hash values of two data with too high similarity are generally consistent, and the flow is shown in fig. 2, and specifically includes:
(1) Before the transaction reaches the real-time memory database processing module, static pre-compiling is carried out on the transaction, all task sets in the transaction and data records required to be accessed by all tasks are extracted, and all working sets of the transaction are finally generated.
(2) The method comprises the steps of determining the hash value of a transaction working set by utilizing a MinHash algorithm, firstly forming a matrix by using an extracted characteristic value vector and the working set, generating a signature matrix by operating the characteristic value vector matrix through a plurality of hash functions, then randomly transforming and arranging row numbers in the matrix, taking out the first 1 in a row corresponding to the working set, and selecting a plurality of characteristic values to represent the working set through a plurality of times of Hash random transformations, thereby realizing dimension reduction on the working set, and compressing the high-dimensional working set into 16 integers to represent the minimum 16-bit hash value of the work.
(3) A cluster is searched for the incoming transaction by utilizing a hash table, the hash table is realized by using an associated container, and any input key value can be quickly positioned to one position in the hash table to access a data record, namely the cluster information of the transaction is obtained.
(4) And adding the affiliated cluster information for the incoming transaction, completing the isolation of different types and realizing a transaction clustering task.
Further, in this embodiment, for the problem that the traditional real-time memory database transaction lock has a low concurrency due to an excessively large granularity, a transaction lock mechanism based on cluster locking is provided, which automatically isolates a current transaction from other transactions in the same cluster, and a suitable transaction lock table is designed and implemented based on a two-segment lock structure, adds a lock with an optimal granularity to the transaction, and promotes the concurrency of the real-time memory database under the condition that normal execution of the transaction is guaranteed, in step S102, the transaction lock corresponding to the transaction to be processed in the cluster to which the transaction belongs and the data lock for calling data of the transaction to be processed are obtained, including:
judging whether the data corresponding to the to-be-processed transaction is locked or not;
and if the data corresponding to the to-be-processed transaction is not locked, acquiring a transaction lock corresponding to the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction call data, and marking the acquisition state as successful.
After the step of determining whether the data corresponding to the to-be-processed transaction is locked, the method further includes:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if so, the acquisition status is marked as failed.
After the step of determining whether the data corresponding to the to-be-processed transaction is locked, the method further includes:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if not, acquiring the corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and the data lock of the to-be-processed transaction call data, and marking the acquisition state as successful.
In one embodiment, a transaction is a program execution unit that queries and updates various data in a real-time memory database, and is a basic unit of concurrency control. When concurrent transactions are processed, concurrency control based on locks is often adopted, and in a management mechanism based on locks, the locks are divided into row locks, table locks, database-level locks and the like according to different granularity of the locks. At present, the locking of the memory database is complex to realize when processing concurrent transactions, and cannot meet the application field with strict requirements on time delay performance. The database level lock or table lock is added to the memory database, and although the implementation is simpler when concurrent transactions are processed, the concurrency is not high, and the throughput rate of the system is not high. Therefore, on the basis of transaction completion clustering, a simple, novel and high-concurrency transaction lock mechanism based on cluster groups is provided.
The lock table design of the transaction lock mechanism is similar to a 2PL lock table, the first layer is used for indicating whether the data record is locked by the related transaction, and the second layer is used for indicating the information of each transaction cluster. By searching the lock table, the current incoming transaction can be directly informed whether there are other transactions belonging to the same cluster and holding the lock. If not, the lock may be granted to the requesting transaction. Otherwise, if and only if the requested locking pattern meets current specifications, then locking is granted, and the lock compatibility matrix of the mechanism is identical to the lock compatibility matrix of the 2PL algorithm. The lock acquisition process and the lock release process of the mechanism are shown in fig. 3, and specifically include:
(1) Firstly, acquiring a working set of an input memory database real-time transaction, and dividing the transaction into a cluster to which the transaction belongs by using the transaction clustering algorithm based on the locality sensitive hashing.
(2) Second, a transaction begins executing and applies for acquiring a related data lock and determines whether the data is locked.
(3) And if the data is locked, jumping to the step (4), continuously judging whether the data lock is acquired by the transaction of the same cluster, otherwise, successfully acquiring the data lock and performing data operation by the transaction, and releasing the data lock and the cluster lock after the transaction is executed.
(4) If the data lock is acquired by a transaction of the same cluster, i.e., the transaction cluster is locked, the transaction fails to acquire the data lock, and the transaction starts to queue for re-execution. Otherwise, the transaction successfully acquires the data lock and performs data operation, and after the transaction is executed, the data lock and the cluster lock are released.
In this embodiment, aiming at the problem that the execution latency of a transaction is long due to serious contention of a transaction lock in a pessimistic algorithm, and the number of times of repeated execution is large due to high transaction abort rate in an optimistic algorithm, a concurrency control mechanism combining the pessimistic and optimistic control algorithms is provided, so that the performance bottleneck of the two algorithms is alleviated, the pessimistic control algorithm and the transaction lock mechanism are used for transactions in the same cluster, the optimistic control algorithm is used for transactions among different sets of rights, the latency and the abort rate required by the execution of the transaction can be effectively reduced, the efficiency and the practicability of concurrency control of the real-time memory database are improved, and in step S103, the conflict verification is conflict verification in the optimistic concurrency control algorithm.
In one embodiment, concurrency control is a mechanism provided by a database system, which allows multiple transactions to be executed simultaneously in the system, and meanwhile, data consistency is maintained, thereby improving reliability and efficiency of the database. Currently, the mainstream concurrency control algorithms mainly include two types: pessimistic algorithms and optimistic algorithms. Pessimistic algorithms require a transaction to hold a lock throughout its lifecycle, whereas optimistic algorithms only acquire locks when a transaction commits. Thus, the lock holding time for pessimistic algorithms is typically much longer than for optimistic algorithms, and thus lock contention will be more severe. Research has shown that lock contention is a major performance bottleneck for pessimistic algorithms because a transaction may need to wait long to perform any operations during the contention for a lock. In the optimistic algorithm, the reason for transaction abort is mainly that validation fails when a transaction commits, and for a highly competitive workload, almost all transactions are aborted by the optimistic control algorithm, so that a high abort rate becomes the optimistic control algorithm. Therefore, on the basis of the transaction clustering algorithm based on locality sensitive hashing and the transaction lock mechanism based on cluster locking, a concurrency control mechanism combining pessimistic and optimistic algorithms is provided, the two algorithms are organically fused to inherit the advantages of the two algorithms, and the defects of the two algorithms are overcome, wherein the concurrency control technology based on transaction clustering mainly comprises three steps: the process of transaction clustering, applying for acquiring a data lock in a cluster, and conflict validation is shown in fig. 4, and specifically includes:
(1) Firstly, the transaction clustering algorithm based on locality sensitive hashing is utilized to complete clustering analysis on input transactions.
(2) Secondly, the above-mentioned transaction lock mechanism based on cluster locking is used to control the data operation of a transaction, the transaction applies for acquiring the data lock of the cluster before accessing any data, when the rest transactions in the cluster occupy the data lock, the access request will be blocked until the lock is authorized.
(3) Finally, even if the same transaction in the same cluster uses lock isolation, access to transactions from different clusters is not controlled, which may result in data inconsistencies, the mechanism requires any transaction to perform conflict validation in optimistic concurrency control at commit, and if there is a conflict, the transaction must be blocked.
Example 2
Based on the same inventive concept, the present invention further provides a lightweight real-time memory database transaction concurrency control device, as shown in fig. 5, the lightweight real-time memory database transaction concurrency control device includes:
the classification module is used for classifying the to-be-processed transaction through cluster analysis and determining a cluster to which the to-be-processed transaction belongs;
the acquisition module is used for acquiring a corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction calling data, and entering the verification module under the condition that the acquisition state is successful;
and the verification module is used for performing conflict verification on the to-be-processed transaction, if the conflict exists, the to-be-processed transaction is stopped, and otherwise, the to-be-processed transaction is executed.
Preferably, the classification module is specifically configured to:
acquiring a transaction to be processed, and extracting a working set corresponding to the transaction to be processed;
determining the hash value of the working set by utilizing a MinHash algorithm;
searching in a pre-constructed hash table based on the hash value of the working set to obtain a target cluster;
and taking the target cluster as the cluster to which the to-be-processed transaction belongs.
Further, the obtaining the transaction to be processed and extracting the working set corresponding to the transaction to be processed includes:
performing static pre-compilation on the transaction to be processed;
extracting at least one task and a data record required to be accessed by each task in the statically precompiled to-be-processed transaction;
and generating a working set corresponding to the to-be-processed transaction based on all the tasks and the data records required to be accessed by each task.
Preferably, the obtaining module is specifically configured to:
judging whether the data corresponding to the to-be-processed transaction is locked or not;
and if the data corresponding to the to-be-processed transaction is not locked, acquiring a transaction lock corresponding to the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction call data, and marking the acquisition state as successful.
Further, after the step of determining, by the obtaining module, whether the data corresponding to the to-be-processed transaction is locked, the apparatus further includes:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if so, the acquisition status is marked as failed.
Further, after the step of determining, by the obtaining module, whether the data corresponding to the to-be-processed transaction is locked, the apparatus further includes:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if not, acquiring the corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and the data lock of the to-be-processed transaction call data, and marking the acquisition state as successful.
Preferably, in the verification module, the conflict verification is a conflict verification in an optimistic concurrency control algorithm.
Example 3
Based on the same inventive concept, the invention also provides a lightweight real-time memory database, which at least comprises the lightweight real-time memory database transaction concurrency control device.
Example 4
Based on the same inventive concept, the present invention also provides a computer apparatus comprising a processor and a memory, the memory being configured to store a computer program comprising program instructions, the processor being configured to execute the program instructions stored by the computer storage medium. The Processor may be a Central Processing Unit (CPU), or may be other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable gate array (FPGA) or other Programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc., which is a computing core and a control core of the terminal, and is specifically adapted to load and execute one or more instructions in a computer storage medium so as to implement a corresponding method flow or a corresponding function, so as to implement the steps of the lightweight real-time memory database transaction concurrence control method in the above embodiments.
Example 5
Based on the same inventive concept, the present invention further provides a storage medium, in particular a computer readable storage medium (Memory), which is a Memory device in a computer device and is used for storing programs and data. It is understood that the computer readable storage medium herein can include both built-in storage media in the computer device and, of course, extended storage media supported by the computer device. The computer-readable storage medium provides a storage space storing an operating system of the terminal. Also, one or more instructions, which may be one or more computer programs (including program code), are stored in the memory space and are adapted to be loaded and executed by the processor. It should be noted that the computer readable storage medium may be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as at least one disk memory. One or more instructions stored in the computer-readable storage medium may be loaded and executed by the processor to implement the steps of the lightweight real-time memory database transaction concurrency control method in the foregoing embodiments.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting the same, and although the present invention is described in detail with reference to the above embodiments, those of ordinary skill in the art should understand that: modifications and equivalents may be made to the embodiments of the invention without departing from the spirit and scope of the invention, which is to be covered by the claims.

Claims (17)

1. A lightweight real-time memory database transaction concurrency control method is characterized by comprising the following steps:
s101, classifying the to-be-processed transaction through cluster analysis, and determining a cluster to which the to-be-processed transaction belongs;
s102, acquiring a corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction calling data, and executing the step S103 under the condition that the acquisition state is successful;
s103, performing conflict verification on the to-be-processed transaction, if a conflict exists, stopping the to-be-processed transaction, and if not, executing the to-be-processed transaction.
2. The method of claim 1, wherein the step S101 comprises:
acquiring a to-be-processed transaction, and extracting a working set corresponding to the to-be-processed transaction;
determining the hash value of the working set by utilizing a MinHash algorithm;
searching in a pre-constructed hash table based on the hash value of the working set to obtain a target cluster;
and taking the target cluster as the cluster to which the to-be-processed transaction belongs.
3. The method of claim 2, wherein the obtaining the pending transaction and extracting the working set corresponding to the pending transaction comprises:
performing static pre-compilation on the transaction to be processed;
extracting at least one task and a data record required to be accessed by each task in the statically precompiled to-be-processed transaction;
and generating a working set corresponding to the to-be-processed transaction based on all the tasks and the data records required to be accessed by each task.
4. The method of claim 1, wherein the acquiring the transaction lock corresponding to the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and the data lock of the to-be-processed transaction call data comprises:
judging whether the data corresponding to the transaction to be processed is locked or not;
and if the data corresponding to the to-be-processed transaction is not locked, acquiring a transaction lock corresponding to the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction call data, and marking the acquisition state as successful.
5. The method of claim 4, wherein after the step of determining whether the data corresponding to the pending transaction is locked, the method further comprises:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if so, the acquisition status is marked as failed.
6. The method of claim 4, wherein after the step of determining whether the data corresponding to the pending transaction is locked, the method further comprises:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if not, acquiring the corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and the data lock of the to-be-processed transaction call data, and marking the acquisition state as successful.
7. The method according to claim 1, wherein in the step S103, the conflict verification is a conflict verification in an optimistic concurrency control algorithm.
8. A lightweight real-time memory database transaction concurrency control apparatus, the apparatus comprising:
the classification module is used for classifying the to-be-processed transaction through cluster analysis and determining a cluster to which the to-be-processed transaction belongs;
the acquisition module is used for acquiring a corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction calling data, and entering the verification module under the condition that the acquisition state is successful;
and the verification module is used for performing conflict verification on the to-be-processed transaction, if the conflict exists, the to-be-processed transaction is stopped, and otherwise, the to-be-processed transaction is executed.
9. The apparatus of claim 8, wherein the classification module is specifically configured to:
acquiring a to-be-processed transaction, and extracting a working set corresponding to the to-be-processed transaction;
determining a hash value of the working set by utilizing a MinHash algorithm;
searching in a pre-constructed hash table based on the hash value of the working set to obtain a target cluster;
and taking the target cluster as the cluster to which the to-be-processed transaction belongs.
10. The apparatus of claim 9, wherein the obtaining the pending transaction and extracting the working set corresponding to the pending transaction comprises:
performing static pre-compilation on the transaction to be processed;
extracting at least one task and a data record required to be accessed by each task in the statically precompiled to-be-processed transaction;
and generating a working set corresponding to the to-be-processed transaction based on all the tasks and the data records required to be accessed by each task.
11. The apparatus of claim 8, wherein the acquisition module is specifically configured to:
judging whether the data corresponding to the to-be-processed transaction is locked or not;
and if the data corresponding to the to-be-processed transaction is not locked, acquiring a transaction lock corresponding to the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and a data lock of the to-be-processed transaction call data, and marking the acquisition state as successful.
12. The apparatus as claimed in claim 11, wherein after the step of determining whether the data corresponding to the transaction to be processed is locked by the obtaining module, the apparatus further comprises:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if so, the acquisition status is marked as failed.
13. The apparatus as claimed in claim 11, wherein after the step of determining whether the data corresponding to the transaction to be processed is locked by the obtaining module, the apparatus further comprises:
if the data corresponding to the to-be-processed transaction is locked, judging whether the locked data is acquired by the similar transaction of the cluster to which the to-be-processed transaction belongs;
if not, acquiring the corresponding transaction lock of the to-be-processed transaction in the cluster to which the to-be-processed transaction belongs and the data lock of the to-be-processed transaction call data, and marking the acquisition state as successful.
14. The apparatus of claim 8, wherein in the verification module, the conflicting verification is a conflicting verification in an optimistic concurrency control algorithm.
15. A lightweight real-time memory database, characterized in that the lightweight real-time memory database comprises at least the lightweight real-time memory database transaction concurrency control device according to any one of claims 8 to 14.
16. A computer device, comprising: one or more processors;
the processor to store one or more programs;
the one or more programs, when executed by the one or more processors, implement the lightweight real-time memory database transaction concurrency control method of any of claims 1-7.
17. A computer-readable storage medium having stored thereon a computer program which, when executed, implements a lightweight real-time memory database transaction concurrency control method as claimed in any one of claims 1 to 7.
CN202210621956.8A 2022-06-01 2022-06-01 Lightweight real-time memory database transaction concurrency control method and device Pending CN115185957A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210621956.8A CN115185957A (en) 2022-06-01 2022-06-01 Lightweight real-time memory database transaction concurrency control method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210621956.8A CN115185957A (en) 2022-06-01 2022-06-01 Lightweight real-time memory database transaction concurrency control method and device

Publications (1)

Publication Number Publication Date
CN115185957A true CN115185957A (en) 2022-10-14

Family

ID=83513057

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210621956.8A Pending CN115185957A (en) 2022-06-01 2022-06-01 Lightweight real-time memory database transaction concurrency control method and device

Country Status (1)

Country Link
CN (1) CN115185957A (en)

Similar Documents

Publication Publication Date Title
CN107977376B (en) Distributed database system and transaction processing method
EP3278239B1 (en) Processing database transactions in a distributed computing system
Ren et al. Lightweight locking for main memory database systems
US11556396B2 (en) Structure linked native query database management system and methods
US11487435B1 (en) System and method for non-volatile memory-based optimized, versioned, log-structured metadata storage with efficient data retrieval
US6961729B1 (en) Processing in parallel units of work that perform DML operations on the same spanning rows
Wu et al. Survey of large-scale data management systems for big data applications
US20090287703A1 (en) Transaction processing system of database using multi-operation processing providing concurrency control of transactions
Bernstein et al. Optimizing optimistic concurrency control for tree-structured, log-structured databases
WO2012060889A1 (en) Systems and methods for grouped request execution
CN102354289A (en) Concurrent transaction scheduling method and related device
Lyu et al. Greenplum: a hybrid database for transactional and analytical workloads
US7792819B2 (en) Priority reduction for fast partitions during query execution
CN102999522A (en) Data storage method and device
EP3396542B1 (en) Database operating method and device
Wang et al. Elastic pipelining in an in-memory database cluster
JP2781092B2 (en) Exclusive control method between systems
Chen et al. Plor: General transactions with predictable, low tail latency
Barthels et al. Designing Databases for Future High-Performance Networks.
Yao et al. Dgcc: A new dependency graph based concurrency control protocol for multicore database systems
WO2023066070A1 (en) Sql statement control method and apparatus
CN115185957A (en) Lightweight real-time memory database transaction concurrency control method and device
Zhu et al. Interactive transaction processing for in-memory database system
Sangat et al. Nimble join: A parallel star join for main memory column‐stores
Fan et al. Scalable transaction processing using functors

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination