Database log processing method, device, equipment and storage medium

By using the circular buffer storage and parsing mechanism in database log processing, the problems of slow processing speed and data loss in the existing technology are solved, and efficient and reliable log processing is achieved.

CN113297150BActive Publication Date: 2024-10-29AGRICULTURAL BANK OF CHINA
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202110694432.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-22
Publication Date
2024-10-29
Estimated Expiration
2041-06-22

AI Technical Summary

Technical Problem

Existing database log processing technology has slow processing speed and is easy to lose log data.

Method used

By loading the log data to be processed into a circular buffer, and using the storage and parsing mechanism of the circular buffer, it processes and confirms the parsing results one by one to ensure data integrity, and re-obtains the data for processing when an exception is detected.

Benefits of technology

It improves the speed and reliability of database log processing, avoids the loss of log data, and achieves fast and efficient log processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113297150B_ABST
    Figure CN113297150B_ABST
Patent Text Reader

Abstract

The present application provides a database log processing method, device, equipment and storage medium, the method comprising: in response to a processing instruction for a database log, loading the to-be-processed log data of a first threshold into a circular buffer, obtaining the to-be-processed log data of a second threshold in the circular buffer for parsing, determining whether the parsing of the to-be-processed log data of the second threshold is completed, if the parsing of the to-be-processed log data of the second threshold is completed, obtaining log data in a target format, and deleting the parsed to-be-processed log data in the circular buffer, so that the space after deleting the parsed to-be-processed log data is used to cache new to-be-processed log data, if an abnormality is detected during the parsing of the to-be-processed log data of the second threshold, re-obtaining the to-be-processed log data of the second threshold in the circular buffer for parsing. The present application can process database logs quickly, efficiently and reliably.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a database log processing method, device, equipment and storage medium. Background Art

[0002] With the booming demand for database synchronization, it has become a common practice in the industry to parse database logs to obtain increments for synchronization. In this process, how to parse database logs quickly, efficiently and reliably has become a research focus.

[0003] The inventors found during the research that the current database log processing technology is to read and process the database log line by line, which is slow or may lose the database log during the processing. Therefore, a new database log processing solution is urgently needed. Summary of the invention

[0004] The present application provides a database log processing method, device, equipment and storage medium to solve the problem that the current database log processing technology has a slow database log processing speed or loses the database log during the processing process.

[0005] In a first aspect, the present application provides a database log processing method, comprising:

[0006] In response to a processing instruction for a database log, loading a first threshold of log data to be processed into a circular buffer, the processing instruction including a storage location of the log data to be processed, the first threshold being an integer greater than 1, and the first threshold being less than or equal to the total number of elements stored in the circular buffer;

[0007] Obtaining to-be-processed log data of a second threshold in the circular buffer for parsing, where the second threshold is less than or equal to the first threshold;

[0008] Determining whether parsing of the log data to be processed of the second threshold is completed;

[0009] If the parsing of the log data to be processed of the second threshold is completed, the log data in the target format is obtained, and the parsed log data to be processed is deleted in the circular buffer, so that the space after deleting the parsed log data to be processed is used to cache new log data to be processed;

[0010] If an abnormality is detected during the parsing of the log data to be processed of the second threshold, the log data to be processed of the second threshold is re-obtained in the circular buffer for parsing.

[0011] Optionally, obtaining the to-be-processed log data of the second threshold in the circular buffer for parsing includes: sequentially obtaining the to-be-processed log data of the second threshold for parsing through multiple threads.

[0012] Optionally, the maximum identifier of the log data to be processed obtained sequentially by each thread is stored in a queue to determine whether the parsing of the log data to be processed of the second threshold is completed, including: determining whether the identifier corresponding to the last log data to be processed parsed by the thread is equal to the first number in the queue; if the identifier corresponding to the last log data to be processed parsed by the thread is equal to the first number in the queue, then it is determined that the thread has completed the parsing of the corresponding log data to be processed of the second threshold; if the identifier corresponding to the last log data to be processed parsed by the thread is not equal to the first number in the queue, then it is determined that the thread has not completed the parsing of the corresponding log data to be processed of the second threshold.

[0013] Optionally, before loading the to-be-processed log data of the first threshold into the circular buffer, the method further includes: determining that the size of the free space of the circular buffer is greater than or equal to the first threshold.

[0014] Optionally, the database log processing method further includes: if the size of the free space of the circular buffer is smaller than a first threshold, loading the to-be-processed log data of the size of the free space into the circular buffer.

[0015] Optionally, the database log processing method further includes at least one of the following: outputting log data in a target format; and storing the log data in the target format in a database.

[0016] In a second aspect, the present application provides a database log processing device, comprising:

[0017] A loading module, configured to load a first threshold of log data to be processed into a circular buffer in response to a processing instruction for a database log, wherein the processing instruction includes a storage location of the log data to be processed, the first threshold is an integer greater than 1, and the first threshold is less than or equal to the total number of elements stored in the circular buffer;

[0018] A parsing module, used for obtaining to-be-processed log data of a second threshold in a circular buffer for parsing, where the second threshold is less than or equal to the first threshold;

[0019] A determination module, used to determine whether parsing of the log data to be processed of the second threshold is completed;

[0020] A processing module is used to obtain log data in a target format if parsing of the log data to be processed of the second threshold is completed, and to delete the parsed log data to be processed in a circular buffer so that the space after deleting the parsed log data to be processed is used to cache new log data to be processed; and if an abnormality is detected during the parsing of the log data to be processed of the second threshold, the log data to be processed of the second threshold is re-obtained in the circular buffer for parsing.

[0021] Optionally, the parsing module is specifically used to: sequentially obtain the to-be-processed log data of the second threshold through multiple threads for parsing.

[0022] Optionally, the maximum identifier of the log data to be processed obtained sequentially by each thread is stored in a queue, and the determination module is specifically used to: determine whether the identifier corresponding to the last log data to be processed parsed by the thread is equal to the first number in the queue; if the identifier corresponding to the last log data to be processed parsed by the thread is equal to the first number in the queue, then it is determined that the thread has completed the parsing of the corresponding second threshold of the log data to be processed; if the identifier corresponding to the last log data to be processed parsed by the thread is not equal to the first number in the queue, then it is determined that the thread has not completed the parsing of the corresponding second threshold of the log data to be processed.

[0023] Optionally, before loading the to-be-processed log data of the first threshold into the circular buffer, the loading module is further configured to: determine whether the size of the free space of the circular buffer is greater than or equal to the first threshold.

[0024] Optionally, the loading module is further used to: if the size of the free space of the circular buffer is smaller than a first threshold, load the to-be-processed log data of the size of the free space into the circular buffer.

[0025] Optionally, the processing module is further used for at least one of the following: outputting log data in a target format; storing the log data in the target format in a database.

[0026] In a third aspect, the present application provides an electronic device, including: a memory and a processor;

[0027] The memory is used to store program instructions;

[0028] The processor is used to call the program instructions in the memory to execute the database log processing method as described in the first aspect of the present application.

[0029] In a fourth aspect, the present application provides a computer-readable storage medium, in which computer program instructions are stored. When the computer program instructions are executed, the database log processing method described in the first aspect of the present application is implemented.

[0030] In a fifth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the database log processing method as described in the first aspect of the present application.

[0031] The database log processing method, device, equipment and storage medium provided by the present application, by responding to the processing instruction for the database log, loading the to-be-processed log data of the first threshold into the circular buffer, obtaining the to-be-processed log data of the second threshold in the circular buffer for parsing, determining whether the parsing of the to-be-processed log data of the second threshold is completed, if the parsing of the to-be-processed log data of the second threshold is completed, then obtaining the log data of the target format, and deleting the parsed to-be-processed log data in the circular buffer, so that the space after deleting the parsed to-be-processed log data is used to cache new to-be-processed log data, if an abnormality is detected during the parsing of the to-be-processed log data of the second threshold, then re-obtaining the to-be-processed log data of the second threshold in the circular buffer for parsing. Since the present application stores the to-be-processed log data in the circular buffer, obtains the to-be-processed log data from the circular buffer for parsing, and confirms the parsing results, it can greatly improve the processing speed of the database log and ensure that the database log is not lost during the processing. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0033] Figure 1 A schematic diagram of an application scenario provided for an embodiment of the present application;

[0034] Figure 2 A flowchart of a database log processing method provided in an embodiment of the present application;

[0035] FIG3( a ) is a schematic diagram of unloaded data into a circular buffer according to an embodiment of the present application;

[0036] FIG3( b ) is a schematic diagram of loading 15 log data to be processed into a circular buffer according to an embodiment of the present application;

[0037] FIG3( c ) is a schematic diagram of obtaining 10 pieces of to-be-processed log data from a circular buffer for parsing according to an embodiment of the present application;

[0038] FIG3( d ) is a schematic diagram of determining that parsing of 10 log data to be processed in a circular buffer is completed according to an embodiment of the present application;

[0039] FIG3( e) is a schematic diagram of obtaining 5 more log data to be processed for parsing after parsing of 10 log data to be processed in the circular buffer is completed according to an embodiment of the present application;

[0040] Figure 4 A flowchart of a database log processing method provided by another embodiment of the present application;

[0041] Figure 5 A schematic diagram of the structure of a database log processing device provided in one embodiment of the present application;

[0042] Figure 6 A schematic diagram of the structure of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0044] First, some technical terms involved in this application are explained:

[0045] RingBuffer: A data structure used to represent a fixed-size, head-to-tail connected buffer, suitable for caching data streams.

[0046] Database: A warehouse that organizes, stores, and manages data according to data structures.

[0047] Pointer: used to point to the variable storage address.

[0048] The current database log processing technology reads and processes the database log line by line. The processing speed is slow or the database log may be lost during the processing, which cannot meet the actual needs. There is a large room for optimization for a large number of database log processing solutions.

[0049] Based on the above problems, the present application provides a database log processing method, device, equipment and storage medium, which loads the database log into a circular buffer of the memory to quickly, efficiently and reliably store, read and parse the database log in the circular buffer.

[0050] In the following, the application scenarios of the solution provided in this application are first illustrated.

[0051] Figure 1 This is a schematic diagram of an application scenario provided by an embodiment of the present application. Figure 1 As shown, Figure 1As shown, in this application scenario, the client 110 stores the database log to be processed, and the server 120 obtains the database log to be processed from the client 110 through the network, and processes the database log to be processed to obtain log data in the target format. The specific implementation process of the server 120 processing the database log to be processed can refer to the solutions of the following embodiments.

[0052] It should be noted that Figure 1 This is only a schematic diagram of an application scenario provided by the embodiment of the present application. Figure 1 does not limit the equipment included in Figure 1 The positional relationship between the devices in the Figure 1 In the application scenario shown, a data storage device may also be included. The data storage device may be an external memory relative to the client 110 or the server 120 , or an internal memory integrated in the client 110 or the server 120 .

[0053] Next, a database log processing method is introduced through a specific embodiment.

[0054] Figure 2 The flowchart of the database log processing method provided by an embodiment of the present application. The method of the embodiment of the present application can be applied to an electronic device, which can be a server or a server cluster. Figure 2 As shown, the method of the embodiment of the present application includes:

[0055] S201 . In response to a processing instruction for a database log, load a first threshold of to-be-processed log data into a circular buffer.

[0056] The processing instruction includes the storage location of the log data to be processed, the first threshold is an integer greater than 1, and the first threshold is less than or equal to the total number of elements stored in the circular buffer.

[0057] In an embodiment of the present application, the processing instruction for the database log may be input by a user to the electronic device executing the embodiment of the present method, or may be sent by other devices to the electronic device executing the embodiment of the present method. Exemplarily, the first threshold is, for example, 15, and the total number of elements stored in the circular buffer is, for example, 15. Exemplarily, Figure 3(a) is a schematic diagram of unloaded data into a circular buffer provided in an embodiment of the present application. As shown in Figure 3(a), the circular buffer is RingBuffer, and the total number of elements stored in the circular buffer is 15, corresponding to storage locations numbered 0 to 14. Exemplarily, refer to Figure 1, the client 110 stores a log file corresponding to the log data to be processed in a directory, and the storage location of the log data to be processed included in the processing instruction for the database log is the storage directory of the log file. The log file can be accessed through the network, that is, the storage directory containing the log file is accessed, and the log data to be processed of the first threshold is obtained from the log file, and the log data to be processed of the first threshold is loaded into the circular buffer of the memory through the Put pointer (also called Put operation). Exemplarily, 10 log data to be processed are loaded from the log file into the circular buffer. It can be understood that the circular buffer stores these 10 log data to be processed as 10 elements. Table 1 is the relevant information of 10 elements stored in the circular buffer provided in an embodiment of the present application. As shown in Table 1, the 10 elements are list elements (list element): (A, B, C, D, E, F, G, H, I, J). In the initial state, the initial value (current) is -1. Among the 10 elements, each element has a corresponding next (next) sequence number. For example, the next sequence number corresponding to the first element is 0, and the next sequence number corresponding to the last (end) element is 9, that is, end=9. The corresponding list elements are stored according to the next sequence number through the array (entries[next]).

[0058] Table 1

[0059]

[0060]

[0061] After 10 elements are loaded into the circular buffer through the Put operation, the variable put sequence number (putSequence, putSeq) is set to 9. Assume that the 5 list elements in Table 2 are loaded through the Put operation: (K, L, M, N, O), as shown in Table 2, for these 5 list elements, current is 9, starting next = 9 + 1 = 10, end = 9 + 5 = 14, and accordingly, putSeq is set to 14. Exemplarily, Figure 3 (b) is a schematic diagram of loading 15 log data to be processed into the circular buffer provided by an embodiment of the present application, as shown in Figure 3 (b), referring to Figure 3 (a), A, B, C, D, E, F, G, H, I, J, K, L, M, N, O are stored in the storage locations with sequence numbers 0 to 14, respectively, and the value of putSeq changes from -1 in Figure 3 (a) to 14 in Figure 3 (b).

[0062] Table 2

[0063] next entries[next] list element 10 entries

[10] K 11 entries

[11] L 12 entries

[12] M 13 entries

[13] N 14 entries

[14] O

[0064] Assume that the total number of elements stored in the circular buffer is 15. After the above two Put operations, a total of 15 elements are generated, which just fills up the circular buffer. If another Put operation comes in, since the circular buffer is full and there is no available slot, that is, there is no free space in the circular buffer, the Put operation will be blocked until there is free space in the circular buffer.

[0065] S202: Obtain the to-be-processed log data of a second threshold value in the circular buffer for parsing.

[0066] The second threshold is less than or equal to the first threshold.

[0067] After loading the first threshold of the pending log data into the circular buffer, the second threshold of the pending log data can be obtained in the circular buffer for parsing. Exemplarily, the first threshold is, for example, 15, and the second threshold is, for example, 10. Assuming that 15 elements, i.e., 15 pending log data, have been stored in the circular buffer, 10 pending log data are obtained through the Get pointer (also referred to as the Get operation) for parsing. It can be understood that the Put pointer in the above S201 is the production data, and the Get pointer here is the consumption data. The data consumed by the Get pointer must not exceed the data produced by the Put pointer. For example, if 10 pending log data are loaded in the circular buffer through the Put pointer, the Get pointer can only obtain 10 pending log data at most. However, sometimes in order to ensure the processing speed of the Get pointer, the number of data loaded by the Put pointer and the number of data obtained by the Get pointer will not be equal. The Put operation can be regarded as a producer, and the Get operation can be regarded as a consumer. The producer can be very fast, and the consumer can consume slowly. For example, 1000 log data to be processed are loaded in the circular buffer through the Put pointer, and the Get pointer only needs to process 10 log data to be processed each time. For example, referring to Table 1 and Table 2, current = -1 at the beginning, the total number of elements stored in the circular buffer is 15, the corresponding maximum sequence number (maxAbleSequence) is 14, and the batch size (BatchSize) of the Get pointer is assumed to be 10, that is, the Get pointer only needs to process 10 log data to be processed each time. In the initial state, next = current = -1, end = -1, through the starting position (startPosition), next = 0 will be set, based on the data in Table 1, and finally end is assigned to 9, that is, the circular buffer [0, 9] has a total of 10 elements, and the Get pointer obtains these 10 elements for parsing. Correspondingly, the acquisition sequence number (getSequence, getSeq) corresponding to the Get pointer is set to 10. Exemplarily, Figure 3(c) is a schematic diagram of obtaining 10 pieces of log data to be processed from a circular buffer for parsing provided by an embodiment of the present application. As shown in Figure 3(c), referring to Figure 3(a), 10 elements A, B, C, D, E, F, G, H, I, and J corresponding to storage locations with sequence numbers 0 to 9 (i.e., 10 pieces of log data to be processed) are obtained for parsing, and the value of getSeq changes from -1 in Figure 3(a) to 10 in Figure 3(c).

[0068] S203: Determine whether parsing of the log data to be processed of the second threshold is completed.

[0069] Exemplarily, in the circular buffer, the log data to be processed of the second threshold is obtained through the Get pointer for parsing, and the confirmation (Ack) pointer (also referred to as the Ack operation) can be used to determine whether the parsing of the log data to be processed of the second threshold is completed. For how to determine whether the parsing of the log data to be processed of the second threshold is completed, reference can be made to the relevant technology or subsequent embodiments, which will not be repeated here.

[0070] S204: If parsing of the log data to be processed of the second threshold is completed, log data in the target format is obtained, and the parsed log data to be processed is deleted from the circular buffer, so that the space after deleting the parsed log data to be processed is used to cache new log data to be processed.

[0071] Exemplarily, referring to Table 1 and Table 2, 15 log data to be processed are loaded in the circular buffer through the Put pointer, and the Get pointer obtains 10 log data to be processed in Table 1 for parsing. The Ack pointer determines that the parsing of these 10 log data to be processed is completed, that is, all 10 log data to be processed are parsed correctly, and no abnormality is detected, then the corresponding log data in the target format is obtained, and the 10 parsed log data to be processed are deleted in the circular buffer. After deletion, there will be 10 free slots in the circular buffer for caching new log data to be processed, that is, the new 10 log data to be processed can be loaded into the circular buffer through the Put pointer. Exemplarily, FIG3(d) is a schematic diagram of determining the completion of the analysis of 10 log data to be processed in the circular buffer provided by an embodiment of the present application. As shown in FIG3(d), with reference to FIG3(a), the analysis of 10 elements A, B, C, D, E, F, G, H, I, and J corresponding to the storage locations with sequence numbers 0 to 9 (i.e., 10 log data to be processed) is completed, and the value of the confirmation sequence number (ackSequence, ackSeq) changes from -1 in FIG3(a) to 10 in FIG3(d), and the 10 elements A, B, C, D, E, F, G, H, I, and J corresponding to the storage locations with sequence numbers 0 to 9 are deleted. It should be noted that the data confirmed by the Ack pointer must not exceed the data consumed by the Get pointer. Exemplarily, 15 log data to be processed are loaded in the circular buffer through the Put pointer, and the Get pointer obtains 10 log data to be processed for analysis, then the Ack pointer can only confirm 10 data at most. The Ack operation can be understood as the completion of consumer consumption, and its purpose is to clear the data in the circular buffer that has been operated by the Get pointer.

[0072] S205: If an exception is detected during the parsing of the log data to be processed of the second threshold, the log data to be processed of the second threshold is re-obtained from the circular buffer for parsing.

[0073] Exemplarily, referring to Table 1 and Table 2, 15 log data to be processed are loaded in the circular buffer through the Put pointer, and the Get pointer obtains 10 log data to be processed in Table 1 for parsing. In the process of parsing the 10 log data to be processed, if an exception is detected, it means that the parsing of the 10 log data to be processed is not completed, and it is necessary to re-acquire the 10 log data to be processed in the circular buffer for parsing, that is, to perform rollback processing. Exemplarily, referring to Figure 3 (c), in the process of parsing the 10 elements A, B, C, D, E, F, G, H, I, and J stored in the storage locations with sequence numbers 0 to 9 (i.e., 10 log data to be processed), if an exception is detected, the getSeq corresponding to the Get pointer is rolled back to the position where the ackSeq is located, and the 10 elements A, B, C, D, E, F, G, H, I, and J stored in the storage locations with sequence numbers 0 to 9 are re-acquired for parsing.

[0074] Exemplarily, Figure 3(e) is a schematic diagram of an embodiment of the present application for determining that after the parsing of 10 log data to be processed in the circular buffer is completed, 5 log data to be processed are continued to be obtained for parsing. As shown in Figure 3(e), referring to Figure 3(a), after completing the parsing of 10 elements A, B, C, D, E, F, G, H, I, and J stored in storage locations with serial numbers 0 to 9 (i.e., 10 log data to be processed), continue to obtain 5 elements K, L, M, N, and O stored in storage locations with serial numbers 10 to 14 (i.e., 5 log data to be processed) for parsing, and the value of getSeq changes from 10 in Figure 3(d) to 14 in Figure 3(e), and repeat the corresponding steps of S203 to S205 to complete the parsing of 15 elements (i.e., 15 log data to be processed) stored in the circular buffer.

[0075] The database log processing method provided in the embodiment of the present application, by responding to the processing instruction for the database log, loads the to-be-processed log data of the first threshold into the circular buffer, obtains the to-be-processed log data of the second threshold in the circular buffer for parsing, determines whether the parsing of the to-be-processed log data of the second threshold is completed, if the parsing of the to-be-processed log data of the second threshold is completed, then obtains the log data of the target format, and deletes the parsed to-be-processed log data in the circular buffer, so that the space after deleting the parsed to-be-processed log data is used to cache new to-be-processed log data, if an abnormality is detected during the parsing of the to-be-processed log data of the second threshold, then re-obtains the to-be-processed log data of the second threshold in the circular buffer for parsing. Since the embodiment of the present application stores the to-be-processed log data in the circular buffer, obtains the to-be-processed log data from the circular buffer for parsing, and confirms the parsing result, it can greatly improve the processing speed of the database log and ensure that the database log is not lost during the processing.

[0076] Figure 4 This is a flowchart of a database log processing method provided by another embodiment of the present application. Based on the above embodiment, the embodiment of the present application further explains how to perform database log processing. Figure 4 As shown, the method of the embodiment of the present application may include:

[0077] S401: In response to a processing instruction for a database log, determine whether the size of the free space of a circular buffer is greater than or equal to a first threshold.

[0078] The processing instruction includes the storage location of the log data to be processed.

[0079] Exemplarily, the first threshold is, for example, 15, and the total number of elements stored in the circular buffer is, for example, 15. Then, it can be determined that the size of the free space of the circular buffer is equal to the first threshold, and step S402 is executed.

[0080] Optionally, if the size of the free space of the circular buffer is smaller than a first threshold, the log data to be processed with the size of the free space is loaded into the circular buffer.

[0081] Exemplarily, the first threshold is 15, the total number of elements stored in the circular buffer is 15, and 10 elements have been stored in the circular buffer. The size of the free space in the circular buffer, that is, the total number of new elements that can be loaded by the Put operation is 5. Then, 5 log data to be processed can be loaded into the circular buffer, and the circular buffer stores the 5 log data to be processed as 5 elements.

[0082] S402: Load the to-be-processed log data of a first threshold into a circular buffer.

[0083] The first threshold is an integer greater than 1, and the first threshold is less than or equal to the total number of elements stored in the circular buffer.

[0084] The detailed description of this step can be found in Figure 2 The relevant description of S201 in the illustrated embodiment will not be repeated here.

[0085] S403: sequentially obtain the to-be-processed log data of the second threshold through multiple threads for parsing.

[0086] The second threshold is less than or equal to the first threshold.

[0087] For example, suppose that 10 threads sequentially obtain the log data to be processed of the second threshold for parsing, that is, each thread performs a Get operation and obtains 10 log data to be processed for parsing. Among these 10 threads, the sequence numbers of the log data to be processed obtained by thread 0 are 0-9, the sequence numbers of the log data to be processed obtained by thread 1 are 10-19, and so on, the sequence numbers of the log data to be processed obtained by thread 9 are 90-99.

[0088] It should be noted that the processing speed of each thread may be different. Assuming that thread 1 has processed the pending log data before thread 0 and performed the Ack operation, ackSeq will be moved to the storage location with sequence number 20 in the circular buffer, and the data stored in the storage locations with sequence numbers 0 to 19 in the circular buffer will be considered processed. However, thread 0 may encounter an exception when processing data, and the data cannot be rolled back. In order to ensure that there is no confusion or loss of data when multi-threaded processing, a queue needs to be opened to store the identifier of each thread when performing the Ack operation.

[0089] Optionally, the maximum identifier of the log data to be processed obtained sequentially by each thread is stored in a queue.

[0090] For example, assuming that 10 threads sequentially obtain 10 log data to be processed for parsing, the serial numbers of the log data to be processed obtained by thread 0 are 0-9, the serial numbers of the log data to be processed obtained by thread 1 are 10-19, and so on. The serial numbers of the log data to be processed obtained by thread 9 are 90-99. The maximum identifier (i.e., the maximum serial number) 9 of the log data to be processed obtained by thread 0 is stored in the queue, and the maximum identifier (i.e., the maximum serial number) 19 of the log data to be processed obtained by thread 1 is stored in the queue, and so on. The queue stores the maximum identifiers of the log data to be processed obtained sequentially by each thread.

[0091] S404: Determine whether the identifier corresponding to the last log data to be processed parsed by the thread is equal to the first number in the queue.

[0092] For example, suppose that 10 threads sequentially obtain 10 unprocessed log data and parse them. When a thread (for example, represented by the loop variable i) parses the 10 unprocessed log data, before performing the Ack operation, the identifier corresponding to the last unprocessed log data parsed by the thread is compared with the number at the head of the queue to determine whether the two are equal. For example, the identifier (i.e., serial number) corresponding to the last unprocessed log data parsed by thread 0 is 9, and the number at the head of the queue is 9. Then, the identifier 9 corresponding to the last unprocessed log data parsed by thread 0 is compared with the number 9 at the head of the queue to determine whether the two are equal. Similarly, it can be determined whether the identifier corresponding to the last unprocessed log data parsed by each thread is equal to the number at the head of the queue.

[0093] If the identifier corresponding to the last processed log data parsed by the thread is equal to the first number in the queue, step S405 is executed; if the identifier corresponding to the last processed log data parsed by the thread is not equal to the first number in the queue, step S406 is executed.

[0094] S405: If the identifier corresponding to the last to-be-processed log data parsed by the thread is equal to the first number in the queue, it is determined that the thread has completed parsing the corresponding second threshold of to-be-processed log data.

[0095] For example, suppose that 10 threads sequentially obtain 10 unprocessed log data and parse them. Compare the identifier 9 corresponding to the last unprocessed log data parsed by thread 0 with the number 9 at the head of the queue. After determining that the two are equal, it can be determined that thread 0 has completed the parsing of the corresponding second threshold of unprocessed log data, and the first number in the queue is dequeued, and the Ack operation can be performed at the same time. Similarly, if the identifier corresponding to the last unprocessed log data parsed by each thread is equal to the first number in the queue, it can be determined that each thread has completed the parsing of the corresponding second threshold of unprocessed log data, and the first number in the queue is dequeued, and the Ack operation can be performed at the same time.

[0096] S406: If the identifier corresponding to the last to-be-processed log data parsed by the thread is not equal to the first number in the queue, it is determined that the thread has not completed the parsing of the corresponding second threshold of to-be-processed log data.

[0097] For example, suppose that 10 threads sequentially obtain 10 pending log data for parsing, and compare the identifier 19 corresponding to the last pending log data parsed by thread 1 with the number 9 at the head of the queue. After determining that the two are not equal, it can be determined that the previous thread, thread 0, has not completed the parsing of the corresponding second threshold pending log data. During the parsing of the second threshold pending log data, thread 0 detected an exception and needs to re-acquire the second threshold pending log data in the circular buffer for parsing. In this case, thread 1 needs to wait until it is determined that thread 0 has completed the parsing of the corresponding second threshold pending log data, and accordingly, the number at the head of the queue becomes 19.

[0098] S407: If parsing of the log data to be processed of the second threshold is completed, log data in the target format is obtained, and the parsed log data to be processed is deleted from the circular buffer, so that the space after deleting the parsed log data to be processed is used to cache new log data to be processed.

[0099] The detailed description of this step can be found in Figure 2 The relevant description of S204 in the illustrated embodiment will not be repeated here.

[0100] S408: If an exception is detected during the parsing of the log data to be processed of the second threshold, the log data to be processed of the second threshold is re-obtained from the circular buffer for parsing.

[0101] The detailed description of this step can be found in Figure 2 The relevant description of S205 in the illustrated embodiment will not be repeated here.

[0102] On the basis of the above embodiment, after obtaining the log data in the target format, the database log processing method may further include at least one of the following: outputting the log data in the target format; storing the log data in the target format into the database.

[0103] For example, reference Figure 1 After obtaining the log data in the target format, the server 120 may output the log data in the target format to the client 110. Exemplarily, after obtaining the log data in the target format, the log data in the target format may be stored in a database to facilitate other services to use the log data.

[0104] The database log processing method provided by the embodiment of the present application determines that the size of the free space of the circular buffer is greater than or equal to the first threshold value by responding to the processing instruction for the database log, loads the to-be-processed log data of the first threshold value into the circular buffer, sequentially obtains the to-be-processed log data of the second threshold value through multiple threads for parsing, determines whether the identifier corresponding to the to-be-processed log data parsed by the thread last is equal to the first number of the queue, if the identifier corresponding to the to-be-processed log data parsed by the thread last is equal to the first number of the queue, then determines that the thread has completed the parsing of the to-be-processed log data of the corresponding second threshold value, if the identifier corresponding to the to-be-processed log data parsed by the thread last is not equal to the first number of the queue, then determines that the thread has not completed the parsing of the to-be-processed log data of the corresponding second threshold value, if the parsing of the to-be-processed log data of the second threshold value is completed, then obtains the log data in the target format, and deletes the parsed to-be-processed log data in the circular buffer, so that the space after deleting the parsed to-be-processed log data is used to cache new to-be-processed log data, if an exception is detected during the parsing of the to-be-processed log data of the second threshold value, then re-obtains the to-be-processed log data of the second threshold value in the circular buffer for parsing. Since the embodiment of the present application stores the log data to be processed in a circular buffer, sequentially obtains the log data to be processed of the second threshold through multiple threads for analysis, and confirms the analysis results, the processing speed of the database log can be greatly improved, and it is ensured that the database log is not lost during the processing process.

[0105] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.

[0106] Figure 5 A schematic diagram of the structure of a database log processing device provided in an embodiment of the present application is shown in FIG. Figure 5 As shown, the database log processing device 500 of the embodiment of the present application includes: a loading module 501, a parsing module 502, a determining module 503 and a processing module 504. Among them:

[0107] The loading module 501 is used to load the log data to be processed of a first threshold into a circular buffer in response to a processing instruction for a database log, the processing instruction includes a storage location of the log data to be processed, the first threshold is an integer greater than 1, and the first threshold is less than or equal to the total number of elements stored in the circular buffer.

[0108] The parsing module 502 is used to obtain the to-be-processed log data of a second threshold in the circular buffer for parsing, where the second threshold is less than or equal to the first threshold.

[0109] The determination module 503 is used to determine whether the parsing of the log data to be processed of the second threshold is completed.

[0110] The processing module 504 is used to obtain the log data in the target format if the parsing of the log data to be processed of the second threshold is completed, and delete the parsed log data to be processed in the circular buffer so that the space after deleting the parsed log data to be processed is used to cache new log data to be processed; and if an abnormality is detected during the parsing of the log data to be processed of the second threshold, the log data to be processed of the second threshold is re-obtained in the circular buffer for parsing.

[0111] In some embodiments, the parsing module 502 may be specifically configured to sequentially obtain the to-be-processed log data of the second threshold through multiple threads for parsing.

[0112] Optionally, the maximum identifier of the log data to be processed obtained sequentially by each thread is stored in a queue, and the determination module 503 can be specifically used to: determine whether the identifier corresponding to the last log data to be processed parsed by the thread is equal to the first number in the queue; if the identifier corresponding to the last log data to be processed parsed by the thread is equal to the first number in the queue, then it is determined that the thread has completed the parsing of the corresponding second threshold of the log data to be processed; if the identifier corresponding to the last log data to be processed parsed by the thread is not equal to the first number in the queue, then it is determined that the thread has not completed the parsing of the corresponding second threshold of the log data to be processed.

[0113] In some embodiments, before loading the to-be-processed log data of the first threshold into the circular buffer, the loading module 501 may also be used to: determine whether the size of the free space of the circular buffer is greater than or equal to the first threshold.

[0114] Optionally, the loading module 501 may also be used to: if the size of the free space of the circular buffer is smaller than a first threshold, load the to-be-processed log data of the size of the free space into the circular buffer.

[0115] Optionally, the processing module 504 may also be used for at least one of the following: outputting the log data in the target format; storing the log data in the target format into a database.

[0116] The device of this embodiment can be used to execute the technical solution of any of the above-mentioned method embodiments. Its implementation principle and technical effects are similar and will not be repeated here.

[0117] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. For example, the electronic device can be provided as a server or a computer. Figure 6, the electronic device 600 includes a processing component 601, which further includes one or more processors, and a memory resource represented by a memory 602, for storing instructions that can be executed by the processing component 601, such as an application. The application stored in the memory 602 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 601 is configured to execute instructions to perform any of the above method embodiments.

[0118] The electronic device 600 may further include a power supply component 603 configured to perform power management of the electronic device 600, a wired or wireless network interface 604 configured to connect the electronic device 600 to a network, and an input / output (I / O) interface 605. The electronic device 600 may operate based on an operating system stored in the memory 602, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™ or the like.

[0119] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the above database log processing method is implemented.

[0120] The present application also provides a computer program product, including a computer program, which implements the above database log processing method when executed by a processor.

[0121] The computer-readable storage medium mentioned above can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.

[0122] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (Application Specific Integrated Circuits, referred to as ASIC). Of course, the processor and the readable storage medium can also exist in the database log processing device as discrete components.

[0123] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.

[0124] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A database log processing method, It is characterized in that include: In response to a processing instruction for a database log, loading a first threshold of log data to be processed into a circular buffer, the processing instruction including a storage location of the log data to be processed, the first threshold being an integer greater than 1, and the first threshold being less than or equal to the total number of elements stored in the circular buffer; sequentially acquiring, by using multiple threads, log data to be processed of a second threshold in the circular buffer for parsing, where the second threshold is less than or equal to the first threshold; The maximum identifier of the log data to be processed obtained sequentially by each thread is stored in a queue; Determine whether the identifier corresponding to the last log data to be processed parsed by the thread is equal to the first number in the queue; If the identifier corresponding to the last to-be-processed log data parsed by the thread is equal to the first number in the queue, it is determined that the thread has completed the parsing of the corresponding second threshold of to-be-processed log data, and the first number in the queue is dequeued; If the parsing of the log data to be processed of the second threshold is completed, the log data in the target format is obtained, and the parsed log data to be processed is deleted in the circular buffer, so that the space after deleting the parsed log data to be processed is used to cache new log data to be processed; If an exception is detected during the parsing of the log data to be processed of the second threshold, the log data to be processed of the second threshold is re-obtained from the circular buffer for parsing.

2. The database log processing method according to claim 1, It is characterized in that Also includes: If the identifier corresponding to the last to-be-processed log data parsed by the thread is not equal to the first number in the queue, it is determined that the thread has not completed the parsing of the corresponding second threshold of to-be-processed log data.

3. The database log processing method according to claim 1 or 2, It is characterized in that Before loading the to-be-processed log data of the first threshold into the circular buffer, the method further includes: It is determined that the size of the free space of the circular buffer is greater than or equal to the first threshold.

4. The database log processing method according to claim 3, It is characterized in that Also includes: If the size of the free space of the circular buffer is smaller than the first threshold, the to-be-processed log data of the size of the free space is loaded into the circular buffer.

5. The database log processing method according to claim 1 or 2, It is characterized in that Also includes at least one of the following: Outputting log data in the target format; The log data in the target format is stored in a database.

6. A database log processing device, It is characterized in that include: A loading module, configured to load a first threshold of log data to be processed into a circular buffer in response to a processing instruction for a database log, wherein the processing instruction includes a storage location of the log data to be processed, the first threshold is an integer greater than 1, and the first threshold is less than or equal to the total number of elements stored in the circular buffer; A parsing module, configured to sequentially obtain, through multiple threads, log data to be processed of a second threshold in the circular buffer for parsing, wherein the second threshold is less than or equal to the first threshold; and the maximum identifier of the log data to be processed sequentially obtained by each thread is stored in a queue; A determination module is used to determine whether the identifier corresponding to the last processed log data parsed by the thread is equal to the first number in the queue; if the identifier corresponding to the last processed log data parsed by the thread is equal to the first number in the queue, it is determined that the thread has completed the parsing of the corresponding second threshold of the processed log data, and the first number in the queue is dequeued; A processing module, which is used to obtain log data in a target format if parsing of the log data to be processed of the second threshold is completed, and delete the parsed log data to be processed in a circular buffer so that the space after deleting the parsed log data to be processed is used to cache new log data to be processed; and if an exception is detected during the parsing of the log data to be processed of the second threshold, re-obtain the log data to be processed of the second threshold in the circular buffer for parsing.

7. An electronic device, It is characterized in that include: Memory and processor; The memory is used to store program instructions; The processor is used to call the program instructions in the memory to execute the database log processing method according to any one of claims 1 to 5.

8. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed, the database log processing method according to any one of claims 1 to 5 is implemented.

9. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the database log processing method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Database log statistics method, system and related device

    CN111897867A