Method, apparatus, electronic device and medium for database logical log playback
By introducing scan threads and playback threads, and using the cache queue mechanism to optimize the logical log playback process, the problem of limited data recovery speed in high concurrency scenarios is solved, and more efficient logical log playback and data recovery is achieved.
Patent Information
- Application Number
- CN202510046672.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-06-24
- 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.
Introduce scan threads and playback threads to optimize the logical log playback process through the cache queue mechanism. The specific steps include: calling the scanning thread to scan logical log records from the scanning queue, storing it into the cache queue associated with the playback thread, and batch obtaining and storing it into the second cache queue when the playback thread is idle, and finally the playback thread plays back the logical log records one by one.
By reducing the probability of conflict between the playback thread and the scan thread on the first cache queue, the logical log playback speed and data recovery speed are improved.
Smart Images

Figure CN119493805B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and more specifically, to a method, apparatus, electronic device, and medium for database logical log playback. Background Art
[0002] Database systems need to ensure the availability and reliability of data, which requires operations such as backing up and restoring the database system.
[0003] When a database fails or is unexpectedly interrupted, such as a system crash or hardware failure, the database can be restored to its state before the failure using logical logs. For example, by replaying the operation records in the logical logs, the data in the database can be gradually reconstructed to ensure data integrity and consistency.
[0004] In a highly available database cluster, the master and slave nodes maintain synchronization through log transmission. In a high-concurrency scenario, the master node needs to process a large number of write requests, which will generate a large amount of log data. The master node needs to send the generated large amount of log data to the slave node so that the slave node can receive the log data and perform log playback and storage on it to maintain data synchronization and status synchronization between the master node and the slave node.
[0005] In related technologies, slave nodes usually use multiple logical log recovery threads to recover relevant logical log records. However, when multiple logical log recovery threads read logical log records, they will inevitably encounter queue reading conflict problems, which will lead to slow data recovery speed. Summary of the Invention
[0006] In view of this, the present invention provides a method, apparatus, electronic device, and medium for database logical log playback.
[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, where the logical log records are generated after a generating thread parses the logical logs; storing a first logical log record among the multiple logical log records into a first cache queue associated with a playback thread, where the log type of the logical log corresponding to the first logical log record is a concurrency-enabled type; calling the playback thread, and when it is determined that a second cache queue associated with the playback thread is empty, batch-acquiring multiple first logical log records from the first cache queue associated with the playback thread and storing the multiple first logical log records into the second cache queue associated with the playback thread; and sequentially acquiring the first logical log records from the second cache queue of the playback thread and sequentially playing back the logical logs corresponding to the first logical log records.
[0008] According to an embodiment of the present invention, the method further includes: a first queue lock is provided in the scan queue, and the scope of action of the first queue lock is the generation thread and the scan thread; a second queue lock is provided in the first buffer queue associated with each playback thread, and the scope of action of the second queue lock is the scan thread and the playback thread; no queue lock is provided in the second buffer queue associated with each playback thread.
[0009] According to an embodiment of the present invention, the plurality of logical log records further includes a second logical log record of a time series type; the method further includes: calling a scan thread to replay the second logical log record among the plurality of logical log records according to the time series information of the second logical log record.
[0010] According to an embodiment of the present invention, storing the first logical log record among the plurality of logical log records into the first buffer queue of the playback thread includes: determining at least one first logical log record from the plurality of logical log records; determining the hash method called by the corresponding logical log of each first logical log record during the transaction processing; determining the target playback thread matching each first logical log record according to the hash method; and storing each first logical log record into the first buffer queue associated with the target playback thread one by one.
[0011] According to an embodiment of the present invention, the method further includes: after calling the playback thread to replay 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 scan thread to replay 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 scan thread in the first queue array.
[0012] According to an embodiment of the present invention, the method further includes: calling a 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; 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, parsing the new logical log and storing the new logical log record into the scan queue.
[0013] According to an embodiment of the present invention, a counter is associated with the generation thread; calling 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:
[0014] Invoke the generation thread. Based on the quantity data recorded by the counter, alternately obtain the first logical log record in the form of a first empty structure from the first sub-queue of the first queue array and obtain the second logical log record in the form of a first empty structure from the third sub-queue. Among them, during one alternation process, the generation thread determines the first logical log record in the form of a first empty structure from one of the first sub-queues of the first queue array.
[0015] Another aspect of the present invention provides a device for database logical log playback, including: a first invocation module for invoking a scanning thread to scan a plurality of logical log records from a scanning queue, where the logical log records are generated after the generation thread parses the logical logs; a storage module for storing the first logical log record among the plurality of logical log records into a first cache queue associated with the playback thread, where the log type of the logical log corresponding to the first logical log record is a concurrency-enabled type; a second invocation module for invoking the playback thread, and when it is determined that the second cache queue associated with the playback thread is empty, batch obtaining a plurality of first logical log records from the first cache queue associated with the playback thread and storing the plurality of first logical log records into the second cache queue associated with the playback thread; and a playback module for sequentially obtaining the first logical log records from the second cache queue of the playback thread and sequentially playing back the logical logs corresponding to the first logical log records.
[0016] Another aspect of the present invention provides an electronic device, including: one or more processors; a memory for storing one or more programs, and when the one or more programs are executed by the one or more processors, enabling the one or more processors to implement the method as described above.
[0017] Another aspect of the present invention provides a computer-readable storage medium storing computer-executable instructions that are used to implement the method as described above when executed.
[0018] Another aspect of the present invention provides a computer program product, which includes computer-executable instructions that are used to implement the method as described above when executed.
[0019] Embodiments of the present invention add a second cache queue for each playback thread, so that the playback thread reads logical log records from the second cache queue each time and performs playback, and only obtains a plurality of first logical log records from the first cache queue when it is empty, reducing the conflict probability of the playback thread and the scanning thread accessing the first cache queue simultaneously, 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 simultaneously; each playback thread is respectively associated with a corresponding first cache queue and a second cache queue, reducing the conflict probability of multiple playback threads accessing the same cache queue simultaneously, thereby improving the playback speed and data recovery speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Through the following description of the embodiments of the present invention with reference to the accompanying drawings, the above and other objects, features and advantages of the present invention will become more clear. In the drawings:
[0021] Figure 1 An exemplary system architecture in which the method and apparatus for database logical log playback according to the present invention can be applied is shown.
[0022] Figure 2 A flowchart of a method for database logical log playback according to an embodiment of the present invention is shown.
[0023] Figure 3A An application scenario diagram of a method for database logical log playback according to an example is shown.
[0024] Figure 3B An application scenario diagram of a method for database logical log playback according to an embodiment of the present invention is shown.
[0025] Figure 4 An application scenario diagram of recycling resources according to another embodiment of the present invention is shown.
[0026] Figure 5 An interaction diagram between a queue, a queue array and a thread according to a specific embodiment of the present invention is shown.
[0027] Figure 6 A flowchart of a method for database logical log playback according to a specific embodiment of the present invention is shown.
[0028] Figure 7 A block diagram of an apparatus 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 the method for database logical log playback according to an embodiment of the present invention is shown. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0030] Hereinafter, embodiments of the present invention will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present invention. In the following detailed description, for the sake of explanation, numerous specific details are set forth to provide a comprehensive understanding of the embodiments of the present invention. However, it is obvious that one or more embodiments can also be implemented without these specific details. In addition, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily confusing the concepts of the present invention.
[0031] The terms used herein are merely for describing specific embodiments and are not intended to limit the present invention. The terms "comprising", "including", etc. used herein indicate the presence of the described features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0032] All terms used herein (including technical and scientific terms) 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] In cases where expressions similar to "at least one of A, B, and C, etc." are used, generally, it should be interpreted according to the meaning 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 only A, only B, only C, having A and B, having A and C, having B and C, and / or having A, B, and C, etc.).
[0034] In the embodiments of the present invention, in aspects such as the collection, update, analysis, processing, use, transmission, provision, invention, storage, etc. of the data involved (for example, including but not limited to user personal information), they all comply with the provisions of relevant laws and regulations, are used for legal purposes, and do not violate public order and good customs. In particular, necessary measures are taken for user personal information to prevent illegal access to user personal information data and to maintain the security of user personal information, network security, and national security. In the embodiments of the present invention, before obtaining or collecting user personal information, the authorization or consent of the user is obtained.
[0035] 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. It should be noted that Figure 1 What is shown is only an example of the system architecture to which the embodiments of the present invention can be applied, to help those skilled in the art understand the technical content of the present invention, but it does not mean that the embodiments of the present invention cannot be used in other devices, systems, environments, or scenarios.
[0036] As Figure 1 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 a medium for providing 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, etc.
[0038] In a highly available data cluster, each server can act as a node. For example, the first server 101 can act as the master node, and the second server 102, the third server 103, and the fourth server 104 can act as slave nodes.
[0039] In addition, there may also be data interaction between the first server 101, the second server 102, the third server 103, and the fourth server 104 and the database system. For example, the database system performs operations such as data backup and recovery 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 database logical log replay provided by the embodiments of the present invention can generally be executed by the database system. Correspondingly, the device for database logical log replay provided by the embodiments of the present invention can generally be set in the database system.
[0041] It should be understood that Figure 1 the numbers of the network and servers in [[ ]] are merely illustrative. According to the implementation requirements, there can be any number of networks and servers.
[0042] Figure 2 shows a flowchart of the method for database logical log replay according to an embodiment of the present invention.
[0043] As Figure 2 shown, the method 200 includes operations S210 to S240.
[0044] In operation S210, a scanning thread is called to scan multiple logical log records from the scanning queue, where the logical log records are generated after the generation thread parses the logical log.
[0045] In operation S220, the first logical log record among the multiple logical log records is stored in the first cache queue associated with the replay thread, where the log type of the logical log corresponding to the first logical log record is a concurrent type.
[0046] In operation S230, a playback thread is called. When it is determined that the second cache queue associated with the playback thread is empty, a plurality of first logical log records are batch fetched from the first cache queue associated with the playback thread, and the plurality of 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 fetched one by one from the second cache queue of the playback thread, and the logical logs corresponding to the first logical log records are replayed one by one.
[0048] According to an embodiment of the present invention, during the logical log replay process, the database involves three types of threads, namely, a generation thread, a scanning thread, and a playback thread. The generation thread, that is, the logical log record generation thread, is used to parse each logical log into multiple operations, and each operation is a logical log record. Here, the operations include database operations such as addition, deletion, modification, and query. The scanning thread, that is, the logical log scanning thread, is used to scan logical log records. The playback thread, that is, the logical log recovery thread, is used to replay relevant logical log records, so as to recover the data of this operation on the slave node and ensure the data consistency between the master and slave nodes.
[0049] For operation S210, during the logical log replay process, the generation thread converts the content of the logical log into logical log records, and then stores the logical log records in the scanning queue through an insert operation. The scanning queue is also called the logical log record scanning queue.
[0050] For example, the generation thread parses each of the multiple logical logs to generate multiple logical log records. After parsing the logical log, the generation thread stores the multiple logical log records in the scanning queue through a batch interface, that is, the scanning queue can include multiple logical log records at the same time.
[0051] When the database system calls the scanning thread, it can also batch scan multiple logical log records in the scanning queue through a batch interface. Thus, for the scanning queue, the generation thread and the scanning thread reduce the number of resource contention times for the scanning queue through a batch storage / retrieval mechanism, and improve the logical log replay speed.
[0052] According to an embodiment of the present invention, the logical log includes multiple log types. For example, there are a concurrent type and a sequential type. The concurrent type can be understood as that there is no timing requirement between multiple operations in the logical log, and multiple playback threads can be used to concurrently replay the logical log records of the logical log; on the contrary, the sequential type means that there is a timing requirement between multiple operations in the logical log, and the result of a certain operation will affect the results of subsequent operations. Therefore, it is necessary to restore the logical log records of the sequential type according to the timing information.
[0053] In an embodiment of the present invention, each slave node typically uses multiple playback threads to concurrently recover logical log records to improve the playback speed. To ensure data consistency is not affected during concurrent playback by multiple playback threads, for operation S220, the first logical log record among multiple logical log records is stored in a first cache queue associated with the playback thread. The log type of the logical log corresponding to the first logical log record is a concurrently executable type.
[0054] According to an embodiment of the present invention, each playback thread is associated with a first cache queue, such that each playback thread only plays back multiple first logical log records stored in the first cache queue associated with it to ensure playback orderliness during concurrent playback.
[0055] The above operations S210 and S220 are processing operations on the scanning thread side. Meanwhile, operations S230 and S240 are also executed on the playback thread side. The descriptions of operations S230 and S240 are as follows.
[0056] According to an embodiment of the present invention, each playback thread is further associated with a second cache queue. 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 each playback thread is called, the playback thread needs to determine whether there are still unobtained first logical log records in the second cache queue, that is, to determine whether the second cache queue is empty. When the second cache queue is empty, the playback thread needs to first batch obtain multiple first logical log records from the first cache queue and store them in the second cache queue; then, read the first logical log records from the second cache queue one by one for playback. When the second cache queue is not empty, the playback thread can continue to read the first logical log records from the second cache queue one by one for playback.
[0058] Embodiments of the present invention add a second cache queue for each playback thread, enabling the playback thread to read logical log records from the second cache queue each time for playback, and only obtaining multiple first logical log records from the first cache queue when it is empty, reducing the conflict probability between the playback thread and the scanning thread accessing the first cache queue simultaneously, 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 between the playback thread and the scanning thread accessing the first cache queue simultaneously; the first cache queue and the second cache queue associated with each playback thread respectively reduce the conflict probability of multiple playback threads accessing the same cache queue simultaneously, 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 action 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 action of the second queue lock is the scanning thread and the playback thread; the second cache queue associated with each playback thread is not provided with a queue lock.
[0060] In this embodiment, the lock types of the first queue lock and the second queue lock can be the same or different.
[0061] For the first queue lock of the scanning queue, the generation thread can occupy the first queue lock to call the generation thread to deposit logical log records into the scanning queue; after depositing the logical log records, the generation thread releases the first queue lock. Similarly, the scanning thread can also occupy the first queue lock to call the scanning thread to obtain multiple logical log records from the scanning queue and deposit the first logical log record into the first cache queue associated with a certain playback thread.
[0062] For the second queue lock of the first cache queue, call the scanning thread to deposit the first logical log record into the first cache queue; or, call the playback thread to batch obtain multiple first logical log records from the first cache queue and deposit them into the second cache queue.
[0063] It should be noted that the second cache queue is set without a lock, 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] Embodiments of the present invention reduce the request frequency of a single thread for a lock by providing a batch interface, and at the same time reduce the lock granularity, enabling each playback thread to interact with the scanning thread through a separate first cache queue, avoiding lock competition between playback threads and lock competition between the scanning thread and the playback thread, and improving the playback speed and data recovery speed.
[0065] Figure 3A Shows an application scenario diagram of a method for database logical log playback according to an example.
[0066] As Figure 3A shown, the related Example 300A includes a generation thread, a scanning thread, and a playback thread. Commands 1 to 4 are respectively used to deposit 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, the scanning thread, and the 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 depositing (put) and obtaining (get). For one of the 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, four lock occupation operations are required. 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 bottleneck points in the existing examples: 1. There is contention for the lock of the scanning queue between the generation thread and the scanning thread / playback thread. 2. There is contention for the lock of the recovery queue between the scanning thread and the playback thread. The lock contention of multiple threads accessing the same queue simultaneously causes resource competition, resulting in performance degradation. The generation of the above two queue lock contentions has two factors: 1. A single thread only obtains one queue element (logical log record) each time it obtains the lock, resulting in a relatively short actual working time and a relatively long waiting time, and the need to frequently request the lock; 2. The number of playback threads is relatively large, and the lock granularity is relatively large, resulting in overly intense competition for the lock among multiple playback threads. It can be seen that the lock mechanism of the related example has problems such as queue conflicts and intense lock resource contention, resulting in degraded database performance and slow data playback speed.
[0069] Figure 3B Fig. shows an application scenario diagram of the method for replaying database logical logs according to an embodiment of the present invention.
[0070] As Figure 3BAs shown, Embodiment 300B of the present invention achieves playback speedup and high-availability synchronization speedup by reducing the lock granularity. Among them, reducing the lock granularity means that in concurrent programming, the performance of the program is improved by reducing the holding time of the lock and narrowing the scope of the lock. 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 the interaction between the scanning thread and the playback thread; the interaction between the two is implemented by dividing it into two queues, such as the first cache queue and the second cache queue; a batch interface is added to reduce the request frequency of a single thread for the lock, and at the same time reduce the lock granularity to reduce the lock conflict and lock scope between the scanning thread and the playback thread.
[0071] For example, at the beginning of the logical log playback, on the one hand, the generation thread puts multiple logical log records into the scanning queue through the batch interface, and the scanning thread obtains them from the scanning queue through the batch interface. The generation thread and the scanning thread have the first queue lock for the scanning queue, and the batch interface reduces the number of times the generation thread and the scanning thread compete for the first queue lock at the same time.
[0072] On the other hand, as Figure 3B shown, playback thread 1 is respectively associated with the first cache queue 1 and the second cache queue 1, playback thread 2 is respectively associated with the first cache queue 2 and the second cache queue 2, and playback thread 3 is respectively associated with the first cache queue 3 and the second cache queue 3. 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 the same applies to other playback threads and will not be elaborated here.
[0073] After associating a corresponding queue with each playback thread, the scope of the lock of the first cache queue is only for the current playback thread and the scanning thread, a total of two threads. Thus, the number of threads competing for the first cache queue is reduced, 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] On the third aspect, queue partitioning is also carried out. 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). When the second cache queue 1 is empty, the first logical log records in the first cache queue 1 are then batch transferred to the second cache queue 1 (lock operation). The competition between the scanning thread and playback thread 1 is divided into two parts, reducing the lock contention between the two threads for the first cache queue.
[0075] Due to the addition of the second cache queue, when the playback thread fetches logical log records each time, it doesn't have to fetch from the first cache queue every time. And it is a lock-free operation for a single playback thread 1 to fetch the first logical log record only from the second cache queue 1, which narrows the scope of the lock between playback thread 1 and the scanning thread and reduces the conflict probability of accessing the first cache queue simultaneously with the scanning thread. In addition, a series of records are fetched from the first cache queue only when the second cache queue is completely fetched by the playback thread each time. The form of batch fetching reduces the conflict probability of accessing the first cache queue simultaneously with the scanning thread.
[0076] In addition, the scanning thread can recycle the resources released by playback threads 1 to 3 through the second queue array.
[0077] According to an embodiment of the present invention, the multiple logical log records further include second logical log records whose log type is a time series type; the method further includes: calling a scanning thread to replay the second logical log records among the multiple logical log records according to the time series information of the second logical log records.
[0078] According to an embodiment of the present invention, the time series information of the second logical log records can be understood as the operation time information of the second logical log records.
[0079] In this embodiment, a scanning thread can be called to first replay the earlier second logical log records, and after the replay is completed, then replay the subsequent second logical log records that occur.
[0080] According to an embodiment of the present invention, storing the first logical log records among the multiple logical log records into the first cache queue of the playback thread includes: determining at least one first logical log record from the multiple logical log records; determining the hash method called by the corresponding logical log of each first logical log record during the transaction processing; determining the target playback thread that matches each first logical log record according to the hash method; and storing each first logical log record into the first cache queue associated with the target playback thread one by one.
[0081] In an embodiment of the present invention, the scanning thread can first divide the multiple logical log records fetched 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 replayed by the scanning thread itself, and the at least one first logical log record needs to be distributed into the first cache queues respectively associated with multiple playback threads.
[0082] There can be multiple playback threads in the database system that concurrently replay multiple first logical log records simultaneously. In this case, it is necessary to determine how to distribute at least one first logical log record into multiple first cache queues respectively associated with multiple playback threads.
[0083] A transaction is a logical unit during the execution of a database system. It consists of a finite sequence of database operations. These operations are either all executed or none of them are executed, and it is an indivisible unit of work. Generally, a transaction corresponds to a logical log, and the process of transaction processing is also the process of generating the logical log. The hash method called during the transaction processing is also the hash method used in the database processing.
[0084] In one embodiment, the target replay thread matching each first logical log record can be determined according to the type of the hash method.
[0085] After the first cache queue associated with the target replay thread where each first logical log record is to be stored, each of them is stored in the above-mentioned first cache queue one by one.
[0086] It should be noted that the first cache queue of the target replay queue has a second queue lock. When storing the first logical log records in the first cache queue one by one, the target replay thread can synchronously obtain the historical first logical log records from the second cache queue one by one. There is no queue resource contention here for the storage and retrieval; even when the second cache queue is empty and multiple first logical log records are obtained from the first cache queue in batches, only one lock contention occurs between the retrieval and the above-mentioned storage here, and the number of contention times is small.
[0087] The embodiments of the present invention can further improve the data replay speed by using multiple replay threads for replay, and for their respective first cache queues concurrently, which can further improve the replay speed and recovery speed.
[0088] According to the embodiments of the present invention, the method further includes: after calling the replay thread to replay 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 replay 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 replay thread in the second queue array, where in the first queue array, each replay thread corresponds to a first sub-queue, and in the second queue array, each replay thread corresponds to a second sub-queue; and / or, after calling the scan thread to replay 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 scan thread in the first queue array.
[0089] Whether it is the scanning thread or the playback thread, after completing the playback, the resources occupied during playback will be released; the generation thread will recycle this part of the resources and store the newly generated logical log records into the scanning queue. The 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 record are released, and new logical log records are supplemented, such as implementing the resource recycling of the scanning queue through the first queue array. In addition, for the first buffer queue and the second buffer queue, the resource recycling is also implemented through the second queue array.
[0090] In a schematic embodiment, after each playback thread completes the playback of a first logical log record, the structure given back to the generation thread and the scanning thread is different, that is, the structure for the scanning queue, the first buffer queue / the second buffer queue is different. The scanning thread obtains Structure 1 from the scanning queue. The scanning thread will parse the content inside Structure 1, such as timing information, and then encapsulate some transaction information after parsing and the obtained Structure 1 into Structure 2. Multiple Structure 2s are connected together to form the first buffer queue / the second buffer queue. After the playback thread finishes playing back such a Structure 2, 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 the empty Structure 1, and the second empty structure form is the empty Structure 2. Thus, the first logical log in the form of the first empty structure is returned to the first sub-queue in the first queue array, and the first logical log in the form of the second empty structure is returned to the second sub-queue in the second queue array.
[0091] Similarly, after the scanning thread finishes playing back a second logical log record, it will return the empty Structure 1 to the generation thread, that is, return 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 stage of resource recycling, in the first queue array, a first sub-queue is separately 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 separately associated with each playback thread, and the second queue array is composed of multiple second sub-queues.
[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] After the scanning thread finishes playing back, the second logical log record in the first empty structure form is put back into the empty queue, realizing the release of the resources occupied by the scanning queue. The generation thread can batch obtain the resources in the empty queue and put in new logical log records, realizing the reuse of the recycled resources. The scanning thread and the generation thread hold the third queue lock for the empty queue.
[0095] After the playback thread finishes playing back, the first logical log record in the first empty structure form is put back into its own bucket queue in the first queue array, releasing the resources of the used scanning queue. Each playback thread has the fourth queue lock for this bucket queue. Compared with the previous situation where n playback threads, the generation thread, and the scanning thread shared one lock, the scope of lock control is reduced during resource recycling, so that after multiple playback threads finish playing back, they can each obtain the fourth queue lock of their own bucket queue, and there is no lock contention between them.
[0096] Considering that during the existing resource recycling, the first queue array and the second queue array are one array, and both the generation thread and the scanning thread have the queue lock for the entire queue array. When the generation thread occupies the queue array, each playback thread and the scanning thread cannot obtain the queue lock for the queue array, resulting in busy waiting.
[0097] Embodiments of the present invention also add a batch interface on the resource recycling side, distinguish the first queue array and the second queue array, and add sub-queues for each playback thread in the queue array. Each playback thread and the scanning thread only have the queue lock for the sub-queue associated with them, reducing the lock conflict and the scope of lock action between the generation thread and other threads, and at the same time reducing the holding time of the lock by the generation thread, thereby improving the playback speed and the recovery speed.
[0098] According to an embodiment of the present invention, the method further includes: calling 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; 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, parsing the new logical log and depositing the new logical log record into the scanning queue.
[0099] In one embodiment, the first logical log record and the second logical log record in the first empty structure form can be obtained from the first queue array and the second queue array at preset time intervals, such as obtaining all or part of the first logical log record and the second logical log record in the first empty structure form in the first queue array and the second queue array within the preset time interval. Alternatively, all or part of the first logical log record in the first empty structure form can be obtained only from the first queue array; all or part of the second logical log record in the first empty structure form can be obtained only from the second queue array.
[0100] After obtaining the first logical log record and / or the second logical log record, that is, after recycling resources, the new logical log is parsed and a new logical log record is stored in the scan queue.
[0101] According to an embodiment of the present invention, the generation thread is associated with a counter; calling 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: calling the generation thread to alternately obtain the first logical log record in the first empty structure form from the first sub-queue of the first queue array and the second logical log record in the first empty structure form from the third sub-queue based on the quantity data recorded by the counter, where, in one alternation process, the generation thread determines the first logical log record in the first empty structure form from one 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 recycles resources from the first queue array. For example, when obtaining the first logical log record in the first empty structure form from a certain first sub-queue in the first queue array, the first quantity data for the first sub-queue is incremented by 1; when obtaining the second logical log record in the first empty structure form from the third sub-queue, the second quantity data for the third sub-queue is incremented by 1. Thus, the alternation order of recycling resources from the playback thread and the scan thread can be determined according to 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 in the first empty structure form is obtained from a certain first sub-queue in the first queue array, and then the first data volume is increased; when the first quantity data increases, the second logical log record in the first empty structure form is obtained from the third sub-queue in the first queue array, and then the second data volume is increased, thus realizing an alternation process. It should be noted that in adjacent two alternation processes, the first logical log record in the first empty structure form is usually obtained from different first sub-queues associated with different playback threads, but the second logical log record in the first empty structure form is obtained from only one third sub-queue.
[0104] In another embodiment, for the first buffer queue / second buffer queue, the scan queue is called to recycle resources from the second sub-queues associated with each replay thread in the second queue array in sequence. The specific resource recycling operation is similar to the recycling of the above-mentioned first queue array and will not be elaborated here.
[0105] Through the alternating recycling of the first logical log record and the second logical log record, and the alternating recycling of the first logical log records of different replay threads in multiple alternating processes, the embodiments of the present invention can avoid the long waiting time caused by a certain thread getting stuck and continuously waiting for the release of resources by that thread, can timely recycle the logical log records in the form of the first empty structure, and timely supplement new logical log records into the scan queue, thus accelerating the replay speed.
[0106] Figure 4 Fig. shows an application scenario diagram of resource recycling according to another embodiment of the present invention.
[0107] As Figure 4 shown, in Embodiment 400, resources are recycled between the generation thread and replay thread 1 and replay thread 2 through the first queue array, and there are a first sub-queue 1 associated with replay thread 1, a first sub-queue 2 associated with replay thread 2, and a third sub-queue associated with the scan thread in the first queue array. The generation thread and the scan thread obtain logical log records through the scan queue and recycle resources through the third sub-queue. Thus, there will be no lock contention in the process of resource distribution and recycling between the generation thread and the scan thread.
[0108] According to the embodiments of the present invention, the above-mentioned queue-based interaction uses the Communicating Sequential Processes (CSP) model, such as the scan queue, the first buffer queue, and the second buffer queue. Communication between multiple threads is carried out through message passing instead of relying on shared memory.
[0109] In this process, the party depositing the logical log record / first logical log record / second logical log record into the queue can be regarded as the producer, and the party obtaining 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, hereinafter, the logical log record / first logical log record / second logical log record will be collectively referred to as the record. Communication between the producer and the consumer is carried out through the queue. The producer only focuses on the produced records and puts them into the queue, while the consumer takes out the records from the queue for processing. This mechanism effectively reduces the coupling degree between the producer and the consumer, enabling them to be developed, tested, and maintained independently. When it is necessary to increase the number of producers or consumers, simply create more threads and connect them to the queue.
[0110] For example, when increasing the playback speed by adding playback threads, only the first cache queue, the second cache queue, the first sub-queue in the first queue array, and the second sub-queue in the second queue array need to be created and associated for the newly added playback threads. After that, the playback threads can obtain, playback, and recycle the records with the help of the first cache queue, the second cache queue, the first sub-queue, and the second sub-queue, improving the flexibility and scalability of the entire system. Moreover, this flexibility enables the database system to easily handle different loads and demand changes.
[0111] In addition, the producer and the consumer can perform operations at different time points without waiting for each other to complete. After producing a record, the producer can immediately continue with the next production task, while the consumer can take out and process the records from the queue when available. This asynchrony improves the throughput and response speed of the database system, thus increasing the playback speed.
[0112] Figure 5 The interaction diagram between the queue, the queue array, and the threads according to a specific embodiment of the present invention is shown.
[0113] As Figure 5 shown, before playback, the generation thread can deposit logical log records into the scanning thread; the scanning thread, by judging the log type of the logical log, plays back the second logical log record by itself and deposits 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 deposits the first logical log record in the form of a second empty structure into the second sub-queue corresponding to the second queue array, and the scanning thread can continue to deposit new first logical log records into the first cache queue + the second cache queue by recycling this part of resources. In addition, the playback thread also deposits the first logical log record in the form of a first empty structure into the first sub-queue corresponding to the first queue array, and the scanning thread deposits the first logical log record in the form of a first empty structure into the third sub-queue of the first queue array. The generation thread continues to deposit new logical log records into the scanning queue by recycling the resources in the first queue array.
[0115] Figure 6 The flowchart of the method for database logical log playback according to a specific embodiment of the present invention is shown.
[0116] As Figure 6 shown, Embodiment 600 includes operations S601 to S608.
[0117] In operation S601, the logical log starts to be played back.
[0118] In operation S602, check whether there are unplayed logical log pages. The logical log is stored in pages, which are called logical log pages. It is possible to call other threads to determine whether there are unplayed logical log pages. If there are unplayed logical log pages, perform operation S603; if there are no unplayed logical log pages, perform operation S608.
[0119] In operation S603, the generation thread parses the logical log page to generate logical log records.
[0120] In operation S604, the scanning thread obtains the logical log records.
[0121] In operation S605, check whether there are timing requirements. In operation S605, determine whether the logical log corresponding to the logical log record has timing requirements, that is, determine whether the log type of the logical log corresponding to the logical log record is a timing type. If there are timing requirements, this logical log record is the second logical log record, and operation S607 is performed to be replayed by the scanning thread; if there are no timing requirements, this logical log record is the first logical log record, and operation S606 is performed to be replayed by the replay thread.
[0122] In operation S606, the replay thread obtains the first logical log record for replay.
[0123] In operation S607, the scanning thread obtains the second logical log record for replay.
[0124] In operation S608, end.
[0125] For the existing logical log recovery queue (the queue between the scanning thread and the replay thread), the present invention introduces a new queue mechanism to replace the original logical log recovery queue. The main innovation is reflected in: 1) The frequency of lock contention between the scanning thread and the replay thread is reduced. Since a new local second cache queue is added, the replay thread does not have to obtain from the first cache queue every time it obtains the first logical log record from the second cache queue, reducing the conflict probability of accessing the first cache queue simultaneously with the scanning thread. 2) A series of first logical log records are obtained from the first cache queue only when the second cache queue is completely obtained by the replay thread. The form of batch acquisition reduces the conflict probability of accessing the first cache queue simultaneously with the scanning thread. The new queue mechanism has a smaller lock granularity than the original queue lock, and at the same time, the batch acquisition method further reduces the lock competition between the scanning thread and the recovery thread.
[0126] Figure 7 Shows a block diagram of an apparatus for database logical log replay according to an embodiment of the present invention.
[0127] As Figure 7As shown, the apparatus 700 for database logical log playback includes a first calling module 710, a storage module 720, a second calling module 730, and a playback module 740.
[0128] The first calling module 710 is configured to call a scanning thread to scan multiple logical log records from a scanning queue, where the logical log records are generated after a generation thread parses logical logs.
[0129] The storage module 720 is configured to store a first logical log record among the multiple logical log records into a first cache queue associated with a playback thread, where 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 configured to call a playback thread. When it is determined that a 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 into the second cache queue associated with the playback thread.
[0131] The playback module 740 is configured to obtain the first logical log records one by one from the second cache queue of the playback thread and playback the logical logs corresponding to the first logical log records one by one.
[0132] According to embodiments of the present invention, any plurality of modules, sub-modules, units, and sub-units, or at least part of the functions of any of them can be implemented in one module. Any one or more of the modules, sub-modules, units, and sub-units according to embodiments of the present invention can be split into multiple modules for implementation. Any one or more of the modules, sub-modules, units, and sub-units according to embodiments of the present invention 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 chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by any other reasonable way of integrating or packaging circuits in hardware or firmware, or implemented in any one of the three implementation manners of software, hardware, and firmware, or in an appropriate combination of any several of them. Alternatively, one or more of the modules, sub-modules, units, and sub-units according to embodiments of the present invention can be at least partially implemented as a computer program module, and when the computer program module runs, it can execute corresponding functions.
[0133] For example, any combination of the first calling module 710, the storage module 720, the second calling module 730, and the playback module 740 may be combined and implemented in one module / unit / sub-unit, or any one of the modules / units / sub-units may 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 may 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 may 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 any other reasonable manner of integrating or packaging circuits, etc., implemented by hardware or firmware, or implemented in any one of the three implementation manners of software, hardware, and firmware, or in an appropriate combination of any several 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 run, corresponding functions may be executed.
[0134] It should be noted that the device part in the embodiments of the present invention corresponds to the method part in the embodiments of the present invention. For the description of the device part, please refer to the method part for details and will not be elaborated here.
[0135] Figure 8 The block diagram of an electronic device 800 suitable for implementing the method for database logical log playback according to an embodiment of the present invention is shown. Figure 8 The electronic device shown is only an example and should not impose any limitations on the functions and usage scope of the embodiments of the present invention.
[0136] As Figure 8 As shown, the electronic device 800 according to an embodiment of the present invention includes a processor 801, which may perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 802 or the program loaded from the storage part 808 into the random access memory (RAM) 803. The processor 801 may include, for example, a general microprocessor (such as a CPU), an instruction set processor, and / or a related chipset, and / or a dedicated microprocessor (such as an application specific integrated circuit (ASIC)), etc. The processor 801 may also include on-board 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 the RAM 803, various programs and data required for the operation of the electronic device 800 are stored. The processor 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. The processor 801 performs various operations of the method flow according to the embodiments of the present invention by executing the programs in the ROM 802 and / or the RAM 803. It should be noted that the programs can also be stored in one or more memories other than the ROM 802 and the RAM 803. The processor 801 can also perform various operations of the method flow according to the embodiments 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, and the input / output (I / O) interface 805 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 part 806 including a keyboard, a mouse, etc.; an output part 807 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage part 808 including a hard disk, etc.; and a communication part 809 including a network interface card such as a LAN card, a modem, etc. The communication part 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 a computer program read from it can be installed into the storage part 808 as needed.
[0139] According to an embodiment of the present invention, the method flow according to the embodiments 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 program codes for performing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network via the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the processor 801, the above functions defined in the system according to the embodiments of the present invention are executed. According to an embodiment of the present invention, the above-described systems, devices, apparatuses, modules, units, etc. can be implemented by computer program modules.
[0140] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; 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 embodiments 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: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In the present invention, the computer-readable storage medium may be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, apparatus, or device.
[0142] For example, according to an embodiment of the present invention, the computer-readable storage medium may include one or more memories other than the above-described ROM 802 and / or RAM 803 and / or ROM 802 and RAM 803.
[0143] An embodiment of the present invention also includes a computer program product, which includes a computer program that contains program code for executing the method provided by the embodiments of the present invention. When the computer program product runs on an electronic device, the program code is used to cause the electronic device to implement the method provided by the embodiments of the present invention.
[0144] When the computer program is executed by the processor 801, the above functions defined in the system / apparatus of the embodiments of the present invention are executed. According to an embodiment of the present invention, the above-described systems, apparatuses, modules, units, etc. may be implemented by computer program modules.
[0145] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices and magnetic storage devices. In another embodiment, the computer program may also be transmitted and distributed in the form of a signal on a network medium, and be downloaded and installed through the communication part 809, and / or be installed from the removable medium 811. The program code included in the computer program may be transmitted by any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0146] In accordance with embodiments of the present invention, program code for executing the computer programs provided by the embodiments 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 procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, such as Java, C++, Python, the "C" language, or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device can be connected to the user's 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., by connecting through the Internet using an Internet service provider).
[0147] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a portion of code that 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 blocks may occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and combinations of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions. Those skilled in the art can understand that the features described in the various embodiments of the present invention can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in the present invention. In particular, without departing from the spirit and teachings of the present invention, the features described in the various embodiments of the present invention can be combined and / or combined in various ways. All such combinations and / or combinations fall within the scope of the present invention.
[0148] The above describes the embodiments of the present invention. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of the present invention. Although the embodiments are described separately above, this does not mean that the measures in each embodiment cannot be used advantageously in combination. Without departing from the scope of the present invention, those skilled in the art can make various substitutions and modifications, and all such substitutions and modifications should 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 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 storing the multiple first logical log records in the second cache queue associated with the playback thread; 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; Calling the scanning thread to play back the second logical log record in a plurality of the logical log records according to the timing information of the second logical log record, wherein the plurality of the logical log records include the second logical log record whose log type is a timing type; 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.
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 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.
4. The method according to claim 1, 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.
5. The method according to claim 4, 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.
6. 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 A playback module, used for 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; Calling the scanning thread to play back the second logical log record in a plurality of the logical log records according to the timing information of the second logical log record, wherein the plurality of the logical log records include the second logical log record whose log type is a timing type; 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 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.
7. 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 5.
8. 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 5.
Citation Information
Patent Citations
Parallel playback method and device of database standby machine, electronic equipment and medium
CN115994053A