Database logic log playback method and device, electronic equipment and medium
By introducing scan threads and playback threads, and using the cache queue mechanism, the queue read conflict problem of multiple logical log recovery threads when reading logical log records is solved, the data recovery and playback speed is improved, and the system's high availability and Synchronous efficiency.
Patent Information
- Application Number
- CN202510046672.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-02-21
- Estimated Expiration
- 2045-01-13
AI Technical Summary
In high concurrency scenarios, the data recovery speed of the master and slave nodes is limited by the queue read conflict problem of multiple logical log recovery threads when reading logical log records.
By introducing scan threads and playback threads, using the cache queue mechanism, the scan thread batch obtains logical log records from the scan queue and stores them into the cache queue of the playback thread. The playback thread directly reads and plays it back when the cache queue is not empty, reducing the Lock conflict between threads.
It improves data recovery speed and playback speed, reduces the probability of conflict between multiple playback threads on the same cache queue, and enhances the system's high availability and synchronization efficiency.
Smart Images

Figure CN119493805A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and more specifically, to a method, device, electronic device and medium for replaying a database logical log. Background Art
[0002] The database system needs to ensure the availability and reliability of data, which requires operations such as backup and recovery of the database system.
[0003] When a database fails or is interrupted unexpectedly, such as a system crash or hardware failure, the logical log can be used to restore the database to its state before the failure. For example, by replaying the operation records in the logical log, the data in the database can be gradually rebuilt to ensure data integrity and consistency.
[0004] In a high-availability database cluster, the master and slave nodes are synchronized through log transmission. In a high-concurrency scenario, the master node needs to process a large number of write requests, which will generate a lot of log data. The master node needs to send a large amount of generated log data to the slave node so that the slave node can receive the log data and replay and store it, keeping the data and status of the master and slave nodes synchronized.
[0005] In the related art, a slave node usually utilizes multiple logical log recovery threads to recover related logical log records. However, when reading logical log records, multiple logical log recovery threads will inevitably encounter queue reading conflicts, which will lead to slow data recovery. Summary of the invention
[0006] In view of this, the present invention provides a method, device, electronic device and medium for replaying a database logical log.
[0007] One aspect of the present invention provides a method for database logical log playback, including: calling a scanning thread to scan multiple logical log records from a scanning queue, wherein the logical log records are generated by a generating thread after parsing the logical log; storing a first logical log record among the multiple logical log records into a first cache queue associated with the playback thread, wherein the log type of the logical log corresponding to the first logical log record is a concurrent type; calling a playback thread, and when determining that a second cache queue associated with the playback thread is empty, batch-acquire multiple first logical log records from the first cache queue associated with the playback thread, and store the multiple first logical log records into a second cache queue associated with the playback thread; and acquiring the first logical log records one by one from the second cache queue of the playback thread and playing back the logical logs corresponding to the first logical log records one by one.
[0008] According to an embodiment of the present invention, the method also includes: a first queue lock is provided in the scanning queue, and the scope of the first queue lock is the generation thread and the scanning thread; a second queue lock is provided in the first cache queue associated with each playback thread, and the scope of the second queue lock is the scanning thread and the playback thread; and a queue lock is not set in the second cache queue associated with each playback thread.
[0009] According to an embodiment of the present invention, the multiple logical log records also include a second logical log record whose log type is a timing type; the method also includes: calling a scanning thread to replay the second logical log record in the multiple logical log records according to the timing information of the second logical log record.
[0010] According to an embodiment of the present invention, storing a first logical log record among multiple logical log records into a first cache queue of a playback thread includes: determining at least one first logical log record from multiple logical log records; determining a hash method for calling a logical log corresponding to each first logical log record in a transaction processing process; determining a target playback thread matching each first logical log record based on the hash method; and storing each first logical log record one by one into a first cache queue associated with the target playback thread.
[0011] According to an embodiment of the present invention, the method also includes: after calling the playback thread to play back the logical log corresponding to the first logical log record, storing the first logical log record in the first empty structure form into the first sub-queue corresponding to the playback thread in the first queue array, and storing the first logical log record in the second empty structure form into the second sub-queue corresponding to the playback thread in the second queue array, wherein, in the first queue array, each playback thread corresponds to a first sub-queue, and in the second queue array, each playback thread corresponds to a second sub-queue; and / or, after calling the scanning thread to play back the logical log corresponding to the second logical log record, storing the second logical log record in the first empty structure form into the third sub-queue corresponding to the scanning thread in the first queue array.
[0012] According to an embodiment of the present invention, the method also includes: calling a generation thread to obtain a first logical log record and a second logical log record in a first empty structure form from a first queue array; in response to obtaining the first logical log record and the second logical log record in a first empty structure form from the first queue array, parsing a new logical log and storing the new logical log record in a scanning queue.
[0013] According to an embodiment of the present invention, a generation thread is associated with a counter; calling the generation thread to obtain a first logical log record and a second logical log record in a first empty structure form from a first queue array includes:
[0014] The generation thread is called to alternately obtain the first logical log record of the first empty structure form from the first sub-queue of the first queue array and the second logical log record of the first empty structure form from the third sub-queue based on the quantity data recorded by the counter, wherein, in one alternation process, the generation thread determines the first logical log record of the first empty structure form from a first sub-queue of the first queue array.
[0015] Another aspect of the present invention provides a device for database logical log playback, including: a first calling module, used to call a scanning thread, and scan multiple logical log records from a scanning queue, wherein the logical log records are generated after a generating thread parses the logical log; a storage module, used to store a first logical log record among the multiple logical log records into a first cache queue associated with the playback thread, wherein the log type of the logical log corresponding to the first logical log record is a concurrent type; a second calling module, used to call the playback thread, and when determining that the second cache queue associated with the playback thread is empty, batch-acquire multiple first logical log records from the first cache queue associated with the playback thread, and store the multiple first logical log records into the second cache queue associated with the playback thread; and a playback module, used to obtain the first logical log records one by one from the second cache queue of the playback thread and play back the logical logs corresponding to the first logical log records one by one.
[0016] Another aspect of the present invention provides an electronic device, comprising: one or more processors; and a memory for storing one or more programs, which enables the one or more processors to implement the above method when the one or more programs are executed by the one or more processors.
[0017] Another aspect of the present invention provides a computer-readable storage medium storing computer-executable instructions, which are used to implement the above method when executed.
[0018] Another aspect of the present invention provides a computer program product, the computer program product comprising computer executable instructions, and the instructions are used to implement the above method when being executed.
[0019] The embodiment of the present invention adds a second cache queue to each playback thread, so that the playback thread reads the logical log record from the second cache queue and plays it back each time, and obtains multiple first logical log records from the first cache queue only when it is empty, thereby reducing the conflict probability of the playback thread and the scanning thread accessing the first cache queue at the same time, and improving the playback speed and data recovery speed. In addition, the batch acquisition mechanism of the second cache queue can also reduce the conflict probability of the playback thread and the scanning thread accessing the first cache queue at the same time; each playback thread is associated with the corresponding first cache queue and second cache queue, which reduces the conflict probability of multiple playback threads accessing the same cache queue at the same time, thereby improving the playback speed and data recovery speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The above and other objects, features and advantages of the present invention will become more apparent through the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:
[0021] Figure 1 An exemplary system architecture to which the method and apparatus for database logical log playback of the present invention can be applied is shown.
[0022] Figure 2 A flow chart of a method for replaying a database logical log according to an embodiment of the present invention is shown.
[0023] Figure 3A An application scenario diagram of a database logical log playback method according to an example is shown.
[0024] Figure 3B An application scenario diagram of a database logical log playback method according to an embodiment of the present invention is shown.
[0025] Figure 4 A diagram showing an application scenario of recycling resources according to another embodiment of the present invention is shown.
[0026] Figure 5 A schematic diagram of the interaction between a queue, a queue array and a thread according to a specific embodiment of the present invention is shown.
[0027] Figure 6 A flow chart of a method for replaying a database logical log according to a specific embodiment of the present invention is shown.
[0028] Figure 7 A block diagram of a device for database logical log playback according to an embodiment of the present invention is shown.
[0029] Figure 8 A block diagram of an electronic device 800 suitable for implementing a method for replaying a database logical log according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0030] Below, embodiments of the present invention will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present invention. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of embodiments of the present invention. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of concepts of the present invention.
[0031] The terms used herein are only for describing specific embodiments and are not intended to limit the present invention. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.
[0032] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.
[0033] When using expressions such as "at least one of A, B, and C, etc.", they should generally be interpreted according to the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).
[0034] In the embodiments of the present invention, the collection, update, analysis, processing, use, transmission, provision, invention, storage and other aspects of the data involved (for example, including but not limited to user personal information) are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. In particular, necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain user personal information security, network security and national security. In the embodiments of the present invention, the user's authorization or consent is obtained before obtaining or collecting user personal information.
[0035] Figure 1 The following is an exemplary system architecture to which the method and apparatus for database logical log playback of the present invention can be applied. Figure 1 The examples shown are merely examples of system architectures to which the embodiments of the present invention may be applied, to help those skilled in the art understand the technical content of the present invention, but do not mean that the embodiments of the present invention may not be used in other devices, systems, environments or scenarios.
[0036] like Figure 1 As shown, the system architecture 100 according to this embodiment may include a first server 101 , a second server 102 , a third server 103 and a fourth server 104 .
[0037] The network is used to provide a medium for communication links between the first server 101, the second server 102, the third server 103, and the fourth server 104. The network may include various connection types, such as wired and / or wireless communication links, and the like.
[0038] In a high-availability data cluster, each server may serve as a node, for example, the first server 101 may serve as a master node, and the second server 102 , the third server 103 , and the fourth server 104 may serve as slave nodes.
[0039] In addition, the first server 101, the second server 102, the third server 103 and the fourth server 104 may also interact with the database system. For example, the database system performs data backup and recovery operations on the first server 101, the second server 102, the third server 103 and the fourth server 104 by calling threads.
[0040] It should be noted that the method for replaying a database logical log provided in the embodiment of the present invention can generally be executed by a database system. Accordingly, the device for replaying a database logical log provided in the embodiment of the present invention can generally be set in a database system.
[0041] It should be understood that Figure 1 The number of networks and servers in the embodiment is only for illustration. Any number of networks and servers may be provided as required.
[0042] Figure 2 A flow chart of a method for replaying a database logical log according to an embodiment of the present invention is shown.
[0043] like Figure 2 As shown, the method 200 includes operations S210 to S240.
[0044] In operation S210, a scanning thread is called to scan a plurality of logical log records from a scanning queue, wherein the logical log records are generated after a generating thread parses the logical log.
[0045] In operation S220, a first logical log record among the plurality of logical log records is stored in a first cache queue associated with the playback thread, wherein the log type of the logical log corresponding to the first logical log record is a concurrent type.
[0046] In operation S230, the playback thread is called, and when it is determined that the second cache queue associated with the playback thread is empty, multiple first logical log records are batch-acquired from the first cache queue associated with the playback thread, and the multiple first logical log records are stored in the second cache queue associated with the playback thread.
[0047] In operation S240, the first logical log records are obtained one by one from the second cache queue of the playback thread, and the logical logs corresponding to the first logical log records are played back one by one.
[0048] According to an embodiment of the present invention, in the process of logical log playback, the database involves three types of threads, namely, generation thread, scanning thread and playback thread. The generation thread is also the logical log record generation thread, which is used to parse each logical log into multiple operations, each operation is also a logical log record, and the operations here include database operations, such as adding, deleting, modifying and checking. The scanning thread is also the logical log scanning thread, which is used to scan the logical log records. The playback thread is also the logical log recovery thread, which is used to play back the relevant logical log records, so as to restore the data of this operation in the slave node, and ensure the data unification of the master and slave nodes.
[0049] With respect to operation S210 , during the logical log playback process, the generation thread converts the content of the logical log into a logical log record, and then stores the logical log record into a scan queue through an insert operation. The scan queue is also called a logical log record scan queue.
[0050] For example, the generation thread parses each of the multiple logical logs to generate multiple logical log records. After parsing the logical logs, the generation thread stores the multiple logical log records into the scan queue through the batch interface, that is, the scan queue can include multiple logical log records at the same time.
[0051] When the database system calls the scanning thread, it can also use the batch interface to batch scan multiple logical log records in the scanning queue. Therefore, for the scanning queue, the generation thread and the scanning thread use the batch storage / retrieval mechanism to reduce the number of resource competitions for the scanning queue and improve the logical log playback speed.
[0052] According to an embodiment of the present invention, the logical log includes multiple log types, for example, a concurrent type and a sequential type. The concurrent type can be understood as having no sequential requirements between multiple operations in the logical log, and multiple playback threads can be used to concurrently playback the logical log records of the logical log; on the contrary, the sequential type means that there are sequential requirements between multiple operations in the logical log, and the result of a certain operation will affect the result of subsequent operations, so it is necessary to restore the logical log records of the sequential type according to the sequential information.
[0053] In an embodiment of the present invention, each slave node usually uses multiple playback threads to concurrently restore the logical log records to increase the playback speed. In order to ensure that the data consistency is not affected when multiple playback threads are playing back concurrently, for operation S220, the first logical log record among the multiple logical log records is stored in the first cache queue associated with the playback thread. The log type of the logical log corresponding to the first logical log record is a concurrent type.
[0054] According to an embodiment of the present invention, each playback thread is associated with a first cache queue, so that each playback thread only plays back multiple first logical log records stored in its associated first cache queue, so as to ensure playback orderliness during concurrent playback.
[0055] The above operations S210 and S220 are processing operations on the scanning thread side, and at the same time, the playback thread side also performs operations S230 and S240. Operations S230 and S240 are described as follows.
[0056] According to an embodiment of the present invention, each playback thread is also associated with a second cache queue, and there is a logical relationship between the first cache queue and the second cache queue, that is, the second cache queue obtains the first logical log record from the first cache queue, and the playback thread obtains the first logical log record from the second cache queue for playback. It can be understood that the playback thread indirectly obtains the first logical log record through the first cache queue.
[0057] Each playback thread obtains the first logical log record from the associated second cache queue for playback. When calling each playback thread, the playback thread needs to determine whether there are any unobtained first logical log records in the second cache queue, that is, to determine whether the second cache queue is empty. If the second cache queue is empty, the playback thread needs to first obtain multiple first logical log records in batches from the first cache queue and store them in the second cache queue; then, read the first logical log records one by one from the second cache queue for playback. If the second cache queue is not empty, the playback thread can continue to read the first logical log records one by one from the second cache queue for playback.
[0058] The embodiment of the present invention adds a second cache queue to each playback thread, so that the playback thread reads the logical log record from the second cache queue and plays it back each time, and obtains multiple first logical log records from the first cache queue only when it is empty, thereby reducing the conflict probability of the playback thread and the scanning thread accessing the first cache queue at the same time, and improving the playback speed and data recovery speed. In addition, the batch acquisition mechanism of the second cache queue can also reduce the conflict probability of the playback thread and the scanning thread accessing the first cache queue at the same time; the first cache queue and the second cache queue associated with each playback thread reduce the conflict probability of multiple playback threads accessing the same cache queue at the same time, thereby improving the playback speed and data recovery speed.
[0059] According to an embodiment of the present invention, the scanning queue is provided with a first queue lock, and the scope of application of the first queue lock is the generation thread and the scanning thread; the first cache queue associated with each playback thread is provided with a second queue lock, and the scope of application of the second queue lock is the scanning thread and the playback thread; the second cache queue associated with each playback thread is not set with a queue lock.
[0060] In this embodiment, the lock types of the first queue lock and the second queue lock may be the same or different.
[0061] For the first queue lock of the scan queue, the first queue lock can be occupied by the generation thread to call the generation thread to store the logical log record in the scan queue; after storing the logical log record, the generation thread releases the first queue lock. Similarly, the scan thread can also occupy the first queue lock to call the scan thread to obtain multiple logical log records from the scan queue and store the first logical log record in the first cache queue associated with a playback thread.
[0062] For the second queue lock of the first cache queue, a scanning thread is called to store the first logical log record in the first cache queue; or a playback thread is called to batch obtain multiple first logical log records from the first cache queue and store them in the second cache queue.
[0063] It should be noted that the second cache queue is set to be lock-free, and the playback thread does not need to occupy a lock each time it obtains the first logical log record from the second cache queue.
[0064] An embodiment of the present invention reduces the frequency of lock requests by a single thread by providing a batch interface, while reducing the granularity of the lock, allowing each playback thread to interact with the scanning thread through a separate first cache queue, thereby avoiding lock contention between playback threads and lock contention between scanning threads and playback threads, and improving playback speed and data recovery speed.
[0065] Figure 3A An application scenario diagram of a database logical log playback method according to an example is shown.
[0066] like Figure 3A As shown, the related example 300A includes a generation thread, a scanning thread and a playback thread, and commands 1 to 4 are used to store resources into the scanning queue (full queue), obtain resources from the scanning queue, recycle resources from the empty array, and release resources to the empty array. Commands 1 to 4 can be put_full, get_full, get_ empty, and put_empty, respectively.
[0067] The generation thread, scanning thread, and playback thread execute the put_full, get_full, put_empty, and get_ empty commands on the scanning queue. The above four commands require three threads to compete for the lock resources of the scanning queue by storing (put) and obtaining (get). For one recovery queue among n recovery queues, the scanning thread and the playback thread need to execute the put_full, get_full, get_ empty, and put_ empty commands on the recovery queue. Although the above commands only require two threads to compete for the lock resources, they require four lock occupation operations. Multiple playback threads may also execute the get_full and put_ empty commands on the same recovery queue, and multiple playback threads will also compete for the lock resources.
[0068] It can be found that there are two bottlenecks in the existing examples: 1. There is contention between the generation thread and the scanning thread / playback thread for the lock of the scanning queue. 2. There is contention between the scanning thread and the playback thread for the lock of the recovery queue. Multiple threads simultaneously access the same queue and the lock contention causes resource competition, resulting in performance degradation. There are two factors that cause the contention of the above two queue locks: 1. A single thread only obtains one queue element (logical log record) after each lock acquisition, resulting in a short actual working time, a long waiting time, and the need to request locks frequently; 2. There are a large number of playback threads, and the granularity of the lock is large, resulting in excessive competition for the lock among multiple playback threads. It can be seen that the lock mechanism of the relevant examples has queue conflicts and fierce competition for lock resources, resulting in database performance degradation and slow data playback.
[0069] Figure 3B An application scenario diagram of a database logical log playback method according to an embodiment of the present invention is shown.
[0070] like Figure 3BAs shown, embodiment 300B of the present invention achieves playback speed-up and high-availability synchronization speed-up by reducing the lock granularity. Among them, reducing the lock granularity means improving the performance of the program by reducing the lock holding time and narrowing the lock scope in concurrent programming. Specifically, not only is a corresponding queue associated with each playback thread, allowing a single playback thread to interact with other threads through a separate queue to achieve interaction between the scanning thread and the playback thread; the interaction between the two is divided into two queues, such as a first cache queue and a second cache queue; a batch interface is added to reduce the frequency of lock requests by a single thread, and at the same time, the lock granularity is reduced to reduce the lock conflicts and lock scope of the scanning thread and the playback thread.
[0071] For example, when the logical log playback starts, first, the generation thread puts multiple logical log records into the scan queue through the batch interface, and the scan thread obtains them from the scan queue through the batch interface. The generation thread and the scan thread have the first queue lock of the scan queue, and the batch interface reduces the number of times the generation thread and the scan thread simultaneously compete for the first queue lock.
[0072] Second, as Figure 3B As shown, playback thread 1 is associated with the first cache queue 1 and the second cache queue 1 respectively, playback thread 2 is associated with the first cache queue 2 and the second cache queue 2 respectively, and playback thread 3 is associated with the first cache queue 3 and the second cache queue 3 respectively. The first cache queue 1 and the second cache queue 1 can also be regarded as two sub-queues in the first queue associated with playback thread 1, and other playback threads are similar and will not be repeated here.
[0073] After each playback thread is associated with a corresponding queue, the lock of the first cache queue is only applicable to the current playback thread and the scanning thread, a total of two threads. This reduces the number of threads competing for the first cache queue, and the batch acquisition operation also reduces the number of times the scanning thread and playback thread 1 compete for the first queue lock at the same time.
[0074] Thirdly, queue division is also performed. Taking playback thread 1 as an example, each time playback thread 1 first obtains the first logical log record from the second cache queue 1 (lock-free operation), and when the second cache queue 1 is empty, the first logical log record in the first cache queue 1 is transferred to the second cache queue 1 in batches (locked operation). The contention between the scanning thread and the playback thread 1 is divided into two parts, reducing the contention of the two threads for the lock of the first cache queue.
[0075] Due to the addition of the second cache queue, the playback thread does not need to obtain the first cache queue every time it obtains the logical log record, and the single playback thread 1 only obtains the first logical log record from the second cache queue 1, which is a lock-free operation, narrowing the scope of the lock between the playback thread 1 and the scanning thread, and reducing the conflict probability of accessing the first cache queue at the same time with the scanning thread. In addition, each time the second cache queue is fully obtained by the playback thread, a series of records will be obtained from the first cache queue. The form of batch acquisition reduces the conflict probability of accessing the first cache queue at the same time with the scanning thread.
[0076] In addition, the scanning thread can reclaim the resources released by the playback threads 1 to 3 through the second queue array.
[0077] According to an embodiment of the present invention, the multiple logical log records also include a second logical log record whose log type is a timing type; the method also includes: calling a scanning thread to replay the second logical log record in the multiple logical log records according to the timing information of the second logical log record.
[0078] According to an embodiment of the present invention, the timing information of the second logical log record may be understood as the operation time information of the second logical log record.
[0079] In this embodiment, the scanning thread may be called to first replay the earlier second logical log record, and after the replay is completed, the subsequent second logical log record may be replayed.
[0080] According to an embodiment of the present invention, storing a first logical log record among multiple logical log records into a first cache queue of a playback thread includes: determining at least one first logical log record from multiple logical log records; determining a hash method for calling a logical log corresponding to each first logical log record in a transaction processing process; determining a target playback thread matching each first logical log record based on the hash method; and storing each first logical log record one by one into a first cache queue associated with the target playback thread.
[0081] In an embodiment of the present invention, the scanning thread can first divide the multiple logical log records obtained from the scanning queue into at least one first logical log record and at least one second logical log record according to the log type of the logical log. The at least one second logical log record is played back by the scanning thread itself, and the at least one first logical log record needs to be divided into the first cache queues associated with each of the multiple playback threads.
[0082] There may be multiple playback threads in the database system that concurrently play back multiple first logical log records. In this case, it is necessary to determine how to divide at least one first logical log record into multiple first cache queues respectively associated with the multiple playback threads.
[0083] A transaction is a logical unit in the execution process of a database system. It consists of a finite sequence of database operations. These operations are either all executed or not executed. It is an indivisible unit of work. Generally speaking, a transaction corresponds to a logical log, and the transaction processing process is also the process of generating a logical log. The hash method called in the transaction processing process is also the hash method used in the database processing process.
[0084] In one embodiment, a target playback thread matching each first logical log record may be determined according to a type of hashing method.
[0085] After each first logical log record is to be stored in the first cache queue associated with the target playback thread, it is stored one by one in the first cache queue.
[0086] It should be noted that the first cache queue of the target playback queue has a second queue lock. When storing the first logical log records into the first cache queue one by one, the target playback thread can synchronously obtain the historical first logical log records one by one from the second cache queue. There is no queue resource contention for storage and retrieval here. Even when the second cache queue is empty, multiple first logical log records are obtained from the first cache queue in batches. Here, only one retrieval and storage lock contention occurs, and the number of contention times is relatively small.
[0087] The embodiment of the present invention can further improve the data playback speed by using multiple playback threads for playback and can further improve the playback speed and recovery speed by concurrently playing back the respective first cache queues.
[0088] According to an embodiment of the present invention, the method also includes: after calling the playback thread to play back the logical log corresponding to the first logical log record, storing the first logical log record in the first empty structure form into the first sub-queue corresponding to the playback thread in the first queue array, and storing the first logical log record in the second empty structure form into the second sub-queue corresponding to the playback thread in the second queue array, wherein, in the first queue array, each playback thread corresponds to a first sub-queue, and in the second queue array, each playback thread corresponds to a second sub-queue; and / or, after calling the scanning thread to play back the logical log corresponding to the second logical log record, storing the second logical log record in the first empty structure form into the third sub-queue corresponding to the scanning thread in the first queue array.
[0089] After finishing playback, both the scanning thread and the playback thread will release the resources occupied during playback; the generation thread will recycle these resources and store the newly generated logical log records in the scanning queue. Resource release is mainly for the scanning queue. The resources of the scanning queue occupied by the first logical log record and the second logical log record are released, and new logical log records are added, such as the resource recovery of the scanning queue through the first queue array. In addition, the resource recovery of the first cache queue and the second cache queue will also be realized through the second queue array.
[0090] In an illustrative embodiment, after each playback thread completes the playback of a first logical log record, the structure returned to the generation thread and the scanning thread is different, that is, the structure for the scanning queue, the first cache queue / the second cache queue is different. The scanning thread obtains structure 1 from the scanning queue, and the scanning thread will parse the content in structure 1, such as timing information, and then encapsulates the obtained structure 1 with some parsed transaction information into structure 2. Multiple structures 2 are connected to form the first cache queue / the second cache queue. After the playback thread gets such a structure 2 and plays it back, it needs to return the empty structure 2 to the scanning thread and the empty structure 1 to the generation thread. The first empty structure form is also the empty structure 1, and the second empty structure form is also the empty structure 2. Thus, the first logical log in the first empty structure form is returned to the first subqueue in the first queue array, and the first logical log in the second empty structure form is returned to the second subqueue in the second queue array.
[0091] Similarly, after the scanning thread plays back a second logical log record, it returns the empty structure 1 to the generating thread, that is, returns the second logical log in the form of the first empty structure to the third sub-queue in the first queue array.
[0092] Similar to the playback process, in the resource recovery stage, in the first queue array, a first sub-queue is associated with each playback thread and a third sub-queue is associated with the scanning thread. In addition, in the second queue array, a second sub-queue is associated with each playback thread, and a plurality of second sub-queues form the second queue array.
[0093] Both the first queue array and the second queue array can be regarded as arrays composed of queues. For example, each first sub-queue can be a bucket queue in the first queue array, the second sub-queue can be called an empty queue, and the second queue array can be called m_bucket_list.
[0094] When the scanning thread finishes replaying, it puts the second logical log record in the first empty structure form back into the empty queue, thereby releasing the occupied scanning queue resources. The generation thread can obtain the resources in the empty queue in batches and put in new logical log records, thereby realizing the reuse of the above-mentioned recycled resources. The scanning thread and the generation thread hold the third queue lock for the empty queue.
[0095] When the playback thread finishes playback, it puts the first logical log record in the first empty structure back into its own bucket queue in the first queue array, releases the used scan queue resources, and each playback thread has the fourth queue lock for the bucket queue. Compared with the previous situation where n playback threads, generation threads, and scan threads share a lock, the scope of lock control is reduced during resource recycling, so that multiple playback threads obtain the fourth queue lock of their own bucket queue after playback, and there is no lock contention between them.
[0096] Considering the recycling of existing resources, the first queue array and the second queue array are an array, and the generation thread and the scanning thread both have the queue lock of the entire queue array. When the generation thread occupies the queue array, each playback thread and the scanning thread cannot obtain the queue lock of the queue array, resulting in busy waiting.
[0097] The embodiment of the present invention also adds a batch interface on the resource recovery side, distinguishes between the first queue array and the second queue array, and adds a sub-queue for each playback thread in the queue array. Each playback thread and scanning thread only has the queue lock of the sub-queue associated with it, which reduces the lock conflict and lock scope between the generation thread and other threads, and also reduces the time that the generation thread holds the lock, thereby improving the playback speed and recovery speed.
[0098] According to an embodiment of the present invention, the method also includes: calling a generation thread to obtain a first logical log record and a second logical log record in a first empty structure form from a first queue array; in response to obtaining the first logical log record and the second logical log record in a first empty structure form from the first queue array, parsing a new logical log and storing the new logical log record in a scanning queue.
[0099] In one embodiment, the first logical log record and the second logical log record of the first empty structure form can be obtained from the first queue array and the second queue array at intervals of a preset time period, such as obtaining all or part of the first logical log record and the second logical log record of the first empty structure form in the first queue array and the second queue array within the preset time period. Alternatively, all or part of the first logical log record of the first empty structure form can be obtained only from the first queue array; all or part of the second logical log record of the first empty structure form can be obtained only from the second queue array.
[0100] After the first logical log record and / or the second logical log record is obtained, that is, after the resources are reclaimed, the new logical log is parsed and the new logical log record is stored in the scan queue.
[0101] According to an embodiment of the present invention, a generation thread is associated with a counter; calling the generation thread to obtain a first logical log record and a second logical log record in a first empty structural form from a first queue array includes: calling the generation thread, based on the quantity data recorded by the counter, alternately obtaining the first logical log record in a first empty structural form from a first sub-queue of the first queue array, and obtaining the second logical log record in a first empty structural form from a third sub-queue, wherein, in one alternation, the generation thread determines a first logical log record in a first empty structural form from a first sub-queue of the first queue array.
[0102] In one embodiment, the counter is used to calculate the order in which the generation thread reclaims resources from the first queue array. For example, when obtaining a first logical log record in the form of a first empty structure from a first subqueue in the first queue array, the first quantity data for the first subqueue is increased by 1; when obtaining a second logical log record in the form of a first empty structure from a third subqueue, the second quantity data for the third subqueue is increased by 1. Thus, the alternating order of reclaiming resources from the playback thread and the scanning thread can be determined based on the first quantity data and the second quantity data recorded by the counter.
[0103] For example, when the second data volume increases, the first logical log record of the first empty structure form is obtained from a first subqueue in the first queue array, and then the first data volume is increased; when the first data volume increases, the second logical log record of the first empty structure form is obtained from the third subqueue in the first queue array, and then the second data volume is increased, thereby realizing an alternating process. It should be noted that in two adjacent alternating processes, the first logical log record of the first empty structure form is usually obtained from the first subqueues associated with different playback threads, but the second logical log record of the first empty structure form is obtained from the only third subqueue.
[0104] In another embodiment, for the first cache queue / second cache queue, a scan queue is called to recycle resources from the second sub-queue associated with each playback thread in the second queue array in turn. The specific resource recycling operation is similar to the recycling of the first queue array mentioned above and will not be repeated here.
[0105] The embodiments of the present invention can avoid long waiting time caused by a thread being stuck and continuously waiting for the thread to release resources by alternately recovering the first logical log record and the second logical log record, and alternately recovering the first logical log records of different playback threads in multiple alternating processes. The embodiments of the present invention can timely recover the logical log records in the form of the first empty structure, and timely add new logical log records to the scanning queue, thereby speeding up the playback speed.
[0106] Figure 4 A diagram showing an application scenario of recycling resources according to another embodiment of the present invention is shown.
[0107] like Figure 4 As shown, in embodiment 400, resources are recovered through the first queue array between the generation thread and playback thread 1 and playback thread 2, and the first queue array contains a first subqueue 1 associated with playback thread 1, a first subqueue 2 associated with playback thread 2, and a third subqueue associated with the scanning thread. The generation thread and the scanning thread obtain logical log records through the scanning queue and recover resources through the third subqueue, so that there will be no lock contention in the process of issuing and recovering resources between the generation thread and the scanning thread.
[0108] According to an embodiment of the present invention, the queue-based interaction above uses a communicating sequential processes (CSP) model, such as a scan queue, a first cache queue, and a second cache queue. Multiple threads communicate with each other through message passing, rather than relying on shared memory.
[0109] In this process, the party that stores the logical log record / first logical log record / second logical log record in the queue can be regarded as the producer, and the party that obtains the logical log record / first logical log record / second logical log record from the queue can be regarded as the consumer. For the convenience of description, the logical log record / first logical log record / second logical log record are collectively referred to as records below. Producers and consumers communicate through queues. Producers only pay attention to the produced records and put them into the queue, while consumers take records from the queue for processing. This mechanism effectively reduces the coupling between producers and consumers, allowing them to be independently developed, tested and maintained. When the number of producers or consumers needs to be increased, simply create more threads and connect them to the queue.
[0110] For example, when increasing the playback speed by adding playback threads, it is only necessary to create and associate the first cache queue, the second cache queue, the first subqueue in the first queue array, and the second subqueue in the second queue array for the newly added playback thread. After that, the playback thread can use the first cache queue, the second cache queue, the first subqueue, and the second subqueue to obtain, play back, and recycle records, thereby improving the flexibility and scalability of the entire system. This flexibility enables the database system to easily cope with different loads and demand changes.
[0111] In addition, producers and consumers can perform operations at different points in time without waiting for each other to complete. Producers can immediately continue with the next production task after producing a record, while consumers can take records from the queue and process them when they are free. This asynchrony improves the throughput and responsiveness of the database system, thereby improving playback speed.
[0112] Figure 5 A schematic diagram of the interaction between a queue, a queue array and a thread according to a specific embodiment of the present invention is shown.
[0113] like Figure 5 As shown, before playback, the generation thread can store the logical log record into the scanning thread; the scanning thread determines the log type of the logical log, plays back the second logical log record by itself, and stores the first logical log record into the first cache queue, and the playback thread realizes the playback of the first logical log record through the cooperation of the first cache queue + the second cache queue.
[0114] After playback, the playback thread stores the first logical log record in the second empty structure form into the second subqueue corresponding to the second queue array, and the scanning thread can continue to store new first logical log records into the first cache queue + second cache queue by recycling this part of resources. In addition, the playback thread also stores the first logical log record in the first empty structure form into the first subqueue corresponding to the first queue array, and the scanning thread stores the second logical log record in the first empty structure form into the third subqueue of the first queue array. The generation thread continues to store new logical log records into the scanning queue by recycling the resources in the first queue array.
[0115] Figure 6 A flow chart of a method for replaying a database logical log according to a specific embodiment of the present invention is shown.
[0116] like Figure 6 As shown, embodiment 600 includes operations S601-S608.
[0117] In operation S601 , the logical log starts to be played back.
[0118] In operation S602, whether there are any unreplayed logical log pages. Logical logs are stored in units of pages, called logical log pages; other threads can be called to determine whether there are any unreplayed logical log pages. If there are any unreplayed logical log pages, operation S603 is performed; if there are no unreplayed logical log pages, operation S608 is performed.
[0119] In operation S603, the generation thread parses the logical log page and generates a logical log record.
[0120] In operation S604 , the scanning thread obtains the logical log record.
[0121] In operation S605, whether there is a timing requirement. In operation S605, it is determined whether the logical log corresponding to the logical log record has a timing requirement, that is, whether the log type of the logical log corresponding to the logical log record is a timing type. If there is a timing requirement, the logical log record is the second logical log record, and operation S607 is executed to be played back by the scanning thread; if there is no timing requirement, the logical log record is the first logical log record, and operation S606 is executed to be played back by the playback thread.
[0122] In operation S606 , the playback thread obtains the first logical log record for playback.
[0123] In operation S607 , the scanning thread obtains the second logical log record for playback.
[0124] In operation S608, end.
[0125] For the existing logical log recovery queue (the queue between the scanning thread and the playback thread), the present invention introduces a new queue mechanism to replace the original logical log recovery queue. The main innovations are: 1) The frequency of lock contention between the scanning thread and the playback thread is reduced. Since a local second cache queue is newly added, the playback thread does not have to obtain the first logical log record from the second cache queue every time, which reduces the probability of conflict with the scanning thread accessing the first cache queue at the same time. 2) Each time the second cache queue is completely obtained by the playback thread, a series of first logical log records will be obtained from the first cache queue. The form of batch acquisition reduces the probability of conflict with the scanning thread accessing the first cache queue at the same time. The new queue mechanism has a smaller granularity than the original queue lock, and the use of batch acquisition further reduces the lock contention between the scanning thread and the recovery thread.
[0126] Figure 7 A block diagram of a device for replaying a database logical log according to an embodiment of the present invention is shown.
[0127] like Figure 7As shown, the apparatus 700 for replaying a database logic log includes a first calling module 710 , a storage module 720 , a second calling module 730 and a replay module 740 .
[0128] The first calling module 710 is used to call the scanning thread to scan multiple logical log records from the scanning queue, wherein the logical log records are generated after the generating thread parses the logical log.
[0129] The storage module 720 is used to store a first logical log record among the multiple logical log records into a first cache queue associated with the playback thread, wherein the log type of the logical log corresponding to the first logical log record is a concurrent type.
[0130] The second calling module 730 is used to call the playback thread, and when it is determined that the second cache queue associated with the playback thread is empty, batch obtain multiple first logical log records from the first cache queue associated with the playback thread, and store the multiple first logical log records in the second cache queue associated with the playback thread.
[0131] The playback module 740 is used to obtain the first logical log records one by one from the second cache queue of the playback thread and to play back the logical logs corresponding to the first logical log records one by one.
[0132] According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits, or at least part of the functions of any one of them can be implemented in one module. According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits can be split into multiple modules for implementation. According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits can be at least partially implemented as hardware circuits, such as field programmable gate arrays (FPGAs), programmable logic arrays (PLAs), systems on chips, systems on substrates, systems on packages, application specific integrated circuits (ASICs), or can be implemented by hardware or firmware in any other reasonable way of integrating or packaging the circuit, or by any one of the three implementation methods of software, hardware, and firmware, or by a proper combination of any of them. Alternatively, according to the embodiments of the present invention, one or more of the modules, submodules, units, and subunits can be at least partially implemented as computer program modules, and when the computer program modules are run, the corresponding functions can be executed.
[0133] For example, any of the first calling module 710, the storage module 720, the second calling module 730 and the playback module 740 can be combined in one module / unit / sub-unit for implementation, or any of the modules / units / sub-units can be split into multiple modules / units / sub-units. Alternatively, at least part of the functions of one or more of these modules / units / sub-units can be combined with at least part of the functions of other modules / units / sub-units and implemented in one module / unit / sub-unit. According to an embodiment of the present invention, at least one of the first calling module 710, the storage module 720, the second calling module 730 and the playback module 740 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware and firmware or in a suitable combination of any of them. Alternatively, at least one of the first calling module 710, the storage module 720, the second calling module 730 and the playback module 740 may be at least partially implemented as a computer program module, and when the computer program module is executed, a corresponding function may be performed.
[0134] It should be noted that the device part in the embodiment of the present invention corresponds to the method part in the embodiment of the present invention. The description of the device part specifically refers to the method part, which will not be repeated here.
[0135] Figure 8 A block diagram of an electronic device 800 suitable for implementing a method for replaying a database logical log according to an embodiment of the present invention is shown. Figure 8 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0136] like Figure 8 As shown, the electronic device 800 according to an embodiment of the present invention includes a processor 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 to a random access memory (RAM) 803. The processor 801 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 801 may also include an onboard memory for caching purposes. The processor 801 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present invention.
[0137] In RAM 803, various programs and data required for the operation of electronic device 800 are stored. Processor 801, ROM 802 and RAM 803 are connected to each other via bus 804. Processor 801 performs various operations of the method flow according to the embodiment of the present invention by executing the programs in ROM 802 and / or RAM 803. It should be noted that the program can also be stored in one or more memories other than ROM 802 and RAM 803. Processor 801 can also perform various operations of the method flow according to the embodiment of the present invention by executing the programs stored in the one or more memories.
[0138] According to an embodiment of the present invention, the electronic device 800 may further include an input / output (I / O) interface 805, which is also connected to the bus 804. The electronic device 800 may further include one or more of the following components connected to the input / output (I / O) interface 805: an input portion 806 including a keyboard, a mouse, etc.; an output portion 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 808 including a hard disk, etc.; and a communication portion 809 including a network interface card such as a LAN card, a modem, etc. The communication portion 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the input / output (I / O) interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that the computer program read therefrom is installed into the storage portion 808 as needed.
[0139] According to an embodiment of the present invention, the method flow according to an embodiment of the present invention can be implemented as a computer software program. For example, an embodiment of the present invention includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the processor 801, the above-mentioned functions defined in the system of the embodiment of the present invention are executed. According to an embodiment of the present invention, the system, equipment, device, module, unit, etc. described above can be implemented by a computer program module.
[0140] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiment; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present invention is implemented.
[0141] According to an embodiment of the present invention, the computer-readable storage medium may be a non-volatile computer-readable storage medium. For example, it may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus or a device.
[0142] For example, according to an embodiment of the present invention, the computer-readable storage medium may include the ROM 802 and / or the RAM 803 described above and / or one or more memories other than the ROM 802 and the RAM 803 .
[0143] An embodiment of the present invention also includes a computer program product, which includes a computer program, and the computer program contains program code for executing the method provided by the embodiment of the present invention. When the computer program product runs on an electronic device, the program code is used to enable the electronic device to implement the method provided by the embodiment of the present invention.
[0144] When the computer program is executed by the processor 801, the above functions defined in the system / device of the embodiment of the present invention are executed. According to the embodiment of the present invention, the system, device, module, unit, etc. described above can be implemented by a computer program module.
[0145] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices, magnetic storage devices, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of signals on a network medium, and downloaded and installed through the communication part 809, and / or installed from a removable medium 811. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0146] According to an embodiment of the present invention, the program code for executing the computer program provided by the embodiment of the present invention can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).
[0147] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram may represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box may also occur in an order different from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions. It can be understood by those skilled in the art that the features recorded in the various embodiments of the present invention can be combined and / or combined in various ways, even if such a combination or combination is not explicitly recorded in the present invention. In particular, without departing from the spirit and teachings of the present invention, the features recorded in the various embodiments of the present invention can be combined and / or combined in various ways. All these combinations and / or combinations fall within the scope of the present invention.
[0148] The embodiments of the present invention are described above. However, these embodiments are only for the purpose of illustration, and are not intended to limit the scope of the present invention. Although each embodiment is described above, it does not mean that the measures in each embodiment cannot be used in combination advantageously. Without departing from the scope of the present invention, those skilled in the art may make various substitutions and modifications, which should all fall within the scope of the present invention.
Claims
1. A method for replaying a database logical log, characterized in that: The method comprises: Calling a scanning thread to scan multiple logical log records from a scanning queue, wherein the logical log records are generated after the generating thread parses the logical log; storing a first logical log record among the plurality of logical log records into a first cache queue associated with a playback thread, wherein the log type of the logical log corresponding to the first logical log record is a concurrent type; Calling the playback thread, and if determining that the second cache queue associated with the playback thread is empty, batch-acquire multiple first logical log records from the first cache queue associated with the playback thread, and storing the multiple first logical log records in the second cache queue associated with the playback thread; and The first logical log records are obtained one by one from the second cache queue of the playback thread, and the logical logs corresponding to the first logical log records are played back one by one.
2. The method according to claim 1, characterized in that The method further comprises: The scanning queue is provided with a first queue lock, and the scope of action of the first queue lock is the generating thread and the scanning thread; A first cache queue associated with each of the playback threads is provided with a second queue lock, and the second queue lock has an effective scope of the scanning thread and the playback thread; The second cache queue associated with each of the playback threads is not set with a queue lock.
3. The method according to claim 1, characterized in that The plurality of logical log records further include a second logical log record of a time series type; the method further includes: The scanning thread is called to play back the second logical log record among the plurality of logical log records according to the timing information of the second logical log record.
4. The method according to claim 1, characterized in that: The step of storing a first logical log record among the plurality of logical log records into a first cache queue of the playback thread comprises: Determine at least one of the first logical log records from a plurality of the logical log records; Determine a hash method for calling the logical log corresponding to each of the first logical log records in the transaction processing process; Determine, according to the hash method, a target playback thread matching each of the first logical log records; and Each of the first logical log records is stored one by one in a first cache queue associated with the target playback thread.
5. The method according to claim 3, characterized in that: The method further comprises: After calling the playback thread to play back the logical log corresponding to the first logical log record, storing the first logical log record in the first empty structure form into a first subqueue corresponding to the playback thread in a first queue array, and storing the first logical log record in the second empty structure form into a second subqueue corresponding to the playback thread in a second queue array, wherein in the first queue array, each of the playback threads corresponds to one first subqueue, and in the second queue array, each of the playback threads corresponds to one second subqueue; and / or, After calling the scanning thread to play back the logical log corresponding to the second logical log record, the second logical log record in the first empty structure form is stored in a third subqueue in the first queue array corresponding to the scanning thread.
6. The method according to claim 5, characterized in that The method further comprises: Calling the generation thread to obtain the first logical log record and the second logical log record in a first empty structure form from the first queue array; In response to obtaining the first logical log record and the second logical log record in the first empty structure form from the first queue array, the new logical log is parsed and stored in the scanning queue.
7. The method according to claim 6, characterized in that The generation thread is associated with a counter; the calling of the generation thread to obtain the first logical log record and the second logical log record in the first empty structure form from the first queue array includes: Call the generation thread, and based on the quantity data recorded by the counter, alternately obtain the first logical log record in the first empty structure form from the first sub-queue of the first queue array, and obtain the second logical log record in the first empty structure form from the third sub-queue, wherein in one alternation process, the generation thread determines the first logical log record in the first empty structure form from one of the first sub-queues of the first queue array.
8. A device for replaying database logical logs, characterized in that: The device comprises: A first calling module is used to call a scanning thread to scan a plurality of logical log records from a scanning queue, wherein the logical log records are generated after the generating thread parses the logical log; A storage module, used for storing a first logical log record among the plurality of logical log records into a first cache queue associated with a playback thread, wherein the log type of the logical log corresponding to the first logical log record is a concurrent type; a second calling module, configured to call the playback thread, and when determining that the second cache queue associated with the playback thread is empty, batch-acquire a plurality of the first logical log records from the first cache queue associated with the playback thread, and store the plurality of the first logical log records into the second cache queue associated with the playback thread; and The playback module is used to obtain the first logical log records one by one from the second cache queue of the playback thread and to play back the logical logs corresponding to the first logical log records one by one.
9. An electronic device, comprising: one or more processors; a memory for storing one or more programs, It is characterized in that when the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having executable instructions stored thereon, characterized in that: When the instruction is executed by a processor, the processor implements the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Log playback method and device, data recovery method and device and electronic equipment
CN115629901A
Log information processing method and device, electronic equipment and medium
CN115630033A
Parallel playback method and device of database standby machine, electronic equipment and medium
CN115994053A
Two-stage lock-free parallel log playback method and device
CN117009361A
Log playback method and device, equipment and medium
CN117472535A
Cited By
Queue management method and device
CN122420263A