WO2024027057A1 - 一种数据回滚方法、装置、设备及其存储介质 - Google Patents

一种数据回滚方法、装置、设备及其存储介质 Download PDF

Info

Publication number
WO2024027057A1
WO2024027057A1 PCT/CN2022/135900 CN2022135900W WO2024027057A1 WO 2024027057 A1 WO2024027057 A1 WO 2024027057A1 CN 2022135900 W CN2022135900 W CN 2022135900W WO 2024027057 A1 WO2024027057 A1 WO 2024027057A1
Authority
WO
WIPO (PCT)
Prior art keywords
rollback
transaction
thread
background
priority
Prior art date
Application number
PCT/CN2022/135900
Other languages
English (en)
French (fr)
Inventor
陈志标
苏凡
孟凡彬
Original Assignee
深圳计算科学研究院
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 深圳计算科学研究院 filed Critical 深圳计算科学研究院
Publication of WO2024027057A1 publication Critical patent/WO2024027057A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1471Saving, restoring, recovering or retrying involving logging of persistent data for recovery
    • 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/21Design, administration or maintenance of databases
    • G06F16/219Managing data history or versioning
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • This application relates to the field of data processing, in particular to a data rollback method, device, equipment and storage medium thereof.
  • WAL Write-Ahead Logging, write-ahead logging system
  • REDO log redo log
  • the data modifications made by these transactions may have already caused some REDO logs to be written to disk, and these uncommitted dirty data will be played back during the database playback log phase.
  • the database needs to be restarted and rolled back to roll back this batch of residual transactions.
  • the page resources locked by these residual transactions will not be accessible by other connections. These resources will not be accessible until the residual transactions end.
  • the front-end business can access consistent data information.
  • This type of mechanism is a common instance crash recovery and connection recovery mechanism in the database field.
  • the general residual transaction rollback mechanism adopted by the database is as mentioned above, that is, a large number of resources held by the residual transactions must wait for the residual transactions to be rolled back in turn before they can be released. During this period, if the normal operation of the database needs to access these resources, a non-deadlock wait will occur and must wait for the rollback of the remaining transactions to end.
  • the sorting of residual transactions is unstable, and it may be necessary to wait for a large number of irrelevant transactions to be rolled back before rolling back to the transactions that the business is eager to wait for.
  • the existing method has the following shortcomings: it does not take into account the waiting blocking transaction in the background rollback queue. It can only detect non-deadlock waiting problems and give warnings and exceptions, and does not consider the situation from the perspective of the database mechanism itself. To solve the problem; for the problem scenario proposed by the present invention, that is, the abnormal remaining transactions need to be rolled back in the background, the existing method can only analyze the waiting chain, but such problems can only be optimized from the perspective of SQL business, and the present invention proposes Exception scenarios cannot shorten the waiting time of this transaction.
  • this application is proposed to provide a data rollback method, apparatus, equipment and storage medium that overcomes the problems or at least partially solves the problems.
  • the method includes:
  • a data rollback method used to roll back data on blocking transactions caused by occupied resources in the database including:
  • the background thread type is the restart rollback thread
  • a request to increase the rollback priority corresponding to the blocking task is generated, and based on the request to increase the rollback priority, the restart is performed based on the blocking transaction.
  • Rollback processing of the rollback thread or; when the background thread type is the background rollback thread, generate a rollback priority increase request corresponding to the blocked task, and execute according to the rollback priority increase request Rollback processing in the background rollback thread based on the blocking transaction, wherein the background rollback thread includes a queued rollback queue and a priority rollback queue.
  • the step of determining the blocking transaction and the unique transaction ID corresponding to the blocking transaction based on the running status information of the current business in the database includes:
  • the blocking transaction is determined based on the occupied resources and the transaction number, and the transaction number of the blocking transaction is marked as the unique transaction ID.
  • the step of determining the background thread type where the blocking transaction is currently located based on the unique transaction ID, wherein the background thread type includes restarting the rollback thread and the background rollback thread includes:
  • the background thread type where the blocking transaction currently resides is determined to be the background rollback thread according to the transaction status information.
  • the background thread type is the restart rollback thread
  • a request to increase the rollback priority corresponding to the blocked task is generated, and the request to increase the rollback priority is executed based on the blocking task.
  • the steps in the transaction's rollback processing of restarting the rollback thread include:
  • the restart rollback thread executes the rollback processing of the first specified ID transaction.
  • the restart rollback thread completes the rollback processing of the first specified ID transaction
  • the restart rollback thread performs the rollback processing according to the specified ID transaction.
  • the second rollback position information is used for rollback processing in sequence.
  • the step of generating a first specified ID transaction based on the restarting the rollback thread, the request to increase the rollback priority, and the blocking transaction includes:
  • the restart rollback thread polls several waiting rollback queues according to the request to increase the rollback priority, and determines the current waiting rollback queue of the blocking transaction through the unique transaction ID corresponding to the blocking transaction. ;
  • the background rollback thread when the background thread type is the background rollback thread, generate a rollback priority increase request corresponding to the blocking task, and execute the blocking transaction based on the rollback priority increase request according to the request.
  • the background rollback thread includes the steps of queuing a rollback queue and a priority rollback queue, including:
  • the priority rollback queue is locked, and the corresponding transaction is deleted in the locked queued rollback queue.
  • the second specified ID transaction adds the second specified ID transaction to the locked priority rollback queue;
  • the background rollback thread performs rollback processing of the second specified ID transaction.
  • the locked priority rollback queue and the locked queued rollback queue are unlocked respectively, and the unlocked priority rollback queue is processed by the background rollback thread. Polling, after the background rollback thread performs the steps of rollback processing of the second specified ID transaction, it also includes:
  • the background rollback thread polls the unlocked queued rollback queue and performs rollback processing on the transactions in the queued rollback queue.
  • Embodiments of the present invention also provide a data rollback device for performing data rollback processing on blocked transactions caused by occupied resources in the database.
  • the device includes:
  • the first determination module is used to determine the blocking transaction and the unique transaction ID corresponding to the blocking transaction based on the running status information of the current business in the database;
  • the second determination module is used to determine the background thread type where the blocking transaction currently resides based on the unique transaction ID, where the background thread type includes restarting the rollback thread and the background rollback thread;
  • a processing module configured to generate a rollback priority increase request corresponding to the blocked task when the background thread type is the restart rollback thread, and execute a rollback priority request based on the blocking task according to the rollback priority increase request.
  • the transaction is in the rollback processing of the restart rollback thread; or; when the background thread type is the background rollback thread, generate a rollback priority increase request corresponding to the blocked task, and perform the rollback according to the increase
  • the rollback priority request performs rollback processing in the background rollback thread based on the blocking transaction, wherein the background rollback thread includes a queued rollback queue and a priority rollback queue.
  • An embodiment of the present invention also provides a computer device, including a processor, a memory, and a computer program stored on the memory and capable of running on the processor.
  • a computer program stored on the memory and capable of running on the processor.
  • Embodiments of the present invention also provide a computer-readable storage medium.
  • a computer program is stored on the computer-readable storage medium.
  • the steps of a data rollback method as described above are implemented.
  • the blocking transaction and the unique transaction ID corresponding to the blocking transaction are determined based on the running status information of the current business in the database; the background thread type where the blocking transaction is currently located is determined based on the unique transaction ID.
  • the background thread type includes a restart rollback thread and the background rollback thread; when the background thread type is the restart rollback thread, a request to increase the rollback priority corresponding to the blocked task is generated.
  • the background thread type is the background rollback thread, generate a corresponding Make a request to increase the rollback priority of the blocked task, and perform rollback processing based on the blocked transaction in the background rollback thread according to the request to increase the rollback priority, wherein the background rollback thread includes queued rollback Queues and priority rollback queues.
  • Figure 1 is a step flow chart of a data rollback method provided by an embodiment of the present application
  • Figure 2 is a structural block diagram of a data rollback device provided by an embodiment of the present application.
  • FIG. 3 is a schematic structural diagram of a computer device provided by an embodiment of the present invention.
  • Non-deadlock waiting for transactions in databases is a very common phenomenon. When several transactions access the same physical page data, transaction waits may be found. If the waiting transaction is running normally, the transaction can be ended. However, if there is an abnormal situation, the transaction waiting time will be uncontrollable, which will hinder the normal operation of the business. There are two types of scenarios:
  • Scenario 1 The database is interrupted abnormally. At this time, all uncommitted transactions will be rolled back after the database is restarted. Such residual transactions are rolled back sequentially according to the order loaded in the transaction area.
  • a non-deadlock wait for the transaction will occur. The business can not continue to run until the rollback of the awaited transaction is completed.
  • the order in which the waiting transactions are queued for rollback is uncontrollable, which may result in the need to wait for the rollback of a large number of unrelated transactions to end before rolling back to the urgent transaction. In such a blocking situation, the running time of database services will be extended uncontrollably.
  • Scenario 2 When the database connection is interrupted, unfinished transactions on the connection also need to be rolled back. A long rollback will cause the exit of the connection to be blocked. The connection cannot respond to the exit until the transaction rollback is completed. When the database stops running in regular mode, all connections will be disconnected. At this time, the transactions on each connection need to be rolled back, which will cause the stopping process to be slow. The database will become unresponsive after stopping for a long time, blocking the database from being pulled again. start to use.
  • the present invention provides a method to reduce the non-deadlock waiting time for transactions that occur in various scenarios due to abnormal transaction rollback, blocking the use of the database and its connections, and blocking database services.
  • the details are as follows:
  • a data rollback method used to roll back data on blocked transactions caused by occupied resources in the database includes:
  • the background thread type is the restart rollback thread
  • generate a rollback priority increase request corresponding to the blocking task and execute a rollback priority increase request based on the location of the blocking transaction according to the rollback priority increase request.
  • the request is to perform rollback processing in the background rollback thread based on the blocking transaction, wherein the background rollback thread includes a queued rollback queue and a priority rollback queue.
  • the blocking transaction and the unique transaction ID corresponding to the blocking transaction are determined based on the running status information of the current business in the database; the background thread type where the blocking transaction is currently located is determined based on the unique transaction ID.
  • the background thread type includes a restart rollback thread and the background rollback thread; when the background thread type is the restart rollback thread, a request to increase the rollback priority corresponding to the blocked task is generated.
  • the background thread type is the background rollback thread, generate a corresponding Make a request to increase the rollback priority of the blocked task, and perform rollback processing based on the blocked transaction in the background rollback thread according to the request to increase the rollback priority, wherein the background rollback thread includes queued rollback Queues and priority rollback queues.
  • the blocking transaction and the unique transaction ID corresponding to the blocking transaction are determined based on the running status information of the current business in the database.
  • step S110 the specific process of "determining the blocking transaction and the unique transaction ID corresponding to the blocking transaction based on the running status information of the current business in the database" described in step S110 can be further explained in conjunction with the following description.
  • S220 Determine the blocking transaction based on the occupied resources and the transaction number, and mark the transaction number of the blocking transaction as the unique transaction ID.
  • the background thread type where the blocking transaction currently resides is determined based on the unique transaction ID, where the background thread type includes a restart rollback thread and the background rollback thread.
  • step S120 of "determining the background thread type where the blocking transaction is currently located based on the unique transaction ID" can be further explained in combination with the following description, where the background thread type includes restarting the rollback thread and The specific process of "background rollback thread”.
  • S330 Determine the background thread type where the blocking transaction currently resides to be the background rollback thread according to the transaction status information.
  • the transaction status information of the blocking transaction is generated by polling using the unique transaction ID, and the transaction status information is used to determine whether the blocking transaction is in the queue of the two types of rollback threads.
  • the two types of rollback threads are restart rollback threads and background rollback threads.
  • the transaction status information will be bound to a unique thread number.
  • the transaction status information of the blocking transaction will record its bound number.
  • Unique thread number both types of rollback threads belong to database background threads, and their thread numbers are fixed. According to the thread number of the blocking transaction, it can be determined whether the transaction is waiting for processing in two types of rollback threads.
  • step S130 when the background thread type is the restart rollback thread, a rollback priority increase request corresponding to the blocked task is generated, and a rollback priority increase request is generated according to the rollback priority increase request. Execute rollback processing based on the blocking transaction in the restarted rollback thread.
  • step S130 described in "when the background thread type is the restart rollback thread, generating a request to increase the rollback priority corresponding to the blocked task" can be further explained in conjunction with the following description. , and execute the specific process of "rollback processing based on the blocking transaction in the restarted rollback thread" according to the request to increase the rollback priority.
  • the restart rollback thread executes the rollback processing of the first designated ID transaction.
  • the restart rollback thread Rollback processing is performed in sequence according to the second rollback position information.
  • the first specified ID transaction is generated based on restarting the rollback thread, raising the rollback priority request and blocking transaction, in which the restarting rollback thread includes at least one, and there is at least one waiting rollback queue in the restarting rollback thread;
  • the restarting rollback thread includes at least one, and there is at least one waiting rollback queue in the restarting rollback thread;
  • the first designated ID transaction is added between the first rollback position information and the second rollback position information;
  • the restart rollback thread performs the rollback processing of the first designated ID transaction, wherein when the restart When the rollback thread completes the rollback processing of the first specified ID transaction, the restarted rollback thread performs rollback processing in sequence according to the second rollback position information.
  • the database is restarted after an abnormal termination and exit. After the restart, there are x1, x2,..., x200 transactions queued for rollback.
  • the database is configured with two restart rollback threads for rollback work, namely restart rollback thread one and restart rollback thread two.
  • the order is: restart rollback thread one, take off transaction x1 to roll back, restart rollback Thread two takes off transaction x2 and rolls it back; when one of the rollback threads restarts rollback thread one or restarts rollback thread two and rolls back, it will take off transaction x3 according to the order; the rollback time of each transaction is uncertain , but they are all rolled back in the order of x1, x2,..., x200.
  • Restart rollback thread two to first end the current rollback transaction x10. At this time, in the original order, restart rollback thread two and roll back transaction x11. After receiving the early rollback request, restart rollback thread two to record the original transaction x11 and take it off the queue waiting for rollback;
  • Restart rollback thread 2 According to the transaction area information of transaction x80, that is, the unique transaction ID, find the rollback queue where the transaction area information is located and lock it. Search for transaction x80; if transaction x80 is not found, it is considered that it may be within this period. Transaction x80 has been rolled back by other restarted rollback threads; if transaction x80 is found, remove it from the waiting rollback queue and release the lock on the waiting rollback queue;
  • Restart rollback thread 2 to read the original record and start rolling back transaction x11 in the original order.
  • the time that the business waits for the end of transaction x80 is only the time from the current start to when a restarted rollback thread ends the currently rolling back transaction.
  • the time for the rollback of transaction x80 itself is greatly shortened.
  • the uncertain waiting time for other unrelated transaction rollbacks reduces the length of time such abnormal transaction rollbacks block business operations. It can overcome the problem that when the business is waiting for an abnormal rollback transaction due to resource locking, the wait may take an unusually long time due to the uncertainty of the transaction queuing sequence in the rollback, causing the foreground business to be blocked all the time.
  • a first specified ID transaction is generated based on the restart of the rollback thread, the request to increase the rollback priority, and the blocking transaction.
  • step S410 the specific process of "generating a first designated ID transaction based on the restarting the rollback thread, the request to increase the rollback priority, and the blocking transaction" in step S410 can be further explained in conjunction with the following description. .
  • the restart rollback thread polls several waiting rollback queues according to the request to increase the rollback priority, and determines the current waiting rollback of the blocking transaction through the unique transaction ID corresponding to the blocking transaction. Roll queue;
  • the restart rollback thread polls several waiting rollback queues according to the request to increase the rollback priority, and determines the number of the blocking transaction through the unique transaction ID corresponding to the blocking transaction. Currently waiting for the rollback queue, obtain the waiting rollback queue where the blocking transaction is located through the unique transaction ID; obtain the blocking transaction in the current waiting rollback queue, and mark the blocking transaction as the first specified ID transaction ; Get the blocking transaction from the waiting rollback queue of the blocking transaction and mark it as the first specified ID transaction.
  • step S130 when the background thread type is the background rollback thread, a rollback priority increase request corresponding to the blocked task is generated, and based on the rollback priority increase request, the The blocking transaction is rolled back in the background rollback thread, wherein the background rollback thread includes a queued rollback queue and a priority rollback queue.
  • the queued rollback queue is locked according to the request to increase the rollback priority, and the locked queued rollback queue is searched according to the unique transaction ID corresponding to the blocking transaction to obtain the blocking transaction, and the blocking transaction is marked.
  • the transaction is the second specified ID transaction; when the second specified ID transaction is obtained in the locked queued rollback queue, the priority rollback queue is locked, and the corresponding queued rollback queue is deleted.
  • Second specified ID transaction add the second specified ID transaction to the locked priority rollback queue; unlock the locked priority rollback queue and the locked queued rollback queue respectively, and pass them through the background
  • the rollback thread polls the unlocked priority rollback queue, and the background rollback thread performs rollback processing of the second specified ID transaction.
  • the queued rollback queue is locked, and the second specified ID transaction is deleted from the queued rollback queue; the priority rollback queue is locked, and the second specified ID transaction is added to the priority rollback queue; Unlock the priority rollback queue and the queued rollback queue respectively; the background rollback thread polls the transactions in the priority rollback queue, and waits until the priority rollback queue is empty before queuing the rollback queue; blocking transactions are rolled back in advance ; Release blocked resources and continue business.
  • step S630 the locked priority rollback queue and the locked queued rollback queue are unlocked respectively, and the unlocked priority rollback queue is processed by the background rollback thread.
  • the roll queue is polled, and the background rollback thread performs rollback processing of the second specified ID transaction.
  • step S630 described in step S630 can be further described in conjunction with the following description: "Unlock the locked priority rollback queue and the locked queued rollback queue respectively, and use the background to The rollback thread polls the unlocked priority rollback queue, and the background rollback thread performs the specific process after "rollback processing of the second specified ID transaction.”
  • the background rollback thread polls the unlocked queued rollback queue, and performs rollback processing on the transactions in the queued rollback queue.
  • the background rollback thread polls the unlocked queued rollback queue and rolls back the transactions in the queued rollback queue. deal with.
  • the background rollback thread polls the priority rollback queue first, the long transaction x109 will be rolled back in advance, and other long transactions that are still queued in the rollback queue will be rolled back later. After long transaction x109 is rolled back, business two can continue to run.
  • the unique number of the blocked transaction that is, the unique transaction ID
  • the globally unique transaction number can be used to obtain the waiting
  • the transaction information is the transaction status information, and by obtaining the transaction status, which is the transaction status information, and the thread information bound to the blocking transaction, which is the background thread type, it is judged whether the blocking transaction is an abnormal rollback transaction in the above two types of scenarios. Whether the blocking transaction is in two types of queued rollback. If the waiting blocking transaction is queued for rollback in the background, a request is initiated to the background. After receiving the request, the corresponding rollback thread conducts an accurate search of the queued rollback queue.
  • the blocking transaction will be processed in advance. priority, perform early rollback, and release the resources occupied by the blocking transaction. While the front-end business is waiting for the blocking transaction, it will end the transaction waiting after receiving the signal of the end of the blocking transaction, lock the resources required by the blocking transaction, and continue to run the business. This greatly reduces the time for which the return transaction blocks the front-end business in two types of abnormal rollback scenarios. .
  • This application provides a Register residual transactions to the background for rollback.
  • the queuing queue provides the registration function for transactions to be rolled back, and the priority queue provides the ability to roll back transactions in advance when waiting for transactions.
  • the description is relatively simple. For relevant details, please refer to the partial description of the method embodiment.
  • a data rollback device used to roll back data on blocked transactions caused by occupied resources in the database specifically includes:
  • the first determination module 810 is used to determine the blocking transaction and the unique transaction ID corresponding to the blocking transaction based on the running status information of the current business in the database;
  • the second determination module 820 is configured to determine the background thread type where the blocking transaction currently resides based on the unique transaction ID, where the background thread type includes restarting the rollback thread and the background rollback thread;
  • the processing module 830 is configured to generate a rollback priority increase request corresponding to the blocked task when the background thread type is the restart rollback thread, and execute the rollback priority increase request based on the rollback priority request.
  • the blocking transaction is processed during the rollback of the restarted rollback thread; or; when the background thread type is the background rollback thread, a rollback priority increase request corresponding to the blocked task is generated, and based on the increase
  • the rollback priority request performs rollback processing in the background rollback thread based on the blocking transaction, wherein the background rollback thread includes a queued rollback queue and a priority rollback queue.
  • the first determination module 810 includes:
  • the first acquisition sub-module is used to obtain the transaction number and version of the occupied resource in the conflict resource when there is a conflict resource in the current business operation;
  • the first marking submodule is configured to determine the blocking transaction based on the occupied resources and the transaction number, and mark the transaction number of the blocking transaction as the unique transaction ID.
  • the second determination module 820 includes:
  • the first generation sub-module is used to poll the unique transaction ID to generate transaction status information
  • the first determination sub-module is used to determine, based on the transaction status information, that the background thread type where the blocking transaction is currently located is the restart rollback thread; or,
  • the second determination sub-module is used to determine, based on the transaction status information, that the background thread type where the blocking transaction is currently located is the background rollback thread.
  • the processing module 830 includes:
  • the second generation submodule is used to generate a first specified ID transaction based on the restart rollback thread, the rollback priority increase request and the blocking transaction;
  • the first added submodule is used to record the first rollback position information of the current work task in the restart rollback thread and the location of the next work task when the current work task of the restart rollback thread ends. Restart the second rollback position information in the rollback thread, and add the first designated ID transaction between the first rollback position information and the second rollback position information;
  • the first processing sub-module is used for the restarted rollback thread to perform rollback processing of the first specified ID transaction, wherein when the restarted rollback thread completes the rollback processing of the first specified ID transaction, The restarted rollback thread performs rollback processing in sequence according to the second rollback position information.
  • the second generation sub-module includes:
  • the first determination unit is used for the restart rollback thread to poll several waiting rollback queues according to the request to increase the rollback priority, and determine the blocking through the unique transaction ID corresponding to the blocking transaction.
  • a first marking unit is configured to obtain the blocking transaction in the current waiting rollback queue and mark the blocking transaction as the first designated ID transaction.
  • the processing module 830 includes:
  • the second marking submodule is used to lock the queued rollback queue according to the request to increase the rollback priority, and use the unique transaction ID corresponding to the blocking transaction to perform the locking of the queued rollback queue. Search to obtain the blocking transaction, and mark the blocking transaction as the second specified ID transaction;
  • the second adding submodule is used to lock the priority rollback queue when the second specified ID transaction is obtained in the locked rollback queue, and add the lock to the locked queued rollback queue. Delete the corresponding second designated ID transaction from the queued rollback queue, and at the same time, add the second designated ID transaction to the locked priority rollback queue;
  • the second processing sub-module is used to unlock the locked priority rollback queue and the locked queued rollback queue respectively, and use the background rollback thread to process the unlocked priority rollback queue.
  • the roll queue is polled, and the background rollback thread performs rollback processing of the second specified ID transaction.
  • the second processing sub-module after the second processing sub-module, it also includes:
  • the third processing sub-module is used to poll the unlocked queued rollback queue by the background rollback thread when the priority rollback queue is empty, and process the transactions in the queued rollback queue. Perform rollback processing.
  • a computer device for a data rollback method of the present invention is shown, which may specifically include the following:
  • the above-mentioned computer device 12 is in the form of a general computing device.
  • the components of the computer device 12 may include but are not limited to: one or more processors or processing units 16, a system memory 28, connecting different system components (including system memory 28 and processing units). 16) of bus 18.
  • the bus 18 represents one or more of several types of bus 18 structures, including a memory bus 18 or memory controller, a peripheral bus 18 , a graphics acceleration port, a processor or a computer using any of the plurality of bus 18 structures.
  • Domain bus 18 includes, but are not limited to, the Industry Standard Architecture (ISA) bus 18, the Micro Channel Architecture (MAC) bus 18, the Enhanced ISA bus 18, the Video Electronics Standards Association (VESA) local bus 18, and Peripheral Component Interconnect (PCI) bus 18.
  • ISA Industry Standard Architecture
  • MAC Micro Channel Architecture
  • VESA Video Electronics Standards Association
  • PCI Peripheral Component Interconnect
  • Computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by computer device 12, including volatile and nonvolatile media, removable and non-removable media.
  • System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and/or cache memory 32 .
  • Computer device 12 may further include other removable/non-removable, volatile/non-volatile computer system storage media.
  • storage system 34 may be used to read and write to non-removable, non-volatile magnetic media (commonly referred to as "hard drives").
  • a disk drive may be provided for reading and writing to removable non-volatile disks (e.g., "floppy disks"), and for removable non-volatile optical disks (e.g., CD-ROM, DVD-ROM or other optical media) that can read and write optical disc drives.
  • each drive may be connected to bus 18 through one or more data media interfaces.
  • the memory may include at least one program product having a set (e.g., at least one) program module 42 configured to perform the functions of various embodiments of the invention.
  • a program/utility 40 having a set of (at least one) program modules 42, which may be stored, for example, in memory.
  • Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules. 42 As well as program data, each of these examples or some combination may include an implementation of a network environment.
  • Program modules 42 generally perform functions and/or methods in the described embodiments of the invention.
  • Computer device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, camera, etc.) and with one or more devices that enable an operator to interact with computer device 12, and /or communicate with any device (eg, network card, modem, etc.) that enables the computer device 12 to communicate with one or more other computing devices. This communication may occur through an input/output (I/O) interface 22. Also, computer device 12 may communicate with one or more networks (eg, local area network (LAN)), wide area network (WAN), and/or public network (eg, the Internet) through network adapter 20. As shown, network adapter 20 communicates with other modules of computer device 12 via bus 18 .
  • external devices 14 e.g., keyboard, pointing device, display 24, camera, etc.
  • any device eg, network card, modem, etc.
  • network adapter 20 may communicate with other modules of computer device 12 via bus 18 .
  • the processing unit 16 executes programs stored in the system memory 28 to execute various functional applications and data processing, for example, implementing a data rollback method provided by the embodiment of the present invention.
  • the above-mentioned processing unit 16 executes the above-mentioned program, it realizes: determining the blocking transaction and the unique transaction ID corresponding to the blocking transaction based on the running status information of the current business in the database; determining the current location of the blocking transaction based on the unique transaction ID.
  • a background thread type wherein the background thread type includes a restart rollback thread and the background rollback thread; when the background thread type is the restart rollback thread, a promotion callback corresponding to the blocking task is generated.
  • Rollback priority request and perform rollback processing based on the blocked transaction in the restart rollback thread according to the rollback priority increase request; or; when the background thread type is the background rollback thread, generate Corresponding to the request to increase the rollback priority of the blocking task, and performing rollback processing based on the blocking transaction in the background rollback thread according to the request to increase the rollback priority, wherein the background rollback thread Including queued rollback queue and priority rollback queue.
  • the present invention also provides a computer-readable storage medium on which a computer program is stored.
  • a data rollback method as provided in all embodiments of the present application is implemented:
  • the program when executed by the processor, it is implemented: determining the blocking transaction and the unique transaction ID corresponding to the blocking transaction based on the running status information of the current business in the database; determining the current location of the blocking transaction based on the unique transaction ID.
  • the background thread type includes a restart rollback thread and the background rollback thread; when the background thread type is the restart rollback thread, an elevated rollback corresponding to the blocking task is generated Priority request, and perform rollback processing based on the blocked transaction in the restart rollback thread according to the increase rollback priority request; or; when the background thread type is the background rollback thread, generate a corresponding In response to the request to increase the rollback priority of the blocking task, and according to the request to increase the rollback priority, perform rollback processing based on the blocking transaction in the background rollback thread, wherein the background rollback thread includes Queued rollback queue and priority rollback queue.
  • the computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium.
  • the computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared or semiconductor system, apparatus or device, or any combination thereof. More specific examples (non-exhaustive list) of computer readable storage media include: electrical connections having one or more conductors, portable computer disks, hard drives, random access memory (RAM), read only memory (ROM), Erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above.
  • a computer-readable storage medium may be any tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device.
  • a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave carrying computer-readable program code therein. Such propagated data signals may take a variety of forms, including - but not limited to - electromagnetic signals, optical signals, or any suitable combination of the above.
  • a computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device .
  • Computer program code for performing the operations of the present invention may be written in one or more programming languages, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional Procedural programming language - such as "C" or similar programming language.
  • the program code may execute entirely on the operator's computer, partly on the operator's computer, as a stand-alone software package, partly on the operator's computer and partly on a remote computer or entirely on the remote computer or server .
  • the remote computer can be connected to the operator computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., using an Internet service provider). to connect via the Internet).
  • LAN local area network
  • WAN wide area network
  • Internet service provider e.g., using an Internet service provider

Landscapes

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

Abstract

一种数据回滚方法、装置、设备及其存储介质,方法包括依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于阻塞事务的唯一事务ID;依据唯一事务ID确定阻塞事务当前所在的后台线程类型;当后台线程类型为重启回滚线程时,依据提升回滚优先级请求执行基于阻塞事务在重启回滚线程的回滚处理;或,当后台线程类型为后台回滚线程时,依据提升回滚优先级请求执行基于阻塞事务在后台回滚线程的回滚处理。方法能够缩短连接断开、数据库阻塞和连接使用的时长,实现提前回滚急迫等待的事务,缩短阻塞事务的时长。

Description

一种数据回滚方法、装置、设备及其存储介质 技术领域
本申请涉及数据处理领域,特别是一种数据回滚方法、装置、设备及其存储介质。
背景技术
许多数据库多采用WAL(Write-Ahead Logging,预写日志系统)机制,即当发生数据变更时,数据的修改落盘之前保证其REDO日志(重做日志)先落盘。而对于事务而言,若发生commit(操作指令),则一定会使整个事务的REDO日志落盘,保证事务完整。但若没有发生commit,其不完整的REDO日志也可能随时被刷写下去,若此时数据库进行异常终止,则再次拉起数据库后,会加载出一批残留事务,即上一次宕机前未提交的事务。这些事务对数据的修改可能已经有部分REDO日志落盘,并在数据库回放日志阶段将这些未提交的脏数据回放了出来。此时,要恢复这些数据,数据库需要进行重启回滚,将这批残留事务进行回滚,回滚期间,这些残留事务锁定的页面资源其他连接不可访问,等残留事务结束后,这些资源才会被释放,前台业务才能访问到一致的数据信息。此外,当连接断开时,该连接上若有未提交事务,也需要回滚。这类机制是数据库领域通用的实例崩溃恢复、连接恢复机制。
数据库采用这类通用的残留事务回滚机制都如上所述,即残留事务持有的大量的资源,必须等待残留事务依次回滚后才能释放。期间,数据库正常运行的业务若需要访问这些资源则产生了非死锁等待,必须等待残留事务回滚结束。而残留事务排序不稳定,可能需要等待大量无关事务回滚完毕后才回滚至业务所急迫等待的事务。业内部分数据库提出优化回滚线程自动配置等方案,但回滚线程数量总有上限,无法真正解决阻塞业务时长不可控的问题。
数据库异常终止进程、数据库连接异常断连时,都会导致大量事务需要回滚。因为异常情况不可控,此类回滚事务占据的资源不可控。数据库业务 运行时可能产生对处在后台待回滚事务的非死锁等待,阻塞数据库业务运行。此外,由于数据库分配于处理此类异常事务回滚的线程数有限,阻塞总时长很难缩减。
而现有方法有以下缺点:其并没有考虑到等待的阻塞事务处在后台回滚排队的情况,只能发现非死锁等待问题,并给出警告与异常,并没有从数据库本身机制的角度去解决问题;针对本发明提出的问题场景,即异常残留需要在后台回滚的事务,现有方法只能分析出等待链,但此类问题只能从SQL业务角度优化,并针对本发明提出的异常场景无法缩短本次事务等待的时长。
发明内容
鉴于所述问题,提出了本申请以便提供克服所述问题或者至少部分地解决所述问题的一种数据回滚方法、装置、设备及其存储介质,所述方法包括:
一种数据回滚方法,用于对数据库内由于占用资源引发的阻塞事务进行数据回滚处理,包括:
依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID;
依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程;
当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理;或;当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列。
进一步地,所述依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID的步骤,包括:
当所述当前业务运行存在冲突资源时,在所述冲突资源中获取占用资源的事务编号和版本;
依据所述占用资源以及所述事务编号确定所述阻塞事务,并将所述阻塞 事务的所述事务编号标记为所述唯一事务ID。
进一步地,所述依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程的步骤,包括:
对所述唯一事务ID进行轮询生成事务状态信息;
依据所述事务状态信息确定所述阻塞事务当前所在的后台线程类型为所述重启回滚线程;或,
依据所述事务状态信息确定所述阻塞事务当前所在的后台线程类型为所述后台回滚线程。
进一步地,所述当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理的步骤,包括:
依据所述重启回滚线程、所述提升回滚优先级请求和所述阻塞事务生成第一指定ID事务;
当所述重启回滚线程的当前工作任务结束时,记录所述当前工作任务在所述重启回滚线程中的第一回滚位置信息以及下一个工作任务在所述重启回滚线程中的第二回滚位置信息,并将所述第一指定ID事务添加至所述第一回滚位置信息和所述第二回滚位置信息之间;
所述重启回滚线程执行所述第一指定ID事务的回滚处理,其中,当所述重启回滚线程完成所述第一指定ID事务的回滚处理时,所述重启回滚线程依据所述第二回滚位置信息按次序进行回滚处理。
进一步地,所述依据所述重启回滚线程、所述提升回滚优先级请求和所述阻塞事务生成第一指定ID事务的步骤,包括:
所述重启回滚线程依据所述提升回滚优先级请求对若干个等待回滚队列进行轮询,并通过所述阻塞事务对应的所述唯一事务ID确定所述阻塞事务的当前等待回滚队列;
在所述当前等待回滚队列中获取所述阻塞事务,并标记所述阻塞事务为所述第一指定ID事务。
进一步地,所述当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列的步骤,包括:
依据所述提升回滚优先级请求锁定所述排队回滚队列,并通过所述阻塞事务对应的所述唯一事务ID对加锁后的所述排队回滚队列进行搜索获取所述阻塞事务,并标记所述阻塞事务为第二指定ID事务;
当在加锁后的所述排队回滚队列中获取所述第二指定ID事务时,对所述优先回滚队列进行加锁,并在加锁后的所述排队回滚队列中删除对应的所述第二指定ID事务,同时,将所述第二指定ID事务加入至加锁后的所述优先回滚队列;
对加锁后的所述优先回滚队列和加锁后的所述排队回滚队列分别进行解锁,并通过所述后台回滚线程对解锁后的所述优先回滚队列进行轮询,所述后台回滚线程执行所述第二指定ID事务的回滚处理。
进一步地,所述对加锁后的所述优先回滚队列和加锁后的所述排队回滚队列分别进行解锁,并通过所述后台回滚线程对解锁后的所述优先回滚队列进行轮询,所述后台回滚线程执行所述第二指定ID事务的回滚处理的步骤之后,还包括:
当所述优先回滚队列为空时,所述后台回滚线程对解锁后的所述排队回滚队列进行轮询,并对所述排队回滚队列内的事务进行回滚处理。
本发明实施例还提供了一种数据回滚装置,用于对数据库内由于占用资源引发的阻塞事务进行数据回滚处理,所述装置包括:
第一确定模块,用于依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID;
第二确定模块,用于依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程;
处理模块,用于当所述后台线程类型为所述重启回滚线程时,生成对应 于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理;或;当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列。
本发明实施例还提供了一种计算机设备,包括处理器、存储器及存储在所述存储器上并能够在所述处理器上运行的计算机程序,所述计算机程序被所述处理器执行时实现如上所述的一种数据回滚方法的步骤。
本发明实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质上存储计算机程序,所述计算机程序被处理器执行时实现如上所述的一种数据回滚方法的步骤。
本申请具有以下优点:
在本申请的实施例中,通过依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID;依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程;当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理;或;当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列。能够在连接断开时将未完成事务注册至后台回滚线程,缩短了连接断开、数据库阻塞和连接使用的时长;以及能够在业务运行发生事务锁等待排队回滚事务时,提前回滚急迫等待的事务,缩短阻塞事务的时长。
附图说明
为了更清楚地说明本申请的技术方案,下面将对本申请的描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提 下,还可以根据这些附图获得其他的附图。
图1是本申请一实施例提供的一种数据回滚方法的步骤流程图;
图2是本申请一实施例提供的一种数据回滚装置的结构框图;
图3是本发明一实施例提供的一种计算机设备的结构示意图。
具体实施方式
为使本申请的所述目的、特征和优点能够更加明显易懂,下面结合附图和具体实施方式对本申请作进一步详细的说明。显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
数据库中事务的非死锁等待是十分常见的现象,当若干个事务访问相同物理页面数据时,可能发现事务等待。若等待的事务处于正常运行中,则事务运行结束即可。但若有异常情况,则事务等待时间不可控,将妨碍业务正常运行,有以下两类场景:
场景一:数据库异常中断,此时所有的未提交事务会在数据库重新拉起后进行回滚。这类残留事务按照事务区内加载的顺序进行依次回滚。数据库业务运行时,若访问了这些残留事务曾修改过的数据,则会产生事务非死锁等待,直至所等待事务回滚完成后,业务才可以继续运行。而此时,虽然业务急迫等待某事务,但被等待事务排队回滚的顺序不可控,可能导致需要等待大量无关事务回滚结束后,才能回滚到急迫事务。此类阻塞情况下,数据库业务运行时长将不可控地被延长。
场景二:数据库连接中断时,该连接上未完成的事务也需要进行回滚,长时间的回滚会导致该连接的退出被阻塞,等事务回滚结束后该连接才能响应退出。当数据库进行常规模式停止运转时,会断开所有的连接,此时每个连接上的事务都需要回滚,会导致停止运转过程缓慢,数据库长时间在停止运转后无响应,阻塞数据库重新拉起使用。
针对这类问题,本发明提供了一种降低多种场景产生异常事务回滚,导致阻塞数据库及其连接使用、阻塞数据库业务发生事务非死锁等待时长的方 法,具体如下所述:
参照图1,示出了本申请一实施例提供的一种数据回滚方法的步骤流程图;
一种数据回滚方法,用于对数据库内由于占用资源引发的阻塞事务进行数据回滚处理,所述方法包括:
S110、依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID;
S120、依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程;
S130、当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理;或;当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列。
在本申请的实施例中,通过依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID;依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程;当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理;或;当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列。能够在连接断开时将未完成事务注册至后台回滚线程,缩短了连接断开、数据库阻塞和连接使用的时长;以及能够在业务运行发生事务锁等待排队回滚事务时,提前回滚急迫等待的事务,缩短阻塞事务的时长。
下面,将对本示例性实施例中一种数据回滚方法作进一步地说明。
如所述步骤S110所述,依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID。
在本发明一实施例中,可以结合下列描述进一步说明步骤S110所述“依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID”的具体过程。
如下列步骤所述,
S210、当所述当前业务运行存在冲突资源时,在所述冲突资源中获取占用资源的事务编号和版本;
S220、依据所述占用资源以及所述事务编号确定所述阻塞事务,并将所述阻塞事务的所述事务编号标记为所述唯一事务ID。
需要说明的是,当数据库内当前业务运行时发生资源冲突,从而因其产生事务等待,从冲突资源所在的物理页面上读取正在占用资源的事务编号和版本,通过占用资源以及事务编号确定阻塞事务,并将阻塞事务的事务编号标记为唯一事务ID。
如所述步骤S120所述,依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程。
在本发明一实施例中,可以结合下列描述进一步说明步骤S120所述“依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程”的具体过程。
如下列步骤所述,
S310、对所述唯一事务ID进行轮询生成事务状态信息;
S320、依据所述事务状态信息确定所述阻塞事务当前所在的后台线程类型为所述重启回滚线程;或,
S330、依据所述事务状态信息确定所述阻塞事务当前所在的后台线程类型为所述后台回滚线程。
需要说明的是,进入事务等待回滚流程后,通过使用唯一事务ID轮询生成阻塞事务的事务状态信息,通过事务状态信息判断该阻塞事务是否处在 两类回滚线程的队列中,其中,两类回滚线程即重启回滚线程和后台回滚线程。
作为一种示例,事务状态信息将绑定唯一的线程号,当该阻塞事务被加载在重启回滚线程或注册在后台回滚线程时,该阻塞事务的事务状态信息上会记录其绑定的唯一线程号;两类回滚线程都属于数据库后台线程,其线程号是固定的。根据该阻塞事务的线程号,即可判断出事务是否处在两类回滚线程中等待处理。
如所述步骤S130所述,所述当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理。
在本发明一实施例中,可以结合下列描述进一步说明步骤S130所述“所述当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理”的具体过程。
如下列步骤所述,
S410、依据所述重启回滚线程、所述提升回滚优先级请求和所述阻塞事务生成第一指定ID事务;
S420、当所述重启回滚线程的当前工作任务结束时,记录所述当前工作任务在所述重启回滚线程中的第一回滚位置信息以及下一个工作任务在所述重启回滚线程中的第二回滚位置信息,并将所述第一指定ID事务添加至所述第一回滚位置信息和所述第二回滚位置信息之间;
S430、所述重启回滚线程执行所述第一指定ID事务的回滚处理,其中,当所述重启回滚线程完成所述第一指定ID事务的回滚处理时,所述重启回滚线程依据所述第二回滚位置信息按次序进行回滚处理。
需要说明的是,依据重启回滚线程、提升回滚优先级请求和阻塞事务生成第一指定ID事务,其中重启回滚线程至少包括一个,重启回滚线程内设有至少一个等待回滚队列;当重启回滚线程的当前工作任务结束时,记录当前工作任务在重启回滚线程中的第一回滚位置信息以及下一个工作任务在 重启回滚线程中的第二回滚位置信息,并将第一指定ID事务添加至所述第一回滚位置信息和第二回滚位置信息之间;所述重启回滚线程执行所述第一指定ID事务的回滚处理,其中,当所述重启回滚线程完成所述第一指定ID事务的回滚处理时,所述重启回滚线程依据所述第二回滚位置信息按次序进行回滚处理。
作为一种示例,将阻塞事务提前至下一个要回滚的事务;待回滚完成后,恢复原重启回滚线程回滚顺序;使得阻塞的资源释放,继续进行业务。
在一具体实现中,数据库在异常终止退出后重新拉起,重启后,存在x1,x2,……,x200个事务在排队进行回滚。假设数据库配置了2个重启回滚线程进行回滚工作,分别为重启回滚线程一和重启回滚线程二,则其顺序为:重启回滚线程一摘下事务x1进行回滚,重启回滚线程二摘下事务x2进行回滚;当重启回滚线程一或重启回滚线程二其中一个回滚线程回滚完,则依据顺序再摘下事务x3;每个事务回滚的时间是不确定,但都按照x1,x2,……,x200的顺序依次进行回滚。
此时数据库中有业务一运行中,需要访问页面page1上的某些数据,访问时发现这些数据被事务x80锁定。正常情况下,业务一必须等待事务x80回滚结束完后,才能获取页面资源,继续运行业务。
通过本发明提供的方法,当业务一发生事务等待,识别出事务x80处于重启回滚线程中排队回滚。此时假设重启回滚线程回滚至了事务x10,若不采取任何措施,则必须等事务x10-事务x79都已经开始进行回滚处理流程后,才能轮到事务x80回滚。
事实上,业务一本身只需要等待事务x80回滚的时间,但因为排队次序问题,业务一必须等待其余事务全部回滚结束后才能开始等待事务x80回滚。为了解决这个问题,本发明提供的技术方案实施如下:
a.将事务x80即第一指定ID事务需要提前回滚的请求发送给重启回滚线程;
b.重启回滚线程二先结束当前回滚事务x10,此时按原此次序,重启回滚线程二应回滚事务x11,收到提前回滚请求后,重启回滚线程二记录原位 置事务x11并将其从等待回滚队列中摘下;
c.重启回滚线程二根据事务x80的事务区信息即唯一事务ID,找到该事务区信息所在的回滚队列并加锁,搜索事务x80;若没有找到事务x80,则认为可能这段时间内事务x80已经被其他重启回滚线程回滚完毕;若找到了事务x80,则将其从等待回滚队列中摘下,对等待回滚队列放锁;
d.重启回滚线程二回滚事务x80,回滚结束后,业务一则立即结束事务等待,获取了资源,可以继续运行业务;
e.重启回滚线程二读取原记录,开始按原顺序继续回滚事务x11。
通过本技术方案,可以使得业务一等待事务x80结束的时间仅为从当前开始至有一个重启回滚线程结束了当前正在回滚事务的时间,加上事务x80本身回滚的时间,大大缩短了其中不确定性的等待其他无关事务回滚时间,降低了此类异常事务回滚导致阻塞业务运行的时长。能够克服,在业务因资源锁定等待异常回滚事务时,由于事务在回滚中排队序列的不确定而导致可能等待耗时异常久,使得前台业务一直阻塞的问题。
如所述步骤S410所述,依据所述重启回滚线程、所述提升回滚优先级请求和所述阻塞事务生成第一指定ID事务。
在本发明一实施例中,可以结合下列描述进一步说明步骤S410所述“依据所述重启回滚线程、所述提升回滚优先级请求和所述阻塞事务生成第一指定ID事务”的具体过程。
如下列步骤所述,
S510、所述重启回滚线程依据所述提升回滚优先级请求对若干个等待回滚队列进行轮询,并通过所述阻塞事务对应的所述唯一事务ID确定所述阻塞事务的当前等待回滚队列;
S520、在所述当前等待回滚队列中获取所述阻塞事务,并标记所述阻塞事务为所述第一指定ID事务。
需要说明的是,所述重启回滚线程依据所述提升回滚优先级请求对若干个等待回滚队列进行轮询,并通过所述阻塞事务对应的所述唯一事务ID确定所述阻塞事务的当前等待回滚队列,通过唯一事务ID得到阻塞事务所在 的等待回滚队列;在所述当前等待回滚队列中获取所述阻塞事务,并标记所述阻塞事务为所述第一指定ID事务;在从阻塞事务所在的等待回滚队列中得到阻塞事务,并将其标记为第一指定ID事务。
如所述步骤S130所述,当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列。
在本发明一实施例中,可以结合下列描述进一步说明步骤S130所述“当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列”的具体过程。
如下列步骤所述,
S610、依据所述提升回滚优先级请求锁定所述排队回滚队列,并通过所述阻塞事务对应的所述唯一事务ID对加锁后的所述排队回滚队列进行搜索获取所述阻塞事务,并标记所述阻塞事务为第二指定ID事务;
S620、当在加锁后的所述排队回滚队列中获取所述第二指定ID事务时,对所述优先回滚队列进行加锁,并在加锁后的所述排队回滚队列中删除对应的所述第二指定ID事务,同时,将所述第二指定ID事务加入至加锁后的所述优先回滚队列;
S630、对加锁后的所述优先回滚队列和加锁后的所述排队回滚队列分别进行解锁,并通过所述后台回滚线程对解锁后的所述优先回滚队列进行轮询,所述后台回滚线程执行所述第二指定ID事务的回滚处理。
需要说明的是,依据提升回滚优先级请求对排队回滚队列进行加锁,并依据阻塞事务对应的唯一事务ID对加锁后的排队回滚队列进行搜索获取得到阻塞事务,并标记该阻塞事务为第二指定ID事务;当在加锁后的排队回滚队列中获取第二指定ID事务时,对优先回滚队列进行加锁,并在加锁后的排队回滚队列中删除对应的第二指定ID事务,同时,将第二指定ID事务 加入至加锁后的优先回滚队列;对加锁后的优先回滚队列和加锁后的排队回滚队列分别进行解锁,并通过后台回滚线程对解锁后的优先回滚队列进行轮询,后台回滚线程执行第二指定ID事务的回滚处理。
作为一种示例,将排队回滚队列进行加锁,并将第二指定ID事务从排队回滚队列上删除;将优先回滚队列加锁,将第二指定ID事务加入优先回滚队列中;对优先回滚队列与排队回滚队列分别进行解锁;后台回滚线程轮询优先回滚队列中的事务,待优先回滚队列为空时,再开始排队回滚队列;阻塞事务被提前回滚;阻塞的资源释放,继续进行业务。
在一具体实现中,当数据库的连接断开时,将该连接上未完成的事务注册至后台回滚线程中的排队队列。其中,若为数据库处于停止运转,则将所有连接上的未完成事务都进行注册。当存在若干个连接异常断开时,产生了10个长事务分别为长事务x100至长事务x110,将所有长事务注册至后台进行回滚。其中数据库运行的业务二产生等待长事务x109即第二指定ID事务,发起请求提前回滚;后台回滚线程对排队回滚队列加锁,进行搜索长事务x109,搜索到后将优先回滚队列加锁,将长事务x109从排队回滚队列上删除,并加入优先回滚队列;后台回滚线程优先轮询优先回滚队列,则会提前回滚长事务x109,其他仍在排队回滚队列上的长事务会延后回滚。当长事务x109回滚完毕之后,业务二可以继续运行。可以在连接异常退出或数据库停止运转时,不阻塞数据库和连接的继续使用。
如所述步骤S630所述,对加锁后的所述优先回滚队列和加锁后的所述排队回滚队列分别进行解锁,并通过所述后台回滚线程对解锁后的所述优先回滚队列进行轮询,所述后台回滚线程执行所述第二指定ID事务的回滚处理。
在本发明一实施例中,可以结合下列描述进一步说明步骤S630所述“对加锁后的所述优先回滚队列和加锁后的所述排队回滚队列分别进行解锁,并通过所述后台回滚线程对解锁后的所述优先回滚队列进行轮询,所述后台回滚线程执行所述第二指定ID事务的回滚处理”之后的具体过程。
如下列步骤所述,
S710、当所述优先回滚队列为空时,所述后台回滚线程对解锁后的所述排队回滚队列进行轮询,并对所述排队回滚队列内的事务进行回滚处理。
需要说明的是,当所述优先回滚队列为空时,所述后台回滚线程对解锁后的所述排队回滚队列进行轮询,并对所述排队回滚队列内的事务进行回滚处理。
在一具体实现中,后台回滚线程优先轮询优先回滚队列,则会提前回滚长事务x109,其他仍在排队回滚队列上的长事务会延后回滚。当长事务x109回滚完毕之后,业务二可以继续运行。
在本发明实施例中,通过在数据库业务执行过程中,若遇到资源被其他事务锁定,通过物理页面事务机制可获取阻塞事务的唯一编号即唯一事务ID,以此全局唯一事务编号获取所等待的事务信息即事务状态信息,并通过获取事务状态即事务状态信息及阻塞事务所绑定的线程信息即后台线程类型,判断出该阻塞事务是否为以上两类场景中的异常回滚事务,判断该阻塞事务是否处于两类排队回滚之中。若等待的阻塞事务处在后台排队回滚中,则对后台发起一个请求,对应的回滚线程收到请求后,对排队回滚队列进行精准搜索,若找到该阻塞事务,提前该阻塞事务的优先级,进行提前回滚,释放该阻塞事务占用的资源。前台业务在等待阻塞事务的过程中,接收到阻塞事务结束的信号则结束事务等待,锁定阻塞事务需要的资源,继续运行业务,大大降低了两类异常回滚场景待回归事务阻塞前台业务的时长。
本发明的有益效果:
1、能够在数据库处于停止运转、连接断开、异常掉电、故障重启等情况,从而导致数据库和连接长时间不可用情况下,实现不阻塞数据库和业务继续运行;本申请中提供了一种将残留事务注册至后台回滚,其中排队队列为待回滚事务提供注册登记功能,优先队列为发生事务等待时提供事务提前回滚能力。
2、提供了一种发生由于异常事务回滚导致锁定资源阻塞业务时,通过获取唯一事务ID,判断阻塞事务状态,发出提高阻塞事务回滚优先级请求,从而使得。
对于装置实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
如图2所示,示出了本申请一实施例提供的一种数据回滚装置的结构框图;
一种数据回滚装置,用于对数据库内由于占用资源引发的阻塞事务进行数据回滚处理,所述装置具体包括:
第一确定模块810,用于依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID;
第二确定模块820,用于依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程;
处理模块830,用于当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理;或;当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列。
在本发明一实施例中,所述第一确定模块810,包括:
第一获取子模块,用于当所述当前业务运行存在冲突资源时,在所述冲突资源中获取占用资源的事务编号和版本;
第一标记子模块,用于依据所述占用资源以及所述事务编号确定所述阻塞事务,并将所述阻塞事务的所述事务编号标记为所述唯一事务ID。
在本发明一实施例中,所述第二确定模块820,包括:
第一生成子模块,用于对所述唯一事务ID进行轮询生成事务状态信息;
第一确定子模块,用于依据所述事务状态信息确定所述阻塞事务当前所在的后台线程类型为所述重启回滚线程;或,
第二确定子模块,用于依据所述事务状态信息确定所述阻塞事务当前所 在的后台线程类型为所述后台回滚线程。
在本发明一实施例中,所述处理模块830,包括:
第二生成子模块,用于依据所述重启回滚线程、所述提升回滚优先级请求和所述阻塞事务生成第一指定ID事务;
第一添加子模块,用于当所述重启回滚线程的当前工作任务结束时,记录所述当前工作任务在所述重启回滚线程中的第一回滚位置信息以及下一个工作任务在所述重启回滚线程中的第二回滚位置信息,并将所述第一指定ID事务添加至所述第一回滚位置信息和所述第二回滚位置信息之间;
第一处理子模块,用于所述重启回滚线程执行所述第一指定ID事务的回滚处理,其中,当所述重启回滚线程完成所述第一指定ID事务的回滚处理时,所述重启回滚线程依据所述第二回滚位置信息按次序进行回滚处理。
在本发明一实施例中,所述第二生成子模块,包括:
第一确定单元,用于所述重启回滚线程依据所述提升回滚优先级请求对若干个等待回滚队列进行轮询,并通过所述阻塞事务对应的所述唯一事务ID确定所述阻塞事务的当前等待回滚队列;
第一标记单元,用于在所述当前等待回滚队列中获取所述阻塞事务,并标记所述阻塞事务为所述第一指定ID事务。
在本发明一实施例中,所述处理模块830,包括:
第二标记子模块,用于依据所述提升回滚优先级请求锁定所述排队回滚队列,并通过所述阻塞事务对应的所述唯一事务ID对加锁后的所述排队回滚队列进行搜索获取所述阻塞事务,并标记所述阻塞事务为第二指定ID事务;
第二添加子模块,用于当在加锁后的所述排队回滚队列中获取所述第二指定ID事务时,对所述优先回滚队列进行加锁,并在加锁后的所述排队回滚队列中删除对应的所述第二指定ID事务,同时,将所述第二指定ID事务加入至加锁后的所述优先回滚队列;
第二处理子模块,用于对加锁后的所述优先回滚队列和加锁后的所述排队回滚队列分别进行解锁,并通过所述后台回滚线程对解锁后的所述优先回 滚队列进行轮询,所述后台回滚线程执行所述第二指定ID事务的回滚处理。
在本发明一实施例中,所述第二处理子模块之后,还包括:
第三处理子模块,用于当所述优先回滚队列为空时,所述后台回滚线程对解锁后的所述排队回滚队列进行轮询,并对所述排队回滚队列内的事务进行回滚处理。
参照图3,示出了本发明的一种数据回滚方法的计算机设备,具体可以包括如下:
上述计算机设备12以通用计算设备的形式表现,计算机设备12的组件可以包括但不限于:一个或者多个处理器或者处理单元16,系统存储器28,连接不同系统组件(包括系统存储器28和处理单元16)的总线18。
总线18表示几类总线18结构中的一种或多种,包括存储器总线18或者存储器控制器,外围总线18,图形加速端口,处理器或者使用多种总线18结构中的任意总线18结构的局域总线18。举例来说,这些体系结构包括但不限于工业标准体系结构(ISA)总线18,微通道体系结构(MAC)总线18,增强型ISA总线18、音视频电子标准协会(VESA)局域总线18以及外围组件互连(PCI)总线18。
计算机设备12典型地包括多种计算机系统可读介质。这些介质可以是任何能够被计算机设备12访问的可用介质,包括易失性和非易失性介质,可移动的和不可移动的介质。
系统存储器28可以包括易失性存储器形式的计算机系统可读介质,例如随机存取存储器(RAM)30和/或高速缓存存储器32。计算机设备12可以进一步包括其他移动/不可移动的、易失性/非易失性计算机体统存储介质。仅作为举例,存储系统34可以用于读写不可移动的、非易失性磁介质(通常称为“硬盘驱动器”)。尽管图3中未示出,可以提供用于对可移动非易失性磁盘(如“软盘”)读写的磁盘驱动器,以及对可移动非易失性光盘(例如CD-ROM,DVD-ROM或者其他光介质)读写的光盘驱动器。在这些情况下,每个驱动器可以通过一个或者多个数据介质界面与总线18相连。存储器可以包括至少一个程序产品,该程序产品具有一组(例如至少一个)程序 模块42,这些程序模块42被配置以执行本发明各实施例的功能。
具有一组(至少一个)程序模块42的程序/实用工具40,可以存储在例如存储器中,这样的程序模块42包括——但不限于——操作系统、一个或者多个应用程序、其他程序模块42以及程序数据,这些示例中的每一个或某种组合中可能包括网络环境的实现。程序模块42通常执行本发明所描述的实施例中的功能和/或方法。
计算机设备12也可以与一个或多个外部设备14(例如键盘、指向设备、显示器24、摄像头等)通信,还可与一个或者多个使得操作人员能与该计算机设备12交互的设备通信,和/或与使得该计算机设备12能与一个或多个其他计算设备进行通信的任何设备(例如网卡,调制解调器等等)通信。这种通信可以通过输入/输出(I/O)界面22进行。并且,计算机设备12还可以通过网络适配器20与一个或者多个网络(例如局域网(LAN)),广域网(WAN)和/或公共网络(例如因特网)通信。如图所示,网络适配器20通过总线18与计算机设备12的其他模块通信。应当明白,尽管图3中未示出,可以结合计算机设备12使用其他硬件和/或软件模块,包括但不限于:微代码、设备驱动器、冗余处理单元16、外部磁盘驱动阵列、RAID系统、磁带驱动器以及数据备份存储系统34等。
处理单元16通过运行存储在系统存储器28中的程序,从而执行各种功能应用以及数据处理,例如实现本发明实施例所提供的一种数据回滚方法。
也即,上述处理单元16执行上述程序时实现:依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID;依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程;当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理;或;当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线 程包括排队回滚队列和优先回滚队列。
在本发明实施例中,本发明还提供一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现如本申请所有实施例提供的一种数据回滚方法:
也即,给程序被处理器执行时实现:依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID;依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程;当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理;或;当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列。
可以采用一个或多个计算机可读的介质的任意组合。计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子(非穷举的列表)包括:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件或者上述的任意合适的组合。在本文件中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。
计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括——但不限于——电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算 机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。
可以以一种或多种程序设计语言或其组合来编写用于执行本发明操作的计算机程序代码,上述程序设计语言包括面向对象的程序设计语言——诸如Java、Smalltalk、C++,还包括常规的过程式程序设计语言——诸如“C”语言或类似的程序设计语言。程序代码可以完全地在操作人员计算机上执行、部分地在操作人员计算机上执行、作为一个独立的软件包执行、部分在操作人员计算机上部分在远程计算机上执行或者完全在远程计算机或者服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络——包括局域网(LAN)或广域网(WAN)——连接到操作人员计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。本说明书中的各个实施例均采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似的部分互相参见即可。
尽管已描述了本申请实施例的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例做出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本申请实施例范围的所有变更和修改。
最后,还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者终端设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者终端设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者终端设备中还存在另外的相同要素。
以上对本申请所提供的一种数据回滚方法、装置、设备及其存储介质, 进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的一般技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。

Claims (10)

  1. 一种数据回滚方法,用于对数据库内由于占用资源引发的阻塞事务进行数据回滚处理,其特征在于,包括:
    依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID;
    依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程;
    当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理;或;当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列。
  2. 根据权利要求1所述的方法,其特征在于,所述依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID的步骤,包括:
    当所述当前业务运行存在冲突资源时,在所述冲突资源中获取占用资源的事务编号和版本;
    依据所述占用资源以及所述事务编号确定所述阻塞事务,并将所述阻塞事务的所述事务编号标记为所述唯一事务ID。
  3. 根据权利要求1所述的方法,其特征在于,所述依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程的步骤,包括:
    对所述唯一事务ID进行轮询生成事务状态信息;
    依据所述事务状态信息确定所述阻塞事务当前所在的后台线程类型为所述重启回滚线程;或,
    依据所述事务状态信息确定所述阻塞事务当前所在的后台线程类型为 所述后台回滚线程。
  4. 根据权利要求1所述的方法,其特征在于,所述当所述后台线程类型为所述重启回滚线程时,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理的步骤,包括:
    依据所述重启回滚线程、所述提升回滚优先级请求和所述阻塞事务生成第一指定ID事务;
    当所述重启回滚线程的当前工作任务结束时,记录所述当前工作任务在所述重启回滚线程中的第一回滚位置信息以及下一个工作任务在所述重启回滚线程中的第二回滚位置信息,并将所述第一指定ID事务添加至所述第一回滚位置信息和所述第二回滚位置信息之间;
    所述重启回滚线程执行所述第一指定ID事务的回滚处理,其中,当所述重启回滚线程完成所述第一指定ID事务的回滚处理时,所述重启回滚线程依据所述第二回滚位置信息按次序进行回滚处理。
  5. 根据权利要求4所述的方法,其特征在于,所述依据所述重启回滚线程、所述提升回滚优先级请求和所述阻塞事务生成第一指定ID事务的步骤,包括:
    所述重启回滚线程依据所述提升回滚优先级请求对若干个等待回滚队列进行轮询,并通过所述阻塞事务对应的所述唯一事务ID确定所述阻塞事务的当前等待回滚队列;
    在所述当前等待回滚队列中获取所述阻塞事务,并标记所述阻塞事务为所述第一指定ID事务。
  6. 根据权利要求1所述的方法,其特征在于,所述当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线 程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列的步骤,包括:
    依据所述提升回滚优先级请求锁定所述排队回滚队列,并通过所述阻塞事务对应的所述唯一事务ID对加锁后的所述排队回滚队列进行搜索获取所述阻塞事务,并标记所述阻塞事务为第二指定ID事务;
    当在加锁后的所述排队回滚队列中获取所述第二指定ID事务时,对所述优先回滚队列进行加锁,并在加锁后的所述排队回滚队列中删除对应的所述第二指定ID事务,同时,将所述第二指定ID事务加入至加锁后的所述优先回滚队列;
    对加锁后的所述优先回滚队列和加锁后的所述排队回滚队列分别进行解锁,并通过所述后台回滚线程对解锁后的所述优先回滚队列进行轮询,所述后台回滚线程执行所述第二指定ID事务的回滚处理。
  7. 根据权利要求6所述的方法,其特征在于,所述对加锁后的所述优先回滚队列和加锁后的所述排队回滚队列分别进行解锁,并通过所述后台回滚线程对解锁后的所述优先回滚队列进行轮询,所述后台回滚线程执行所述第二指定ID事务的回滚处理的步骤之后,还包括:
    当所述优先回滚队列为空时,所述后台回滚线程对解锁后的所述排队回滚队列进行轮询,并对所述排队回滚队列内的事务进行回滚处理。
  8. 一种数据回滚装置,用于对数据库内由于占用资源引发的阻塞事务进行数据回滚处理,其特征在于,包括:
    第一确定模块,用于依据数据库内当前业务的运行状态信息确定阻塞事务以及对应于所述阻塞事务的唯一事务ID;
    第二确定模块,用于依据所述唯一事务ID确定所述阻塞事务当前所在的后台线程类型,其中,所述后台线程类型包括重启回滚线程和所述后台回滚线程;
    处理模块,用于当所述后台线程类型为所述重启回滚线程时,生成对应 于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述重启回滚线程的回滚处理;或;当所述后台线程类型为所述后台回滚线程,生成对应于所述阻塞任务的提升回滚优先级请求,并依据所述提升回滚优先级请求执行基于所述阻塞事务在所述后台回滚线程的回滚处理,其中,所述后台回滚线程包括排队回滚队列和优先回滚队列。
  9. 一种计算机设备,其特征在于,包括处理器、存储器及存储在所述存储器上并能够在所述处理器上运行的计算机程序,所述计算机程序被所述处理器执行时实现如权利要求1至7中任一项所述的方法。
  10. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储计算机程序,所述计算机程序被处理器执行时实现如权利要求1至7中任一项所述的方法。
PCT/CN2022/135900 2022-08-04 2022-12-01 一种数据回滚方法、装置、设备及其存储介质 WO2024027057A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210935768.2 2022-08-04
CN202210935768.2A CN115292092B (zh) 2022-08-04 2022-08-04 一种数据回滚方法、装置、设备及其存储介质

Publications (1)

Publication Number Publication Date
WO2024027057A1 true WO2024027057A1 (zh) 2024-02-08

Family

ID=83828476

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/135900 WO2024027057A1 (zh) 2022-08-04 2022-12-01 一种数据回滚方法、装置、设备及其存储介质

Country Status (2)

Country Link
CN (1) CN115292092B (zh)
WO (1) WO2024027057A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115292092B (zh) * 2022-08-04 2023-04-25 深圳计算科学研究院 一种数据回滚方法、装置、设备及其存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120005684A1 (en) * 2010-07-02 2012-01-05 Fiji Systems, Inc. Priority rollback protocol
US20140189693A1 (en) * 2013-01-02 2014-07-03 Apple Inc. Adaptive handling of priority inversions using transactions
CN106557514A (zh) * 2015-09-29 2017-04-05 中兴通讯股份有限公司 一种分布式事务回滚方法及装置
CN113781154A (zh) * 2021-03-19 2021-12-10 北京京东拓先科技有限公司 一种信息回滚方法、系统、电子设备及存储介质
CN115292092A (zh) * 2022-08-04 2022-11-04 深圳计算科学研究院 一种数据回滚方法、装置、设备及其存储介质

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9372910B2 (en) * 2012-01-04 2016-06-21 International Business Machines Corporation Managing remote data replication
US10318280B2 (en) * 2014-09-24 2019-06-11 Oracle International Corporation System and method for supporting patching in a multitenant application server environment
CN111400085A (zh) * 2020-02-18 2020-07-10 中国平安人寿保险股份有限公司 事务回滚异常的处理方法、装置、计算机设备及存储介质
CN111338766B (zh) * 2020-03-12 2022-10-25 腾讯科技(深圳)有限公司 事务处理方法、装置、计算机设备及存储介质
CN111597015B (zh) * 2020-04-27 2023-01-06 腾讯科技(深圳)有限公司 事务处理方法、装置、计算机设备及存储介质
CN113742034A (zh) * 2020-05-29 2021-12-03 北京沃东天骏信息技术有限公司 事件处理方法与装置、计算机可读存储介质、电子设备
CN112835982B (zh) * 2021-02-26 2023-03-24 浪潮云信息技术股份公司 一种基于分布式数据库的表锁实现方法
CN113806142B (zh) * 2021-08-30 2023-12-22 济南浪潮数据技术有限公司 一种数据恢复方法、装置及相关设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120005684A1 (en) * 2010-07-02 2012-01-05 Fiji Systems, Inc. Priority rollback protocol
US20140189693A1 (en) * 2013-01-02 2014-07-03 Apple Inc. Adaptive handling of priority inversions using transactions
CN106557514A (zh) * 2015-09-29 2017-04-05 中兴通讯股份有限公司 一种分布式事务回滚方法及装置
CN113781154A (zh) * 2021-03-19 2021-12-10 北京京东拓先科技有限公司 一种信息回滚方法、系统、电子设备及存储介质
CN115292092A (zh) * 2022-08-04 2022-11-04 深圳计算科学研究院 一种数据回滚方法、装置、设备及其存储介质

Also Published As

Publication number Publication date
CN115292092B (zh) 2023-04-25
CN115292092A (zh) 2022-11-04

Similar Documents

Publication Publication Date Title
US10152364B2 (en) Predicting, diagnosing, and recovering from application failures based on resource access patterns
US9720911B2 (en) System and method for variable block logging with log-ahead buffers
US8190946B2 (en) Fault detecting method and information processing apparatus
US9189348B2 (en) High availability database management system and database management method using same
US9053137B2 (en) Identifying database triggers
US7634496B1 (en) Techniques for managing state changes of a data storage system utilizing the object oriented paradigm
US9189303B2 (en) Shadow queues for recovery of messages
KR101278818B1 (ko) 트랜잭션 일관 및 문제 상태
US20050193039A1 (en) Fault tolerant mechanism to handle initial load of replicated object in live system
WO2019109854A1 (zh) 分布式数据库数据处理方法、装置、存储介质及电子装置
WO2024027057A1 (zh) 一种数据回滚方法、装置、设备及其存储介质
US20240143469A1 (en) Scalable exactly-once data processing using transactional streaming writes
CN112579307A (zh) 一种物理锁资源的分配检测方法、装置及电子设备
CN115994053A (zh) 数据库备机的并行回放方法、装置、电子设备及介质
CN106815094B (zh) 一种用于实现主备同步模式下事务提交的方法与设备
US20030236811A1 (en) System and method for process management
CN113254536A (zh) 数据库事务处理方法、系统、电子设备及存储介质
CN112231403A (zh) 数据同步的一致性校验方法、装置、设备和存储介质
US20230315713A1 (en) Operation request processing method, apparatus, device, readable storage medium, and system
CN108880873B (zh) 一种应用于异构系统的事务补偿方法和装置
CN117112522A (zh) 并发进程日志管理方法、装置、设备和存储介质
US11294866B2 (en) Lazy optimistic concurrency control
US7657664B2 (en) Method and system for tracking device driver requests
CN115098469A (zh) 数据库迁移方法及装置、电子设备和可读存储介质
CN114579260A (zh) 一种事务处理方法及系统

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22953845

Country of ref document: EP

Kind code of ref document: A1