Database log processing method, storage medium and equipment
By detecting the data page modification amount in the database log processing method, and recording the data page only when the threshold exceeds the threshold, the problem of excessive database log data affecting synchronization performance is solved, and the synchronization efficiency of the main and backup databases is improved.
Patent Information
- Application Number
- CN202311864230.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-29
- Publication Date
- 2025-07-08
AI Technical Summary
During the database synchronization process, the large amount of data in the database log affects the performance of synchronous stream replication, and the prior art is difficult to effectively reduce the amount of data synchronization between the main and standby databases.
By detecting that the data page is modified, the database log sequence number corresponding to the modification operation is obtained, and whether the modified data volume exceeds the preset threshold is determined. The data page is recorded and updated in the database log only when the threshold is exceeded. After the log redo point, the data page is recorded and updated to reduce the generation of page mirror data.
It reduces the amount of data in the database log, improves the synchronization efficiency between the master and backup databases, and reduces the frequency and pressure of data synchronization.
Smart Images

Figure CN120277148A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of databases, and in particular to a method for processing database logs, a storage medium, and a device. Background Art
[0002] During the use of a database, database logs are recorded. An important function of database logs is to build a master-slave database cluster. Briefly speaking, after the master-slave database cluster is built, the master database provides read and write services externally and continuously generates database logs. The database logs are transmitted to the slave database through streaming replication, so that the slave database is almost identical to the master database.
[0003] In order to strictly keep the data of the master database and the slave database consistent, the synchronous streaming replication mode is usually adopted. In the synchronous streaming replication mode, after the master database sends a database log to the slave database, it needs to wait for the slave database to store this database log locally or replay it successfully before the master database can continue to execute. Therefore, the amount of data of the database logs that the master database needs to transmit to the slave database is an important factor affecting the performance of synchronous streaming replication. Summary of the Invention
[0004] An object of the present invention is to provide a method for processing database logs, a storage medium, and a device that can reduce the amount of data of the database logs to be transmitted.
[0005] In particular, the present invention provides a method for processing database logs, including:
[0006] Detecting that a data page is modified;
[0007] Obtaining the log sequence number of the database log corresponding to the modification operation, denoted as the modification sequence number;
[0008] Reading the record mark sequence number of the data page, where the record mark sequence number is the log sequence number corresponding to the data page when it was last recorded in the database log;
[0009] If the record mark sequence number is less than or equal to the log replay point of the database, detecting whether the amount of modified data between the modification sequence number and the record mark sequence number of the data page is greater than or equal to a preset threshold;
[0010] If it is greater than or equal to the preset threshold, recording the data page in the database log and updating the record mark sequence number to the modification sequence number.
[0011] Optionally, after the step of detecting whether the amount of log data between the modification sequence number and the record mark sequence number is greater than or equal to a preset threshold includes:
[0012] If it is less than the preset threshold, do not record the data page into the database log and keep the record mark sequence number.
[0013] Optionally, before the step of detecting whether the amount of log data between the modification sequence number and the record mark sequence number is greater than or equal to a preset threshold, it includes:
[0014] Check whether the record mark sequence number is less than or equal to the log restart point. If so, execute the step of detecting whether the amount of log data between the modification sequence number and the record mark sequence number is greater than or equal to a preset threshold. If not, do not record the data page into the database log and keep the record mark sequence number.
[0015] Optionally, after the complete content of a database log containing page mirror data is determined, where the page mirror data is the data of the data page recorded in the database log, the processing method of the database log further includes:
[0016] Obtain the complete content of the database log;
[0017] Pre-assemble the database log into a structure composed of an assembly linked list and a page data linked list connected after the assembly linked list. The page data linked list is a linked list composed of the page mirror data in the database log, and the assembly linked list is a linked list composed of other data except the page mirror data in the database log;
[0018] Read and record the log sequence number of the database log, denoted as the reference sequence number;
[0019] Obtain the page data linked list of the database log, denoted as the page data linked list to be stored;
[0020] According to the reference sequence number, store the page data linked list to be stored into a preset global page data linked list in ascending order of the log sequence number, so that the page data linked lists in the global page data linked list are connected in ascending order of the log sequence number;
[0021] Store the assembly linked list part of the database log into the log buffer.
[0022] Optionally, before the step of storing the page data linked list to be stored into a preset global page data linked list in ascending order of the log sequence number according to the reference sequence number, it includes:
[0023] Obtain the preset lock of the global page data linked list.
[0024] Optionally, the global page data linked list is pre-configured with a preset number of preset locks, and each of the preset locks can be bound to a range of log sequence numbers. The step of obtaining the preset lock of the global page data linked list includes:
[0025] Obtain an available preset lock of the global page data linked list, where the available preset lock is a preset lock whose bound log sequence number range includes the reference sequence number.
[0026] Optionally, the method for processing the database log further includes:
[0027] Detect an enabling signal for flushing the database log in the cache to disk;
[0028] Obtain the database logs in the cache that meet the preset disk flushing rules, denoted as disk-flushable logs. The database logs that meet the preset disk flushing rules are at least one database log that has been completely written into the cache and whose log sequence numbers are consecutive starting from the log sequence number of the last database log completed in the previous disk flushing;
[0029] Find the corresponding page data linked list from the global page data linked list according to the log sequence numbers of the disk-flushable logs, denoted as the disk-flushable page data linked list;
[0030] Copy the page mirror data in the disk-flushable page data linked list to the end of a preset page mirror data storage table in sequence according to the connection order;
[0031] Partially flush the assembled linked list of the disk-flushable logs to disk.
[0032] Optionally, after the step of copying the data content corresponding to the disk-flushable page data linked list to the end of a preset page mirror data storage table, it includes:
[0033] Remove the disk-flushable page data linked list from the global page data linked list.
[0034] In another aspect, the present invention further provides a machine-readable storage medium, on which a machine-executable program is stored. When the machine-executable program is executed by a processor, the method for processing the database log according to any one of the above is implemented.
[0035] In yet another aspect, the present invention further provides a computer device, including a memory, a processor, and a machine-executable program stored on the memory and running on the processor. When the processor executes the machine-executable program, the method for processing the database log according to any one of the above is implemented.
[0036] The method for processing database logs, storage medium and device of the present invention set a preset threshold. After detecting that a data page is modified, obtain the log sequence number of the database log corresponding to the modification operation, denoted as the modification sequence number, and read the record mark sequence number of the data page. When the record mark sequence number is less than or equal to the log replay point of the database, detect whether the amount of modified data between the modification sequence number and the record mark sequence number of the data page is greater than or equal to the preset threshold. When it is greater than or equal to the preset threshold, record the data page into the database log and update the record mark sequence number to the modification sequence number. That is to say, after detecting that a data page is modified, only when the data page has not been recorded into the database log after the log replay point, and the amount of modified data between the modification sequence number and the record mark sequence number of the data page is greater than or equal to the preset threshold, will the data page be recorded into the database log. Even for the first modification of the data page after the log replay point, when the amount of modified data between the modification sequence number and the record mark sequence number of the data page is less than the preset threshold, the data page will not be recorded into the database log. Therefore, the solution of the present invention can reduce the frequency of writing data pages into the database log, that is, can reduce the frequency of generating page mirror data in the database log, thereby can reduce the data volume of the database log to a certain extent, and further helps to reduce the data synchronization volume between the primary and standby databases and improve the synchronization efficiency between the primary and standby databases.
[0037] From the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more clear about the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Some specific embodiments of the present invention will be described in detail hereinafter with reference to the accompanying drawings in an exemplary but not restrictive manner. The same reference numerals in the drawings denote the same or similar components or parts. Those skilled in the art should understand that these drawings are not necessarily drawn to scale. In the drawings:
[0039] Figure 1 is a schematic diagram of a database log in the prior art;
[0040] Figure 2 is a schematic flowchart of a method for processing a database log according to an embodiment of the present invention;
[0041] Figure 3 is a schematic flowchart of a method for processing a database log according to another embodiment of the present invention;
[0042] Figure 4 is a first schematic diagram of a database log according to an embodiment of the present invention;
[0043] Figure 5It is the second schematic diagram of the database log according to an embodiment of the present invention;
[0044] Figure 6 It is the schematic diagram of the page data chain of the database log according to an embodiment of the present invention;
[0045] Figure 7 It is the schematic diagram of the page mirror data content of the database log according to an embodiment of the present invention;
[0046] Figure 8 It is the third schematic diagram of the database log according to an embodiment of the present invention;
[0047] Figure 9 It is the schematic diagram of the global page data linked list according to an embodiment of the present invention;
[0048] Figure 10 It is the schematic flowchart of the processing method of the database log according to another embodiment of the present invention;
[0049] Figure 11 It is the schematic flowchart of the processing method of the database log according to another embodiment of the present invention;
[0050] Figure 12 It is the schematic flowchart of the step of determining the required range of new log sequence numbers according to the first preset rule in the processing method of the database log according to another embodiment of the present invention;
[0051] Figure 13 It is the schematic flowchart of the step of determining the required range of new log sequence numbers according to the second preset rule in the processing method of the database log according to another embodiment of the present invention;
[0052] Figure 14 It is the schematic flowchart of the step of storing the page data linked list to be stored into the global page data linked list in the processing method of the database log according to another embodiment of the present invention;
[0053] Figure 15 It is the schematic flowchart of the processing method of the database log according to another embodiment of the present invention;
[0054] Figure 16 It is the schematic diagram of the page mirror data storage table according to an embodiment of the present invention;
[0055] Figure 17 It is the schematic diagram of the machine-readable storage medium according to an embodiment of the present invention;
[0056] Figure 18 It is the schematic diagram of the computer device according to an embodiment of the present invention. Detailed implementation manners
[0057] Those skilled in the art should understand that the embodiments described below are only a part of the embodiments of the present invention, rather than all the embodiments of the present invention. This part of the embodiments is intended to explain the technical principles of the present invention and is not intended to limit the protection scope of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts should still fall within the protection scope of the present invention.
[0058] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a fixed sequence list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, apparatus, or device (such as a computer-based system, a system including a processor, or other systems that can fetch and execute instructions from the instruction execution system, apparatus, or device), or used in combination with these instruction execution systems, apparatus, or devices.
[0059] The flowchart provided by the present invention is not intended to indicate that the operations of the method will be executed in any specific order, or that all operations of the method are included in every case. In addition, the method may include additional operations. Within the scope of the technical concept provided by the method of this embodiment, additional changes can be made to the above method.
[0060] To facilitate the understanding of this solution, the operation mode of the database in the prior art will be described. First, during the process of modifying the database data, the database data on the disk is not directly modified. Instead, the data on the disk is extracted into the cache in units of data pages (the data to be modified is located in the data pages), modified in the cache, and then written back to the disk later.
[0061] Further, when modifying the data pages in the cache, database logs will be generated. As Figure 1 shown, the existing database logs generally include two parts: a header and a data area. The data area records various modification operations on the data pages. At the same time, there is also a kind of data in the data area that is page mirror data. The page mirror data is formed after recording the complete page information of a data page in the database log. In the prior art, after the log redo point (the log redo point is a log sequence number. Before this log sequence number, the database logs have all been written back to the disk and the information reflected by the written-back logs and all the data in the actual database on the disk is the same), if the data of a data page in the cache is modified for the first time, then the entire page information of the data page after the first modification will be recorded in the database log, and then page mirror data will be generated.
[0062] Because during the process of data page disk write, it is possible that a crash occurs during the disk write of a data page, resulting in a situation where the disk-written data page contains a mixture of old and new data. Therefore, by generating page mirror data, the page information recorded in the page mirror data can be used to replace the broken page with the mixture of old and new data, and then replaying the subsequent operations recorded in the database log can complete the recovery of the data page. Therefore, page mirror data is important data for ensuring the security and stability of the database where it is located.
[0063] As Figure 2 shown, in an embodiment of the present application, the method for processing a database log generally includes:
[0064] Step S101, detecting that a data page is modified. Specifically, that is, detecting that a modification operation is performed on the data page in the cache.
[0065] Step S102, obtaining the log sequence number of the database log corresponding to the modification operation, denoted as the modification sequence number. Specifically, the modification operation on the data page is recorded in the database log, that is, obtaining the log sequence number of the database log where the modification operation is located. The log sequence number is incrementally configured during the formation of the database log and can identify the order of the database log.
[0066] Step S103, reading the record mark sequence number of the data page, where the record mark sequence number is the log sequence number corresponding to when the data page was last recorded in the database log. Specifically, that is, obtaining the log sequence number of the database log where the currently modified data page was last recorded in the database log.
[0067] Step S104, checking whether the record mark sequence number is less than or equal to the log redo point. If so, execute step S105; if not, execute step S107. Specifically, as described above, the log redo point is a log sequence number, and all database logs before this log sequence number have been disk-written and make the information reflected by the disk-written logs and all data in the actual database on the disk the same. That is to say, both the record mark sequence number and the log redo point are log sequence numbers, and the front-back relationship of their order can be known by comparison. Therefore, it is to check whether the record mark sequence number is before the log redo point.
[0068] Step S105: Detect whether the amount of modified data between the modified sequence number and the record mark sequence number of the data page is greater than or equal to a preset threshold. If so, execute Step S106; if not, execute Step S107. Specifically, the preset threshold is a modifiable setting value. For example, it can be 1GB, 1.5GB, 2GB, etc. If the record mark sequence number is less than or equal to the log redo point, it means that the node where the current modified data page was last recorded in the database log is before the log redo point. That is to say, after the log redo point, this data page has not been recorded in the database log yet.
[0069] Because the record mark sequence number marks the log sequence number of the database log where the data page was last recorded in the database. That is to say, it is to judge whether the amount of modified data recorded during the process from the page information of the database when it was last recorded in the database log to the page information obtained after the current modification is greater than or equal to the preset threshold.
[0070] Step S106: Record the data page in the database log and update the record mark sequence number to the modified sequence number. Specifically, if the amount of modified data between the modified sequence number and the record mark sequence number of the data page is greater than or equal to the preset threshold, then record the page information of the current modified data page in the database log. And update the record mark sequence number to the modified sequence number.
[0071] Step S107: Do not record the data page in the database log and keep the record mark sequence number. Specifically, if the amount of modified data between the modified sequence number and the record mark sequence number of the data page is greater than or equal to the preset threshold, then do not record the data page in the database log and keep the record mark sequence number. In other words, no special processing is done. That is to say, even if the current modification of the data page is the first modification after the log redo point, the data page is not recorded in the database log.
[0072] In addition, if the record mark sequence number is greater than the log redo point, it means that the node where the current modified data page was last recorded in the database log is after the log redo point. That is to say, after the log redo point, this data page has already been recorded in the database log. Then the data page after this modification does not need to be recorded in the database log anymore.
[0073] Exemplarily, there is a data page A in the cache. The current record mark sequence number of data page A is LSN1, and the log redo point of the database is LSN2. When data page A is modified by operation a, the log sequence number of the database log where operation a is located is obtained as LSN3, and the modification sequence number is LSN3. First, check whether LSN1 is less than or equal to LSN2. If so, detect whether the amount of modified data of data page A between LSN1 and LSN3 is greater than or equal to a preset threshold. If so, record the page information of data page A after being modified by operation a into the database log, and update the record mark sequence number to LSN3.
[0074] If LSN1 is greater than LSN2, it means that after the log redo point, the page information of data page A at a certain moment has been recorded in the database log. Then, before the log redo point changes, data page A does not need to be recorded in the database log anymore.
[0075] If LSN1 is less than or equal to LSN2 and the amount of modified data of data page A between LSN1 and LSN3 is less than the preset threshold, it means that after the log redo point, the complete page information of data page A has not been recorded in the database log. However, in this embodiment, the page information of data page A after being modified by operation a is not recorded in the database log either, and the record mark sequence number remains LSN1.
[0076] In the solution of this embodiment, by setting a preset threshold, after detecting that a data page is modified, obtain the log sequence number of the database log corresponding to the modification operation, denoted as the modification sequence number, read the record mark sequence number of the data page. When the record mark sequence number is less than or equal to the log redo point of the database, detect whether the amount of modified data of the data page between the modification sequence number and the record mark sequence number is greater than or equal to the preset threshold. When it is greater than or equal to the preset threshold, record the data page in the database log and update the record mark sequence number to the modification sequence number. That is to say, after detecting that a data page is modified, only when the data page has not been recorded in the database log after the log redo point and the amount of modified data of the data page between the modification sequence number and the record mark sequence number is greater than or equal to the preset threshold, will the data page be recorded in the database log. Even if it is the first modification of the data page after the log redo point, when the amount of modified data of the data page between the modification sequence number and the record mark sequence number is less than the preset threshold, the data page will not be recorded in the database log.
[0077] Therefore, the solution of this embodiment can reduce the frequency of writing data pages into the database log, that is, it can reduce the frequency of generating page mirror data in the database log, thereby reducing the amount of data in the database log to a certain extent, and further helping to reduce the data synchronization amount between the primary and standby databases and improve the synchronization efficiency between the primary and standby databases.
[0078] Refer to Figure 1 As shown, in the database, the length of a database log is fixed. As the modification operations continuously increase, it will reach the capacity limit of a database log or be filled up. At this time, the log information generated later needs to be written into the next database log. For the filled database log, the complete content of the database log is determined.
[0079] As Figure 3 shown, in one embodiment, after the complete content of a database log containing page mirror data is determined, the page mirror data is the data page data recorded in the database log. Specifically, that is, the complete content of a database log is determined, and there is page mirror data in the data area of the database log. In other words, the page information of the data page is recorded in this database log. Then, generally, the processing method of the database log further includes:
[0080] Step S201, obtain the complete content of the database log. Specifically, that is, obtain all the content in the database log with the determined complete content. Refer to Figure 1 shown, that is, obtain all the content of the header and data area of a database log.
[0081] Step S202, pre-assemble the database log into a structure composed of an assembly linked list and a page data linked list connected after the assembly linked list. The page data linked list is a linked list composed of the page mirror data in the database log, and the assembly linked list is a linked list composed of other data in the database log except the page mirror data. Specifically, that is, connect the page mirror data of the database log in the form of a page data linked list after the assembly linked list composed of other data of the database log.
[0082] Refer to Figures 4 to 8 shown. Specifically, taking the database log with two page mirror data nodes in the complete content as an example, Figure 4 is an example of the linked list form of an original database log with page mirror data, Figure 5 is Figure 4 an example of the linked list form after removing the page mirror data from the linked list in, where next represents pointing to the next node; len represents the len function for calculating the length of the corresponding data; head data represents the header data of the database log; page data represents all the page mirror data in the database log; tupledata and main data represent other data in the database log except the page mirror data. Figure 6For the simplified example of the linked list of two page mirror data nodes in the database log, wal1 pagedata1 and wal1 page data2 are just simple notations used to represent two different page mirror data nodes belonging to the same database log, and do not represent specific content. Figure 7 For the example of the specific content of a page mirror data node, RelFileNode represents the location information of the table to which the data page corresponding to this page mirror belongs on the disk, BlockNumber represents the block number of the data page corresponding to this page mirror in the table to which it belongs. Therefore, RelFileNode and BlockNumber can determine the location of the data page corresponding to the page mirror data on the disk, lsn represents the log sequence number of the database log to which the page mirror data belongs, page data is the complete information of the data page recorded by this page mirror data node, and next points to the next node. Figure 8 For the example of the finally formed database log.
[0083] During the assembly process of the database log, first remove the page mirror data in the database log, as Figures 4 to 5 shown. Then form the page data linked list with the page mirror data in the order in the database log, as Figure 6 shown. Then, connect the page data linked list to the back of the linked list composed of other data in the database log, so as to assemble the database log into a structure composed of an assembled linked list and a page data linked list connected after the assembled linked list, as Figure 8 shown. That is to say, Figure 7 can be regarded as Figure 6 the schematic diagram of the specific content of a page mirror data node in. Figure 8 The assembled linked list in represents Figure 5 the linked list of the database log in, that is, the linked list composed of other data in the database log except the page mirror data.
[0084] Step S203, read and record the log sequence number of the database log, denoted as the reference sequence number. After the database is assembled, read and record the log sequence number of this database log, denoted as the reference sequence number.
[0085] Step S204, obtain the page data linked list of the database log, denoted as the page data linked list to be stored. Specifically, remove the page data linked list in the database log from the database log. Refer to Figure 8 shown, that is, remove the part of the linked list after connecting the assembled linked list, and the removed part is the page data linked list to be stored. In simple terms, it is the linked list composed of the page mirror data of this database log as Figure 6 shown.
[0086] Step S205: Store the linked list of page data to be stored into a preset global linked list of page data in ascending order of log sequence numbers according to the reference sequence number, so that the linked lists of page data in the global linked list of page data are connected in turn in ascending order of log sequence numbers. Specifically, the global linked list of page data is located in the shared memory, that is, the cache, and is used to store the linked list of page data. After removing the linked list of page data of the database log, the linked list of page data is stored in the global linked list of page data, that is, the linked list of page data to be stored is stored in the global linked list of page data. And when storing, the linked list of page data to be stored is stored in ascending order of log sequence numbers. In other words, the global linked list of page data is a linked list composed of linked lists of page data, and the linked lists of page data in the global linked list of page data are connected in turn in ascending order of log sequence numbers.
[0087] Refer to Figure 9 As shown, it is a simple illustration of the global linked list of page data storing two linked lists of page data. page_data_list_local represents the linked list of page data of a database log, and page_data_list_global represents the global linked list of page data. Among them, wal1 and wal2 are only used to indicate that the two linked lists of page data belong to different database logs.
[0088] Specifically, according to the size relationship between the reference sequence number and the log sequence numbers corresponding to the existing linked lists of page data in the global linked list of page data, the linked list of page data to be stored is stored in the position before the first linked list of page data in the global linked list of page data whose log sequence number is greater than the reference sequence number from front to back, or in other words, stored in the position after the first linked list of page data whose log sequence number is less than the reference sequence number from back to front.
[0089] Step S206: Store the assembled list part of the database log into the log buffer. Specifically, allocate a storage position in the log buffer according to the length of the assembled list part, that is, allocate a storage position in the log buffer according to the length of the database log after removing the linked list of page data, and store the assembled list part of the database log into the position allocated for it in the log buffer. So far, both the linked list of page data part and the assembled list part of a database log have been written into the cache, that is to say, all the contents of a database log have been written into the cache.
[0090] It should be noted that there is no strict sequence relationship between this step and the step of storing the linked list of page data into the global linked list of page data.
[0091] In the solution of this embodiment, after the complete content of a database log containing page mirror data is determined, the complete content of the database log is obtained. The database log is pre-assembled into a structure consisting of an assembly linked list and a page data linked list connected after the assembly linked list. The log sequence number of the database log is read and recorded, denoted as the reference sequence number. The page data linked list of the database log is obtained, denoted as the page data linked list to be stored. According to the reference sequence number, the page data linked list to be stored is stored in a preset global page data linked list in ascending order of the log sequence number. That is to say, the page mirror data in the database log is separated from the database log in the form of a page data linked list and stored separately in the global page data linked list. Then, during the subsequent disk writing process, the page mirror data in the database log and other data except the page mirror data can be disk-written separately. Therefore, when this database synchronizes the database log to other standby databases, it can synchronize only other data except the page mirror data, thereby reducing the data synchronization volume between the master and standby databases and helping to improve the synchronization efficiency. Moreover, the page mirror data of the database log is still stored on the disk, which can also ensure the security and stability of this database.
[0092] Moreover, since the amount of modified data between the modification sequence number and the record mark sequence number of the data page is greater than or equal to a preset threshold, the data page is recorded in the database log, that is, the page mirror data is generated less, so the disk writing pressure of the page data linked list is also reduced.
[0093] In addition, by storing the page data linked list to be stored in the preset global page data linked list in ascending order of the log sequence number according to the reference sequence number, the page data linked lists in the global page data linked list are connected in ascending order of the log sequence number in turn. In the subsequent disk writing stage, there is no need to perform additional sorting work on the global page data linked list, reducing the work pressure in the disk writing stage and improving the disk writing efficiency.
[0094] As Figure 10 shown, in one embodiment, the processing method of the database log generally includes:
[0095] Step S301, obtaining the complete content of the database log.
[0096] Step S302, pre-assembling the database log into a structure consisting of an assembly linked list and a page data linked list connected after the assembly linked list.
[0097] Step S303, reading and recording the log sequence number of the database log, denoted as the reference sequence number.
[0098] Step S304, obtaining the page data linked list of the database log, denoted as the page data linked list to be stored.
[0099] Step S305: Obtain the preset lock of the global page data linked list. Specifically, the global page data linked list is pre-configured with a preset lock, and the preset lock is a mutex lock. During the process of storing the page data linked list to be stored into the global page data linked list, first obtain the preset lock of the global page data linked list, so that only the process that obtains the preset lock can execute the task of storing the page data linked list to be stored into the global page data linked list, avoiding the chaos of the sorting of the page data linked lists in the global page data linked list.
[0100] Step S306: Store the page data linked list to be stored into the preset global page data linked list in ascending order of the log sequence number according to the reference sequence number, so that the page data linked lists in the global page data linked list are connected in ascending order of the log sequence number.
[0101] Step S307: Release the preset lock of the global page data linked list. Specifically, after the page data linked list to be stored completes the storage task in the global page data linked list, release the preset lock obtained during the storage process.
[0102] Step S308: Store the assembled linked list part of the database log into the log buffer.
[0103] In the solution of this embodiment, by obtaining the preset lock of the global page data linked list before the step of storing the page data linked list to be stored into the preset global page data linked list in ascending order of the log sequence number, only the process that obtains the preset lock can execute the task of storing the page data linked list to be stored into the global page data linked list, avoiding the chaos of the sorting of the page data linked lists in the global page data linked list.
[0104] It should be noted that the steps not detailed in this embodiment refer to the foregoing.
[0105] As Figure 11 shown, in one embodiment, the global page data linked list is pre-configured with a preset number of preset locks, and each preset lock can bind a range of log sequence numbers. The step of obtaining the preset lock of the global page data linked list includes: obtaining an available preset lock of the global page data linked list, and the available preset lock is a preset lock whose bound log sequence number range includes the reference sequence number. The preset number can be set as needed, for example, it can be 8, 9 or 10, etc. Each preset lock can bind a range of log sequence numbers, which is a range that is open at the front and closed at the back, and the log sequence number ranges bound by each preset lock do not overlap. Specifically, each preset lock and its corresponding log sequence number range are encapsulated in a structure. Exemplarily, the log sequence number range of a preset lock is (LSN1, LSN2], that is, the range where the log sequence number is greater than LSN1 and less than or equal to LSN2.
[0106] In this embodiment, the processing method of the database log generally includes:
[0107] Step S401, obtain the complete content of the database log.
[0108] Step S402, pre-assemble the database log into a structure composed of an assembly linked list and a page data linked list connected after the assembly linked list.
[0109] Step S403, read and record the log sequence number of the database log, denoted as the reference sequence number.
[0110] Step S404, obtain the page data linked list of the database log, denoted as the to-be-stored page data linked list.
[0111] Step S405, detect whether there is a pre-set lock that has been used in the global page data linked list. If so, execute Step S406; if not, execute Step S414. A pre-set lock that has been used refers to a pre-set lock with a bound log sequence number range, that is, detect whether there is a pre-set lock with a bound log sequence number range in the global page data linked list.
[0112] Step S406, detect whether there is an available pre-set lock among the pre-set locks that have been used in the global page data linked list. If so, execute Step S417; if not, execute S407. Specifically, that is, detect whether the reference sequence number is within the log sequence number range of a pre-set lock that has been used.
[0113] Step S407, determine the required new log sequence number range according to the first preset rule, and the reference sequence number is within the new log sequence number range. If there is no available pre-set lock among the pre-set locks that have been used, that is, the log sequence number of the to-be-stored page data linked list is not within the log sequence number range of the pre-set lock that has been used, then a new range of pre-set locks needs to be configured for the to-be-stored page data linked list. At this time, it is necessary to first determine the new log sequence number range that includes the log sequence number of the to-be-stored page data linked list.
[0114] Refer to Figure 12 As shown, specifically, this step includes:
[0115] Step S501, obtain the maximum value of the log sequence number ranges bound by all the pre-set locks that have been used in the global page data linked list, denoted as the first sequence number. Specifically, that is, find the maximum value from the log sequence number ranges bound by all the pre-set locks that have been used.
[0116] Step S502, determine whether the difference between the reference sequence number and the first sequence number is greater than the set threshold. If so, execute Step S503; if not, execute Step S504. Specifically, the set threshold is a modifiable preset value. After finding the first sequence number, subtract the first sequence number from the reference sequence number to get the difference between the two, and compare this difference with the set threshold to determine whether the difference is greater than the set threshold.
[0117] Step S503: Determine that the range of the newly added log sequence numbers is greater than the first sequence number and less than or equal to the reference sequence number. If the difference between the reference sequence number and the first sequence number is greater than the set threshold, the range of the newly added log sequence numbers is greater than the first sequence number and less than or equal to the reference sequence number.
[0118] Step S504: Determine that the range of the newly added log sequence numbers is greater than the first sequence number and less than or equal to the first sequence number plus the set threshold. If the difference between the reference sequence number and the first sequence number is not greater than the set threshold, the range of the newly added log sequence numbers is greater than the first sequence number and less than or equal to the first sequence number plus the set threshold.
[0119] Exemplarily, the set threshold is 4, and there are two used preset locks in the global page data linked list. The log sequence number ranges bound by the two used preset locks are (0, 5] and (5, 10] respectively.
[0120] If the log sequence number of the page data linked list to be stored, that is, the reference sequence number, is 15, then the range of the newly added log sequence numbers needs to be determined. The maximum value among the log sequence number ranges bound by the two used preset locks, that is, the first sequence number, is 10. The difference between the reference sequence number and the first sequence number is 5, which is greater than the set threshold of 4. Then the range of the newly added log sequence numbers is (10, 15], that is, greater than the first sequence number and less than or equal to the reference sequence number.
[0121] If the log sequence number of the page data linked list to be stored, that is, the reference sequence number, is 13, then the range of the newly added log sequence numbers needs to be determined. The maximum value among the log sequence number ranges bound by the two used preset locks, that is, the first sequence number, is 10. The difference between the reference sequence number and the first sequence number is 3, which is less than the set threshold of 4. Then the range of the newly added log sequence numbers is (10, 14], that is, greater than the first sequence number and less than or equal to the first sequence number plus the set threshold.
[0122] It should be noted that the above numbers are only simple illustrations for the convenience of explanation and understanding, and do not represent the actual form of the log sequence numbers.
[0123] It should be noted that in some other embodiments, the range of the newly added log sequence numbers can also be directly determined to be greater than the first sequence number and less than or equal to the reference sequence number without setting a set threshold and without judgment.
[0124] Step S408: Determine whether there is still an unused preset lock in the global page data linked list. If so, execute Step S409; if not, execute Step S411. Specifically, that is to check whether all the preset locks pre-configured in the global page data linked list have been used and whether there are still unused preset locks.
[0125] Step S409: Obtain a pre-set lock from the unused pre-set locks in the global page data linked list, and denote it as the pre-set lock to be assigned. Specifically, if there are still unused pre-set locks, obtain one from them.
[0126] Step S410: Bind the newly added log sequence number range to the pre-set lock to be assigned to make it an available pre-set lock. Execute step S417. Since the log sequence number of the page data linked list to be stored is within the newly added log sequence number range, after binding the newly added log sequence number range to the pre-set lock to be assigned, there will be an available pre-set lock.
[0127] Step S411: Find two pre-set locks with the smallest maximum value among the log sequence number ranges bound to the used pre-set locks, and denote them as the first pre-set lock to be modified and the second pre-set lock to be modified. The maximum value of the log sequence number range of the first pre-set lock to be modified is less than the maximum value of the log sequence number range of the second pre-set lock to be modified. Specifically, each used pre-set lock is bound to a log sequence number range corresponding to a maximum value. Obtain the maximum values of the log sequence number ranges bound to all used pre-set locks, and then find the two smallest maximum values from all the maximum values. The pre-set locks corresponding to the log sequence number ranges of the two smallest maximum values are the first pre-set lock to be modified and the second pre-set lock to be modified. And the maximum value of the log sequence number range of the first pre-set lock to be modified is less than the maximum value of the log sequence number range of the second pre-set lock to be modified.
[0128] Step S412: Modify the maximum value of the log sequence number range of the first pre-set lock to be modified to the maximum value of the log sequence number range of the second pre-set lock to be modified. Specifically, that is to modify the log sequence number range bound to the first pre-set lock to be modified so that it includes the log sequence number range of the second pre-set lock to be modified.
[0129] Step S413: Bind the newly added log sequence number range to the second pre-set lock to be modified to make it an available pre-set lock. Execute step S417.
[0130] Exemplarily, it is determined that the newly added log sequence number range is (10, 15]. There are only two pre-set locks in the global page data linked list and both are used, and the bound log sequence number ranges are (0, 5] and (5, 10] respectively. Then the log sequence number range of the first pre-set lock to be modified is (0, 5], and the log sequence number range of the second pre-set lock to be modified is (5, 10]. Then, modify the log sequence number range of the first pre-set lock to be modified to (0, 10], and the log sequence number range of the second pre-set lock to be modified is (10, 15].
[0131] Step S414, determine the required range of new log sequence numbers according to the second preset rule, and the reference sequence number is within the range of new log sequence numbers. Specifically, if there is no used preset lock in the global page data linked list, that is, all the preset locks in the global page data linked list have not been bound to the log sequence number range yet. That is, there is no available preset lock, then a new range of preset locks needs to be configured for the page data linked list to be stored. At this time, it is necessary to first determine the new log sequence number range that includes the log sequence number of the page data linked list to be stored.
[0132] Refer to Figure 13 As shown, this step includes:
[0133] Step S601, obtain the log sequence number corresponding to the currently last disk-written database log, denoted as the second sequence number. Specifically, that is, the log sequence number of the currently last database log written to the disk.
[0134] Step S602, determine whether the difference between the reference sequence number and the second sequence number is greater than the set threshold. If so, execute Step S603; if not, execute Step S604.
[0135] Step S603, determine that the new log sequence number range is greater than the second sequence number and less than or equal to the reference sequence number.
[0136] Step S604, determine that the new log sequence number range is greater than the second sequence number and less than or equal to the second sequence number plus the set threshold.
[0137] Specifically, the specific execution methods of Step S602 to Step S604 refer to those described in Step S502 to Step S504 in the previous text, and will not be elaborated here.
[0138] Step S415, obtain a preset lock. Since all the preset locks in the global page data linked list are in the unused state, a preset lock can be directly obtained from it.
[0139] Step S416, bind the new log sequence number range to the preset lock to make it an available preset lock. Since the log sequence number of the page data linked list to be stored is within the new log sequence number range, after binding the new log sequence number range to the preset lock, there will be an available preset lock. Then execute Step S417.
[0140] Step S417, obtain the available preset lock of the global page data linked list. After making the global page data linked list have an available preset lock through various methods, the available preset lock can be obtained, and then the subsequent step of storing the page data linked list to be stored into the global page data linked list in ascending order of the log sequence number according to the reference sequence number can be executed.
[0141] Refer to Figure 14As shown, specifically, the steps of storing the linked list of page data to be stored in the global linked list of page data in ascending order of log sequence numbers according to the reference sequence number include:
[0142] Step S701, check whether there is a basic linked list of page data in the global linked list of page data. The basic linked list of page data is the linked list of page data within the range of log sequence numbers of the available preset lock. If so, execute step S702; if not, execute step S703. Specifically, that is, for the range of log sequence numbers bound by the available preset lock, whether there is a linked list of page data with a log sequence number within this range that has been stored in the global linked list of page data.
[0143] Step S702, connect the linked list of page data to be stored and the basic linked list of page data in ascending order of log sequence numbers according to the reference sequence number. Specifically, if there is a basic linked list of page data in the global linked list of page data, it means that there is a basic connection node for the linked list of page data to be stored within the range of log sequence numbers of the available preset lock. Just connect the linked list of page data to be stored to the basic linked list of page data in ascending order of log sequence numbers.
[0144] Specifically, traverse all the basic linked lists of page data from the back to the front. If the first linked list of page data with a log sequence number less than the reference sequence number is found, connect the linked list of page data to be stored after the first linked list of page data with a log sequence number less than the reference sequence number; if no linked list of page data with a log sequence number less than the reference sequence number is found after the traversal is completed, it means that the log sequence numbers of all the basic linked lists of page data are greater than the reference sequence number. Then insert the linked list of page data to be stored in front of the basic linked list of page data with the smallest log sequence number.
[0145] Step S703, obtain all the preset locks of the global linked list of page data. Then execute step S704. Specifically, if there is no basic linked list of page data in the global linked list of page data, it means that there is no basic connection node for the linked list of page data to be stored within the range of log sequence numbers of the available preset lock. Then, in one case, the linked list of page data to be stored may need to be connected to the linked list of page data within the range of log sequence numbers of other preset locks. To avoid conflicts caused by other preset locks also performing storage tasks within their range of log sequence numbers and to improve the task priority of the linked list of page data to be stored, obtain all the preset locks, that is, make it so that only the linked list of page data to be stored can perform the task of being stored in the global linked list of page data.
[0146] For example, the available log sequence number range of the pre-set lock is (10, 15], and there is no page data linked list stored in the global page data linked list within this range. The used log sequence number range of a pre-set lock is (5, 10], and the global page data linked list has stored the page data linked lists with log sequence numbers 8 and 9. The log sequence number of the page data linked list to be stored is 11, and it needs to be connected after the page data linked list with log sequence number 9. If the page data linked list with log sequence number 10 is also storing data into the global page data linked list at this time, it may cause confusion in the connection between the page data linked list with log sequence number 11 and the page data linked list with log sequence number 10.
[0147] In another case, the global page data linked list may be empty, that is, no page data linked list is stored. Then the page data linked list to be stored does not need to be connected to other page data linked lists. However, to ensure that only the page data linked list to be stored can perform the task of storing into the global page data linked list, all pre-set locks are also acquired.
[0148] Step S704, check whether the global page data linked list is empty. If it is, execute step S705; if not, execute step S706. Specifically, it is to check whether there is already a page data linked list stored in the global page data linked list.
[0149] Step S705, store the page data linked list to be stored into the global page data linked list. If the global page data linked list is empty, that is, there is no page data linked list in the global page data linked list, then there is no need to consider the problem of connection nodes, so the page data linked list to be stored can be directly stored into the global page data linked list.
[0150] Step S706, find the first page data linked list in the global page data linked list from the back forward whose log sequence number is less than the reference sequence number.
[0151] Step S707, connect the page data linked list to be stored behind the first page data linked list whose log sequence number is less than the reference sequence number.
[0152] Specifically, traverse the global page data linked list from the back forward until finding the first page data linked list whose log sequence number is less than the reference sequence number. This indicates that the position behind this page data linked list is the correct position for the page data linked list to be stored. Connecting the page data linked list to be stored behind the first page data linked list whose log sequence number is less than the reference sequence number can ensure that the page data linked list to be stored is correctly connected in the global page data linked list in ascending order of log sequence numbers.
[0153] After that, release the pre-set lock of the global page data linked list. Specifically, after the page data linked list to be stored completes the storage task in the global page data linked list, all the pre-set locks acquired during the storage process are released. Then, store the assembled linked list part of the database log into the log buffer.
[0154] Because it needs to be stored in the global page data linked list in ascending order of the log sequence number. On the one hand, in the case of only one lock or no lock, the page data linked lists can only be strictly stored in the global page data linked list one by one. That is, before one page data linked list is completely stored, other page data linked lists cannot be stored in the global page data linked list. On the other hand, as the page data linked lists are continuously stored in the global page data linked list, the global page data linked list will become very long, which may lead to a long time for searching the global page data linked list. The above two aspects will limit the storage efficiency of the page data linked list.
[0155] Therefore, by pre-configuring a preset number of preset locks for the global page data linked list, each preset lock is bound to a range of log sequence numbers, so that different page data linked lists within the log sequence number ranges of different preset locks can each obtain the preset locks within their respective ranges, and thus perform the task of storing in the global page data linked list without interference. On the basis of ensuring that the page data linked lists in the global page data linked list are connected in order, the concurrency of storing the page data linked list in the global page data linked list is improved, which further helps to improve the storage efficiency of the page data linked list into the global page data linked list.
[0156] Furthermore, by checking whether there is a basic page data linked list in the global page data linked list, in the case of non-existence, all the preset locks of the global page data linked list are obtained, and then the page data linked list to be stored is stored in the global page data linked list. In the case where the page data linked list to be stored needs to be connected to the page data linked lists within the log sequence number ranges of other preset locks, it can avoid the situation of conflicts caused by other preset locks also performing storage tasks within their log sequence number ranges.
[0157] Furthermore, by setting a set threshold, after obtaining the first sequence number, it is judged whether the difference between the reference sequence number and the first sequence number is greater than the set threshold. In the case of not being greater than the set threshold, the newly added log sequence number range is determined to be greater than the first sequence number and less than or equal to the first sequence number plus the set threshold. Compared with directly determining the newly added log sequence number range to be greater than the first sequence number and less than or equal to the reference sequence number, it can avoid the situation that the newly added log sequence number range is too small, resulting in frequent acquisition of preset locks and having an adverse impact on the processing efficiency.
[0158] By modifying the range of the used preset locks when there is no unused preset lock in the global page data linked list, available preset locks can be obtained without waiting for the used preset locks to become available, thereby improving the processing efficiency.
[0159] It should be noted that the steps not detailed in this embodiment refer to those described above.
[0160] Such as Figure 15As shown, in one embodiment, the method for processing database logs generally further includes:
[0161] Step S801: Detect an enabling signal for flushing the database logs in the cache to disk. Specifically, the enabling signal can be a signal that is triggered at fixed intervals, or it can also be a signal that is triggered after the amount of database log data in the cache reaches a certain threshold, etc. Simply put, it is to detect that it is necessary to perform the work of flushing the database logs in the cache to disk.
[0162] Step S802: Obtain the database logs in the cache that meet the preset flushing rules, denoted as flushable logs. Specifically, the database logs that meet the preset flushing rules are at least one database log that has been completely written into the cache and whose log sequence numbers are consecutive starting from the log sequence number of the last database log completed in the previous flush. A database log that has been completely written into the cache is a database log whose linked list part has been written into the log buffer area and whose page data linked list has been stored in the global page data linked list.
[0163] Specifically, the preset flushing rules can be configured such that all database logs whose log sequence numbers are consecutive starting from the log sequence number of the last database log completed in the previous flush are used as the database logs that can be flushed this time, or it can also be configured such that a set number (such as one, two, ten, one hundred, etc.) of database logs whose log sequence numbers are consecutive starting from the log sequence number of the last database log completed in the previous flush are used as the database logs that can be flushed this time.
[0164] Exemplarily, if the database logs with log sequence numbers 3, 4, 5, 8, 9 (the numbers are only for illustration and do not represent actual complete log sequence numbers) are completely stored in the current cache, and the log sequence number of the last database log completed in the previous flush is 2.
[0165] With the preset flushing rules configured such that all database logs whose log sequence numbers are consecutive starting from the log sequence number of the last database log completed in the previous flush are used as the database logs that can be flushed this time: Starting from 2, 3, 4, and 5 are the database logs whose log sequence numbers are consecutive. Since 6 and 7 are missing between 5 and 8, they are no longer consecutive. Then the database logs with log sequence numbers 3, 4, and 5 meet the preset flushing rules.
[0166] With the preset flushing rules configured such that two database logs whose log sequence numbers are consecutive starting from the log sequence number of the last database log completed in the previous flush are used as the database logs that can be flushed this time: Starting from 2, 3 and 4 are the database logs whose log sequence numbers are consecutive.
[0167] Step S803, find the corresponding page data linked list from the global page data linked list according to the log sequence number of the log that can be written to disk, and record it as the page data linked list that can be written to disk. Specifically, after determining the log that can be written to disk, find the corresponding page data linked list from the global page data linked list according to the log sequence number.
[0168] Step S804, the page mirror data in the page data linked list that can be stored on disk are copied to the end of the preset page mirror data storage table in the connection order. Specifically, a page mirror data storage table is pre-created in the disk, and after the page mirror data that can be stored on disk is obtained, the data content of the page mirror data that can be stored on disk is copied to the page mirror data storage table.
[0169] Reference Figure 16 As shown, this is an example of a page mirror data storage table. Because the page data linked list was previously stored in the global page data linked list in the order of log sequence numbers, the page mirror data in the disk-capable page data linked list is directly copied to the end of the storage table in the connection order. The page mirror data in the page mirror data storage table must also be arranged in the order of log sequence numbers.
[0170] Furthermore, because the page mirror data is generated according to a preset threshold interval, the size of the page mirror data storage table will not increase very quickly.
[0171] Step S805, the assembly linked list part of the log that can be put on disk is put on disk. Specifically, the assembly linked list part of the database log in the log buffer area is put on disk. At this point, the page data linked list and assembly linked list of the database log that needs to be put on disk in this disk work are all put on disk, that is, the complete database log is put on disk.
[0172] It should be noted that this step has no strict context relationship with the step of putting the page mirror data into the page mirror data storage table.
[0173] Furthermore, after the step of sequentially copying the page mirror data in the page data linked list that can be written to the disk to the end of the preset page mirror data storage table in the connection order, the following steps are included:
[0174] Step S806, remove the page data linked list that can be written to disk from the global page data linked list. Specifically, the page data linked list that has been written to disk in the global page data linked list is deleted to free up storage space.
[0175] In addition, when the global page data linked list is provided with multiple preset locks, if it is detected that the log sequence number range corresponding to all page data linked lists of a preset lock of the global page data linked list has been stored on disk, the preset lock will be recycled, that is, the preset lock will be returned to an unused state without a bound log sequence number range for reuse.
[0176] In the solution of this embodiment, by storing the page mirror data in the page mirror data storage table, since the database can manage and search tables more conveniently, the management convenience of the page mirror data on the disk can be improved. Moreover, since the page data linked list was sorted in the order of the log sequence number during the process of storing it in the global page data linked list before, the page mirror data can be directly placed at the end of the page mirror data storage table without the need for sorting during the disk write stage, and the efficiency is very high. Also, since the page mirror data is generated at preset threshold intervals, the size of the page mirror data storage table will not grow very fast.
[0177] This embodiment also provides a machine-readable storage medium and a computer device. Figure 17 FIG. is a schematic diagram of a machine-readable storage medium 10 according to an embodiment of the present invention. Figure 18 FIG. is a schematic diagram of a computer device 20 according to an embodiment of the present invention.
[0178] The machine-readable storage medium 10 stores thereon a machine-executable program 11, and when the machine-executable program 11 is executed by a processor, it implements the processing method of the database log in any of the above embodiments.
[0179] The computer device 20 may include a memory 210, a processor 220, and a machine-executable program 11 stored on the memory 210 and running on the processor 220, and when the processor 220 executes the machine-executable program 11, it implements the processing method of the database log in any of the above embodiments.
[0180] For the description of this embodiment, the machine-readable storage medium 10 may be any device that can contain, store, communicate, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. More specific examples (non-exhaustive list) of the computer-readable medium include the following: an electrical connection portion (electronic device) having one or more wirings, a portable computer disk cartridge (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the machine-readable storage medium 10 can even be paper or other suitable media on which the program can be printed, because the program can be obtained electronically, for example, by optically scanning the paper or other media, then editing, interpreting, or otherwise processing it as appropriate, and then storing it in a computer memory.
[0181] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.
[0182] The computer device 20 can be, for example, a server, a desktop computer, a laptop computer, a tablet computer, or a smart phone. In some examples, the computer device 20 can be a cloud computing node. The computer device 20 can be described in the general context of computer system executable instructions, such as program modules, executed by a computer system. Generally, program modules can include routines, programs, object programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. The computer device 20 can be implemented in a distributed cloud computing environment where tasks are executed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can be located on local or remote computing system storage media including storage devices.
[0183] The computer device 20 can include a processor 220 adapted to execute stored instructions and a memory 210 that provides temporary storage space for the operation of the instructions during operation. The processor 220 can be a single-core processor, a multi-core processor, a computing cluster, or any other number of other configurations. The memory 210 can include random access memory (RAM), read-only memory, flash memory, or any other suitable storage system.
[0184] The processor 220 can be connected through a system interconnect (such as PCI, PCI-Express, etc.) to an I / O interface (input / output interface) adapted to connect the computer device 20 to one or more I / O devices (input / output devices). The I / O devices can include, for example, a keyboard and a pointing device, where the pointing device can include a touchpad or a touch screen, etc. The I / O devices can be built-in components of the computer device 20, or can be devices externally connected to the computing device.
[0185] The processor 220 may also be linked via the system interconnect to a display interface adapted to connect the computer device 20 to a display device. The display device may include a display screen that is an in-built component of the computer device 20. The display device may also include a computer monitor, a television set, a projector, etc. that are externally connected to the computer device 20. In addition, a network interface controller (NIC) may be adapted to connect the computer device 20 to a network via the system interconnect. In some embodiments, the NIC may use any suitable interface or protocol (such as Internet Small Computer System Interface, etc.) to transmit data. The network may be a cellular network, a radio network, a wide area network (WAN), a local area network (LAN), or the Internet, etc. A remote device may be connected to the computing device via the network.
[0186] At this point, those skilled in the art should recognize that although numerous exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications consistent with the principles of the present invention may still be directly determined or derived from the disclosure of the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and construed as covering all such other variations or modifications.
Claims
1. A method for processing database logs, comprising: Detecting that a data page is modified; Obtaining the log sequence number of the database log corresponding to the modification operation, denoted as the modification sequence number; Reading the record mark sequence number of the data page, where the record mark sequence number is the log sequence number corresponding to the data page when it was last recorded in the database log; If the record mark sequence number is less than or equal to the log redo point of the database, detecting whether the amount of modified data between the modification sequence number and the record mark sequence number of the data page is greater than or equal to a preset threshold; If it is greater than or equal to the preset threshold, recording the data page in the database log and updating the record mark sequence number to the modification sequence number.
2. The method for processing database logs according to claim 1, wherein, After the step of detecting whether the amount of log data between the modification sequence number and the record mark sequence number is greater than or equal to a preset threshold, it includes: If it is less than the preset threshold, not recording the data page in the database log and maintaining the record mark sequence number.
3. The method for processing a database log according to claim 1, wherein, Before the step of detecting whether the amount of log data between the modification sequence number and the record mark sequence number is greater than or equal to a preset threshold, it includes: Checking whether the record mark sequence number is less than or equal to the log redo point. If so, performing the step of detecting whether the amount of log data between the modification sequence number and the record mark sequence number is greater than or equal to a preset threshold. If not, not recording the data page in the database log and maintaining the record mark sequence number.
4. The method for processing database logs according to claim 1, wherein, After determining the complete content of a database log containing page mirror data, where the page mirror data is the data of the data page recorded in the database log, the method for processing the database log further includes: Obtaining the complete content of the database log; Pre-assembling the database log into a structure composed of an assembly linked list and a page data linked list connected after the assembly linked list. The page data linked list is a linked list composed of the page mirror data in the database log, and the assembly linked list is a linked list composed of other data in the database log except the page mirror data; Reading and recording the log sequence number of the database log, denoted as the reference sequence number; Obtaining the page data linked list of the database log, denoted as the page data linked list to be stored; Storing the page data linked list to be stored into a preset global page data linked list in ascending order of the log sequence number according to the reference sequence number, so that the page data linked lists in the global page data linked list are connected in ascending order of the log sequence number; Storing the assembly linked list part of the database log into the log buffer.
5. The method for processing a database log according to claim 4, wherein, Before the step of storing the page data linked list to be stored into a preset global page data linked list in ascending order of the log sequence number according to the reference sequence number, it includes: Obtaining the preset lock of the global page data linked list.
6. The method for processing database logs according to claim 5, wherein, The global page data linked list is pre-configured with a preset number of preset locks, and each preset lock can bind a range of log sequence numbers. The step of obtaining the preset lock of the global page data linked list includes: Obtain an available preset lock of the global page data linked list, where the available preset lock is a preset lock whose bound log sequence number range includes the reference sequence number.
7. The method for processing a database log according to claim 4, wherein, The method for processing the database log further includes: Detect an enabling signal for flushing the database log in the cache to disk; Obtain the database logs in the cache that meet the preset disk flushing rules, denoted as disk-flushable logs. The database logs that meet the preset disk flushing rules are at least one database log that has been completely written into the cache and whose log sequence numbers are consecutive starting from the log sequence number of the last database log completed in the previous disk flushing; Find the corresponding page data linked list from the global page data linked list according to the log sequence numbers of the disk-flushable logs, denoted as the disk-flushable page data linked list; Copy the page mirror data in the disk-flushable page data linked list to the end of a preset page mirror data storage table in sequence according to the connection order; Partially flush the assembled linked list of the disk-flushable logs to disk.
8. The method for processing a database log according to claim 7, wherein, After the step of copying the page mirror data in the disk-flushable page data linked list to the end of a preset page mirror data storage table in sequence according to the connection order includes: Remove the disk-flushable page data linked list from the global page data linked list.
9. A machine-readable storage medium, on which a machine-executable program is stored. When the machine-executable program is executed by a processor, it implements the method for processing a database log according to any one of claims 1 to 8.
10. A computer device, including a memory, a processor, and a machine-executable program stored on the memory and running on the processor. When the processor executes the machine-executable program, it implements the method for processing a database log according to any one of claims 1 to 8.